core: resolve view_image paths in selected environment (#29526)

## Why

view_image needs to support foreign OS remote executors.

## What

- resolve image paths against the selected environment as `PathUri` and
read them through that environment's filesystem
- keep app-server's public path field wire-compatible as
`LegacyAppPathString`, with purpose-specific UI rendering
- cover relative and absolute target-native paths in the core
integration test and run the full `view_image` suite under wine-exec
without skips
This commit is contained in:
Adam Perry @ OpenAI authored and GitHub committed 2026-06-23 19:52:37 +00:00
1 parent c660e2b644
commit 510bce9927
35 files changed
+155 -101

No files matched your search

+8 -16
View File
@@ -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;