@saluzi/codegraph 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/dist/bin/codegraph.d.ts +25 -0
  2. package/dist/bin/node-version-check.d.ts +37 -0
  3. package/dist/bin/uninstall.d.ts +14 -0
  4. package/dist/context/formatter.d.ts +33 -0
  5. package/dist/context/formatter.js +244 -0
  6. package/dist/context/index.d.ts +117 -0
  7. package/dist/context/index.js +1050 -0
  8. package/dist/db/index.d.ts +101 -0
  9. package/dist/db/index.js +250 -0
  10. package/dist/db/migrations.d.ts +47 -0
  11. package/dist/db/migrations.js +131 -0
  12. package/dist/db/queries.d.ts +291 -0
  13. package/dist/db/queries.js +1349 -0
  14. package/dist/db/schema.sql +151 -0
  15. package/dist/db/sqlite-adapter.d.ts +49 -0
  16. package/dist/db/sqlite-adapter.js +141 -0
  17. package/dist/directory.d.ts +62 -0
  18. package/dist/directory.js +264 -0
  19. package/dist/errors.d.ts +149 -0
  20. package/dist/errors.js +219 -0
  21. package/dist/extraction/dfm-extractor.d.ts +31 -0
  22. package/dist/extraction/dfm-extractor.js +151 -0
  23. package/dist/extraction/grammars.d.ts +94 -0
  24. package/dist/extraction/grammars.js +357 -0
  25. package/dist/extraction/index.d.ts +148 -0
  26. package/dist/extraction/index.js +1286 -0
  27. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  28. package/dist/extraction/languages/c-cpp.js +126 -0
  29. package/dist/extraction/languages/csharp.d.ts +3 -0
  30. package/dist/extraction/languages/csharp.js +72 -0
  31. package/dist/extraction/languages/dart.d.ts +3 -0
  32. package/dist/extraction/languages/dart.js +192 -0
  33. package/dist/extraction/languages/go.d.ts +3 -0
  34. package/dist/extraction/languages/go.js +58 -0
  35. package/dist/extraction/languages/index.d.ts +10 -0
  36. package/dist/extraction/languages/index.js +49 -0
  37. package/dist/extraction/languages/java.d.ts +3 -0
  38. package/dist/extraction/languages/java.js +64 -0
  39. package/dist/extraction/languages/javascript.d.ts +3 -0
  40. package/dist/extraction/languages/javascript.js +90 -0
  41. package/dist/extraction/languages/kotlin.d.ts +3 -0
  42. package/dist/extraction/languages/kotlin.js +253 -0
  43. package/dist/extraction/languages/lua.d.ts +3 -0
  44. package/dist/extraction/languages/lua.js +150 -0
  45. package/dist/extraction/languages/luau.d.ts +3 -0
  46. package/dist/extraction/languages/luau.js +37 -0
  47. package/dist/extraction/languages/pascal.d.ts +3 -0
  48. package/dist/extraction/languages/pascal.js +66 -0
  49. package/dist/extraction/languages/php.d.ts +3 -0
  50. package/dist/extraction/languages/php.js +107 -0
  51. package/dist/extraction/languages/python.d.ts +3 -0
  52. package/dist/extraction/languages/python.js +56 -0
  53. package/dist/extraction/languages/ruby.d.ts +3 -0
  54. package/dist/extraction/languages/ruby.js +114 -0
  55. package/dist/extraction/languages/rust.d.ts +3 -0
  56. package/dist/extraction/languages/rust.js +109 -0
  57. package/dist/extraction/languages/scala.d.ts +3 -0
  58. package/dist/extraction/languages/scala.js +139 -0
  59. package/dist/extraction/languages/swift.d.ts +3 -0
  60. package/dist/extraction/languages/swift.js +91 -0
  61. package/dist/extraction/languages/typescript.d.ts +3 -0
  62. package/dist/extraction/languages/typescript.js +129 -0
  63. package/dist/extraction/liquid-extractor.d.ts +52 -0
  64. package/dist/extraction/liquid-extractor.js +313 -0
  65. package/dist/extraction/parse-worker.d.ts +8 -0
  66. package/dist/extraction/parse-worker.js +94 -0
  67. package/dist/extraction/svelte-extractor.d.ts +56 -0
  68. package/dist/extraction/svelte-extractor.js +272 -0
  69. package/dist/extraction/tree-sitter-helpers.d.ts +39 -0
  70. package/dist/extraction/tree-sitter-helpers.js +103 -0
  71. package/dist/extraction/tree-sitter-types.d.ts +191 -0
  72. package/dist/extraction/tree-sitter-types.js +10 -0
  73. package/dist/extraction/tree-sitter.d.ts +238 -0
  74. package/dist/extraction/tree-sitter.js +2430 -0
  75. package/dist/extraction/vue-extractor.d.ts +36 -0
  76. package/dist/extraction/vue-extractor.js +163 -0
  77. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  78. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  79. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  80. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  81. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  82. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  83. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  84. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  85. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  86. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  87. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  88. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  89. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  90. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  91. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  92. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  93. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  94. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  95. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  96. package/dist/extraction/wasm-runtime-flags.d.ts +46 -0
  97. package/dist/extraction/wasm-runtime-flags.js +105 -0
  98. package/dist/graph/index.d.ts +8 -0
  99. package/dist/graph/index.js +13 -0
  100. package/dist/graph/queries.d.ts +109 -0
  101. package/dist/graph/queries.js +366 -0
  102. package/dist/graph/traversal.d.ts +137 -0
  103. package/dist/graph/traversal.js +528 -0
  104. package/dist/index.d.ts +509 -0
  105. package/dist/index.js +800 -0
  106. package/dist/installer/claude-md-template.d.ts +19 -0
  107. package/dist/installer/config-writer.d.ts +29 -0
  108. package/dist/installer/index.d.ts +140 -0
  109. package/dist/installer/instructions-template.d.ts +30 -0
  110. package/dist/installer/targets/claude.d.ts +55 -0
  111. package/dist/installer/targets/codex.d.ts +18 -0
  112. package/dist/installer/targets/cursor.d.ts +35 -0
  113. package/dist/installer/targets/hermes.d.ts +18 -0
  114. package/dist/installer/targets/opencode.d.ts +30 -0
  115. package/dist/installer/targets/registry.d.ts +38 -0
  116. package/dist/installer/targets/shared.d.ts +92 -0
  117. package/dist/installer/targets/toml.d.ts +64 -0
  118. package/dist/installer/targets/types.d.ts +122 -0
  119. package/dist/mcp/index.d.ts +98 -0
  120. package/dist/mcp/server-instructions.d.ts +20 -0
  121. package/dist/mcp/tools.d.ts +269 -0
  122. package/dist/mcp/transport.d.ts +117 -0
  123. package/dist/resolution/frameworks/cargo-workspace.d.ts +20 -0
  124. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  125. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  126. package/dist/resolution/frameworks/csharp.js +213 -0
  127. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  128. package/dist/resolution/frameworks/drupal.js +335 -0
  129. package/dist/resolution/frameworks/express.d.ts +8 -0
  130. package/dist/resolution/frameworks/express.js +225 -0
  131. package/dist/resolution/frameworks/go.d.ts +8 -0
  132. package/dist/resolution/frameworks/go.js +158 -0
  133. package/dist/resolution/frameworks/index.d.ts +52 -0
  134. package/dist/resolution/frameworks/index.js +137 -0
  135. package/dist/resolution/frameworks/java.d.ts +8 -0
  136. package/dist/resolution/frameworks/java.js +177 -0
  137. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  138. package/dist/resolution/frameworks/laravel.js +248 -0
  139. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  140. package/dist/resolution/frameworks/nestjs.js +374 -0
  141. package/dist/resolution/frameworks/python.d.ts +10 -0
  142. package/dist/resolution/frameworks/python.js +278 -0
  143. package/dist/resolution/frameworks/react.d.ts +8 -0
  144. package/dist/resolution/frameworks/react.js +272 -0
  145. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  146. package/dist/resolution/frameworks/ruby.js +198 -0
  147. package/dist/resolution/frameworks/rust.d.ts +8 -0
  148. package/dist/resolution/frameworks/rust.js +207 -0
  149. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  150. package/dist/resolution/frameworks/svelte.js +249 -0
  151. package/dist/resolution/frameworks/swift.d.ts +10 -0
  152. package/dist/resolution/frameworks/swift.js +376 -0
  153. package/dist/resolution/frameworks/vue.d.ts +9 -0
  154. package/dist/resolution/frameworks/vue.js +306 -0
  155. package/dist/resolution/import-resolver.d.ts +61 -0
  156. package/dist/resolution/import-resolver.js +663 -0
  157. package/dist/resolution/index.d.ts +118 -0
  158. package/dist/resolution/index.js +744 -0
  159. package/dist/resolution/lru-cache.d.ts +24 -0
  160. package/dist/resolution/lru-cache.js +62 -0
  161. package/dist/resolution/name-matcher.d.ts +50 -0
  162. package/dist/resolution/name-matcher.js +384 -0
  163. package/dist/resolution/path-aliases.d.ts +72 -0
  164. package/dist/resolution/path-aliases.js +238 -0
  165. package/dist/resolution/strip-comments.d.ts +40 -0
  166. package/dist/resolution/strip-comments.js +441 -0
  167. package/dist/resolution/types.d.ts +181 -0
  168. package/dist/resolution/types.js +8 -0
  169. package/dist/search/query-parser.d.ts +61 -0
  170. package/dist/search/query-parser.js +177 -0
  171. package/dist/search/query-utils.d.ts +59 -0
  172. package/dist/search/query-utils.js +383 -0
  173. package/dist/sync/git-hooks.d.ts +54 -0
  174. package/dist/sync/git-hooks.js +223 -0
  175. package/dist/sync/index.d.ts +25 -0
  176. package/dist/sync/index.js +28 -0
  177. package/dist/sync/watch-policy.d.ts +51 -0
  178. package/dist/sync/watch-policy.js +124 -0
  179. package/dist/sync/watcher.d.ts +83 -0
  180. package/dist/sync/watcher.js +192 -0
  181. package/dist/types.d.ts +433 -0
  182. package/dist/types.js +75 -0
  183. package/dist/ui/glyphs.d.ts +42 -0
  184. package/dist/ui/shimmer-progress.d.ts +11 -0
  185. package/dist/ui/shimmer-worker.d.ts +2 -0
  186. package/dist/ui/types.d.ts +20 -0
  187. package/dist/utils.d.ts +231 -0
  188. package/dist/utils.js +549 -0
  189. package/package.json +24 -0
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+ /**
3
+ * Grammar Loading and Caching
4
+ *
5
+ * Uses web-tree-sitter (WASM) for universal cross-platform support.
6
+ * Grammars are loaded lazily — only languages actually present in the project
7
+ * are compiled, keeping V8 WASM memory pressure low on large codebases.
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || (function () {
26
+ var ownKeys = function(o) {
27
+ ownKeys = Object.getOwnPropertyNames || function (o) {
28
+ var ar = [];
29
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
+ return ar;
31
+ };
32
+ return ownKeys(o);
33
+ };
34
+ return function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ })();
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.EXTENSION_MAP = void 0;
44
+ exports.isSourceFile = isSourceFile;
45
+ exports.initGrammars = initGrammars;
46
+ exports.loadGrammarsForLanguages = loadGrammarsForLanguages;
47
+ exports.loadAllGrammars = loadAllGrammars;
48
+ exports.isGrammarsInitialized = isGrammarsInitialized;
49
+ exports.getParser = getParser;
50
+ exports.detectLanguage = detectLanguage;
51
+ exports.isLanguageSupported = isLanguageSupported;
52
+ exports.isGrammarLoaded = isGrammarLoaded;
53
+ exports.getSupportedLanguages = getSupportedLanguages;
54
+ exports.resetParser = resetParser;
55
+ exports.clearParserCache = clearParserCache;
56
+ exports.getUnavailableGrammarErrors = getUnavailableGrammarErrors;
57
+ exports.getLanguageDisplayName = getLanguageDisplayName;
58
+ const path = __importStar(require("path"));
59
+ const web_tree_sitter_1 = require("web-tree-sitter");
60
+ /**
61
+ * WASM filename map — maps each language to its .wasm grammar file
62
+ * in the tree-sitter-wasms package.
63
+ */
64
+ const WASM_GRAMMAR_FILES = {
65
+ typescript: 'tree-sitter-typescript.wasm',
66
+ tsx: 'tree-sitter-tsx.wasm',
67
+ javascript: 'tree-sitter-javascript.wasm',
68
+ jsx: 'tree-sitter-javascript.wasm',
69
+ python: 'tree-sitter-python.wasm',
70
+ go: 'tree-sitter-go.wasm',
71
+ rust: 'tree-sitter-rust.wasm',
72
+ java: 'tree-sitter-java.wasm',
73
+ c: 'tree-sitter-c.wasm',
74
+ cpp: 'tree-sitter-cpp.wasm',
75
+ csharp: 'tree-sitter-c_sharp.wasm',
76
+ php: 'tree-sitter-php.wasm',
77
+ ruby: 'tree-sitter-ruby.wasm',
78
+ swift: 'tree-sitter-swift.wasm',
79
+ kotlin: 'tree-sitter-kotlin.wasm',
80
+ dart: 'tree-sitter-dart.wasm',
81
+ pascal: 'tree-sitter-pascal.wasm',
82
+ scala: 'tree-sitter-scala.wasm',
83
+ lua: 'tree-sitter-lua.wasm',
84
+ luau: 'tree-sitter-luau.wasm',
85
+ };
86
+ /**
87
+ * File extension to Language mapping
88
+ */
89
+ exports.EXTENSION_MAP = {
90
+ '.ts': 'typescript',
91
+ '.tsx': 'tsx',
92
+ '.js': 'javascript',
93
+ '.mjs': 'javascript',
94
+ '.cjs': 'javascript',
95
+ '.jsx': 'jsx',
96
+ '.py': 'python',
97
+ '.pyw': 'python',
98
+ '.go': 'go',
99
+ '.rs': 'rust',
100
+ '.java': 'java',
101
+ '.c': 'c',
102
+ '.h': 'c', // Could also be C++, defaulting to C
103
+ '.cpp': 'cpp',
104
+ '.cc': 'cpp',
105
+ '.cxx': 'cpp',
106
+ '.hpp': 'cpp',
107
+ '.hxx': 'cpp',
108
+ '.cs': 'csharp',
109
+ '.php': 'php',
110
+ // Drupal-specific PHP file extensions
111
+ '.module': 'php',
112
+ '.install': 'php',
113
+ '.theme': 'php',
114
+ '.inc': 'php',
115
+ // YAML (used for Drupal routing files; no symbol extraction, file-level tracking only)
116
+ '.yml': 'yaml',
117
+ '.yaml': 'yaml',
118
+ // Twig templates (file-level tracking only, no symbol extraction)
119
+ '.twig': 'twig',
120
+ '.rb': 'ruby',
121
+ '.rake': 'ruby',
122
+ '.swift': 'swift',
123
+ '.kt': 'kotlin',
124
+ '.kts': 'kotlin',
125
+ '.dart': 'dart',
126
+ '.liquid': 'liquid',
127
+ '.svelte': 'svelte',
128
+ '.vue': 'vue',
129
+ '.pas': 'pascal',
130
+ '.dpr': 'pascal',
131
+ '.dpk': 'pascal',
132
+ '.lpr': 'pascal',
133
+ '.dfm': 'pascal',
134
+ '.fmx': 'pascal',
135
+ '.scala': 'scala',
136
+ '.sc': 'scala',
137
+ '.lua': 'lua',
138
+ '.luau': 'luau',
139
+ };
140
+ /**
141
+ * Whether a file is one CodeGraph can parse, based purely on its extension.
142
+ * This is the single source of truth for "should we index this file" — derived
143
+ * from EXTENSION_MAP so parser support and indexing selection never drift.
144
+ */
145
+ function isSourceFile(filePath) {
146
+ const dot = filePath.lastIndexOf('.');
147
+ if (dot < 0)
148
+ return false;
149
+ return filePath.slice(dot).toLowerCase() in exports.EXTENSION_MAP;
150
+ }
151
+ /**
152
+ * Caches for loaded grammars and parsers
153
+ */
154
+ const parserCache = new Map();
155
+ const languageCache = new Map();
156
+ const unavailableGrammarErrors = new Map();
157
+ let parserInitialized = false;
158
+ /**
159
+ * Initialize the tree-sitter WASM runtime. Must be called before loading grammars.
160
+ * Does NOT load any grammar WASM files — use loadGrammarsForLanguages() for that.
161
+ * Idempotent — safe to call multiple times.
162
+ */
163
+ async function initGrammars() {
164
+ if (parserInitialized)
165
+ return;
166
+ await web_tree_sitter_1.Parser.init();
167
+ parserInitialized = true;
168
+ }
169
+ /**
170
+ * Load grammar WASM files for specific languages only.
171
+ * Skips languages that are already loaded or have no WASM grammar.
172
+ * Must be called after initGrammars().
173
+ */
174
+ async function loadGrammarsForLanguages(languages) {
175
+ if (!parserInitialized) {
176
+ await initGrammars();
177
+ }
178
+ // Deduplicate and filter to languages that have WASM grammars and aren't already loaded
179
+ const toLoad = [...new Set(languages)].filter((lang) => lang in WASM_GRAMMAR_FILES &&
180
+ !languageCache.has(lang) &&
181
+ !unavailableGrammarErrors.has(lang));
182
+ // Load grammars sequentially to avoid web-tree-sitter WASM race condition on Node 20+
183
+ // See: https://github.com/tree-sitter/tree-sitter/issues/2338
184
+ for (const lang of toLoad) {
185
+ const wasmFile = WASM_GRAMMAR_FILES[lang];
186
+ try {
187
+ // All WASM grammars are vendored locally in the wasm/ directory
188
+ // (patched by Saluzi to avoid tree-sitter-wasms npm dependency)
189
+ const wasmPath = path.join(__dirname, 'wasm', wasmFile);
190
+ const language = await web_tree_sitter_1.Language.load(wasmPath);
191
+ languageCache.set(lang, language);
192
+ }
193
+ catch (error) {
194
+ const message = error instanceof Error ? error.message : String(error);
195
+ console.warn(`[CodeGraph] Failed to load ${lang} grammar — parsing will be unavailable: ${message}`);
196
+ unavailableGrammarErrors.set(lang, message);
197
+ }
198
+ }
199
+ }
200
+ /**
201
+ * Load ALL grammar WASM files. Convenience function for tests and
202
+ * backward compatibility. Prefer loadGrammarsForLanguages() in production.
203
+ */
204
+ async function loadAllGrammars() {
205
+ const allLanguages = Object.keys(WASM_GRAMMAR_FILES);
206
+ await loadGrammarsForLanguages(allLanguages);
207
+ }
208
+ /**
209
+ * Check if grammars have been initialized
210
+ */
211
+ function isGrammarsInitialized() {
212
+ return parserInitialized;
213
+ }
214
+ /**
215
+ * Get a parser for the specified language.
216
+ * Returns synchronously from pre-loaded cache.
217
+ */
218
+ function getParser(language) {
219
+ if (parserCache.has(language)) {
220
+ return parserCache.get(language);
221
+ }
222
+ const lang = languageCache.get(language);
223
+ if (!lang) {
224
+ return null;
225
+ }
226
+ const parser = new web_tree_sitter_1.Parser();
227
+ parser.setLanguage(lang);
228
+ parserCache.set(language, parser);
229
+ return parser;
230
+ }
231
+ /**
232
+ * Detect language from file extension
233
+ */
234
+ function detectLanguage(filePath, source) {
235
+ const ext = filePath.substring(filePath.lastIndexOf('.')).toLowerCase();
236
+ const lang = exports.EXTENSION_MAP[ext] || 'unknown';
237
+ // .h files could be C or C++ — check source content for C++ features
238
+ if (lang === 'c' && ext === '.h' && source) {
239
+ if (looksLikeCpp(source))
240
+ return 'cpp';
241
+ }
242
+ return lang;
243
+ }
244
+ /**
245
+ * Heuristic: does a .h file contain C++ constructs?
246
+ * Checks the first ~8KB for patterns that are unique to C++ and never valid C.
247
+ */
248
+ function looksLikeCpp(source) {
249
+ const sample = source.substring(0, 8192);
250
+ return /\bnamespace\b|\bclass\s+\w+\s*[:{]|\btemplate\s*<|\b(?:public|private|protected)\s*:|\bvirtual\b|\busing\s+(?:namespace\b|\w+\s*=)/.test(sample);
251
+ }
252
+ /**
253
+ * Check if a language is supported (has a grammar defined).
254
+ * Returns true if the grammar exists, even if not yet loaded.
255
+ */
256
+ function isLanguageSupported(language) {
257
+ if (language === 'svelte')
258
+ return true; // custom extractor (script block delegation)
259
+ if (language === 'vue')
260
+ return true; // custom extractor (script block delegation)
261
+ if (language === 'liquid')
262
+ return true; // custom regex extractor
263
+ if (language === 'yaml')
264
+ return true; // file-level tracking only; Drupal routing extraction via framework resolver
265
+ if (language === 'twig')
266
+ return true; // file-level tracking only
267
+ if (language === 'unknown')
268
+ return false;
269
+ return language in WASM_GRAMMAR_FILES;
270
+ }
271
+ /**
272
+ * Check if a grammar has been loaded and is ready for parsing.
273
+ */
274
+ function isGrammarLoaded(language) {
275
+ if (language === 'svelte' || language === 'vue' || language === 'liquid')
276
+ return true;
277
+ if (language === 'yaml' || language === 'twig')
278
+ return true; // no WASM grammar needed
279
+ return languageCache.has(language);
280
+ }
281
+ /**
282
+ * Get all supported languages (those with grammar definitions).
283
+ */
284
+ function getSupportedLanguages() {
285
+ return [...Object.keys(WASM_GRAMMAR_FILES), 'svelte', 'vue', 'liquid'];
286
+ }
287
+ /**
288
+ * Reset the cached parser for a language to reclaim WASM heap memory.
289
+ * The tree-sitter WASM runtime accumulates fragmented memory over thousands
290
+ * of parses. Deleting and recreating the Parser instance forces the WASM
291
+ * heap to reset, preventing "memory access out of bounds" crashes in
292
+ * large repos.
293
+ */
294
+ function resetParser(language) {
295
+ const old = parserCache.get(language);
296
+ if (old) {
297
+ old.delete();
298
+ parserCache.delete(language);
299
+ }
300
+ }
301
+ /**
302
+ * Clear parser/grammar caches (useful for testing)
303
+ */
304
+ function clearParserCache() {
305
+ for (const parser of parserCache.values()) {
306
+ parser.delete();
307
+ }
308
+ parserCache.clear();
309
+ // Note: languageCache is NOT cleared — WASM languages persist.
310
+ // To fully re-init, set parserInitialized = false and call initGrammars() again.
311
+ unavailableGrammarErrors.clear();
312
+ }
313
+ /**
314
+ * Report grammars that failed to load.
315
+ */
316
+ function getUnavailableGrammarErrors() {
317
+ const out = {};
318
+ for (const [language, message] of unavailableGrammarErrors.entries()) {
319
+ out[language] = message;
320
+ }
321
+ return out;
322
+ }
323
+ /**
324
+ * Get language display name
325
+ */
326
+ function getLanguageDisplayName(language) {
327
+ const names = {
328
+ typescript: 'TypeScript',
329
+ javascript: 'JavaScript',
330
+ tsx: 'TypeScript (TSX)',
331
+ jsx: 'JavaScript (JSX)',
332
+ python: 'Python',
333
+ go: 'Go',
334
+ rust: 'Rust',
335
+ java: 'Java',
336
+ c: 'C',
337
+ cpp: 'C++',
338
+ csharp: 'C#',
339
+ php: 'PHP',
340
+ ruby: 'Ruby',
341
+ swift: 'Swift',
342
+ kotlin: 'Kotlin',
343
+ dart: 'Dart',
344
+ svelte: 'Svelte',
345
+ vue: 'Vue',
346
+ liquid: 'Liquid',
347
+ pascal: 'Pascal / Delphi',
348
+ scala: 'Scala',
349
+ lua: 'Lua',
350
+ luau: 'Luau',
351
+ yaml: 'YAML',
352
+ twig: 'Twig',
353
+ unknown: 'Unknown',
354
+ };
355
+ return names[language] || language;
356
+ }
357
+ //# sourceMappingURL=grammars.js.map
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Extraction Orchestrator
3
+ *
4
+ * Coordinates file scanning, parsing, and database storage.
5
+ */
6
+ import * as fs from 'fs'
7
+ import { ExtractionResult, ExtractionError } from '../types'
8
+ import { QueryBuilder } from '../db/queries'
9
+ /**
10
+ * Progress callback for indexing operations
11
+ */
12
+ export interface IndexProgress {
13
+ phase: 'scanning' | 'parsing' | 'storing' | 'resolving'
14
+ current: number
15
+ total: number
16
+ currentFile?: string
17
+ }
18
+ /**
19
+ * Result of an indexing operation
20
+ */
21
+ export interface IndexResult {
22
+ success: boolean
23
+ filesIndexed: number
24
+ filesSkipped: number
25
+ filesErrored: number
26
+ nodesCreated: number
27
+ edgesCreated: number
28
+ errors: ExtractionError[]
29
+ durationMs: number
30
+ }
31
+ /**
32
+ * Result of a sync operation
33
+ */
34
+ export interface SyncResult {
35
+ filesChecked: number
36
+ filesAdded: number
37
+ filesModified: number
38
+ filesRemoved: number
39
+ nodesUpdated: number
40
+ durationMs: number
41
+ changedFilePaths?: string[]
42
+ }
43
+ /**
44
+ * Calculate SHA256 hash of file contents
45
+ */
46
+ export declare function hashContent(content: string): string
47
+ /**
48
+ * Recursively scan a directory for source files.
49
+ *
50
+ * In git repos, uses `git ls-files` (inherently respects .gitignore at all
51
+ * levels), then keeps files with a supported source extension. For non-git
52
+ * projects, falls back to a filesystem walk that parses .gitignore itself.
53
+ */
54
+ export declare function scanDirectory(
55
+ rootDir: string,
56
+ onProgress?: (current: number, file: string) => void,
57
+ ): string[]
58
+ /**
59
+ * Async variant of scanDirectory that yields to the event loop periodically,
60
+ * allowing worker threads to receive and render progress messages.
61
+ */
62
+ export declare function scanDirectoryAsync(
63
+ rootDir: string,
64
+ onProgress?: (current: number, file: string) => void,
65
+ ): Promise<string[]>
66
+ /**
67
+ * Extraction orchestrator
68
+ */
69
+ export declare class ExtractionOrchestrator {
70
+ private rootDir
71
+ private queries
72
+ /**
73
+ * Names of frameworks detected for this project, populated by indexAll().
74
+ * Passed to extractFromSource so framework-specific extractors (route nodes,
75
+ * middleware, etc.) run after the tree-sitter pass. Cleared if detection
76
+ * hasn't run yet so single-file re-index paths can detect on the spot.
77
+ */
78
+ private detectedFrameworkNames
79
+ constructor(rootDir: string, queries: QueryBuilder)
80
+ /**
81
+ * Build a filesystem-backed ResolutionContext sufficient for framework
82
+ * detection. Graph-query methods (getNodesByName etc.) return empty because
83
+ * the DB hasn't been populated yet, but detect() only uses readFile,
84
+ * fileExists, and getAllFiles, so that's fine.
85
+ */
86
+ private buildDetectionContext
87
+ /**
88
+ * Detect frameworks on demand using the current scanned files (or a fresh
89
+ * scan if none are provided). Cached on the orchestrator so repeat calls
90
+ * inside a single run don't re-scan.
91
+ */
92
+ private ensureDetectedFrameworks
93
+ /**
94
+ * Index all files in the project
95
+ */
96
+ indexAll(
97
+ onProgress?: (progress: IndexProgress) => void,
98
+ signal?: AbortSignal,
99
+ verbose?: boolean,
100
+ ): Promise<IndexResult>
101
+ /**
102
+ * Index specific files
103
+ */
104
+ indexFiles(filePaths: string[]): Promise<IndexResult>
105
+ /**
106
+ * Index a single file
107
+ */
108
+ indexFile(relativePath: string): Promise<ExtractionResult>
109
+ /**
110
+ * Index a single file with pre-read content and stats.
111
+ * Used by the parallel batch reader to avoid redundant file I/O.
112
+ */
113
+ indexFileWithContent(
114
+ relativePath: string,
115
+ content: string,
116
+ stats: fs.Stats,
117
+ ): Promise<ExtractionResult>
118
+ /**
119
+ * Store extraction result in database
120
+ */
121
+ private storeExtractionResult
122
+ /**
123
+ * Sync with current file state.
124
+ * Uses git status as a fast path when available, falling back to full scan.
125
+ */
126
+ sync(onProgress?: (progress: IndexProgress) => void): Promise<SyncResult>
127
+ /**
128
+ * Get files that have changed since last index.
129
+ * Uses git status as a fast path when available, falling back to full scan.
130
+ */
131
+ getChangedFiles(): {
132
+ added: string[]
133
+ modified: string[]
134
+ removed: string[]
135
+ }
136
+ }
137
+ export { extractFromSource } from './tree-sitter'
138
+ export {
139
+ detectLanguage,
140
+ isSourceFile,
141
+ isLanguageSupported,
142
+ isGrammarLoaded,
143
+ getSupportedLanguages,
144
+ initGrammars,
145
+ loadGrammarsForLanguages,
146
+ loadAllGrammars,
147
+ } from './grammars'
148
+ //# sourceMappingURL=index.d.ts.map