Skip to content

Commit 52eba84

Browse files
ScottN-PVclaude
andauthored
fix(provider-cursor): a symlinked skills root is no longer scanned twice (pingdotgg#18664)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 10db5e4 commit 52eba84

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎packages/provider-cursor/src/server/skills.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,42 @@ describe("Cursor skills", () => {
229229
}),
230230
));
231231

232+
it.skipIf(!symlinksSupported)(
233+
"scans a skills root linked to another root only once",
234+
async () =>
235+
await runNode(
236+
Effect.gen(function* () {
237+
const fileSystem = yield* FileSystem.FileSystem;
238+
const path = yield* Path.Path;
239+
const userHome = yield* fileSystem.makeTempDirectoryScoped({
240+
directory: NodeOS.tmpdir(),
241+
prefix: "cursor-skills-home-",
242+
});
243+
// More than half the entry budget, so a second walk of the same tree runs out.
244+
const claudeRoot = path.join(userHome, ".claude", "skills");
245+
yield* fileSystem.makeDirectory(path.join(claudeRoot, "review"), { recursive: true });
246+
yield* fileSystem.writeFileString(
247+
path.join(claudeRoot, "review", "SKILL.md"),
248+
"---\n---\n",
249+
);
250+
yield* Effect.forEach(
251+
Array.from({ length: 6_000 }, (_, index) => path.join(claudeRoot, `entry-${index}`)),
252+
(file) => fileSystem.writeFileString(file, ""),
253+
{ concurrency: 64, discard: true },
254+
);
255+
yield* fileSystem.makeDirectory(path.join(userHome, ".agents"), { recursive: true });
256+
yield* fileSystem.symlink(claudeRoot, path.join(userHome, ".agents", "skills"));
257+
258+
const result = yield* probeCursorSkills(undefined, { HOME: userHome }).pipe(
259+
Effect.result,
260+
);
261+
expect(result._tag).toBe("Success");
262+
const skills = yield* discoverCursorSkills(undefined, { HOME: userHome });
263+
expect(skills.map((skill) => `${skill.scope}:${skill.name}`)).toEqual(["user:review"]);
264+
}),
265+
),
266+
);
267+
232268
it.skipIf(!symlinksSupported)(
233269
"treats a symlinked skill outside the root as a package boundary",
234270
async () =>

‎packages/provider-cursor/src/server/skills.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,19 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (
127127
readonly directory: string;
128128
readonly scope: "user" | "project";
129129
readonly budget: CursorSkillScanBudget;
130+
/** Real paths of the roots already walked in this scan. */
131+
readonly scannedRoots: Set<string>;
130132
}): Effect.fn.Return<ReadonlyArray<ServerProviderSkill>, never, FileSystem.FileSystem | Path.Path> {
131133
const fileSystem = yield* FileSystem.FileSystem;
132134
const path = yield* Path.Path;
133135
const skills: ServerProviderSkill[] = [];
134136
if (input.budget.exhausted) return skills;
135137
const rootDirectory = yield* orUndefined(fileSystem.realPath(input.directory), input.budget);
136138
if (!rootDirectory) return skills;
139+
// A root linked to another one, such as `~/.agents/skills` pointing at `~/.claude/skills`,
140+
// is the same tree: walking it again would charge the scan budget twice for nothing new.
141+
if (input.scannedRoots.has(rootDirectory)) return skills;
142+
input.scannedRoots.add(rootDirectory);
137143
const visitedDirectories = new Set<string>();
138144

139145
const visit = Effect.fn("visitCursorSkillDirectory")(function* (
@@ -235,9 +241,10 @@ const inspectCursorSkills = Effect.fn("inspectCursorSkills")(function* (
235241
exhausted: false,
236242
incomplete: false,
237243
};
244+
const scannedRoots = new Set<string>();
238245
for (const root of roots) {
239246
if (budget.exhausted) break;
240-
const skills = yield* discoverSkillsInRoot({ ...root, budget });
247+
const skills = yield* discoverSkillsInRoot({ ...root, budget, scannedRoots });
241248
for (const skill of skills) {
242249
if (!skillsByName.has(skill.name)) skillsByName.set(skill.name, skill);
243250
}

0 commit comments

Comments
 (0)