Skip to content

perf(skills): full multi-root recursive skill rescan on every prompt build, load_skill call, and /skills command #3921

Description

@Hmbown

Problem

Skill discovery re-walks up to ~10 roots recursively (depth 8, with per-dir fs::canonicalize) on every prompt construction, every load_skill tool call, and every /skills invocation — for data that changes rarely.

Evidence

  • crates/tui/src/prompts.rs:1240-1254 — the ## Skills system-prompt block re-runs discovery from disk on each prompt build.
  • crates/tui/src/skills/mod.rs:160-283 — the walk (canonicalize per directory at :280); roots list at :550-584 — note the workspace-root skills/ candidate (:558) means any repo with an unrelated top-level skills/ tree gets an 8-level recursive walk every turn.
  • crates/tui/src/tools/skill.rs:98-104 and skills.rs:23-29 repeat the walk per call.

Impact

Per-turn latency proportional to workspace layout — worst on big monorepos with a coincidental skills/ directory or large ~/.agents/skills libraries.

Proposed approach

Cache the merged SkillRegistry keyed by (dir list, per-root mtime): stat the roots and re-walk only when an mtime changed; invalidate explicitly on /skill install|uninstall|update (hooks already exist: refresh_skill_cache, app.rs:2882-2889).

Acceptance criteria

  • Subsequent prompt builds in an unchanged workspace do zero recursive walks (verifiable via a discovery counter in tests); adding/removing a SKILL.md is still picked up on the next turn; load_skill uses the same cache.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    cleanupCode cleanup, refactor, or maintenance workenhancementNew feature or requestperformanceRuntime/render performance

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions