Skip to content

fix: doctor resolves skills/ from install path when run outside repo#128

Open
TheAndersMadsen wants to merge 1 commit intogarrytan:masterfrom
TheAndersMadsen:fix-resolver-fallback-paths
Open

fix: doctor resolves skills/ from install path when run outside repo#128
TheAndersMadsen wants to merge 1 commit intogarrytan:masterfrom
TheAndersMadsen:fix-resolver-fallback-paths

Conversation

@TheAndersMadsen
Copy link
Copy Markdown

Summary

gbrain doctor reports resolver_health: warn — "Could not find skills directory" for every user who installed via bun install github:garrytan/gbrain and runs gbrain from ~ or any other directory that has no skills/RESOLVER.md up the tree. The bundled skills/ directory lives under node_modules/gbrain/skills/ but the cwd-only walk in findRepoRoot() never looks there.

Impact: every hosted-CLI install takes a permanent -5 on the health score, plus the scary-sounding warning noise, even though everything is actually wired correctly.

Fix

Three-tier resolution in findRepoRoot() (first hit wins):

  1. GBRAIN_SKILLS_DIR env var — explicit override for Docker mounts, CI, monorepo subdirs, or anyone who wants a deterministic path.
  2. Walk up from cwd — original behavior, preferred when you're inside a brain repo.
  3. Walk up from this module's install path — via fileURLToPath(import.meta.url), catches node_modules/gbrain/ automatically without user config.

Also refactors the walk into a walkUpFor(start, relPath) helper so cwd and install-path both share a single, tested implementation.

Test plan

  • bun test test/doctor.test.ts — 7 pass, 0 fail (2 new tests added)
  • bun test (full suite) — 823 pass, 126 skip, 0 fail
  • Verified from a hosted install on Linux aarch64: cd ~ && gbrain doctor --fast --json no longer shows "Could not find skills directory" — resolver_health now reports the actual resolver state (found 10 upstream DRY_VIOLATION warnings in bundled skill content, which is a separate issue).
  • Verified env override: GBRAIN_SKILLS_DIR=/tmp/my-skills gbrain doctor --fast uses the override path.
  • Verified cwd walk unchanged when running from inside a brain repo.

New tests

  • resolver_health finds bundled skills when run outside repo — spawns gbrain doctor --fast --json from a fresh tmpdir and asserts the message does not contain "Could not find".
  • resolver_health honors GBRAIN_SKILLS_DIR env override — creates a tmpdir skills layout, points the env var at it, asserts the resolver finds it.

🤖 Generated with Claude Code

Before this patch, `gbrain doctor` required the user to be inside (or
below) a directory containing `skills/RESOLVER.md`. That matches the
"clone and hack on the brain" flow, but breaks the hosted/CLI-only flow
where the user installs via `bun install github:garrytan/gbrain` and
runs `gbrain` from `~` — the bundled skills live under
`node_modules/gbrain/skills/` and are invisible to a cwd-only walk.

The resolver_health check then reports "Could not find skills directory"
and drops the health score by 5 for every user of the hosted path.

Resolution now falls back through three sources (first hit wins):

  1. `GBRAIN_SKILLS_DIR` env var — explicit override for non-standard
     layouts (Docker mounts, CI, monorepo subdirs).
  2. Walk up from cwd — original behavior, still preferred when you
     are inside a brain repo.
  3. Walk up from this module's install path via `import.meta.url` —
     catches the `node_modules/gbrain/` case without requiring any
     user configuration.

Two new tests cover the hosted-CLI case (run from tmpdir, expect no
"Could not find" warning) and the env override path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant