@rpcajr/smart-graph-indexer 1.0.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 (60) hide show
  1. package/.agents/rules/antigravity-rtk-rules.md +32 -0
  2. package/README.md +116 -0
  3. package/dist/graph.d.ts +32 -0
  4. package/dist/graph.js +86 -0
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.js +227 -0
  7. package/dist/mcp_server.d.ts +48 -0
  8. package/dist/mcp_server.js +433 -0
  9. package/dist/parser.d.ts +42 -0
  10. package/dist/parser.js +529 -0
  11. package/dist/stats.d.ts +43 -0
  12. package/dist/stats.js +146 -0
  13. package/dist/ui.d.ts +2 -0
  14. package/dist/ui.js +1003 -0
  15. package/dist/vector.d.ts +66 -0
  16. package/dist/vector.js +144 -0
  17. package/dist/wasm/tree-sitter-c.wasm +0 -0
  18. package/dist/wasm/tree-sitter-c_sharp.wasm +0 -0
  19. package/dist/wasm/tree-sitter-cpp.wasm +0 -0
  20. package/dist/wasm/tree-sitter-go.wasm +0 -0
  21. package/dist/wasm/tree-sitter-java.wasm +0 -0
  22. package/dist/wasm/tree-sitter-python.wasm +0 -0
  23. package/dist/wasm/tree-sitter-ruby.wasm +0 -0
  24. package/dist/wasm/tree-sitter-rust.wasm +0 -0
  25. package/dist/wasm/tree-sitter-typescript.wasm +0 -0
  26. package/dist/wasm/tree-sitter.wasm +0 -0
  27. package/dist/watcher.d.ts +36 -0
  28. package/dist/watcher.js +166 -0
  29. package/mcp-config-example.json +12 -0
  30. package/mcp_smart_indexer_implementation_spec.md +366 -0
  31. package/package.json +35 -0
  32. package/src/graph.ts +93 -0
  33. package/src/index.ts +216 -0
  34. package/src/mcp_server.ts +454 -0
  35. package/src/parser.ts +484 -0
  36. package/src/stats.ts +156 -0
  37. package/src/ui.ts +956 -0
  38. package/src/vector.ts +166 -0
  39. package/src/watcher.ts +144 -0
  40. package/test_project/App.java +16 -0
  41. package/test_project/BillingService.cs +31 -0
  42. package/test_project/auth.ts +18 -0
  43. package/test_project/config.ts +11 -0
  44. package/test_project/database.ts +21 -0
  45. package/test_project/index.ts +13 -0
  46. package/test_project/main.go +11 -0
  47. package/test_project/main.py +21 -0
  48. package/test_project/processor.py +12 -0
  49. package/test_project/utils.py +13 -0
  50. package/tsconfig.json +16 -0
  51. package/wasm/tree-sitter-c.wasm +0 -0
  52. package/wasm/tree-sitter-c_sharp.wasm +0 -0
  53. package/wasm/tree-sitter-cpp.wasm +0 -0
  54. package/wasm/tree-sitter-go.wasm +0 -0
  55. package/wasm/tree-sitter-java.wasm +0 -0
  56. package/wasm/tree-sitter-python.wasm +0 -0
  57. package/wasm/tree-sitter-ruby.wasm +0 -0
  58. package/wasm/tree-sitter-rust.wasm +0 -0
  59. package/wasm/tree-sitter-typescript.wasm +0 -0
  60. package/wasm/tree-sitter.wasm +0 -0
package/dist/stats.js ADDED
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.StatsManager = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ class StatsManager {
40
+ statsPath;
41
+ stats;
42
+ currentSessionId;
43
+ constructor(projectPath) {
44
+ const mcpDir = path.join(path.resolve(projectPath), '.graph-indexer');
45
+ this.statsPath = path.join(mcpDir, 'stats.json');
46
+ this.currentSessionId = new Date().toISOString();
47
+ this.stats = this.loadStats();
48
+ }
49
+ loadStats() {
50
+ if (fs.existsSync(this.statsPath)) {
51
+ try {
52
+ const raw = fs.readFileSync(this.statsPath, 'utf-8');
53
+ const parsed = JSON.parse(raw);
54
+ if (parsed && parsed.totalCalls !== undefined) {
55
+ if (!parsed.history) {
56
+ parsed.history = [];
57
+ }
58
+ parsed.efficiencyPercentage = parsed.totalTokensAlternative > 0
59
+ ? Math.round((parsed.totalTokensSaved / parsed.totalTokensAlternative) * 100)
60
+ : 0;
61
+ return parsed;
62
+ }
63
+ }
64
+ catch (err) {
65
+ console.error('Failed to load stats, resetting...', err);
66
+ }
67
+ }
68
+ return {
69
+ totalCalls: 0,
70
+ totalTokensSaved: 0,
71
+ totalTokensActual: 0,
72
+ totalTokensAlternative: 0,
73
+ efficiencyPercentage: 0,
74
+ callsByType: {
75
+ search_symbols: { calls: 0, saved: 0, actual: 0, alternative: 0, totalTimeMs: 0 },
76
+ get_file_skeleton: { calls: 0, saved: 0, actual: 0, alternative: 0, totalTimeMs: 0 },
77
+ get_dependencies: { calls: 0, saved: 0, actual: 0, alternative: 0, totalTimeMs: 0 },
78
+ read_symbol_body: { calls: 0, saved: 0, actual: 0, alternative: 0, totalTimeMs: 0 }
79
+ },
80
+ history: []
81
+ };
82
+ }
83
+ saveStats() {
84
+ try {
85
+ const mcpDir = path.dirname(this.statsPath);
86
+ if (!fs.existsSync(mcpDir)) {
87
+ fs.mkdirSync(mcpDir, { recursive: true });
88
+ }
89
+ fs.writeFileSync(this.statsPath, JSON.stringify(this.stats, null, 2), 'utf-8');
90
+ }
91
+ catch (err) {
92
+ console.error('Failed to save stats:', err);
93
+ }
94
+ }
95
+ /**
96
+ * Estimates tokens based on character count (1 token approx 4 characters).
97
+ */
98
+ estimateTokens(text) {
99
+ return Math.ceil(text.length / 4);
100
+ }
101
+ /**
102
+ * Records a tool call and computes the token savings.
103
+ */
104
+ recordCall(toolName, actualPayload, alternativeText, target, execTimeMs = 0) {
105
+ const actualTokens = this.estimateTokens(actualPayload);
106
+ const alternativeTokens = this.estimateTokens(alternativeText);
107
+ const savedTokens = Math.max(0, alternativeTokens - actualTokens);
108
+ this.stats.totalCalls += 1;
109
+ this.stats.totalTokensActual += actualTokens;
110
+ this.stats.totalTokensAlternative += alternativeTokens;
111
+ this.stats.totalTokensSaved += savedTokens;
112
+ // Calculate overall efficiency percentage
113
+ this.stats.efficiencyPercentage = this.stats.totalTokensAlternative > 0
114
+ ? Math.round((this.stats.totalTokensSaved / this.stats.totalTokensAlternative) * 100)
115
+ : 0;
116
+ if (!this.stats.callsByType[toolName]) {
117
+ this.stats.callsByType[toolName] = { calls: 0, saved: 0, actual: 0, alternative: 0, totalTimeMs: 0 };
118
+ }
119
+ const toolStats = this.stats.callsByType[toolName];
120
+ toolStats.calls += 1;
121
+ toolStats.saved += savedTokens;
122
+ toolStats.actual += actualTokens;
123
+ toolStats.alternative += alternativeTokens;
124
+ toolStats.totalTimeMs += execTimeMs;
125
+ // Add entry to history
126
+ this.stats.history.unshift({
127
+ timestamp: new Date().toISOString(),
128
+ sessionId: this.currentSessionId,
129
+ toolName,
130
+ saved: savedTokens,
131
+ actual: actualTokens,
132
+ alternative: alternativeTokens,
133
+ target,
134
+ execTimeMs
135
+ });
136
+ // Cap history to 500 entries to avoid file bloat
137
+ if (this.stats.history.length > 500) {
138
+ this.stats.history = this.stats.history.slice(0, 500);
139
+ }
140
+ this.saveStats();
141
+ }
142
+ getStats() {
143
+ return this.stats;
144
+ }
145
+ }
146
+ exports.StatsManager = StatsManager;
package/dist/ui.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { IndexerEngine } from './mcp_server.js';
2
+ export declare function generateGraphHtml(engine: IndexerEngine): string;