mirror of
https://github.com/openai/codex.git
synced 2026-10-26 18:38:47 +00:00
+15








ba5b94287e
- [x] Add tool_suggest tool. - [x] Move chatgpt/src/connectors.rs and core/src/connectors.rs into a dedicated mod so that we have all the logic and global cache in one place. - [x] Update TUI app link view to support rendering the installation view for mcp elicitation. --------- Co-authored-by: Shaqayeq <shaqayeq@openai.com> Co-authored-by: Eric Traut <etraut@openai.com> Co-authored-by: pakrym-oai <pakrym@openai.com> Co-authored-by: Ahmed Ibrahim <aibrahim@openai.com> Co-authored-by: guinness-oai <guinness@openai.com> Co-authored-by: Eugene Brevdo <ebrevdo@users.noreply.github.com> Co-authored-by: Charlie Guo <cguo@openai.com> Co-authored-by: Fouad Matin <fouad@openai.com> Co-authored-by: Fouad Matin <169186268+fouad-openai@users.noreply.github.com> Co-authored-by: xl-openai <xl@openai.com> Co-authored-by: alexsong-oai <alexsong@openai.com> Co-authored-by: Owen Lin <owenlin0@gmail.com> Co-authored-by: sdcoffey <stevendcoffey@gmail.com> Co-authored-by: Codex <noreply@openai.com> Co-authored-by: Won Park <won@openai.com> Co-authored-by: Dylan Hurd <dylan.hurd@openai.com> Co-authored-by: celia-oai <celia@openai.com> Co-authored-by: gabec-openai <gabec@openai.com> Co-authored-by: joeytrasatti-openai <joey.trasatti@openai.com> Co-authored-by: Leo Shimonaka <leoshimo@openai.com> Co-authored-by: Rasmus Rygaard <rasmus@openai.com> Co-authored-by: maja-openai <163171781+maja-openai@users.noreply.github.com> Co-authored-by: pash-openai <pash@openai.com> Co-authored-by: Josh McKinney <joshka@openai.com>
120 lines
3.5 KiB
Rust
120 lines
3.5 KiB
Rust
pub mod code_mode;
|
|
pub(crate) mod code_mode_description;
|
|
pub mod context;
|
|
pub(crate) mod discoverable;
|
|
pub mod events;
|
|
pub(crate) mod handlers;
|
|
pub mod js_repl;
|
|
pub(crate) mod network_approval;
|
|
pub mod orchestrator;
|
|
pub mod parallel;
|
|
pub mod registry;
|
|
pub mod router;
|
|
pub mod runtimes;
|
|
pub mod sandboxing;
|
|
pub mod spec;
|
|
|
|
use crate::exec::ExecToolCallOutput;
|
|
use crate::truncate::TruncationPolicy;
|
|
use crate::truncate::formatted_truncate_text;
|
|
use crate::truncate::truncate_text;
|
|
pub use router::ToolRouter;
|
|
use serde::Serialize;
|
|
|
|
// Telemetry preview limits: keep log events smaller than model budgets.
|
|
pub(crate) const TELEMETRY_PREVIEW_MAX_BYTES: usize = 2 * 1024; // 2 KiB
|
|
pub(crate) const TELEMETRY_PREVIEW_MAX_LINES: usize = 64; // lines
|
|
pub(crate) const TELEMETRY_PREVIEW_TRUNCATION_NOTICE: &str =
|
|
"[... telemetry preview truncated ...]";
|
|
|
|
/// Format the combined exec output for sending back to the model.
|
|
/// Includes exit code and duration metadata; truncates large bodies safely.
|
|
pub fn format_exec_output_for_model_structured(
|
|
exec_output: &ExecToolCallOutput,
|
|
truncation_policy: TruncationPolicy,
|
|
) -> String {
|
|
let ExecToolCallOutput {
|
|
exit_code,
|
|
duration,
|
|
..
|
|
} = exec_output;
|
|
|
|
#[derive(Serialize)]
|
|
struct ExecMetadata {
|
|
exit_code: i32,
|
|
duration_seconds: f32,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
struct ExecOutput<'a> {
|
|
output: &'a str,
|
|
metadata: ExecMetadata,
|
|
}
|
|
|
|
// round to 1 decimal place
|
|
let duration_seconds = ((duration.as_secs_f32()) * 10.0).round() / 10.0;
|
|
|
|
let formatted_output = format_exec_output_str(exec_output, truncation_policy);
|
|
|
|
let payload = ExecOutput {
|
|
output: &formatted_output,
|
|
metadata: ExecMetadata {
|
|
exit_code: *exit_code,
|
|
duration_seconds,
|
|
},
|
|
};
|
|
|
|
#[expect(clippy::expect_used)]
|
|
serde_json::to_string(&payload).expect("serialize ExecOutput")
|
|
}
|
|
|
|
pub fn format_exec_output_for_model_freeform(
|
|
exec_output: &ExecToolCallOutput,
|
|
truncation_policy: TruncationPolicy,
|
|
) -> String {
|
|
// round to 1 decimal place
|
|
let duration_seconds = ((exec_output.duration.as_secs_f32()) * 10.0).round() / 10.0;
|
|
|
|
let content = build_content_with_timeout(exec_output);
|
|
|
|
let total_lines = content.lines().count();
|
|
|
|
let formatted_output = truncate_text(&content, truncation_policy);
|
|
|
|
let mut sections = Vec::new();
|
|
|
|
sections.push(format!("Exit code: {}", exec_output.exit_code));
|
|
sections.push(format!("Wall time: {duration_seconds} seconds"));
|
|
if total_lines != formatted_output.lines().count() {
|
|
sections.push(format!("Total output lines: {total_lines}"));
|
|
}
|
|
|
|
sections.push("Output:".to_string());
|
|
sections.push(formatted_output);
|
|
|
|
sections.join("\n")
|
|
}
|
|
|
|
pub fn format_exec_output_str(
|
|
exec_output: &ExecToolCallOutput,
|
|
truncation_policy: TruncationPolicy,
|
|
) -> String {
|
|
let content = build_content_with_timeout(exec_output);
|
|
|
|
// Truncate for model consumption before serialization.
|
|
formatted_truncate_text(&content, truncation_policy)
|
|
}
|
|
|
|
/// Extracts exec output content and prepends a timeout message if the command timed out.
|
|
fn build_content_with_timeout(exec_output: &ExecToolCallOutput) -> String {
|
|
if exec_output.timed_out {
|
|
format!(
|
|
"command timed out after {} milliseconds\n{}",
|
|
exec_output.duration.as_millis(),
|
|
exec_output.aggregated_output.text
|
|
)
|
|
} else {
|
|
exec_output.aggregated_output.text.clone()
|
|
}
|
|
}
|