From 9032a50981abbad92f7c6d097fc0daa4295fd301 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 17 Feb 2026 00:44:51 +0000 Subject: [PATCH] refactor: reuse sandbox path expansion in apply-patch --- src/agents/apply-patch.ts | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/src/agents/apply-patch.ts b/src/agents/apply-patch.ts index f1dadcee556..d07c419efa6 100644 --- a/src/agents/apply-patch.ts +++ b/src/agents/apply-patch.ts @@ -1,11 +1,10 @@ -import fs from "node:fs/promises"; -import os from "node:os"; -import path from "node:path"; import type { AgentTool } from "@mariozechner/pi-agent-core"; import { Type } from "@sinclair/typebox"; -import { applyUpdateHunk } from "./apply-patch-update.js"; -import { assertSandboxPath } from "./sandbox-paths.js"; +import fs from "node:fs/promises"; +import path from "node:path"; import type { SandboxFsBridge } from "./sandbox/fs-bridge.js"; +import { applyUpdateHunk } from "./apply-patch-update.js"; +import { assertSandboxPath, resolveSandboxInputPath } from "./sandbox-paths.js"; const BEGIN_PATCH_MARKER = "*** Begin Patch"; const END_PATCH_MARKER = "*** End Patch"; @@ -284,29 +283,8 @@ async function resolvePatchPath( }; } -const UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g; - -function normalizeUnicodeSpaces(value: string): string { - return value.replace(UNICODE_SPACES, " "); -} - -function expandPath(filePath: string): string { - const normalized = normalizeUnicodeSpaces(filePath); - if (normalized === "~") { - return os.homedir(); - } - if (normalized.startsWith("~/")) { - return os.homedir() + normalized.slice(1); - } - return normalized; -} - function resolvePathFromCwd(filePath: string, cwd: string): string { - const expanded = expandPath(filePath); - if (path.isAbsolute(expanded)) { - return path.normalize(expanded); - } - return path.resolve(cwd, expanded); + return path.normalize(resolveSandboxInputPath(filePath, cwd)); } function toDisplayPath(resolved: string, cwd: string): string {