mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Remove legacy turn context environment fields
Switch TurnContext to carry only the selected environment list and explicit-selection marker. Preserve the no-list rollout path by representing the default environment internally with no environment id while keeping multi-environment tool rendering disabled unless explicit selections are present. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -32,10 +32,10 @@ pub(crate) struct ApplyPatchRuntimeInvocation {
|
||||
|
||||
pub(crate) async fn apply_patch(
|
||||
turn_context: &TurnContext,
|
||||
cwd: &codex_utils_absolute_path::AbsolutePathBuf,
|
||||
file_system_sandbox_policy: &FileSystemSandboxPolicy,
|
||||
action: ApplyPatchAction,
|
||||
) -> InternalApplyPatchInvocation {
|
||||
let cwd = &action.cwd;
|
||||
match assess_patch_safety(
|
||||
&action,
|
||||
turn_context.approval_policy.value(),
|
||||
|
||||
@@ -127,8 +127,9 @@ impl EnvironmentContext {
|
||||
}
|
||||
|
||||
pub(crate) fn from_turn_context(turn_context: &TurnContext, shell: &Shell) -> Self {
|
||||
let cwd = turn_context.default_environment_cwd();
|
||||
Self::new_with_environments(
|
||||
Some(turn_context.cwd.to_path_buf()),
|
||||
Some(cwd.to_path_buf()),
|
||||
Self::environments_from_turn_context(turn_context),
|
||||
shell.name().to_string(),
|
||||
turn_context.current_date.clone(),
|
||||
@@ -201,19 +202,21 @@ impl EnvironmentContext {
|
||||
if !turn_context.tools_config.multi_environment_tools {
|
||||
return None;
|
||||
}
|
||||
let environments = turn_context.environments.as_ref()?;
|
||||
if environments.is_empty() {
|
||||
if turn_context.environments.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(
|
||||
environments
|
||||
turn_context
|
||||
.environments
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, environment)| EnvironmentContextEnvironment {
|
||||
id: environment.environment_id.clone(),
|
||||
cwd: environment.cwd.to_path_buf(),
|
||||
primary: index == 0,
|
||||
.filter_map(|(index, environment)| {
|
||||
Some(EnvironmentContextEnvironment {
|
||||
id: environment.environment_id.clone()?,
|
||||
cwd: environment.cwd.to_path_buf(),
|
||||
primary: index == 0,
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
|
||||
@@ -587,7 +587,7 @@ async fn run_review_on_session(
|
||||
.submit(Op::UserTurn {
|
||||
environments: None,
|
||||
items: prompt_items.items,
|
||||
cwd: params.parent_turn.cwd.to_path_buf(),
|
||||
cwd: params.parent_turn.default_environment_cwd().to_path_buf(),
|
||||
approval_policy: AskForApproval::Never,
|
||||
approvals_reviewer: None,
|
||||
sandbox_policy: SandboxPolicy::new_read_only_policy(),
|
||||
|
||||
@@ -28,6 +28,7 @@ use codex_protocol::protocol::HookRunSummary;
|
||||
use codex_protocol::protocol::HookSource;
|
||||
use codex_protocol::protocol::HookStartedEvent;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::context::ContextualUserFragment;
|
||||
@@ -37,6 +38,10 @@ use crate::session::session::Session;
|
||||
use crate::session::turn_context::TurnContext;
|
||||
use crate::tools::sandboxing::PermissionRequestPayload;
|
||||
|
||||
fn default_environment_cwd(turn_context: &TurnContext) -> AbsolutePathBuf {
|
||||
turn_context.default_environment_cwd().clone()
|
||||
}
|
||||
|
||||
pub(crate) struct HookRuntimeOutcome {
|
||||
pub should_stop: bool,
|
||||
pub additional_contexts: Vec<String>,
|
||||
@@ -109,7 +114,7 @@ pub(crate) async fn run_pending_session_start_hooks(
|
||||
|
||||
let request = codex_hooks::SessionStartRequest {
|
||||
session_id: sess.conversation_id,
|
||||
cwd: turn_context.cwd.clone(),
|
||||
cwd: default_environment_cwd(turn_context),
|
||||
transcript_path: sess.hook_transcript_path().await,
|
||||
model: turn_context.model_info.slug.clone(),
|
||||
permission_mode: hook_permission_mode(turn_context),
|
||||
@@ -137,7 +142,7 @@ pub(crate) async fn run_pre_tool_use_hooks(
|
||||
let request = PreToolUseRequest {
|
||||
session_id: sess.conversation_id,
|
||||
turn_id: turn_context.sub_id.clone(),
|
||||
cwd: turn_context.cwd.clone(),
|
||||
cwd: default_environment_cwd(turn_context),
|
||||
transcript_path: sess.hook_transcript_path().await,
|
||||
model: turn_context.model_info.slug.clone(),
|
||||
permission_mode: hook_permission_mode(turn_context),
|
||||
@@ -170,7 +175,7 @@ pub(crate) async fn run_permission_request_hooks(
|
||||
let request = PermissionRequestRequest {
|
||||
session_id: sess.conversation_id,
|
||||
turn_id: turn_context.sub_id.clone(),
|
||||
cwd: turn_context.cwd.to_path_buf(),
|
||||
cwd: default_environment_cwd(turn_context),
|
||||
transcript_path: sess.hook_transcript_path().await,
|
||||
model: turn_context.model_info.slug.clone(),
|
||||
permission_mode: hook_permission_mode(turn_context),
|
||||
@@ -201,7 +206,7 @@ pub(crate) async fn run_post_tool_use_hooks(
|
||||
let request = PostToolUseRequest {
|
||||
session_id: sess.conversation_id,
|
||||
turn_id: turn_context.sub_id.clone(),
|
||||
cwd: turn_context.cwd.clone(),
|
||||
cwd: default_environment_cwd(turn_context),
|
||||
transcript_path: sess.hook_transcript_path().await,
|
||||
model: turn_context.model_info.slug.clone(),
|
||||
permission_mode: hook_permission_mode(turn_context),
|
||||
@@ -226,7 +231,7 @@ pub(crate) async fn run_user_prompt_submit_hooks(
|
||||
let request = UserPromptSubmitRequest {
|
||||
session_id: sess.conversation_id,
|
||||
turn_id: turn_context.sub_id.clone(),
|
||||
cwd: turn_context.cwd.clone(),
|
||||
cwd: default_environment_cwd(turn_context),
|
||||
transcript_path: sess.hook_transcript_path().await,
|
||||
model: turn_context.model_info.slug.clone(),
|
||||
permission_mode: hook_permission_mode(turn_context),
|
||||
|
||||
@@ -114,7 +114,11 @@ async fn build_uploaded_local_argument_value(
|
||||
index: Option<usize>,
|
||||
file_path: &str,
|
||||
) -> Result<JsonValue, String> {
|
||||
let resolved_path = turn_context.resolve_path(Some(file_path.to_string()));
|
||||
let tool_environment = turn_context
|
||||
.default_environment()
|
||||
.ok_or_else(|| "file uploads are unavailable in this session".to_string())?;
|
||||
let resolved_path =
|
||||
turn_context.resolve_path_for_environment(&tool_environment, Some(file_path.to_string()));
|
||||
let Some(auth) = auth else {
|
||||
return Err(
|
||||
"ChatGPT auth is required to upload local files for Codex Apps tools".to_string(),
|
||||
@@ -315,7 +319,9 @@ mod tests {
|
||||
tokio::fs::write(&local_path, b"hello")
|
||||
.await
|
||||
.expect("write local file");
|
||||
turn_context.cwd = AbsolutePathBuf::try_from(dir.path()).expect("absolute path");
|
||||
turn_context.set_default_environment_cwd_for_test(
|
||||
AbsolutePathBuf::try_from(dir.path()).expect("absolute path"),
|
||||
);
|
||||
|
||||
let mut config = (*turn_context.config).clone();
|
||||
config.chatgpt_base_url = format!("{}/backend-api", server.uri());
|
||||
@@ -397,7 +403,9 @@ mod tests {
|
||||
tokio::fs::write(&local_path, b"hello")
|
||||
.await
|
||||
.expect("write local file");
|
||||
turn_context.cwd = AbsolutePathBuf::try_from(dir.path()).expect("absolute path");
|
||||
turn_context.set_default_environment_cwd_for_test(
|
||||
AbsolutePathBuf::try_from(dir.path()).expect("absolute path"),
|
||||
);
|
||||
|
||||
let mut config = (*turn_context.config).clone();
|
||||
config.chatgpt_base_url = format!("{}/backend-api", server.uri());
|
||||
@@ -512,7 +520,9 @@ mod tests {
|
||||
tokio::fs::write(dir.path().join("two.csv"), b"two")
|
||||
.await
|
||||
.expect("write second local file");
|
||||
turn_context.cwd = AbsolutePathBuf::try_from(dir.path()).expect("absolute path");
|
||||
turn_context.set_default_environment_cwd_for_test(
|
||||
AbsolutePathBuf::try_from(dir.path()).expect("absolute path"),
|
||||
);
|
||||
|
||||
let mut config = (*turn_context.config).clone();
|
||||
config.chatgpt_base_url = format!("{}/backend-api", server.uri());
|
||||
@@ -624,7 +634,9 @@ mod tests {
|
||||
tokio::fs::write(&local_path, b"hello")
|
||||
.await
|
||||
.expect("write local file");
|
||||
turn_context.cwd = AbsolutePathBuf::try_from(dir.path()).expect("absolute path");
|
||||
turn_context.set_default_environment_cwd_for_test(
|
||||
AbsolutePathBuf::try_from(dir.path()).expect("absolute path"),
|
||||
);
|
||||
|
||||
let mut config = (*turn_context.config).clone();
|
||||
config.chatgpt_base_url = format!("{}/backend-api", server.uri());
|
||||
|
||||
@@ -518,10 +518,13 @@ async fn augment_mcp_tool_request_meta_with_sandbox_state(
|
||||
return Ok(meta);
|
||||
}
|
||||
|
||||
let tool_environment = turn_context
|
||||
.default_environment()
|
||||
.ok_or_else(|| anyhow::anyhow!("MCP sandbox state is unavailable in this session"))?;
|
||||
let sandbox_state = serde_json::to_value(SandboxState {
|
||||
sandbox_policy: turn_context.sandbox_policy.get().clone(),
|
||||
codex_linux_sandbox_exe: turn_context.codex_linux_sandbox_exe.clone(),
|
||||
sandbox_cwd: turn_context.cwd.to_path_buf(),
|
||||
sandbox_cwd: tool_environment.cwd.to_path_buf(),
|
||||
use_legacy_landlock: turn_context.features.use_legacy_landlock(),
|
||||
})?;
|
||||
|
||||
|
||||
@@ -1321,7 +1321,7 @@ async fn maybe_persist_mcp_tool_approval_writes_project_config_for_project_serve
|
||||
.build()
|
||||
.await
|
||||
.expect("load project config");
|
||||
turn_context.cwd = config.cwd.clone();
|
||||
turn_context.set_default_environment_cwd_for_test(config.cwd.clone());
|
||||
turn_context.config = Arc::new(config);
|
||||
let key = McpToolApprovalKey {
|
||||
server: "docs".to_string(),
|
||||
|
||||
@@ -84,20 +84,24 @@ fn shell_command_for_invocation(invocation: &ToolInvocation) -> Option<(Vec<Stri
|
||||
) {
|
||||
(None, "shell") => serde_json::from_str::<ShellToolCallParams>(arguments)
|
||||
.ok()
|
||||
.map(|params| {
|
||||
(
|
||||
params.command,
|
||||
invocation.turn.resolve_path(params.workdir).to_path_buf(),
|
||||
)
|
||||
.and_then(|params| {
|
||||
let workdir = resolve_tool_workdir(
|
||||
invocation,
|
||||
params.environment_id.as_deref(),
|
||||
params.workdir,
|
||||
)?;
|
||||
Some((params.command, workdir))
|
||||
}),
|
||||
(None, "shell_command") => serde_json::from_str::<ShellCommandToolCallParams>(arguments)
|
||||
.ok()
|
||||
.map(|params| {
|
||||
.and_then(|params| {
|
||||
let workdir = resolve_tool_workdir(
|
||||
invocation,
|
||||
params.environment_id.as_deref(),
|
||||
params.workdir,
|
||||
)?;
|
||||
if !invocation.turn.tools_config.allow_login_shell && params.login == Some(true) {
|
||||
return (
|
||||
Vec::new(),
|
||||
invocation.turn.resolve_path(params.workdir).to_path_buf(),
|
||||
);
|
||||
return Some((Vec::new(), workdir));
|
||||
}
|
||||
let use_login_shell = params
|
||||
.login
|
||||
@@ -106,14 +110,17 @@ fn shell_command_for_invocation(invocation: &ToolInvocation) -> Option<(Vec<Stri
|
||||
.session
|
||||
.user_shell()
|
||||
.derive_exec_args(¶ms.command, use_login_shell);
|
||||
(
|
||||
command,
|
||||
invocation.turn.resolve_path(params.workdir).to_path_buf(),
|
||||
)
|
||||
Some((command, workdir))
|
||||
}),
|
||||
(None, "exec_command") => serde_json::from_str::<ExecCommandArgs>(arguments)
|
||||
.ok()
|
||||
.and_then(|params| {
|
||||
let environment_id = tool_environment_id(arguments);
|
||||
let workdir = resolve_tool_workdir(
|
||||
invocation,
|
||||
environment_id.as_deref(),
|
||||
params.workdir.clone(),
|
||||
)?;
|
||||
let command = crate::tools::handlers::unified_exec::get_command(
|
||||
¶ms,
|
||||
invocation.session.user_shell(),
|
||||
@@ -121,15 +128,43 @@ fn shell_command_for_invocation(invocation: &ToolInvocation) -> Option<(Vec<Stri
|
||||
invocation.turn.tools_config.allow_login_shell,
|
||||
)
|
||||
.ok()?;
|
||||
Some((
|
||||
command,
|
||||
invocation.turn.resolve_path(params.workdir).to_path_buf(),
|
||||
))
|
||||
Some((command, workdir))
|
||||
}),
|
||||
(Some(_), _) | (None, _) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn tool_environment_id(arguments: &str) -> Option<String> {
|
||||
let value: serde_json::Value = serde_json::from_str(arguments).ok()?;
|
||||
value
|
||||
.get("environment_id")
|
||||
.or_else(|| value.get("environmentId"))
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.map(ToString::to_string)
|
||||
}
|
||||
|
||||
fn resolve_tool_workdir(
|
||||
invocation: &ToolInvocation,
|
||||
environment_id: Option<&str>,
|
||||
workdir: Option<String>,
|
||||
) -> Option<PathBuf> {
|
||||
let requested_environment_id = invocation
|
||||
.turn
|
||||
.tools_config
|
||||
.multi_environment_tools
|
||||
.then_some(environment_id)
|
||||
.flatten();
|
||||
let environment = invocation
|
||||
.turn
|
||||
.environment_for_tool(requested_environment_id)?;
|
||||
Some(
|
||||
invocation
|
||||
.turn
|
||||
.resolve_path_for_environment(&environment, workdir)
|
||||
.to_path_buf(),
|
||||
)
|
||||
}
|
||||
|
||||
fn get_memory_kind(path: String) -> Option<MemoriesUsageKind> {
|
||||
if path.contains("memories/MEMORY.md") {
|
||||
Some(MemoriesUsageKind::MemoryMd)
|
||||
|
||||
@@ -992,7 +992,8 @@ pub async fn review(
|
||||
sess.maybe_emit_unknown_model_warning_for_turn(turn_context.as_ref())
|
||||
.await;
|
||||
sess.refresh_mcp_servers_if_requested(&turn_context).await;
|
||||
match resolve_review_request(review_request, &turn_context.cwd) {
|
||||
let default_cwd = turn_context.default_environment_cwd();
|
||||
match resolve_review_request(review_request, default_cwd) {
|
||||
Ok(resolved) => {
|
||||
spawn_review_thread(
|
||||
Arc::clone(sess),
|
||||
|
||||
@@ -238,6 +238,15 @@ impl Session {
|
||||
guard.cancel();
|
||||
*guard = CancellationToken::new();
|
||||
}
|
||||
let (runtime_environment, runtime_cwd) = turn_context
|
||||
.default_environment()
|
||||
.map(|environment| (environment.environment, environment.cwd.to_path_buf()))
|
||||
.unwrap_or_else(|| {
|
||||
(
|
||||
Arc::new(Environment::default()),
|
||||
turn_context.config.cwd.to_path_buf(),
|
||||
)
|
||||
});
|
||||
let (refreshed_manager, cancel_token) = McpConnectionManager::new(
|
||||
&mcp_servers,
|
||||
store_mode,
|
||||
@@ -246,13 +255,7 @@ impl Session {
|
||||
turn_context.sub_id.clone(),
|
||||
self.get_tx_event(),
|
||||
turn_context.sandbox_policy.get().clone(),
|
||||
McpRuntimeEnvironment::new(
|
||||
turn_context
|
||||
.environment
|
||||
.clone()
|
||||
.unwrap_or_else(|| Arc::new(Environment::default())),
|
||||
turn_context.cwd.to_path_buf(),
|
||||
),
|
||||
McpRuntimeEnvironment::new(runtime_environment, runtime_cwd),
|
||||
config.codex_home.to_path_buf(),
|
||||
codex_apps_tools_cache_key(auth.as_ref()),
|
||||
tool_plugin_provenance,
|
||||
|
||||
@@ -2460,6 +2460,7 @@ impl Session {
|
||||
state.session_configuration.session_source.clone(),
|
||||
)
|
||||
};
|
||||
let default_cwd = turn_context.default_environment_cwd().clone();
|
||||
if let Some(model_switch_message) =
|
||||
crate::context_manager::updates::build_model_instructions_update_item(
|
||||
previous_turn_settings.as_ref(),
|
||||
@@ -2475,7 +2476,7 @@ impl Session {
|
||||
turn_context.approval_policy.value(),
|
||||
turn_context.config.approvals_reviewer,
|
||||
self.services.exec_policy.current().as_ref(),
|
||||
&turn_context.cwd,
|
||||
&default_cwd,
|
||||
turn_context
|
||||
.features
|
||||
.enabled(Feature::ExecPermissionApprovals),
|
||||
@@ -2596,7 +2597,7 @@ impl Session {
|
||||
contextual_user_sections.push(
|
||||
UserInstructions {
|
||||
text: user_instructions.to_string(),
|
||||
directory: turn_context.cwd.to_string_lossy().into_owned(),
|
||||
directory: default_cwd.to_string_lossy().into_owned(),
|
||||
}
|
||||
.render(),
|
||||
);
|
||||
|
||||
@@ -46,7 +46,7 @@ pub(super) async fn spawn_review_thread(
|
||||
)
|
||||
.with_web_search_config(/*web_search_config*/ None)
|
||||
.with_allow_login_shell(config.permissions.allow_login_shell)
|
||||
.with_has_environment(parent_turn_context.tools_config.has_environment)
|
||||
.with_has_environment(!parent_turn_context.environments.is_empty())
|
||||
.with_spawn_agent_usage_hint(config.multi_agent_v2.usage_hint_enabled)
|
||||
.with_spawn_agent_usage_hint_text(config.multi_agent_v2.usage_hint_text.clone())
|
||||
.with_hide_spawn_agent_metadata(config.multi_agent_v2.hide_spawn_agent_metadata)
|
||||
@@ -85,6 +85,12 @@ pub(super) async fn spawn_review_thread(
|
||||
.model_reasoning_summary
|
||||
.unwrap_or(model_info.default_reasoning_summary);
|
||||
let session_source = parent_turn_context.session_source.clone();
|
||||
let parent_tool_environment = parent_turn_context.default_environment();
|
||||
let review_cwd = parent_tool_environment.as_ref().map_or_else(
|
||||
|| parent_turn_context.config.cwd.clone(),
|
||||
|environment| environment.cwd.clone(),
|
||||
);
|
||||
per_turn_config.cwd = review_cwd.clone();
|
||||
|
||||
let per_turn_config = Arc::new(per_turn_config);
|
||||
let review_turn_id = sub_id.to_string();
|
||||
@@ -92,7 +98,7 @@ pub(super) async fn spawn_review_thread(
|
||||
sess.conversation_id.to_string(),
|
||||
&session_source,
|
||||
review_turn_id.clone(),
|
||||
parent_turn_context.cwd.clone(),
|
||||
review_cwd.clone(),
|
||||
parent_turn_context.sandbox_policy.get(),
|
||||
parent_turn_context.windows_sandbox_level,
|
||||
));
|
||||
@@ -109,8 +115,8 @@ pub(super) async fn spawn_review_thread(
|
||||
reasoning_effort,
|
||||
reasoning_summary,
|
||||
session_source,
|
||||
environment: parent_turn_context.environment.clone(),
|
||||
environments: parent_turn_context.environments.clone(),
|
||||
environment_selections_explicit: parent_turn_context.environment_selections_explicit,
|
||||
tools_config,
|
||||
features: parent_turn_context.features.clone(),
|
||||
ghost_snapshot: parent_turn_context.ghost_snapshot.clone(),
|
||||
@@ -129,7 +135,6 @@ pub(super) async fn spawn_review_thread(
|
||||
network: parent_turn_context.network.clone(),
|
||||
windows_sandbox_level: parent_turn_context.windows_sandbox_level,
|
||||
shell_environment_policy: parent_turn_context.shell_environment_policy.clone(),
|
||||
cwd: parent_turn_context.cwd.clone(),
|
||||
final_output_json_schema: None,
|
||||
codex_self_exe: parent_turn_context.codex_self_exe.clone(),
|
||||
codex_linux_sandbox_exe: parent_turn_context.codex_linux_sandbox_exe.clone(),
|
||||
|
||||
@@ -63,7 +63,7 @@ async fn record_initial_history_resumed_bare_turn_context_does_not_hydrate_previ
|
||||
let previous_context_item = TurnContextItem {
|
||||
turn_id: Some(turn_context.sub_id.clone()),
|
||||
trace_id: turn_context.trace_id.clone(),
|
||||
cwd: turn_context.cwd.to_path_buf(),
|
||||
cwd: turn_context.default_environment_cwd().to_path_buf(),
|
||||
environments: None,
|
||||
current_date: turn_context.current_date.clone(),
|
||||
timezone: turn_context.timezone.clone(),
|
||||
@@ -104,7 +104,7 @@ async fn record_initial_history_resumed_hydrates_previous_turn_settings_from_lif
|
||||
let mut previous_context_item = TurnContextItem {
|
||||
turn_id: Some(turn_context.sub_id.clone()),
|
||||
trace_id: turn_context.trace_id.clone(),
|
||||
cwd: turn_context.cwd.to_path_buf(),
|
||||
cwd: turn_context.default_environment_cwd().to_path_buf(),
|
||||
environments: None,
|
||||
current_date: turn_context.current_date.clone(),
|
||||
timezone: turn_context.timezone.clone(),
|
||||
@@ -900,7 +900,7 @@ async fn record_initial_history_resumed_turn_context_after_compaction_reestablis
|
||||
let previous_context_item = TurnContextItem {
|
||||
turn_id: Some(turn_context.sub_id.clone()),
|
||||
trace_id: turn_context.trace_id.clone(),
|
||||
cwd: turn_context.cwd.to_path_buf(),
|
||||
cwd: turn_context.default_environment_cwd().to_path_buf(),
|
||||
environments: None,
|
||||
current_date: turn_context.current_date.clone(),
|
||||
timezone: turn_context.timezone.clone(),
|
||||
@@ -977,7 +977,7 @@ async fn record_initial_history_resumed_turn_context_after_compaction_reestablis
|
||||
serde_json::to_value(Some(TurnContextItem {
|
||||
turn_id: Some(turn_context.sub_id.clone()),
|
||||
trace_id: turn_context.trace_id.clone(),
|
||||
cwd: turn_context.cwd.to_path_buf(),
|
||||
cwd: turn_context.default_environment_cwd().to_path_buf(),
|
||||
environments: None,
|
||||
current_date: turn_context.current_date.clone(),
|
||||
timezone: turn_context.timezone.clone(),
|
||||
@@ -1008,7 +1008,7 @@ async fn record_initial_history_resumed_aborted_turn_without_id_clears_active_tu
|
||||
let previous_context_item = TurnContextItem {
|
||||
turn_id: Some(turn_context.sub_id.clone()),
|
||||
trace_id: turn_context.trace_id.clone(),
|
||||
cwd: turn_context.cwd.to_path_buf(),
|
||||
cwd: turn_context.default_environment_cwd().to_path_buf(),
|
||||
environments: None,
|
||||
current_date: turn_context.current_date.clone(),
|
||||
timezone: turn_context.timezone.clone(),
|
||||
@@ -1122,7 +1122,7 @@ async fn record_initial_history_resumed_unmatched_abort_preserves_active_turn_fo
|
||||
let current_context_item = TurnContextItem {
|
||||
turn_id: Some(current_turn_id.clone()),
|
||||
trace_id: turn_context.trace_id.clone(),
|
||||
cwd: turn_context.cwd.to_path_buf(),
|
||||
cwd: turn_context.default_environment_cwd().to_path_buf(),
|
||||
environments: None,
|
||||
current_date: turn_context.current_date.clone(),
|
||||
timezone: turn_context.timezone.clone(),
|
||||
@@ -1234,7 +1234,7 @@ async fn record_initial_history_resumed_trailing_incomplete_turn_compaction_clea
|
||||
let previous_context_item = TurnContextItem {
|
||||
turn_id: Some(turn_context.sub_id.clone()),
|
||||
trace_id: turn_context.trace_id.clone(),
|
||||
cwd: turn_context.cwd.to_path_buf(),
|
||||
cwd: turn_context.default_environment_cwd().to_path_buf(),
|
||||
environments: None,
|
||||
current_date: turn_context.current_date.clone(),
|
||||
timezone: turn_context.timezone.clone(),
|
||||
@@ -1385,7 +1385,7 @@ async fn record_initial_history_resumed_replaced_incomplete_compacted_turn_clear
|
||||
let previous_context_item = TurnContextItem {
|
||||
turn_id: Some(turn_context.sub_id.clone()),
|
||||
trace_id: turn_context.trace_id.clone(),
|
||||
cwd: turn_context.cwd.to_path_buf(),
|
||||
cwd: turn_context.default_environment_cwd().to_path_buf(),
|
||||
environments: None,
|
||||
current_date: turn_context.current_date.clone(),
|
||||
timezone: turn_context.timezone.clone(),
|
||||
|
||||
@@ -1740,7 +1740,7 @@ async fn record_initial_history_forked_hydrates_previous_turn_settings() {
|
||||
let previous_context_item = TurnContextItem {
|
||||
turn_id: Some(turn_context.sub_id.clone()),
|
||||
trace_id: turn_context.trace_id.clone(),
|
||||
cwd: turn_context.cwd.to_path_buf(),
|
||||
cwd: turn_context.default_environment_cwd().to_path_buf(),
|
||||
environments: Some(previous_environments.clone()),
|
||||
current_date: turn_context.current_date.clone(),
|
||||
timezone: turn_context.timezone.clone(),
|
||||
@@ -2992,7 +2992,7 @@ async fn session_configuration_apply_rederives_legacy_file_system_policy_on_cwd_
|
||||
#[tokio::test]
|
||||
async fn session_update_settings_keeps_runtime_cwds_absolute() {
|
||||
let (session, turn_context) = make_session_and_context().await;
|
||||
let updated_cwd = turn_context.cwd.join("project");
|
||||
let updated_cwd = turn_context.default_environment_cwd().join("project");
|
||||
std::fs::create_dir_all(updated_cwd.as_path()).expect("create project dir");
|
||||
|
||||
session
|
||||
@@ -3011,8 +3011,8 @@ async fn session_update_settings_keeps_runtime_cwds_absolute() {
|
||||
let next_turn = session.new_default_turn().await;
|
||||
|
||||
assert_eq!(session_cwd, updated_cwd);
|
||||
assert_eq!(config.cwd, turn_context.cwd);
|
||||
assert_eq!(next_turn.cwd, updated_cwd);
|
||||
assert_eq!(&config.cwd, turn_context.default_environment_cwd());
|
||||
assert_eq!(next_turn.default_environment_cwd(), &updated_cwd);
|
||||
assert_eq!(next_turn.config.cwd, updated_cwd);
|
||||
}
|
||||
|
||||
@@ -3925,7 +3925,7 @@ async fn user_turn_updates_approvals_reviewer() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn turn_environment_selection_sets_primary_environment() {
|
||||
async fn turn_environment_selection_sets_default_environment() {
|
||||
let (session, _turn_context, _rx) = make_session_and_context_with_rx().await;
|
||||
let selected_cwd =
|
||||
AbsolutePathBuf::try_from(session.get_config().await.cwd.as_path().join("selected"))
|
||||
@@ -3943,31 +3943,27 @@ async fn turn_environment_selection_sets_primary_environment() {
|
||||
.await
|
||||
.expect("turn should start");
|
||||
|
||||
let turn_environments = turn_context
|
||||
.environments
|
||||
.as_ref()
|
||||
.expect("turn environments should be recorded");
|
||||
let turn_environments = &turn_context.environments;
|
||||
assert_eq!(turn_environments.len(), 1);
|
||||
assert_eq!(turn_environments[0].environment_id, "local");
|
||||
assert!(std::sync::Arc::ptr_eq(
|
||||
turn_context
|
||||
.environment
|
||||
.as_ref()
|
||||
.expect("primary environment should be set"),
|
||||
&turn_environments[0].environment
|
||||
));
|
||||
assert_eq!(turn_context.cwd.as_path(), selected_cwd.as_path());
|
||||
assert_eq!(
|
||||
turn_environments[0].environment_id.as_deref(),
|
||||
Some("local")
|
||||
);
|
||||
assert_eq!(
|
||||
turn_context.default_environment_cwd().as_path(),
|
||||
selected_cwd.as_path()
|
||||
);
|
||||
assert_eq!(turn_context.config.cwd.as_path(), selected_cwd.as_path());
|
||||
|
||||
let primary_environment = turn_context
|
||||
.primary_environment()
|
||||
.expect("primary environment should resolve");
|
||||
assert_eq!(primary_environment.environment_id.as_deref(), Some("local"));
|
||||
let default_environment = turn_context
|
||||
.default_environment()
|
||||
.expect("default environment should resolve");
|
||||
assert_eq!(default_environment.environment_id.as_deref(), Some("local"));
|
||||
assert!(std::sync::Arc::ptr_eq(
|
||||
&primary_environment.environment,
|
||||
&default_environment.environment,
|
||||
&turn_environments[0].environment
|
||||
));
|
||||
assert_eq!(primary_environment.cwd, selected_cwd);
|
||||
assert_eq!(default_environment.cwd, selected_cwd);
|
||||
let tool_environment = turn_context
|
||||
.environment_for_tool(Some("local"))
|
||||
.expect("tool environment should resolve by id");
|
||||
@@ -3978,14 +3974,14 @@ async fn turn_environment_selection_sets_primary_environment() {
|
||||
));
|
||||
let default_tool_environment = turn_context
|
||||
.environment_for_tool(/*environment_id*/ None)
|
||||
.expect("tool environment should default to primary");
|
||||
.expect("tool environment should resolve to the default environment");
|
||||
assert_eq!(
|
||||
default_tool_environment.environment_id.as_deref(),
|
||||
Some("local")
|
||||
);
|
||||
assert_eq!(
|
||||
turn_context
|
||||
.resolve_path_for_environment(&primary_environment, Some("relative/path".to_string())),
|
||||
.resolve_path_for_environment(&default_environment, Some("relative/path".to_string())),
|
||||
selected_cwd.join("relative/path")
|
||||
);
|
||||
|
||||
@@ -3999,7 +3995,7 @@ async fn turn_environment_selection_sets_primary_environment() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn multiple_turn_environment_selections_use_first_as_primary_environment() {
|
||||
async fn multiple_turn_environment_selections_use_first_as_default_environment() {
|
||||
let (session, _turn_context, _rx) = make_session_and_context_with_rx().await;
|
||||
let session_cwd = session.get_config().await.cwd.clone();
|
||||
let first_cwd =
|
||||
@@ -4025,27 +4021,17 @@ async fn multiple_turn_environment_selections_use_first_as_primary_environment()
|
||||
.await
|
||||
.expect("turn should start");
|
||||
|
||||
let turn_environments = turn_context
|
||||
.environments
|
||||
.as_ref()
|
||||
.expect("turn environments should be recorded");
|
||||
let turn_environments = &turn_context.environments;
|
||||
assert_eq!(turn_environments.len(), 2);
|
||||
assert_eq!(turn_environments[0].cwd, first_cwd);
|
||||
assert_eq!(turn_environments[1].cwd, second_cwd);
|
||||
assert!(std::sync::Arc::ptr_eq(
|
||||
turn_context
|
||||
.environment
|
||||
.as_ref()
|
||||
.expect("primary environment should be set"),
|
||||
&turn_environments[0].environment
|
||||
));
|
||||
assert_eq!(turn_context.cwd, first_cwd);
|
||||
assert_eq!(turn_context.default_environment_cwd(), &first_cwd);
|
||||
assert_eq!(turn_context.config.cwd, first_cwd);
|
||||
|
||||
let primary_environment = turn_context
|
||||
.primary_environment()
|
||||
.expect("primary environment should resolve");
|
||||
assert_eq!(primary_environment.cwd, first_cwd);
|
||||
let default_environment = turn_context
|
||||
.default_environment()
|
||||
.expect("default environment should resolve");
|
||||
assert_eq!(default_environment.cwd, first_cwd);
|
||||
let tool_environment = turn_context
|
||||
.environment_for_tool(Some("local"))
|
||||
.expect("tool environment should resolve by id");
|
||||
@@ -4067,7 +4053,7 @@ async fn multiple_turn_environment_selections_use_first_as_primary_environment()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn empty_turn_environment_selection_clears_primary_environment() {
|
||||
async fn empty_turn_environment_selection_clears_default_environment() {
|
||||
let (session, _turn_context, _rx) = make_session_and_context_with_rx().await;
|
||||
|
||||
let turn_context = session
|
||||
@@ -4079,18 +4065,11 @@ async fn empty_turn_environment_selection_clears_primary_environment() {
|
||||
.await
|
||||
.expect("turn should start");
|
||||
|
||||
assert!(turn_context.environment.is_none());
|
||||
assert_eq!(turn_context.cwd, session.get_config().await.cwd);
|
||||
assert_eq!(turn_context.config.cwd, session.get_config().await.cwd);
|
||||
assert_eq!(
|
||||
turn_context
|
||||
.environments
|
||||
.as_ref()
|
||||
.expect("turn environments should be recorded")
|
||||
.len(),
|
||||
0
|
||||
);
|
||||
assert!(turn_context.primary_environment().is_none());
|
||||
let session_cwd = session.get_config().await.cwd;
|
||||
assert_eq!(turn_context.default_environment_cwd(), &session_cwd);
|
||||
assert_eq!(turn_context.config.cwd, session_cwd);
|
||||
assert_eq!(turn_context.environments.len(), 0);
|
||||
assert!(turn_context.default_environment().is_none());
|
||||
assert!(
|
||||
turn_context
|
||||
.environment_for_tool(/*environment_id*/ None)
|
||||
@@ -4100,35 +4079,35 @@ async fn empty_turn_environment_selection_clears_primary_environment() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn primary_environment_falls_back_to_compatibility_projection() {
|
||||
async fn default_environment_uses_default_environment_list_entry() {
|
||||
let (_session, turn_context, _rx) = make_session_and_context_with_rx().await;
|
||||
|
||||
let primary_environment = turn_context
|
||||
.primary_environment()
|
||||
.expect("primary environment should resolve from compatibility fields");
|
||||
assert_eq!(primary_environment.environment_id.as_deref(), None);
|
||||
let default_environment = turn_context
|
||||
.default_environment()
|
||||
.expect("default environment should resolve from default environment list entry");
|
||||
assert_eq!(default_environment.environment_id.as_deref(), None);
|
||||
assert!(std::sync::Arc::ptr_eq(
|
||||
&primary_environment.environment,
|
||||
turn_context
|
||||
.environment
|
||||
.as_ref()
|
||||
.expect("compatibility environment should be set")
|
||||
&default_environment.environment,
|
||||
&turn_context.environments[0].environment
|
||||
));
|
||||
assert_eq!(primary_environment.cwd, turn_context.cwd);
|
||||
assert_eq!(
|
||||
&default_environment.cwd,
|
||||
turn_context.default_environment_cwd()
|
||||
);
|
||||
|
||||
let default_tool_environment = turn_context
|
||||
.environment_for_tool(/*environment_id*/ None)
|
||||
.expect("tool environment should resolve from compatibility fields");
|
||||
.expect("tool environment should resolve from default environment list entry");
|
||||
assert_eq!(default_tool_environment.environment_id.as_deref(), None);
|
||||
assert!(std::sync::Arc::ptr_eq(
|
||||
&default_tool_environment.environment,
|
||||
&primary_environment.environment
|
||||
&default_environment.environment
|
||||
));
|
||||
assert!(turn_context.environment_for_tool(Some("local")).is_none());
|
||||
assert_eq!(
|
||||
turn_context
|
||||
.resolve_path_for_environment(&primary_environment, Some("relative/path".to_string())),
|
||||
turn_context.cwd.join("relative/path")
|
||||
.resolve_path_for_environment(&default_environment, Some("relative/path".to_string())),
|
||||
turn_context.default_environment_cwd().join("relative/path")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4151,15 +4130,19 @@ async fn multi_environment_feature_without_selections_uses_single_environment_be
|
||||
.features
|
||||
.enabled(Feature::MultiEnvironmentTools)
|
||||
);
|
||||
assert!(turn_context.environments.is_none());
|
||||
assert_eq!(turn_context.environments.len(), 1);
|
||||
assert_eq!(turn_context.environments[0].environment_id, None);
|
||||
assert!(!turn_context.tools_config.multi_environment_tools);
|
||||
assert_eq!(turn_context.to_turn_context_item().environments, None);
|
||||
|
||||
let primary_environment = turn_context
|
||||
.primary_environment()
|
||||
.expect("primary environment should resolve from compatibility fields");
|
||||
assert_eq!(primary_environment.environment_id, None);
|
||||
assert_eq!(primary_environment.cwd, turn_context.cwd);
|
||||
let default_environment = turn_context
|
||||
.default_environment()
|
||||
.expect("default environment should resolve from default environment list entry");
|
||||
assert_eq!(default_environment.environment_id, None);
|
||||
assert_eq!(
|
||||
&default_environment.cwd,
|
||||
turn_context.default_environment_cwd()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -5651,11 +5634,14 @@ async fn build_initial_context_restates_realtime_start_when_reference_context_is
|
||||
fn file_system_policy_with_unreadable_glob(turn_context: &TurnContext) -> FileSystemSandboxPolicy {
|
||||
let mut policy = FileSystemSandboxPolicy::from_legacy_sandbox_policy(
|
||||
turn_context.sandbox_policy.get(),
|
||||
&turn_context.cwd,
|
||||
turn_context.default_environment_cwd(),
|
||||
);
|
||||
policy.entries.push(FileSystemSandboxEntry {
|
||||
path: FileSystemPath::GlobPattern {
|
||||
pattern: format!("{}/**/*.env", turn_context.cwd.as_path().display()),
|
||||
pattern: format!(
|
||||
"{}/**/*.env",
|
||||
turn_context.default_environment_cwd().as_path().display()
|
||||
),
|
||||
},
|
||||
access: FileSystemAccessMode::None,
|
||||
});
|
||||
@@ -5667,7 +5653,7 @@ async fn turn_context_item_omits_legacy_equivalent_file_system_sandbox_policy()
|
||||
let (_session, mut turn_context) = make_session_and_context().await;
|
||||
turn_context.file_system_sandbox_policy = FileSystemSandboxPolicy::from_legacy_sandbox_policy(
|
||||
turn_context.sandbox_policy.get(),
|
||||
&turn_context.cwd,
|
||||
turn_context.default_environment_cwd(),
|
||||
);
|
||||
|
||||
let item = turn_context.to_turn_context_item();
|
||||
@@ -7033,7 +7019,7 @@ async fn rejects_escalated_permissions_when_policy_not_on_request() {
|
||||
"echo hi".to_string(),
|
||||
]
|
||||
},
|
||||
cwd: turn_context.cwd.clone(),
|
||||
cwd: turn_context.default_environment_cwd().clone(),
|
||||
expiration: timeout_ms.into(),
|
||||
capture_policy: ExecCapturePolicy::ShellTool,
|
||||
env: HashMap::new(),
|
||||
@@ -7065,7 +7051,7 @@ async fn rejects_escalated_permissions_when_policy_not_on_request() {
|
||||
payload: ToolPayload::Function {
|
||||
arguments: serde_json::json!({
|
||||
"command": params.command.clone(),
|
||||
"workdir": Some(turn_context.cwd.to_string_lossy().to_string()),
|
||||
"workdir": Some(turn_context.default_environment_cwd().to_string_lossy().to_string()),
|
||||
"timeout_ms": params.expiration.timeout_ms(),
|
||||
"sandbox_permissions": params.sandbox_permissions,
|
||||
"justification": params.justification.clone(),
|
||||
|
||||
@@ -315,7 +315,7 @@ async fn guardian_allows_shell_additional_permissions_requests_past_policy_valid
|
||||
"echo hi".to_string(),
|
||||
]
|
||||
},
|
||||
cwd: turn_context.cwd.clone(),
|
||||
cwd: turn_context.default_environment_cwd().clone(),
|
||||
expiration: expiration_ms.into(),
|
||||
capture_policy: ExecCapturePolicy::ShellTool,
|
||||
env: HashMap::new(),
|
||||
@@ -342,7 +342,7 @@ async fn guardian_allows_shell_additional_permissions_requests_past_policy_valid
|
||||
payload: ToolPayload::Function {
|
||||
arguments: serde_json::json!({
|
||||
"command": params.command.clone(),
|
||||
"workdir": Some(turn_context.cwd.to_string_lossy().to_string()),
|
||||
"workdir": Some(turn_context.default_environment_cwd().to_string_lossy().to_string()),
|
||||
"timeout_ms": params.expiration.timeout_ms(),
|
||||
"sandbox_permissions": params.sandbox_permissions,
|
||||
"additional_permissions": PermissionProfile {
|
||||
@@ -532,7 +532,7 @@ async fn shell_handler_allows_sticky_turn_permissions_without_inline_request_per
|
||||
"echo hi",
|
||||
],
|
||||
"timeout_ms": 1_000_u64,
|
||||
"workdir": Some(turn_context.cwd.to_string_lossy().to_string()),
|
||||
"workdir": Some(turn_context.default_environment_cwd().to_string_lossy().to_string()),
|
||||
})
|
||||
.to_string(),
|
||||
},
|
||||
|
||||
@@ -546,10 +546,11 @@ pub(crate) async fn run_turn(
|
||||
| AskForApproval::Granular(_) => "default",
|
||||
}
|
||||
.to_string();
|
||||
let default_cwd = turn_context.default_environment_cwd().clone();
|
||||
let stop_request = codex_hooks::StopRequest {
|
||||
session_id: sess.conversation_id,
|
||||
turn_id: turn_context.sub_id.clone(),
|
||||
cwd: turn_context.cwd.clone(),
|
||||
cwd: default_cwd.clone(),
|
||||
transcript_path: sess.hook_transcript_path().await,
|
||||
model: turn_context.model_info.slug.clone(),
|
||||
permission_mode: stop_hook_permission_mode,
|
||||
@@ -597,7 +598,7 @@ pub(crate) async fn run_turn(
|
||||
.hooks()
|
||||
.dispatch(HookPayload {
|
||||
session_id: sess.conversation_id,
|
||||
cwd: turn_context.cwd.clone(),
|
||||
cwd: default_cwd.clone(),
|
||||
client: turn_context.app_server_client_name.clone(),
|
||||
triggered_at: chrono::Utc::now(),
|
||||
hook_event: HookEvent::AfterAgent {
|
||||
@@ -1038,7 +1039,9 @@ fn filter_deferred_dynamic_tool_spec(
|
||||
fields(
|
||||
turn_id = %turn_context.sub_id,
|
||||
model = %turn_context.model_info.slug,
|
||||
cwd = %turn_context.cwd.display()
|
||||
cwd = %turn_context
|
||||
.default_environment_cwd()
|
||||
.display()
|
||||
)
|
||||
)]
|
||||
async fn run_sampling_request(
|
||||
|
||||
@@ -12,10 +12,14 @@ pub(super) fn image_generation_tool_auth_allowed(auth_manager: Option<&AuthManag
|
||||
|
||||
fn multi_environment_tools_enabled(
|
||||
features: &codex_features::Features,
|
||||
environments: Option<&[TurnEnvironment]>,
|
||||
environment_selections_explicit: bool,
|
||||
environments: &[TurnEnvironment],
|
||||
) -> bool {
|
||||
features.enabled(codex_features::Feature::MultiEnvironmentTools)
|
||||
&& environments.is_some_and(|environments| !environments.is_empty())
|
||||
&& environment_selections_explicit
|
||||
&& environments
|
||||
.iter()
|
||||
.any(|environment| environment.environment_id.is_some())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -36,7 +40,7 @@ impl TurnSkillsContext {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct TurnEnvironment {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) environment_id: String,
|
||||
pub(crate) environment_id: Option<String>,
|
||||
pub(crate) environment: Arc<Environment>,
|
||||
pub(crate) cwd: AbsolutePathBuf,
|
||||
}
|
||||
@@ -52,7 +56,7 @@ pub(crate) struct SelectedTurnEnvironment {
|
||||
impl TurnEnvironment {
|
||||
fn selected(&self) -> SelectedTurnEnvironment {
|
||||
SelectedTurnEnvironment {
|
||||
environment_id: Some(self.environment_id.clone()),
|
||||
environment_id: self.environment_id.clone(),
|
||||
environment: Arc::clone(&self.environment),
|
||||
cwd: self.cwd.clone(),
|
||||
}
|
||||
@@ -73,12 +77,8 @@ pub(crate) struct TurnContext {
|
||||
pub(crate) reasoning_effort: Option<ReasoningEffortConfig>,
|
||||
pub(crate) reasoning_summary: ReasoningSummaryConfig,
|
||||
pub(crate) session_source: SessionSource,
|
||||
pub(crate) environment: Option<Arc<Environment>>,
|
||||
pub(crate) environments: Option<Vec<TurnEnvironment>>,
|
||||
/// The session's absolute working directory. All relative paths provided
|
||||
/// by the model as well as sandbox policies are resolved against this path
|
||||
/// instead of `std::env::current_dir()`.
|
||||
pub(crate) cwd: AbsolutePathBuf,
|
||||
pub(crate) environments: Vec<TurnEnvironment>,
|
||||
pub(crate) environment_selections_explicit: bool,
|
||||
pub(crate) current_date: Option<String>,
|
||||
pub(crate) timezone: Option<String>,
|
||||
pub(crate) app_server_client_name: Option<String>,
|
||||
@@ -163,8 +163,11 @@ impl TurnContext {
|
||||
/*developer_instructions*/ None,
|
||||
);
|
||||
let features = self.features.clone();
|
||||
let multi_environment_tools =
|
||||
multi_environment_tools_enabled(&features, self.environments.as_deref());
|
||||
let multi_environment_tools = multi_environment_tools_enabled(
|
||||
&features,
|
||||
self.environment_selections_explicit,
|
||||
&self.environments,
|
||||
);
|
||||
let tools_config = ToolsConfig::new(&ToolsConfigParams {
|
||||
model_info: &model_info,
|
||||
available_models: &models_manager
|
||||
@@ -182,7 +185,7 @@ impl TurnContext {
|
||||
.with_unified_exec_shell_mode(self.tools_config.unified_exec_shell_mode.clone())
|
||||
.with_web_search_config(self.tools_config.web_search_config.clone())
|
||||
.with_allow_login_shell(self.tools_config.allow_login_shell)
|
||||
.with_has_environment(self.tools_config.has_environment)
|
||||
.with_has_environment(!self.environments.is_empty())
|
||||
.with_multi_environment_tools(multi_environment_tools)
|
||||
.with_spawn_agent_usage_hint(config.multi_agent_v2.usage_hint_enabled)
|
||||
.with_spawn_agent_usage_hint_text(config.multi_agent_v2.usage_hint_text.clone())
|
||||
@@ -206,9 +209,8 @@ impl TurnContext {
|
||||
reasoning_effort,
|
||||
reasoning_summary: self.reasoning_summary,
|
||||
session_source: self.session_source.clone(),
|
||||
environment: self.environment.clone(),
|
||||
environments: self.environments.clone(),
|
||||
cwd: self.cwd.clone(),
|
||||
environment_selections_explicit: self.environment_selections_explicit,
|
||||
current_date: self.current_date.clone(),
|
||||
timezone: self.timezone.clone(),
|
||||
app_server_client_name: self.app_server_client_name.clone(),
|
||||
@@ -240,26 +242,49 @@ impl TurnContext {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_path(&self, path: Option<String>) -> AbsolutePathBuf {
|
||||
path.as_ref()
|
||||
.map_or_else(|| self.cwd.clone(), |path| self.cwd.join(path))
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn default_environment(&self) -> Option<SelectedTurnEnvironment> {
|
||||
self.environments.first().map(TurnEnvironment::selected)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn primary_environment(&self) -> Option<SelectedTurnEnvironment> {
|
||||
pub(crate) fn default_environment_cwd(&self) -> &AbsolutePathBuf {
|
||||
self.environments
|
||||
.as_ref()
|
||||
.and_then(|environments| environments.first())
|
||||
.map(TurnEnvironment::selected)
|
||||
.or_else(|| {
|
||||
self.environment
|
||||
.as_ref()
|
||||
.map(|environment| SelectedTurnEnvironment {
|
||||
environment_id: None,
|
||||
environment: Arc::clone(environment),
|
||||
cwd: self.cwd.clone(),
|
||||
})
|
||||
})
|
||||
.first()
|
||||
.map_or(&self.config.cwd, |environment| &environment.cwd)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn set_default_environment_cwd_for_test(&mut self, cwd: AbsolutePathBuf) {
|
||||
if let Some(environment) = self.environments.first_mut() {
|
||||
environment.cwd = cwd.clone();
|
||||
}
|
||||
let mut config = (*self.config).clone();
|
||||
config.cwd = cwd;
|
||||
self.config = Arc::new(config);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn set_default_environment_for_test(
|
||||
&mut self,
|
||||
environment: Arc<Environment>,
|
||||
cwd: AbsolutePathBuf,
|
||||
) {
|
||||
match self.environments.first_mut() {
|
||||
Some(turn_environment) => {
|
||||
turn_environment.environment = environment;
|
||||
turn_environment.cwd = cwd.clone();
|
||||
}
|
||||
None => {
|
||||
self.environments.push(TurnEnvironment {
|
||||
environment_id: None,
|
||||
environment,
|
||||
cwd: cwd.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
let mut config = (*self.config).clone();
|
||||
config.cwd = cwd;
|
||||
self.config = Arc::new(config);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -270,11 +295,10 @@ impl TurnContext {
|
||||
match environment_id {
|
||||
Some(environment_id) => self
|
||||
.environments
|
||||
.as_ref()?
|
||||
.iter()
|
||||
.find(|environment| environment.environment_id == environment_id)
|
||||
.find(|environment| environment.environment_id.as_deref() == Some(environment_id))
|
||||
.map(TurnEnvironment::selected),
|
||||
None => self.primary_environment(),
|
||||
None => self.default_environment(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,9 +338,9 @@ impl TurnContext {
|
||||
cwd: &AbsolutePathBuf,
|
||||
) -> Option<FileSystemSandboxPolicy> {
|
||||
// Omit the derived split filesystem policy when it is equivalent to
|
||||
// the legacy sandbox policy. This keeps turn-context payloads stable
|
||||
// while both fields exist; once callers consume only the split policy,
|
||||
// this comparison and the legacy projection should go away.
|
||||
// the sandbox policy projected from the default environment cwd. This keeps
|
||||
// turn-context payloads stable while callers migrate to the split
|
||||
// policy field.
|
||||
let legacy_file_system_sandbox_policy =
|
||||
FileSystemSandboxPolicy::from_legacy_sandbox_policy(self.sandbox_policy.get(), cwd);
|
||||
(self.file_system_sandbox_policy != legacy_file_system_sandbox_policy)
|
||||
@@ -330,16 +354,19 @@ impl TurnContext {
|
||||
}
|
||||
|
||||
pub(crate) fn to_turn_context_item(&self) -> TurnContextItem {
|
||||
let default_cwd = self.default_environment_cwd();
|
||||
TurnContextItem {
|
||||
turn_id: Some(self.sub_id.clone()),
|
||||
trace_id: self.trace_id.clone(),
|
||||
cwd: self.cwd.to_path_buf(),
|
||||
environments: self.environments.as_ref().map(|environments| {
|
||||
environments
|
||||
cwd: default_cwd.to_path_buf(),
|
||||
environments: self.environment_selections_explicit.then(|| {
|
||||
self.environments
|
||||
.iter()
|
||||
.map(|environment| TurnEnvironmentSelection {
|
||||
environment_id: environment.environment_id.clone(),
|
||||
cwd: environment.cwd.clone(),
|
||||
.filter_map(|environment| {
|
||||
Some(TurnEnvironmentSelection {
|
||||
environment_id: environment.environment_id.clone()?,
|
||||
cwd: environment.cwd.clone(),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}),
|
||||
@@ -348,7 +375,7 @@ impl TurnContext {
|
||||
approval_policy: self.approval_policy.value(),
|
||||
sandbox_policy: self.sandbox_policy.get().clone(),
|
||||
network: self.turn_context_network_item(),
|
||||
file_system_sandbox_policy: self.non_legacy_file_system_sandbox_policy(&self.cwd),
|
||||
file_system_sandbox_policy: self.non_legacy_file_system_sandbox_policy(default_cwd),
|
||||
model: self.model_info.slug.clone(),
|
||||
personality: self.personality,
|
||||
collaboration_mode: Some(self.collaboration_mode.clone()),
|
||||
@@ -444,9 +471,8 @@ impl Session {
|
||||
model_info: ModelInfo,
|
||||
models_manager: &ModelsManager,
|
||||
network: Option<NetworkProxy>,
|
||||
environment: Option<Arc<Environment>>,
|
||||
environments: Option<Vec<TurnEnvironment>>,
|
||||
cwd: AbsolutePathBuf,
|
||||
environments: Vec<TurnEnvironment>,
|
||||
environment_selections_explicit: bool,
|
||||
sub_id: String,
|
||||
js_repl: Arc<JsReplHandle>,
|
||||
skills_outcome: Arc<SkillLoadOutcome>,
|
||||
@@ -462,8 +488,11 @@ impl Session {
|
||||
let session_source = session_configuration.session_source.clone();
|
||||
let image_generation_tool_auth_allowed =
|
||||
image_generation_tool_auth_allowed(auth_manager.as_deref());
|
||||
let multi_environment_tools =
|
||||
multi_environment_tools_enabled(&per_turn_config.features, environments.as_deref());
|
||||
let multi_environment_tools = multi_environment_tools_enabled(
|
||||
&per_turn_config.features,
|
||||
environment_selections_explicit,
|
||||
&environments,
|
||||
);
|
||||
let auth_manager_for_context = auth_manager.clone();
|
||||
let provider_for_context = create_model_provider(provider, auth_manager);
|
||||
let session_telemetry_for_context = session_telemetry;
|
||||
@@ -484,7 +513,7 @@ impl Session {
|
||||
)
|
||||
.with_web_search_config(per_turn_config.web_search_config.clone())
|
||||
.with_allow_login_shell(per_turn_config.permissions.allow_login_shell)
|
||||
.with_has_environment(environment.is_some())
|
||||
.with_has_environment(!environments.is_empty())
|
||||
.with_multi_environment_tools(multi_environment_tools)
|
||||
.with_spawn_agent_usage_hint(per_turn_config.multi_agent_v2.usage_hint_enabled)
|
||||
.with_spawn_agent_usage_hint_text(per_turn_config.multi_agent_v2.usage_hint_text.clone())
|
||||
@@ -498,7 +527,7 @@ impl Session {
|
||||
conversation_id.to_string(),
|
||||
&session_source,
|
||||
sub_id.clone(),
|
||||
cwd.clone(),
|
||||
per_turn_config.cwd.clone(),
|
||||
session_configuration.sandbox_policy.get(),
|
||||
session_configuration.windows_sandbox_level,
|
||||
));
|
||||
@@ -515,9 +544,8 @@ impl Session {
|
||||
reasoning_effort,
|
||||
reasoning_summary,
|
||||
session_source,
|
||||
environment,
|
||||
environments,
|
||||
cwd,
|
||||
environment_selections_explicit,
|
||||
current_date: Some(current_date),
|
||||
timezone: Some(timezone),
|
||||
app_server_client_name: session_configuration.app_server_client_name.clone(),
|
||||
@@ -600,21 +628,23 @@ impl Session {
|
||||
};
|
||||
let effective_environment_selections =
|
||||
environment_selections.or_else(|| session_configuration.environment_selections.clone());
|
||||
let turn_environments =
|
||||
match self.resolve_turn_environments(effective_environment_selections) {
|
||||
Ok(turn_environments) => turn_environments,
|
||||
Err(err) => {
|
||||
self.send_event_raw(Event {
|
||||
id: sub_id.clone(),
|
||||
msg: EventMsg::Error(ErrorEvent {
|
||||
message: err.to_string(),
|
||||
codex_error_info: Some(CodexErrorInfo::BadRequest),
|
||||
}),
|
||||
})
|
||||
.await;
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
let environment_selections_explicit = effective_environment_selections.is_some();
|
||||
let turn_environments = match self
|
||||
.resolve_turn_environments(&session_configuration, effective_environment_selections)
|
||||
{
|
||||
Ok(turn_environments) => turn_environments,
|
||||
Err(err) => {
|
||||
self.send_event_raw(Event {
|
||||
id: sub_id.clone(),
|
||||
msg: EventMsg::Error(ErrorEvent {
|
||||
message: err.to_string(),
|
||||
codex_error_info: Some(CodexErrorInfo::BadRequest),
|
||||
}),
|
||||
})
|
||||
.await;
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
|
||||
self.maybe_refresh_shell_snapshot_for_cwd(
|
||||
&previous_cwd,
|
||||
@@ -634,16 +664,25 @@ impl Session {
|
||||
session_configuration,
|
||||
updates.final_output_json_schema,
|
||||
turn_environments,
|
||||
environment_selections_explicit,
|
||||
)
|
||||
.await)
|
||||
}
|
||||
|
||||
fn resolve_turn_environments(
|
||||
&self,
|
||||
session_configuration: &SessionConfiguration,
|
||||
environment_selections: Option<Vec<TurnEnvironmentSelection>>,
|
||||
) -> CodexResult<Option<Vec<TurnEnvironment>>> {
|
||||
) -> CodexResult<Vec<TurnEnvironment>> {
|
||||
let Some(environment_selections) = environment_selections else {
|
||||
return Ok(None);
|
||||
let Some(environment) = self.services.environment_manager.default_environment() else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
return Ok(vec![TurnEnvironment {
|
||||
environment_id: None,
|
||||
environment,
|
||||
cwd: session_configuration.cwd.clone(),
|
||||
}]);
|
||||
};
|
||||
|
||||
let mut turn_environments = Vec::with_capacity(environment_selections.len());
|
||||
@@ -660,13 +699,13 @@ impl Session {
|
||||
})?;
|
||||
let cwd = environment_selection.cwd;
|
||||
turn_environments.push(TurnEnvironment {
|
||||
environment_id: environment_selection.environment_id,
|
||||
environment_id: Some(environment_selection.environment_id),
|
||||
environment,
|
||||
cwd,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(Some(turn_environments))
|
||||
Ok(turn_environments)
|
||||
}
|
||||
|
||||
async fn new_turn_from_configuration(
|
||||
@@ -674,18 +713,13 @@ impl Session {
|
||||
sub_id: String,
|
||||
session_configuration: SessionConfiguration,
|
||||
final_output_json_schema: Option<Option<Value>>,
|
||||
turn_environments: Option<Vec<TurnEnvironment>>,
|
||||
turn_environments: Vec<TurnEnvironment>,
|
||||
environment_selections_explicit: bool,
|
||||
) -> Arc<TurnContext> {
|
||||
// `None` means use the thread's default environment. `Some([])` is an
|
||||
// explicit no-environment turn, so do not fall back in that case.
|
||||
let primary_turn_environment = turn_environments
|
||||
.as_ref()
|
||||
.and_then(|turn_environments| turn_environments.first());
|
||||
let environment = match primary_turn_environment {
|
||||
Some(turn_environment) => Some(Arc::clone(&turn_environment.environment)),
|
||||
None if turn_environments.is_some() => None,
|
||||
None => self.services.environment_manager.default_environment(),
|
||||
};
|
||||
// Omitted selections are resolved to the thread's default environment
|
||||
// above. An explicit empty selection remains empty, so do not fall back
|
||||
// here.
|
||||
let primary_turn_environment = turn_environments.first();
|
||||
let cwd = primary_turn_environment
|
||||
.map(|turn_environment| turn_environment.cwd.clone())
|
||||
.unwrap_or_else(|| session_configuration.cwd.clone());
|
||||
@@ -712,9 +746,8 @@ impl Session {
|
||||
.await;
|
||||
let effective_skill_roots = plugin_outcome.effective_skill_roots();
|
||||
let skills_input = skills_load_input_from_config(&per_turn_config, effective_skill_roots);
|
||||
let fs = environment
|
||||
.as_ref()
|
||||
.map(|environment| environment.get_filesystem());
|
||||
let fs = primary_turn_environment
|
||||
.map(|turn_environment| turn_environment.environment.get_filesystem());
|
||||
let skills_outcome = Arc::new(
|
||||
self.services
|
||||
.skills_manager
|
||||
@@ -742,9 +775,8 @@ impl Session {
|
||||
)
|
||||
.then(|| started_proxy.proxy())
|
||||
}),
|
||||
environment,
|
||||
turn_environments,
|
||||
cwd,
|
||||
environment_selections_explicit,
|
||||
sub_id,
|
||||
Arc::clone(&self.js_repl),
|
||||
skills_outcome,
|
||||
@@ -784,11 +816,15 @@ impl Session {
|
||||
let state = self.state.lock().await;
|
||||
state.session_configuration.clone()
|
||||
};
|
||||
let turn_environments = self
|
||||
.resolve_turn_environments(&session_configuration, None)
|
||||
.unwrap_or_default();
|
||||
self.new_turn_from_configuration(
|
||||
sub_id,
|
||||
session_configuration,
|
||||
/*final_output_json_schema*/ None,
|
||||
/*turn_environments*/ None,
|
||||
turn_environments,
|
||||
/*environment_selections_explicit*/ false,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -128,17 +128,17 @@ pub(crate) async fn execute_user_shell_command(
|
||||
&turn_context.shell_environment_policy,
|
||||
Some(session.conversation_id),
|
||||
);
|
||||
let cwd = turn_context.default_environment_cwd().clone();
|
||||
let exec_command = maybe_wrap_shell_lc_with_snapshot(
|
||||
&display_command,
|
||||
session_shell.as_ref(),
|
||||
&turn_context.cwd,
|
||||
&cwd,
|
||||
&turn_context.shell_environment_policy.r#set,
|
||||
&exec_env_map,
|
||||
);
|
||||
|
||||
let call_id = Uuid::new_v4().to_string();
|
||||
let raw_command = command;
|
||||
let cwd = turn_context.cwd.clone();
|
||||
|
||||
let parsed_cmd = parse_command(&display_command);
|
||||
session
|
||||
|
||||
@@ -237,7 +237,12 @@ mod spawn_agents_on_csv {
|
||||
}
|
||||
|
||||
let db = required_state_db(&session)?;
|
||||
let input_path = turn.resolve_path(Some(args.csv_path));
|
||||
let tool_environment = turn.default_environment().ok_or_else(|| {
|
||||
FunctionCallError::RespondToModel(
|
||||
"spawn_agents_on_csv is unavailable in this session".to_string(),
|
||||
)
|
||||
})?;
|
||||
let input_path = turn.resolve_path_for_environment(&tool_environment, Some(args.csv_path));
|
||||
let input_path_display = input_path.display().to_string();
|
||||
let csv_content = tokio::fs::read_to_string(&input_path)
|
||||
.await
|
||||
@@ -310,7 +315,7 @@ mod spawn_agents_on_csv {
|
||||
let job_id = Uuid::new_v4().to_string();
|
||||
let output_csv_path = args.output_csv_path.map_or_else(
|
||||
|| default_output_csv_path(&input_path, job_id.as_str()),
|
||||
|path| turn.resolve_path(Some(path)),
|
||||
|path| turn.resolve_path_for_environment(&tool_environment, Some(path)),
|
||||
);
|
||||
let job_suffix = &job_id[..8];
|
||||
let job_name = format!("agent-job-{job_suffix}");
|
||||
|
||||
@@ -281,7 +281,6 @@ fn merge_apply_patch_environment_ids(
|
||||
async fn effective_patch_permissions(
|
||||
session: &Session,
|
||||
turn: &TurnContext,
|
||||
cwd: &AbsolutePathBuf,
|
||||
action: &ApplyPatchAction,
|
||||
) -> (
|
||||
Vec<AbsolutePathBuf>,
|
||||
@@ -301,7 +300,7 @@ async fn effective_patch_permissions(
|
||||
session,
|
||||
turn.cwd.as_path(),
|
||||
crate::sandboxing::SandboxPermissions::UseDefault,
|
||||
write_permissions_for_paths(&file_paths, &file_system_sandbox_policy, cwd),
|
||||
write_permissions_for_paths(&file_paths, &file_system_sandbox_policy, &action.cwd),
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -402,22 +401,10 @@ impl ToolHandler for ApplyPatchHandler {
|
||||
.await
|
||||
{
|
||||
codex_apply_patch::MaybeApplyPatchVerified::Body(changes) => {
|
||||
let action_cwd = changes.cwd.clone();
|
||||
let (file_paths, effective_additional_permissions, file_system_sandbox_policy) =
|
||||
effective_patch_permissions(
|
||||
session.as_ref(),
|
||||
turn.as_ref(),
|
||||
&action_cwd,
|
||||
&changes,
|
||||
)
|
||||
.await;
|
||||
match apply_patch::apply_patch(
|
||||
turn.as_ref(),
|
||||
&action_cwd,
|
||||
&file_system_sandbox_policy,
|
||||
changes,
|
||||
)
|
||||
.await
|
||||
effective_patch_permissions(session.as_ref(), turn.as_ref(), &changes).await;
|
||||
match apply_patch::apply_patch(turn.as_ref(), &file_system_sandbox_policy, changes)
|
||||
.await
|
||||
{
|
||||
InternalApplyPatchInvocation::Output(item) => {
|
||||
let content = item?;
|
||||
@@ -438,7 +425,6 @@ impl ToolHandler for ApplyPatchHandler {
|
||||
let req = ApplyPatchRequest {
|
||||
environment_id: tool_environment.environment_id.clone(),
|
||||
environment: tool_environment.environment,
|
||||
cwd: action_cwd,
|
||||
action: apply.action,
|
||||
file_paths,
|
||||
changes,
|
||||
@@ -520,7 +506,6 @@ pub(crate) async fn intercept_apply_patch(
|
||||
.await
|
||||
{
|
||||
codex_apply_patch::MaybeApplyPatchVerified::Body(changes) => {
|
||||
let action_cwd = changes.cwd.clone();
|
||||
session
|
||||
.record_model_warning(
|
||||
format!(
|
||||
@@ -530,15 +515,9 @@ pub(crate) async fn intercept_apply_patch(
|
||||
)
|
||||
.await;
|
||||
let (approval_keys, effective_additional_permissions, file_system_sandbox_policy) =
|
||||
effective_patch_permissions(session.as_ref(), turn.as_ref(), &action_cwd, &changes)
|
||||
.await;
|
||||
match apply_patch::apply_patch(
|
||||
turn.as_ref(),
|
||||
&action_cwd,
|
||||
&file_system_sandbox_policy,
|
||||
changes,
|
||||
)
|
||||
.await
|
||||
effective_patch_permissions(session.as_ref(), turn.as_ref(), &changes).await;
|
||||
match apply_patch::apply_patch(turn.as_ref(), &file_system_sandbox_policy, changes)
|
||||
.await
|
||||
{
|
||||
InternalApplyPatchInvocation::Output(item) => {
|
||||
let content = item?;
|
||||
@@ -567,7 +546,6 @@ pub(crate) async fn intercept_apply_patch(
|
||||
"apply_patch is unavailable in this session".to_string(),
|
||||
)
|
||||
})?,
|
||||
cwd: action_cwd,
|
||||
action: apply.action,
|
||||
file_paths: approval_keys,
|
||||
changes,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use serde_json::Value as JsonValue;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
@@ -57,10 +58,11 @@ async fn emit_js_repl_exec_begin(
|
||||
session: &crate::session::session::Session,
|
||||
turn: &crate::session::turn_context::TurnContext,
|
||||
call_id: &str,
|
||||
cwd: &AbsolutePathBuf,
|
||||
) {
|
||||
let emitter = ToolEmitter::shell(
|
||||
vec!["js_repl".to_string()],
|
||||
turn.cwd.clone(),
|
||||
cwd.clone(),
|
||||
ExecCommandSource::Agent,
|
||||
/*freeform*/ false,
|
||||
);
|
||||
@@ -72,6 +74,7 @@ async fn emit_js_repl_exec_end(
|
||||
session: &crate::session::session::Session,
|
||||
turn: &crate::session::turn_context::TurnContext,
|
||||
call_id: &str,
|
||||
cwd: &AbsolutePathBuf,
|
||||
output: &str,
|
||||
error: Option<&str>,
|
||||
duration: Duration,
|
||||
@@ -79,7 +82,7 @@ async fn emit_js_repl_exec_end(
|
||||
let exec_output = build_js_repl_exec_output(output, error, duration);
|
||||
let emitter = ToolEmitter::shell(
|
||||
vec!["js_repl".to_string()],
|
||||
turn.cwd.clone(),
|
||||
cwd.clone(),
|
||||
ExecCommandSource::Agent,
|
||||
/*freeform*/ false,
|
||||
);
|
||||
@@ -131,9 +134,18 @@ impl ToolHandler for JsReplHandler {
|
||||
));
|
||||
}
|
||||
};
|
||||
let tool_environment = turn.default_environment().ok_or_else(|| {
|
||||
FunctionCallError::RespondToModel("js_repl is unavailable in this session".to_string())
|
||||
})?;
|
||||
let manager = turn.js_repl.manager().await?;
|
||||
let started_at = Instant::now();
|
||||
emit_js_repl_exec_begin(session.as_ref(), turn.as_ref(), &call_id).await;
|
||||
emit_js_repl_exec_begin(
|
||||
session.as_ref(),
|
||||
turn.as_ref(),
|
||||
&call_id,
|
||||
&tool_environment.cwd,
|
||||
)
|
||||
.await;
|
||||
let result = manager
|
||||
.execute_with_cancellation(
|
||||
Arc::clone(&session),
|
||||
@@ -151,6 +163,7 @@ impl ToolHandler for JsReplHandler {
|
||||
session.as_ref(),
|
||||
turn.as_ref(),
|
||||
&call_id,
|
||||
&tool_environment.cwd,
|
||||
"",
|
||||
Some(&message),
|
||||
started_at.elapsed(),
|
||||
@@ -173,6 +186,7 @@ impl ToolHandler for JsReplHandler {
|
||||
session.as_ref(),
|
||||
turn.as_ref(),
|
||||
&call_id,
|
||||
&tool_environment.cwd,
|
||||
&content,
|
||||
/*error*/ None,
|
||||
started_at.elapsed(),
|
||||
|
||||
@@ -77,7 +77,7 @@ async fn emit_js_repl_exec_end_sends_event() {
|
||||
assert_eq!(event.call_id, "call-1");
|
||||
assert_eq!(event.turn_id, turn.sub_id);
|
||||
assert_eq!(event.command, vec!["js_repl".to_string()]);
|
||||
assert_eq!(event.cwd, turn.cwd);
|
||||
assert_eq!(&event.cwd, turn.default_environment_cwd());
|
||||
assert_eq!(event.source, ExecCommandSource::Agent);
|
||||
assert_eq!(event.interaction_input, None);
|
||||
assert_eq!(event.stdout, "hello");
|
||||
|
||||
@@ -99,7 +99,11 @@ impl ToolHandler for ListDirHandler {
|
||||
"dir_path must be an absolute path".to_string(),
|
||||
));
|
||||
}
|
||||
let read_deny_matcher = ReadDenyMatcher::new(&turn.file_system_sandbox_policy, &turn.cwd);
|
||||
let tool_environment = turn.default_environment().ok_or_else(|| {
|
||||
FunctionCallError::RespondToModel("list_dir is unavailable in this session".to_string())
|
||||
})?;
|
||||
let read_deny_matcher =
|
||||
ReadDenyMatcher::new(&turn.file_system_sandbox_policy, &tool_environment.cwd);
|
||||
if read_deny_matcher
|
||||
.as_ref()
|
||||
.is_some_and(|matcher| matcher.is_read_denied(&path))
|
||||
|
||||
@@ -266,7 +266,12 @@ pub(crate) fn apply_spawn_agent_runtime_overrides(
|
||||
})?;
|
||||
config.permissions.shell_environment_policy = turn.shell_environment_policy.clone();
|
||||
config.codex_linux_sandbox_exe = turn.codex_linux_sandbox_exe.clone();
|
||||
config.cwd = turn.cwd.clone();
|
||||
let Some(tool_environment) = turn.default_environment() else {
|
||||
return Err(FunctionCallError::RespondToModel(
|
||||
"spawn_agent is unavailable in this session".to_string(),
|
||||
));
|
||||
};
|
||||
config.cwd = tool_environment.cwd;
|
||||
config
|
||||
.permissions
|
||||
.sandbox_policy
|
||||
|
||||
@@ -1952,8 +1952,10 @@ async fn spawn_agent_reapplies_runtime_sandbox_after_role_config() {
|
||||
&turn.config.permissions.sandbox_policy,
|
||||
turn.config.permissions.sandbox_policy.get().clone(),
|
||||
);
|
||||
let expected_file_system_sandbox_policy =
|
||||
FileSystemSandboxPolicy::from_legacy_sandbox_policy(&expected_sandbox, &turn.cwd);
|
||||
let expected_file_system_sandbox_policy = FileSystemSandboxPolicy::from_legacy_sandbox_policy(
|
||||
&expected_sandbox,
|
||||
turn.default_environment_cwd(),
|
||||
);
|
||||
let expected_network_sandbox_policy = NetworkSandboxPolicy::from(&expected_sandbox);
|
||||
turn.approval_policy
|
||||
.set(AskForApproval::OnRequest)
|
||||
@@ -3486,14 +3488,16 @@ async fn build_agent_spawn_config_uses_turn_context_values() {
|
||||
..ShellEnvironmentPolicy::default()
|
||||
};
|
||||
let temp_dir = tempfile::tempdir().expect("temp dir");
|
||||
turn.cwd = temp_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(temp_dir.abs());
|
||||
turn.codex_linux_sandbox_exe = Some(PathBuf::from("/bin/echo"));
|
||||
let sandbox_policy = pick_allowed_sandbox_policy(
|
||||
&turn.config.permissions.sandbox_policy,
|
||||
turn.config.permissions.sandbox_policy.get().clone(),
|
||||
);
|
||||
let file_system_sandbox_policy =
|
||||
FileSystemSandboxPolicy::from_legacy_sandbox_policy(&sandbox_policy, &turn.cwd);
|
||||
let file_system_sandbox_policy = FileSystemSandboxPolicy::from_legacy_sandbox_policy(
|
||||
&sandbox_policy,
|
||||
turn.default_environment_cwd(),
|
||||
);
|
||||
let network_sandbox_policy = NetworkSandboxPolicy::from(&sandbox_policy);
|
||||
turn.sandbox_policy
|
||||
.set(sandbox_policy)
|
||||
@@ -3515,7 +3519,7 @@ async fn build_agent_spawn_config_uses_turn_context_values() {
|
||||
expected.compact_prompt = turn.compact_prompt.clone();
|
||||
expected.permissions.shell_environment_policy = turn.shell_environment_policy.clone();
|
||||
expected.codex_linux_sandbox_exe = turn.codex_linux_sandbox_exe.clone();
|
||||
expected.cwd = turn.cwd.clone();
|
||||
expected.cwd = turn.default_environment_cwd().clone();
|
||||
expected
|
||||
.permissions
|
||||
.approval_policy
|
||||
@@ -3569,7 +3573,7 @@ async fn build_agent_resume_config_clears_base_instructions() {
|
||||
expected.compact_prompt = turn.compact_prompt.clone();
|
||||
expected.permissions.shell_environment_policy = turn.shell_environment_policy.clone();
|
||||
expected.codex_linux_sandbox_exe = turn.codex_linux_sandbox_exe.clone();
|
||||
expected.cwd = turn.cwd.clone();
|
||||
expected.cwd = turn.default_environment_cwd().clone();
|
||||
expected
|
||||
.permissions
|
||||
.approval_policy
|
||||
|
||||
@@ -37,8 +37,13 @@ impl ToolHandler for RequestPermissionsHandler {
|
||||
}
|
||||
};
|
||||
|
||||
let tool_environment = turn.default_environment().ok_or_else(|| {
|
||||
FunctionCallError::RespondToModel(
|
||||
"request_permissions is unavailable in this session".to_string(),
|
||||
)
|
||||
})?;
|
||||
let mut args: RequestPermissionsArgs =
|
||||
parse_arguments_with_base_path(&arguments, &turn.cwd)?;
|
||||
parse_arguments_with_base_path(&arguments, &tool_environment.cwd)?;
|
||||
args.permissions = normalize_additional_permissions(args.permissions.into())
|
||||
.map(codex_protocol::request_permissions::RequestPermissionProfile::from)
|
||||
.map_err(FunctionCallError::RespondToModel)?;
|
||||
|
||||
@@ -10,6 +10,7 @@ use crate::exec_env::create_env;
|
||||
use crate::exec_policy::ExecApprovalRequest;
|
||||
use crate::function_tool::FunctionCallError;
|
||||
use crate::maybe_emit_implicit_skill_invocation;
|
||||
use crate::session::turn_context::SelectedTurnEnvironment;
|
||||
use crate::session::turn_context::TurnContext;
|
||||
use crate::shell::Shell;
|
||||
use crate::tools::context::FunctionToolOutput;
|
||||
@@ -82,21 +83,47 @@ struct RunExecLikeArgs {
|
||||
prefix_rule: Option<Vec<String>>,
|
||||
session: Arc<crate::session::session::Session>,
|
||||
turn: Arc<TurnContext>,
|
||||
tool_environment: SelectedTurnEnvironment,
|
||||
tracker: crate::tools::context::SharedTurnDiffTracker,
|
||||
call_id: String,
|
||||
freeform: bool,
|
||||
shell_runtime_backend: ShellRuntimeBackend,
|
||||
should_intercept_apply_patch: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct ToolEnvironmentArgs {
|
||||
#[serde(default, alias = "environmentId")]
|
||||
environment_id: Option<String>,
|
||||
}
|
||||
|
||||
fn resolve_tool_environment(
|
||||
turn: &TurnContext,
|
||||
requested_environment_id: Option<&str>,
|
||||
tool_name: &str,
|
||||
) -> Result<SelectedTurnEnvironment, FunctionCallError> {
|
||||
turn.environment_for_tool(requested_environment_id)
|
||||
.ok_or_else(|| {
|
||||
FunctionCallError::RespondToModel(match requested_environment_id {
|
||||
Some(environment_id) => {
|
||||
format!("environment `{environment_id}` is unavailable in this session")
|
||||
}
|
||||
None => format!("{tool_name} is unavailable in this session"),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
impl ShellHandler {
|
||||
fn to_exec_params(
|
||||
params: &ShellToolCallParams,
|
||||
turn_context: &TurnContext,
|
||||
tool_environment: &SelectedTurnEnvironment,
|
||||
thread_id: ThreadId,
|
||||
) -> ExecParams {
|
||||
ExecParams {
|
||||
command: params.command.clone(),
|
||||
cwd: turn_context.resolve_path(params.workdir.clone()),
|
||||
cwd: turn_context
|
||||
.resolve_path_for_environment(tool_environment, params.workdir.clone()),
|
||||
expiration: params.timeout_ms.into(),
|
||||
capture_policy: ExecCapturePolicy::ShellTool,
|
||||
env: create_env(&turn_context.shell_environment_policy, Some(thread_id)),
|
||||
@@ -142,6 +169,7 @@ impl ShellCommandHandler {
|
||||
params: &ShellCommandToolCallParams,
|
||||
session: &crate::session::session::Session,
|
||||
turn_context: &TurnContext,
|
||||
tool_environment: &SelectedTurnEnvironment,
|
||||
thread_id: ThreadId,
|
||||
allow_login_shell: bool,
|
||||
) -> Result<ExecParams, FunctionCallError> {
|
||||
@@ -151,7 +179,8 @@ impl ShellCommandHandler {
|
||||
|
||||
Ok(ExecParams {
|
||||
command,
|
||||
cwd: turn_context.resolve_path(params.workdir.clone()),
|
||||
cwd: turn_context
|
||||
.resolve_path_for_environment(tool_environment, params.workdir.clone()),
|
||||
expiration: params.timeout_ms.into(),
|
||||
capture_policy: ExecCapturePolicy::ShellTool,
|
||||
env: create_env(&turn_context.shell_environment_policy, Some(thread_id)),
|
||||
@@ -234,11 +263,23 @@ impl ToolHandler for ShellHandler {
|
||||
|
||||
match payload {
|
||||
ToolPayload::Function { arguments } => {
|
||||
let cwd = resolve_workdir_base_path(&arguments, &turn.cwd)?;
|
||||
let selector: ToolEnvironmentArgs = parse_arguments(&arguments)?;
|
||||
let requested_environment_id = if turn.tools_config.multi_environment_tools {
|
||||
selector.environment_id.as_deref()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let tool_environment =
|
||||
resolve_tool_environment(turn.as_ref(), requested_environment_id, "shell")?;
|
||||
let cwd = resolve_workdir_base_path(&arguments, &tool_environment.cwd)?;
|
||||
let params: ShellToolCallParams = parse_arguments_with_base_path(&arguments, &cwd)?;
|
||||
let prefix_rule = params.prefix_rule.clone();
|
||||
let exec_params =
|
||||
Self::to_exec_params(¶ms, turn.as_ref(), session.conversation_id);
|
||||
let exec_params = Self::to_exec_params(
|
||||
¶ms,
|
||||
turn.as_ref(),
|
||||
&tool_environment,
|
||||
session.conversation_id,
|
||||
);
|
||||
Self::run_exec_like(RunExecLikeArgs {
|
||||
tool_name: tool_name.display(),
|
||||
exec_params,
|
||||
@@ -247,16 +288,27 @@ impl ToolHandler for ShellHandler {
|
||||
prefix_rule,
|
||||
session,
|
||||
turn,
|
||||
tool_environment,
|
||||
tracker,
|
||||
call_id,
|
||||
freeform: false,
|
||||
shell_runtime_backend: ShellRuntimeBackend::Generic,
|
||||
should_intercept_apply_patch: requested_environment_id.is_none(),
|
||||
})
|
||||
.await
|
||||
}
|
||||
ToolPayload::LocalShell { params } => {
|
||||
let exec_params =
|
||||
Self::to_exec_params(¶ms, turn.as_ref(), session.conversation_id);
|
||||
let tool_environment = resolve_tool_environment(
|
||||
turn.as_ref(),
|
||||
/*requested_environment_id*/ None,
|
||||
"shell",
|
||||
)?;
|
||||
let exec_params = Self::to_exec_params(
|
||||
¶ms,
|
||||
turn.as_ref(),
|
||||
&tool_environment,
|
||||
session.conversation_id,
|
||||
);
|
||||
Self::run_exec_like(RunExecLikeArgs {
|
||||
tool_name: tool_name.display(),
|
||||
exec_params,
|
||||
@@ -265,10 +317,12 @@ impl ToolHandler for ShellHandler {
|
||||
prefix_rule: None,
|
||||
session,
|
||||
turn,
|
||||
tool_environment,
|
||||
tracker,
|
||||
call_id,
|
||||
freeform: false,
|
||||
shell_runtime_backend: ShellRuntimeBackend::Generic,
|
||||
should_intercept_apply_patch: true,
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -348,9 +402,17 @@ impl ToolHandler for ShellCommandHandler {
|
||||
)));
|
||||
};
|
||||
|
||||
let cwd = resolve_workdir_base_path(&arguments, &turn.cwd)?;
|
||||
let selector: ToolEnvironmentArgs = parse_arguments(&arguments)?;
|
||||
let requested_environment_id = if turn.tools_config.multi_environment_tools {
|
||||
selector.environment_id.as_deref()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let tool_environment =
|
||||
resolve_tool_environment(turn.as_ref(), requested_environment_id, "shell_command")?;
|
||||
let cwd = resolve_workdir_base_path(&arguments, &tool_environment.cwd)?;
|
||||
let params: ShellCommandToolCallParams = parse_arguments_with_base_path(&arguments, &cwd)?;
|
||||
let workdir = turn.resolve_path(params.workdir.clone());
|
||||
let workdir = turn.resolve_path_for_environment(&tool_environment, params.workdir.clone());
|
||||
maybe_emit_implicit_skill_invocation(
|
||||
session.as_ref(),
|
||||
turn.as_ref(),
|
||||
@@ -363,6 +425,7 @@ impl ToolHandler for ShellCommandHandler {
|
||||
¶ms,
|
||||
session.as_ref(),
|
||||
turn.as_ref(),
|
||||
&tool_environment,
|
||||
session.conversation_id,
|
||||
turn.tools_config.allow_login_shell,
|
||||
)?;
|
||||
@@ -374,10 +437,12 @@ impl ToolHandler for ShellCommandHandler {
|
||||
prefix_rule,
|
||||
session,
|
||||
turn,
|
||||
tool_environment,
|
||||
tracker,
|
||||
call_id,
|
||||
freeform: true,
|
||||
shell_runtime_backend: self.shell_runtime_backend(),
|
||||
should_intercept_apply_patch: requested_environment_id.is_none(),
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -393,19 +458,16 @@ impl ShellHandler {
|
||||
prefix_rule,
|
||||
session,
|
||||
turn,
|
||||
tool_environment,
|
||||
tracker,
|
||||
call_id,
|
||||
freeform,
|
||||
shell_runtime_backend,
|
||||
should_intercept_apply_patch,
|
||||
} = args;
|
||||
|
||||
let mut exec_params = exec_params;
|
||||
let Some(environment) = turn.environment.as_ref() else {
|
||||
return Err(FunctionCallError::RespondToModel(
|
||||
"shell is unavailable in this session".to_string(),
|
||||
));
|
||||
};
|
||||
let fs = environment.get_filesystem();
|
||||
let fs = tool_environment.environment.get_filesystem();
|
||||
|
||||
let dependency_env = session.dependency_env().await;
|
||||
if !dependency_env.is_empty() {
|
||||
@@ -471,17 +533,18 @@ impl ShellHandler {
|
||||
}
|
||||
|
||||
// Intercept apply_patch if present.
|
||||
if let Some(output) = intercept_apply_patch(
|
||||
&exec_params.command,
|
||||
&exec_params.cwd,
|
||||
fs.as_ref(),
|
||||
session.clone(),
|
||||
turn.clone(),
|
||||
Some(&tracker),
|
||||
&call_id,
|
||||
tool_name.as_str(),
|
||||
)
|
||||
.await?
|
||||
if should_intercept_apply_patch
|
||||
&& let Some(output) = intercept_apply_patch(
|
||||
&exec_params.command,
|
||||
&exec_params.cwd,
|
||||
fs.as_ref(),
|
||||
session.clone(),
|
||||
turn.clone(),
|
||||
Some(&tracker),
|
||||
&call_id,
|
||||
tool_name.as_str(),
|
||||
)
|
||||
.await?
|
||||
{
|
||||
return Ok(output);
|
||||
}
|
||||
@@ -519,6 +582,7 @@ impl ShellHandler {
|
||||
.await;
|
||||
|
||||
let req = ShellRequest {
|
||||
environment_id: tool_environment.environment_id.clone(),
|
||||
command: exec_params.command.clone(),
|
||||
hook_command,
|
||||
cwd: exec_params.cwd.clone(),
|
||||
|
||||
@@ -87,7 +87,11 @@ async fn shell_command_handler_to_exec_params_uses_session_shell_and_turn_contex
|
||||
let expected_command = session
|
||||
.user_shell()
|
||||
.derive_exec_args(&command, /*use_login_shell*/ true);
|
||||
let expected_cwd = turn_context.resolve_path(workdir.clone());
|
||||
let tool_environment = turn_context
|
||||
.default_environment()
|
||||
.expect("default environment should resolve");
|
||||
let expected_cwd =
|
||||
turn_context.resolve_path_for_environment(&tool_environment, workdir.clone());
|
||||
let expected_env = create_env(
|
||||
&turn_context.shell_environment_policy,
|
||||
Some(session.conversation_id),
|
||||
@@ -95,6 +99,7 @@ async fn shell_command_handler_to_exec_params_uses_session_shell_and_turn_contex
|
||||
|
||||
let params = ShellCommandToolCallParams {
|
||||
command,
|
||||
environment_id: None,
|
||||
workdir,
|
||||
login,
|
||||
timeout_ms,
|
||||
@@ -108,6 +113,7 @@ async fn shell_command_handler_to_exec_params_uses_session_shell_and_turn_contex
|
||||
¶ms,
|
||||
&session,
|
||||
&turn_context,
|
||||
&tool_environment,
|
||||
session.conversation_id,
|
||||
/*allow_login_shell*/ true,
|
||||
)
|
||||
@@ -160,8 +166,12 @@ fn shell_command_handler_respects_explicit_login_flag() {
|
||||
#[tokio::test]
|
||||
async fn shell_command_handler_defaults_to_non_login_when_disallowed() {
|
||||
let (session, turn_context) = make_session_and_context().await;
|
||||
let tool_environment = turn_context
|
||||
.default_environment()
|
||||
.expect("default environment should resolve");
|
||||
let params = ShellCommandToolCallParams {
|
||||
command: "echo hello".to_string(),
|
||||
environment_id: None,
|
||||
workdir: None,
|
||||
login: None,
|
||||
timeout_ms: None,
|
||||
@@ -175,6 +185,7 @@ async fn shell_command_handler_defaults_to_non_login_when_disallowed() {
|
||||
¶ms,
|
||||
&session,
|
||||
&turn_context,
|
||||
&tool_environment,
|
||||
session.conversation_id,
|
||||
/*allow_login_shell*/ false,
|
||||
)
|
||||
@@ -210,6 +221,7 @@ async fn shell_pre_tool_use_payload_uses_joined_command() {
|
||||
"-lc".to_string(),
|
||||
"printf hi".to_string(),
|
||||
],
|
||||
environment_id: None,
|
||||
workdir: None,
|
||||
timeout_ms: None,
|
||||
sandbox_permissions: None,
|
||||
|
||||
@@ -1048,6 +1048,9 @@ impl JsReplManager {
|
||||
joined.to_string_lossy().to_string(),
|
||||
);
|
||||
}
|
||||
let tool_environment = turn
|
||||
.default_environment()
|
||||
.ok_or_else(|| "js_repl is unavailable in this session".to_string())?;
|
||||
|
||||
let sandbox = SandboxManager::new();
|
||||
let managed_network_active = turn.network.is_some();
|
||||
@@ -1064,7 +1067,7 @@ impl JsReplManager {
|
||||
"--experimental-vm-modules".to_string(),
|
||||
kernel_path.to_string_lossy().to_string(),
|
||||
],
|
||||
cwd: turn.cwd.clone(),
|
||||
cwd: tool_environment.cwd.clone(),
|
||||
env,
|
||||
additional_permissions: None,
|
||||
};
|
||||
@@ -1081,7 +1084,7 @@ impl JsReplManager {
|
||||
sandbox: sandbox_type,
|
||||
enforce_managed_network: managed_network_active,
|
||||
network: None,
|
||||
sandbox_policy_cwd: &turn.cwd,
|
||||
sandbox_policy_cwd: &tool_environment.cwd,
|
||||
codex_linux_sandbox_exe: turn.codex_linux_sandbox_exe.as_deref(),
|
||||
use_legacy_landlock: turn.features.use_legacy_landlock(),
|
||||
windows_sandbox_level: turn.windows_sandbox_level,
|
||||
|
||||
@@ -716,7 +716,7 @@ async fn interrupt_active_exec_stops_aborted_kernel_before_later_exec() -> anyho
|
||||
|
||||
let dir = tempdir()?;
|
||||
let (session, mut turn) = make_session_and_context().await;
|
||||
turn.cwd = dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(dir.abs());
|
||||
set_danger_full_access(&mut turn);
|
||||
let session = Arc::new(session);
|
||||
let turn = Arc::new(turn);
|
||||
@@ -2078,7 +2078,7 @@ async fn js_repl_prefers_env_node_module_dirs_over_config() -> anyhow::Result<()
|
||||
"CODEX_JS_REPL_NODE_MODULE_DIRS".to_string(),
|
||||
env_base.path().to_string_lossy().to_string(),
|
||||
);
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
vec![config_base.path().to_path_buf()],
|
||||
@@ -2122,7 +2122,7 @@ async fn js_repl_resolves_from_first_config_dir() -> anyhow::Result<()> {
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
vec![
|
||||
@@ -2166,7 +2166,7 @@ async fn js_repl_falls_back_to_cwd_node_modules() -> anyhow::Result<()> {
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
vec![config_base.path().to_path_buf()],
|
||||
@@ -2207,7 +2207,7 @@ async fn js_repl_accepts_node_modules_dir_entries() -> anyhow::Result<()> {
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
vec![base_dir.path().join("node_modules")],
|
||||
@@ -2261,7 +2261,7 @@ async fn js_repl_supports_relative_file_imports() -> anyhow::Result<()> {
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
Vec::new(),
|
||||
@@ -2308,7 +2308,7 @@ async fn js_repl_supports_absolute_file_imports() -> anyhow::Result<()> {
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
Vec::new(),
|
||||
@@ -2362,7 +2362,7 @@ async fn js_repl_imported_local_files_can_access_repl_globals() -> anyhow::Resul
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
Vec::new(),
|
||||
@@ -2406,7 +2406,7 @@ async fn js_repl_reimports_local_files_after_edit() -> anyhow::Result<()> {
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
Vec::new(),
|
||||
@@ -2462,7 +2462,7 @@ async fn js_repl_reimports_local_files_after_fixing_failure() -> anyhow::Result<
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
Vec::new(),
|
||||
@@ -2540,7 +2540,7 @@ async fn js_repl_local_files_expose_node_like_import_meta() -> anyhow::Result<()
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
Vec::new(),
|
||||
@@ -2625,7 +2625,7 @@ async fn js_repl_local_files_reject_static_bare_imports() -> anyhow::Result<()>
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
Vec::new(),
|
||||
@@ -2670,7 +2670,7 @@ async fn js_repl_rejects_unsupported_file_specifiers() -> anyhow::Result<()> {
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
Vec::new(),
|
||||
@@ -2772,7 +2772,7 @@ async fn js_repl_blocks_sensitive_builtin_imports_from_local_files() -> anyhow::
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
Vec::new(),
|
||||
@@ -2822,7 +2822,7 @@ async fn js_repl_local_files_do_not_escape_node_module_search_roots() -> anyhow:
|
||||
turn.shell_environment_policy
|
||||
.r#set
|
||||
.remove("CODEX_JS_REPL_NODE_MODULE_DIRS");
|
||||
turn.cwd = cwd_dir.abs();
|
||||
turn.set_default_environment_cwd_for_test(cwd_dir.abs());
|
||||
turn.js_repl = Arc::new(JsReplHandle::with_node_path(
|
||||
turn.config.js_repl_node_path.clone(),
|
||||
Vec::new(),
|
||||
|
||||
@@ -349,6 +349,15 @@ impl NetworkApprovalService {
|
||||
.await;
|
||||
return NetworkDecision::deny(REASON_NOT_ALLOWED);
|
||||
};
|
||||
let Some(tool_environment) = turn_context.default_environment() else {
|
||||
pending.set_decision(PendingApprovalDecision::Deny).await;
|
||||
self.pending_host_approvals.lock().await.remove(&key);
|
||||
self.record_outcome_for_single_active_call(NetworkApprovalOutcome::DeniedByPolicy(
|
||||
policy_denial_message,
|
||||
))
|
||||
.await;
|
||||
return NetworkDecision::deny(REASON_NOT_ALLOWED);
|
||||
};
|
||||
if !sandbox_policy_allows_network_approval_flow(turn_context.sandbox_policy.get()) {
|
||||
pending.set_decision(PendingApprovalDecision::Deny).await;
|
||||
self.pending_host_approvals.lock().await.remove(&key);
|
||||
@@ -442,7 +451,7 @@ impl NetworkApprovalService {
|
||||
guardian_approval_id,
|
||||
/*approval_id*/ None,
|
||||
prompt_command,
|
||||
turn_context.cwd.clone(),
|
||||
tool_environment.cwd,
|
||||
Some(prompt_reason),
|
||||
Some(network_approval_context.clone()),
|
||||
/*proposed_execpolicy_amendment*/ None,
|
||||
|
||||
@@ -611,11 +611,16 @@ async fn dispatch_after_tool_use_hook(
|
||||
let session = invocation.session.as_ref();
|
||||
let turn = invocation.turn.as_ref();
|
||||
let tool_input = HookToolInput::from(&invocation.payload);
|
||||
let Some(tool_environment) = turn.default_environment() else {
|
||||
return Some(FunctionCallError::RespondToModel(
|
||||
"after-tool hooks are unavailable in this session".to_string(),
|
||||
));
|
||||
};
|
||||
let hook_outcomes = session
|
||||
.hooks()
|
||||
.dispatch(HookPayload {
|
||||
session_id: session.conversation_id,
|
||||
cwd: turn.cwd.clone(),
|
||||
cwd: tool_environment.cwd,
|
||||
client: turn.app_server_client_name.clone(),
|
||||
triggered_at: chrono::Utc::now(),
|
||||
hook_event: HookEvent::AfterToolUse {
|
||||
|
||||
@@ -244,6 +244,7 @@ impl ToolRouter {
|
||||
LocalShellAction::Exec(exec) => {
|
||||
let params = ShellToolCallParams {
|
||||
command: exec.command,
|
||||
environment_id: None,
|
||||
workdir: exec.working_directory,
|
||||
timeout_ms: exec.timeout_ms,
|
||||
sandbox_permissions: Some(SandboxPermissions::UseDefault),
|
||||
|
||||
@@ -43,7 +43,6 @@ use std::time::Instant;
|
||||
pub struct ApplyPatchRequest {
|
||||
pub environment_id: Option<String>,
|
||||
pub environment: Arc<Environment>,
|
||||
pub cwd: AbsolutePathBuf,
|
||||
pub action: ApplyPatchAction,
|
||||
pub file_paths: Vec<AbsolutePathBuf>,
|
||||
pub changes: std::collections::HashMap<PathBuf, FileChange>,
|
||||
@@ -72,7 +71,7 @@ impl ApplyPatchRuntime {
|
||||
) -> GuardianApprovalRequest {
|
||||
GuardianApprovalRequest::ApplyPatch {
|
||||
id: call_id.to_string(),
|
||||
cwd: req.cwd.clone(),
|
||||
cwd: req.action.cwd.clone(),
|
||||
files: req.file_paths.clone(),
|
||||
patch: req.action.patch.clone(),
|
||||
}
|
||||
@@ -224,7 +223,7 @@ impl ToolRuntime<ApplyPatchRequest, ExecToolCallOutput> for ApplyPatchRuntime {
|
||||
req: &'a ApplyPatchRequest,
|
||||
_turn_ctx: &'a crate::session::turn_context::TurnContext,
|
||||
) -> &'a AbsolutePathBuf {
|
||||
&req.cwd
|
||||
&req.action.cwd
|
||||
}
|
||||
|
||||
async fn run(
|
||||
@@ -240,7 +239,7 @@ impl ToolRuntime<ApplyPatchRequest, ExecToolCallOutput> for ApplyPatchRuntime {
|
||||
let mut stderr = Vec::new();
|
||||
let result = codex_apply_patch::apply_patch(
|
||||
&req.action.patch,
|
||||
&req.cwd,
|
||||
&req.action.cwd,
|
||||
&mut stdout,
|
||||
&mut stderr,
|
||||
fs.as_ref(),
|
||||
|
||||
@@ -56,7 +56,6 @@ fn guardian_review_request_includes_patch_context() {
|
||||
let request = ApplyPatchRequest {
|
||||
environment_id: None,
|
||||
environment: local_environment(),
|
||||
cwd: expected_cwd.clone(),
|
||||
action,
|
||||
file_paths: vec![path.clone()],
|
||||
changes: HashMap::from([(
|
||||
@@ -101,7 +100,6 @@ fn file_system_sandbox_context_uses_active_attempt() {
|
||||
let req = ApplyPatchRequest {
|
||||
environment_id: None,
|
||||
environment: local_environment(),
|
||||
cwd: path.clone(),
|
||||
action: ApplyPatchAction::new_add_for_test(&path, "hello".to_string()),
|
||||
file_paths: vec![path.clone()],
|
||||
changes: HashMap::new(),
|
||||
@@ -160,7 +158,6 @@ fn file_system_sandbox_context_omits_legacy_equivalent_policy() {
|
||||
let req = ApplyPatchRequest {
|
||||
environment_id: None,
|
||||
environment: local_environment(),
|
||||
cwd: path.clone(),
|
||||
action: ApplyPatchAction::new_add_for_test(&path, "hello".to_string()),
|
||||
file_paths: vec![path.clone()],
|
||||
changes: HashMap::new(),
|
||||
@@ -204,7 +201,6 @@ fn no_sandbox_attempt_has_no_file_system_context() {
|
||||
let req = ApplyPatchRequest {
|
||||
environment_id: None,
|
||||
environment: local_environment(),
|
||||
cwd: path.clone(),
|
||||
action: ApplyPatchAction::new_add_for_test(&path, "hello".to_string()),
|
||||
file_paths: vec![path.clone()],
|
||||
changes: HashMap::new(),
|
||||
|
||||
@@ -44,6 +44,7 @@ use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ShellRequest {
|
||||
pub environment_id: Option<String>,
|
||||
pub command: Vec<String>,
|
||||
pub hook_command: String,
|
||||
pub cwd: AbsolutePathBuf,
|
||||
@@ -93,6 +94,7 @@ pub struct ShellRuntime {
|
||||
|
||||
#[derive(serde::Serialize, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub(crate) struct ApprovalKey {
|
||||
environment_id: Option<String>,
|
||||
command: Vec<String>,
|
||||
cwd: AbsolutePathBuf,
|
||||
sandbox_permissions: SandboxPermissions,
|
||||
@@ -133,6 +135,7 @@ impl Approvable<ShellRequest> for ShellRuntime {
|
||||
|
||||
fn approval_keys(&self, req: &ShellRequest) -> Vec<Self::ApprovalKey> {
|
||||
vec![ApprovalKey {
|
||||
environment_id: req.environment_id.clone(),
|
||||
command: canonicalize_command_for_approval(&req.command),
|
||||
cwd: req.cwd.clone(),
|
||||
sandbox_permissions: req.sandbox_permissions,
|
||||
@@ -213,6 +216,14 @@ impl Approvable<ShellRequest> for ShellRuntime {
|
||||
}
|
||||
|
||||
impl ToolRuntime<ShellRequest, ExecToolCallOutput> for ShellRuntime {
|
||||
fn sandbox_cwd<'a>(
|
||||
&self,
|
||||
req: &'a ShellRequest,
|
||||
_turn_ctx: &'a crate::session::turn_context::TurnContext,
|
||||
) -> &'a AbsolutePathBuf {
|
||||
&req.cwd
|
||||
}
|
||||
|
||||
fn network_approval_spec(
|
||||
&self,
|
||||
req: &ShellRequest,
|
||||
|
||||
@@ -161,7 +161,7 @@ pub(super) async fn try_run_zsh_fork(
|
||||
network: sandbox_network,
|
||||
windows_sandbox_level,
|
||||
arg0,
|
||||
sandbox_policy_cwd: ctx.turn.cwd.clone(),
|
||||
sandbox_policy_cwd: attempt.sandbox_cwd.clone(),
|
||||
codex_linux_sandbox_exe: ctx.turn.codex_linux_sandbox_exe.clone(),
|
||||
use_legacy_landlock: ctx.turn.features.use_legacy_landlock(),
|
||||
};
|
||||
@@ -259,7 +259,7 @@ pub(crate) async fn prepare_unified_exec_zsh_fork(
|
||||
network: exec_request.network.clone(),
|
||||
windows_sandbox_level: exec_request.windows_sandbox_level,
|
||||
arg0: exec_request.arg0.clone(),
|
||||
sandbox_policy_cwd: ctx.turn.cwd.clone(),
|
||||
sandbox_policy_cwd: req.cwd.clone(),
|
||||
codex_linux_sandbox_exe: ctx.turn.codex_linux_sandbox_exe.clone(),
|
||||
use_legacy_landlock: ctx.turn.features.use_legacy_landlock(),
|
||||
};
|
||||
|
||||
@@ -330,7 +330,7 @@ pub(crate) trait ToolRuntime<Req, Out>: Approvable<Req> + Sandboxable {
|
||||
}
|
||||
|
||||
fn sandbox_cwd<'a>(&self, _req: &'a Req, turn_ctx: &'a TurnContext) -> &'a AbsolutePathBuf {
|
||||
&turn_ctx.cwd
|
||||
turn_ctx.default_environment_cwd()
|
||||
}
|
||||
|
||||
async fn run(
|
||||
|
||||
@@ -87,9 +87,10 @@ async fn exec_command_with_tty(
|
||||
) -> Result<ExecCommandToolOutput, UnifiedExecError> {
|
||||
let manager = &session.services.unified_exec_manager;
|
||||
let process_id = manager.allocate_process_id().await;
|
||||
let cwd = workdir
|
||||
.as_ref()
|
||||
.map_or_else(|| turn.cwd.clone(), |workdir| turn.cwd.join(workdir));
|
||||
let cwd = workdir.as_ref().map_or_else(
|
||||
|| turn.default_environment_cwd().clone(),
|
||||
|workdir| turn.default_environment_cwd().join(workdir),
|
||||
);
|
||||
let command = vec!["bash".to_string(), "-lc".to_string(), cmd.to_string()];
|
||||
let request = test_exec_request(turn, command.clone(), cwd.clone(), shell_env());
|
||||
|
||||
@@ -100,7 +101,10 @@ async fn exec_command_with_tty(
|
||||
&request,
|
||||
tty,
|
||||
Box::new(NoopSpawnLifecycle),
|
||||
turn.environment.as_ref().expect("turn environment"),
|
||||
&turn
|
||||
.default_environment()
|
||||
.expect("turn environment")
|
||||
.environment,
|
||||
)
|
||||
.await?,
|
||||
);
|
||||
@@ -504,7 +508,7 @@ async fn completed_pipe_commands_preserve_exit_code() -> anyhow::Result<()> {
|
||||
let request = test_exec_request(
|
||||
&turn,
|
||||
vec!["bash".to_string(), "-lc".to_string(), "exit 17".to_string()],
|
||||
turn.cwd.clone(),
|
||||
turn.default_environment_cwd().clone(),
|
||||
shell_env(),
|
||||
);
|
||||
|
||||
@@ -595,12 +599,15 @@ async fn remote_exec_server_rejects_inherited_fd_launches() -> anyhow::Result<()
|
||||
|
||||
let remote_test_env = remote_test_env().await?;
|
||||
let (_, mut turn) = make_session_and_context().await;
|
||||
turn.environment = Some(Arc::new(remote_test_env.environment().clone()));
|
||||
turn.set_default_environment_for_test(
|
||||
Arc::new(remote_test_env.environment().clone()),
|
||||
remote_test_env.cwd().clone(),
|
||||
);
|
||||
|
||||
let request = test_exec_request(
|
||||
&turn,
|
||||
vec!["bash".to_string(), "-lc".to_string(), "echo ok".to_string()],
|
||||
turn.cwd.clone(),
|
||||
turn.default_environment_cwd().clone(),
|
||||
shell_env(),
|
||||
);
|
||||
|
||||
@@ -613,7 +620,10 @@ async fn remote_exec_server_rejects_inherited_fd_launches() -> anyhow::Result<()
|
||||
Box::new(TestSpawnLifecycle {
|
||||
inherited_fds: vec![42],
|
||||
}),
|
||||
turn.environment.as_ref().expect("turn environment"),
|
||||
&turn
|
||||
.default_environment()
|
||||
.expect("turn environment")
|
||||
.environment,
|
||||
)
|
||||
.await
|
||||
.expect_err("expected inherited fd rejection");
|
||||
|
||||
@@ -236,7 +236,7 @@ impl UnifiedExecProcessManager {
|
||||
let cwd = request
|
||||
.workdir
|
||||
.clone()
|
||||
.unwrap_or_else(|| context.turn.cwd.clone());
|
||||
.unwrap_or_else(|| context.turn.default_environment_cwd().clone());
|
||||
let process = self
|
||||
.open_session_with_sandbox(&request, cwd.clone(), context)
|
||||
.await;
|
||||
|
||||
@@ -956,6 +956,9 @@ pub struct SearchToolCallParams {
|
||||
#[derive(Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
pub struct ShellToolCallParams {
|
||||
pub command: Vec<String>,
|
||||
#[serde(default, alias = "environmentId")]
|
||||
#[ts(optional)]
|
||||
pub environment_id: Option<String>,
|
||||
pub workdir: Option<String>,
|
||||
|
||||
/// This is the maximum time in milliseconds that the command is allowed to run.
|
||||
@@ -980,6 +983,9 @@ pub struct ShellToolCallParams {
|
||||
#[derive(Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
pub struct ShellCommandToolCallParams {
|
||||
pub command: String,
|
||||
#[serde(default, alias = "environmentId")]
|
||||
#[ts(optional)]
|
||||
pub environment_id: Option<String>,
|
||||
pub workdir: Option<String>,
|
||||
|
||||
/// Whether to run the shell with login shell semantics
|
||||
@@ -2021,6 +2027,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
ShellToolCallParams {
|
||||
command: vec!["ls".to_string(), "-l".to_string()],
|
||||
environment_id: None,
|
||||
workdir: Some("/tmp".to_string()),
|
||||
timeout_ms: Some(1000),
|
||||
sandbox_permissions: None,
|
||||
|
||||
@@ -129,7 +129,7 @@ pub fn create_apply_patch_json_tool(options: ApplyPatchToolOptions) -> ToolSpec
|
||||
properties.insert(
|
||||
"environment_id".to_string(),
|
||||
JsonSchema::string(Some(
|
||||
"Optional selected environment id to apply the patch in; omit to use the primary environment.".to_string(),
|
||||
"Optional selected environment id to apply the patch in; omit to use the default environment.".to_string(),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ pub struct CommandToolOptions {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct ShellToolOptions {
|
||||
pub exec_permission_approvals_enabled: bool,
|
||||
pub multi_environment_tools: bool,
|
||||
}
|
||||
|
||||
pub fn create_exec_command_tool(options: CommandToolOptions) -> ToolSpec {
|
||||
@@ -68,7 +69,7 @@ pub fn create_exec_command_tool(options: CommandToolOptions) -> ToolSpec {
|
||||
properties.insert(
|
||||
"environment_id".to_string(),
|
||||
JsonSchema::string(Some(
|
||||
"Optional selected environment id to run the command in; omit to use the primary environment.".to_string(),
|
||||
"Optional selected environment id to run the command in; omit to use the default environment.".to_string(),
|
||||
)),
|
||||
);
|
||||
}
|
||||
@@ -164,6 +165,14 @@ pub fn create_shell_tool(options: ShellToolOptions) -> ToolSpec {
|
||||
)),
|
||||
),
|
||||
]);
|
||||
if options.multi_environment_tools {
|
||||
properties.insert(
|
||||
"environment_id".to_string(),
|
||||
JsonSchema::string(Some(
|
||||
"Optional selected environment id to run the command in; omit to use the default environment.".to_string(),
|
||||
)),
|
||||
);
|
||||
}
|
||||
properties.extend(create_approval_parameters(
|
||||
options.exec_permission_approvals_enabled,
|
||||
));
|
||||
@@ -235,6 +244,14 @@ pub fn create_shell_command_tool(options: CommandToolOptions) -> ToolSpec {
|
||||
)),
|
||||
);
|
||||
}
|
||||
if options.multi_environment_tools {
|
||||
properties.insert(
|
||||
"environment_id".to_string(),
|
||||
JsonSchema::string(Some(
|
||||
"Optional selected environment id to run the command in; omit to use the default environment.".to_string(),
|
||||
)),
|
||||
);
|
||||
}
|
||||
properties.extend(create_approval_parameters(
|
||||
options.exec_permission_approvals_enabled,
|
||||
));
|
||||
|
||||
@@ -10,6 +10,7 @@ fn windows_shell_safety_description() -> String {
|
||||
fn shell_tool_matches_expected_spec() {
|
||||
let tool = create_shell_tool(ShellToolOptions {
|
||||
exec_permission_approvals_enabled: false,
|
||||
multi_environment_tools: false,
|
||||
});
|
||||
|
||||
let description = if cfg!(windows) {
|
||||
@@ -229,6 +230,7 @@ fn write_stdin_tool_matches_expected_spec() {
|
||||
fn shell_tool_with_request_permission_includes_additional_permissions() {
|
||||
let tool = create_shell_tool(ShellToolOptions {
|
||||
exec_permission_approvals_enabled: true,
|
||||
multi_environment_tools: false,
|
||||
});
|
||||
|
||||
let mut properties = BTreeMap::from([
|
||||
|
||||
@@ -141,6 +141,7 @@ pub fn build_tool_registry_plan(
|
||||
plan.push_spec(
|
||||
create_shell_tool(ShellToolOptions {
|
||||
exec_permission_approvals_enabled,
|
||||
multi_environment_tools: config.multi_environment_tools,
|
||||
}),
|
||||
/*supports_parallel_tool_calls*/ true,
|
||||
config.code_mode_enabled,
|
||||
@@ -177,7 +178,7 @@ pub fn build_tool_registry_plan(
|
||||
create_shell_command_tool(CommandToolOptions {
|
||||
allow_login_shell: config.allow_login_shell,
|
||||
exec_permission_approvals_enabled,
|
||||
multi_environment_tools: false,
|
||||
multi_environment_tools: config.multi_environment_tools,
|
||||
}),
|
||||
/*supports_parallel_tool_calls*/ true,
|
||||
config.code_mode_enabled,
|
||||
|
||||
@@ -29,7 +29,7 @@ pub fn create_view_image_tool(options: ViewImageToolOptions) -> ToolSpec {
|
||||
properties.insert(
|
||||
"environment_id".to_string(),
|
||||
JsonSchema::string(Some(
|
||||
"Optional selected environment id to load the image from; omit to use the primary environment.".to_string(),
|
||||
"Optional selected environment id to load the image from; omit to use the default environment.".to_string(),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user