1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! Transcript-recording `LlmClientTrait` decorator (#1034).
//!
//! Why: `AgentLoop::run` returns only the final `AgentOutput` (content + usage);
//! it does not expose the per-turn conversation. The `run-task` command must
//! emit a structured transcript of every PM and engineer turn (model + assistant
//! text + tool calls). Rather than change the loop's signature, we wrap the
//! shared `LlmClientTrait` in a recorder that observes each request/response
//! pair and appends a `TurnRecord`. The wrapper is transparent — it forwards to
//! the inner client unchanged — so the real OpenRouter client and the offline
//! mock both work behind it.
//! What: `RecordingLlmClient` holds an inner `Arc<dyn LlmClientTrait>`, a role
//! label (`"pm"` / `"python-engineer"`), and a shared `Arc<Mutex<Vec<TurnRecord>>>`.
//! Each `chat` call records the resolved model and the resulting assistant text
//! plus tool-call names, then returns the inner response verbatim.
//! Test: `run_task::tests` assert the recorded transcript carries both roles, and
//! the per-run engineer model slug.
use ;
use async_trait;
use ;
use crate;
use crateTokenUsage;
/// One recorded assistant turn for the run transcript.
///
/// Why: The transcript output needs a machine- and human-renderable shape that
/// captures who spoke (role), with which model, what text, and which tools it
/// invoked — enough to reconstruct the PM→engineer interaction without leaking
/// the full raw message history.
/// What: `role` is the agent label; `model` is the resolved slug for that turn;
/// `text` is the assistant prose (empty for tool-only turns); `tool_calls` lists
/// the invoked tool names in order; `ran_test_command` (#2279) is a summarized
/// signal — `true` iff this turn's tool calls included a `bash` invocation
/// matching `crate::verify_gate::is_test_command` — the delegating PM's own
/// `verify_gate::pm_finish_gate` consults this instead of the engineer's full
/// transcript, since the PM never calls `bash` itself; `usage` is the token
/// usage the provider reported for this turn (the per-turn unit the run
/// aggregates over both PM and engineer turns, since the engineer's usage is
/// otherwise lost when its output flows back to the PM as a tool-result
/// string). `Deserialize` (#2060) lets `tcode`'s CLI thin client parse a
/// `session.get_transcript` JSON-RPC result straight back into
/// `Vec<TurnRecord>`.
/// Test: `run_task::tests::end_to_end_pm_delegates_to_engineer`,
/// `verify_gate::tests::pm_gate_satisfied_when_engineer_ran_tests`.
/// Shared, thread-safe transcript accumulator.
///
/// Why: The PM and engineer recorders run on the same tokio runtime and both
/// append to one ordered transcript; an `Arc<Mutex<…>>` is the minimal shared
/// sink that keeps turn order without global state.
/// What: A type alias for the shared vector of `TurnRecord`s.
/// Test: Exercised by every `run_task` end-to-end test.
pub type SharedTranscript = ;
/// A transparent `LlmClientTrait` that records each turn into a shared transcript.
///
/// Why: Captures the conversation for the run report without modifying the agent
/// loop. Wrapping the shared client means PM and engineer turns land in one
/// ordered transcript while usage still accrues on the inner client.
/// What: Forwards `chat` to the inner client, then appends a `TurnRecord` tagged
/// with this wrapper's `role` and the request's model. A poisoned transcript
/// lock is treated as a no-op record (the run must not panic mid-flight).
/// Test: `run_task::tests::end_to_end_pm_delegates_to_engineer`.