@duytransipher/gitnexus 1.4.6-sipher.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 (224) hide show
  1. package/LICENSE +73 -0
  2. package/README.md +261 -0
  3. package/dist/cli/ai-context.d.ts +23 -0
  4. package/dist/cli/ai-context.js +265 -0
  5. package/dist/cli/analyze.d.ts +12 -0
  6. package/dist/cli/analyze.js +345 -0
  7. package/dist/cli/augment.d.ts +13 -0
  8. package/dist/cli/augment.js +33 -0
  9. package/dist/cli/clean.d.ts +10 -0
  10. package/dist/cli/clean.js +60 -0
  11. package/dist/cli/eval-server.d.ts +37 -0
  12. package/dist/cli/eval-server.js +389 -0
  13. package/dist/cli/index.d.ts +2 -0
  14. package/dist/cli/index.js +137 -0
  15. package/dist/cli/lazy-action.d.ts +6 -0
  16. package/dist/cli/lazy-action.js +18 -0
  17. package/dist/cli/list.d.ts +6 -0
  18. package/dist/cli/list.js +30 -0
  19. package/dist/cli/mcp.d.ts +8 -0
  20. package/dist/cli/mcp.js +36 -0
  21. package/dist/cli/serve.d.ts +4 -0
  22. package/dist/cli/serve.js +6 -0
  23. package/dist/cli/setup.d.ts +8 -0
  24. package/dist/cli/setup.js +367 -0
  25. package/dist/cli/sipher-patched.d.ts +2 -0
  26. package/dist/cli/sipher-patched.js +77 -0
  27. package/dist/cli/skill-gen.d.ts +26 -0
  28. package/dist/cli/skill-gen.js +549 -0
  29. package/dist/cli/status.d.ts +6 -0
  30. package/dist/cli/status.js +36 -0
  31. package/dist/cli/tool.d.ts +60 -0
  32. package/dist/cli/tool.js +180 -0
  33. package/dist/cli/wiki.d.ts +15 -0
  34. package/dist/cli/wiki.js +365 -0
  35. package/dist/config/ignore-service.d.ts +26 -0
  36. package/dist/config/ignore-service.js +284 -0
  37. package/dist/config/supported-languages.d.ts +15 -0
  38. package/dist/config/supported-languages.js +16 -0
  39. package/dist/core/augmentation/engine.d.ts +26 -0
  40. package/dist/core/augmentation/engine.js +240 -0
  41. package/dist/core/embeddings/embedder.d.ts +60 -0
  42. package/dist/core/embeddings/embedder.js +251 -0
  43. package/dist/core/embeddings/embedding-pipeline.d.ts +51 -0
  44. package/dist/core/embeddings/embedding-pipeline.js +356 -0
  45. package/dist/core/embeddings/index.d.ts +9 -0
  46. package/dist/core/embeddings/index.js +9 -0
  47. package/dist/core/embeddings/text-generator.d.ts +24 -0
  48. package/dist/core/embeddings/text-generator.js +182 -0
  49. package/dist/core/embeddings/types.d.ts +87 -0
  50. package/dist/core/embeddings/types.js +32 -0
  51. package/dist/core/graph/graph.d.ts +2 -0
  52. package/dist/core/graph/graph.js +66 -0
  53. package/dist/core/graph/types.d.ts +66 -0
  54. package/dist/core/graph/types.js +1 -0
  55. package/dist/core/ingestion/ast-cache.d.ts +11 -0
  56. package/dist/core/ingestion/ast-cache.js +35 -0
  57. package/dist/core/ingestion/call-processor.d.ts +23 -0
  58. package/dist/core/ingestion/call-processor.js +793 -0
  59. package/dist/core/ingestion/call-routing.d.ts +68 -0
  60. package/dist/core/ingestion/call-routing.js +129 -0
  61. package/dist/core/ingestion/cluster-enricher.d.ts +38 -0
  62. package/dist/core/ingestion/cluster-enricher.js +170 -0
  63. package/dist/core/ingestion/community-processor.d.ts +39 -0
  64. package/dist/core/ingestion/community-processor.js +312 -0
  65. package/dist/core/ingestion/constants.d.ts +16 -0
  66. package/dist/core/ingestion/constants.js +16 -0
  67. package/dist/core/ingestion/entry-point-scoring.d.ts +40 -0
  68. package/dist/core/ingestion/entry-point-scoring.js +353 -0
  69. package/dist/core/ingestion/export-detection.d.ts +18 -0
  70. package/dist/core/ingestion/export-detection.js +231 -0
  71. package/dist/core/ingestion/filesystem-walker.d.ts +28 -0
  72. package/dist/core/ingestion/filesystem-walker.js +81 -0
  73. package/dist/core/ingestion/framework-detection.d.ts +54 -0
  74. package/dist/core/ingestion/framework-detection.js +411 -0
  75. package/dist/core/ingestion/heritage-processor.d.ts +28 -0
  76. package/dist/core/ingestion/heritage-processor.js +251 -0
  77. package/dist/core/ingestion/import-processor.d.ts +34 -0
  78. package/dist/core/ingestion/import-processor.js +398 -0
  79. package/dist/core/ingestion/language-config.d.ts +46 -0
  80. package/dist/core/ingestion/language-config.js +167 -0
  81. package/dist/core/ingestion/mro-processor.d.ts +45 -0
  82. package/dist/core/ingestion/mro-processor.js +369 -0
  83. package/dist/core/ingestion/named-binding-extraction.d.ts +61 -0
  84. package/dist/core/ingestion/named-binding-extraction.js +363 -0
  85. package/dist/core/ingestion/parsing-processor.d.ts +19 -0
  86. package/dist/core/ingestion/parsing-processor.js +315 -0
  87. package/dist/core/ingestion/pipeline.d.ts +6 -0
  88. package/dist/core/ingestion/pipeline.js +401 -0
  89. package/dist/core/ingestion/process-processor.d.ts +51 -0
  90. package/dist/core/ingestion/process-processor.js +315 -0
  91. package/dist/core/ingestion/resolution-context.d.ts +53 -0
  92. package/dist/core/ingestion/resolution-context.js +132 -0
  93. package/dist/core/ingestion/resolvers/csharp.d.ts +22 -0
  94. package/dist/core/ingestion/resolvers/csharp.js +109 -0
  95. package/dist/core/ingestion/resolvers/go.d.ts +19 -0
  96. package/dist/core/ingestion/resolvers/go.js +42 -0
  97. package/dist/core/ingestion/resolvers/index.d.ts +18 -0
  98. package/dist/core/ingestion/resolvers/index.js +13 -0
  99. package/dist/core/ingestion/resolvers/jvm.d.ts +23 -0
  100. package/dist/core/ingestion/resolvers/jvm.js +87 -0
  101. package/dist/core/ingestion/resolvers/php.d.ts +15 -0
  102. package/dist/core/ingestion/resolvers/php.js +35 -0
  103. package/dist/core/ingestion/resolvers/python.d.ts +19 -0
  104. package/dist/core/ingestion/resolvers/python.js +52 -0
  105. package/dist/core/ingestion/resolvers/ruby.d.ts +12 -0
  106. package/dist/core/ingestion/resolvers/ruby.js +15 -0
  107. package/dist/core/ingestion/resolvers/rust.d.ts +15 -0
  108. package/dist/core/ingestion/resolvers/rust.js +73 -0
  109. package/dist/core/ingestion/resolvers/standard.d.ts +28 -0
  110. package/dist/core/ingestion/resolvers/standard.js +123 -0
  111. package/dist/core/ingestion/resolvers/utils.d.ts +33 -0
  112. package/dist/core/ingestion/resolvers/utils.js +122 -0
  113. package/dist/core/ingestion/structure-processor.d.ts +2 -0
  114. package/dist/core/ingestion/structure-processor.js +36 -0
  115. package/dist/core/ingestion/symbol-table.d.ts +63 -0
  116. package/dist/core/ingestion/symbol-table.js +85 -0
  117. package/dist/core/ingestion/tree-sitter-queries.d.ts +15 -0
  118. package/dist/core/ingestion/tree-sitter-queries.js +888 -0
  119. package/dist/core/ingestion/type-env.d.ts +49 -0
  120. package/dist/core/ingestion/type-env.js +613 -0
  121. package/dist/core/ingestion/type-extractors/c-cpp.d.ts +2 -0
  122. package/dist/core/ingestion/type-extractors/c-cpp.js +385 -0
  123. package/dist/core/ingestion/type-extractors/csharp.d.ts +2 -0
  124. package/dist/core/ingestion/type-extractors/csharp.js +383 -0
  125. package/dist/core/ingestion/type-extractors/go.d.ts +2 -0
  126. package/dist/core/ingestion/type-extractors/go.js +467 -0
  127. package/dist/core/ingestion/type-extractors/index.d.ts +22 -0
  128. package/dist/core/ingestion/type-extractors/index.js +31 -0
  129. package/dist/core/ingestion/type-extractors/jvm.d.ts +3 -0
  130. package/dist/core/ingestion/type-extractors/jvm.js +681 -0
  131. package/dist/core/ingestion/type-extractors/php.d.ts +2 -0
  132. package/dist/core/ingestion/type-extractors/php.js +549 -0
  133. package/dist/core/ingestion/type-extractors/python.d.ts +2 -0
  134. package/dist/core/ingestion/type-extractors/python.js +455 -0
  135. package/dist/core/ingestion/type-extractors/ruby.d.ts +2 -0
  136. package/dist/core/ingestion/type-extractors/ruby.js +389 -0
  137. package/dist/core/ingestion/type-extractors/rust.d.ts +2 -0
  138. package/dist/core/ingestion/type-extractors/rust.js +456 -0
  139. package/dist/core/ingestion/type-extractors/shared.d.ts +145 -0
  140. package/dist/core/ingestion/type-extractors/shared.js +810 -0
  141. package/dist/core/ingestion/type-extractors/swift.d.ts +2 -0
  142. package/dist/core/ingestion/type-extractors/swift.js +137 -0
  143. package/dist/core/ingestion/type-extractors/types.d.ts +127 -0
  144. package/dist/core/ingestion/type-extractors/types.js +1 -0
  145. package/dist/core/ingestion/type-extractors/typescript.d.ts +2 -0
  146. package/dist/core/ingestion/type-extractors/typescript.js +494 -0
  147. package/dist/core/ingestion/utils.d.ts +138 -0
  148. package/dist/core/ingestion/utils.js +1290 -0
  149. package/dist/core/ingestion/workers/parse-worker.d.ts +122 -0
  150. package/dist/core/ingestion/workers/parse-worker.js +1126 -0
  151. package/dist/core/ingestion/workers/worker-pool.d.ts +16 -0
  152. package/dist/core/ingestion/workers/worker-pool.js +128 -0
  153. package/dist/core/lbug/csv-generator.d.ts +33 -0
  154. package/dist/core/lbug/csv-generator.js +366 -0
  155. package/dist/core/lbug/lbug-adapter.d.ts +103 -0
  156. package/dist/core/lbug/lbug-adapter.js +769 -0
  157. package/dist/core/lbug/schema.d.ts +53 -0
  158. package/dist/core/lbug/schema.js +430 -0
  159. package/dist/core/search/bm25-index.d.ts +23 -0
  160. package/dist/core/search/bm25-index.js +96 -0
  161. package/dist/core/search/hybrid-search.d.ts +49 -0
  162. package/dist/core/search/hybrid-search.js +118 -0
  163. package/dist/core/tree-sitter/parser-loader.d.ts +5 -0
  164. package/dist/core/tree-sitter/parser-loader.js +63 -0
  165. package/dist/core/wiki/generator.d.ts +120 -0
  166. package/dist/core/wiki/generator.js +939 -0
  167. package/dist/core/wiki/graph-queries.d.ts +80 -0
  168. package/dist/core/wiki/graph-queries.js +238 -0
  169. package/dist/core/wiki/html-viewer.d.ts +10 -0
  170. package/dist/core/wiki/html-viewer.js +297 -0
  171. package/dist/core/wiki/llm-client.d.ts +43 -0
  172. package/dist/core/wiki/llm-client.js +186 -0
  173. package/dist/core/wiki/prompts.d.ts +53 -0
  174. package/dist/core/wiki/prompts.js +174 -0
  175. package/dist/lib/utils.d.ts +1 -0
  176. package/dist/lib/utils.js +3 -0
  177. package/dist/mcp/compatible-stdio-transport.d.ts +25 -0
  178. package/dist/mcp/compatible-stdio-transport.js +200 -0
  179. package/dist/mcp/core/embedder.d.ts +27 -0
  180. package/dist/mcp/core/embedder.js +108 -0
  181. package/dist/mcp/core/lbug-adapter.d.ts +57 -0
  182. package/dist/mcp/core/lbug-adapter.js +455 -0
  183. package/dist/mcp/local/local-backend.d.ts +181 -0
  184. package/dist/mcp/local/local-backend.js +1722 -0
  185. package/dist/mcp/resources.d.ts +31 -0
  186. package/dist/mcp/resources.js +411 -0
  187. package/dist/mcp/server.d.ts +23 -0
  188. package/dist/mcp/server.js +296 -0
  189. package/dist/mcp/staleness.d.ts +15 -0
  190. package/dist/mcp/staleness.js +29 -0
  191. package/dist/mcp/tools.d.ts +24 -0
  192. package/dist/mcp/tools.js +292 -0
  193. package/dist/server/api.d.ts +10 -0
  194. package/dist/server/api.js +344 -0
  195. package/dist/server/mcp-http.d.ts +13 -0
  196. package/dist/server/mcp-http.js +100 -0
  197. package/dist/storage/git.d.ts +6 -0
  198. package/dist/storage/git.js +35 -0
  199. package/dist/storage/repo-manager.d.ts +138 -0
  200. package/dist/storage/repo-manager.js +299 -0
  201. package/dist/types/pipeline.d.ts +32 -0
  202. package/dist/types/pipeline.js +18 -0
  203. package/dist/unreal/bridge.d.ts +4 -0
  204. package/dist/unreal/bridge.js +113 -0
  205. package/dist/unreal/config.d.ts +6 -0
  206. package/dist/unreal/config.js +55 -0
  207. package/dist/unreal/types.d.ts +105 -0
  208. package/dist/unreal/types.js +1 -0
  209. package/hooks/claude/gitnexus-hook.cjs +238 -0
  210. package/hooks/claude/pre-tool-use.sh +79 -0
  211. package/hooks/claude/session-start.sh +42 -0
  212. package/package.json +100 -0
  213. package/scripts/ensure-cli-executable.cjs +21 -0
  214. package/scripts/patch-tree-sitter-swift.cjs +74 -0
  215. package/scripts/setup-unreal-gitnexus.ps1 +191 -0
  216. package/skills/gitnexus-cli.md +82 -0
  217. package/skills/gitnexus-debugging.md +89 -0
  218. package/skills/gitnexus-exploring.md +78 -0
  219. package/skills/gitnexus-guide.md +64 -0
  220. package/skills/gitnexus-impact-analysis.md +97 -0
  221. package/skills/gitnexus-pr-review.md +163 -0
  222. package/skills/gitnexus-refactoring.md +121 -0
  223. package/vendor/leiden/index.cjs +355 -0
  224. package/vendor/leiden/utils.cjs +392 -0
@@ -0,0 +1,284 @@
1
+ import ignore from 'ignore';
2
+ import fs from 'fs/promises';
3
+ import nodePath from 'path';
4
+ const DEFAULT_IGNORE_LIST = new Set([
5
+ // Version Control
6
+ '.git',
7
+ '.svn',
8
+ '.hg',
9
+ '.bzr',
10
+ // IDEs & Editors
11
+ '.idea',
12
+ '.vscode',
13
+ '.vs',
14
+ '.eclipse',
15
+ '.settings',
16
+ '.DS_Store',
17
+ 'Thumbs.db',
18
+ // Dependencies
19
+ 'node_modules',
20
+ 'bower_components',
21
+ 'jspm_packages',
22
+ 'vendor', // PHP/Go
23
+ // 'packages' removed - commonly used for monorepo source code (lerna, pnpm, yarn workspaces)
24
+ 'venv',
25
+ '.venv',
26
+ 'env',
27
+ '.env',
28
+ '__pycache__',
29
+ '.pytest_cache',
30
+ '.mypy_cache',
31
+ 'site-packages',
32
+ '.tox',
33
+ 'eggs',
34
+ '.eggs',
35
+ 'lib64',
36
+ 'parts',
37
+ 'sdist',
38
+ 'wheels',
39
+ // Build Outputs
40
+ 'dist',
41
+ 'build',
42
+ 'out',
43
+ 'output',
44
+ 'bin',
45
+ 'obj',
46
+ 'target', // Java/Rust
47
+ '.next',
48
+ '.nuxt',
49
+ '.output',
50
+ '.vercel',
51
+ '.netlify',
52
+ '.serverless',
53
+ '_build',
54
+ 'public/build',
55
+ '.parcel-cache',
56
+ '.turbo',
57
+ '.svelte-kit',
58
+ // Test & Coverage
59
+ 'coverage',
60
+ '.nyc_output',
61
+ 'htmlcov',
62
+ '.coverage',
63
+ '__tests__', // Often just test files
64
+ '__mocks__',
65
+ '.jest',
66
+ // Logs & Temp
67
+ 'logs',
68
+ 'log',
69
+ 'tmp',
70
+ 'temp',
71
+ 'cache',
72
+ '.cache',
73
+ '.tmp',
74
+ '.temp',
75
+ // Generated/Compiled
76
+ '.generated',
77
+ 'generated',
78
+ 'auto-generated',
79
+ '.terraform',
80
+ '.serverless',
81
+ // Documentation (optional - might want to keep)
82
+ // 'docs',
83
+ // 'documentation',
84
+ // Misc
85
+ '.husky',
86
+ '.github', // GitHub config, not code
87
+ '.circleci',
88
+ '.gitlab',
89
+ 'fixtures', // Test fixtures
90
+ 'snapshots', // Jest snapshots
91
+ '__snapshots__',
92
+ ]);
93
+ const IGNORED_EXTENSIONS = new Set([
94
+ // Images
95
+ '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.webp', '.bmp', '.tiff', '.tif',
96
+ '.psd', '.ai', '.sketch', '.fig', '.xd',
97
+ // Archives
98
+ '.zip', '.tar', '.gz', '.rar', '.7z', '.bz2', '.xz', '.tgz',
99
+ // Binary/Compiled
100
+ '.exe', '.dll', '.so', '.dylib', '.a', '.lib', '.o', '.obj',
101
+ '.class', '.jar', '.war', '.ear',
102
+ '.pyc', '.pyo', '.pyd',
103
+ '.beam', // Erlang
104
+ '.wasm', // WebAssembly - important!
105
+ '.node', // Native Node addons
106
+ // Documents
107
+ '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx',
108
+ '.odt', '.ods', '.odp',
109
+ // Media
110
+ '.mp4', '.mp3', '.wav', '.mov', '.avi', '.mkv', '.flv', '.wmv',
111
+ '.ogg', '.webm', '.flac', '.aac', '.m4a',
112
+ // Fonts
113
+ '.woff', '.woff2', '.ttf', '.eot', '.otf',
114
+ // Databases
115
+ '.db', '.sqlite', '.sqlite3', '.mdb', '.accdb',
116
+ // Minified/Bundled files
117
+ '.min.js', '.min.css', '.bundle.js', '.chunk.js',
118
+ // Source maps (debug files, not source)
119
+ '.map',
120
+ // Lock files (handled separately, but also here)
121
+ '.lock',
122
+ // Certificates & Keys (security - don't index!)
123
+ '.pem', '.key', '.crt', '.cer', '.p12', '.pfx',
124
+ // Data files (often large/binary)
125
+ '.csv', '.tsv', '.parquet', '.avro', '.feather',
126
+ '.npy', '.npz', '.pkl', '.pickle', '.h5', '.hdf5',
127
+ // Misc binary
128
+ '.bin', '.dat', '.data', '.raw',
129
+ '.iso', '.img', '.dmg',
130
+ ]);
131
+ // Files to ignore by exact name
132
+ const IGNORED_FILES = new Set([
133
+ 'package-lock.json',
134
+ 'yarn.lock',
135
+ 'pnpm-lock.yaml',
136
+ 'composer.lock',
137
+ 'Gemfile.lock',
138
+ 'poetry.lock',
139
+ 'Cargo.lock',
140
+ 'go.sum',
141
+ '.gitignore',
142
+ '.gitattributes',
143
+ '.npmrc',
144
+ '.yarnrc',
145
+ '.editorconfig',
146
+ '.prettierrc',
147
+ '.prettierignore',
148
+ '.eslintignore',
149
+ '.dockerignore',
150
+ 'Thumbs.db',
151
+ '.DS_Store',
152
+ 'LICENSE',
153
+ 'LICENSE.md',
154
+ 'LICENSE.txt',
155
+ 'CHANGELOG.md',
156
+ 'CHANGELOG',
157
+ 'CONTRIBUTING.md',
158
+ 'CODE_OF_CONDUCT.md',
159
+ 'SECURITY.md',
160
+ '.env',
161
+ '.env.local',
162
+ '.env.development',
163
+ '.env.production',
164
+ '.env.test',
165
+ '.env.example',
166
+ ]);
167
+ // NOTE: Negation patterns in .gitnexusignore (e.g. `!vendor/`) cannot override
168
+ // entries in DEFAULT_IGNORE_LIST — this is intentional. The hardcoded list protects
169
+ // against indexing directories that are almost never source code (node_modules, .git, etc.).
170
+ // Users who need to include such directories should remove them from the hardcoded list.
171
+ export const shouldIgnorePath = (filePath) => {
172
+ const normalizedPath = filePath.replace(/\\/g, '/');
173
+ const parts = normalizedPath.split('/');
174
+ const fileName = parts[parts.length - 1];
175
+ const fileNameLower = fileName.toLowerCase();
176
+ // Check if any path segment is in ignore list
177
+ for (const part of parts) {
178
+ if (DEFAULT_IGNORE_LIST.has(part)) {
179
+ return true;
180
+ }
181
+ }
182
+ // Check exact filename matches
183
+ if (IGNORED_FILES.has(fileName) || IGNORED_FILES.has(fileNameLower)) {
184
+ return true;
185
+ }
186
+ // Check extension
187
+ const lastDotIndex = fileNameLower.lastIndexOf('.');
188
+ if (lastDotIndex !== -1) {
189
+ const ext = fileNameLower.substring(lastDotIndex);
190
+ if (IGNORED_EXTENSIONS.has(ext))
191
+ return true;
192
+ // Handle compound extensions like .min.js, .bundle.js
193
+ const secondLastDot = fileNameLower.lastIndexOf('.', lastDotIndex - 1);
194
+ if (secondLastDot !== -1) {
195
+ const compoundExt = fileNameLower.substring(secondLastDot);
196
+ if (IGNORED_EXTENSIONS.has(compoundExt))
197
+ return true;
198
+ }
199
+ }
200
+ // Ignore hidden files (starting with .)
201
+ if (fileName.startsWith('.') && fileName !== '.') {
202
+ // But allow some important config files
203
+ const allowedDotFiles = ['.env', '.gitignore']; // Already in IGNORED_FILES, so this is redundant
204
+ // Actually, let's NOT ignore all dot files - many are important configs
205
+ // Just rely on the explicit lists above
206
+ }
207
+ // Ignore files that look like generated/bundled code
208
+ if (fileNameLower.includes('.bundle.') ||
209
+ fileNameLower.includes('.chunk.') ||
210
+ fileNameLower.includes('.generated.') ||
211
+ fileNameLower.endsWith('.d.ts')) { // TypeScript declaration files
212
+ return true;
213
+ }
214
+ return false;
215
+ };
216
+ /** Check if a directory name is in the hardcoded ignore list */
217
+ export const isHardcodedIgnoredDirectory = (name) => {
218
+ return DEFAULT_IGNORE_LIST.has(name);
219
+ };
220
+ export const loadIgnoreRules = async (repoPath, options) => {
221
+ const ig = ignore();
222
+ let hasRules = false;
223
+ // Allow users to bypass .gitignore parsing (e.g. when .gitignore accidentally excludes source files)
224
+ const skipGitignore = options?.noGitignore ?? !!process.env.GITNEXUS_NO_GITIGNORE;
225
+ const filenames = skipGitignore
226
+ ? ['.gitnexusignore']
227
+ : ['.gitignore', '.gitnexusignore'];
228
+ for (const filename of filenames) {
229
+ try {
230
+ const content = await fs.readFile(nodePath.join(repoPath, filename), 'utf-8');
231
+ ig.add(content);
232
+ hasRules = true;
233
+ }
234
+ catch (err) {
235
+ const code = err.code;
236
+ if (code !== 'ENOENT') {
237
+ console.warn(` Warning: could not read ${filename}: ${err.message}`);
238
+ }
239
+ }
240
+ }
241
+ return hasRules ? ig : null;
242
+ };
243
+ /**
244
+ * Create a glob-compatible ignore filter combining:
245
+ * - .gitignore / .gitnexusignore patterns (via `ignore` package)
246
+ * - Hardcoded DEFAULT_IGNORE_LIST, IGNORED_EXTENSIONS, IGNORED_FILES
247
+ *
248
+ * Returns an IgnoreLike object for glob's `ignore` option,
249
+ * enabling directory-level pruning during traversal.
250
+ */
251
+ export const createIgnoreFilter = async (repoPath, options) => {
252
+ const ig = await loadIgnoreRules(repoPath, options);
253
+ return {
254
+ ignored(p) {
255
+ // path-scurry's Path.relative() returns POSIX paths on all platforms,
256
+ // which is what the `ignore` package expects. No explicit normalization needed.
257
+ const rel = p.relative();
258
+ if (!rel)
259
+ return false;
260
+ // Check .gitignore / .gitnexusignore patterns
261
+ if (ig && ig.ignores(rel))
262
+ return true;
263
+ // Fall back to hardcoded rules
264
+ return shouldIgnorePath(rel);
265
+ },
266
+ childrenIgnored(p) {
267
+ // Fast path: check directory name against hardcoded list.
268
+ // Note: dot-directories (.git, .vscode, etc.) are primarily excluded by
269
+ // glob's `dot: false` option in filesystem-walker.ts. This check is
270
+ // defense-in-depth — do not remove `dot: false` assuming this covers it.
271
+ if (DEFAULT_IGNORE_LIST.has(p.name))
272
+ return true;
273
+ // Check against .gitignore / .gitnexusignore patterns.
274
+ // Test both bare path and path with trailing slash to handle
275
+ // bare-name patterns (e.g. `local`) and dir-only patterns (e.g. `local/`).
276
+ if (ig) {
277
+ const rel = p.relative();
278
+ if (rel && (ig.ignores(rel) || ig.ignores(rel + '/')))
279
+ return true;
280
+ }
281
+ return false;
282
+ },
283
+ };
284
+ };
@@ -0,0 +1,15 @@
1
+ export declare enum SupportedLanguages {
2
+ JavaScript = "javascript",
3
+ TypeScript = "typescript",
4
+ Python = "python",
5
+ Java = "java",
6
+ C = "c",
7
+ CPlusPlus = "cpp",
8
+ CSharp = "csharp",
9
+ Go = "go",
10
+ Ruby = "ruby",
11
+ Rust = "rust",
12
+ PHP = "php",
13
+ Kotlin = "kotlin",
14
+ Swift = "swift"
15
+ }
@@ -0,0 +1,16 @@
1
+ export var SupportedLanguages;
2
+ (function (SupportedLanguages) {
3
+ SupportedLanguages["JavaScript"] = "javascript";
4
+ SupportedLanguages["TypeScript"] = "typescript";
5
+ SupportedLanguages["Python"] = "python";
6
+ SupportedLanguages["Java"] = "java";
7
+ SupportedLanguages["C"] = "c";
8
+ SupportedLanguages["CPlusPlus"] = "cpp";
9
+ SupportedLanguages["CSharp"] = "csharp";
10
+ SupportedLanguages["Go"] = "go";
11
+ SupportedLanguages["Ruby"] = "ruby";
12
+ SupportedLanguages["Rust"] = "rust";
13
+ SupportedLanguages["PHP"] = "php";
14
+ SupportedLanguages["Kotlin"] = "kotlin";
15
+ SupportedLanguages["Swift"] = "swift";
16
+ })(SupportedLanguages || (SupportedLanguages = {}));
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Augmentation Engine
3
+ *
4
+ * Lightweight, fast-path enrichment of search patterns with knowledge graph context.
5
+ * Designed to be called from platform hooks (Claude Code PreToolUse, Cursor beforeShellExecution)
6
+ * when an agent runs grep/glob/search.
7
+ *
8
+ * Performance target: <500ms cold start, <200ms warm.
9
+ *
10
+ * Design decisions:
11
+ * - Uses only BM25 search (no semantic/embedding) for speed
12
+ * - Clusters used internally for ranking, NEVER in output
13
+ * - Output is pure relationships: callers, callees, process participation
14
+ * - Graceful failure: any error → return empty string
15
+ */
16
+ /**
17
+ * Augment a search pattern with knowledge graph context.
18
+ *
19
+ * 1. BM25 search for the pattern
20
+ * 2. For top matches, fetch callers/callees/processes
21
+ * 3. Rank by internal cluster cohesion (not exposed)
22
+ * 4. Format as structured text block
23
+ *
24
+ * Returns empty string on any error (graceful failure).
25
+ */
26
+ export declare function augment(pattern: string, cwd?: string): Promise<string>;
@@ -0,0 +1,240 @@
1
+ /**
2
+ * Augmentation Engine
3
+ *
4
+ * Lightweight, fast-path enrichment of search patterns with knowledge graph context.
5
+ * Designed to be called from platform hooks (Claude Code PreToolUse, Cursor beforeShellExecution)
6
+ * when an agent runs grep/glob/search.
7
+ *
8
+ * Performance target: <500ms cold start, <200ms warm.
9
+ *
10
+ * Design decisions:
11
+ * - Uses only BM25 search (no semantic/embedding) for speed
12
+ * - Clusters used internally for ranking, NEVER in output
13
+ * - Output is pure relationships: callers, callees, process participation
14
+ * - Graceful failure: any error → return empty string
15
+ */
16
+ import path from 'path';
17
+ import { listRegisteredRepos } from '../../storage/repo-manager.js';
18
+ /**
19
+ * Find the best matching repo for a given working directory.
20
+ * Matches by checking if cwd is within the repo's path.
21
+ */
22
+ async function findRepoForCwd(cwd) {
23
+ try {
24
+ const entries = await listRegisteredRepos({ validate: true });
25
+ const resolved = path.resolve(cwd);
26
+ // Normalize to lowercase on Windows (drive letters can differ: D: vs d:)
27
+ const isWindows = process.platform === 'win32';
28
+ const normalizedCwd = isWindows ? resolved.toLowerCase() : resolved;
29
+ const sep = path.sep;
30
+ // Find the LONGEST matching repo path (most specific match wins)
31
+ let bestMatch = null;
32
+ let bestLen = 0;
33
+ for (const entry of entries) {
34
+ const repoResolved = path.resolve(entry.path);
35
+ const normalizedRepo = isWindows ? repoResolved.toLowerCase() : repoResolved;
36
+ // Check if cwd is inside repo OR repo is inside cwd
37
+ // Must match at a path separator boundary to avoid false positives
38
+ // (e.g. /projects/gitnexusv2 should NOT match /projects/gitnexus)
39
+ let matched = false;
40
+ if (normalizedCwd === normalizedRepo) {
41
+ matched = true;
42
+ }
43
+ else if (normalizedCwd.startsWith(normalizedRepo + sep)) {
44
+ matched = true;
45
+ }
46
+ else if (normalizedRepo.startsWith(normalizedCwd + sep)) {
47
+ matched = true;
48
+ }
49
+ if (matched && normalizedRepo.length > bestLen) {
50
+ bestMatch = entry;
51
+ bestLen = normalizedRepo.length;
52
+ }
53
+ }
54
+ if (!bestMatch)
55
+ return null;
56
+ return {
57
+ name: bestMatch.name,
58
+ storagePath: bestMatch.storagePath,
59
+ lbugPath: path.join(bestMatch.storagePath, 'lbug'),
60
+ };
61
+ }
62
+ catch {
63
+ return null;
64
+ }
65
+ }
66
+ /**
67
+ * Augment a search pattern with knowledge graph context.
68
+ *
69
+ * 1. BM25 search for the pattern
70
+ * 2. For top matches, fetch callers/callees/processes
71
+ * 3. Rank by internal cluster cohesion (not exposed)
72
+ * 4. Format as structured text block
73
+ *
74
+ * Returns empty string on any error (graceful failure).
75
+ */
76
+ export async function augment(pattern, cwd) {
77
+ if (!pattern || pattern.length < 3)
78
+ return '';
79
+ const workDir = cwd || process.cwd();
80
+ try {
81
+ const repo = await findRepoForCwd(workDir);
82
+ if (!repo)
83
+ return '';
84
+ // Lazy-load lbug adapter (skip unnecessary init)
85
+ const { initLbug, executeQuery, isLbugReady } = await import('../../mcp/core/lbug-adapter.js');
86
+ const { searchFTSFromLbug } = await import('../search/bm25-index.js');
87
+ const repoId = repo.name.toLowerCase();
88
+ // Init LadybugDB if not already
89
+ if (!isLbugReady(repoId)) {
90
+ await initLbug(repoId, repo.lbugPath);
91
+ }
92
+ // Step 1: BM25 search (fast, no embeddings)
93
+ const bm25Results = await searchFTSFromLbug(pattern, 10, repoId);
94
+ if (bm25Results.length === 0)
95
+ return '';
96
+ // Step 2: Map BM25 file results to symbols
97
+ const symbolMatches = [];
98
+ for (const result of bm25Results.slice(0, 5)) {
99
+ const escaped = result.filePath.replace(/'/g, "''");
100
+ try {
101
+ const symbols = await executeQuery(repoId, `
102
+ MATCH (n) WHERE n.filePath = '${escaped}'
103
+ AND n.name CONTAINS '${pattern.replace(/'/g, "''").split(/\s+/)[0]}'
104
+ RETURN n.id AS id, n.name AS name, labels(n)[0] AS type, n.filePath AS filePath
105
+ LIMIT 3
106
+ `);
107
+ for (const sym of symbols) {
108
+ symbolMatches.push({
109
+ nodeId: sym.id || sym[0],
110
+ name: sym.name || sym[1],
111
+ type: sym.type || sym[2],
112
+ filePath: sym.filePath || sym[3],
113
+ score: result.score,
114
+ });
115
+ }
116
+ }
117
+ catch { /* skip */ }
118
+ }
119
+ if (symbolMatches.length === 0)
120
+ return '';
121
+ // Step 3: Batch-fetch callers/callees/processes/cohesion for top matches
122
+ // Uses batched WHERE n.id IN [...] queries instead of per-symbol queries
123
+ const uniqueSymbols = symbolMatches.slice(0, 5).filter((sym, i, arr) => arr.findIndex(s => s.nodeId === sym.nodeId) === i);
124
+ if (uniqueSymbols.length === 0)
125
+ return '';
126
+ const idList = uniqueSymbols.map(s => `'${s.nodeId.replace(/'/g, "''")}'`).join(', ');
127
+ // Batch fetch callers
128
+ const callersMap = new Map();
129
+ try {
130
+ const rows = await executeQuery(repoId, `
131
+ MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(n)
132
+ WHERE n.id IN [${idList}]
133
+ RETURN n.id AS targetId, caller.name AS name
134
+ LIMIT 15
135
+ `);
136
+ for (const r of rows) {
137
+ const tid = r.targetId || r[0];
138
+ const name = r.name || r[1];
139
+ if (tid && name) {
140
+ if (!callersMap.has(tid))
141
+ callersMap.set(tid, []);
142
+ callersMap.get(tid).push(name);
143
+ }
144
+ }
145
+ }
146
+ catch { /* skip */ }
147
+ // Batch fetch callees
148
+ const calleesMap = new Map();
149
+ try {
150
+ const rows = await executeQuery(repoId, `
151
+ MATCH (n)-[:CodeRelation {type: 'CALLS'}]->(callee)
152
+ WHERE n.id IN [${idList}]
153
+ RETURN n.id AS sourceId, callee.name AS name
154
+ LIMIT 15
155
+ `);
156
+ for (const r of rows) {
157
+ const sid = r.sourceId || r[0];
158
+ const name = r.name || r[1];
159
+ if (sid && name) {
160
+ if (!calleesMap.has(sid))
161
+ calleesMap.set(sid, []);
162
+ calleesMap.get(sid).push(name);
163
+ }
164
+ }
165
+ }
166
+ catch { /* skip */ }
167
+ // Batch fetch processes
168
+ const processesMap = new Map();
169
+ try {
170
+ const rows = await executeQuery(repoId, `
171
+ MATCH (n)-[r:CodeRelation {type: 'STEP_IN_PROCESS'}]->(p:Process)
172
+ WHERE n.id IN [${idList}]
173
+ RETURN n.id AS nodeId, p.heuristicLabel AS label, r.step AS step, p.stepCount AS stepCount
174
+ `);
175
+ for (const r of rows) {
176
+ const nid = r.nodeId || r[0];
177
+ const label = r.label || r[1];
178
+ const step = r.step || r[2];
179
+ const stepCount = r.stepCount || r[3];
180
+ if (nid && label) {
181
+ if (!processesMap.has(nid))
182
+ processesMap.set(nid, []);
183
+ processesMap.get(nid).push(`${label} (step ${step}/${stepCount})`);
184
+ }
185
+ }
186
+ }
187
+ catch { /* skip */ }
188
+ // Batch fetch cohesion
189
+ const cohesionMap = new Map();
190
+ try {
191
+ const rows = await executeQuery(repoId, `
192
+ MATCH (n)-[:CodeRelation {type: 'MEMBER_OF'}]->(c:Community)
193
+ WHERE n.id IN [${idList}]
194
+ RETURN n.id AS nodeId, c.cohesion AS cohesion
195
+ `);
196
+ for (const r of rows) {
197
+ const nid = r.nodeId || r[0];
198
+ const coh = r.cohesion ?? r[1] ?? 0;
199
+ if (nid)
200
+ cohesionMap.set(nid, coh);
201
+ }
202
+ }
203
+ catch { /* skip */ }
204
+ // Assemble enriched results
205
+ const enriched = [];
206
+ for (const sym of uniqueSymbols) {
207
+ enriched.push({
208
+ name: sym.name,
209
+ filePath: sym.filePath,
210
+ callers: (callersMap.get(sym.nodeId) || []).slice(0, 3),
211
+ callees: (calleesMap.get(sym.nodeId) || []).slice(0, 3),
212
+ processes: processesMap.get(sym.nodeId) || [],
213
+ cohesion: cohesionMap.get(sym.nodeId) || 0,
214
+ });
215
+ }
216
+ if (enriched.length === 0)
217
+ return '';
218
+ // Step 4: Rank by cohesion (internal signal) and format
219
+ enriched.sort((a, b) => b.cohesion - a.cohesion);
220
+ const lines = [`[GitNexus] ${enriched.length} related symbols found:`, ''];
221
+ for (const item of enriched) {
222
+ lines.push(`${item.name} (${item.filePath})`);
223
+ if (item.callers.length > 0) {
224
+ lines.push(` Called by: ${item.callers.join(', ')}`);
225
+ }
226
+ if (item.callees.length > 0) {
227
+ lines.push(` Calls: ${item.callees.join(', ')}`);
228
+ }
229
+ if (item.processes.length > 0) {
230
+ lines.push(` Flows: ${item.processes.join(', ')}`);
231
+ }
232
+ lines.push('');
233
+ }
234
+ return lines.join('\n').trim();
235
+ }
236
+ catch {
237
+ // Graceful failure — never break the original tool
238
+ return '';
239
+ }
240
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Embedder Module
3
+ *
4
+ * Singleton factory for transformers.js embedding pipeline.
5
+ * Handles model loading, caching, and both single and batch embedding operations.
6
+ *
7
+ * Uses snowflake-arctic-embed-xs by default (22M params, 384 dims, ~90MB)
8
+ */
9
+ import { type FeatureExtractionPipeline } from '@huggingface/transformers';
10
+ import { type EmbeddingConfig, type ModelProgress } from './types.js';
11
+ /**
12
+ * Progress callback type for model loading
13
+ */
14
+ export type ModelProgressCallback = (progress: ModelProgress) => void;
15
+ /**
16
+ * Get the current device being used for inference
17
+ */
18
+ export declare const getCurrentDevice: () => "dml" | "cuda" | "cpu" | "wasm" | null;
19
+ /**
20
+ * Initialize the embedding model
21
+ * Uses singleton pattern - only loads once, subsequent calls return cached instance
22
+ *
23
+ * @param onProgress - Optional callback for model download progress
24
+ * @param config - Optional configuration override
25
+ * @param forceDevice - Force a specific device
26
+ * @returns Promise resolving to the embedder pipeline
27
+ */
28
+ export declare const initEmbedder: (onProgress?: ModelProgressCallback, config?: Partial<EmbeddingConfig>, forceDevice?: "dml" | "cuda" | "cpu" | "wasm") => Promise<FeatureExtractionPipeline>;
29
+ /**
30
+ * Check if the embedder is initialized and ready
31
+ */
32
+ export declare const isEmbedderReady: () => boolean;
33
+ /**
34
+ * Get the embedder instance (throws if not initialized)
35
+ */
36
+ export declare const getEmbedder: () => FeatureExtractionPipeline;
37
+ /**
38
+ * Embed a single text string
39
+ *
40
+ * @param text - Text to embed
41
+ * @returns Float32Array of embedding vector (384 dimensions)
42
+ */
43
+ export declare const embedText: (text: string) => Promise<Float32Array>;
44
+ /**
45
+ * Embed multiple texts in a single batch
46
+ * More efficient than calling embedText multiple times
47
+ *
48
+ * @param texts - Array of texts to embed
49
+ * @returns Array of Float32Array embedding vectors
50
+ */
51
+ export declare const embedBatch: (texts: string[]) => Promise<Float32Array[]>;
52
+ /**
53
+ * Convert Float32Array to regular number array (for LadybugDB storage)
54
+ */
55
+ export declare const embeddingToArray: (embedding: Float32Array) => number[];
56
+ /**
57
+ * Cleanup the embedder (free memory)
58
+ * Call this when done with embeddings
59
+ */
60
+ export declare const disposeEmbedder: () => Promise<void>;