Skip to content

Commit 323dcdc

Browse files
t3dotggclaude
andcommitted
fix(cli): project paths split on the right separator per platform
On POSIX a backslash is a file name character, so /work/app\backup no longer counts as inside /work/app. A project at a filesystem root now matches paths below it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent bba4f43 commit 323dcdc

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎apps/server/src/cli/thread.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,24 @@ describe("matchProject", () => {
225225
it("matches a path inside one of the project's worktrees", () => {
226226
assert.equal(match("/home/me/.t3/worktrees/app/a1b2/src"), "app");
227227
});
228+
229+
it("splits POSIX paths on / only and handles root projects", () => {
230+
// A backslash is a normal file name character on POSIX.
231+
assert.equal(match("/code/app\\backup"), undefined);
232+
const rooted = { projects: [makeProject("root", "/")], threads: [] };
233+
assert.equal(matchProject(rooted, "/srv/site", "/srv/site")?.id, "root");
234+
});
235+
236+
it("splits Windows paths on backslashes", () => {
237+
const windows = {
238+
projects: [makeProject("win", "C:\\code\\app"), makeProject("drive", "D:\\")],
239+
threads: [],
240+
};
241+
assert.equal(matchProject(windows, "C:\\code\\app\\src", "C:\\code\\app\\src")?.id, "win");
242+
assert.equal(
243+
matchProject(windows, "C:\\code\\application", "C:\\code\\application")?.id,
244+
undefined,
245+
);
246+
assert.equal(matchProject(windows, "D:\\data", "D:\\data")?.id, "drive");
247+
});
228248
});

‎apps/server/src/cli/thread.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
ThreadId,
3232
} from "@t3tools/contracts";
3333
import { buildTemporaryWorktreeBranchName } from "@t3tools/shared/git";
34-
import { normalizeProjectPathForComparison } from "@t3tools/shared/path";
34+
import { isWindowsAbsolutePath, normalizeProjectPathForComparison } from "@t3tools/shared/path";
3535
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
3636
import { fromLenientJson } from "@t3tools/shared/schemaJson";
3737
import { isModelSelectionProviderEnabled } from "@t3tools/shared/serverSettings";
@@ -321,8 +321,16 @@ const readMessage = Effect.fn("readThreadMessage")(function* (message: string) {
321321
return trimmed;
322322
});
323323

324-
const isPathWithin = (root: string, target: string) =>
325-
target === root || target.startsWith(`${root}/`) || target.startsWith(`${root}\\`);
324+
/**
325+
* Whether `target` is `root` or inside it. Both are normalized. Windows paths
326+
* split on `\` and POSIX paths on `/`, where a backslash is a normal file
327+
* name character. A root like `/` or `c:\` already ends in its separator.
328+
*/
329+
const isPathWithin = (root: string, target: string) => {
330+
if (target === root) return true;
331+
const separator = isWindowsAbsolutePath(root) ? "\\" : "/";
332+
return target.startsWith(root.endsWith(separator) ? root : `${root}${separator}`);
333+
};
326334

327335
/**
328336
* Matches a project id, or a path inside a project folder or inside one of

0 commit comments

Comments
 (0)