xonecas.io
64875
Mc

mini-coder / commit bf34c34

fix: recursive skill scanning per agentskills.io spec

Replace hardcoded 2-level scan (direct + namespace) with recursive
directory walking up to depth 5 and max 2000 directories, matching
the agentskills.io specification guidance.

Skills nested at any depth (e.g. org/team/skill/SKILL.md) are now
correctly discovered.

xonecas2026-03-21 bf34c3484d54bc39096fd103dcaa150d2566d3d1 parent e0e8015

2 files changed

src/cli/skills.test.ts+16−5
@@ -235,7 +235,7 @@ describe("skills loader", () => {
235235 );
236236 });
237237
238- test("direct skills take precedence over namespace skills with same name", () => {
238+ test("last-found skill wins when names collide within the same scope", () => {
239239 // Direct skill at .agents/skills/brainstorming/SKILL.md
240240 writeSkill(
241241 dir,
@@ -243,7 +243,7 @@ describe("skills loader", () => {
243243 "brainstorming",
244244 "---\nname: brainstorming\ndescription: local direct\n---\ncontent",
245245 );
246- // Namespace skill at .agents/skills/superpowers/brainstorming/SKILL.md
246+ // Nested skill at .agents/skills/superpowers/brainstorming/SKILL.md
247247 const nsDir = join(
248248 dir,
249249 ".agents",
@@ -258,12 +258,23 @@ describe("skills loader", () => {
258258 );
259259
260260 const index = loadSkillsIndex(dir, fakeHome);
261- // Direct skill should win because it comes first in directory listing (b < s)
262- // and last-write-wins in our Map, but direct skills are scanned before namespace
263- // Actually: "brainstorming" dir < "superpowers" dir alphabetically, so direct wins
261+ // "brainstorming" is found first (alphabetically before "superpowers"),
262+ // then "superpowers/brainstorming" overwrites it in the Map (last-write-wins)
264263 expect(index.get("brainstorming")?.description).toBe("from superpowers");
265264 });
266265
266+ test("discovers skills nested 3+ levels deep", () => {
267+ const deepDir = join(dir, ".agents", "skills", "org", "team", "deep-skill");
268+ mkdirSync(deepDir, { recursive: true });
269+ writeFileSync(
270+ join(deepDir, "SKILL.md"),
271+ "---\nname: deep-skill\ndescription: deeply nested\n---\nContent",
272+ );
273+
274+ const index = loadSkillsIndex(dir, fakeHome);
275+ expect(index.get("deep-skill")?.description).toBe("deeply nested");
276+ });
277+
267278 it("does not set context for skills without context: fork", () => {
268279 writeSkill(
269280 dir,
src/cli/skills.ts+29−39
@@ -109,61 +109,51 @@ function localSearchRoots(cwd: string): string[] {
109109 return roots;
110110 }
111111
112+const MAX_SKILL_SCAN_DEPTH = 5;
113+const MAX_SKILL_DIRS_SCANNED = 2000;
114+
112115 function listSkillCandidates(
113116 skillsDir: string,
114117 source: "global" | "local",
115118 rootPath: string,
116119 ): SkillCandidate[] {
117120 if (!existsSync(skillsDir)) return [];
118- let entries: string[];
119- try {
120- entries = readdirSync(skillsDir).sort((a, b) => a.localeCompare(b));
121- } catch {
122- return [];
123- }
124121 const candidates: SkillCandidate[] = [];
125- for (const entry of entries) {
126- const skillDir = join(skillsDir, entry);
127- try {
128- if (!statSync(skillDir).isDirectory()) continue;
129- } catch {
130- continue;
131- }
132- const filePath = join(skillDir, "SKILL.md");
133- if (existsSync(filePath)) {
134- candidates.push({
135- folderName: entry,
136- filePath,
137- rootPath,
138- source,
139- });
140- continue;
141- }
142- // Namespace directory: scan one level deeper for skill subdirectories
143- // (e.g., superpowers/brainstorming/SKILL.md)
144- let subEntries: string[];
122+ let dirsScanned = 0;
123+
124+ function walk(dir: string, depth: number): void {
125+ if (depth > MAX_SKILL_SCAN_DEPTH || dirsScanned >= MAX_SKILL_DIRS_SCANNED)
126+ return;
127+ let entries: string[];
145128 try {
146- subEntries = readdirSync(skillDir).sort((a, b) => a.localeCompare(b));
129+ entries = readdirSync(dir).sort((a, b) => a.localeCompare(b));
147130 } catch {
148- continue;
131+ return;
149132 }
150- for (const subEntry of subEntries) {
151- const subSkillDir = join(skillDir, subEntry);
133+ for (const entry of entries) {
134+ if (dirsScanned >= MAX_SKILL_DIRS_SCANNED) return;
135+ const entryPath = join(dir, entry);
152136 try {
153- if (!statSync(subSkillDir).isDirectory()) continue;
137+ if (!statSync(entryPath).isDirectory()) continue;
154138 } catch {
155139 continue;
156140 }
157- const subFilePath = join(subSkillDir, "SKILL.md");
158- if (!existsSync(subFilePath)) continue;
159- candidates.push({
160- folderName: subEntry,
161- filePath: subFilePath,
162- rootPath,
163- source,
164- });
141+ dirsScanned++;
142+ const filePath = join(entryPath, "SKILL.md");
143+ if (existsSync(filePath)) {
144+ candidates.push({
145+ folderName: entry,
146+ filePath,
147+ rootPath,
148+ source,
149+ });
150+ } else {
151+ walk(entryPath, depth + 1);
152+ }
165153 }
166154 }
155+
156+ walk(skillsDir, 1);
167157 return candidates;
168158 }