The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 18:30 UTC
fix(server): workspace search keeps backslashes in POSIX file names (#35672)
Julius Marminge committed
Nov 12, 2026 at 15:23 UTC
1e20361c91fb27975c4b6168ab040b95f1e9f08b
2 files changed
+47
-16
apps/server/src/workspace/WorkspaceSearchIndex.test.ts
+25
@@ -113,6 +113,31 @@ it.effect("fetches past a first page of Git-ignored results", () =>
113
).pipe(Effect.provide(testLayer)),
114
);
115
116
+// A backslash is a file name character on Linux and macOS, so only Windows may treat it as a separator.
117
+it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
118
+ "keeps a backslash in a POSIX folder name as part of the search result path",
119
+ () =>
120
+ Effect.scoped(
121
+ Effect.gen(function* () {
122
+ const items = [fileItem("dir\\one/report.txt")];
123
+ const finder = {
124
+ destroy: vi.fn(),
125
+ waitForIndexReady: vi.fn(async () => ({ ok: true as const, value: true })),
126
+ fileSearch: vi.fn(() => ({
127
+ ok: true as const,
128
+ value: { items, scores: [], totalMatched: 1, totalFiles: 1 },
129
+ })),
130
+ } as unknown as FileFinder;
131
+ vi.spyOn(FileFinder, "create").mockReturnValueOnce({ ok: true, value: finder });
132
+
133
+ const searchIndex = yield* WorkspaceSearchIndex.make("/workspace/project");
134
+ const result = yield* searchIndex.search("report", 50, "file");
135
+
136
+ expect(result.entries).toEqual([{ kind: "file", path: "dir\\one/report.txt" }]);
137
+ }),
138
+ ),
139
+);
140
+
141
it.effect("continues whole-word searches after a filtered grep page", () =>
142
Effect.scoped(
143
Effect.gen(function* () {
apps/server/src/workspace/WorkspaceSearchIndex.ts
+22
-16
@@ -22,6 +22,7 @@ import type {
22
ProjectSearchContentsResult,
23
ProjectSearchEntriesResult,
24
} from "@t3tools/contracts";
25
+import * as HostProcess from "@t3tools/shared/HostProcess";
26
import { isProjectFaviconPath } from "@t3tools/shared/projectFavicon";
27
28
import * as VcsProcess from "../vcs/VcsProcess.ts";
@@ -120,8 +121,9 @@ export class WorkspaceSearchIndex extends Context.Service<
121
}
122
>()("t3/workspace/WorkspaceSearchIndex") {}
123
123
-function toPosixPath(input: string): string {
124
- return input.replaceAll("\\", "/");
124
+// Only the host separator becomes `/`: on POSIX `\` is a file name character.
125
+function toPosixPath(input: string, hostIsWindows: boolean): string {
126
+ return hostIsWindows ? input.replaceAll("\\", "/") : input;
127
}
128
129
function trimDirectorySeparator(input: string): string {
@@ -133,8 +135,8 @@ function parentPathOf(input: string): string | undefined {
135
return separatorIndex === -1 ? undefined : input.slice(0, separatorIndex);
136
}
137
136
-function toProjectEntry(item: MixedItem): ProjectEntry | null {
137
- const normalizedPath = trimDirectorySeparator(toPosixPath(item.item.relativePath));
138
+function toProjectEntry(item: MixedItem, hostIsWindows: boolean): ProjectEntry | null {
139
+ const normalizedPath = trimDirectorySeparator(toPosixPath(item.item.relativePath, hostIsWindows));
140
if (!normalizedPath) {
141
return null;
142
}
@@ -145,13 +147,13 @@ function toProjectEntry(item: MixedItem): ProjectEntry | null {
147
};
148
}
149
148
-function toFileEntry(item: FileItem): ProjectEntry | null {
149
- const normalizedPath = trimDirectorySeparator(toPosixPath(item.relativePath));
150
+function toFileEntry(item: FileItem, hostIsWindows: boolean): ProjectEntry | null {
151
+ const normalizedPath = trimDirectorySeparator(toPosixPath(item.relativePath, hostIsWindows));
152
return normalizedPath ? { path: normalizedPath, kind: "file" } : null;
153
}
154
153
-function toDirectoryEntry(item: DirItem): ProjectEntry | null {
154
- const normalizedPath = trimDirectorySeparator(toPosixPath(item.relativePath));
155
+function toDirectoryEntry(item: DirItem, hostIsWindows: boolean): ProjectEntry | null {
156
+ const normalizedPath = trimDirectorySeparator(toPosixPath(item.relativePath, hostIsWindows));
157
return normalizedPath ? { path: normalizedPath, kind: "directory" } : null;
158
}
159
@@ -160,10 +162,11 @@ type SearchPage<I> = { readonly items: ReadonlyArray<I>; readonly totalMatched:
162
function mapFileSearchResult(
163
result: SearchPage<FileItem>,
164
limit: number,
165
+ hostIsWindows: boolean,
166
imageOnly = false,
167
): ProjectSearchEntriesResult {
168
const entries = result.items.flatMap((item) => {
166
- const entry = toFileEntry(item);
169
+ const entry = toFileEntry(item, hostIsWindows);
170
return entry && (!imageOnly || isProjectFaviconPath(entry.path)) ? [entry] : [];
171
});
172
return {
@@ -175,9 +178,10 @@ function mapFileSearchResult(
178
function mapDirectorySearchResult(
179
result: SearchPage<DirItem>,
180
limit: number,
181
+ hostIsWindows: boolean,
182
): ProjectSearchEntriesResult {
183
const entries = result.items.flatMap((item) => {
180
- const entry = toDirectoryEntry(item);
184
+ const entry = toDirectoryEntry(item, hostIsWindows);
185
return entry ? [entry] : [];
186
});
187
const rootDirectoryCount = result.items.some((item) => item.relativePath.length === 0) ? 1 : 0;
@@ -190,10 +194,11 @@ function mapDirectorySearchResult(
194
function mapMixedSearchResult(
195
result: SearchPage<MixedItem>,
196
limit: number,
197
+ hostIsWindows: boolean,
198
): { readonly entries: ProjectEntry[]; readonly truncated: boolean } {
199
const entries: ProjectEntry[] = [];
200
for (const item of result.items) {
196
- const entry = toProjectEntry(item);
201
+ const entry = toProjectEntry(item, hostIsWindows);
202
if (entry) {
203
entries.push(entry);
204
}
@@ -388,6 +393,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
393
cwd: string,
394
variant: WorkspaceSearchIndexVariant = "paths",
395
) {
396
+ const hostIsWindows = yield* HostProcess.isWindows;
397
const finder = yield* Effect.acquireRelease(createFinder(cwd, variant), (finder) =>
398
Effect.try({
399
try: () => finder.destroy(),
@@ -519,7 +525,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
525
(pageSize) => finder.mixedSearch("", { pageSize }),
526
mixedItemPath,
527
);
522
- const mapped = mapMixedSearchResult(result, WORKSPACE_INDEX_MAX_ENTRIES);
528
+ const mapped = mapMixedSearchResult(result, WORKSPACE_INDEX_MAX_ENTRIES, hostIsWindows);
529
const sortedEntries = withDirectoryAncestors(mapped.entries).toSorted((left, right) =>
530
left.path.localeCompare(right.path),
531
);
@@ -547,7 +553,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
553
(size) => finder.fileSearch(query, { pageSize: size }),
554
(item) => item.relativePath,
555
);
550
- return mapFileSearchResult(result, limit, imageOnly);
556
+ return mapFileSearchResult(result, limit, hostIsWindows, imageOnly);
557
}
558
if (kind === "directory") {
559
const result = yield* searchVisible(
@@ -557,7 +563,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
563
(size) => finder.directorySearch(query, { pageSize: size }),
564
(item) => item.relativePath,
565
);
560
- return mapDirectorySearchResult(result, limit);
566
+ return mapDirectorySearchResult(result, limit, hostIsWindows);
567
}
568
const result = yield* searchVisible(
569
query,
@@ -566,7 +572,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
572
(size) => finder.mixedSearch(query, { pageSize: size }),
573
mixedItemPath,
574
);
569
- return mapMixedSearchResult(result, limit);
575
+ return mapMixedSearchResult(result, limit, hostIsWindows);
576
});
577
578
const search: WorkspaceSearchIndex["Service"]["search"] = Effect.fn(
@@ -626,7 +632,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
632
// fff reports hits past its 512-char lineContent cap with no ranges, so whole words can't be verified there.
633
if (input.wholeWord && matchRanges.length === 0) continue;
634
matches.push({
629
- path: toPosixPath(match.relativePath),
635
+ path: toPosixPath(match.relativePath, hostIsWindows),
636
lineNumber: match.lineNumber,
637
lineContent: match.lineContent,
638
matchRanges,