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.
Problem
Skill discovery re-walks up to ~10 roots recursively (depth 8, with per-dir
fs::canonicalize) on every prompt construction, everyload_skilltool call, and every/skillsinvocation — for data that changes rarely.Evidence
crates/tui/src/prompts.rs:1240-1254— the## Skillssystem-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-rootskills/candidate (:558) means any repo with an unrelated top-levelskills/tree gets an 8-level recursive walk every turn.crates/tui/src/tools/skill.rs:98-104andskills.rs:23-29repeat the walk per call.Impact
Per-turn latency proportional to workspace layout — worst on big monorepos with a coincidental
skills/directory or large~/.agents/skillslibraries.Proposed approach
Cache the merged
SkillRegistrykeyed 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
load_skilluses the same cache.