TypeScript
fix(provider-cursor): a symlinked skills root is no longer scanned twice (#18664)
Scott Norteman52eba84734ce
diff --git a/packages/provider-cursor/src/server/skills.test.ts b/packages/provider-cursor/src/server/skills.test.tsindex 0c7d31f3974..df22875f8d2 100644--- a/packages/provider-cursor/src/server/skills.test.ts+++ b/packages/provider-cursor/src/server/skills.test.ts@@ -229,6 +229,42 @@ describe("Cursor skills", () => {}),));+ it.skipIf(!symlinksSupported)(+ "scans a skills root linked to another root only once",+ async () =>+ await runNode(+ Effect.gen(function* () {+ const fileSystem = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const userHome = yield* fileSystem.makeTempDirectoryScoped({+ directory: NodeOS.tmpdir(),+ prefix: "cursor-skills-home-",+ });+ // More than half the entry budget, so a second walk of the same tree runs out.+ const claudeRoot = path.join(userHome, ".claude", "skills");+ yield* fileSystem.makeDirectory(path.join(claudeRoot, "review"), { recursive: true });+ yield* fileSystem.writeFileString(+ path.join(claudeRoot, "review", "SKILL.md"),+ "---\n---\n",+ );+ yield* Effect.forEach(+ Array.from({ length: 6_000 }, (_, index) => path.join(claudeRoot, `entry-${index}`)),+ (file) => fileSystem.writeFileString(file, ""),+ { concurrency: 64, discard: true },+ );+ yield* fileSystem.makeDirectory(path.join(userHome, ".agents"), { recursive: true });+ yield* fileSystem.symlink(claudeRoot, path.join(userHome, ".agents", "skills"));++ const result = yield* probeCursorSkills(undefined, { HOME: userHome }).pipe(+ Effect.result,+ );+ expect(result._tag).toBe("Success");+ const skills = yield* discoverCursorSkills(undefined, { HOME: userHome });+ expect(skills.map((skill) => `${skill.scope}:${skill.name}`)).toEqual(["user:review"]);+ }),+ ),+ );+it.skipIf(!symlinksSupported)("treats a symlinked skill outside the root as a package boundary",async () =>diff --git a/packages/provider-cursor/src/server/skills.ts b/packages/provider-cursor/src/server/skills.tsindex bd778801574..3b5aa6aa514 100644--- a/packages/provider-cursor/src/server/skills.ts+++ b/packages/provider-cursor/src/server/skills.ts@@ -127,6 +127,8 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (readonly directory: string;readonly scope: "user" | "project";readonly budget: CursorSkillScanBudget;+ /** Real paths of the roots already walked in this scan. */+ readonly scannedRoots: Set<string>;}): Effect.fn.Return<ReadonlyArray<ServerProviderSkill>, never, FileSystem.FileSystem | Path.Path> {const fileSystem = yield* FileSystem.FileSystem;const path = yield* Path.Path;@@ -134,6 +136,10 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (if (input.budget.exhausted) return skills;const rootDirectory = yield* orUndefined(fileSystem.realPath(input.directory), input.budget);if (!rootDirectory) return skills;+ // A root linked to another one, such as `~/.agents/skills` pointing at `~/.claude/skills`,+ // is the same tree: walking it again would charge the scan budget twice for nothing new.+ if (input.scannedRoots.has(rootDirectory)) return skills;+ input.scannedRoots.add(rootDirectory);const visitedDirectories = new Set<string>();const visit = Effect.fn("visitCursorSkillDirectory")(function* (@@ -235,9 +241,10 @@ const inspectCursorSkills = Effect.fn("inspectCursorSkills")(function* (exhausted: false,incomplete: false,};+ const scannedRoots = new Set<string>();for (const root of roots) {if (budget.exhausted) break;- const skills = yield* discoverSkillsInRoot({ ...root, budget });+ const skills = yield* discoverSkillsInRoot({ ...root, budget, scannedRoots });for (const skill of skills) {if (!skillsByName.has(skill.name)) skillsByName.set(skill.name, skill);}