@colbymchenry/codegraph-win32-arm64 1.4.0 → 1.5.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 (202) hide show
  1. package/bin/codegraph.cmd +1 -1
  2. package/lib/dist/bin/codegraph.js +106 -19
  3. package/lib/dist/bin/codegraph.js.map +1 -1
  4. package/lib/dist/bin/command-supervision.d.ts +38 -1
  5. package/lib/dist/bin/command-supervision.d.ts.map +1 -1
  6. package/lib/dist/bin/command-supervision.js +8 -2
  7. package/lib/dist/bin/command-supervision.js.map +1 -1
  8. package/lib/dist/context/index.d.ts.map +1 -1
  9. package/lib/dist/context/index.js +41 -11
  10. package/lib/dist/context/index.js.map +1 -1
  11. package/lib/dist/db/index.d.ts +142 -0
  12. package/lib/dist/db/index.d.ts.map +1 -1
  13. package/lib/dist/db/index.js +267 -6
  14. package/lib/dist/db/index.js.map +1 -1
  15. package/lib/dist/db/migrations.d.ts +1 -1
  16. package/lib/dist/db/migrations.d.ts.map +1 -1
  17. package/lib/dist/db/migrations.js +31 -1
  18. package/lib/dist/db/migrations.js.map +1 -1
  19. package/lib/dist/db/queries.d.ts +113 -4
  20. package/lib/dist/db/queries.d.ts.map +1 -1
  21. package/lib/dist/db/queries.js +398 -24
  22. package/lib/dist/db/queries.js.map +1 -1
  23. package/lib/dist/db/schema.sql +13 -1
  24. package/lib/dist/db/sqlite-adapter.d.ts +3 -1
  25. package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
  26. package/lib/dist/db/sqlite-adapter.js +22 -4
  27. package/lib/dist/db/sqlite-adapter.js.map +1 -1
  28. package/lib/dist/db/wal-valve.d.ts +15 -2
  29. package/lib/dist/db/wal-valve.d.ts.map +1 -1
  30. package/lib/dist/db/wal-valve.js +88 -6
  31. package/lib/dist/db/wal-valve.js.map +1 -1
  32. package/lib/dist/extraction/grammars.d.ts.map +1 -1
  33. package/lib/dist/extraction/grammars.js +63 -0
  34. package/lib/dist/extraction/grammars.js.map +1 -1
  35. package/lib/dist/extraction/index.d.ts +32 -3
  36. package/lib/dist/extraction/index.d.ts.map +1 -1
  37. package/lib/dist/extraction/index.js +313 -56
  38. package/lib/dist/extraction/index.js.map +1 -1
  39. package/lib/dist/extraction/kernel/decode.d.ts +9 -0
  40. package/lib/dist/extraction/kernel/decode.d.ts.map +1 -0
  41. package/lib/dist/extraction/kernel/decode.js +162 -0
  42. package/lib/dist/extraction/kernel/decode.js.map +1 -0
  43. package/lib/dist/extraction/kernel/index.d.ts +64 -0
  44. package/lib/dist/extraction/kernel/index.d.ts.map +1 -0
  45. package/lib/dist/extraction/kernel/index.js +279 -0
  46. package/lib/dist/extraction/kernel/index.js.map +1 -0
  47. package/lib/dist/extraction/kernel/layout.d.ts +101 -0
  48. package/lib/dist/extraction/kernel/layout.d.ts.map +1 -0
  49. package/lib/dist/extraction/kernel/layout.js +104 -0
  50. package/lib/dist/extraction/kernel/layout.js.map +1 -0
  51. package/lib/dist/extraction/kernel/loader.d.ts +103 -0
  52. package/lib/dist/extraction/kernel/loader.d.ts.map +1 -0
  53. package/lib/dist/extraction/kernel/loader.js +146 -0
  54. package/lib/dist/extraction/kernel/loader.js.map +1 -0
  55. package/lib/dist/extraction/languages/c-cpp.d.ts +14 -0
  56. package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  57. package/lib/dist/extraction/languages/c-cpp.js +849 -12
  58. package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
  59. package/lib/dist/extraction/parse-pool.d.ts +8 -0
  60. package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
  61. package/lib/dist/extraction/parse-pool.js +15 -0
  62. package/lib/dist/extraction/parse-pool.js.map +1 -1
  63. package/lib/dist/extraction/parse-worker.js +35 -1
  64. package/lib/dist/extraction/parse-worker.js.map +1 -1
  65. package/lib/dist/extraction/store-worker.d.ts +24 -0
  66. package/lib/dist/extraction/store-worker.d.ts.map +1 -0
  67. package/lib/dist/extraction/store-worker.js +139 -0
  68. package/lib/dist/extraction/store-worker.js.map +1 -0
  69. package/lib/dist/extraction/store-writer.d.ts +63 -0
  70. package/lib/dist/extraction/store-writer.d.ts.map +1 -0
  71. package/lib/dist/extraction/store-writer.js +174 -0
  72. package/lib/dist/extraction/store-writer.js.map +1 -0
  73. package/lib/dist/extraction/tree-sitter.d.ts +22 -4
  74. package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
  75. package/lib/dist/extraction/tree-sitter.js +151 -6
  76. package/lib/dist/extraction/tree-sitter.js.map +1 -1
  77. package/lib/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  78. package/lib/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  79. package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  80. package/lib/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  81. package/lib/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  82. package/lib/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  83. package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  84. package/lib/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  85. package/lib/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  86. package/lib/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  87. package/lib/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  88. package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  89. package/lib/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  90. package/lib/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  91. package/lib/dist/extraction/wasm-runtime-flags.d.ts +15 -0
  92. package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
  93. package/lib/dist/extraction/wasm-runtime-flags.js +27 -3
  94. package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
  95. package/lib/dist/index.d.ts +19 -6
  96. package/lib/dist/index.d.ts.map +1 -1
  97. package/lib/dist/index.js +233 -17
  98. package/lib/dist/index.js.map +1 -1
  99. package/lib/dist/installer/beta-signup.d.ts +54 -0
  100. package/lib/dist/installer/beta-signup.d.ts.map +1 -0
  101. package/lib/dist/installer/beta-signup.js +178 -0
  102. package/lib/dist/installer/beta-signup.js.map +1 -0
  103. package/lib/dist/installer/index.d.ts +42 -0
  104. package/lib/dist/installer/index.d.ts.map +1 -1
  105. package/lib/dist/installer/index.js +105 -1
  106. package/lib/dist/installer/index.js.map +1 -1
  107. package/lib/dist/mcp/index.d.ts.map +1 -1
  108. package/lib/dist/mcp/index.js +8 -0
  109. package/lib/dist/mcp/index.js.map +1 -1
  110. package/lib/dist/mcp/liveness-watchdog.d.ts +18 -1
  111. package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
  112. package/lib/dist/mcp/liveness-watchdog.js +73 -13
  113. package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
  114. package/lib/dist/mcp/proxy.js +1 -1
  115. package/lib/dist/mcp/proxy.js.map +1 -1
  116. package/lib/dist/mcp/session.d.ts +14 -0
  117. package/lib/dist/mcp/session.d.ts.map +1 -1
  118. package/lib/dist/mcp/session.js +22 -1
  119. package/lib/dist/mcp/session.js.map +1 -1
  120. package/lib/dist/mcp/tools.d.ts.map +1 -1
  121. package/lib/dist/mcp/tools.js +76 -1
  122. package/lib/dist/mcp/tools.js.map +1 -1
  123. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +1 -1
  124. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
  125. package/lib/dist/resolution/c-fnptr-synthesizer.js +574 -132
  126. package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
  127. package/lib/dist/resolution/callback-synthesizer.d.ts +54 -10
  128. package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
  129. package/lib/dist/resolution/callback-synthesizer.js +249 -157
  130. package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
  131. package/lib/dist/resolution/cooperative-yield.d.ts +10 -2
  132. package/lib/dist/resolution/cooperative-yield.d.ts.map +1 -1
  133. package/lib/dist/resolution/cooperative-yield.js +6 -4
  134. package/lib/dist/resolution/cooperative-yield.js.map +1 -1
  135. package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
  136. package/lib/dist/resolution/frameworks/go.js +29 -6
  137. package/lib/dist/resolution/frameworks/go.js.map +1 -1
  138. package/lib/dist/resolution/import-resolver.d.ts +2 -3
  139. package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
  140. package/lib/dist/resolution/import-resolver.js +166 -7
  141. package/lib/dist/resolution/import-resolver.js.map +1 -1
  142. package/lib/dist/resolution/index.d.ts +97 -2
  143. package/lib/dist/resolution/index.d.ts.map +1 -1
  144. package/lib/dist/resolution/index.js +783 -124
  145. package/lib/dist/resolution/index.js.map +1 -1
  146. package/lib/dist/resolution/memory-budget.d.ts +48 -0
  147. package/lib/dist/resolution/memory-budget.d.ts.map +1 -0
  148. package/lib/dist/resolution/memory-budget.js +162 -0
  149. package/lib/dist/resolution/memory-budget.js.map +1 -0
  150. package/lib/dist/resolution/name-matcher.d.ts +12 -1
  151. package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
  152. package/lib/dist/resolution/name-matcher.js +517 -96
  153. package/lib/dist/resolution/name-matcher.js.map +1 -1
  154. package/lib/dist/resolution/resolver-pool.d.ts +106 -0
  155. package/lib/dist/resolution/resolver-pool.d.ts.map +1 -0
  156. package/lib/dist/resolution/resolver-pool.js +344 -0
  157. package/lib/dist/resolution/resolver-pool.js.map +1 -0
  158. package/lib/dist/resolution/resolver-worker.d.ts +17 -0
  159. package/lib/dist/resolution/resolver-worker.d.ts.map +1 -0
  160. package/lib/dist/resolution/resolver-worker.js +141 -0
  161. package/lib/dist/resolution/resolver-worker.js.map +1 -0
  162. package/lib/dist/resolution/types.d.ts +3 -0
  163. package/lib/dist/resolution/types.d.ts.map +1 -1
  164. package/lib/dist/sync/watcher.d.ts +25 -1
  165. package/lib/dist/sync/watcher.d.ts.map +1 -1
  166. package/lib/dist/sync/watcher.js +76 -3
  167. package/lib/dist/sync/watcher.js.map +1 -1
  168. package/lib/dist/types.d.ts +41 -2
  169. package/lib/dist/types.d.ts.map +1 -1
  170. package/lib/dist/types.js +26 -1
  171. package/lib/dist/types.js.map +1 -1
  172. package/lib/dist/ui/color.d.ts +21 -0
  173. package/lib/dist/ui/color.d.ts.map +1 -0
  174. package/lib/dist/ui/color.js +42 -0
  175. package/lib/dist/ui/color.js.map +1 -0
  176. package/lib/dist/ui/glyphs.d.ts +35 -10
  177. package/lib/dist/ui/glyphs.d.ts.map +1 -1
  178. package/lib/dist/ui/glyphs.js +59 -12
  179. package/lib/dist/ui/glyphs.js.map +1 -1
  180. package/lib/dist/ui/shimmer-progress.d.ts.map +1 -1
  181. package/lib/dist/ui/shimmer-progress.js +78 -4
  182. package/lib/dist/ui/shimmer-progress.js.map +1 -1
  183. package/lib/dist/ui/shimmer-worker.js +25 -17
  184. package/lib/dist/ui/shimmer-worker.js.map +1 -1
  185. package/lib/dist/ui/types.d.ts +0 -2
  186. package/lib/dist/ui/types.d.ts.map +1 -1
  187. package/lib/dist/upgrade/index.d.ts +39 -0
  188. package/lib/dist/upgrade/index.d.ts.map +1 -1
  189. package/lib/dist/upgrade/index.js +180 -19
  190. package/lib/dist/upgrade/index.js.map +1 -1
  191. package/lib/dist/upgrade/remove-binary.d.ts +87 -0
  192. package/lib/dist/upgrade/remove-binary.d.ts.map +1 -0
  193. package/lib/dist/upgrade/remove-binary.js +289 -0
  194. package/lib/dist/upgrade/remove-binary.js.map +1 -0
  195. package/lib/dist/upgrade/update-check.d.ts +92 -0
  196. package/lib/dist/upgrade/update-check.d.ts.map +1 -0
  197. package/lib/dist/upgrade/update-check.js +258 -0
  198. package/lib/dist/upgrade/update-check.js.map +1 -0
  199. package/lib/kernel/codegraph-kernel.node +0 -0
  200. package/lib/node_modules/.package-lock.json +1 -1
  201. package/lib/package.json +6 -1
  202. package/package.json +6 -2
@@ -34,6 +34,17 @@ function isLowValueFile(filePath) {
34
34
  (0, generated_detection_1.isGeneratedFile)(filePath));
35
35
  }
36
36
  const SQLITE_PARAM_CHUNK_SIZE = 500;
37
+ /**
38
+ * Last segment of a (possibly dotted/qualified) reference name — the part a
39
+ * new symbol's plain node name could match: 'util.greet' → 'greet',
40
+ * 'mod::fn' → 'fn', 'greet' → 'greet'. Written to unresolved_refs.name_tail
41
+ * when a ref is marked failed, so the #1240 retry lookup can match dotted
42
+ * refs against newly-added node names.
43
+ */
44
+ function referenceNameTail(referenceName) {
45
+ const idx = Math.max(referenceName.lastIndexOf('.'), referenceName.lastIndexOf(':'));
46
+ return idx >= 0 ? referenceName.slice(idx + 1) : referenceName;
47
+ }
37
48
  /**
38
49
  * Convert database row to Node object
39
50
  */
@@ -112,9 +123,67 @@ class QueryBuilder {
112
123
  // correctness backstop. Bounded so a pathological repo can't grow it forever.
113
124
  segmentedNames = new Set();
114
125
  static MAX_SEGMENTED_NAMES = 65536;
126
+ // Multi-row INSERT statements, cached per (statement kind × row count). The
127
+ // bulk write path decomposes N rows into a few fixed batch sizes so each
128
+ // size's statement is prepared once and reused — one .run() binds a whole
129
+ // chunk instead of one row, which is where the per-call overhead lives.
130
+ // Row order within and across chunks is the input order, so rowid assignment
131
+ // (and therefore resolution's insertion-order disambiguation) is identical
132
+ // to the one-row-per-run path.
133
+ batchStmts = new Map();
134
+ static BATCH_SIZES = [128, 32, 8, 1];
135
+ /**
136
+ * Run `rows` through a multi-row `INSERT` built as `head + (tuple,)*n`,
137
+ * decomposed greedily into the cached batch sizes. Preserves row order.
138
+ */
139
+ runBatched(kind, head, tuple, rows) {
140
+ if (rows.length === 0)
141
+ return;
142
+ let i = 0;
143
+ for (const size of QueryBuilder.BATCH_SIZES) {
144
+ while (rows.length - i >= size) {
145
+ const key = `${kind}:${size}`;
146
+ let stmt = this.batchStmts.get(key);
147
+ if (!stmt) {
148
+ stmt = this.db.prepare(head + new Array(size).fill(tuple).join(','));
149
+ this.batchStmts.set(key, stmt);
150
+ }
151
+ if (size === 1) {
152
+ stmt.run(...rows[i]);
153
+ }
154
+ else {
155
+ const params = [];
156
+ for (let r = 0; r < size; r++) {
157
+ const row = rows[i + r];
158
+ for (let c = 0; c < row.length; c++)
159
+ params.push(row[c]);
160
+ }
161
+ stmt.run(...params);
162
+ }
163
+ i += size;
164
+ }
165
+ }
166
+ }
115
167
  constructor(db) {
116
168
  this.db = db;
117
169
  }
170
+ /**
171
+ * Swap the underlying connection in place. Used by pool workers'
172
+ * connection recycling (plan §7a.6, writes-under-readers): a long-lived
173
+ * read connection pins WAL checkpoint progress, and the deep WAL that
174
+ * accumulates behind it taxes every main-thread B-tree page operation
175
+ * (deletes measured 42.6s → 118.8s from 0 to 4 attached readers on
176
+ * identical hardware). Workers therefore close and reopen their read-only
177
+ * connection at the pool-idle boundary; everything above the connection —
178
+ * this QueryBuilder, the resolver and its warm caches — survives, and only
179
+ * connection-derived state (prepared statements) resets, re-preparing
180
+ * lazily on next use.
181
+ */
182
+ rebind(db) {
183
+ this.db = db;
184
+ this.stmts = {};
185
+ this.batchStmts.clear();
186
+ }
118
187
  /** Set the normalized project-name tokens used to down-weight non-discriminative
119
188
  * query words in path scoring (#720). Called once when the project opens. */
120
189
  setProjectNameTokens(tokens) {
@@ -209,28 +278,115 @@ class QueryBuilder {
209
278
  }
210
279
  /** Write `name`'s segments into name_segment_vocab (idempotent). */
211
280
  insertNameSegments(name) {
212
- if (this.segmentedNames.has(name))
213
- return;
214
- if (this.segmentedNames.size >= QueryBuilder.MAX_SEGMENTED_NAMES)
215
- this.segmentedNames.clear();
216
- this.segmentedNames.add(name);
217
- if (!this.stmts.insertNameSegment) {
218
- this.stmts.insertNameSegment = this.db.prepare('INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES (?, ?)');
219
- }
220
- for (const segment of (0, identifier_segments_1.splitIdentifierSegments)(name)) {
221
- this.stmts.insertNameSegment.run(segment, name);
222
- }
281
+ const rows = [];
282
+ this.collectNameSegmentRows(name, rows);
283
+ this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
223
284
  }
224
285
  /**
225
286
  * Insert multiple nodes in a transaction
226
287
  */
227
288
  insertNodes(nodes) {
228
289
  this.db.transaction(() => {
290
+ // Bulk path: same semantics as insertNode() per row (validation, cache
291
+ // invalidation, segment vocab), but bound as multi-row INSERTs — the
292
+ // per-.run() call overhead dominates the store phase on full indexes.
293
+ const rows = [];
294
+ const segmentRows = [];
229
295
  for (const node of nodes) {
230
- this.insertNode(node);
296
+ if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
297
+ console.error('[CodeGraph] Skipping node with missing required fields:', {
298
+ id: node.id,
299
+ kind: node.kind,
300
+ name: node.name,
301
+ filePath: node.filePath,
302
+ language: node.language,
303
+ });
304
+ continue;
305
+ }
306
+ this.nodeCache.delete(node.id);
307
+ rows.push([
308
+ node.id,
309
+ node.kind,
310
+ node.name,
311
+ node.qualifiedName ?? node.name,
312
+ node.filePath,
313
+ node.language,
314
+ node.startLine ?? 0,
315
+ node.endLine ?? 0,
316
+ node.startColumn ?? 0,
317
+ node.endColumn ?? 0,
318
+ node.docstring ?? null,
319
+ node.signature ?? null,
320
+ node.visibility ?? null,
321
+ node.isExported ? 1 : 0,
322
+ node.isAsync ? 1 : 0,
323
+ node.isStatic ? 1 : 0,
324
+ node.isAbstract ? 1 : 0,
325
+ node.decorators ? JSON.stringify(node.decorators) : null,
326
+ node.typeParameters ? JSON.stringify(node.typeParameters) : null,
327
+ node.returnType ?? null,
328
+ node.updatedAt ?? Date.now(),
329
+ ]);
330
+ if (this.isSegmentableKind(node.kind))
331
+ this.collectNameSegmentRows(node.name, segmentRows);
231
332
  }
333
+ this.runBatched('insertNodes', `INSERT OR REPLACE INTO nodes (
334
+ id, kind, name, qualified_name, file_path, language,
335
+ start_line, end_line, start_column, end_column,
336
+ docstring, signature, visibility,
337
+ is_exported, is_async, is_static, is_abstract,
338
+ decorators, type_parameters, return_type, updated_at
339
+ ) VALUES `, '(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', rows);
340
+ this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', segmentRows);
232
341
  })();
233
342
  }
343
+ /**
344
+ * Store one file's whole extraction bundle — nodes, edges, unresolved refs,
345
+ * and the file record — in a SINGLE transaction. The bulk-index path calls
346
+ * this once per file instead of opening one transaction per table (#1015
347
+ * file-order commit discipline is unchanged: callers still invoke it in file
348
+ * order, and row order within is input order).
349
+ *
350
+ * Edges MUST already be endpoint-filtered by the caller (the store path
351
+ * filters to the file's own inserted node ids), so the per-file existence
352
+ * SELECT that insertEdges() pays is skipped here.
353
+ */
354
+ storeFileBundle(bundle) {
355
+ this.db.transaction(() => {
356
+ this.insertNodes(bundle.nodes);
357
+ if (bundle.edges.length > 0) {
358
+ const rows = [];
359
+ for (const edge of bundle.edges) {
360
+ rows.push([
361
+ edge.source,
362
+ edge.target,
363
+ edge.kind,
364
+ edge.metadata ? JSON.stringify(edge.metadata) : null,
365
+ edge.line ?? null,
366
+ edge.column ?? null,
367
+ edge.provenance ?? null,
368
+ ]);
369
+ }
370
+ this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
371
+ }
372
+ if (bundle.refs.length > 0)
373
+ this.insertUnresolvedRefsBatch(bundle.refs);
374
+ this.upsertFile(bundle.file);
375
+ })();
376
+ }
377
+ /**
378
+ * Collect (segment, name) rows for a name, honouring the same session-dedupe
379
+ * semantics as insertNameSegments(). Shared by the bulk write paths.
380
+ */
381
+ collectNameSegmentRows(name, out) {
382
+ if (this.segmentedNames.has(name))
383
+ return;
384
+ if (this.segmentedNames.size >= QueryBuilder.MAX_SEGMENTED_NAMES)
385
+ this.segmentedNames.clear();
386
+ this.segmentedNames.add(name);
387
+ for (const segment of (0, identifier_segments_1.splitIdentifierSegments)(name))
388
+ out.push([segment, name]);
389
+ }
234
390
  /**
235
391
  * Update an existing node
236
392
  */
@@ -356,8 +512,10 @@ class QueryBuilder {
356
512
  /** Insert segments for a batch of names in one transaction (vocab heal path). */
357
513
  insertNameSegmentsBatch(names) {
358
514
  this.db.transaction(() => {
515
+ const rows = [];
359
516
  for (const name of names)
360
- this.insertNameSegments(name);
517
+ this.collectNameSegmentRows(name, rows);
518
+ this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
361
519
  })();
362
520
  }
363
521
  /**
@@ -1239,12 +1397,22 @@ class QueryBuilder {
1239
1397
  endpointIds.add(edge.target);
1240
1398
  }
1241
1399
  const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
1400
+ const rows = [];
1242
1401
  for (const edge of edges) {
1243
1402
  if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
1244
1403
  continue;
1245
1404
  }
1246
- this.insertEdge(edge);
1405
+ rows.push([
1406
+ edge.source,
1407
+ edge.target,
1408
+ edge.kind,
1409
+ edge.metadata ? JSON.stringify(edge.metadata) : null,
1410
+ edge.line ?? null,
1411
+ edge.column ?? null,
1412
+ edge.provenance ?? null,
1413
+ ]);
1247
1414
  }
1415
+ this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
1248
1416
  })();
1249
1417
  }
1250
1418
  /**
@@ -1367,7 +1535,8 @@ class QueryBuilder {
1367
1535
  * {@link getDependentFilePaths}: all kinds except `contains`.
1368
1536
  */
1369
1537
  getCrossFileIncomingEdgesWithTarget(filePath) {
1370
- const sql = `SELECT e.*, tgt.name AS target_name, tgt.kind AS target_kind
1538
+ const sql = `SELECT e.*, tgt.name AS target_name, tgt.kind AS target_kind,
1539
+ src.file_path AS source_file_path, src.language AS source_language
1371
1540
  FROM edges e
1372
1541
  JOIN nodes tgt ON tgt.id = e.target
1373
1542
  JOIN nodes src ON src.id = e.source
@@ -1379,6 +1548,8 @@ class QueryBuilder {
1379
1548
  ...rowToEdge(row),
1380
1549
  targetName: row.target_name,
1381
1550
  targetKind: row.target_kind,
1551
+ sourceFilePath: row.source_file_path,
1552
+ sourceLanguage: row.source_language,
1382
1553
  }));
1383
1554
  }
1384
1555
  // ===========================================================================
@@ -1496,9 +1667,20 @@ class QueryBuilder {
1496
1667
  if (refs.length === 0)
1497
1668
  return;
1498
1669
  const insert = this.db.transaction(() => {
1670
+ const rows = [];
1499
1671
  for (const ref of refs) {
1500
- this.insertUnresolvedRef(ref);
1672
+ rows.push([
1673
+ ref.fromNodeId,
1674
+ ref.referenceName,
1675
+ ref.referenceKind,
1676
+ ref.line,
1677
+ ref.column,
1678
+ ref.candidates ? JSON.stringify(ref.candidates) : null,
1679
+ ref.filePath ?? '',
1680
+ ref.language ?? 'unknown',
1681
+ ]);
1501
1682
  }
1683
+ this.runBatched('insertUnresolvedRefs', 'INSERT INTO unresolved_refs (from_node_id, reference_name, reference_kind, line, col, candidates, file_path, language) VALUES ', '(?,?,?,?,?,?,?,?)', rows);
1502
1684
  });
1503
1685
  insert();
1504
1686
  }
@@ -1528,6 +1710,7 @@ class QueryBuilder {
1528
1710
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1529
1711
  filePath: row.file_path,
1530
1712
  language: row.language,
1713
+ rowId: row.id,
1531
1714
  }));
1532
1715
  }
1533
1716
  /**
@@ -1544,25 +1727,37 @@ class QueryBuilder {
1544
1727
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1545
1728
  filePath: row.file_path,
1546
1729
  language: row.language,
1730
+ rowId: row.id,
1547
1731
  }));
1548
1732
  }
1549
1733
  /**
1550
- * Get the count of unresolved references without loading them into memory
1734
+ * Get the count of PENDING (never-attempted) references without loading
1735
+ * them into memory. Rows marked status='failed' — attempted by a completed
1736
+ * pass, no match — are excluded: they are not outstanding work, only retry
1737
+ * candidates for the #1240 sweep, so they must not trip the #1187 orphan
1738
+ * sweep or the `status` pending-refs warning.
1551
1739
  */
1552
1740
  getUnresolvedReferencesCount() {
1553
1741
  if (!this.stmts.getUnresolvedCount) {
1554
- this.stmts.getUnresolvedCount = this.db.prepare('SELECT COUNT(*) as count FROM unresolved_refs');
1742
+ this.stmts.getUnresolvedCount = this.db.prepare("SELECT COUNT(*) as count FROM unresolved_refs WHERE status = 'pending'");
1555
1743
  }
1556
1744
  const row = this.stmts.getUnresolvedCount.get();
1557
1745
  return row.count;
1558
1746
  }
1559
1747
  /**
1560
- * Get a batch of unresolved references using LIMIT/OFFSET pagination.
1561
- * Used to process references in bounded memory chunks.
1748
+ * Get a batch of PENDING unresolved references using LIMIT/OFFSET
1749
+ * pagination. Used to process references in bounded memory chunks; failed
1750
+ * rows are excluded so the batched drain loop terminates once every row
1751
+ * has been attempted.
1562
1752
  */
1563
1753
  getUnresolvedReferencesBatch(offset, limit) {
1564
1754
  if (!this.stmts.getUnresolvedBatch) {
1565
- this.stmts.getUnresolvedBatch = this.db.prepare('SELECT * FROM unresolved_refs LIMIT ? OFFSET ?');
1755
+ // ORDER BY rowid is load-bearing for the pipelined resolution loop: it
1756
+ // prefetches batch k+1 at OFFSET batch_k.length while batch k's rows are
1757
+ // still pending, which is only exact under a stable enumeration. (A plain
1758
+ // scan and the status index both return rowid order anyway — this pins
1759
+ // it.)
1760
+ this.stmts.getUnresolvedBatch = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' ORDER BY rowid LIMIT ? OFFSET ?");
1566
1761
  }
1567
1762
  const rows = this.stmts.getUnresolvedBatch.all(limit, offset);
1568
1763
  return rows.map((row) => ({
@@ -1574,6 +1769,32 @@ class QueryBuilder {
1574
1769
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1575
1770
  filePath: row.file_path,
1576
1771
  language: row.language,
1772
+ rowId: row.id,
1773
+ }));
1774
+ }
1775
+ /**
1776
+ * Keyset variant of {@link getUnresolvedReferencesBatch} for the batched
1777
+ * resolution loop: seek past the last-seen row id instead of OFFSET-walking.
1778
+ * OFFSET reads re-scan the accumulated failed-row prefix on every batch —
1779
+ * O(failed rows) per read, measured at 54.6s of the kernel-scale batch loop
1780
+ * (§7a.2) — while the seek is O(batch) forever. `id` is the rowid alias, so
1781
+ * the enumeration order is identical to the OFFSET reader's.
1782
+ */
1783
+ getUnresolvedReferencesBatchAfter(afterRowId, limit) {
1784
+ if (!this.stmts.getUnresolvedBatchAfter) {
1785
+ this.stmts.getUnresolvedBatchAfter = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' AND id > ? ORDER BY id LIMIT ?");
1786
+ }
1787
+ const rows = this.stmts.getUnresolvedBatchAfter.all(afterRowId, limit);
1788
+ return rows.map((row) => ({
1789
+ fromNodeId: row.from_node_id,
1790
+ referenceName: row.reference_name,
1791
+ referenceKind: row.reference_kind,
1792
+ line: row.line,
1793
+ column: row.col,
1794
+ candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1795
+ filePath: row.file_path,
1796
+ language: row.language,
1797
+ rowId: row.id,
1577
1798
  }));
1578
1799
  }
1579
1800
  /**
@@ -1624,7 +1845,7 @@ class QueryBuilder {
1624
1845
  const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
1625
1846
  const placeholders = chunk.map(() => '?').join(',');
1626
1847
  const chunkRows = this.db
1627
- .prepare(`SELECT * FROM unresolved_refs WHERE file_path IN (${placeholders})`)
1848
+ .prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND file_path IN (${placeholders})`)
1628
1849
  .all(...chunk);
1629
1850
  rows.push(...chunkRows);
1630
1851
  }
@@ -1637,6 +1858,7 @@ class QueryBuilder {
1637
1858
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1638
1859
  filePath: row.file_path,
1639
1860
  language: row.language,
1861
+ rowId: row.id,
1640
1862
  }));
1641
1863
  }
1642
1864
  /**
@@ -1668,14 +1890,166 @@ class QueryBuilder {
1668
1890
  */
1669
1891
  deleteSpecificResolvedReferences(refs) {
1670
1892
  if (refs.length === 0)
1671
- return;
1893
+ return 0;
1672
1894
  const stmt = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?');
1895
+ // Returns rows actually removed (SQLite `changes`, summed): the batched
1896
+ // resolution loop's non-progress guard keys on this — zero removals from
1897
+ // a batch that claimed work is the direct runaway signal (§7a.2).
1898
+ let changed = 0;
1673
1899
  const deleteMany = this.db.transaction((items) => {
1674
1900
  for (const ref of items) {
1675
- stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind);
1901
+ changed += stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
1676
1902
  }
1677
1903
  });
1678
1904
  deleteMany(refs);
1905
+ return changed;
1906
+ }
1907
+ /**
1908
+ * Delete unresolved-ref rows by row id — the precise cleanup for refs a
1909
+ * resolution pass actually processed. The key-tuple variant above also
1910
+ * deletes SIBLING rows (same caller calling the same callee at other lines)
1911
+ * that a later batch hasn't attempted yet, so when a batch boundary split a
1912
+ * caller's same-named call sites, the later sites' edges were silently never
1913
+ * created (#1269).
1914
+ */
1915
+ deleteReferencesByRowIds(rowIds) {
1916
+ if (rowIds.length === 0)
1917
+ return 0;
1918
+ // One transaction for all chunks (each chunk was previously its own
1919
+ // implicit transaction = its own WAL commit — measurable on 100k+-ref
1920
+ // resolution persists), and the full-size chunk statement is cached so
1921
+ // repeat calls skip the re-prepare; only the final partial chunk (if any)
1922
+ // prepares ad hoc. Returns rows actually removed (summed `changes`) for
1923
+ // the batched loop's non-progress guard (§7a.2).
1924
+ let changed = 0;
1925
+ this.db.transaction(() => {
1926
+ for (let i = 0; i < rowIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
1927
+ const chunk = rowIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
1928
+ if (chunk.length === SQLITE_PARAM_CHUNK_SIZE) {
1929
+ if (!this.stmts.deleteRefsByRowIdsFull) {
1930
+ const placeholders = new Array(SQLITE_PARAM_CHUNK_SIZE).fill('?').join(',');
1931
+ this.stmts.deleteRefsByRowIdsFull = this.db.prepare(`DELETE FROM unresolved_refs WHERE id IN (${placeholders})`);
1932
+ }
1933
+ changed += this.stmts.deleteRefsByRowIdsFull.run(...chunk).changes;
1934
+ }
1935
+ else {
1936
+ const placeholders = chunk.map(() => '?').join(',');
1937
+ changed += this.db.prepare(`DELETE FROM unresolved_refs WHERE id IN (${placeholders})`).run(...chunk).changes;
1938
+ }
1939
+ }
1940
+ })();
1941
+ return changed;
1942
+ }
1943
+ /**
1944
+ * Mark refs a completed resolution pass could not resolve as status='failed'
1945
+ * instead of deleting them (#1240). Failed rows are invisible to the pending
1946
+ * count/batch readers (so drain loops and the #1187 orphan sweep still
1947
+ * terminate) but stay queryable by name_tail so a later sync can retry them
1948
+ * when a changed file introduces a symbol that could satisfy them. name_tail
1949
+ * is (re)written here so rows inserted before the v8 migration get their
1950
+ * tail the first time they're attempted.
1951
+ */
1952
+ markReferencesFailed(refs) {
1953
+ if (refs.length === 0)
1954
+ return 0;
1955
+ const stmt = this.db.prepare("UPDATE unresolved_refs SET status = 'failed', name_tail = ? WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?");
1956
+ let changed = 0;
1957
+ const markMany = this.db.transaction((items) => {
1958
+ for (const ref of items) {
1959
+ changed += stmt.run(referenceNameTail(ref.referenceName), ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
1960
+ }
1961
+ });
1962
+ markMany(refs);
1963
+ return changed;
1964
+ }
1965
+ /**
1966
+ * Park refs as status='failed' by row id — the precise counterpart of
1967
+ * markReferencesFailed, for the same reason as deleteReferencesByRowIds:
1968
+ * the key-tuple variant also flips same-key sibling rows in later batches
1969
+ * to 'failed' before they were ever attempted (#1269). Resolution outcome
1970
+ * can differ per call site (receiver-type inference reads the ref's line),
1971
+ * so a sibling must not inherit this row's failure.
1972
+ */
1973
+ markReferencesFailedByRowIds(refs) {
1974
+ if (refs.length === 0)
1975
+ return 0;
1976
+ const stmt = this.db.prepare("UPDATE unresolved_refs SET status = 'failed', name_tail = ? WHERE id = ?");
1977
+ let changed = 0;
1978
+ const markMany = this.db.transaction((items) => {
1979
+ for (const ref of items) {
1980
+ changed += stmt.run(referenceNameTail(ref.referenceName), ref.rowId).changes;
1981
+ }
1982
+ });
1983
+ markMany(refs);
1984
+ return changed;
1985
+ }
1986
+ /**
1987
+ * Failed refs whose name tail matches one of the given symbol names — the
1988
+ * candidates a sync should retry after files carrying those names changed
1989
+ * (#1240). Names matching more than `perNameCeiling` failed refs are
1990
+ * skipped entirely: at that population a name is external/builtin noise
1991
+ * (`get`, `map`, …) that one new definition won't resolve — the same
1992
+ * rationale as resolution's AMBIGUOUS_NAME_CEILING (#999) — and retrying an
1993
+ * arbitrary subset would be both wasted work and incoherent coverage.
1994
+ */
1995
+ getRetryableFailedReferences(names, perNameCeiling = 500) {
1996
+ if (names.length === 0)
1997
+ return [];
1998
+ // Pass 1: per-tail counts, chunked under the SQLite parameter limit.
1999
+ const retryNames = [];
2000
+ for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2001
+ const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2002
+ const placeholders = chunk.map(() => '?').join(',');
2003
+ const counts = this.db
2004
+ .prepare(`SELECT name_tail, COUNT(*) as count FROM unresolved_refs WHERE status = 'failed' AND name_tail IN (${placeholders}) GROUP BY name_tail`)
2005
+ .all(...chunk);
2006
+ for (const row of counts) {
2007
+ if (row.count <= perNameCeiling)
2008
+ retryNames.push(row.name_tail);
2009
+ }
2010
+ }
2011
+ if (retryNames.length === 0)
2012
+ return [];
2013
+ // Pass 2: load the surviving rows.
2014
+ const rows = [];
2015
+ for (let i = 0; i < retryNames.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2016
+ const chunk = retryNames.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2017
+ const placeholders = chunk.map(() => '?').join(',');
2018
+ const chunkRows = this.db
2019
+ .prepare(`SELECT * FROM unresolved_refs WHERE status = 'failed' AND name_tail IN (${placeholders})`)
2020
+ .all(...chunk);
2021
+ rows.push(...chunkRows);
2022
+ }
2023
+ return rows.map((row) => ({
2024
+ fromNodeId: row.from_node_id,
2025
+ referenceName: row.reference_name,
2026
+ referenceKind: row.reference_kind,
2027
+ line: row.line,
2028
+ column: row.col,
2029
+ candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
2030
+ filePath: row.file_path,
2031
+ language: row.language,
2032
+ rowId: row.id,
2033
+ }));
2034
+ }
2035
+ /**
2036
+ * Distinct node names present in the given files — the symbol names a sync
2037
+ * pass uses to look up retryable failed refs after those files changed.
2038
+ */
2039
+ getNodeNamesByFiles(filePaths) {
2040
+ if (filePaths.length === 0)
2041
+ return [];
2042
+ const names = new Set();
2043
+ for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2044
+ const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2045
+ const placeholders = chunk.map(() => '?').join(',');
2046
+ const rows = this.db
2047
+ .prepare(`SELECT DISTINCT name FROM nodes WHERE file_path IN (${placeholders})`)
2048
+ .all(...chunk);
2049
+ for (const row of rows)
2050
+ names.add(row.name);
2051
+ }
2052
+ return [...names];
1679
2053
  }
1680
2054
  // ===========================================================================
1681
2055
  // Statistics