Skip to content

Discover nested and linked Pi skills like Pi does - #5519

Merged
ymichael merged 3 commits into
mainfrom
fix/5364-pi-nested-skills
Oct 14, 2026
Merged

ymichael merged 3 commits into
mainfrom
fix/5364-pi-nested-skills

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Pi discovers skills at any depth under its skill roots and follows symlinked folders (its loader has done so since at least 0.27.1). BB's Pi plugin declared its four skill roots as plain strings, which default to recursive: false, so BB only scanned one level. Skills in grouping folders (~/.pi/agent/skills/team/<skill>/SKILL.md) and linked bundles (~/.pi/agent/skills/pstack → …/skills/<skill>) were missing from the / menu, the Skills page, and bb project commands. Flipping the flag alone was not enough: the daemon's recursive walker skipped every symlink, so turning recursion on would have hidden skills that users link in today (the shallow scan follows user-origin links). That regression is why the issue's autopilot attempt was reverted. Pi also reads project .agents/skills from the cwd up to the repository root, which the plugin did not declare.

What changed

  • Pi plugin (plugins/provider-pi/src/native-roots.ts):

    • Declared roots (~/.pi/agent/skills, ~/.agents/skills, .pi/skills, .agents/skills) and resolved roots (moved agent dir, settings.json skill paths) are now recursive: true.
    • Project .agents/skills now walks ancestors up to the repository root, as Pi does. .pi/skills stays cwd-only, matching Pi.
  • Recursive skill walker (apps/host-daemon/src/command-discovery.ts):

    • Follows symlinked directories under user-origin roots. Project roots still never follow links.
    • Guards against symlink cycles with a per-root set of visited real paths.
    • Skips .git and node_modules.
    • As before, it keeps descending inside skill folders and does not skip other dot folders.

    I checked these rules against each agent that uses recursive roots:

    Pi 1.1.0 Cursor 2026.06.19 Grok (source 2bdd1d6) Hermes (source b5be2a3c) This PR
    Follows linked folders yes yes yes yes yes, user roots
    Descends past a SKILL.md no yes yes yes, except support dirs yes
    Skips dot folders all fixed list none fixed list .git only
    Skips node_modules yes yes no yes yes

    Following links is common to all four. The other rules follow the majority, so Pi may list a skill nested inside another skill's folder, or under a dot folder, that Pi itself ignores. Making these rules declarable per root would need new plugin API; this PR avoids that.

  • Other providers: Cursor, Grok, and Hermes already declare recursive roots. For them, linked skill folders under user roots now appear, where they were silently skipped before, and .git/node_modules are no longer walked.

  • Wire: HOST_DAEMON_PROTOCOL_VERSION 236 → 237. No fields changed, but the meaning of recursive did: recursive scans now follow user-origin links. Without the bump, an older daemon would scan Pi roots recursively while skipping links, which hides linked Pi skills.

  • Docs (docs/configuration.md): Pi is listed among the recursively scanned providers, and its project-root row matches the declaration.

Not changed:

  • Skill names still come from the folder name. Pi, Grok, and Hermes use the frontmatter name; Cursor uses the folder name for slash ids.
  • Per-agent depth caps (Grok 6, Cursor 10) are not mirrored; BB keeps its 24-level and 1,000-entry bounds.
  • Pi's .gitignore handling is not mirrored.
  • Hermes project roots and Cursor's descendant-folder scan are not declared.

How you verified

  • Repro against the CLI, with nested user, linked-bundle, and nested project skills. On main, native Pi 1.1.0 loadSkills finds 4 and bb project commands --provider pi finds 0. On this branch, BB finds all 4.
  • In the app, typing /demo in the Pi composer on main lists only the top-level control skill. On this branch, the nested skills one and two levels deep are listed too.
  • Tests:
    • New: nested skills through a linked bundle with a cycle, a skill inside a skill, a skill under a dot folder, and .git/node_modules skipped.
    • Existing user and project symlink tests and the linked flag tests now run with both recursive: false and recursive: true.
    • The Pi declaration test covers the .agents/skills ancestors.
    • The new and parametrized tests fail on main's walker and pass here.
  • pnpm exec turbo run typecheck lint test --continue --filter='...[origin/main]'.

Fixes #5364

🤖 Generated with Claude Code

AGENT GENERATED

qa and others added 3 commits October 14, 2026 14:43
Pi scans its skill roots recursively and follows symlinked bundles; bb
declared them shallow, so nested skills never appeared. Declare Pi's
declared and resolved skill roots recursive, and make the recursive walker
follow user-origin directory links (with a cycle guard), stop at the first
SKILL.md, and skip dot directories and node_modules, matching Pi's loader.

Fixes #5364

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pi reads .agents/skills from the cwd up to the repository root, so the
project root now walks ancestors. Cursor, Grok, and Hermes keep scanning
inside skill folders and only skip a few known directories, so the
recursive walker no longer stops at the first SKILL.md and skips only
.git and node_modules; following user-origin links stays, as every one
of these agents does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 9daa623 into main Oct 14, 2026
48 checks passed
@ymichael
ymichael deleted the fix/5364-pi-nested-skills branch October 14, 2026 22:09
ymichael added a commit that referenced this pull request Oct 17, 2026
## Human comments

## What was wrong

Imported skills discovered through a symlinked directory retain their
logical path. The Skills detail page and CLI then use that directory as
the root for `host.read_file_relative` and `host.list_files`, whose
host-side validation rejects symlink roots. A listed, readable Pi skill
therefore shows `Failed to load SKILL.md.`; both `bb skill show` and `bb
skill files` return HTTP 502. This remains reproducible with the file
handler from upstream `main` at
`05771e3c82404328854468f0fff7f0f8203e2076`. The reproduction and
investigation are in #5555. Merged #5519 fixes discovery, while this
change fixes the subsequent detail reads.

## What changed

- Add a required `followRootSymlink` boolean to the two host file RPCs.
The server opts in for skill content and file-list reads; other callers
explicitly pass `false`.
- When opted in, the host resolves the root before using the existing
directory and relative-file validation. Relative reads stay confined to
the resolved skill directory, dotfiles remain denied, and file listings
continue to skip nested symlinks. Linked skills remain non-manageable.
- Increment `HOST_DAEMON_PROTOCOL_VERSION` from **240 to 241** for the
required wire fields, update existing callers and contract fixtures, and
document the policy in `docs/debugging-and-qa.md`.
- A followed root that no longer exists (removed target or dangling
link) returns the usual missing-file `ENOENT` error instead of a raw
filesystem error.
- The existing SDK and CLI skill operations use the same server paths;
there are no new user-facing flags or configuration.

## How you verified

- Reproduced the installed BB 0.46.0 failure using both `bb skill show`
and `bb skill files` against a real Pi directory link. The target
`SKILL.md` exists and resolves successfully.
- Added an owner-boundary regression covering listing a linked
directory, reading `SKILL.md` and a nested reference, hiding dotfiles,
rejecting `..`, and rejecting a nested link escaping the resolved root.
With `host-files.ts` taken from latest upstream `main`, it fails with
`Path "…/research" must not be a symlink`; it passes with this fix.
- Extended the server skill-detail test to check that both RPCs receive
the explicit opt-in. Existing generic file-root rejection tests continue
to pass with `false`.
- After rebasing onto the checked upstream `main`, all **168 focused
tests passed**:
  ```sh
pnpm exec turbo run test --filter=@bb/host-daemon --
test/command/workspace-dispatch.test.ts
src/command-handlers/host-files.test.ts
src/command-handlers/list-skills.test.ts
pnpm exec turbo run test --filter=@bb/server --
test/public/public-project-skills.test.ts
test/files/host-file-routes.test.ts
test/internal/internal-environment-change.test.ts
pnpm exec turbo run test --filter=@bb/host-daemon-contract --
test/contract.test.ts
pnpm exec turbo run lint typecheck --filter=@bb/host-daemon
--filter=@bb/server --filter=@bb/host-daemon-contract
  ```
- Formatting and `git diff --check` passed. Source verification used
Node 22.19.0 and pnpm 9.15.0 on macOS arm64. The installed desktop app
was not replaced; post-fix browser/desktop UI verification has not been
run.

- Commandeered by a maintainer: merged current `main` (protocol 240 →
241) and added the missing-root handling above, with a dangling-link
case in the regression test. Re-ran the focused host-daemon, server (8
files touching these RPCs), and contract suites plus lint/typecheck; all
pass.

Fixes #5555

> AGENT GENERATED

---------

Co-authored-by: Michael Yong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Pi nested skills are missing from BB discovery

1 participant