Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions codex-rs/core/src/tools/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub(crate) enum ToolEmitter {
},
UnifiedExec {
command: String,
display_command: Vec<String>,
cwd: PathBuf,
// True for `exec_command` and false for `write_stdin`.
#[allow(dead_code)]
Expand All @@ -111,9 +112,15 @@ impl ToolEmitter {
}
}

pub fn unified_exec(command: String, cwd: PathBuf, is_startup_command: bool) -> Self {
pub fn unified_exec(
command: String,
display_command: Vec<String>,
cwd: PathBuf,
is_startup_command: bool,
) -> Self {
Self::UnifiedExec {
command,
display_command,
cwd,
is_startup_command,
}
Expand Down Expand Up @@ -217,8 +224,21 @@ impl ToolEmitter {
) => {
emit_patch_end(ctx, String::new(), (*message).to_string(), false).await;
}
(Self::UnifiedExec { command, cwd, .. }, ToolEventStage::Begin) => {
emit_exec_command_begin(ctx, &[command.to_string()], cwd.as_path(), false).await;
(
Self::UnifiedExec {
command,
display_command,
cwd,
..
},
ToolEventStage::Begin,
) => {
let command_args = if display_command.is_empty() {
vec![command.clone()]
} else {
display_command.clone()
};
emit_exec_command_begin(ctx, &command_args, cwd.as_path(), false).await;
}
(Self::UnifiedExec { .. }, ToolEventStage::Success(output)) => {
emit_exec_end(
Expand Down
5 changes: 4 additions & 1 deletion codex-rs/core/src/tools/handlers/unified_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::unified_exec::UnifiedExecContext;
use crate::unified_exec::UnifiedExecResponse;
use crate::unified_exec::UnifiedExecSessionManager;
use crate::unified_exec::WriteStdinRequest;
use crate::unified_exec::build_shell_command;

pub struct UnifiedExecHandler;

Expand Down Expand Up @@ -113,7 +114,9 @@ impl ToolHandler for UnifiedExecHandler {
&context.call_id,
None,
);
let emitter = ToolEmitter::unified_exec(args.cmd.clone(), cwd.clone(), true);
let display_command = build_shell_command(&args.shell, args.login, &args.cmd);
let emitter =
ToolEmitter::unified_exec(args.cmd.clone(), display_command, cwd.clone(), true);
emitter.emit(event_ctx, ToolEventStage::Begin).await;

manager
Expand Down
4 changes: 2 additions & 2 deletions codex-rs/core/src/tools/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ impl ToolCallRuntime {
Ok(Self::aborted_response(&call, secs))
},
res = async {
tracing::info!("waiting for tool gate");
tracing::trace!("waiting for tool gate");
readiness.wait_ready().await;
tracing::info!("tool gate released");
tracing::trace!("tool gate released");
let _guard = if supports_parallel {
Either::Left(lock.read().await)
} else {
Expand Down
17 changes: 17 additions & 0 deletions codex-rs/core/src/unified_exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,35 @@ pub(crate) struct UnifiedExecResponse {
pub original_token_count: Option<usize>,
}

pub(crate) fn build_shell_command(shell: &str, login: bool, command: &str) -> Vec<String> {
let shell_flag = if login { "-lc" } else { "-c" };
vec![
shell.to_string(),
shell_flag.to_string(),
command.to_string(),
]
}

#[derive(Default)]
pub(crate) struct UnifiedExecSessionManager {
next_session_id: AtomicI32,
sessions: Mutex<HashMap<i32, SessionEntry>>,
}

#[derive(Clone, Debug)]
pub(crate) struct StdinEvent {
pub input: String,
#[allow(dead_code)]
pub output: String,
}

struct SessionEntry {
session: session::UnifiedExecSession,
session_ref: Arc<Session>,
turn_ref: Arc<TurnContext>,
call_id: String,
command: String,
stdin_events: Vec<StdinEvent>,
cwd: PathBuf,
started_at: tokio::time::Instant,
}
Expand Down
Loading
Loading