gitnexus 1.6.3 → 1.6.4-rc.10

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 (98) hide show
  1. package/dist/_shared/index.d.ts +1 -1
  2. package/dist/_shared/index.d.ts.map +1 -1
  3. package/dist/_shared/index.js +1 -1
  4. package/dist/_shared/index.js.map +1 -1
  5. package/dist/_shared/scope-resolution/finalize-algorithm.d.ts +22 -14
  6. package/dist/_shared/scope-resolution/finalize-algorithm.d.ts.map +1 -1
  7. package/dist/_shared/scope-resolution/finalize-algorithm.js +298 -37
  8. package/dist/_shared/scope-resolution/finalize-algorithm.js.map +1 -1
  9. package/dist/_shared/scope-resolution/scope-tree.d.ts +23 -1
  10. package/dist/_shared/scope-resolution/scope-tree.d.ts.map +1 -1
  11. package/dist/_shared/scope-resolution/scope-tree.js +36 -2
  12. package/dist/_shared/scope-resolution/scope-tree.js.map +1 -1
  13. package/dist/_shared/scope-resolution/types.d.ts +47 -3
  14. package/dist/_shared/scope-resolution/types.d.ts.map +1 -1
  15. package/dist/_shared/scope-resolution/types.js +10 -2
  16. package/dist/_shared/scope-resolution/types.js.map +1 -1
  17. package/dist/core/embeddings/embedder.js +2 -1
  18. package/dist/core/ingestion/call-processor.js +2 -2
  19. package/dist/core/ingestion/constants.d.ts +4 -3
  20. package/dist/core/ingestion/constants.js +8 -3
  21. package/dist/core/ingestion/finalize-orchestrator.js +6 -3
  22. package/dist/core/ingestion/heritage-processor.js +2 -2
  23. package/dist/core/ingestion/import-processor.js +1 -1
  24. package/dist/core/ingestion/languages/csharp/captures.js +4 -1
  25. package/dist/core/ingestion/languages/csharp/namespace-siblings.d.ts +14 -13
  26. package/dist/core/ingestion/languages/csharp/namespace-siblings.js +62 -50
  27. package/dist/core/ingestion/languages/python/captures.js +9 -1
  28. package/dist/core/ingestion/languages/python/index.d.ts +1 -1
  29. package/dist/core/ingestion/languages/python/index.js +1 -1
  30. package/dist/core/ingestion/languages/python/simple-hooks.d.ts +3 -1
  31. package/dist/core/ingestion/languages/python/simple-hooks.js +8 -0
  32. package/dist/core/ingestion/languages/python.js +2 -1
  33. package/dist/core/ingestion/languages/typescript/arity-metadata.d.ts +59 -0
  34. package/dist/core/ingestion/languages/typescript/arity-metadata.js +103 -0
  35. package/dist/core/ingestion/languages/typescript/arity.d.ts +37 -0
  36. package/dist/core/ingestion/languages/typescript/arity.js +54 -0
  37. package/dist/core/ingestion/languages/typescript/cache-stats.d.ts +17 -0
  38. package/dist/core/ingestion/languages/typescript/cache-stats.js +28 -0
  39. package/dist/core/ingestion/languages/typescript/captures.d.ts +28 -0
  40. package/dist/core/ingestion/languages/typescript/captures.js +451 -0
  41. package/dist/core/ingestion/languages/typescript/import-decomposer.d.ts +49 -0
  42. package/dist/core/ingestion/languages/typescript/import-decomposer.js +371 -0
  43. package/dist/core/ingestion/languages/typescript/import-target.d.ts +50 -0
  44. package/dist/core/ingestion/languages/typescript/import-target.js +61 -0
  45. package/dist/core/ingestion/languages/typescript/index.d.ts +94 -0
  46. package/dist/core/ingestion/languages/typescript/index.js +94 -0
  47. package/dist/core/ingestion/languages/typescript/interpret.d.ts +35 -0
  48. package/dist/core/ingestion/languages/typescript/interpret.js +317 -0
  49. package/dist/core/ingestion/languages/typescript/merge-bindings.d.ts +62 -0
  50. package/dist/core/ingestion/languages/typescript/merge-bindings.js +158 -0
  51. package/dist/core/ingestion/languages/typescript/query.d.ts +77 -0
  52. package/dist/core/ingestion/languages/typescript/query.js +778 -0
  53. package/dist/core/ingestion/languages/typescript/receiver-binding.d.ts +59 -0
  54. package/dist/core/ingestion/languages/typescript/receiver-binding.js +171 -0
  55. package/dist/core/ingestion/languages/typescript/scope-resolver.d.ts +16 -0
  56. package/dist/core/ingestion/languages/typescript/scope-resolver.js +113 -0
  57. package/dist/core/ingestion/languages/typescript/simple-hooks.d.ts +71 -0
  58. package/dist/core/ingestion/languages/typescript/simple-hooks.js +131 -0
  59. package/dist/core/ingestion/languages/typescript.js +19 -0
  60. package/dist/core/ingestion/model/scope-resolution-indexes.d.ts +14 -1
  61. package/dist/core/ingestion/parsing-processor.js +3 -3
  62. package/dist/core/ingestion/registry-primary-flag.d.ts +3 -1
  63. package/dist/core/ingestion/registry-primary-flag.js +4 -1
  64. package/dist/core/ingestion/scope-extractor-bridge.d.ts +5 -2
  65. package/dist/core/ingestion/scope-extractor-bridge.js +7 -2
  66. package/dist/core/ingestion/scope-extractor.js +19 -18
  67. package/dist/core/ingestion/scope-resolution/contract/scope-resolver.d.ts +73 -11
  68. package/dist/core/ingestion/scope-resolution/contract/scope-resolver.js +48 -10
  69. package/dist/core/ingestion/scope-resolution/passes/compound-receiver.js +283 -14
  70. package/dist/core/ingestion/scope-resolution/passes/imported-return-types.d.ts +23 -2
  71. package/dist/core/ingestion/scope-resolution/passes/imported-return-types.js +109 -37
  72. package/dist/core/ingestion/scope-resolution/passes/mro.js +3 -1
  73. package/dist/core/ingestion/scope-resolution/passes/receiver-bound-calls.js +13 -5
  74. package/dist/core/ingestion/scope-resolution/pipeline/phase.js +11 -2
  75. package/dist/core/ingestion/scope-resolution/pipeline/registry.js +2 -0
  76. package/dist/core/ingestion/scope-resolution/pipeline/run.d.ts +8 -0
  77. package/dist/core/ingestion/scope-resolution/pipeline/run.js +21 -5
  78. package/dist/core/ingestion/scope-resolution/pipeline/validate-bindings-immutability.d.ts +39 -0
  79. package/dist/core/ingestion/scope-resolution/pipeline/validate-bindings-immutability.js +65 -0
  80. package/dist/core/ingestion/scope-resolution/scope/walkers.d.ts +54 -11
  81. package/dist/core/ingestion/scope-resolution/scope/walkers.js +105 -30
  82. package/dist/core/ingestion/utils/ast-helpers.d.ts +2 -0
  83. package/dist/core/ingestion/utils/ast-helpers.js +12 -0
  84. package/dist/core/ingestion/utils/env.d.ts +10 -0
  85. package/dist/core/ingestion/utils/env.js +14 -0
  86. package/dist/core/ingestion/workers/parse-worker.js +3 -3
  87. package/dist/core/lbug/lbug-adapter.d.ts +3 -4
  88. package/dist/core/lbug/lbug-adapter.js +6 -9
  89. package/dist/core/run-analyze.js +4 -6
  90. package/dist/core/search/bm25-index.d.ts +0 -17
  91. package/dist/core/search/bm25-index.js +10 -118
  92. package/dist/core/search/fts-indexes.d.ts +1 -0
  93. package/dist/core/search/fts-indexes.js +7 -0
  94. package/dist/core/search/fts-schema.d.ts +6 -0
  95. package/dist/core/search/fts-schema.js +7 -0
  96. package/dist/mcp/core/embedder.js +3 -1
  97. package/package.json +1 -1
  98. package/skills/gitnexus-cli.md +1 -1
@@ -12,6 +12,7 @@ import path from 'path';
12
12
  import fs from 'fs/promises';
13
13
  import { runPipelineFromRepo } from './ingestion/pipeline.js';
14
14
  import { initLbug, loadGraphToLbug, getLbugStats, executeQuery, executeWithReusedStatement, closeLbug, loadCachedEmbeddings, } from './lbug/lbug-adapter.js';
15
+ import { createSearchFTSIndexes } from './search/fts-indexes.js';
15
16
  import { getStoragePaths, saveMeta, loadMeta, addToGitignore, registerRepo, cleanupOldKuzuFiles, } from '../storage/repo-manager.js';
16
17
  import { getCurrentCommit, getRemoteUrl, hasGitDir, getInferredRepoName } from '../storage/git.js';
17
18
  import { generateAIContextFiles } from '../cli/ai-context.js';
@@ -165,12 +166,9 @@ export async function runFullAnalysis(repoPath, options, callbacks) {
165
166
  progress('lbug', pct, msg);
166
167
  });
167
168
  // ── Phase 3: FTS (85–90%) ─────────────────────────────────────────
168
- // FTS indexes are created lazily on first `query`/`context` call instead
169
- // of eagerly here. On small repos / CI runners the LadybugDB
170
- // CREATE_FTS_INDEX cost is ~440 ms × 5 (≈2 s) regardless of table size,
171
- // which dominated `analyze` runtime and pushed Windows CI past its
172
- // 30 s test budget. Lazy creation is implemented in
173
- // `core/search/bm25-index.ts` via `ensureFTSIndex`.
169
+ progress('fts', 85, 'Creating search indexes...');
170
+ await createSearchFTSIndexes();
171
+ progress('fts', 90, 'Search indexes ready');
174
172
  // ── Phase 3.5: Re-insert cached embeddings ────────────────────────
175
173
  if (cachedEmbeddings.length > 0) {
176
174
  const cachedDims = cachedEmbeddings[0].embedding.length;
@@ -3,12 +3,6 @@
3
3
  *
4
4
  * Uses LadybugDB's built-in full-text search indexes for keyword-based search.
5
5
  * Always reads from the database (no cached state to drift).
6
- *
7
- * FTS indexes are created lazily on first query (via `ensureFTSIndex`) — see
8
- * `lbug-adapter.ts` for the rationale. This keeps `analyze` fast (the
9
- * ~440 ms × 5 LadybugDB CREATE_FTS_INDEX cost dominates pipeline time on
10
- * small repos / CI runners) at the cost of paying that overhead on the
11
- * first `query`/`context` call in a session.
12
6
  */
13
7
  export interface BM25SearchResult {
14
8
  filePath: string;
@@ -16,17 +10,6 @@ export interface BM25SearchResult {
16
10
  rank: number;
17
11
  nodeIds?: string[];
18
12
  }
19
- /**
20
- * Drop all ensured-FTS cache entries for a given repoId.
21
- *
22
- * Called from the pool-close listener so that a pool teardown / recreation
23
- * forces the next `searchFTSFromLbug` call to re-issue `CREATE_FTS_INDEX`
24
- * against the fresh connection rather than trust stale ensure-state from a
25
- * previous pool lifetime.
26
- *
27
- * Exported for tests; the listener wiring is internal.
28
- */
29
- export declare function invalidateEnsuredFTSForRepo(repoId: string): void;
30
13
  /**
31
14
  * Search using LadybugDB's built-in FTS (always fresh, reads from disk)
32
15
  *
@@ -3,96 +3,9 @@
3
3
  *
4
4
  * Uses LadybugDB's built-in full-text search indexes for keyword-based search.
5
5
  * Always reads from the database (no cached state to drift).
6
- *
7
- * FTS indexes are created lazily on first query (via `ensureFTSIndex`) — see
8
- * `lbug-adapter.ts` for the rationale. This keeps `analyze` fast (the
9
- * ~440 ms × 5 LadybugDB CREATE_FTS_INDEX cost dominates pipeline time on
10
- * small repos / CI runners) at the cost of paying that overhead on the
11
- * first `query`/`context` call in a session.
12
- */
13
- import { queryFTS, ensureFTSIndex } from '../lbug/lbug-adapter.js';
14
- /**
15
- * FTS schema served by `searchFTSFromLbug`. Centralised so that both the
16
- * CLI/pipeline path and the MCP pool path use identical (table, index,
17
- * properties) tuples and the lazy-create logic stays in one place.
18
- */
19
- const FTS_INDEXES = [
20
- { table: 'File', indexName: 'file_fts', properties: ['name', 'content'] },
21
- { table: 'Function', indexName: 'function_fts', properties: ['name', 'content'] },
22
- { table: 'Class', indexName: 'class_fts', properties: ['name', 'content'] },
23
- { table: 'Method', indexName: 'method_fts', properties: ['name', 'content'] },
24
- { table: 'Interface', indexName: 'interface_fts', properties: ['name', 'content'] },
25
- ];
26
- /**
27
- * Per-process cache for the MCP pool path: tracks which `(repoId, table)`
28
- * pairs have been ensured. The CLI/pipeline path gets its own cache inside
29
- * `lbug-adapter.ts` keyed by table/index, scoped to the singleton connection.
30
- *
31
- * IMPORTANT: an entry is added ONLY when the index was confirmed to exist
32
- * (CREATE_FTS_INDEX succeeded, or failed with `'already exists'`). Other
33
- * failures (transient lock errors, missing extension, etc.) leave the key
34
- * unset so the next query retries instead of silently caching the failure.
35
- *
36
- * Entries for a given repoId are invalidated when its pool is closed —
37
- * see the `addPoolCloseListener` registration in `searchFTSFromLbug`.
38
- */
39
- const ensuredPoolFTS = new Set();
40
- /**
41
- * Drop all ensured-FTS cache entries for a given repoId.
42
- *
43
- * Called from the pool-close listener so that a pool teardown / recreation
44
- * forces the next `searchFTSFromLbug` call to re-issue `CREATE_FTS_INDEX`
45
- * against the fresh connection rather than trust stale ensure-state from a
46
- * previous pool lifetime.
47
- *
48
- * Exported for tests; the listener wiring is internal.
49
6
  */
50
- export function invalidateEnsuredFTSForRepo(repoId) {
51
- const prefix = `${repoId}:`;
52
- for (const key of ensuredPoolFTS) {
53
- if (key.startsWith(prefix))
54
- ensuredPoolFTS.delete(key);
55
- }
56
- }
57
- /**
58
- * Tracks whether we've already wired the pool-close listener for this
59
- * process. The pool adapter is dynamically imported, so registration
60
- * happens lazily on the first MCP-pool-backed FTS query.
61
- */
62
- let poolCloseListenerRegistered = false;
63
- function registerPoolCloseListenerOnce(addPoolCloseListener) {
64
- if (poolCloseListenerRegistered)
65
- return;
66
- poolCloseListenerRegistered = true;
67
- addPoolCloseListener((repoId) => invalidateEnsuredFTSForRepo(repoId));
68
- }
69
- async function ensureFTSIndexViaExecutor(executor, repoId, table, indexName, properties) {
70
- const key = `${repoId}:${table}:${indexName}`;
71
- if (ensuredPoolFTS.has(key))
72
- return;
73
- const propList = properties.map((p) => `'${p}'`).join(', ');
74
- try {
75
- await executor(`CALL CREATE_FTS_INDEX('${table}', '${indexName}', [${propList}], stemmer := 'porter')`);
76
- // Index was created successfully — safe to cache.
77
- ensuredPoolFTS.add(key);
78
- }
79
- catch (e) {
80
- // 'already exists' is the happy path (index persists on disk between
81
- // process invocations) — cache it. Anything else is treated as a
82
- // transient failure: surface a one-time warning and leave the key
83
- // unset so the NEXT query retries rather than silently using a
84
- // cached failure (which previously disabled BM25 for the whole
85
- // process for that repo).
86
- const msg = String(e?.message ?? '');
87
- if (msg.includes('already exists')) {
88
- ensuredPoolFTS.add(key);
89
- }
90
- else {
91
- console.warn(`[gitnexus] FTS index ensure failed for repo "${repoId}" table "${table}" ` +
92
- `(index "${indexName}"): ${msg || e}. Will retry on next query.`);
93
- }
94
- }
95
- }
7
+ import { queryFTS } from '../lbug/lbug-adapter.js';
8
+ import { FTS_INDEXES } from './fts-schema.js';
96
9
  /**
97
10
  * Execute a single FTS query via a custom executor (for MCP connection pool).
98
11
  * Returns the same shape as core queryFTS (from LadybugDB adapter).
@@ -134,41 +47,23 @@ async function queryFTSViaExecutor(executor, tableName, indexName, query, limit)
134
47
  * @returns Ranked search results from FTS indexes
135
48
  */
136
49
  export const searchFTSFromLbug = async (query, limit = 20, repoId) => {
137
- let fileResults, functionResults, classResults, methodResults, interfaceResults;
50
+ const resultsByIndex = [];
138
51
  if (repoId) {
139
52
  // Use MCP connection pool via dynamic import
140
53
  // IMPORTANT: FTS queries run sequentially to avoid connection contention.
141
54
  // The MCP pool supports multiple connections, but FTS is best run serially.
142
55
  const poolMod = await import('../lbug/pool-adapter.js');
143
- const { executeQuery, addPoolCloseListener } = poolMod;
144
- // Register the pool-close listener lazily on first use so a teardown of
145
- // the pool entry (LRU eviction, idle timeout, explicit close) drops the
146
- // matching `ensuredPoolFTS` entries. Without this, stale ensure-state
147
- // can outlive the pool that produced it.
148
- registerPoolCloseListenerOnce(addPoolCloseListener);
56
+ const { executeQuery } = poolMod;
149
57
  const executor = (cypher) => executeQuery(repoId, cypher);
150
- // Lazy-create FTS indexes on first query for this repo (analyze no longer
151
- // creates them up-front, so we ensure them here). Cached per-process.
152
- for (const { table, indexName, properties } of FTS_INDEXES) {
153
- await ensureFTSIndexViaExecutor(executor, repoId, table, indexName, properties);
58
+ for (const { table, indexName } of FTS_INDEXES) {
59
+ resultsByIndex.push(await queryFTSViaExecutor(executor, table, indexName, query, limit));
154
60
  }
155
- fileResults = await queryFTSViaExecutor(executor, 'File', 'file_fts', query, limit);
156
- functionResults = await queryFTSViaExecutor(executor, 'Function', 'function_fts', query, limit);
157
- classResults = await queryFTSViaExecutor(executor, 'Class', 'class_fts', query, limit);
158
- methodResults = await queryFTSViaExecutor(executor, 'Method', 'method_fts', query, limit);
159
- interfaceResults = await queryFTSViaExecutor(executor, 'Interface', 'interface_fts', query, limit);
160
61
  }
161
62
  else {
162
63
  // Use core lbug adapter (CLI / pipeline context) — also sequential for safety.
163
- // Lazy-create FTS indexes on first query (analyze no longer does it).
164
- for (const { table, indexName, properties } of FTS_INDEXES) {
165
- await ensureFTSIndex(table, indexName, [...properties]).catch(() => { });
64
+ for (const { table, indexName } of FTS_INDEXES) {
65
+ resultsByIndex.push(await queryFTS(table, indexName, query, limit, false).catch(() => []));
166
66
  }
167
- fileResults = await queryFTS('File', 'file_fts', query, limit, false).catch(() => []);
168
- functionResults = await queryFTS('Function', 'function_fts', query, limit, false).catch(() => []);
169
- classResults = await queryFTS('Class', 'class_fts', query, limit, false).catch(() => []);
170
- methodResults = await queryFTS('Method', 'method_fts', query, limit, false).catch(() => []);
171
- interfaceResults = await queryFTS('Interface', 'interface_fts', query, limit, false).catch(() => []);
172
67
  }
173
68
  // Collect all node scores per filePath to track which nodes actually matched
174
69
  const fileNodeScores = new Map();
@@ -179,11 +74,8 @@ export const searchFTSFromLbug = async (query, limit = 20, repoId) => {
179
74
  fileNodeScores.get(r.filePath).push({ score: r.score, nodeId: r.nodeId });
180
75
  }
181
76
  };
182
- addResults(fileResults);
183
- addResults(functionResults);
184
- addResults(classResults);
185
- addResults(methodResults);
186
- addResults(interfaceResults);
77
+ for (const results of resultsByIndex)
78
+ addResults(results);
187
79
  // Sum the top-3 highest-scoring nodes per file and collect their nodeIds.
188
80
  // Summing all nodes naively inflates scores for files with many mediocre
189
81
  // matches (e.g. test files) over files with a single highly-relevant symbol.
@@ -0,0 +1 @@
1
+ export declare function createSearchFTSIndexes(): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import { createFTSIndex } from '../lbug/lbug-adapter.js';
2
+ import { FTS_INDEXES } from './fts-schema.js';
3
+ export async function createSearchFTSIndexes() {
4
+ for (const { table, indexName, properties } of FTS_INDEXES) {
5
+ await createFTSIndex(table, indexName, [...properties]);
6
+ }
7
+ }
@@ -0,0 +1,6 @@
1
+ export interface FTSIndexDefinition {
2
+ readonly table: string;
3
+ readonly indexName: string;
4
+ readonly properties: readonly string[];
5
+ }
6
+ export declare const FTS_INDEXES: readonly FTSIndexDefinition[];
@@ -0,0 +1,7 @@
1
+ export const FTS_INDEXES = [
2
+ { table: 'File', indexName: 'file_fts', properties: ['name', 'content'] },
3
+ { table: 'Function', indexName: 'function_fts', properties: ['name', 'content'] },
4
+ { table: 'Class', indexName: 'class_fts', properties: ['name', 'content'] },
5
+ { table: 'Method', indexName: 'method_fts', properties: ['name', 'content'] },
6
+ { table: 'Interface', indexName: 'interface_fts', properties: ['name', 'content'] },
7
+ ];
@@ -5,6 +5,8 @@
5
5
  * For MCP, we only need to compute query embeddings, not batch embed.
6
6
  */
7
7
  import { pipeline, env } from '@huggingface/transformers';
8
+ import os from 'os';
9
+ import { join } from 'path';
8
10
  import { isHttpMode, getHttpDimensions, httpEmbedQuery, } from '../../core/embeddings/http-client.js';
9
11
  import { silenceStdout, restoreStdout, realStderrWrite } from '../../core/lbug/pool-adapter.js';
10
12
  // Model config
@@ -34,7 +36,7 @@ export const initEmbedder = async () => {
34
36
  // ./node_modules/.cache inside its own install dir, which is unwritable
35
37
  // when gitnexus is installed globally (e.g. /usr/lib/node_modules/).
36
38
  // Respect HF_HOME if set, otherwise fall back to ~/.cache/huggingface.
37
- env.cacheDir = process.env.HF_HOME ?? `${process.env.HOME}/.cache/huggingface`;
39
+ env.cacheDir = process.env.HF_HOME ?? join(os.homedir(), '.cache', 'huggingface');
38
40
  console.error('GitNexus: Loading embedding model (first search may take a moment)...');
39
41
  // Try GPU first (DirectML on Windows, CUDA on Linux), fall back to CPU
40
42
  const isWindows = process.platform === 'win32';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitnexus",
3
- "version": "1.6.3",
3
+ "version": "1.6.4-rc.10",
4
4
  "description": "Graph-powered code intelligence for AI agents. Index any codebase, query via MCP or CLI.",
5
5
  "author": "Abhigyan Patwari",
6
6
  "license": "PolyForm-Noncommercial-1.0.0",
@@ -23,7 +23,7 @@ Run from the project root. This parses all source files, builds the knowledge gr
23
23
  | `--embeddings` | Enable embedding generation for semantic search (off by default) |
24
24
  | `--drop-embeddings` | Drop existing embeddings on rebuild. By default, an `analyze` without `--embeddings` preserves them. |
25
25
 
26
- **When to run:** First time in a project, after major code changes, or when `gitnexus://repo/{name}/context` reports the index is stale. In Claude Code, a PostToolUse hook runs `analyze` automatically after `git commit` and `git merge`, preserving embeddings if previously generated.
26
+ **When to run:** First time in a project, after major code changes, or when `gitnexus://repo/{name}/context` reports the index is stale. In Claude Code, a PostToolUse hook detects staleness after `git commit` and `git merge` and notifies the agent to run `analyze` — the hook does not run analyze itself, to avoid blocking the agent for up to 120s and risking KuzuDB corruption on timeout.
27
27
 
28
28
  ### status — Check index freshness
29
29