Vectrum
Sign In

skills: skip a non-absolute personal or project root

Discover joined home/workroot with Dirname without checking the result
was absolute, so an empty home (the fallback main.go uses when
os.UserHomeDir fails) or a relative workroot resolved against the
process's working directory instead of a real root, silently loading
whatever .agents/skills happened to be there as "personal" or "project".

Skip any root whose joined path is not absolute, silently: an unknown
home is not a user error, and neither root existing is already normal.

Fix round 1 of 5, addressing an Important review finding from Task 6.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Jjonicommitted 1 parent dc52c6dcommitb755ae9

Showing 2 changed files with 35 additions and 0 deletions.

+7−0internal/skills/skills.goView File
@@ -62,6 +62,13 @@ func Discover(home, workroot string) ([]Skill, []error) {
6262 {filepath.Join(home, Dirname), "personal"},
6363 {filepath.Join(workroot, Dirname), "project"},
6464 } {
65+ if !filepath.IsAbs(r.dir) {
66+ // home or workroot was empty or relative, so this root would
67+ // resolve against the process's working directory instead of a
68+ // real personal or project root. An unknown home is not a user
69+ // error, so this is silently skipped rather than reported.
70+ continue
71+ }
6572 found, probs := scan(r.dir, r.source)
6673 problems = append(problems, probs...)
6774 for _, s := range found {
+28−0internal/skills/skills_test.goView File
@@ -195,6 +195,34 @@ symlinked body
195195 }
196196 }
197197
198+ func TestEmptyHomeDoesNotScanWorkingDirectory(t *testing.T) {
199+ cwd := t.TempDir()
200+ write(t, filepath.Join(cwd, ".agents", "skills"), "leaky", wellFormed2())
201+ t.Chdir(cwd)
202+
203+ found, problems := Discover("", t.TempDir())
204+ if len(found) != 0 {
205+ t.Fatalf("found %+v, want none", found)
206+ }
207+ if len(problems) != 0 {
208+ t.Fatalf("problems: %v", problems)
209+ }
210+ }
211+
212+ func TestRelativeWorkrootDoesNotScanWorkingDirectory(t *testing.T) {
213+ cwd := t.TempDir()
214+ write(t, filepath.Join(cwd, ".agents-probe-relative", ".agents", "skills"), "leaky", wellFormed2())
215+ t.Chdir(cwd)
216+
217+ found, problems := Discover(t.TempDir(), ".agents-probe-relative")
218+ if len(found) != 0 {
219+ t.Fatalf("found %+v, want none", found)
220+ }
221+ if len(problems) != 0 {
222+ t.Fatalf("problems: %v", problems)
223+ }
224+ }
225+
198226 func TestSortedByName(t *testing.T) {
199227 home, work := t.TempDir(), t.TempDir()
200228 root := filepath.Join(home, ".agents", "skills")