fix: improve file URL handling and enhance image loading logic

- Added handling for file URLs using fileURLToPath for proper resolution.
- Updated logic to skip relative path resolution if ref.resolved is already absolute.
- Enhanced cap calculation for image loading to handle undefined maxBytes more gracefully.
This commit is contained in:
Tyler Yust
2026-01-17 03:20:02 -08:00
committed by Peter Steinberger
parent 8d74578ceb
commit 7bfc77db25
2 changed files with 6 additions and 2 deletions

View File

@@ -163,6 +163,8 @@ export async function loadImageFromRef(
// For file paths, resolve relative to the appropriate root:
// - When sandbox is enabled, resolve relative to sandboxRoot for security
// - Otherwise, resolve relative to workspaceDir
// Note: ref.resolved may already be absolute (e.g., after ~ expansion in detectImageReferences),
// in which case we skip relative resolution.
if (ref.type === "path" && !path.isAbsolute(targetPath)) {
const resolveRoot = options?.sandboxRoot ?? workspaceDir;
targetPath = path.resolve(resolveRoot, targetPath);