Skip to content

Commit 30767c2

Browse files
fix(cursor): supporting files no longer hide sibling skills (pingdotgg#23326)
Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 10f3657 commit 30767c2

2 files changed

Lines changed: 100 additions & 4 deletions

File tree

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
33
import { describe, expect, it } from "vite-plus/test";
44
import * as Effect from "effect/Effect";
55
import * as FileSystem from "effect/FileSystem";
6+
import * as Layer from "effect/Layer";
67
import * as Path from "effect/Path";
8+
import * as PlatformError from "effect/PlatformError";
79
import type * as Scope from "effect/Scope";
810
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
911

@@ -173,6 +175,84 @@ describe("Cursor skills", () => {
173175
}),
174176
));
175177

178+
it("finds sibling skills when one skill ships more files than the scan budget", async () =>
179+
await runNode(
180+
Effect.gen(function* () {
181+
const fileSystem = yield* FileSystem.FileSystem;
182+
const path = yield* Path.Path;
183+
const tempDirectory = (prefix: string) =>
184+
fileSystem
185+
.makeTempDirectoryScoped({ directory: NodeOS.tmpdir(), prefix })
186+
.pipe(Effect.flatMap((directory) => fileSystem.realPath(directory)));
187+
const userHome = yield* tempDirectory("cursor-skills-home-");
188+
const workspace = yield* tempDirectory("cursor-skills-workspace-");
189+
const root = path.join(workspace, ".cursor", "skills");
190+
const artifacts = path.join(root, "a-large", "artifacts");
191+
yield* fileSystem.makeDirectory(artifacts, { recursive: true });
192+
yield* fileSystem.writeFileString(path.join(root, "a-large", "SKILL.md"), "---\n---\n");
193+
yield* fileSystem.makeDirectory(path.join(root, "b-small"), { recursive: true });
194+
yield* fileSystem.writeFileString(path.join(root, "b-small", "SKILL.md"), "---\n---\n");
195+
// More ordinary files than the whole-scan entry budget of 10,000.
196+
yield* Effect.forEach(
197+
Array.from({ length: 11_000 }, (_, index) => path.join(artifacts, `file-${index}.txt`)),
198+
(file) => fileSystem.writeFileString(file, ""),
199+
{ concurrency: 64, discard: true },
200+
);
201+
202+
const expected = [
203+
{
204+
name: "a-large",
205+
path: path.join(root, "a-large", "SKILL.md"),
206+
scope: "project",
207+
enabled: true,
208+
},
209+
{
210+
name: "b-small",
211+
path: path.join(root, "b-small", "SKILL.md"),
212+
scope: "project",
213+
enabled: true,
214+
},
215+
];
216+
expect(yield* discoverCursorSkills(workspace, { HOME: userHome })).toEqual(expected);
217+
expect(yield* probeCursorSkills(workspace, { HOME: userHome })).toEqual(expected);
218+
}),
219+
));
220+
221+
it("stops a scan of a huge file tree instead of statting every file", async () => {
222+
const root = "/workspace/.cursor/skills";
223+
let stats = 0;
224+
const fileSystem = FileSystem.layerNoop({
225+
realPath: (path) => Effect.succeed(path),
226+
readDirectory: (path) =>
227+
path === root
228+
? Effect.succeed(Array.from({ length: 200_000 }, (_, index) => `file-${index}`))
229+
: Effect.succeed([]),
230+
stat: (path) => {
231+
stats += 1;
232+
if (path === root) return Effect.succeed({ type: "Directory" } as FileSystem.File.Info);
233+
if (path.startsWith(`${root}/file-`)) {
234+
return Effect.succeed({ type: "File" } as FileSystem.File.Info);
235+
}
236+
return Effect.fail(
237+
PlatformError.systemError({ _tag: "NotFound", module: "FileSystem", method: "stat" }),
238+
);
239+
},
240+
});
241+
242+
const result = await probeCursorSkills("/workspace", { HOME: "/home" }).pipe(
243+
Effect.result,
244+
Effect.provide(Layer.mergeAll(fileSystem, Path.layer)),
245+
Effect.runPromise,
246+
);
247+
248+
expect(result).toMatchObject({
249+
_tag: "Failure",
250+
failure: { reason: "scan-budget-exhausted" },
251+
});
252+
expect(stats).toBeGreaterThanOrEqual(100_000);
253+
expect(stats).toBeLessThanOrEqual(100_000);
254+
});
255+
176256
it.skipIf(!symlinksSupported)(
177257
"treats a symlinked skill outside the root as a package boundary",
178258
async () =>

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const HAS_SKILL_MENTION_PATTERN = new RegExp(SKILL_MENTION_PATTERN.source, "u");
1717
const MAX_SKILL_DEPTH = 10;
1818
const MAX_SKILL_BYTES = ByteSize.bytes(1_000_000);
1919
const MAX_SKILL_SCAN_ENTRIES = 10_000;
20+
const MAX_SKILL_SCAN_STATS = 100_000;
2021
const MAX_SKILL_SCAN_BYTES = ByteSize.bytes(8_000_000);
2122

2223
interface CursorSkillFrontmatter {
@@ -29,6 +30,7 @@ interface CursorSkillFrontmatter {
2930

3031
interface CursorSkillScanBudget {
3132
remainingEntries: number;
33+
remainingStats: number;
3234
remainingBytes: bigint;
3335
exhausted: boolean;
3436
incomplete: boolean;
@@ -153,6 +155,11 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (
153155
resolvedDirectory === rootDirectory ||
154156
resolvedDirectory.startsWith(`${rootDirectory}${path.sep}`);
155157

158+
if (input.budget.remainingStats === 0) {
159+
input.budget.exhausted = true;
160+
return;
161+
}
162+
input.budget.remainingStats -= 1;
156163
const skillPath = path.join(directory, "SKILL.md");
157164
const skillInfo = yield* orUndefined(fileSystem.stat(skillPath), input.budget);
158165
if (skillInfo?.type === "File") {
@@ -189,17 +196,25 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (
189196
return;
190197
}
191198
for (const entry of [...entries].sort()) {
192-
if (input.budget.remainingEntries === 0) {
199+
// Installed dependencies can exhaust the shared budget and hide unrelated skills.
200+
if (entry === "node_modules") continue;
201+
// Files spend no directory budget, so a separate cap keeps a huge file tree bounded.
202+
if (input.budget.remainingStats === 0) {
193203
input.budget.exhausted = true;
194204
return;
195205
}
196-
input.budget.remainingEntries -= 1;
197-
// Installed dependencies can exhaust the shared budget and hide unrelated skills.
198-
if (entry === "node_modules") continue;
206+
input.budget.remainingStats -= 1;
199207
const child = path.join(directory, entry);
200208
const info = yield* orUndefined(fileSystem.stat(child), input.budget);
209+
// Only directories can hold skills, so only they spend the budget: a skill
210+
// shipping many ordinary files must not hide its siblings.
201211
if (info?.type !== "Directory") continue;
202212
if (depth >= MAX_SKILL_DEPTH) continue;
213+
if (input.budget.remainingEntries === 0) {
214+
input.budget.exhausted = true;
215+
return;
216+
}
217+
input.budget.remainingEntries -= 1;
203218
yield* visit(child, depth + 1);
204219
}
205220
});
@@ -233,6 +248,7 @@ const inspectCursorSkills = Effect.fn("inspectCursorSkills")(function* (
233248
const skillsByName = new Map<string, ServerProviderSkill>();
234249
const budget: CursorSkillScanBudget = {
235250
remainingEntries: MAX_SKILL_SCAN_ENTRIES,
251+
remainingStats: MAX_SKILL_SCAN_STATS,
236252
remainingBytes: MAX_SKILL_SCAN_BYTES,
237253
exhausted: false,
238254
incomplete: false,

0 commit comments

Comments
 (0)