Repository navigation
fix(skills): bound the skill and command walk by entries and reads, not folders alone - #1746
Merged
Merged
Conversation
Share folder, entry, and read allowances across Command Code, Claude, and Devin discovery roots. Add deterministic linked-lattice regressions while preserving normal-tree catalog behavior. Refs #1452
Do not charge absent optional ignore files against the read allowance, and allow realistic large skill trees. Filter Claude and Devin command metadata from the original read so exhaustion retains the completed visible prefix. Cover normal large catalogs and command cap boundaries while preserving lattice bounds. Refs #1452
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Owner
Author
|
Merge pass: reviewed in place of a CodeRabbit review (rate-limited). A gate reviewer on a different model than the author's confirmed:
|
devswha
added a commit
that referenced
this pull request
Oct 26, 2026
…s in discovery (#1970) ## Change Follow-ups from #1449's review (#1452): Command Code's skill and command discovery. - **4, duplicate rows for custom commands with the same name** (`server/skills/cmd.ts`): one row per name now, the one Command Code itself would run. Builtins win over custom commands. The user's commands win over the project's, and the cwd's over the repository root's. Among nested commands with the same basename, the first in Node's depth-first, byte-sorted `readdir` order wins. Command Code runs under Node, so that order is what it dispatches; Bun's raw directory order differs, so the walk sorts by UTF-8 bytes. - **6, the shared budget could hide skills**: the walk still has the same total bound (4,096 folders, 32,768 entries, 4,096 reads). Now the user's own roots take their turn first, roots that do not exist take nothing, and a root that ends early leaves its unused allowance to the rest. A huge or hostile repository can no longer hide the user's skills. Ordinary trees list what main lists. - **5, `/mode:` completion** (`shared/skill-syntax.ts`): Command Code is namespaced, so `/mode:` and `/mode:pl` keep the menu open. - **7, tests**: - Command walks up to the repository boundary. - Precedence collisions, the ordinary-catalog sizes from the review, alias floods, and hostile roots with 600 personal skills kept. - Readdir and dirent counts under a spent budget. - The `cmd-nested` demo case now gets its rows from real discovery over a temporary tree. - **LOW**: - `skillName` reads a BOM-prefixed `SKILL.md` header. - `server/skills/hermes.ts` reads at most 64 KiB, with the newline-restricted header pattern. - A test checks that distinct configured folders share one bound. - **#1444 LOW, `O_NOCTTY`**: `openRegular` in `server/skills/walk.ts` opens with `O_NOCTTY` where the platform has it. **Not a defect, 3: skill precedence is project-first.** That is Command Code's own order: `[email protected]` (the pinned version, read from the npm package and never run) lists project `.commandcode/skills`, project `.agents/skills`, user roots, extra locations, then bundled skills, first name wins (`reference/skills.md`, `createSkillRegistry`). A collision test pins it. **Already fixed on main, 1 and 2**: #1746 counts entries and reads, and gives Claude and Devin one budget per discovery. Fixes #1452 ## Verification - New tests fail on origin/main and pass here: the dedupe cases (also on tmpfs, where directory order differs), the `/mode:` completion, the BOM name, the Hermes bounds, and the hostile-root reservations. The ordinary-catalog cases pass on both main and this branch, so ordinary trees list the same rows. - Probe from the review, 1,000 configured aliases to one 40,000-file directory: main 1 readdir and 158 ms; the first fix round 1,000 readdirs, 40 million entries and 14.5 s; this branch 1 readdir, 40,000 entries and about 180 ms. - Single-file runs on the rebased head: 437 pass, 0 fail across the 16 touched and dependent test files (`server/skills/*.test.ts`, `server/commands.test.ts`, `shared/skill-syntax.test.ts`, `src/lib/compose.test.ts`). - Reviews: - Round 1: omo-native-code-reviewer and Codex (gpt-6.1-sol, xhigh) found the readdir-order dedupe and the fixed per-root shares. - Round 2: the code reviewer found resumed walks re-reading directories after the budget was spent, and Codex the UTF-16 sort. - Round 3: the code reviewer approved; Codex found the personal reservation ended before buffered entries were processed (512 configured aliases took 100 personal skills to 0). Fixed: the reservation now holds until charged work crosses half the bound. - Round 4, on the head rebased onto main: omo-native-code-reviewer APPROVE (LOW notes only; mutating the reservation, the byte sort or the cwd-first walk fails a test each) and Codex APPROVE (its reproduction keeps 100 of 100 personal skills; ordinary rows equal main's). - Names compare case-insensitively, as Command Code's own slash menu does (it dedupes names by `toLowerCase()` and dispatches with a lowercased match), and its skill names are lowercase only. - Browser: `bun scripts/agent-skill-menu-demo-regression.ts cmd-nested` (rows from real discovery over a temporary tree): the nested `/component` row and `/mode:` / `/mode:pl` completion pass at 1280 and 390 px in dark and light, 12 screenshots; the same case at 1440 px also passes (6 screenshots, local run only). - `bun run check fast` on the rebased head: workflow syntax, generated files, typecheck and build pass; unit tests 7,226 pass, 1 fail. The one failure is `scripts/check.test.ts` ("fails closed when source identity is lost"), untouched here: its nested check was refused the PC-wide check slot after its 20 s wait on a host running about 35 other lanes' checks. Run alone, the file passes 66 of 66. ## Fix round after the merge-pass gate - **G1, cut-short command roots** (84dba53): a walk that ends while the shared bound is spent may hold names it never listed. After such a command root (priority: the user's, then the cwd's up to the repository root), lower-priority command roots list nothing, and skills are offered only as `/skill:<name>`, which Command Code 1.84.0 always resolves to the skill (`parseSkillNamespacedCommand`). - **Same root, after a skip** (7c2071e, from Codex's review of 84dba53): a command row is kept only if the bound was not yet spent when it was found, so the kept rows are a prefix of the walk with nothing skipped before them. - **Unreadable command root** (84dba53, CodeRabbit): an EACCES root lists nothing instead of throwing out of discovery, as Command Code's own loader does. - **Kept, by choice:** a project skill root cut short beside a personal skill of the same name still lists the personal one; dropping it would let a large repository hide the user's skills again (item 6). main behaves the same. - Each fix has a test that fails before it and passes after. Untruncated catalogs list the same rows as before. - Reviews: omo-native-code-reviewer APPROVE on 84dba53 and on 7c2071e (mutations of each fix fail a test). Codex: Codex (gpt-6.1-sol, xhigh) found the same-root case on 84dba53, then APPROVE on 7c2071e (its folder- and entry-exhaustion reproductions pass; 224 budget combinations keep a safe prefix; untruncated catalogs match). - `bun run check fast` on 7c2071e: all steps pass (unit 7,230 pass, 0 fail, 24 skipped). - Browser, `cmd-nested` on 7c2071e: 12 of 12 scenarios pass at 1280 and 390 px, dark and light. --------- Co-authored-by: mp <mp@local>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
Items 1 and 2 of #1452. The skill and custom-command walk in
server/skills/walk.tscounted folder visits only, so a repository whose few real folders are linked into a lattice made the walk pass through them up to 4,096 times, repeating astatSyncper entry and, for commands, a 64 KiB read per.mdat every pass (9 s and 27.7 s measured in the issue). The shared discovery budget now also counts directory entries (32,768) and file reads (4,096; a missing optional file such as an absent ignore file does not count) besides folder visits (4,096), and Claude and Devin share one budget per discovery as Command Code already did. Normal trees list the same rows as before, and when a cap is reached Claude and Devin keep the commands found so far, in order, because each command's metadata is filtered from its own read rather than after reading them all.Items 3-7 and the LOWs stay open; item 5 needs
shared/skill-syntax.ts, which another open PR holds.Refs #1452
Validation
server/skills/walk.test.tscases build a linked lattice in a temp folder and count the filesystem work (not time); they fail on main. Others keep all 300 and 1,500 ordinary skills, and give an intact, ordered prefix for 513, 1,024 and 4,097 command files.bun test server/skills server/commands.test.ts: 340 pass, so the existing catalogs are unchanged.bun run check fast: pass.