Skip to content

Commit da983c1

Browse files
authored
feat: add is-mutating detection for shell command handler (#7729)
1 parent c2bdee0 commit da983c1

File tree

1 file changed

+14
-0
lines changed
  • codex-rs/core/src/tools/handlers

1 file changed

+14
-0
lines changed

codex-rs/core/src/tools/handlers/shell.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ impl ToolHandler for ShellCommandHandler {
148148
matches!(payload, ToolPayload::Function { .. })
149149
}
150150

151+
fn is_mutating(&self, invocation: &ToolInvocation) -> bool {
152+
let ToolPayload::Function { arguments } = &invocation.payload else {
153+
return true;
154+
};
155+
156+
serde_json::from_str::<ShellCommandToolCallParams>(arguments)
157+
.map(|params| {
158+
let shell = invocation.session.user_shell();
159+
let command = shell.derive_exec_args(&params.command, params.login.unwrap_or(true));
160+
!is_known_safe_command(&command)
161+
})
162+
.unwrap_or(true)
163+
}
164+
151165
async fn handle(&self, invocation: ToolInvocation) -> Result<ToolOutput, FunctionCallError> {
152166
let ToolInvocation {
153167
session,

0 commit comments

Comments
 (0)