Skip to content

Discover nested skills while preserving existing precedence - #1786

Open
VIOLETee0 wants to merge 1 commit into
CodebuffAI:mainfrom
VIOLETee0:fix/discover-nested-skills
Open

VIOLETee0 wants to merge 1 commit into
CodebuffAI:mainfrom
VIOLETee0:fix/discover-nested-skills

Conversation

@VIOLETee0

Copy link
Copy Markdown

Problem / Why

Fixes #1784.

Skill discovery only checks immediate children of each skills root. Organizing a valid skill as ~/.agents/skills/bundle/group/nested-skill/SKILL.md silently removes it from the available skills, despite the CLI already opting into that home root.

Changes

Search grouping directories breadth-first. Stop at a directory containing SKILL.md, so a skill's resources and examples do not become additional skills. Track canonical directory paths to terminate cycles through symlinks/junctions.

Shallower definitions win within one root; sorted traversal makes same-depth selection deterministic. Existing project/global and .agents/.claude precedence still applies between roots. One real-filesystem regression covers the nested layout, a directory cycle, a resource example and a duplicate flat definition.

Verification

  • New regression: 0 pass / 1 fail before the implementation change (nested skill missing), then 1 pass / 0 fail. It runs against real temporary directories and a Windows junction, without module mocks.
  • Original SDK skill suite: 20 pass / 2 fail before, then 21 pass / 1 fail. The remaining failure is an existing POSIX path-prefix assertion on Windows. A temporary copy normalizing only that constant and relocating imports passes all 22 tests; this is supplemental verification, not a Linux run.
  • Related common skill parsing/listing tests: 14 pass / 0 fail. SDK typecheck passes with installed native TypeScript 7.0.2. Frozen-lockfile install reports no changes. ESLint: 0 errors / 6 existing resolver/import-order warnings.
  • Raw Prettier checks report Windows CRLF and existing test-file style differences. The LF-normalized loader formats cleanly, and comparison against main finds no new formatting differences in either file.
  • SDK build remains blocked during declaration-generator loading by the existing ts.sys.getCurrentDirectory error. Binary build and smoke were not run because SDK build is a prerequisite.

Scope / Tradeoffs

Two SDK files only. Group directories retain the existing skill-directory naming restrictions. Discovery stops at SKILL.md even when the document is invalid. The home-directory opt-in, skill names, frontmatter validation and public loader API are retained. No namespace prefixes, plugin discovery, new configuration or project-switch behavior is added.

@codebuff-team

Copy link
Copy Markdown
Contributor

Good bug fix with a clear root cause: discoverSkillsFromDirectory previously only checked immediate children of a skills root, so anything under bundle/group/nested-skill/SKILL.md was invisible even though the root was already opted into. The breadth-first rewrite in sdk/src/skills/load-skills.ts is sound — using the growing directories array as a queue with for...of correctly visits newly-pushed entries, fs.realpathSync + visited set handles symlink/junction cycles, and stopping recursion as soon as a SKILL.md is found correctly avoids treating a skill's resources/ subfolder as more skills.

The within-root precedence (!Object.hasOwn(skills, skill.name)) combined with sorted entries and natural BFS ordering gives a deterministic 'shallowest/first-sorted wins' rule, which matches the stated intent and is exercised directly by the new regression test (nested skill, duplicate flat definition, resource folder, symlink loop all in one test — nice, realistic coverage with real temp dirs rather than mocks).

Two things worth a second look before porting:

  1. Grouping directories now share isValidSkillName restrictions with skill directories (acknowledged in the PR body) — confirm this doesn't surprise users who already have arbitrarily-named organizational folders.
  2. Unbounded directory walking could be slower on large or deeply-nested skills trees versus the old flat scan; worth a quick sanity check on a large repo if that's a realistic shape, though no correctness issue here.

No forbidden paths touched, change is isolated to two SDK files, and the reasoning/trade-offs section is unusually honest about what wasn't verified (SDK build blocked, Windows-only run). This is exactly the kind of focused, well-tested fix worth porting.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested skills discovery

2 participants