Skip to content

Commit ae169cb

Browse files
Jose Mussacursoragent
andcommitted
fix: sort glob results for deterministic file order
fast-glob returns files in arbitrary filesystem traversal order, which varies across runs. This caused the bash tool description (which lists available files) to differ between calls with the same directory, breaking prompt cache hits. Sort the results from both `streamFiles` and `getFilePaths` so the file list is always in stable lexicographic order. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b222e47 commit ae169cb

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/files/loader.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ export async function* streamFiles(
3838
const { source, include = "**/*" } = options.uploadDirectory;
3939
const absoluteSource = path.resolve(source);
4040

41-
const foundPaths = await fg(include, {
42-
cwd: absoluteSource,
43-
dot: true,
44-
onlyFiles: true,
45-
ignore: ["**/node_modules/**", "**/.git/**"],
46-
});
41+
const foundPaths = (
42+
await fg(include, {
43+
cwd: absoluteSource,
44+
dot: true,
45+
onlyFiles: true,
46+
ignore: ["**/node_modules/**", "**/.git/**"],
47+
})
48+
).sort();
4749

4850
for (const relativePath of foundPaths) {
4951
if (yieldedPaths.has(relativePath)) {
@@ -69,12 +71,14 @@ export async function getFilePaths(
6971
const { source, include = "**/*" } = options.uploadDirectory;
7072
const absoluteSource = path.resolve(source);
7173

72-
const foundPaths = await fg(include, {
73-
cwd: absoluteSource,
74-
dot: true,
75-
onlyFiles: true,
76-
ignore: ["**/node_modules/**", "**/.git/**"],
77-
});
74+
const foundPaths = (
75+
await fg(include, {
76+
cwd: absoluteSource,
77+
dot: true,
78+
onlyFiles: true,
79+
ignore: ["**/node_modules/**", "**/.git/**"],
80+
})
81+
).sort();
7882
paths.push(...foundPaths);
7983
}
8084

0 commit comments

Comments
 (0)