Skip to content
Open
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
29 changes: 24 additions & 5 deletions apps/cursor/src/lib/github-plugin/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ export function githubAuthHeaders(): Record<string, string> {

const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

/**
* Normalize a sub-plugin dir to `a/b/` form: no leading `./` or `/`, exactly
* one trailing `/`. Marketplace manifests commonly write `./plugins/foo`.
*/
function normalizeSubPluginDir(source: string): string {
const trimmed = source.replace(/^(?:\.\/)+/, "").replace(/^\/+|\/+$/g, "");
return trimmed ? `${trimmed}/` : "";
}

function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}

/** Match tree paths under `prefix` (a literal dir) followed by `pattern` (a regex). */
function pathUnder(prefix: string, pattern: string): RegExp {
return new RegExp(`^${escapeRegExp(prefix)}${pattern}`);
}

/**
* Fetch with bounded retry on GitHub rate-limit (429 / 403 + retry-after).
*
Expand Down Expand Up @@ -344,7 +362,8 @@ export async function parseGitHubPlugin(
if (entry && typeof entry === "object") {
const source = (entry as Record<string, unknown>).source;
if (typeof source === "string" && source && !source.includes("..")) {
subPluginDirs.add(`${source.replace(/^\/+|\/+$/g, "")}/`);
const dir = normalizeSubPluginDir(source);
if (dir) subPluginDirs.add(dir);
}
}
}
Expand Down Expand Up @@ -389,7 +408,7 @@ export async function parseGitHubPlugin(
const ruleFiles = tree.filter(
(f) =>
f.type === "blob" &&
new RegExp(`^${prefix}rules/.*\\.mdc$`).test(f.path),
pathUnder(prefix, "rules/.*\\.mdc$").test(f.path),
);
for (const rf of ruleFiles) {
const raw = await fetchGitHubFile(owner, repo, rf.path);
Expand Down Expand Up @@ -452,7 +471,7 @@ export async function parseGitHubPlugin(
const agentFiles = tree.filter(
(f) =>
f.type === "blob" &&
new RegExp(`^${prefix}agents/.*\\.md$`).test(f.path),
pathUnder(prefix, "agents/.*\\.md$").test(f.path),
);
for (const af of agentFiles) {
const raw = await fetchGitHubFile(owner, repo, af.path);
Expand All @@ -473,7 +492,7 @@ export async function parseGitHubPlugin(
const skillFiles = tree.filter(
(f) =>
f.type === "blob" &&
new RegExp(`^${prefix}skills/[^/]+/SKILL\\.md$`).test(f.path),
pathUnder(prefix, "skills/[^/]+/SKILL\\.md$").test(f.path),
);
for (const sf of skillFiles) {
const raw = await fetchGitHubFile(owner, repo, sf.path);
Expand All @@ -495,7 +514,7 @@ export async function parseGitHubPlugin(
const commandFiles = tree.filter(
(f) =>
f.type === "blob" &&
new RegExp(`^${prefix}commands/.*\\.md$`).test(f.path),
pathUnder(prefix, "commands/.*\\.md$").test(f.path),
);
for (const cf of commandFiles) {
const raw = await fetchGitHubFile(owner, repo, cf.path);
Expand Down