chore: introduce codex-common crate (#843)
I started this PR because I wanted to share the `format_duration()`
utility function in `codex-rs/exec/src/event_processor.rs` with the TUI.
The question was: where to put it?
`core` should have as few dependencies as possible, so moving it there
would introduce a dependency on `chrono`, which seemed undesirable.
`core` already had this `cli` feature to deal with a similar situation
around sharing common utility functions, so I decided to:
* make `core` feature-free
* introduce `common`
* `common` can have as many "special interest" features as it needs,
each of which can declare their own deps
* the first two features of common are `cli` and `elapsed`
In practice, this meant updating a number of `Cargo.toml` files,
replacing this line:
```toml
codex-core = { path = "../core", features = ["cli"] }
```
with these:
```toml
codex-core = { path = "../core" }
codex-common = { path = "../common", features = ["cli"] }
```
Moving `format_duration()` into its own file gave it some "breathing
room" to add a unit test, so I had Codex generate some tests and new
support for durations over 1 minute.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use clap::Parser;
|
||||
use codex_core::ApprovalModeCliArg;
|
||||
use codex_core::SandboxPermissionOption;
|
||||
use codex_common::ApprovalModeCliArg;
|
||||
use codex_common::SandboxPermissionOption;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use codex_ansi_escape::ansi_escape_line;
|
||||
use codex_common::elapsed::format_duration;
|
||||
use codex_core::config::Config;
|
||||
use codex_core::protocol::FileChange;
|
||||
use ratatui::prelude::*;
|
||||
@@ -132,7 +133,12 @@ impl HistoryCell {
|
||||
// Title depends on whether we have output yet.
|
||||
let title_line = Line::from(vec![
|
||||
"command".magenta(),
|
||||
format!(" (code: {}, duration: {:?})", exit_code, duration).dim(),
|
||||
format!(
|
||||
" (code: {}, duration: {})",
|
||||
exit_code,
|
||||
format_duration(duration)
|
||||
)
|
||||
.dim(),
|
||||
]);
|
||||
lines.push(title_line);
|
||||
|
||||
@@ -201,11 +207,11 @@ impl HistoryCell {
|
||||
success: bool,
|
||||
result: Option<serde_json::Value>,
|
||||
) -> Self {
|
||||
let duration = start.elapsed();
|
||||
let duration = format_duration(start.elapsed());
|
||||
let status_str = if success { "success" } else { "failed" };
|
||||
let title_line = Line::from(vec![
|
||||
"tool".magenta(),
|
||||
format!(" {fq_tool_name} ({status_str}, duration: {:?})", duration).dim(),
|
||||
format!(" {fq_tool_name} ({status_str}, duration: {})", duration).dim(),
|
||||
]);
|
||||
|
||||
let mut lines: Vec<Line<'static>> = Vec::new();
|
||||
|
||||
Reference in New Issue
Block a user