Skip to content

Commit 20bd3e4

Browse files
ScottN-PVclaude
andcommitted
fix(provider-cursor): a skills root linked to another is scanned once
Skill discovery walks each skills root below the project and the home directory. When one root is a symlink to another, for example ~/.agents/skills pointing at ~/.claude/skills, the same tree was walked twice and charged twice against the entry budget. A tree over half the budget then failed discovery with scan-budget-exhausted, so Cursor showed no skills. Discovery now skips a root whose real path it already walked, keeping the current root order. Refs #17215 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5753207 commit 20bd3e4

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
@@ -185,6 +185,42 @@ describe("Cursor skills", () => {
185185
}),
186186
));
187187

188+
it.skipIf(!symlinksSupported)(
189+
"scans a skills root linked to another root only once",
190+
async () =>
191+
await runNode(
192+
Effect.gen(function* () {
193+
const fileSystem = yield* FileSystem.FileSystem;
194+
const path = yield* Path.Path;
195+
const userHome = yield* fileSystem.makeTempDirectoryScoped({
196+
directory: NodeOS.tmpdir(),
197+
prefix: "cursor-skills-home-",
198+
});
199+
// More than half the entry budget, so a second walk of the same tree runs out.
200+
const claudeRoot = path.join(userHome, ".claude", "skills");
201+
yield* fileSystem.makeDirectory(path.join(claudeRoot, "review"), { recursive: true });
202+
yield* fileSystem.writeFileString(
203+
path.join(claudeRoot, "review", "SKILL.md"),
204+
"---\n---\n",
205+
);
206+
yield* Effect.forEach(
207+
Array.from({ length: 6_000 }, (_, index) => path.join(claudeRoot, `entry-${index}`)),
208+
(file) => fileSystem.writeFileString(file, ""),
209+
{ concurrency: 64, discard: true },
210+
);
211+
yield* fileSystem.makeDirectory(path.join(userHome, ".agents"), { recursive: true });
212+
yield* fileSystem.symlink(claudeRoot, path.join(userHome, ".agents", "skills"));
213+
214+
const result = yield* probeCursorSkills(undefined, { HOME: userHome }).pipe(
215+
Effect.result,
216+
);
217+
expect(result._tag).toBe("Success");
218+
const skills = yield* discoverCursorSkills(undefined, { HOME: userHome });
219+
expect(skills.map((skill) => `${skill.scope}:${skill.name}`)).toEqual(["user:review"]);
220+
}),
221+
),
222+
);
223+
188224
it.skipIf(!symlinksSupported)(
189225
"treats a symlinked skill outside the root as a package boundary",
190226
async () =>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,19 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (
131131
readonly directory: string;
132132
readonly scope: "user" | "project";
133133
readonly budget: CursorSkillScanBudget;
134+
/** Real paths of the roots already walked in this scan. */
135+
readonly scannedRoots: Set<string>;
134136
}): Effect.fn.Return<ReadonlyArray<ServerProviderSkill>, never, FileSystem.FileSystem | Path.Path> {
135137
const fileSystem = yield* FileSystem.FileSystem;
136138
const path = yield* Path.Path;
137139
const skills: ServerProviderSkill[] = [];
138140
if (input.budget.exhausted) return skills;
139141
const rootDirectory = yield* orUndefined(fileSystem.realPath(input.directory), input.budget);
140142
if (!rootDirectory) return skills;
143+
// A root linked to another one, such as `~/.agents/skills` pointing at `~/.claude/skills`,
144+
// is the same tree: walking it again would charge the scan budget twice for nothing new.
145+
if (input.scannedRoots.has(rootDirectory)) return skills;
146+
input.scannedRoots.add(rootDirectory);
141147
const visitedDirectories = new Set<string>();
142148

143149
const visit = Effect.fn("visitCursorSkillDirectory")(function* (
@@ -239,9 +245,10 @@ const inspectCursorSkills = Effect.fn("inspectCursorSkills")(function* (
239245
exhausted: false,
240246
incomplete: false,
241247
};
248+
const scannedRoots = new Set<string>();
242249
for (const root of roots) {
243250
if (budget.exhausted) break;
244-
const skills = yield* discoverSkillsInRoot({ ...root, budget });
251+
const skills = yield* discoverSkillsInRoot({ ...root, budget, scannedRoots });
245252
for (const skill of skills) {
246253
if (!skillsByName.has(skill.name)) skillsByName.set(skill.name, skill);
247254
}

0 commit comments

Comments
 (0)