perf: lazy-load tree-sitter grammars to eliminate startup lag (#189)
Every muse command (including muse init) was paying the full cost of loading tree_sitter and all 13+ language grammar packages at import time, because app.py eagerly imports every command module, and many of those transitively pulled in ast_parser.py, which ran the adapter registry build at module level.
Changes: - ast_parser.py: move `from tree_sitter import ...` behind a TYPE_CHECKING guard; replace the module-level ADAPTERS/SEMANTIC_EXTENSIONS assignments with _adapters()/_semantic_extensions() lazy initializers. First access triggers grammar loading; subsequent accesses are O(1) dict lookups on promoted module attributes. TreeSitterAdapter.__init__ now takes a pre-built Query (removes the dead _language field). - _query.py: move SEMANTIC_EXTENSIONS import inside is_semantic() so importing _query never pulls in the grammar registry. - dead.py / deps.py: same SEMANTIC_EXTENSIONS deferral inside the helper functions that actually need it. - init.py: remove unused find_repo_root import (dead import).
Co-authored-by: Gabriel Cardona <gabriel@tellurstori.com>
No comments yet. Be the first to start the discussion.