Skip to content

Commit 55d7e43

Browse files
Add debug trace reduction command
1 parent c657343 commit 55d7e43

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

codex-rs/cli/src/main.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use codex_exec::Command as ExecCommand;
2222
use codex_exec::ReviewArgs;
2323
use codex_execpolicy::ExecPolicyCheckCommand;
2424
use codex_responses_api_proxy::Args as ResponsesApiProxyArgs;
25+
use codex_rollout_trace::REDUCED_STATE_FILE_NAME;
26+
use codex_rollout_trace::replay_bundle;
2527
use codex_state::StateRuntime;
2628
use codex_state::state_db_path;
2729
use codex_tui::AppExitInfo;
@@ -190,6 +192,9 @@ enum DebugSubcommand {
190192
/// Render the model-visible prompt input list as JSON.
191193
PromptInput(DebugPromptInputCommand),
192194

195+
/// Replay a rollout trace bundle and write reduced state JSON.
196+
TraceReduce(DebugTraceReduceCommand),
197+
193198
/// Internal: reset local memory state for a fresh start.
194199
#[clap(hide = true)]
195200
ClearMemories,
@@ -224,6 +229,17 @@ struct DebugPromptInputCommand {
224229
images: Vec<PathBuf>,
225230
}
226231

232+
#[derive(Debug, Parser)]
233+
struct DebugTraceReduceCommand {
234+
/// Trace bundle directory containing manifest.json and trace.jsonl.
235+
#[arg(value_name = "TRACE_BUNDLE")]
236+
trace_bundle: PathBuf,
237+
238+
/// Output path for reduced RolloutTrace JSON. Defaults to TRACE_BUNDLE/state.json.
239+
#[arg(long = "output", short = 'o', value_name = "FILE")]
240+
output: Option<PathBuf>,
241+
}
242+
227243
#[derive(Debug, Parser)]
228244
struct ResumeCommand {
229245
/// Conversation/session id (UUID) or thread name. UUIDs take precedence if it parses.
@@ -991,6 +1007,14 @@ async fn cli_main(arg0_paths: Arg0DispatchPaths) -> anyhow::Result<()> {
9911007
)
9921008
.await?;
9931009
}
1010+
DebugSubcommand::TraceReduce(cmd) => {
1011+
reject_remote_mode_for_subcommand(
1012+
root_remote.as_deref(),
1013+
root_remote_auth_token_env.as_deref(),
1014+
"debug trace-reduce",
1015+
)?;
1016+
run_debug_trace_reduce_command(cmd).await?;
1017+
}
9941018
DebugSubcommand::ClearMemories => {
9951019
reject_remote_mode_for_subcommand(
9961020
root_remote.as_deref(),
@@ -1192,6 +1216,19 @@ fn maybe_print_under_development_feature_warning(
11921216
);
11931217
}
11941218

1219+
async fn run_debug_trace_reduce_command(cmd: DebugTraceReduceCommand) -> anyhow::Result<()> {
1220+
let output = cmd
1221+
.output
1222+
.unwrap_or_else(|| cmd.trace_bundle.join(REDUCED_STATE_FILE_NAME));
1223+
1224+
let trace = replay_bundle(&cmd.trace_bundle)?;
1225+
let reduced_json = serde_json::to_vec_pretty(&trace)?;
1226+
tokio::fs::write(&output, reduced_json).await?;
1227+
println!("{}", output.display());
1228+
1229+
Ok(())
1230+
}
1231+
11951232
async fn run_debug_prompt_input_command(
11961233
cmd: DebugPromptInputCommand,
11971234
root_config_overrides: CliConfigOverrides,

0 commit comments

Comments
 (0)