refactor(skills): split package into focused files#2571
Merged
dgageot merged 3 commits intodocker:mainfrom Apr 28, 2026
Merged
Conversation
- Merge loadRemoteSkills wrapper + defaultCache helper - Merge loadSkillsRecursive + walkSkillsRecursive - Use slices.Collect(maps.Values(...)) for map -> slice conversions - Drop redundant os.Stat in loadSkillsFromDir No public API or behavior change. Assisted-By: docker-agent
skills.go (402 -> 82 lines) now only holds the public API: the Skill type and the Load entry point. The implementation is split into focused files: - local.go: filesystem skill discovery, with a declarative localSearchPaths table that makes the precedence rules (codex, claude, agents, project) easy to read at a glance. findGitRoot+projectSearchDirs share a single walk-up. - frontmatter.go: YAML-ish frontmatter parsing, split into parseTopLevelLine and parseIndentedLine for clarity. Other small simplifications: - Load now sorts its result by name for deterministic output. - Load avoids the double map -> slice -> map round-trip via loadLocalSkillsInto. - Skill.IsFork uses a value receiver for consistency with the rest of the API. - isHTTPSource extracted from Load. No public API or behavior change; all existing tests pass. Assisted-By: docker-agent
Two small follow-ups from reviewing the refactor: - Load: add a FilePath tiebreaker to the sort. slices.SortedFunc uses pdqsort which is unstable, so two skills sharing a Name (e.g. a local and a remote source both exposing 'foo') would otherwise have non-deterministic relative ordering across runs. FilePath is unique, so this gives Load a fully deterministic output. - local.go: clarify the symlink behavior of loadSkillsFlat (skips symlinks explicitly) and loadSkillsRecursive (filepath.WalkDir does not follow symlinks; the visited map is defensive against bind mounts and symlinked roots, not symlinks inside the tree). Assisted-By: docker-agent
gtardif
approved these changes
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Internal refactor of
pkg/skillsto make the package easier to read and maintain. No public API or behavior change.Why
pkg/skills/skills.gohad grown to 402 lines doing five different jobs (types, public API, local discovery, frontmatter parsing, helpers). The precedence rules for local skill loading were buried in nested for-loops. A few one-line wrappers (loadRemoteSkills→loadRemoteSkillsWithCache,defaultCache()) added indirection without value.What changed
Three small commits:
refactor(skills): inline trivial wrappers and use maps.ValuesloadRemoteSkillswrapper +defaultCache()helper.loadSkillsRecursive+walkSkillsRecursive.slices.Collect(maps.Values(...))for map → slice conversions.os.StatinloadSkillsFromDir.refactor(skills): split package into focused filesskills.go(402 → 82 lines): public API only —Skilltype +Load.local.go(new): filesystem discovery, with a declarativelocalSearchPaths()table that makes the precedence rules (codex → claude → agents → project) easy to read at a glance.findGitRoot+projectSearchDirsshare a single walk-up.frontmatter.go(new): YAML-ish frontmatter parsing, split intoparseTopLevelLineandparseIndentedLine.Loadnow sorts its result byNamefor deterministic output.Loadavoids the double map → slice → map round-trip vialoadLocalSkillsInto.Skill.IsForkuses a value receiver for consistency.isHTTPSourceextracted fromLoad.fix(skills): tighten review nits from refactorLoad: addFilePathtiebreaker to the sort.slices.SortedFuncuses pdqsort which is unstable, so two skills sharing aName(e.g. local + remote both exposingfoo) would have non-deterministic relative order.FilePathis unique → fully deterministic output.loadSkillsFlat(skips symlinks explicitly) andloadSkillsRecursive(filepath.WalkDirdoes not follow symlinks; the visited map is defensive against bind mounts and symlinked roots, not symlinks inside the tree).File sizes (before → after)
skills.golocal.gofrontmatter.goremote.goValidation
mise lint— clean (golangci-lint + custom cop +go mod tidy --diff)mise test— all packages passSkill,Skill.IsFork,Load,ExpandCommandskeep the same signatures