mirror of
https://github.com/thedotmack/claude-mem.git
synced 2026-09-20 04:23:02 +08:00
a51affa9ed
`runBatchQuery()` shells out with `tree-sitter query -p <grammar-dir>`, and `-p/--grammar-path` is documented as implying `--rebuild`: the CLI recompiled the grammar from C on every invocation. Measured with tree-sitter-cli 0.26.9 on Linux x86_64, one `smart_outline` over a 933-line TypeScript file cost 734/711/704 ms across three runs, nearly all of it the compile. The artifact the CLI wrote to its own cache was rewritten each time and never read back. Grammars are now built once into <data-dir>/tree-sitter-libs and queried with `-l <lib> --lang-name <language>`. The same three runs become 733/16/12 ms and return the identical 30 symbols; the first call still pays one build. Because `parseFilesBatch()` issues one CLI call per language group, the old cost was a fixed ~0.7s per language per tool call regardless of batch size, paid alike by smart_outline, smart_search and smart_unfold, and repeatedly by anything that walks a repository. The artifact lives in the data dir rather than in node_modules: an update replaces node_modules wholesale, and those directories belong to the installer. Staleness is an mtime comparison against src/parser.c and the optional scanner — npm and bun both stamp installed files with the install time, so a plugin update invalidates the previous artifact on its own. The check is re-run per call rather than memoized, since four stats cost nothing next to the spawn they guard and a memo would pin a long-lived MCP server to the grammar that was current at boot. Every failure path falls back to the previous `-p` invocation: a build that does not compile, or a grammar whose language function is not named after our language key. The opt-out is remembered per language, so a mismatch costs one extra spawn once instead of two per batch forever. All 24 shipped grammars were verified to bind under their existing GRAMMAR_PACKAGES key, including the irregular ones (typescript, tsx, kotlin, php, scss, sql, markdown). Fixes #3926 Co-authored-by: rorar <rorar@users.noreply.github.com> Co-authored-by: Alex Newman <thedotmack@users.noreply.github.com>