Standardize shell execution on unified exec (#39757)

## What changed

- Remove the legacy `shell_command` handler and runtime, leaving `exec_command`
  and `write_stdin` as the shell execution tools.
- Treat legacy `shell_command` model metadata as `unified_exec`, and normalize
  legacy user opt-outs so they do not disable command execution. Managed feature
  requirements and `shell_tool` can still disable it.
- Preserve shell approvals, sandboxing, zsh-fork support, and output truncation
  through the unified execution path.

## Testing

- Cover legacy configuration and model-metadata compatibility.
- Exercise unified shell execution, approvals, truncation, and `apply_patch`
  serialization across the app-server and core test suites.

GitOrigin-RevId: 5c2fd6164fc3519cdae4944cb9db276b8467311c
This commit is contained in:
jif authored and copyberry committed 2026-08-20 17:46:05 +00:00
1 parent d0cc662b8c
commit 8a40095ea3
116 files changed
+1338 -4711

No files matched your search

+1 -54
View File
@@ -26,7 +26,6 @@ use codex_protocol::protocol::FileChange;
use codex_protocol::protocol::PatchApplyStatus;
use codex_protocol::protocol::TurnDiffEvent;
use codex_shell_command::parse_command::parse_command;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use codex_utils_string::truncate_middle_with_token_budget;
use std::collections::HashMap;
@@ -180,13 +179,6 @@ async fn emit_exec_command_begin(ctx: ToolEventCtx<'_>, exec_input: &ExecCommand
}
// Concrete, allocation-free emitter: avoid trait objects and boxed futures.
pub(crate) enum ToolEmitter {
Shell {
command: Vec<String>,
cwd: PathUri,
source: ExecCommandSource,
parsed_cmd: Vec<ParsedCommand>,
plugin_attribution: Option<PluginCommandAttribution>,
},
ApplyPatch {
changes: HashMap<PathBuf, FileChange>,
auto_approved: bool,
@@ -203,22 +195,6 @@ pub(crate) enum ToolEmitter {
}
impl ToolEmitter {
pub fn shell(
command: Vec<String>,
cwd: AbsolutePathBuf,
source: ExecCommandSource,
plugin_attribution: Option<PluginCommandAttribution>,
) -> Self {
let parsed_cmd = parse_command(&command);
Self::Shell {
command,
cwd: PathUri::from_abs_path(&cwd),
source,
parsed_cmd,
plugin_attribution,
}
}
pub fn apply_patch_for_environment(
changes: HashMap<PathBuf, FileChange>,
auto_approved: bool,
@@ -251,33 +227,6 @@ impl ToolEmitter {
pub async fn emit(&self, ctx: ToolEventCtx<'_>, stage: ToolEventStage<'_>) {
match (self, stage) {
(
Self::Shell {
command,
cwd,
source,
parsed_cmd,
plugin_attribution,
..
},
stage,
) => {
emit_exec_stage(
ctx,
ExecCommandInput::new(
command,
cwd,
parsed_cmd,
*source,
/*interaction_input*/ None,
/*process_id*/ None,
plugin_attribution.as_ref(),
),
stage,
)
.await;
}
(
Self::ApplyPatch {
changes,
@@ -491,9 +440,7 @@ impl ToolEmitter {
// TODO: We should add a new ToolError variant for user-declined approvals.
let normalized = if msg == "rejected by user" {
match self {
Self::Shell { .. } | Self::UnifiedExec { .. } => {
"exec command rejected by user".to_string()
}
Self::UnifiedExec { .. } => "exec command rejected by user".to_string(),
Self::ApplyPatch { .. } => "patch rejected by user".to_string(),
}
} else {