Skip to content

Commit 8267896

Browse files
njb90claude
andcommitted
fix: correct dir name usage, dedup copilot sections, per-file ref error handling
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8b54a4b commit 8267896

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

src/commands/configureAiTools.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type EditorType = "cursor" | "vscode" | "windsurf" | "antigravity" | "unknown";
77
type SkillInfo = {
88
name: string;
99
description: string;
10+
dirName: string; // GitHub directory name, used for API paths and local install paths
1011
};
1112

1213
type GitHubEntry = {
@@ -87,7 +88,7 @@ function getBodyAfterFrontmatter(content: string): string {
8788

8889
/** Returns SKILL.md content with the `name:` line removed (Cursor .mdc format). */
8990
function toMdcContent(content: string): string {
90-
return content.replace(/^(---\n)([\s\S]*?)(\n---)/m, (_, open, body, close) => {
91+
return content.replace(/^(---\n)([\s\S]*?)(\n---)/, (_, open, body, close) => {
9192
const filtered = body
9293
.split("\n")
9394
.filter((line: string) => !line.startsWith("name:"))
@@ -110,7 +111,7 @@ async function fetchSkillList(): Promise<SkillInfo[]> {
110111
);
111112
const content = decodeBase64(file.content);
112113
const fm = parseFrontmatter(content);
113-
return { name: fm.name || dir.name, description: fm.description || "" };
114+
return { name: fm.name || dir.name, description: fm.description || "", dirName: dir.name };
114115
} catch {
115116
return null;
116117
}
@@ -139,17 +140,21 @@ async function fetchReferenceFiles(
139140
return []; // no references directory — that's fine
140141
}
141142

142-
const files = await Promise.all(
143+
const results = await Promise.all(
143144
entries
144145
.filter((e) => e.type === "file")
145146
.map(async (e) => {
146-
const file = await githubFetchJson<GitHubFile>(
147-
`${SKILLS_BASE}/skills/${skillName}/references/${e.name}`
148-
);
149-
return { name: e.name, content: decodeBase64(file.content) };
147+
try {
148+
const file = await githubFetchJson<GitHubFile>(
149+
`${SKILLS_BASE}/skills/${skillName}/references/${e.name}`
150+
);
151+
return { name: e.name, content: decodeBase64(file.content) };
152+
} catch {
153+
return null;
154+
}
150155
})
151156
);
152-
return files;
157+
return results.filter((f): f is { name: string; content: string } => f !== null);
153158
}
154159

155160
// ── Filesystem helpers ───────────────────────────────────────────────────────
@@ -255,6 +260,13 @@ async function installForCopilot(
255260
// new file
256261
}
257262

263+
if (existing.includes(`## ${skillName}`)) {
264+
if (!createdFiles.includes(".github/copilot-instructions.md")) {
265+
createdFiles.push(".github/copilot-instructions.md");
266+
}
267+
return;
268+
}
269+
258270
const body = getBodyAfterFrontmatter(skillContent);
259271
const section = `## ${skillName}\n\n${body}\n`;
260272
const separator = existing.length > 0 ? "\n" : "";
@@ -351,21 +363,22 @@ function registerConfigureAiTools(context: vscode.ExtensionContext): void {
351363
if (!ideTarget) { return; }
352364

353365
for (const item of pickedSkills) {
354-
const skill = skills.find((s) => s.name === item.label)!;
366+
const skill = skills.find((s) => s.name === item.label);
367+
if (!skill) { continue; }
355368
let content: string;
356369
try {
357-
content = await fetchSkillContent(skill.name);
370+
content = await fetchSkillContent(skill.dirName);
358371
} catch (err: any) {
359-
errors.push(`${skill.name}: ${err.message}`);
372+
errors.push(`${skill.dirName}: ${err.message}`);
360373
continue;
361374
}
362375

363376
if (ideTarget.label === "Claude Code") {
364-
await installForClaudeCode(rootUri, skill.name, content, createdFiles, errors);
377+
await installForClaudeCode(rootUri, skill.dirName, content, createdFiles, errors);
365378
} else if (ideTarget.label === "Cursor") {
366-
await installForCursor(rootUri, skill.name, content, createdFiles);
379+
await installForCursor(rootUri, skill.dirName, content, createdFiles);
367380
} else {
368-
await installForCopilot(rootUri, skill.name, content, createdFiles);
381+
await installForCopilot(rootUri, skill.dirName, content, createdFiles);
369382
}
370383
}
371384
}

0 commit comments

Comments
 (0)