@colbymchenry/codegraph-win32-arm64 1.4.1 → 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 (171) hide show
  1. package/bin/codegraph.cmd +1 -1
  2. package/lib/dist/bin/codegraph.js +61 -15
  3. package/lib/dist/bin/codegraph.js.map +1 -1
  4. package/lib/dist/context/index.d.ts.map +1 -1
  5. package/lib/dist/context/index.js +41 -11
  6. package/lib/dist/context/index.js.map +1 -1
  7. package/lib/dist/db/index.d.ts +142 -0
  8. package/lib/dist/db/index.d.ts.map +1 -1
  9. package/lib/dist/db/index.js +267 -6
  10. package/lib/dist/db/index.js.map +1 -1
  11. package/lib/dist/db/queries.d.ts +74 -2
  12. package/lib/dist/db/queries.d.ts.map +1 -1
  13. package/lib/dist/db/queries.js +287 -20
  14. package/lib/dist/db/queries.js.map +1 -1
  15. package/lib/dist/db/sqlite-adapter.d.ts +3 -1
  16. package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
  17. package/lib/dist/db/sqlite-adapter.js +22 -4
  18. package/lib/dist/db/sqlite-adapter.js.map +1 -1
  19. package/lib/dist/db/wal-valve.d.ts +15 -2
  20. package/lib/dist/db/wal-valve.d.ts.map +1 -1
  21. package/lib/dist/db/wal-valve.js +88 -6
  22. package/lib/dist/db/wal-valve.js.map +1 -1
  23. package/lib/dist/extraction/grammars.d.ts.map +1 -1
  24. package/lib/dist/extraction/grammars.js +63 -0
  25. package/lib/dist/extraction/grammars.js.map +1 -1
  26. package/lib/dist/extraction/index.d.ts +32 -3
  27. package/lib/dist/extraction/index.d.ts.map +1 -1
  28. package/lib/dist/extraction/index.js +254 -61
  29. package/lib/dist/extraction/index.js.map +1 -1
  30. package/lib/dist/extraction/kernel/decode.d.ts +9 -0
  31. package/lib/dist/extraction/kernel/decode.d.ts.map +1 -0
  32. package/lib/dist/extraction/kernel/decode.js +162 -0
  33. package/lib/dist/extraction/kernel/decode.js.map +1 -0
  34. package/lib/dist/extraction/kernel/index.d.ts +64 -0
  35. package/lib/dist/extraction/kernel/index.d.ts.map +1 -0
  36. package/lib/dist/extraction/kernel/index.js +279 -0
  37. package/lib/dist/extraction/kernel/index.js.map +1 -0
  38. package/lib/dist/extraction/kernel/layout.d.ts +101 -0
  39. package/lib/dist/extraction/kernel/layout.d.ts.map +1 -0
  40. package/lib/dist/extraction/kernel/layout.js +104 -0
  41. package/lib/dist/extraction/kernel/layout.js.map +1 -0
  42. package/lib/dist/extraction/kernel/loader.d.ts +103 -0
  43. package/lib/dist/extraction/kernel/loader.d.ts.map +1 -0
  44. package/lib/dist/extraction/kernel/loader.js +146 -0
  45. package/lib/dist/extraction/kernel/loader.js.map +1 -0
  46. package/lib/dist/extraction/languages/c-cpp.d.ts +14 -0
  47. package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  48. package/lib/dist/extraction/languages/c-cpp.js +849 -12
  49. package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
  50. package/lib/dist/extraction/parse-pool.d.ts +8 -0
  51. package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
  52. package/lib/dist/extraction/parse-pool.js +15 -0
  53. package/lib/dist/extraction/parse-pool.js.map +1 -1
  54. package/lib/dist/extraction/parse-worker.js +35 -1
  55. package/lib/dist/extraction/parse-worker.js.map +1 -1
  56. package/lib/dist/extraction/store-worker.d.ts +24 -0
  57. package/lib/dist/extraction/store-worker.d.ts.map +1 -0
  58. package/lib/dist/extraction/store-worker.js +139 -0
  59. package/lib/dist/extraction/store-worker.js.map +1 -0
  60. package/lib/dist/extraction/store-writer.d.ts +63 -0
  61. package/lib/dist/extraction/store-writer.d.ts.map +1 -0
  62. package/lib/dist/extraction/store-writer.js +174 -0
  63. package/lib/dist/extraction/store-writer.js.map +1 -0
  64. package/lib/dist/extraction/tree-sitter.d.ts +22 -4
  65. package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
  66. package/lib/dist/extraction/tree-sitter.js +151 -6
  67. package/lib/dist/extraction/tree-sitter.js.map +1 -1
  68. package/lib/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  69. package/lib/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  70. package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  71. package/lib/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  72. package/lib/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  73. package/lib/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  74. package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  75. package/lib/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  76. package/lib/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  77. package/lib/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  78. package/lib/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  79. package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  80. package/lib/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  81. package/lib/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  82. package/lib/dist/extraction/wasm-runtime-flags.d.ts +15 -0
  83. package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
  84. package/lib/dist/extraction/wasm-runtime-flags.js +27 -3
  85. package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
  86. package/lib/dist/index.d.ts +14 -2
  87. package/lib/dist/index.d.ts.map +1 -1
  88. package/lib/dist/index.js +188 -10
  89. package/lib/dist/index.js.map +1 -1
  90. package/lib/dist/installer/beta-signup.d.ts +54 -0
  91. package/lib/dist/installer/beta-signup.d.ts.map +1 -0
  92. package/lib/dist/installer/beta-signup.js +178 -0
  93. package/lib/dist/installer/beta-signup.js.map +1 -0
  94. package/lib/dist/installer/index.d.ts.map +1 -1
  95. package/lib/dist/installer/index.js +11 -0
  96. package/lib/dist/installer/index.js.map +1 -1
  97. package/lib/dist/mcp/tools.d.ts.map +1 -1
  98. package/lib/dist/mcp/tools.js +27 -0
  99. package/lib/dist/mcp/tools.js.map +1 -1
  100. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +1 -1
  101. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
  102. package/lib/dist/resolution/c-fnptr-synthesizer.js +574 -132
  103. package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
  104. package/lib/dist/resolution/callback-synthesizer.d.ts +54 -10
  105. package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
  106. package/lib/dist/resolution/callback-synthesizer.js +249 -157
  107. package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
  108. package/lib/dist/resolution/cooperative-yield.d.ts +10 -2
  109. package/lib/dist/resolution/cooperative-yield.d.ts.map +1 -1
  110. package/lib/dist/resolution/cooperative-yield.js +6 -4
  111. package/lib/dist/resolution/cooperative-yield.js.map +1 -1
  112. package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
  113. package/lib/dist/resolution/frameworks/go.js +29 -6
  114. package/lib/dist/resolution/frameworks/go.js.map +1 -1
  115. package/lib/dist/resolution/import-resolver.d.ts +2 -3
  116. package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
  117. package/lib/dist/resolution/import-resolver.js +166 -7
  118. package/lib/dist/resolution/import-resolver.js.map +1 -1
  119. package/lib/dist/resolution/index.d.ts +87 -2
  120. package/lib/dist/resolution/index.d.ts.map +1 -1
  121. package/lib/dist/resolution/index.js +716 -130
  122. package/lib/dist/resolution/index.js.map +1 -1
  123. package/lib/dist/resolution/memory-budget.d.ts +48 -0
  124. package/lib/dist/resolution/memory-budget.d.ts.map +1 -0
  125. package/lib/dist/resolution/memory-budget.js +162 -0
  126. package/lib/dist/resolution/memory-budget.js.map +1 -0
  127. package/lib/dist/resolution/name-matcher.d.ts +12 -1
  128. package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
  129. package/lib/dist/resolution/name-matcher.js +387 -95
  130. package/lib/dist/resolution/name-matcher.js.map +1 -1
  131. package/lib/dist/resolution/resolver-pool.d.ts +106 -0
  132. package/lib/dist/resolution/resolver-pool.d.ts.map +1 -0
  133. package/lib/dist/resolution/resolver-pool.js +344 -0
  134. package/lib/dist/resolution/resolver-pool.js.map +1 -0
  135. package/lib/dist/resolution/resolver-worker.d.ts +17 -0
  136. package/lib/dist/resolution/resolver-worker.d.ts.map +1 -0
  137. package/lib/dist/resolution/resolver-worker.js +141 -0
  138. package/lib/dist/resolution/resolver-worker.js.map +1 -0
  139. package/lib/dist/resolution/types.d.ts +3 -0
  140. package/lib/dist/resolution/types.d.ts.map +1 -1
  141. package/lib/dist/sync/watcher.d.ts +25 -1
  142. package/lib/dist/sync/watcher.d.ts.map +1 -1
  143. package/lib/dist/sync/watcher.js +76 -3
  144. package/lib/dist/sync/watcher.js.map +1 -1
  145. package/lib/dist/types.d.ts +41 -2
  146. package/lib/dist/types.d.ts.map +1 -1
  147. package/lib/dist/types.js +26 -1
  148. package/lib/dist/types.js.map +1 -1
  149. package/lib/dist/ui/color.d.ts +21 -0
  150. package/lib/dist/ui/color.d.ts.map +1 -0
  151. package/lib/dist/ui/color.js +42 -0
  152. package/lib/dist/ui/color.js.map +1 -0
  153. package/lib/dist/ui/glyphs.d.ts +35 -10
  154. package/lib/dist/ui/glyphs.d.ts.map +1 -1
  155. package/lib/dist/ui/glyphs.js +59 -12
  156. package/lib/dist/ui/glyphs.js.map +1 -1
  157. package/lib/dist/ui/shimmer-progress.d.ts.map +1 -1
  158. package/lib/dist/ui/shimmer-progress.js +78 -4
  159. package/lib/dist/ui/shimmer-progress.js.map +1 -1
  160. package/lib/dist/ui/shimmer-worker.js +25 -17
  161. package/lib/dist/ui/shimmer-worker.js.map +1 -1
  162. package/lib/dist/ui/types.d.ts +0 -2
  163. package/lib/dist/ui/types.d.ts.map +1 -1
  164. package/lib/dist/upgrade/index.d.ts +7 -0
  165. package/lib/dist/upgrade/index.d.ts.map +1 -1
  166. package/lib/dist/upgrade/index.js +18 -5
  167. package/lib/dist/upgrade/index.js.map +1 -1
  168. package/lib/kernel/codegraph-kernel.node +0 -0
  169. package/lib/node_modules/.package-lock.json +1 -1
  170. package/lib/package.json +6 -1
  171. package/package.json +6 -2
@@ -123,9 +123,67 @@ class QueryBuilder {
123
123
  // correctness backstop. Bounded so a pathological repo can't grow it forever.
124
124
  segmentedNames = new Set();
125
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
+ }
126
167
  constructor(db) {
127
168
  this.db = db;
128
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
+ }
129
187
  /** Set the normalized project-name tokens used to down-weight non-discriminative
130
188
  * query words in path scoring (#720). Called once when the project opens. */
131
189
  setProjectNameTokens(tokens) {
@@ -220,28 +278,115 @@ class QueryBuilder {
220
278
  }
221
279
  /** Write `name`'s segments into name_segment_vocab (idempotent). */
222
280
  insertNameSegments(name) {
223
- if (this.segmentedNames.has(name))
224
- return;
225
- if (this.segmentedNames.size >= QueryBuilder.MAX_SEGMENTED_NAMES)
226
- this.segmentedNames.clear();
227
- this.segmentedNames.add(name);
228
- if (!this.stmts.insertNameSegment) {
229
- this.stmts.insertNameSegment = this.db.prepare('INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES (?, ?)');
230
- }
231
- for (const segment of (0, identifier_segments_1.splitIdentifierSegments)(name)) {
232
- this.stmts.insertNameSegment.run(segment, name);
233
- }
281
+ const rows = [];
282
+ this.collectNameSegmentRows(name, rows);
283
+ this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
234
284
  }
235
285
  /**
236
286
  * Insert multiple nodes in a transaction
237
287
  */
238
288
  insertNodes(nodes) {
239
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 = [];
240
295
  for (const node of nodes) {
241
- 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);
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);
341
+ })();
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);
242
371
  }
372
+ if (bundle.refs.length > 0)
373
+ this.insertUnresolvedRefsBatch(bundle.refs);
374
+ this.upsertFile(bundle.file);
243
375
  })();
244
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
+ }
245
390
  /**
246
391
  * Update an existing node
247
392
  */
@@ -367,8 +512,10 @@ class QueryBuilder {
367
512
  /** Insert segments for a batch of names in one transaction (vocab heal path). */
368
513
  insertNameSegmentsBatch(names) {
369
514
  this.db.transaction(() => {
515
+ const rows = [];
370
516
  for (const name of names)
371
- this.insertNameSegments(name);
517
+ this.collectNameSegmentRows(name, rows);
518
+ this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
372
519
  })();
373
520
  }
374
521
  /**
@@ -1250,12 +1397,22 @@ class QueryBuilder {
1250
1397
  endpointIds.add(edge.target);
1251
1398
  }
1252
1399
  const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
1400
+ const rows = [];
1253
1401
  for (const edge of edges) {
1254
1402
  if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
1255
1403
  continue;
1256
1404
  }
1257
- 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
+ ]);
1258
1414
  }
1415
+ this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
1259
1416
  })();
1260
1417
  }
1261
1418
  /**
@@ -1510,9 +1667,20 @@ class QueryBuilder {
1510
1667
  if (refs.length === 0)
1511
1668
  return;
1512
1669
  const insert = this.db.transaction(() => {
1670
+ const rows = [];
1513
1671
  for (const ref of refs) {
1514
- 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
+ ]);
1515
1682
  }
1683
+ this.runBatched('insertUnresolvedRefs', 'INSERT INTO unresolved_refs (from_node_id, reference_name, reference_kind, line, col, candidates, file_path, language) VALUES ', '(?,?,?,?,?,?,?,?)', rows);
1516
1684
  });
1517
1685
  insert();
1518
1686
  }
@@ -1542,6 +1710,7 @@ class QueryBuilder {
1542
1710
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1543
1711
  filePath: row.file_path,
1544
1712
  language: row.language,
1713
+ rowId: row.id,
1545
1714
  }));
1546
1715
  }
1547
1716
  /**
@@ -1558,6 +1727,7 @@ class QueryBuilder {
1558
1727
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1559
1728
  filePath: row.file_path,
1560
1729
  language: row.language,
1730
+ rowId: row.id,
1561
1731
  }));
1562
1732
  }
1563
1733
  /**
@@ -1582,7 +1752,12 @@ class QueryBuilder {
1582
1752
  */
1583
1753
  getUnresolvedReferencesBatch(offset, limit) {
1584
1754
  if (!this.stmts.getUnresolvedBatch) {
1585
- this.stmts.getUnresolvedBatch = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' 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 ?");
1586
1761
  }
1587
1762
  const rows = this.stmts.getUnresolvedBatch.all(limit, offset);
1588
1763
  return rows.map((row) => ({
@@ -1594,6 +1769,32 @@ class QueryBuilder {
1594
1769
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1595
1770
  filePath: row.file_path,
1596
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,
1597
1798
  }));
1598
1799
  }
1599
1800
  /**
@@ -1657,6 +1858,7 @@ class QueryBuilder {
1657
1858
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1658
1859
  filePath: row.file_path,
1659
1860
  language: row.language,
1861
+ rowId: row.id,
1660
1862
  }));
1661
1863
  }
1662
1864
  /**
@@ -1688,14 +1890,55 @@ class QueryBuilder {
1688
1890
  */
1689
1891
  deleteSpecificResolvedReferences(refs) {
1690
1892
  if (refs.length === 0)
1691
- return;
1893
+ return 0;
1692
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;
1693
1899
  const deleteMany = this.db.transaction((items) => {
1694
1900
  for (const ref of items) {
1695
- stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind);
1901
+ changed += stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
1696
1902
  }
1697
1903
  });
1698
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;
1699
1942
  }
1700
1943
  /**
1701
1944
  * Mark refs a completed resolution pass could not resolve as status='failed'
@@ -1708,14 +1951,37 @@ class QueryBuilder {
1708
1951
  */
1709
1952
  markReferencesFailed(refs) {
1710
1953
  if (refs.length === 0)
1711
- return;
1954
+ return 0;
1712
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;
1713
1978
  const markMany = this.db.transaction((items) => {
1714
1979
  for (const ref of items) {
1715
- stmt.run(referenceNameTail(ref.referenceName), ref.fromNodeId, ref.referenceName, ref.referenceKind);
1980
+ changed += stmt.run(referenceNameTail(ref.referenceName), ref.rowId).changes;
1716
1981
  }
1717
1982
  });
1718
1983
  markMany(refs);
1984
+ return changed;
1719
1985
  }
1720
1986
  /**
1721
1987
  * Failed refs whose name tail matches one of the given symbol names — the
@@ -1763,6 +2029,7 @@ class QueryBuilder {
1763
2029
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1764
2030
  filePath: row.file_path,
1765
2031
  language: row.language,
2032
+ rowId: row.id,
1766
2033
  }));
1767
2034
  }
1768
2035
  /**