trusty_code/session/transcript.rs
1//! `session.get_transcript`'s response shape (#2058).
2//!
3//! Why: `SessionRegistry::set_run_outcome` (#2056) already persists a
4//! finished execution's turn-by-turn transcript, aggregate token usage, and
5//! priced cost onto the `SessionEntry` — this is the M1 cut-line's "inspect
6//! transcript" verb, exposing that stored record over the wire without
7//! recomputing anything. Kept as its own small file (rather than growing
8//! `registry.rs`) so the wire shape has one obvious home and stays decoupled
9//! from the registry's storage/locking internals.
10//! What: [`TranscriptRecord`] is a plain, `Serialize`+`Deserialize` DTO
11//! (#2060: the `Deserialize` half lets `tcode`'s CLI thin client — see
12//! `crate::cli_client` — parse `session.get_transcript`'s JSON-RPC result
13//! straight back into this type rather than picking fields off a raw
14//! `serde_json::Value`): `session_id`,
15//! the ordered `turns` (each already `role`/`model`/`text`/`tool_calls`/
16//! `usage` — see `crate::run_task::TurnRecord`), the aggregate `usage`, and
17//! `cost_usd` exactly as stored (`None` either because pricing was
18//! unavailable for the run, or because no run has ever completed on this
19//! session — the two cases are indistinguishable here by design, matching
20//! `RunReport::cost_usd`'s existing convention). A session that has never
21//! run a task returns `turns: []`, `usage` all-zero, `cost_usd: null` — a
22//! valid, empty transcript, not an error. `mode` (#2059) is the resolved
23//! `HarnessMode` `task.run` set via `SessionRegistry::set_mode` — `None` for
24//! the same "never run" case.
25//! Test: `session::registry_tests::get_transcript_*`.
26
27use serde::{Deserialize, Serialize};
28
29use crate::mode::HarnessMode;
30use crate::perf::TokenUsage;
31use crate::run_task::TurnRecord;
32
33/// The full stored run record for one session, as `session.get_transcript`
34/// returns it.
35///
36/// Why: see module docs — this is the read-only DTO wrapping whatever
37/// `SessionRegistry::set_run_outcome` last stored (or the all-empty default
38/// for a session that has never run a task).
39/// What: field-for-field passthrough of `SessionEntry`'s transcript/usage/
40/// cost, plus the `session_id` for a self-describing response (the wire
41/// method already takes `session_id` as a param, but echoing it back keeps
42/// the result self-contained for a caller inspecting the JSON alone).
43/// `mode` (#2059) mirrors `Session.mode` — the same field, read at
44/// `get_transcript` time.
45/// Test: `session::registry_tests::get_transcript_returns_stored_record`,
46/// `session::registry_tests::get_transcript_on_never_run_session_is_empty`.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct TranscriptRecord {
49 pub session_id: String,
50 pub turns: Vec<TurnRecord>,
51 pub usage: TokenUsage,
52 pub cost_usd: Option<f64>,
53 pub mode: Option<HarnessMode>,
54}