mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Attribute command executions to trusted plugin scripts (#35020)
## What changed - Resolve shell and unified-exec commands against the trusted plugin roots loaded for each turn. - Add optional `pluginId` and safe plugin-relative `scriptPath` fields to command execution items and legacy execution events, and propagate them through app-server notifications. - Include the attribution in command execution analytics while rejecting absolute, unsafe, and unattributed script paths. ## Testing - Cover attribution for cached curated and remote plugin scripts from command execution through core and app-server events. - Verify analytics serialization and unsafe-path filtering. GitOrigin-RevId: 02fac3a233284ccfc6642fa502a95f1881dba83d
This commit is contained in:
1 parent
5bdbd3ee90
commit
84fa68b429
52 files changed
+858
-32
No files matched your search
@@ -4,6 +4,7 @@ use crate::session::turn_context::TurnContext;
|
||||
use crate::tools::context::SharedTurnDiffTracker;
|
||||
use crate::tools::sandboxing::ToolError;
|
||||
use codex_apply_patch::AppliedPatchDelta;
|
||||
use codex_core_plugins::PluginCommandAttribution;
|
||||
use codex_protocol::error::CodexErrorDetails;
|
||||
use codex_protocol::error::SandboxErr;
|
||||
use codex_protocol::exec_output::ExecToolCallOutput;
|
||||
@@ -99,26 +100,21 @@ fn tracker_update_for_known_delta<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn emit_exec_command_begin(
|
||||
ctx: ToolEventCtx<'_>,
|
||||
command: &[String],
|
||||
cwd: &PathUri,
|
||||
parsed_cmd: &[ParsedCommand],
|
||||
source: ExecCommandSource,
|
||||
interaction_input: Option<String>,
|
||||
process_id: Option<&str>,
|
||||
) {
|
||||
async fn emit_exec_command_begin(ctx: ToolEventCtx<'_>, exec_input: &ExecCommandInput<'_>) {
|
||||
let (plugin_id, script_path) = plugin_attribution_fields(exec_input.plugin_attribution);
|
||||
ctx.session
|
||||
.emit_turn_item_started(
|
||||
ctx.turn,
|
||||
&TurnItem::CommandExecution(CommandExecutionItem {
|
||||
id: ctx.call_id.to_string(),
|
||||
process_id: process_id.map(str::to_owned),
|
||||
command: command.to_vec(),
|
||||
cwd: cwd.clone(),
|
||||
parsed_cmd: parsed_cmd.to_vec(),
|
||||
source,
|
||||
interaction_input,
|
||||
plugin_id,
|
||||
script_path,
|
||||
process_id: exec_input.process_id.map(str::to_owned),
|
||||
command: exec_input.command.to_vec(),
|
||||
cwd: exec_input.cwd.clone(),
|
||||
parsed_cmd: exec_input.parsed_cmd.to_vec(),
|
||||
source: exec_input.source,
|
||||
interaction_input: exec_input.interaction_input.map(str::to_owned),
|
||||
status: CommandExecutionStatus::InProgress,
|
||||
stdout: None,
|
||||
stderr: None,
|
||||
@@ -137,6 +133,7 @@ pub(crate) enum ToolEmitter {
|
||||
cwd: PathUri,
|
||||
source: ExecCommandSource,
|
||||
parsed_cmd: Vec<ParsedCommand>,
|
||||
plugin_attribution: Option<PluginCommandAttribution>,
|
||||
},
|
||||
ApplyPatch {
|
||||
changes: HashMap<PathBuf, FileChange>,
|
||||
@@ -149,17 +146,24 @@ pub(crate) enum ToolEmitter {
|
||||
source: ExecCommandSource,
|
||||
parsed_cmd: Vec<ParsedCommand>,
|
||||
process_id: Option<String>,
|
||||
plugin_attribution: Option<PluginCommandAttribution>,
|
||||
},
|
||||
}
|
||||
|
||||
impl ToolEmitter {
|
||||
pub fn shell(command: Vec<String>, cwd: AbsolutePathBuf, source: ExecCommandSource) -> Self {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +184,7 @@ impl ToolEmitter {
|
||||
cwd: PathUri,
|
||||
source: ExecCommandSource,
|
||||
process_id: Option<String>,
|
||||
plugin_attribution: Option<PluginCommandAttribution>,
|
||||
) -> Self {
|
||||
let parsed_cmd = parse_command(command);
|
||||
Self::UnifiedExec {
|
||||
@@ -188,6 +193,7 @@ impl ToolEmitter {
|
||||
source,
|
||||
parsed_cmd,
|
||||
process_id,
|
||||
plugin_attribution,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +205,7 @@ impl ToolEmitter {
|
||||
cwd,
|
||||
source,
|
||||
parsed_cmd,
|
||||
plugin_attribution,
|
||||
..
|
||||
},
|
||||
stage,
|
||||
@@ -206,8 +213,13 @@ impl ToolEmitter {
|
||||
emit_exec_stage(
|
||||
ctx,
|
||||
ExecCommandInput::new(
|
||||
command, cwd, parsed_cmd, *source, /*interaction_input*/ None,
|
||||
command,
|
||||
cwd,
|
||||
parsed_cmd,
|
||||
*source,
|
||||
/*interaction_input*/ None,
|
||||
/*process_id*/ None,
|
||||
plugin_attribution.as_ref(),
|
||||
),
|
||||
stage,
|
||||
)
|
||||
@@ -329,6 +341,7 @@ impl ToolEmitter {
|
||||
source,
|
||||
parsed_cmd,
|
||||
process_id,
|
||||
plugin_attribution,
|
||||
},
|
||||
stage,
|
||||
) => {
|
||||
@@ -341,6 +354,7 @@ impl ToolEmitter {
|
||||
*source,
|
||||
/*interaction_input*/ None,
|
||||
process_id.as_deref(),
|
||||
plugin_attribution.as_ref(),
|
||||
),
|
||||
stage,
|
||||
)
|
||||
@@ -454,6 +468,7 @@ struct ExecCommandInput<'a> {
|
||||
source: ExecCommandSource,
|
||||
interaction_input: Option<&'a str>,
|
||||
process_id: Option<&'a str>,
|
||||
plugin_attribution: Option<&'a PluginCommandAttribution>,
|
||||
}
|
||||
|
||||
impl<'a> ExecCommandInput<'a> {
|
||||
@@ -464,6 +479,7 @@ impl<'a> ExecCommandInput<'a> {
|
||||
source: ExecCommandSource,
|
||||
interaction_input: Option<&'a str>,
|
||||
process_id: Option<&'a str>,
|
||||
plugin_attribution: Option<&'a PluginCommandAttribution>,
|
||||
) -> Self {
|
||||
Self {
|
||||
command,
|
||||
@@ -472,6 +488,7 @@ impl<'a> ExecCommandInput<'a> {
|
||||
source,
|
||||
interaction_input,
|
||||
process_id,
|
||||
plugin_attribution,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -493,16 +510,7 @@ async fn emit_exec_stage(
|
||||
) {
|
||||
match stage {
|
||||
ToolEventStage::Begin => {
|
||||
emit_exec_command_begin(
|
||||
ctx,
|
||||
exec_input.command,
|
||||
exec_input.cwd,
|
||||
exec_input.parsed_cmd,
|
||||
exec_input.source,
|
||||
exec_input.interaction_input.map(str::to_owned),
|
||||
exec_input.process_id,
|
||||
)
|
||||
.await;
|
||||
emit_exec_command_begin(ctx, &exec_input).await;
|
||||
}
|
||||
ToolEventStage::Success { output, .. }
|
||||
| ToolEventStage::Failure(ToolEventFailure::Output(output)) => {
|
||||
@@ -558,11 +566,14 @@ async fn emit_exec_end(
|
||||
exec_input: ExecCommandInput<'_>,
|
||||
exec_result: ExecCommandResult,
|
||||
) {
|
||||
let (plugin_id, script_path) = plugin_attribution_fields(exec_input.plugin_attribution);
|
||||
ctx.session
|
||||
.emit_turn_item_completed(
|
||||
ctx.turn,
|
||||
TurnItem::CommandExecution(CommandExecutionItem {
|
||||
id: ctx.call_id.to_string(),
|
||||
plugin_id,
|
||||
script_path,
|
||||
process_id: exec_input.process_id.map(str::to_owned),
|
||||
command: exec_input.command.to_vec(),
|
||||
cwd: exec_input.cwd.clone(),
|
||||
@@ -581,6 +592,14 @@ async fn emit_exec_end(
|
||||
.await;
|
||||
}
|
||||
|
||||
fn plugin_attribution_fields(
|
||||
attribution: Option<&PluginCommandAttribution>,
|
||||
) -> (Option<String>, Option<String>) {
|
||||
attribution
|
||||
.map(PluginCommandAttribution::serialized_fields)
|
||||
.unzip()
|
||||
}
|
||||
|
||||
async fn emit_patch_end(
|
||||
ctx: ToolEventCtx<'_>,
|
||||
changes: HashMap<PathBuf, FileChange>,
|
||||
|
||||
Reference in new issue
Block a user