Base: codex-main originale (prima del fork aKode)
This commit is contained in:
48
codex-rs/core/src/user_shell_command.rs
Normal file
48
codex-rs/core/src/user_shell_command.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use codex_protocol::exec_output::ExecToolCallOutput;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
#[cfg(test)]
|
||||
use codex_protocol_test_support::ContentItemTestExt;
|
||||
|
||||
use crate::context::ContextualUserFragment;
|
||||
use crate::context::UserShellCommand;
|
||||
use crate::session::turn_context::TurnContext;
|
||||
use crate::tools::format_exec_output_str;
|
||||
|
||||
fn user_shell_command_fragment(
|
||||
command: &str,
|
||||
exec_output: &ExecToolCallOutput,
|
||||
turn_context: &TurnContext,
|
||||
) -> UserShellCommand {
|
||||
let output = format_exec_output_str(
|
||||
exec_output,
|
||||
turn_context.model_info().truncation_policy.into(),
|
||||
);
|
||||
UserShellCommand::new(command, exec_output.exit_code, exec_output.duration, output)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn format_user_shell_command_record(
|
||||
command: &str,
|
||||
exec_output: &ExecToolCallOutput,
|
||||
turn_context: &TurnContext,
|
||||
) -> String {
|
||||
user_shell_command_fragment(command, exec_output, turn_context)
|
||||
.render()
|
||||
.expect_text()
|
||||
}
|
||||
|
||||
pub fn user_shell_command_record_item(
|
||||
command: &str,
|
||||
exec_output: &ExecToolCallOutput,
|
||||
turn_context: &TurnContext,
|
||||
) -> ResponseItem {
|
||||
ContextualUserFragment::into(user_shell_command_fragment(
|
||||
command,
|
||||
exec_output,
|
||||
turn_context,
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "user_shell_command_tests.rs"]
|
||||
mod tests;
|
||||
Reference in New Issue
Block a user