ruvector 0.1.62 → 0.1.64

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.
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ /**
3
+ * Cluster Wrapper - Distributed coordination for multi-agent systems
4
+ *
5
+ * Wraps @ruvector/cluster for Raft consensus, auto-sharding,
6
+ * and distributed memory across agents.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.RuvectorCluster = void 0;
10
+ exports.isClusterAvailable = isClusterAvailable;
11
+ exports.createCluster = createCluster;
12
+ let clusterModule = null;
13
+ let loadError = null;
14
+ function getClusterModule() {
15
+ if (clusterModule)
16
+ return clusterModule;
17
+ if (loadError)
18
+ throw loadError;
19
+ try {
20
+ clusterModule = require('@ruvector/cluster');
21
+ return clusterModule;
22
+ }
23
+ catch (e) {
24
+ loadError = new Error(`@ruvector/cluster not installed: ${e.message}\n` +
25
+ `Install with: npm install @ruvector/cluster`);
26
+ throw loadError;
27
+ }
28
+ }
29
+ function isClusterAvailable() {
30
+ try {
31
+ getClusterModule();
32
+ return true;
33
+ }
34
+ catch {
35
+ return false;
36
+ }
37
+ }
38
+ /**
39
+ * Distributed cluster for multi-agent coordination
40
+ */
41
+ class RuvectorCluster {
42
+ constructor(config) {
43
+ this.isLeader = false;
44
+ const cluster = getClusterModule();
45
+ this.nodeId = config.nodeId;
46
+ this.inner = new cluster.Cluster({
47
+ nodeId: config.nodeId,
48
+ address: config.address,
49
+ peers: config.peers ?? [],
50
+ shards: config.shards ?? 16,
51
+ replicationFactor: config.replicationFactor ?? 2,
52
+ });
53
+ }
54
+ // ===========================================================================
55
+ // Cluster Lifecycle
56
+ // ===========================================================================
57
+ /**
58
+ * Start the cluster node
59
+ */
60
+ async start() {
61
+ await this.inner.start();
62
+ }
63
+ /**
64
+ * Stop the cluster node gracefully
65
+ */
66
+ async stop() {
67
+ await this.inner.stop();
68
+ }
69
+ /**
70
+ * Join an existing cluster
71
+ */
72
+ async join(peerAddress) {
73
+ return this.inner.join(peerAddress);
74
+ }
75
+ /**
76
+ * Leave the cluster
77
+ */
78
+ async leave() {
79
+ await this.inner.leave();
80
+ }
81
+ // ===========================================================================
82
+ // Node Management
83
+ // ===========================================================================
84
+ /**
85
+ * Get current node info
86
+ */
87
+ getNodeInfo() {
88
+ return this.inner.getNodeInfo();
89
+ }
90
+ /**
91
+ * Get all cluster nodes
92
+ */
93
+ getNodes() {
94
+ return this.inner.getNodes();
95
+ }
96
+ /**
97
+ * Check if this node is the leader
98
+ */
99
+ isClusterLeader() {
100
+ this.isLeader = this.inner.isLeader();
101
+ return this.isLeader;
102
+ }
103
+ /**
104
+ * Get the current leader
105
+ */
106
+ getLeader() {
107
+ return this.inner.getLeader();
108
+ }
109
+ // ===========================================================================
110
+ // Distributed Operations
111
+ // ===========================================================================
112
+ /**
113
+ * Put a value in distributed storage
114
+ */
115
+ async put(key, value) {
116
+ return this.inner.put(key, JSON.stringify(value));
117
+ }
118
+ /**
119
+ * Get a value from distributed storage
120
+ */
121
+ async get(key) {
122
+ const result = await this.inner.get(key);
123
+ return result ? JSON.parse(result) : null;
124
+ }
125
+ /**
126
+ * Delete a value from distributed storage
127
+ */
128
+ async delete(key) {
129
+ return this.inner.delete(key);
130
+ }
131
+ /**
132
+ * Atomic compare-and-swap
133
+ */
134
+ async compareAndSwap(key, expected, newValue) {
135
+ return this.inner.compareAndSwap(key, JSON.stringify(expected), JSON.stringify(newValue));
136
+ }
137
+ // ===========================================================================
138
+ // Sharding
139
+ // ===========================================================================
140
+ /**
141
+ * Get shard information
142
+ */
143
+ getShards() {
144
+ return this.inner.getShards();
145
+ }
146
+ /**
147
+ * Get the shard for a key
148
+ */
149
+ getShardForKey(key) {
150
+ return this.inner.getShardForKey(key);
151
+ }
152
+ /**
153
+ * Trigger shard rebalancing
154
+ */
155
+ async rebalance() {
156
+ await this.inner.rebalance();
157
+ }
158
+ // ===========================================================================
159
+ // Distributed Locks
160
+ // ===========================================================================
161
+ /**
162
+ * Acquire a distributed lock
163
+ */
164
+ async lock(name, timeout = 30000) {
165
+ return this.inner.lock(name, timeout);
166
+ }
167
+ /**
168
+ * Release a distributed lock
169
+ */
170
+ async unlock(name, token) {
171
+ return this.inner.unlock(name, token);
172
+ }
173
+ /**
174
+ * Extend a lock's TTL
175
+ */
176
+ async extendLock(name, token, extension = 30000) {
177
+ return this.inner.extendLock(name, token, extension);
178
+ }
179
+ // ===========================================================================
180
+ // Pub/Sub
181
+ // ===========================================================================
182
+ /**
183
+ * Subscribe to a channel
184
+ */
185
+ subscribe(channel, callback) {
186
+ return this.inner.subscribe(channel, (msg) => {
187
+ callback(JSON.parse(msg));
188
+ });
189
+ }
190
+ /**
191
+ * Publish to a channel
192
+ */
193
+ async publish(channel, message) {
194
+ return this.inner.publish(channel, JSON.stringify(message));
195
+ }
196
+ // ===========================================================================
197
+ // Agent Coordination
198
+ // ===========================================================================
199
+ /**
200
+ * Register an agent with the cluster
201
+ */
202
+ async registerAgent(agentId, capabilities) {
203
+ return this.put(`agent:${agentId}`, {
204
+ id: agentId,
205
+ capabilities,
206
+ node: this.nodeId,
207
+ registeredAt: Date.now(),
208
+ });
209
+ }
210
+ /**
211
+ * Find agents with a capability
212
+ */
213
+ async findAgents(capability) {
214
+ const agents = await this.inner.scan('agent:*');
215
+ const matching = [];
216
+ for (const key of agents) {
217
+ const agent = await this.get(key);
218
+ if (agent?.capabilities?.includes(capability)) {
219
+ matching.push(agent.id);
220
+ }
221
+ }
222
+ return matching;
223
+ }
224
+ /**
225
+ * Assign a task to an agent
226
+ */
227
+ async assignTask(taskId, agentId, task) {
228
+ const assigned = await this.put(`task:${taskId}`, {
229
+ id: taskId,
230
+ agent: agentId,
231
+ task,
232
+ status: 'assigned',
233
+ assignedAt: Date.now(),
234
+ });
235
+ if (assigned) {
236
+ await this.publish(`agent:${agentId}:tasks`, { type: 'new_task', taskId });
237
+ }
238
+ return assigned;
239
+ }
240
+ /**
241
+ * Complete a task
242
+ */
243
+ async completeTask(taskId, result) {
244
+ const task = await this.get(`task:${taskId}`);
245
+ if (!task)
246
+ return false;
247
+ return this.put(`task:${taskId}`, {
248
+ ...task,
249
+ status: 'completed',
250
+ result,
251
+ completedAt: Date.now(),
252
+ });
253
+ }
254
+ // ===========================================================================
255
+ // Stats
256
+ // ===========================================================================
257
+ /**
258
+ * Get cluster statistics
259
+ */
260
+ stats() {
261
+ return this.inner.stats();
262
+ }
263
+ }
264
+ exports.RuvectorCluster = RuvectorCluster;
265
+ /**
266
+ * Create a cluster node for agent coordination
267
+ */
268
+ function createCluster(config) {
269
+ return new RuvectorCluster(config);
270
+ }
271
+ exports.default = RuvectorCluster;
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Graph Wrapper - Hypergraph database for code relationships
3
+ *
4
+ * Wraps @ruvector/graph-node for dependency analysis, co-edit patterns,
5
+ * and code structure understanding.
6
+ */
7
+ export declare function isGraphAvailable(): boolean;
8
+ export interface Node {
9
+ id: string;
10
+ labels: string[];
11
+ properties: Record<string, any>;
12
+ }
13
+ export interface Edge {
14
+ id?: string;
15
+ from: string;
16
+ to: string;
17
+ type: string;
18
+ properties?: Record<string, any>;
19
+ }
20
+ export interface Hyperedge {
21
+ id?: string;
22
+ nodes: string[];
23
+ type: string;
24
+ properties?: Record<string, any>;
25
+ }
26
+ export interface CypherResult {
27
+ columns: string[];
28
+ rows: any[][];
29
+ }
30
+ export interface PathResult {
31
+ nodes: Node[];
32
+ edges: Edge[];
33
+ length: number;
34
+ }
35
+ /**
36
+ * Graph Database for code relationships
37
+ */
38
+ export declare class CodeGraph {
39
+ private inner;
40
+ private storagePath?;
41
+ constructor(options?: {
42
+ storagePath?: string;
43
+ inMemory?: boolean;
44
+ });
45
+ /**
46
+ * Create a node (file, function, class, etc.)
47
+ */
48
+ createNode(id: string, labels: string[], properties?: Record<string, any>): Node;
49
+ /**
50
+ * Get a node by ID
51
+ */
52
+ getNode(id: string): Node | null;
53
+ /**
54
+ * Update node properties
55
+ */
56
+ updateNode(id: string, properties: Record<string, any>): boolean;
57
+ /**
58
+ * Delete a node
59
+ */
60
+ deleteNode(id: string): boolean;
61
+ /**
62
+ * Find nodes by label
63
+ */
64
+ findNodesByLabel(label: string): Node[];
65
+ /**
66
+ * Create an edge (import, call, reference, etc.)
67
+ */
68
+ createEdge(from: string, to: string, type: string, properties?: Record<string, any>): Edge;
69
+ /**
70
+ * Get edges from a node
71
+ */
72
+ getOutgoingEdges(nodeId: string, type?: string): Edge[];
73
+ /**
74
+ * Get edges to a node
75
+ */
76
+ getIncomingEdges(nodeId: string, type?: string): Edge[];
77
+ /**
78
+ * Delete an edge
79
+ */
80
+ deleteEdge(edgeId: string): boolean;
81
+ /**
82
+ * Create a hyperedge connecting multiple nodes
83
+ */
84
+ createHyperedge(nodes: string[], type: string, properties?: Record<string, any>): Hyperedge;
85
+ /**
86
+ * Get hyperedges containing a node
87
+ */
88
+ getHyperedges(nodeId: string, type?: string): Hyperedge[];
89
+ /**
90
+ * Execute a Cypher query
91
+ */
92
+ cypher(query: string, params?: Record<string, any>): CypherResult;
93
+ /**
94
+ * Find shortest path between nodes
95
+ */
96
+ shortestPath(from: string, to: string, maxDepth?: number): PathResult | null;
97
+ /**
98
+ * Get all paths between nodes (up to maxPaths)
99
+ */
100
+ allPaths(from: string, to: string, maxDepth?: number, maxPaths?: number): PathResult[];
101
+ /**
102
+ * Get neighbors of a node
103
+ */
104
+ neighbors(nodeId: string, depth?: number): Node[];
105
+ /**
106
+ * Calculate PageRank for nodes
107
+ */
108
+ pageRank(iterations?: number, dampingFactor?: number): Map<string, number>;
109
+ /**
110
+ * Find connected components
111
+ */
112
+ connectedComponents(): string[][];
113
+ /**
114
+ * Detect communities (Louvain algorithm)
115
+ */
116
+ communities(): Map<string, number>;
117
+ /**
118
+ * Calculate betweenness centrality
119
+ */
120
+ betweennessCentrality(): Map<string, number>;
121
+ /**
122
+ * Save graph to storage
123
+ */
124
+ save(): void;
125
+ /**
126
+ * Load graph from storage
127
+ */
128
+ load(): void;
129
+ /**
130
+ * Clear all data
131
+ */
132
+ clear(): void;
133
+ /**
134
+ * Get graph statistics
135
+ */
136
+ stats(): {
137
+ nodes: number;
138
+ edges: number;
139
+ hyperedges: number;
140
+ };
141
+ }
142
+ /**
143
+ * Create a code dependency graph from file analysis
144
+ */
145
+ export declare function createCodeDependencyGraph(storagePath?: string): CodeGraph;
146
+ export default CodeGraph;
147
+ //# sourceMappingURL=graph-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-wrapper.d.ts","sourceRoot":"","sources":["../../src/core/graph-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH,wBAAgB,gBAAgB,IAAI,OAAO,CAO1C;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,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