Skip to content

Commit eb1e9d7

Browse files
committed
fix(tools): keep Windows path normalizer internal
1 parent c854807 commit eb1e9d7

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

src/agents/sessions/tools/path-utils.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises";
22
import { tmpdir } from "node:os";
33
import { join } from "node:path";
44
import { afterEach, describe, expect, it } from "vitest";
5-
import { normalizeWindowsPosixDrivePath, resolveReadPath } from "./path-utils.js";
5+
import { resolveReadPath } from "./path-utils.js";
6+
import { normalizeWindowsPosixDrivePath } from "./windows-posix-path.js";
67

78
describe("normalizeWindowsPosixDrivePath", () => {
89
it.each([

src/agents/sessions/tools/path-utils.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { accessSync, constants } from "node:fs";
77
import * as os from "node:os";
88
import { isAbsolute, resolve as resolvePath } from "node:path";
99
import { fileURLToPath } from "node:url";
10+
import { normalizeWindowsPosixDrivePath } from "./windows-posix-path.js";
1011

1112
const UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
1213
const NARROW_NO_BREAK_SPACE = "\u202F";
@@ -42,23 +43,6 @@ function normalizeAtPrefix(filePath: string): string {
4243
return filePath.startsWith("@") ? filePath.slice(1) : filePath;
4344
}
4445

45-
const WINDOWS_POSIX_DRIVE_PATH_RE = /^\/(?:cygdrive\/|mnt\/)?([a-z])(?:\/(.*))?$/i;
46-
47-
export function normalizeWindowsPosixDrivePath(
48-
filePath: string,
49-
platform: NodeJS.Platform = process.platform,
50-
): string {
51-
if (platform !== "win32") {
52-
return filePath;
53-
}
54-
const match = WINDOWS_POSIX_DRIVE_PATH_RE.exec(filePath);
55-
if (!match?.[1]) {
56-
return filePath;
57-
}
58-
const root = `${match[1].toUpperCase()}:\\`;
59-
return match[2] ? `${root}${match[2].replaceAll("/", "\\")}` : root;
60-
}
61-
6246
function expandPath(filePath: string): string {
6347
const normalized = normalizeWindowsPosixDrivePath(
6448
normalizeUnicodeSpaces(normalizeAtPrefix(filePath)),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const WINDOWS_POSIX_DRIVE_PATH_RE = /^\/(?:cygdrive\/|mnt\/)?([a-z])(?:\/(.*))?$/i;
2+
3+
export function normalizeWindowsPosixDrivePath(
4+
filePath: string,
5+
platform: NodeJS.Platform = process.platform,
6+
): string {
7+
if (platform !== "win32") {
8+
return filePath;
9+
}
10+
const match = WINDOWS_POSIX_DRIVE_PATH_RE.exec(filePath);
11+
if (!match?.[1]) {
12+
return filePath;
13+
}
14+
const root = `${match[1].toUpperCase()}:\\`;
15+
return match[2] ? `${root}${match[2].replaceAll("/", "\\")}` : root;
16+
}

0 commit comments

Comments
 (0)