Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions packages/provider-cursor/src/server/skills.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,89 @@ describe("Cursor skills", () => {
}),
));

it("skips a skill tree deeper than the limit instead of failing discovery", 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 writeSkill = Effect.fn("writeCursorSkill")(function* (directory: string) {
yield* fileSystem.makeDirectory(directory, { recursive: true });
yield* fileSystem.writeFileString(path.join(directory, "SKILL.md"), "---\n---\n");
});
const userRoot = path.join(userHome, ".claude", "skills");
// The root is depth 0, so `deep-skill` sits at the depth limit and `below` past it.
const atLimit = path.join(
userRoot,
"deep",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"deep-skill",
);

yield* writeSkill(path.join(workspace, ".agents", "skills", "review"));
yield* writeSkill(atLimit);
yield* writeSkill(path.join(atLimit, "below"));
yield* writeSkill(path.join(userRoot, "later"));

const expected = [
{
name: "deep-skill",
path: path.join(atLimit, "SKILL.md"),
scope: "user",
enabled: true,
},
{
name: "later",
path: path.join(userRoot, "later", "SKILL.md"),
scope: "user",
enabled: true,
},
{
name: "review",
path: path.join(workspace, ".agents", "skills", "review", "SKILL.md"),
scope: "project",
enabled: true,
},
];
expect(yield* discoverCursorSkills(workspace, { HOME: userHome })).toEqual(expected);
expect(yield* probeCursorSkills(workspace, { HOME: userHome })).toEqual(expected);
}),
));

it("still fails discovery when a root holds more entries than the scan allows", 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-",
});
const root = path.join(userHome, ".cursor", "skills");
yield* fileSystem.makeDirectory(root, { recursive: true });
yield* Effect.forEach(
Array.from({ length: 10_001 }, (_, index) => path.join(root, `entry-${index}`)),
(file) => fileSystem.writeFileString(file, ""),
{ concurrency: 64, discard: true },
);

const error = yield* Effect.flip(probeCursorSkills(undefined, { HOME: userHome }));
expect(error.message).toContain("scan-budget-exhausted");
}),
));

it.skipIf(!symlinksSupported)(
"treats a symlinked skill outside the root as a package boundary",
async () =>
Expand Down
7 changes: 3 additions & 4 deletions packages/provider-cursor/src/server/skills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (
const child = path.join(directory, entry);
const info = yield* orUndefined(fileSystem.stat(child), input.budget);
if (info?.type !== "Directory") continue;
if (depth >= MAX_SKILL_DEPTH) {
input.budget.exhausted = true;
return;
}
// A tree deeper than the limit is skipped rather than fatal: the same tree would fail
// every refresh and hide every other skill with it.
if (depth >= MAX_SKILL_DEPTH) continue;
yield* visit(child, depth + 1);
}
});
Expand Down
Loading