Lightweight coding agent that runs in your terminal
Rust
core: resolve view_image paths in selected environment (#29526)
Adam Perry @ OpenAI510bce992701
diff --git a/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/codex-rs/app-server-protocol/schema/json/ServerNotification.jsonindex 27753341bf..ea6076fa89 100644--- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json+++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json@@ -4444,7 +4444,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.jsonindex 8e1000aaa1..dc5bc6f24c 100644--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json@@ -18038,7 +18038,7 @@"type": "string"},"path": {- "$ref": "#/definitions/v2/AbsolutePathBuf"+ "$ref": "#/definitions/v2/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.jsonindex c98f7d44da..40a5110a73 100644--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json@@ -15817,7 +15817,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.jsonindex d7bfb3827e..8f4b533d8f 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json@@ -1106,7 +1106,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.jsonindex 770fc8bd4c..4c930afde1 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json@@ -1106,7 +1106,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.jsonindex 4eb3489663..d87dd74401 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json@@ -1250,7 +1250,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.jsonindex ac77905901..e735aaa89b 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json@@ -1755,7 +1755,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.jsonindex 71e698e5ac..a428f109db 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json@@ -1562,7 +1562,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.jsonindex 203e5e9434..2731ab409a 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json@@ -1562,7 +1562,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.jsonindex 17eb143f6a..c591beea3c 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json@@ -1562,7 +1562,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.jsonindex 6f9bf68112..120f972e51 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json@@ -1755,7 +1755,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.jsonindex fd58f93e87..409a1ca5f5 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json@@ -1562,7 +1562,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.jsonindex 530ea82217..63efc4e3d6 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json@@ -1755,7 +1755,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.jsonindex b0bbf345d0..152d83a150 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json@@ -1562,7 +1562,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.jsonindex d311e39970..291b88a923 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json@@ -1562,7 +1562,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.jsonindex fb703d511f..566922e80c 100644--- a/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json@@ -1250,7 +1250,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.jsonindex a8a9d5a62b..627aea2126 100644--- a/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json@@ -1250,7 +1250,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.jsonindex becf0d87cd..cacfb01564 100644--- a/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json@@ -1250,7 +1250,7 @@"type": "string"},"path": {- "$ref": "#/definitions/AbsolutePathBuf"+ "$ref": "#/definitions/LegacyAppPathString"},"type": {"enum": [diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.tsindex eb8c6486b8..c611ab071c 100644--- a/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts+++ b/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts@@ -105,4 +105,4 @@ reasoningEffort: ReasoningEffort | null,/*** Last known status of the target agents, when available.*/-agentsStates: { [key in string]?: CollabAgentState }, } | { "type": "subAgentActivity", id: string, kind: SubAgentActivityKind, agentThreadId: string, agentPath: string, } | { "type": "webSearch", id: string, query: string, action: WebSearchAction | null, } | { "type": "imageView", id: string, path: AbsolutePathBuf, } | { "type": "sleep", id: string, durationMs: number, } | { "type": "imageGeneration", id: string, status: string, revisedPrompt: string | null, result: string, savedPath?: AbsolutePathBuf, } | { "type": "enteredReviewMode", id: string, review: string, } | { "type": "exitedReviewMode", id: string, review: string, } | { "type": "contextCompaction", id: string, };+agentsStates: { [key in string]?: CollabAgentState }, } | { "type": "subAgentActivity", id: string, kind: SubAgentActivityKind, agentThreadId: string, agentPath: string, } | { "type": "webSearch", id: string, query: string, action: WebSearchAction | null, } | { "type": "imageView", id: string, path: LegacyAppPathString, } | { "type": "sleep", id: string, durationMs: number, } | { "type": "imageGeneration", id: string, status: string, revisedPrompt: string | null, result: string, savedPath?: AbsolutePathBuf, } | { "type": "enteredReviewMode", id: string, review: string, } | { "type": "exitedReviewMode", id: string, review: string, } | { "type": "contextCompaction", id: string, };diff --git a/codex-rs/app-server-protocol/src/protocol/thread_history.rs b/codex-rs/app-server-protocol/src/protocol/thread_history.rsindex 1e087c4c5f..f9ebc93bf2 100644--- a/codex-rs/app-server-protocol/src/protocol/thread_history.rs+++ b/codex-rs/app-server-protocol/src/protocol/thread_history.rs@@ -836,7 +836,7 @@ impl ThreadHistoryBuilder {fn handle_view_image_tool_call(&mut self, payload: &ViewImageToolCallEvent) {let item = ThreadItem::ImageView {id: payload.call_id.clone(),- path: payload.path.clone(),+ path: payload.path.clone().into(),};self.upsert_item_in_current_turn(item);}diff --git a/codex-rs/app-server-protocol/src/protocol/v2/item.rs b/codex-rs/app-server-protocol/src/protocol/v2/item.rsindex e630de634b..e2a0d45129 100644--- a/codex-rs/app-server-protocol/src/protocol/v2/item.rs+++ b/codex-rs/app-server-protocol/src/protocol/v2/item.rs@@ -356,7 +356,10 @@ pub enum ThreadItem {},#[serde(rename_all = "camelCase")]#[ts(rename_all = "camelCase")]- ImageView { id: String, path: AbsolutePathBuf },+ ImageView {+ id: String,+ path: LegacyAppPathString,+ },#[serde(rename_all = "camelCase")]#[ts(rename_all = "camelCase")]Sleep {@@ -855,7 +858,7 @@ impl From<CoreTurnItem> for ThreadItem {},CoreTurnItem::ImageView(image) => ThreadItem::ImageView {id: image.id,- path: image.path,+ path: image.path.into(),},CoreTurnItem::Sleep(sleep) => ThreadItem::Sleep {id: sleep.id,diff --git a/codex-rs/app-server-protocol/src/protocol/v2/tests.rs b/codex-rs/app-server-protocol/src/protocol/v2/tests.rsindex 96ba995770..85a95a2723 100644--- a/codex-rs/app-server-protocol/src/protocol/v2/tests.rs+++ b/codex-rs/app-server-protocol/src/protocol/v2/tests.rs@@ -2574,14 +2574,14 @@ fn core_turn_item_into_thread_item_converts_supported_variants() {let image_view_item = TurnItem::ImageView(ImageViewItem {id: "view-image-1".to_string(),- path: test_path_buf("/tmp/view-image.png").abs(),+ path: PathUri::from_abs_path(&test_path_buf("/tmp/view-image.png").abs()),});assert_eq!(ThreadItem::from(image_view_item),ThreadItem::ImageView {id: "view-image-1".to_string(),- path: test_path_buf("/tmp/view-image.png").abs(),+ path: LegacyAppPathString::from_abs_path(&test_path_buf("/tmp/view-image.png").abs()),});diff --git a/codex-rs/core/src/tools/handlers/view_image.rs b/codex-rs/core/src/tools/handlers/view_image.rsindex 09a6844f19..ca04ef470e 100644--- a/codex-rs/core/src/tools/handlers/view_image.rs+++ b/codex-rs/core/src/tools/handlers/view_image.rs@@ -24,7 +24,6 @@ use crate::tools::registry::CoreToolRuntime;use crate::tools::registry::ToolExecutor;use codex_tools::ToolName;use codex_tools::ToolSpec;-use codex_utils_path_uri::PathUri;pub struct ViewImageHandler {options: ViewImageToolOptions,@@ -140,36 +139,31 @@ impl ViewImageHandler {"view_image is unavailable in this session".to_string(),));};- // TODO(anp): Resolve tool paths using the selected environment's native path convention- // so view_image can support relative paths in foreign environments.- let cwd = turn_environment.cwd().to_abs_path().map_err(|err| {+ let path_uri = turn_environment.cwd().join(&path).map_err(|err| {FunctionCallError::RespondToModel(format!(- "environment cwd `{}` is not native to the Codex host: {err}",- turn_environment.cwd()+ "unable to resolve image path `{path}` against environment cwd `{}`: {err}",+ turn_environment.cwd(),))})?;- let abs_path = cwd.join(path);+ let model_visible_path = path_uri.inferred_native_path_string();let sandbox = turn.file_system_sandbox_context(/*additional_permissions*/ None,turn_environment.cwd(),);let fs = turn_environment.environment.get_filesystem();- let path_uri = PathUri::from_abs_path(&abs_path);let metadata = fs.get_metadata(&path_uri, Some(&sandbox)).await.map_err(|error| {FunctionCallError::RespondToModel(format!(- "unable to locate image at `{}`: {error}",- abs_path.display()+ "unable to locate image at `{model_visible_path}`: {error}"))})?;if !metadata.is_file {return Err(FunctionCallError::RespondToModel(format!(- "image path `{}` is not a file",- abs_path.display()+ "image path `{model_visible_path}` is not a file")));}let file_bytes = fs@@ -177,11 +171,9 @@ impl ViewImageHandler {.await.map_err(|error| {FunctionCallError::RespondToModel(format!(- "unable to read image at `{}`: {error}",- abs_path.display()+ "unable to read image at `{model_visible_path}`: {error}"))})?;- let event_path = abs_path.clone();let can_request_original_detail = can_request_original_image_detail(&turn.model_info);let use_original_detail =@@ -197,7 +189,7 @@ impl ViewImageHandler {let item = TurnItem::ImageView(ImageViewItem {id: call_id,- path: event_path,+ path: path_uri,});session.emit_turn_item_started(turn.as_ref(), &item).await;session.emit_turn_item_completed(turn.as_ref(), item).await;diff --git a/codex-rs/core/tests/suite/view_image.rs b/codex-rs/core/tests/suite/view_image.rsindex a660ec4da6..e0e52172fb 100644--- a/codex-rs/core/tests/suite/view_image.rs+++ b/codex-rs/core/tests/suite/view_image.rs@@ -29,7 +29,6 @@ use codex_protocol::protocol::Op;use codex_protocol::protocol::TurnEnvironmentSelection;use codex_protocol::user_input::UserInput;use codex_utils_path_uri::PathUri;-use core_test_support::PathBufExt;use core_test_support::PathExt;use core_test_support::get_remote_test_env;use core_test_support::responses;@@ -42,7 +41,6 @@ use core_test_support::responses::mount_sse_sequence;use core_test_support::responses::sse;use core_test_support::responses::start_mock_server;use core_test_support::skip_if_no_network;-use core_test_support::skip_if_wine_exec;use core_test_support::test_codex::TestCodex;use core_test_support::test_codex::local;use core_test_support::test_codex::test_codex;@@ -59,8 +57,6 @@ use serde_json::json;use std::fs;use std::io::Cursor;use std::path::PathBuf;-use std::time::SystemTime;-use std::time::UNIX_EPOCH;use tempfile::TempDir;use tokio::time::Duration;use wiremock::BodyPrintLimit;@@ -295,6 +291,7 @@ async fn view_image_tool_attaches_local_image() -> anyhow::Result<()> {let rel_path = "assets/example.png";let abs_path = cwd.join(rel_path);+ let path_uri = PathUri::from_abs_path(&abs_path);let original_width = 2304;let original_height = 864;write_workspace_png(@@ -369,20 +366,20 @@ async fn view_image_tool_attaches_local_image() -> anyhow::Result<()> {match item_started.expect("view image item started event emitted") {codex_protocol::items::TurnItem::ImageView(item) => {assert_eq!(item.id, call_id);- assert_eq!(item.path, abs_path);+ assert_eq!(item.path, path_uri);}other => panic!("expected ImageView item, got {other:?}"),}match item_completed.expect("view image item completed event emitted") {codex_protocol::items::TurnItem::ImageView(item) => {assert_eq!(item.id, call_id);- assert_eq!(item.path, abs_path);+ assert_eq!(item.path, path_uri);}other => panic!("expected ImageView item, got {other:?}"),}let legacy_event = legacy_event.expect("legacy view image event emitted");assert_eq!(legacy_event.call_id, call_id);- assert_eq!(legacy_event.path, abs_path);+ assert_eq!(legacy_event.path, path_uri);let req = mock.single_request();let body = req.body_json();@@ -557,8 +554,10 @@ async fn view_image_tool_applies_local_sandbox_read_denies() -> anyhow::Result<(.function_call_output_content_and_success(call_id).and_then(|(content, _)| content).context("sandboxed view_image error text present")?;- let expected_locate_prefix = format!("unable to locate image at `{}`:", denied_path.display());- let expected_read_prefix = format!("unable to read image at `{}`:", denied_path.display());+ let denied_path_display =+ PathUri::from_host_native_path(&denied_path)?.inferred_native_path_string();+ let expected_locate_prefix = format!("unable to locate image at `{denied_path_display}`:");+ let expected_read_prefix = format!("unable to read image at `{denied_path_display}`:");assert!(output_text.starts_with(&expected_locate_prefix)|| output_text.starts_with(&expected_read_prefix),@@ -570,8 +569,6 @@ async fn view_image_tool_applies_local_sandbox_read_denies() -> anyhow::Result<(#[tokio::test(flavor = "multi_thread", worker_threads = 2)]async fn view_image_routes_to_selected_remote_environment() -> anyhow::Result<()> {- // TODO(anp): Remove after remote-cwd fixtures use target-native paths.- skip_if_wine_exec!(Ok(()), "hardcodes a POSIX remote cwd");skip_if_no_network!(Ok(()));let Some(_remote_env) = get_remote_test_env() else {return Ok(());@@ -583,37 +580,26 @@ async fn view_image_routes_to_selected_remote_environment() -> anyhow::Result<()let local_cwd = TempDir::new()?;fs::write(local_cwd.path().join("remote.png"), b"not a remote image")?;let local_selection = local(local_cwd.path().abs());- let remote_cwd = PathBuf::from(format!(- "/tmp/codex-view-image-routing-{}",- SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis()- ))- .abs();- let image_path = remote_cwd.join("remote.png");- let remote_cwd_uri = PathUri::from_host_native_path(&remote_cwd)?;- test.fs()- .create_directory(- &remote_cwd_uri,- CreateDirectoryOptions { recursive: true },- /*sandbox*/ None,- )- .await?;+ let remote_cwd_uri = PathUri::from_abs_path(test.executor_environment().cwd());+ let image_path_uri = remote_cwd_uri.join("remote.png")?;let png = png_bytes(/*width*/ 1, /*height*/ 1, [0, 255, 0, 255])?;- let image_path_uri = PathUri::from_host_native_path(&image_path)?;test.fs().write_file(&image_path_uri, png, /*sandbox*/ None).await?;+ let absolute_image_path = image_path_uri.inferred_native_path_string();let remote_selection = TurnEnvironmentSelection {environment_id: REMOTE_ENVIRONMENT_ID.to_string(),- cwd: PathUri::from_abs_path(&remote_cwd),+ cwd: remote_cwd_uri,};- let call_id = "call-view-image-multi-env";+ let relative_call_id = "call-view-image-relative-multi-env";+ let absolute_call_id = "call-view-image-absolute-multi-env";let response_mock = mount_sse_sequence(&server,vec![sse(vec![ev_response_created("resp-1"),ev_function_call(- call_id,+ relative_call_id,"view_image",&json!({"path": "remote.png",@@ -625,9 +611,22 @@ async fn view_image_routes_to_selected_remote_environment() -> anyhow::Result<()]),sse(vec![ev_response_created("resp-2"),- ev_assistant_message("msg-1", "done"),+ ev_function_call(+ absolute_call_id,+ "view_image",+ &json!({+ "path": absolute_image_path,+ "environment_id": REMOTE_ENVIRONMENT_ID,+ })+ .to_string(),+ ),ev_completed("resp-2"),]),+ sse(vec![+ ev_response_created("resp-3"),+ ev_assistant_message("msg-1", "done"),+ ev_completed("resp-3"),+ ]),],).await;@@ -638,30 +637,32 @@ async fn view_image_routes_to_selected_remote_environment() -> anyhow::Result<()).await?;- let output = response_mock+ let request = response_mock.last_request().context("missing request containing view_image output")?- .function_call_output(call_id).clone();- let output_items = output- .get("output")- .and_then(Value::as_array)- .context("view_image output should be content items")?;- assert_eq!(output_items.len(), 1);- let image_url = output_items[0]- .get("image_url")- .and_then(Value::as_str)- .context("view_image output should include image_url")?;- assert!(- image_url.starts_with("data:image/png;base64,"),- "unexpected image_url: {image_url}",- );+ for call_id in [relative_call_id, absolute_call_id] {+ let output = request.function_call_output(call_id);+ let output_items = output+ .get("output")+ .and_then(Value::as_array)+ .context("view_image output should be content items")?;+ assert_eq!(output_items.len(), 1);+ let image_url = output_items[0]+ .get("image_url")+ .and_then(Value::as_str)+ .context("view_image output should include image_url")?;+ assert!(+ image_url.starts_with("data:image/png;base64,"),+ "unexpected image_url: {image_url}",+ );+ }test.fs().remove(- &remote_cwd_uri,+ &image_path_uri,RemoveOptions {- recursive: true,+ recursive: false,force: true,},/*sandbox*/ None,@@ -1174,7 +1175,8 @@ async fn view_image_tool_errors_when_path_is_directory() -> anyhow::Result<()> {.function_call_output_content_and_success(call_id).and_then(|(content, _)| content).expect("output text present");- let expected_message = format!("image path `{}` is not a file", abs_path.display());+ let expected_path = PathUri::from_host_native_path(&abs_path)?.inferred_native_path_string();+ let expected_message = format!("image path `{expected_path}` is not a file");assert_eq!(output_text, expected_message);assert!(@@ -1253,19 +1255,26 @@ async fn view_image_tool_turns_invalid_image_into_placeholder() -> anyhow::Resulasync fn view_image_tool_errors_when_file_missing() -> anyhow::Result<()> {skip_if_no_network!(Ok(()));+ let remote_test_env = get_remote_test_env();+ println!("view_image missing-file test exec-server environment: {remote_test_env:?}");+let server = start_mock_server().await;let mut builder = test_codex();let test = builder.build_with_remote_env(&server).await?;let TestCodex {codex,- config,session_configured,..} = &test;let rel_path = "missing/example.png";- let abs_path = config.cwd.join(rel_path);+ // Under wine-exec, the executor cwd is stored as a host-compatible `/C:/...`+ // projection. Reconstruct its `PathUri` so the expected error uses the selected+ // environment's native Windows spelling, matching the handler.+ let expected_path = PathUri::from_abs_path(test.executor_environment().cwd())+ .join(rel_path)?+ .inferred_native_path_string();let call_id = "view-image-missing";let arguments = serde_json::json!({ "path": rel_path }).to_string();@@ -1309,7 +1318,7 @@ async fn view_image_tool_errors_when_file_missing() -> anyhow::Result<()> {.function_call_output_content_and_success(call_id).and_then(|(content, _)| content).expect("output text present");- let expected_prefix = format!("unable to locate image at `{}`:", abs_path.display());+ let expected_prefix = format!("unable to locate image at `{expected_path}`:");assert!(output_text.starts_with(&expected_prefix),"expected error to start with `{expected_prefix}` but got `{output_text}`"diff --git a/codex-rs/protocol/src/items.rs b/codex-rs/protocol/src/items.rsindex 76bc0e3992..508d71d4be 100644--- a/codex-rs/protocol/src/items.rs+++ b/codex-rs/protocol/src/items.rs@@ -25,6 +25,7 @@ use crate::user_input::ByteRange;use crate::user_input::TextElement;use crate::user_input::UserInput;use codex_utils_absolute_path::AbsolutePathBuf;+use codex_utils_path_uri::PathUri;use quick_xml::de::from_str as from_xml_str;use quick_xml::se::to_string as to_xml_string;use schemars::JsonSchema;@@ -138,7 +139,11 @@ pub struct WebSearchItem {#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema, PartialEq)]pub struct ImageViewItem {pub id: String,- pub path: AbsolutePathBuf,+ /// Path resolved within the selected execution environment.+ ///+ /// This core protocol type is not exposed directly in the app-server API.+ /// App-server converts the path to `LegacyAppPathString` at its boundary.+ pub path: PathUri,}#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema, PartialEq, Eq)]diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rsindex 6e93dc9120..52464f7067 100644--- a/codex-rs/protocol/src/protocol.rs+++ b/codex-rs/protocol/src/protocol.rs@@ -3399,8 +3399,11 @@ pub struct ExecCommandEndEvent {pub struct ViewImageToolCallEvent {/// Identifier for the originating tool call.pub call_id: String,- /// Local filesystem path provided to the tool.- pub path: AbsolutePathBuf,+ /// Filesystem path resolved for the selected environment.+ ///+ /// This core event is not exposed directly in the app-server API. App-server+ /// converts the path to `LegacyAppPathString` when building its public item.+ pub path: PathUri,}#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, JsonSchema, TS)]diff --git a/codex-rs/tui/src/app/agent_status_feed.rs b/codex-rs/tui/src/app/agent_status_feed.rsindex 544c0b7172..eb14551d5a 100644--- a/codex-rs/tui/src/app/agent_status_feed.rs+++ b/codex-rs/tui/src/app/agent_status_feed.rs@@ -182,7 +182,8 @@ fn activity_summary(item: &ThreadItem) -> Option<String> {return bounded_summary(&format!("Web search: {query}"));}ThreadItem::ImageView { path, .. } => {- return bounded_summary(&format!("Viewed {}", path.display()));+ let path = path.render_for_ui();+ return bounded_summary(&format!("Viewed {path}"));}ThreadItem::ImageGeneration { .. } => return Some("Generated an image".to_string()),ThreadItem::EnteredReviewMode { .. } => return Some("Entered review mode".to_string()),diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__foreign_image_attachment_history_snapshot.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__foreign_image_attachment_history_snapshot.snapnew file mode 100644index 0000000000..1c2102e4ce--- /dev/null+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__foreign_image_attachment_history_snapshot.snap@@ -0,0 +1,7 @@+---+source: tui/src/chatwidget/tests/exec_flow.rs+assertion_line: 877+expression: combined+---+• Viewed Image+ └ C:\workspace\assets\example.pngdiff --git a/codex-rs/tui/src/chatwidget/tests/exec_flow.rs b/codex-rs/tui/src/chatwidget/tests/exec_flow.rsindex 4f7d225dd8..99190ec726 100644--- a/codex-rs/tui/src/chatwidget/tests/exec_flow.rs+++ b/codex-rs/tui/src/chatwidget/tests/exec_flow.rs@@ -862,6 +862,21 @@ async fn view_image_tool_call_adds_history_cell() {assert_chatwidget_snapshot!("local_image_attachment_history_snapshot", combined);}+#[tokio::test]+async fn view_image_tool_call_preserves_foreign_path() {+ let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;+ let image_path: LegacyAppPathString =+ serde_json::from_value(json!(r"C:\workspace\assets\example.png"))+ .expect("valid legacy app path string");++ handle_view_image_tool_call(&mut chat, "call-image", image_path);++ let cells = drain_insert_history(&mut rx);+ assert_eq!(cells.len(), 1, "expected a single history cell");+ let combined = lines_to_single_string(&cells[0]);+ assert_chatwidget_snapshot!("foreign_image_attachment_history_snapshot", combined);+}+#[tokio::test]async fn image_generation_call_adds_history_cell() {let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;diff --git a/codex-rs/tui/src/chatwidget/tests/helpers.rs b/codex-rs/tui/src/chatwidget/tests/helpers.rsindex 06c440bfb2..5e23e9f96a 100644--- a/codex-rs/tui/src/chatwidget/tests/helpers.rs+++ b/codex-rs/tui/src/chatwidget/tests/helpers.rs@@ -679,7 +679,7 @@ pub(super) fn handle_patch_apply_end(pub(super) fn handle_view_image_tool_call(chat: &mut ChatWidget,call_id: impl Into<String>,- path: AbsolutePathBuf,+ path: impl Into<LegacyAppPathString>,) {chat.handle_server_notification(ServerNotification::ItemCompleted(ItemCompletedNotification {@@ -688,7 +688,7 @@ pub(super) fn handle_view_image_tool_call(completed_at_ms: 0,item: AppServerThreadItem::ImageView {id: call_id.into(),- path,+ path: path.into(),},}),/*replay_kind*/ None,diff --git a/codex-rs/tui/src/chatwidget/tool_lifecycle.rs b/codex-rs/tui/src/chatwidget/tool_lifecycle.rsindex e37c44a4fa..99d84d155b 100644--- a/codex-rs/tui/src/chatwidget/tool_lifecycle.rs+++ b/codex-rs/tui/src/chatwidget/tool_lifecycle.rs@@ -4,6 +4,7 @@//! events as transcript cells.use super::*;+use codex_utils_path_uri::LegacyAppPathString;impl ChatWidget {pub(super) fn on_patch_apply_begin(&mut self, changes: HashMap<PathBuf, FileChange>) {@@ -11,7 +12,7 @@ impl ChatWidget {self.add_to_history(history_cell::new_patch_event(changes, &self.config.cwd));}- pub(super) fn on_view_image_tool_call(&mut self, path: AbsolutePathBuf) {+ pub(super) fn on_view_image_tool_call(&mut self, path: LegacyAppPathString) {self.record_visible_turn_activity();self.flush_answer_stream_with_separator();self.add_to_history(history_cell::new_view_image_tool_call(diff --git a/codex-rs/tui/src/history_cell/patches.rs b/codex-rs/tui/src/history_cell/patches.rsindex 8a2dcb33f3..7892b7c4d7 100644--- a/codex-rs/tui/src/history_cell/patches.rs+++ b/codex-rs/tui/src/history_cell/patches.rs@@ -1,6 +1,7 @@//! Patch summaries and image-tool transcript helpers.use super::*;+use codex_utils_path_uri::LegacyAppPathString;#[derive(Debug)]pub(crate) struct PatchHistoryCell {@@ -60,8 +61,12 @@ pub(crate) fn new_patch_apply_failure(stderr: String) -> PlainHistoryCell {PlainHistoryCell { lines }}-pub(crate) fn new_view_image_tool_call(path: AbsolutePathBuf, cwd: &Path) -> PlainHistoryCell {- let display_path = display_path_for(path.as_path(), cwd);+pub(crate) fn new_view_image_tool_call(path: LegacyAppPathString, cwd: &Path) -> PlainHistoryCell {+ let display_path = path+ .to_inferred_path_uri()+ .and_then(|path| path.to_abs_path().ok())+ .map(|path| display_path_for(path.as_path(), cwd))+ .unwrap_or_else(|| path.into_string());let lines: Vec<Line<'static>> = vec![vec!["• ".dim(), "Viewed Image".bold()].into(),diff --git a/codex-rs/tui/src/thread_transcript.rs b/codex-rs/tui/src/thread_transcript.rsindex 13b2a3a389..cdffaab27c 100644--- a/codex-rs/tui/src/thread_transcript.rs+++ b/codex-rs/tui/src/thread_transcript.rs@@ -203,7 +203,8 @@ fn fallback_transcript_cell(item: &ThreadItem) -> Option<PlainHistoryCell> {vec![vec!["web search: ".dim(), query.clone().into()].into()]}ThreadItem::ImageView { path, .. } => {- vec![format!("image: {}", path.as_path().display()).dim().into()]+ let path = path.render_for_ui();+ vec![format!("image: {path}").dim().into()]}ThreadItem::ImageGeneration {status, saved_path, ..diff --git a/codex-rs/utils/path-uri/src/api_path_string.rs b/codex-rs/utils/path-uri/src/api_path_string.rsindex e4fdbe7c27..bc63990679 100644--- a/codex-rs/utils/path-uri/src/api_path_string.rs+++ b/codex-rs/utils/path-uri/src/api_path_string.rs@@ -86,6 +86,17 @@ impl LegacyAppPathString {PathUri::try_from(self.clone()).ok()}+ /// Renders this API path for display in a user interface.+ ///+ /// Absolute paths are normalized using their inferred native convention.+ /// Strings that cannot be interpreted as absolute paths retain their raw+ /// API spelling.+ pub fn render_for_ui(&self) -> String {+ self.to_inferred_path_uri()+ .map(|path| path.inferred_native_path_string())+ .unwrap_or_else(|| self.0.clone())+ }+/// Parses this API string as a host-native absolute path.pub fn to_inferred_abs_path(&self) -> Option<AbsolutePathBuf> {AbsolutePathBuf::try_from(self.clone()).ok()diff --git a/codex-rs/utils/path-uri/src/api_path_string_tests.rs b/codex-rs/utils/path-uri/src/api_path_string_tests.rsindex c71a65abf3..c6ee1ea6ae 100644--- a/codex-rs/utils/path-uri/src/api_path_string_tests.rs+++ b/codex-rs/utils/path-uri/src/api_path_string_tests.rs@@ -458,6 +458,7 @@ fn converts_absolute_api_paths_using_the_inferred_convention() {path.to_inferred_path_uri(),Some(PathUri::parse(expected_uri).expect("expected URI should parse")),);+ assert_eq!(path.render_for_ui(), raw_path);assert_eq!(PathUri::try_from(path.clone()),path.to_path_uri(convention)