mirror of
https://github.com/openai/codex.git
synced 2026-11-05 20:10:33 +00:00
user shell command filtering
This commit is contained in:
@@ -15,6 +15,12 @@ use uuid::Uuid;
|
||||
|
||||
use crate::user_instructions::UserInstructions;
|
||||
|
||||
fn is_user_shell_command_prefix(text: &str) -> bool {
|
||||
let trimmed = text.trim_start();
|
||||
let lowered = trimmed.to_ascii_lowercase();
|
||||
lowered.starts_with("<user_shell_command>") || lowered.starts_with("<user_shell_command_output>")
|
||||
}
|
||||
|
||||
fn is_session_prefix(text: &str) -> bool {
|
||||
let trimmed = text.trim_start();
|
||||
let lowered = trimmed.to_ascii_lowercase();
|
||||
@@ -31,7 +37,7 @@ fn parse_user_message(message: &[ContentItem]) -> Option<UserMessageItem> {
|
||||
for content_item in message.iter() {
|
||||
match content_item {
|
||||
ContentItem::InputText { text } => {
|
||||
if is_session_prefix(text) {
|
||||
if is_session_prefix(text) || is_user_shell_command_prefix(text) {
|
||||
return None;
|
||||
}
|
||||
content.push(UserInput::Text { text: text.clone() });
|
||||
@@ -42,7 +48,7 @@ fn parse_user_message(message: &[ContentItem]) -> Option<UserMessageItem> {
|
||||
});
|
||||
}
|
||||
ContentItem::OutputText { text } => {
|
||||
if is_session_prefix(text) {
|
||||
if is_session_prefix(text) || is_user_shell_command_prefix(text) {
|
||||
return None;
|
||||
}
|
||||
warn!("Output text in user message: {}", text);
|
||||
|
||||
@@ -95,10 +95,9 @@ impl SessionTask for UserShellCommandTask {
|
||||
}
|
||||
|
||||
let call_id = Uuid::new_v4().to_string();
|
||||
let cwd_display = turn_context.cwd.to_string_lossy();
|
||||
let raw_command = self.command.clone();
|
||||
let command_text = format!(
|
||||
"<user_shell_command cwd=\"{cwd_display}\">\n{raw_command}\n</user_shell_command>"
|
||||
"<user_shell_command>\n{raw_command}\n</user_shell_command>"
|
||||
);
|
||||
let command_items = [build_user_message(command_text)];
|
||||
session
|
||||
@@ -153,7 +152,7 @@ impl SessionTask for UserShellCommandTask {
|
||||
None => {
|
||||
let aborted_message = "command aborted by user".to_string();
|
||||
let aborted_text =
|
||||
format!("<user_shell_output>\n{aborted_message}\n</user_shell_output>");
|
||||
format!("<user_shell_command_output>\n{aborted_message}\n</user_shell_command_output>");
|
||||
let output_items = [build_user_message(aborted_text)];
|
||||
session
|
||||
.record_conversation_items(turn_context.as_ref(), &output_items)
|
||||
@@ -191,7 +190,7 @@ impl SessionTask for UserShellCommandTask {
|
||||
|
||||
let output_payload = format_exec_output_for_model(&output);
|
||||
let output_text =
|
||||
format!("<user_shell_output>\n{output_payload}\n</user_shell_output>");
|
||||
format!("<user_shell_command_output>\n{output_payload}\n</user_shell_command_output>");
|
||||
let output_items = [build_user_message(output_text)];
|
||||
session
|
||||
.record_conversation_items(turn_context.as_ref(), &output_items)
|
||||
@@ -224,7 +223,7 @@ impl SessionTask for UserShellCommandTask {
|
||||
.await;
|
||||
let output_payload = format_exec_output_for_model(&exec_output);
|
||||
let output_text =
|
||||
format!("<user_shell_output>\n{output_payload}\n</user_shell_output>");
|
||||
format!("<user_shell_command_output>\n{output_payload}\n</user_shell_command_output>");
|
||||
let output_items = [build_user_message(output_text)];
|
||||
session
|
||||
.record_conversation_items(turn_context.as_ref(), &output_items)
|
||||
|
||||
Reference in New Issue
Block a user