mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
172b2218a5
## Why `TurnContext` had accumulated dead fields and cached projections of values already owned by its per-turn `Config` or `ModelInfo`. Keeping both copies made ownership unclear and allowed artificial split-brain states, such as a compatibility hash differing from the model metadata it came from. `Prompt` similarly carried a write-only personality after personality selection had already been materialized into its base instructions. This makes the canonical owner explicit: configuration-backed values come from `config`, model-derived values come from `model_info`, and prompts contain only data consumed by request construction. ## What changed - Remove the unused `ghost_snapshot`, `codex_self_exe`, and `thread_source` fields. - Remove duplicate `comp_hash`, `truncation_policy`, `features`, `shell_environment_policy`, `codex_linux_sandbox_exe`, `compact_prompt`, and `tool_mode` fields. - Read those values directly from `TurnContext::config` or `TurnContext::model_info` at their consumers. - Remove the write-only `Prompt::personality` field and its constructor assignments. - Preserve review-turn inheritance of the parent turn's shell policy, Linux sandbox executable, and compact prompt through the review config. ## Testing - `cargo check -p codex-core --tests`
45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
use codex_protocol::exec_output::ExecToolCallOutput;
|
|
use codex_protocol::models::ResponseItem;
|
|
|
|
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()
|
|
}
|
|
|
|
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;
|