@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.
- package/LICENSE +73 -0
- package/README.md +261 -0
- package/dist/cli/ai-context.d.ts +23 -0
- package/dist/cli/ai-context.js +265 -0
- package/dist/cli/analyze.d.ts +12 -0
- package/dist/cli/analyze.js +345 -0
- package/dist/cli/augment.d.ts +13 -0
- package/dist/cli/augment.js +33 -0
- package/dist/cli/clean.d.ts +10 -0
- package/dist/cli/clean.js +60 -0
- package/dist/cli/eval-server.d.ts +37 -0
- package/dist/cli/eval-server.js +389 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +137 -0
- package/dist/cli/lazy-action.d.ts +6 -0
- package/dist/cli/lazy-action.js +18 -0
- package/dist/cli/list.d.ts +6 -0
- package/dist/cli/list.js +30 -0
- package/dist/cli/mcp.d.ts +8 -0
- package/dist/cli/mcp.js +36 -0
- package/dist/cli/serve.d.ts +4 -0
- package/dist/cli/serve.js +6 -0
- package/dist/cli/setup.d.ts +8 -0
- package/dist/cli/setup.js +367 -0
- package/dist/cli/sipher-patched.d.ts +2 -0
- package/dist/cli/sipher-patched.js +77 -0
- package/dist/cli/skill-gen.d.ts +26 -0
- package/dist/cli/skill-gen.js +549 -0
- package/dist/cli/status.d.ts +6 -0
- package/dist/cli/status.js +36 -0
- package/dist/cli/tool.d.ts +60 -0
- package/dist/cli/tool.js +180 -0
- package/dist/cli/wiki.d.ts +15 -0
- package/dist/cli/wiki.js +365 -0
- package/dist/config/ignore-service.d.ts +26 -0
- package/dist/config/ignore-service.js +284 -0
- package/dist/config/supported-languages.d.ts +15 -0
- package/dist/config/supported-languages.js +16 -0
- package/dist/core/augmentation/engine.d.ts +26 -0
- package/dist/core/augmentation/engine.js +240 -0
- package/dist/core/embeddings/embedder.d.ts +60 -0
- package/dist/core/embeddings/embedder.js +251 -0
- package/dist/core/embeddings/embedding-pipeline.d.ts +51 -0
- package/dist/core/embeddings/embedding-pipeline.js +356 -0
- package/dist/core/embeddings/index.d.ts +9 -0
- package/dist/core/embeddings/index.js +9 -0
- package/dist/core/embeddings/text-generator.d.ts +24 -0
- package/dist/core/embeddings/text-generator.js +182 -0
- package/dist/core/embeddings/types.d.ts +87 -0
- package/dist/core/embeddings/types.js +32 -0
- package/dist/core/graph/graph.d.ts +2 -0
- package/dist/core/graph/graph.js +66 -0
- package/dist/core/graph/types.d.ts +66 -0
- package/dist/core/graph/types.js +1 -0
- package/dist/core/ingestion/ast-cache.d.ts +11 -0
- package/dist/core/ingestion/ast-cache.js +35 -0
- package/dist/core/ingestion/call-processor.d.ts +23 -0
- package/dist/core/ingestion/call-processor.js +793 -0
- package/dist/core/ingestion/call-routing.d.ts +68 -0
- package/dist/core/ingestion/call-routing.js +129 -0
- package/dist/core/ingestion/cluster-enricher.d.ts +38 -0
- package/dist/core/ingestion/cluster-enricher.js +170 -0
- package/dist/core/ingestion/community-processor.d.ts +39 -0
- package/dist/core/ingestion/community-processor.js +312 -0
- package/dist/core/ingestion/constants.d.ts +16 -0
- package/dist/core/ingestion/constants.js +16 -0
- package/dist/core/ingestion/entry-point-scoring.d.ts +40 -0
- package/dist/core/ingestion/entry-point-scoring.js +353 -0
- package/dist/core/ingestion/export-detection.d.ts +18 -0
- package/dist/core/ingestion/export-detection.js +231 -0
- package/dist/core/ingestion/filesystem-walker.d.ts +28 -0
- package/dist/core/ingestion/filesystem-walker.js +81 -0
- package/dist/core/ingestion/framework-detection.d.ts +54 -0
- package/dist/core/ingestion/framework-detection.js +411 -0
- package/dist/core/ingestion/heritage-processor.d.ts +28 -0
- package/dist/core/ingestion/heritage-processor.js +251 -0
- package/dist/core/ingestion/import-processor.d.ts +34 -0
- package/dist/core/ingestion/import-processor.js +398 -0
- package/dist/core/ingestion/language-config.d.ts +46 -0
- package/dist/core/ingestion/language-config.js +167 -0
- package/dist/core/ingestion/mro-processor.d.ts +45 -0
- package/dist/core/ingestion/mro-processor.js +369 -0
- package/dist/core/ingestion/named-binding-extraction.d.ts +61 -0
- package/dist/core/ingestion/named-binding-extraction.js +363 -0
- package/dist/core/ingestion/parsing-processor.d.ts +19 -0
- package/dist/core/ingestion/parsing-processor.js +315 -0
- package/dist/core/ingestion/pipeline.d.ts +6 -0
- package/dist/core/ingestion/pipeline.js +401 -0
- package/dist/core/ingestion/process-processor.d.ts +51 -0
- package/dist/core/ingestion/process-processor.js +315 -0
- package/dist/core/ingestion/resolution-context.d.ts +53 -0
- package/dist/core/ingestion/resolution-context.js +132 -0
- package/dist/core/ingestion/resolvers/csharp.d.ts +22 -0
- package/dist/core/ingestion/resolvers/csharp.js +109 -0
- package/dist/core/ingestion/resolvers/go.d.ts +19 -0
- package/dist/core/ingestion/resolvers/go.js +42 -0
- package/dist/core/ingestion/resolvers/index.d.ts +18 -0
- package/dist/core/ingestion/resolvers/index.js +13 -0
- package/dist/core/ingestion/resolvers/jvm.d.ts +23 -0
- package/dist/core/ingestion/resolvers/jvm.js +87 -0
- package/dist/core/ingestion/resolvers/php.d.ts +15 -0
- package/dist/core/ingestion/resolvers/php.js +35 -0
- package/dist/core/ingestion/resolvers/python.d.ts +19 -0
- package/dist/core/ingestion/resolvers/python.js +52 -0
- package/dist/core/ingestion/resolvers/ruby.d.ts +12 -0
- package/dist/core/ingestion/resolvers/ruby.js +15 -0
- package/dist/core/ingestion/resolvers/rust.d.ts +15 -0
- package/dist/core/ingestion/resolvers/rust.js +73 -0
- package/dist/core/ingestion/resolvers/standard.d.ts +28 -0
- package/dist/core/ingestion/resolvers/standard.js +123 -0
- package/dist/core/ingestion/resolvers/utils.d.ts +33 -0
- package/dist/core/ingestion/resolvers/utils.js +122 -0
- package/dist/core/ingestion/structure-processor.d.ts +2 -0
- package/dist/core/ingestion/structure-processor.js +36 -0
- package/dist/core/ingestion/symbol-table.d.ts +63 -0
- package/dist/core/ingestion/symbol-table.js +85 -0
- package/dist/core/ingestion/tree-sitter-queries.d.ts +15 -0
- package/dist/core/ingestion/tree-sitter-queries.js +888 -0
- package/dist/core/ingestion/type-env.d.ts +49 -0
- package/dist/core/ingestion/type-env.js +613 -0
- package/dist/core/ingestion/type-extractors/c-cpp.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/c-cpp.js +385 -0
- package/dist/core/ingestion/type-extractors/csharp.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/csharp.js +383 -0
- package/dist/core/ingestion/type-extractors/go.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/go.js +467 -0
- package/dist/core/ingestion/type-extractors/index.d.ts +22 -0
- package/dist/core/ingestion/type-extractors/index.js +31 -0
- package/dist/core/ingestion/type-extractors/jvm.d.ts +3 -0
- package/dist/core/ingestion/type-extractors/jvm.js +681 -0
- package/dist/core/ingestion/type-extractors/php.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/php.js +549 -0
- package/dist/core/ingestion/type-extractors/python.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/python.js +455 -0
- package/dist/core/ingestion/type-extractors/ruby.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/ruby.js +389 -0
- package/dist/core/ingestion/type-extractors/rust.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/rust.js +456 -0
- package/dist/core/ingestion/type-extractors/shared.d.ts +145 -0
- package/dist/core/ingestion/type-extractors/shared.js +810 -0
- package/dist/core/ingestion/type-extractors/swift.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/swift.js +137 -0
- package/dist/core/ingestion/type-extractors/types.d.ts +127 -0
- package/dist/core/ingestion/type-extractors/types.js +1 -0
- package/dist/core/ingestion/type-extractors/typescript.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/typescript.js +494 -0
- package/dist/core/ingestion/utils.d.ts +138 -0
- package/dist/core/ingestion/utils.js +1290 -0
- package/dist/core/ingestion/workers/parse-worker.d.ts +122 -0
- package/dist/core/ingestion/workers/parse-worker.js +1126 -0
- package/dist/core/ingestion/workers/worker-pool.d.ts +16 -0
- package/dist/core/ingestion/workers/worker-pool.js +128 -0
- package/dist/core/lbug/csv-generator.d.ts +33 -0
- package/dist/core/lbug/csv-generator.js +366 -0
- package/dist/core/lbug/lbug-adapter.d.ts +103 -0
- package/dist/core/lbug/lbug-adapter.js +769 -0
- package/dist/core/lbug/schema.d.ts +53 -0
- package/dist/core/lbug/schema.js +430 -0
- package/dist/core/search/bm25-index.d.ts +23 -0
- package/dist/core/search/bm25-index.js +96 -0
- package/dist/core/search/hybrid-search.d.ts +49 -0
- package/dist/core/search/hybrid-search.js +118 -0
- package/dist/core/tree-sitter/parser-loader.d.ts +5 -0
- package/dist/core/tree-sitter/parser-loader.js +63 -0
- package/dist/core/wiki/generator.d.ts +120 -0
- package/dist/core/wiki/generator.js +939 -0
- package/dist/core/wiki/graph-queries.d.ts +80 -0
- package/dist/core/wiki/graph-queries.js +238 -0
- package/dist/core/wiki/html-viewer.d.ts +10 -0
- package/dist/core/wiki/html-viewer.js +297 -0
- package/dist/core/wiki/llm-client.d.ts +43 -0
- package/dist/core/wiki/llm-client.js +186 -0
- package/dist/core/wiki/prompts.d.ts +53 -0
- package/dist/core/wiki/prompts.js +174 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.js +3 -0
- package/dist/mcp/compatible-stdio-transport.d.ts +25 -0
- package/dist/mcp/compatible-stdio-transport.js +200 -0
- package/dist/mcp/core/embedder.d.ts +27 -0
- package/dist/mcp/core/embedder.js +108 -0
- package/dist/mcp/core/lbug-adapter.d.ts +57 -0
- package/dist/mcp/core/lbug-adapter.js +455 -0
- package/dist/mcp/local/local-backend.d.ts +181 -0
- package/dist/mcp/local/local-backend.js +1722 -0
- package/dist/mcp/resources.d.ts +31 -0
- package/dist/mcp/resources.js +411 -0
- package/dist/mcp/server.d.ts +23 -0
- package/dist/mcp/server.js +296 -0
- package/dist/mcp/staleness.d.ts +15 -0
- package/dist/mcp/staleness.js +29 -0
- package/dist/mcp/tools.d.ts +24 -0
- package/dist/mcp/tools.js +292 -0
- package/dist/server/api.d.ts +10 -0
- package/dist/server/api.js +344 -0
- package/dist/server/mcp-http.d.ts +13 -0
- package/dist/server/mcp-http.js +100 -0
- package/dist/storage/git.d.ts +6 -0
- package/dist/storage/git.js +35 -0
- package/dist/storage/repo-manager.d.ts +138 -0
- package/dist/storage/repo-manager.js +299 -0
- package/dist/types/pipeline.d.ts +32 -0
- package/dist/types/pipeline.js +18 -0
- package/dist/unreal/bridge.d.ts +4 -0
- package/dist/unreal/bridge.js +113 -0
- package/dist/unreal/config.d.ts +6 -0
- package/dist/unreal/config.js +55 -0
- package/dist/unreal/types.d.ts +105 -0
- package/dist/unreal/types.js +1 -0
- package/hooks/claude/gitnexus-hook.cjs +238 -0
- package/hooks/claude/pre-tool-use.sh +79 -0
- package/hooks/claude/session-start.sh +42 -0
- package/package.json +100 -0
- package/scripts/ensure-cli-executable.cjs +21 -0
- package/scripts/patch-tree-sitter-swift.cjs +74 -0
- package/scripts/setup-unreal-gitnexus.ps1 +191 -0
- package/skills/gitnexus-cli.md +82 -0
- package/skills/gitnexus-debugging.md +89 -0
- package/skills/gitnexus-exploring.md +78 -0
- package/skills/gitnexus-guide.md +64 -0
- package/skills/gitnexus-impact-analysis.md +97 -0
- package/skills/gitnexus-pr-review.md +163 -0
- package/skills/gitnexus-refactoring.md +121 -0
- package/vendor/leiden/index.cjs +355 -0
- package/vendor/leiden/utils.cjs +392 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analyze Command
|
|
3
|
+
*
|
|
4
|
+
* Indexes a repository and stores the knowledge graph in .gitnexus/
|
|
5
|
+
*/
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { execFileSync } from 'child_process';
|
|
8
|
+
import v8 from 'v8';
|
|
9
|
+
import cliProgress from 'cli-progress';
|
|
10
|
+
import { runPipelineFromRepo } from '../core/ingestion/pipeline.js';
|
|
11
|
+
import { initLbug, loadGraphToLbug, getLbugStats, executeQuery, executeWithReusedStatement, closeLbug, createFTSIndex, loadCachedEmbeddings } from '../core/lbug/lbug-adapter.js';
|
|
12
|
+
// Embedding imports are lazy (dynamic import) so onnxruntime-node is never
|
|
13
|
+
// loaded when embeddings are not requested. This avoids crashes on Node
|
|
14
|
+
// versions whose ABI is not yet supported by the native binary (#89).
|
|
15
|
+
// disposeEmbedder intentionally not called — ONNX Runtime segfaults on cleanup (see #38)
|
|
16
|
+
import { getStoragePaths, saveMeta, loadMeta, addToGitignore, registerRepo, getGlobalRegistryPath, cleanupOldKuzuFiles } from '../storage/repo-manager.js';
|
|
17
|
+
import { getCurrentCommit, isGitRepo, getGitRoot } from '../storage/git.js';
|
|
18
|
+
import { generateAIContextFiles } from './ai-context.js';
|
|
19
|
+
import { generateSkillFiles } from './skill-gen.js';
|
|
20
|
+
import fs from 'fs/promises';
|
|
21
|
+
const HEAP_MB = 8192;
|
|
22
|
+
const HEAP_FLAG = `--max-old-space-size=${HEAP_MB}`;
|
|
23
|
+
/** Re-exec the process with an 8GB heap if we're currently below that. */
|
|
24
|
+
function ensureHeap() {
|
|
25
|
+
const nodeOpts = process.env.NODE_OPTIONS || '';
|
|
26
|
+
if (nodeOpts.includes('--max-old-space-size'))
|
|
27
|
+
return false;
|
|
28
|
+
const v8Heap = v8.getHeapStatistics().heap_size_limit;
|
|
29
|
+
if (v8Heap >= HEAP_MB * 1024 * 1024 * 0.9)
|
|
30
|
+
return false;
|
|
31
|
+
try {
|
|
32
|
+
execFileSync(process.execPath, [HEAP_FLAG, ...process.argv.slice(1)], {
|
|
33
|
+
stdio: 'inherit',
|
|
34
|
+
env: { ...process.env, NODE_OPTIONS: `${nodeOpts} ${HEAP_FLAG}`.trim() },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
process.exitCode = e.status ?? 1;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
/** Threshold: auto-skip embeddings for repos with more nodes than this */
|
|
43
|
+
const EMBEDDING_NODE_LIMIT = 50_000;
|
|
44
|
+
const PHASE_LABELS = {
|
|
45
|
+
extracting: 'Scanning files',
|
|
46
|
+
structure: 'Building structure',
|
|
47
|
+
parsing: 'Parsing code',
|
|
48
|
+
imports: 'Resolving imports',
|
|
49
|
+
calls: 'Tracing calls',
|
|
50
|
+
heritage: 'Extracting inheritance',
|
|
51
|
+
communities: 'Detecting communities',
|
|
52
|
+
processes: 'Detecting processes',
|
|
53
|
+
complete: 'Pipeline complete',
|
|
54
|
+
lbug: 'Loading into LadybugDB',
|
|
55
|
+
fts: 'Creating search indexes',
|
|
56
|
+
embeddings: 'Generating embeddings',
|
|
57
|
+
done: 'Done',
|
|
58
|
+
};
|
|
59
|
+
export const analyzeCommand = async (inputPath, options) => {
|
|
60
|
+
if (ensureHeap())
|
|
61
|
+
return;
|
|
62
|
+
if (options?.verbose) {
|
|
63
|
+
process.env.GITNEXUS_VERBOSE = '1';
|
|
64
|
+
}
|
|
65
|
+
console.log('\n GitNexus Analyzer\n');
|
|
66
|
+
let repoPath;
|
|
67
|
+
if (inputPath) {
|
|
68
|
+
repoPath = path.resolve(inputPath);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const gitRoot = getGitRoot(process.cwd());
|
|
72
|
+
if (!gitRoot) {
|
|
73
|
+
console.log(' Not inside a git repository\n');
|
|
74
|
+
process.exitCode = 1;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
repoPath = gitRoot;
|
|
78
|
+
}
|
|
79
|
+
if (!isGitRepo(repoPath)) {
|
|
80
|
+
console.log(' Not a git repository\n');
|
|
81
|
+
process.exitCode = 1;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const { storagePath, lbugPath } = getStoragePaths(repoPath);
|
|
85
|
+
// Clean up stale KuzuDB files from before the LadybugDB migration.
|
|
86
|
+
// If kuzu existed but lbug doesn't, we're doing a migration re-index — say so.
|
|
87
|
+
const kuzuResult = await cleanupOldKuzuFiles(storagePath);
|
|
88
|
+
if (kuzuResult.found && kuzuResult.needsReindex) {
|
|
89
|
+
console.log(' Migrating from KuzuDB to LadybugDB — rebuilding index...\n');
|
|
90
|
+
}
|
|
91
|
+
const currentCommit = getCurrentCommit(repoPath);
|
|
92
|
+
const existingMeta = await loadMeta(storagePath);
|
|
93
|
+
if (existingMeta && !options?.force && !options?.skills && existingMeta.lastCommit === currentCommit) {
|
|
94
|
+
console.log(' Already up to date\n');
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (process.env.GITNEXUS_NO_GITIGNORE) {
|
|
98
|
+
console.log(' GITNEXUS_NO_GITIGNORE is set — skipping .gitignore (still reading .gitnexusignore)\n');
|
|
99
|
+
}
|
|
100
|
+
// Single progress bar for entire pipeline
|
|
101
|
+
const bar = new cliProgress.SingleBar({
|
|
102
|
+
format: ' {bar} {percentage}% | {phase}',
|
|
103
|
+
barCompleteChar: '\u2588',
|
|
104
|
+
barIncompleteChar: '\u2591',
|
|
105
|
+
hideCursor: true,
|
|
106
|
+
barGlue: '',
|
|
107
|
+
autopadding: true,
|
|
108
|
+
clearOnComplete: false,
|
|
109
|
+
stopOnComplete: false,
|
|
110
|
+
}, cliProgress.Presets.shades_grey);
|
|
111
|
+
bar.start(100, 0, { phase: 'Initializing...' });
|
|
112
|
+
// Graceful SIGINT handling — clean up resources and exit
|
|
113
|
+
let aborted = false;
|
|
114
|
+
const sigintHandler = () => {
|
|
115
|
+
if (aborted)
|
|
116
|
+
process.exit(1); // Second Ctrl-C: force exit
|
|
117
|
+
aborted = true;
|
|
118
|
+
bar.stop();
|
|
119
|
+
console.log('\n Interrupted — cleaning up...');
|
|
120
|
+
closeLbug().catch(() => { }).finally(() => process.exit(130));
|
|
121
|
+
};
|
|
122
|
+
process.on('SIGINT', sigintHandler);
|
|
123
|
+
// Route all console output through bar.log() so the bar doesn't stamp itself
|
|
124
|
+
// multiple times when other code writes to stdout/stderr mid-render.
|
|
125
|
+
const origLog = console.log.bind(console);
|
|
126
|
+
const origWarn = console.warn.bind(console);
|
|
127
|
+
const origError = console.error.bind(console);
|
|
128
|
+
const barLog = (...args) => {
|
|
129
|
+
// Clear the bar line, print the message, then let the next bar.update redraw
|
|
130
|
+
process.stdout.write('\x1b[2K\r');
|
|
131
|
+
origLog(args.map(a => (typeof a === 'string' ? a : String(a))).join(' '));
|
|
132
|
+
};
|
|
133
|
+
console.log = barLog;
|
|
134
|
+
console.warn = barLog;
|
|
135
|
+
console.error = barLog;
|
|
136
|
+
// Track elapsed time per phase — both updateBar and the interval use the
|
|
137
|
+
// same format so they don't flicker against each other.
|
|
138
|
+
let lastPhaseLabel = 'Initializing...';
|
|
139
|
+
let phaseStart = Date.now();
|
|
140
|
+
/** Update bar with phase label + elapsed seconds (shown after 3s). */
|
|
141
|
+
const updateBar = (value, phaseLabel) => {
|
|
142
|
+
if (phaseLabel !== lastPhaseLabel) {
|
|
143
|
+
lastPhaseLabel = phaseLabel;
|
|
144
|
+
phaseStart = Date.now();
|
|
145
|
+
}
|
|
146
|
+
const elapsed = Math.round((Date.now() - phaseStart) / 1000);
|
|
147
|
+
const display = elapsed >= 3 ? `${phaseLabel} (${elapsed}s)` : phaseLabel;
|
|
148
|
+
bar.update(value, { phase: display });
|
|
149
|
+
};
|
|
150
|
+
// Tick elapsed seconds for phases with infrequent progress callbacks
|
|
151
|
+
// (e.g. CSV streaming, FTS indexing). Uses the same display format as
|
|
152
|
+
// updateBar so there's no flickering.
|
|
153
|
+
const elapsedTimer = setInterval(() => {
|
|
154
|
+
const elapsed = Math.round((Date.now() - phaseStart) / 1000);
|
|
155
|
+
if (elapsed >= 3) {
|
|
156
|
+
bar.update({ phase: `${lastPhaseLabel} (${elapsed}s)` });
|
|
157
|
+
}
|
|
158
|
+
}, 1000);
|
|
159
|
+
const t0Global = Date.now();
|
|
160
|
+
// ── Cache embeddings from existing index before rebuild ────────────
|
|
161
|
+
let cachedEmbeddingNodeIds = new Set();
|
|
162
|
+
let cachedEmbeddings = [];
|
|
163
|
+
if (options?.embeddings && existingMeta && !options?.force) {
|
|
164
|
+
try {
|
|
165
|
+
updateBar(0, 'Caching embeddings...');
|
|
166
|
+
await initLbug(lbugPath);
|
|
167
|
+
const cached = await loadCachedEmbeddings();
|
|
168
|
+
cachedEmbeddingNodeIds = cached.embeddingNodeIds;
|
|
169
|
+
cachedEmbeddings = cached.embeddings;
|
|
170
|
+
await closeLbug();
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
try {
|
|
174
|
+
await closeLbug();
|
|
175
|
+
}
|
|
176
|
+
catch { }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// ── Phase 1: Full Pipeline (0–60%) ─────────────────────────────────
|
|
180
|
+
const pipelineResult = await runPipelineFromRepo(repoPath, (progress) => {
|
|
181
|
+
const phaseLabel = PHASE_LABELS[progress.phase] || progress.phase;
|
|
182
|
+
const scaled = Math.round(progress.percent * 0.6);
|
|
183
|
+
updateBar(scaled, phaseLabel);
|
|
184
|
+
});
|
|
185
|
+
// ── Phase 2: LadybugDB (60–85%) ──────────────────────────────────────
|
|
186
|
+
updateBar(60, 'Loading into LadybugDB...');
|
|
187
|
+
await closeLbug();
|
|
188
|
+
const lbugFiles = [lbugPath, `${lbugPath}.wal`, `${lbugPath}.lock`];
|
|
189
|
+
for (const f of lbugFiles) {
|
|
190
|
+
try {
|
|
191
|
+
await fs.rm(f, { recursive: true, force: true });
|
|
192
|
+
}
|
|
193
|
+
catch { }
|
|
194
|
+
}
|
|
195
|
+
const t0Lbug = Date.now();
|
|
196
|
+
await initLbug(lbugPath);
|
|
197
|
+
let lbugMsgCount = 0;
|
|
198
|
+
const lbugResult = await loadGraphToLbug(pipelineResult.graph, pipelineResult.repoPath, storagePath, (msg) => {
|
|
199
|
+
lbugMsgCount++;
|
|
200
|
+
const progress = Math.min(84, 60 + Math.round((lbugMsgCount / (lbugMsgCount + 10)) * 24));
|
|
201
|
+
updateBar(progress, msg);
|
|
202
|
+
});
|
|
203
|
+
const lbugTime = ((Date.now() - t0Lbug) / 1000).toFixed(1);
|
|
204
|
+
const lbugWarnings = lbugResult.warnings;
|
|
205
|
+
// ── Phase 3: FTS (85–90%) ─────────────────────────────────────────
|
|
206
|
+
updateBar(85, 'Creating search indexes...');
|
|
207
|
+
const t0Fts = Date.now();
|
|
208
|
+
try {
|
|
209
|
+
await createFTSIndex('File', 'file_fts', ['name', 'content']);
|
|
210
|
+
await createFTSIndex('Function', 'function_fts', ['name', 'content']);
|
|
211
|
+
await createFTSIndex('Class', 'class_fts', ['name', 'content']);
|
|
212
|
+
await createFTSIndex('Method', 'method_fts', ['name', 'content']);
|
|
213
|
+
await createFTSIndex('Interface', 'interface_fts', ['name', 'content']);
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
// Non-fatal — FTS is best-effort
|
|
217
|
+
}
|
|
218
|
+
const ftsTime = ((Date.now() - t0Fts) / 1000).toFixed(1);
|
|
219
|
+
// ── Phase 3.5: Re-insert cached embeddings ────────────────────────
|
|
220
|
+
if (cachedEmbeddings.length > 0) {
|
|
221
|
+
updateBar(88, `Restoring ${cachedEmbeddings.length} cached embeddings...`);
|
|
222
|
+
const EMBED_BATCH = 200;
|
|
223
|
+
for (let i = 0; i < cachedEmbeddings.length; i += EMBED_BATCH) {
|
|
224
|
+
const batch = cachedEmbeddings.slice(i, i + EMBED_BATCH);
|
|
225
|
+
const paramsList = batch.map(e => ({ nodeId: e.nodeId, embedding: e.embedding }));
|
|
226
|
+
try {
|
|
227
|
+
await executeWithReusedStatement(`CREATE (e:CodeEmbedding {nodeId: $nodeId, embedding: $embedding})`, paramsList);
|
|
228
|
+
}
|
|
229
|
+
catch { /* some may fail if node was removed, that's fine */ }
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// ── Phase 4: Embeddings (90–98%) ──────────────────────────────────
|
|
233
|
+
const stats = await getLbugStats();
|
|
234
|
+
let embeddingTime = '0.0';
|
|
235
|
+
let embeddingSkipped = true;
|
|
236
|
+
let embeddingSkipReason = 'off (use --embeddings to enable)';
|
|
237
|
+
if (options?.embeddings) {
|
|
238
|
+
if (stats.nodes > EMBEDDING_NODE_LIMIT) {
|
|
239
|
+
embeddingSkipReason = `skipped (${stats.nodes.toLocaleString()} nodes > ${EMBEDDING_NODE_LIMIT.toLocaleString()} limit)`;
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
embeddingSkipped = false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (!embeddingSkipped) {
|
|
246
|
+
updateBar(90, 'Loading embedding model...');
|
|
247
|
+
const t0Emb = Date.now();
|
|
248
|
+
const { runEmbeddingPipeline } = await import('../core/embeddings/embedding-pipeline.js');
|
|
249
|
+
await runEmbeddingPipeline(executeQuery, executeWithReusedStatement, (progress) => {
|
|
250
|
+
const scaled = 90 + Math.round((progress.percent / 100) * 8);
|
|
251
|
+
const label = progress.phase === 'loading-model' ? 'Loading embedding model...' : `Embedding ${progress.nodesProcessed || 0}/${progress.totalNodes || '?'}`;
|
|
252
|
+
updateBar(scaled, label);
|
|
253
|
+
}, {}, cachedEmbeddingNodeIds.size > 0 ? cachedEmbeddingNodeIds : undefined);
|
|
254
|
+
embeddingTime = ((Date.now() - t0Emb) / 1000).toFixed(1);
|
|
255
|
+
}
|
|
256
|
+
// ── Phase 5: Finalize (98–100%) ───────────────────────────────────
|
|
257
|
+
updateBar(98, 'Saving metadata...');
|
|
258
|
+
// Count embeddings in the index (cached + newly generated)
|
|
259
|
+
let embeddingCount = 0;
|
|
260
|
+
try {
|
|
261
|
+
const embResult = await executeQuery(`MATCH (e:CodeEmbedding) RETURN count(e) AS cnt`);
|
|
262
|
+
embeddingCount = embResult?.[0]?.cnt ?? 0;
|
|
263
|
+
}
|
|
264
|
+
catch { /* table may not exist if embeddings never ran */ }
|
|
265
|
+
const meta = {
|
|
266
|
+
repoPath,
|
|
267
|
+
lastCommit: currentCommit,
|
|
268
|
+
indexedAt: new Date().toISOString(),
|
|
269
|
+
stats: {
|
|
270
|
+
files: pipelineResult.totalFileCount,
|
|
271
|
+
nodes: stats.nodes,
|
|
272
|
+
edges: stats.edges,
|
|
273
|
+
communities: pipelineResult.communityResult?.stats.totalCommunities,
|
|
274
|
+
processes: pipelineResult.processResult?.stats.totalProcesses,
|
|
275
|
+
embeddings: embeddingCount,
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
await saveMeta(storagePath, meta);
|
|
279
|
+
await registerRepo(repoPath, meta);
|
|
280
|
+
await addToGitignore(repoPath);
|
|
281
|
+
const projectName = path.basename(repoPath);
|
|
282
|
+
let aggregatedClusterCount = 0;
|
|
283
|
+
if (pipelineResult.communityResult?.communities) {
|
|
284
|
+
const groups = new Map();
|
|
285
|
+
for (const c of pipelineResult.communityResult.communities) {
|
|
286
|
+
const label = c.heuristicLabel || c.label || 'Unknown';
|
|
287
|
+
groups.set(label, (groups.get(label) || 0) + c.symbolCount);
|
|
288
|
+
}
|
|
289
|
+
aggregatedClusterCount = Array.from(groups.values()).filter(count => count >= 5).length;
|
|
290
|
+
}
|
|
291
|
+
let generatedSkills = [];
|
|
292
|
+
if (options?.skills && pipelineResult.communityResult) {
|
|
293
|
+
updateBar(99, 'Generating skill files...');
|
|
294
|
+
const skillResult = await generateSkillFiles(repoPath, projectName, pipelineResult);
|
|
295
|
+
generatedSkills = skillResult.skills;
|
|
296
|
+
}
|
|
297
|
+
const aiContext = await generateAIContextFiles(repoPath, storagePath, projectName, {
|
|
298
|
+
files: pipelineResult.totalFileCount,
|
|
299
|
+
nodes: stats.nodes,
|
|
300
|
+
edges: stats.edges,
|
|
301
|
+
communities: pipelineResult.communityResult?.stats.totalCommunities,
|
|
302
|
+
clusters: aggregatedClusterCount,
|
|
303
|
+
processes: pipelineResult.processResult?.stats.totalProcesses,
|
|
304
|
+
}, generatedSkills);
|
|
305
|
+
await closeLbug();
|
|
306
|
+
// Note: we intentionally do NOT call disposeEmbedder() here.
|
|
307
|
+
// ONNX Runtime's native cleanup segfaults on macOS and some Linux configs.
|
|
308
|
+
// Since the process exits immediately after, Node.js reclaims everything.
|
|
309
|
+
const totalTime = ((Date.now() - t0Global) / 1000).toFixed(1);
|
|
310
|
+
clearInterval(elapsedTimer);
|
|
311
|
+
process.removeListener('SIGINT', sigintHandler);
|
|
312
|
+
console.log = origLog;
|
|
313
|
+
console.warn = origWarn;
|
|
314
|
+
console.error = origError;
|
|
315
|
+
bar.update(100, { phase: 'Done' });
|
|
316
|
+
bar.stop();
|
|
317
|
+
// ── Summary ───────────────────────────────────────────────────────
|
|
318
|
+
const embeddingsCached = cachedEmbeddings.length > 0;
|
|
319
|
+
console.log(`\n Repository indexed successfully (${totalTime}s)${embeddingsCached ? ` [${cachedEmbeddings.length} embeddings cached]` : ''}\n`);
|
|
320
|
+
console.log(` ${stats.nodes.toLocaleString()} nodes | ${stats.edges.toLocaleString()} edges | ${pipelineResult.communityResult?.stats.totalCommunities || 0} clusters | ${pipelineResult.processResult?.stats.totalProcesses || 0} flows`);
|
|
321
|
+
console.log(` LadybugDB ${lbugTime}s | FTS ${ftsTime}s | Embeddings ${embeddingSkipped ? embeddingSkipReason : embeddingTime + 's'}`);
|
|
322
|
+
console.log(` ${repoPath}`);
|
|
323
|
+
if (aiContext.files.length > 0) {
|
|
324
|
+
console.log(` Context: ${aiContext.files.join(', ')}`);
|
|
325
|
+
}
|
|
326
|
+
// Show a quiet summary if some edge types needed fallback insertion
|
|
327
|
+
if (lbugWarnings.length > 0) {
|
|
328
|
+
const totalFallback = lbugWarnings.reduce((sum, w) => {
|
|
329
|
+
const m = w.match(/\((\d+) edges\)/);
|
|
330
|
+
return sum + (m ? parseInt(m[1]) : 0);
|
|
331
|
+
}, 0);
|
|
332
|
+
console.log(` Note: ${totalFallback} edges across ${lbugWarnings.length} types inserted via fallback (schema will be updated in next release)`);
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
await fs.access(getGlobalRegistryPath());
|
|
336
|
+
}
|
|
337
|
+
catch {
|
|
338
|
+
console.log('\n Tip: Run `gitnexus setup` to configure MCP for your editor.');
|
|
339
|
+
}
|
|
340
|
+
console.log('');
|
|
341
|
+
// LadybugDB's native module holds open handles that prevent Node from exiting.
|
|
342
|
+
// ONNX Runtime also registers native atexit hooks that segfault on some
|
|
343
|
+
// platforms (#38, #40). Force-exit to ensure clean termination.
|
|
344
|
+
process.exit(0);
|
|
345
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augment CLI Command
|
|
3
|
+
*
|
|
4
|
+
* Fast-path command for platform hooks.
|
|
5
|
+
* Shells out from Claude Code PreToolUse / Cursor beforeShellExecution hooks.
|
|
6
|
+
*
|
|
7
|
+
* Usage: gitnexus augment <pattern>
|
|
8
|
+
* Returns enriched text to stdout.
|
|
9
|
+
*
|
|
10
|
+
* Performance: Must cold-start fast (<500ms).
|
|
11
|
+
* Skips unnecessary initialization (no web server, no full DB warmup).
|
|
12
|
+
*/
|
|
13
|
+
export declare function augmentCommand(pattern: string): Promise<void>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augment CLI Command
|
|
3
|
+
*
|
|
4
|
+
* Fast-path command for platform hooks.
|
|
5
|
+
* Shells out from Claude Code PreToolUse / Cursor beforeShellExecution hooks.
|
|
6
|
+
*
|
|
7
|
+
* Usage: gitnexus augment <pattern>
|
|
8
|
+
* Returns enriched text to stdout.
|
|
9
|
+
*
|
|
10
|
+
* Performance: Must cold-start fast (<500ms).
|
|
11
|
+
* Skips unnecessary initialization (no web server, no full DB warmup).
|
|
12
|
+
*/
|
|
13
|
+
import { augment } from '../core/augmentation/engine.js';
|
|
14
|
+
export async function augmentCommand(pattern) {
|
|
15
|
+
if (!pattern || pattern.length < 3) {
|
|
16
|
+
process.exit(0);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const result = await augment(pattern, process.cwd());
|
|
20
|
+
if (result) {
|
|
21
|
+
// IMPORTANT: Write to stderr, NOT stdout.
|
|
22
|
+
// LadybugDB's native module captures stdout fd at OS level during init,
|
|
23
|
+
// which makes stdout permanently broken in subprocess contexts.
|
|
24
|
+
// stderr is never captured, so it works reliably everywhere.
|
|
25
|
+
// The hook reads from the subprocess's stderr.
|
|
26
|
+
process.stderr.write(result + '\n');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Graceful failure — never break the calling hook
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clean Command
|
|
3
|
+
*
|
|
4
|
+
* Removes the .gitnexus index from the current repository.
|
|
5
|
+
* Also unregisters it from the global registry.
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'fs/promises';
|
|
8
|
+
import { findRepo, unregisterRepo, listRegisteredRepos } from '../storage/repo-manager.js';
|
|
9
|
+
export const cleanCommand = async (options) => {
|
|
10
|
+
// --all flag: clean all indexed repos
|
|
11
|
+
if (options?.all) {
|
|
12
|
+
if (!options?.force) {
|
|
13
|
+
const entries = await listRegisteredRepos();
|
|
14
|
+
if (entries.length === 0) {
|
|
15
|
+
console.log('No indexed repositories found.');
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
console.log(`This will delete GitNexus indexes for ${entries.length} repo(s):`);
|
|
19
|
+
for (const entry of entries) {
|
|
20
|
+
console.log(` - ${entry.name} (${entry.path})`);
|
|
21
|
+
}
|
|
22
|
+
console.log('\nRun with --force to confirm deletion.');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const entries = await listRegisteredRepos();
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
try {
|
|
28
|
+
await fs.rm(entry.storagePath, { recursive: true, force: true });
|
|
29
|
+
await unregisterRepo(entry.path);
|
|
30
|
+
console.log(`Deleted: ${entry.name} (${entry.storagePath})`);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
console.error(`Failed to delete ${entry.name}:`, err);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
// Default: clean current repo
|
|
39
|
+
const cwd = process.cwd();
|
|
40
|
+
const repo = await findRepo(cwd);
|
|
41
|
+
if (!repo) {
|
|
42
|
+
console.log('No indexed repository found in this directory.');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const repoName = repo.repoPath.split(/[/\\]/).pop() || repo.repoPath;
|
|
46
|
+
if (!options?.force) {
|
|
47
|
+
console.log(`This will delete the GitNexus index for: ${repoName}`);
|
|
48
|
+
console.log(` Path: ${repo.storagePath}`);
|
|
49
|
+
console.log('\nRun with --force to confirm deletion.');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
await fs.rm(repo.storagePath, { recursive: true, force: true });
|
|
54
|
+
await unregisterRepo(repo.repoPath);
|
|
55
|
+
console.log(`Deleted: ${repo.storagePath}`);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
console.error('Failed to delete:', err);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eval Server — Lightweight HTTP server for SWE-bench evaluation
|
|
3
|
+
*
|
|
4
|
+
* Keeps LadybugDB warm in memory so tool calls from the agent are near-instant.
|
|
5
|
+
* Designed to run inside Docker containers during SWE-bench evaluation.
|
|
6
|
+
*
|
|
7
|
+
* KEY DESIGN: Returns LLM-friendly text, not raw JSON.
|
|
8
|
+
* Raw JSON wastes tokens and is hard for models to parse. The text formatter
|
|
9
|
+
* converts structured results into compact, readable output that models
|
|
10
|
+
* can immediately act on. Next-step hints guide the agent through a
|
|
11
|
+
* productive tool-chaining workflow (query → context → impact → fix).
|
|
12
|
+
*
|
|
13
|
+
* Architecture:
|
|
14
|
+
* Agent bash cmd → curl localhost:PORT/tool/query → eval-server → LocalBackend → format → text
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* gitnexus eval-server # default port 4848
|
|
18
|
+
* gitnexus eval-server --port 4848 # explicit port
|
|
19
|
+
* gitnexus eval-server --idle-timeout 300 # auto-shutdown after 300s idle
|
|
20
|
+
*
|
|
21
|
+
* API:
|
|
22
|
+
* POST /tool/:name — Call a tool. Body is JSON arguments. Returns formatted text.
|
|
23
|
+
* GET /health — Health check. Returns {"status":"ok","repos":[...]}
|
|
24
|
+
* POST /shutdown — Graceful shutdown.
|
|
25
|
+
*/
|
|
26
|
+
export interface EvalServerOptions {
|
|
27
|
+
port?: string;
|
|
28
|
+
idleTimeout?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function formatQueryResult(result: any): string;
|
|
31
|
+
export declare function formatContextResult(result: any): string;
|
|
32
|
+
export declare function formatImpactResult(result: any): string;
|
|
33
|
+
export declare function formatCypherResult(result: any): string;
|
|
34
|
+
export declare function formatDetectChangesResult(result: any): string;
|
|
35
|
+
export declare function formatListReposResult(result: any): string;
|
|
36
|
+
export declare function evalServerCommand(options?: EvalServerOptions): Promise<void>;
|
|
37
|
+
export declare const MAX_BODY_SIZE: number;
|