chore: introduce codex-common crate

This commit is contained in:
Michael Bolin
2025-05-06 17:33:11 -07:00
parent 7d8b38b37b
commit 51facd79bf
20 changed files with 143 additions and 42 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ path = "src/lib.rs"
anyhow = "1"
chrono = "0.4.40"
clap = { version = "4", features = ["derive"] }
codex-core = { path = "../core", features = ["cli"] }
codex-core = { path = "../core" }
codex-common = { path = "../common", features = ["cli", "elapsed"] }
mcp-types = { path = "../mcp-types" }
owo-colors = "4.2.0"
serde_json = "1"
+1 -1
View File
@@ -1,6 +1,6 @@
use clap::Parser;
use clap::ValueEnum;
use codex_core::SandboxPermissionOption;
use codex_common::SandboxPermissionOption;
use std::path::PathBuf;
#[derive(Parser, Debug)]
+5 -14
View File
@@ -1,4 +1,5 @@
use chrono::Utc;
use codex_common::elapsed::format_elapsed;
use codex_core::protocol::Event;
use codex_core::protocol::EventMsg;
use codex_core::protocol::FileChange;
@@ -145,7 +146,7 @@ impl EventProcessor {
}) = exec_command
{
(
format_duration(start_time),
format!(" in {}", format_elapsed(start_time)),
format!("{}", escape_command(&command).style(self.bold)),
)
} else {
@@ -160,7 +161,7 @@ impl EventProcessor {
.join("\n");
match exit_code {
0 => {
let title = format!("{call} succeded{duration}:");
let title = format!("{call} succeeded{duration}:");
ts_println!("{}", title.style(self.green));
}
_ => {
@@ -221,7 +222,7 @@ impl EventProcessor {
..
}) = info
{
(format_duration(start_time), invocation)
(format!(" in {}", format_elapsed(start_time)), invocation)
} else {
(String::new(), format!("tool('{call_id}')"))
};
@@ -335,7 +336,7 @@ impl EventProcessor {
}) = patch_begin
{
(
format_duration(start_time),
format!(" in {}", format_elapsed(start_time)),
format!("apply_patch(auto_approved={})", auto_approved),
)
} else {
@@ -383,13 +384,3 @@ fn format_file_change(change: &FileChange) -> &'static str {
} => "M",
}
}
fn format_duration(start_time: chrono::DateTime<Utc>) -> String {
let elapsed = Utc::now().signed_duration_since(start_time);
let millis = elapsed.num_milliseconds();
if millis < 1000 {
format!(" in {}ms", millis)
} else {
format!(" in {:.2}s", millis as f64 / 1000.0)
}
}