TypeScript
fix(cursor): supporting files no longer hide sibling skills (#23326)
Julius Marminge30767c22b5df
diff --git a/packages/provider-cursor/src/server/skills.test.ts b/packages/provider-cursor/src/server/skills.test.tsindex 8d1359b1f57..0bbd1bfeb51 100644--- a/packages/provider-cursor/src/server/skills.test.ts+++ b/packages/provider-cursor/src/server/skills.test.ts@@ -3,7 +3,9 @@ import * as NodeServices from "@effect/platform-node/NodeServices";import { describe, expect, it } from "vite-plus/test";import * as Effect from "effect/Effect";import * as FileSystem from "effect/FileSystem";+import * as Layer from "effect/Layer";import * as Path from "effect/Path";+import * as PlatformError from "effect/PlatformError";import type * as Scope from "effect/Scope";import { symlinksSupported } from "@t3tools/shared/testing/symlinks";@@ -173,6 +175,84 @@ describe("Cursor skills", () => {}),));+ it("finds sibling skills when one skill ships more files than the scan budget", async () =>+ await runNode(+ Effect.gen(function* () {+ const fileSystem = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const tempDirectory = (prefix: string) =>+ fileSystem+ .makeTempDirectoryScoped({ directory: NodeOS.tmpdir(), prefix })+ .pipe(Effect.flatMap((directory) => fileSystem.realPath(directory)));+ const userHome = yield* tempDirectory("cursor-skills-home-");+ const workspace = yield* tempDirectory("cursor-skills-workspace-");+ const root = path.join(workspace, ".cursor", "skills");+ const artifacts = path.join(root, "a-large", "artifacts");+ yield* fileSystem.makeDirectory(artifacts, { recursive: true });+ yield* fileSystem.writeFileString(path.join(root, "a-large", "SKILL.md"), "---\n---\n");+ yield* fileSystem.makeDirectory(path.join(root, "b-small"), { recursive: true });+ yield* fileSystem.writeFileString(path.join(root, "b-small", "SKILL.md"), "---\n---\n");+ // More ordinary files than the whole-scan entry budget of 10,000.+ yield* Effect.forEach(+ Array.from({ length: 11_000 }, (_, index) => path.join(artifacts, `file-${index}.txt`)),+ (file) => fileSystem.writeFileString(file, ""),+ { concurrency: 64, discard: true },+ );++ const expected = [+ {+ name: "a-large",+ path: path.join(root, "a-large", "SKILL.md"),+ scope: "project",+ enabled: true,+ },+ {+ name: "b-small",+ path: path.join(root, "b-small", "SKILL.md"),+ scope: "project",+ enabled: true,+ },+ ];+ expect(yield* discoverCursorSkills(workspace, { HOME: userHome })).toEqual(expected);+ expect(yield* probeCursorSkills(workspace, { HOME: userHome })).toEqual(expected);+ }),+ ));++ it("stops a scan of a huge file tree instead of statting every file", async () => {+ const root = "/workspace/.cursor/skills";+ let stats = 0;+ const fileSystem = FileSystem.layerNoop({+ realPath: (path) => Effect.succeed(path),+ readDirectory: (path) =>+ path === root+ ? Effect.succeed(Array.from({ length: 200_000 }, (_, index) => `file-${index}`))+ : Effect.succeed([]),+ stat: (path) => {+ stats += 1;+ if (path === root) return Effect.succeed({ type: "Directory" } as FileSystem.File.Info);+ if (path.startsWith(`${root}/file-`)) {+ return Effect.succeed({ type: "File" } as FileSystem.File.Info);+ }+ return Effect.fail(+ PlatformError.systemError({ _tag: "NotFound", module: "FileSystem", method: "stat" }),+ );+ },+ });++ const result = await probeCursorSkills("/workspace", { HOME: "/home" }).pipe(+ Effect.result,+ Effect.provide(Layer.mergeAll(fileSystem, Path.layer)),+ Effect.runPromise,+ );++ expect(result).toMatchObject({+ _tag: "Failure",+ failure: { reason: "scan-budget-exhausted" },+ });+ expect(stats).toBeGreaterThanOrEqual(100_000);+ expect(stats).toBeLessThanOrEqual(100_000);+ });+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 bc89ee6e35f..5ef68888760 100644--- a/packages/provider-cursor/src/server/skills.ts+++ b/packages/provider-cursor/src/server/skills.ts@@ -17,6 +17,7 @@ const HAS_SKILL_MENTION_PATTERN = new RegExp(SKILL_MENTION_PATTERN.source, "u");const MAX_SKILL_DEPTH = 10;const MAX_SKILL_BYTES = ByteSize.bytes(1_000_000);const MAX_SKILL_SCAN_ENTRIES = 10_000;+const MAX_SKILL_SCAN_STATS = 100_000;const MAX_SKILL_SCAN_BYTES = ByteSize.bytes(8_000_000);interface CursorSkillFrontmatter {@@ -29,6 +30,7 @@ interface CursorSkillFrontmatter {interface CursorSkillScanBudget {remainingEntries: number;+ remainingStats: number;remainingBytes: bigint;exhausted: boolean;incomplete: boolean;@@ -153,6 +155,11 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (resolvedDirectory === rootDirectory ||resolvedDirectory.startsWith(`${rootDirectory}${path.sep}`);+ if (input.budget.remainingStats === 0) {+ input.budget.exhausted = true;+ return;+ }+ input.budget.remainingStats -= 1;const skillPath = path.join(directory, "SKILL.md");const skillInfo = yield* orUndefined(fileSystem.stat(skillPath), input.budget);if (skillInfo?.type === "File") {@@ -189,17 +196,25 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (return;}for (const entry of [...entries].sort()) {- if (input.budget.remainingEntries === 0) {+ // Installed dependencies can exhaust the shared budget and hide unrelated skills.+ if (entry === "node_modules") continue;+ // Files spend no directory budget, so a separate cap keeps a huge file tree bounded.+ if (input.budget.remainingStats === 0) {input.budget.exhausted = true;return;}- input.budget.remainingEntries -= 1;- // Installed dependencies can exhaust the shared budget and hide unrelated skills.- if (entry === "node_modules") continue;+ input.budget.remainingStats -= 1;const child = path.join(directory, entry);const info = yield* orUndefined(fileSystem.stat(child), input.budget);+ // Only directories can hold skills, so only they spend the budget: a skill+ // shipping many ordinary files must not hide its siblings.if (info?.type !== "Directory") continue;if (depth >= MAX_SKILL_DEPTH) continue;+ if (input.budget.remainingEntries === 0) {+ input.budget.exhausted = true;+ return;+ }+ input.budget.remainingEntries -= 1;yield* visit(child, depth + 1);}});@@ -233,6 +248,7 @@ const inspectCursorSkills = Effect.fn("inspectCursorSkills")(function* (const skillsByName = new Map<string, ServerProviderSkill>();const budget: CursorSkillScanBudget = {remainingEntries: MAX_SKILL_SCAN_ENTRIES,+ remainingStats: MAX_SKILL_SCAN_STATS,remainingBytes: MAX_SKILL_SCAN_BYTES,exhausted: false,incomplete: false,