@sesamespace/hivemind 0.8.13 → 0.10.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 (54) hide show
  1. package/README.md +2 -1
  2. package/dist/{chunk-MLY4VFOO.js → chunk-BHCDOHSK.js} +3 -3
  3. package/dist/{chunk-PFZO67E2.js → chunk-DPLCEMEC.js} +2 -2
  4. package/dist/{chunk-HTLHMXAL.js → chunk-FBQBBAPZ.js} +2 -2
  5. package/dist/{chunk-NSTTILSN.js → chunk-FK6WYXRM.js} +79 -2
  6. package/dist/chunk-FK6WYXRM.js.map +1 -0
  7. package/dist/{chunk-LJHJGDKY.js → chunk-ICSJNKI6.js} +62 -2
  8. package/dist/chunk-ICSJNKI6.js.map +1 -0
  9. package/dist/{chunk-4Y7A25UG.js → chunk-IXBIAX76.js} +2 -2
  10. package/dist/{chunk-ZM7RK5YV.js → chunk-M3A2WRXM.js} +560 -37
  11. package/dist/chunk-M3A2WRXM.js.map +1 -0
  12. package/dist/commands/fleet.js +3 -3
  13. package/dist/commands/init.js +3 -3
  14. package/dist/commands/start.js +3 -3
  15. package/dist/commands/upgrade.js +1 -1
  16. package/dist/commands/watchdog.js +3 -3
  17. package/dist/dashboard.html +873 -131
  18. package/dist/index.js +2 -2
  19. package/dist/main.js +375 -7
  20. package/dist/main.js.map +1 -1
  21. package/dist/start.js +1 -1
  22. package/install.sh +162 -0
  23. package/package.json +24 -23
  24. package/packages/memory/Cargo.lock +6480 -0
  25. package/packages/memory/Cargo.toml +21 -0
  26. package/packages/memory/src/src/context.rs +179 -0
  27. package/packages/memory/src/src/embeddings.rs +51 -0
  28. package/packages/memory/src/src/main.rs +887 -0
  29. package/packages/memory/src/src/promotion.rs +808 -0
  30. package/packages/memory/src/src/scoring.rs +142 -0
  31. package/packages/memory/src/src/store.rs +460 -0
  32. package/packages/memory/src/src/tasks.rs +321 -0
  33. package/.pnpmrc.json +0 -1
  34. package/AUTO-DEBUG-DESIGN.md +0 -267
  35. package/DASHBOARD-PLAN.md +0 -206
  36. package/MEMORY-ENHANCEMENT-PLAN.md +0 -211
  37. package/TOOL-USE-DESIGN.md +0 -173
  38. package/dist/chunk-LJHJGDKY.js.map +0 -1
  39. package/dist/chunk-NSTTILSN.js.map +0 -1
  40. package/dist/chunk-ZM7RK5YV.js.map +0 -1
  41. package/docs/TOOL-PARITY-PLAN.md +0 -191
  42. package/src/memory/dashboard-integration.ts +0 -295
  43. package/src/memory/index.ts +0 -187
  44. package/src/memory/performance-test.ts +0 -208
  45. package/src/memory/processors/agent-sync.ts +0 -312
  46. package/src/memory/processors/command-learner.ts +0 -298
  47. package/src/memory/processors/memory-api-client.ts +0 -105
  48. package/src/memory/processors/message-flow-integration.ts +0 -168
  49. package/src/memory/processors/research-digester.ts +0 -204
  50. package/test-caitlin-access.md +0 -11
  51. /package/dist/{chunk-MLY4VFOO.js.map → chunk-BHCDOHSK.js.map} +0 -0
  52. /package/dist/{chunk-PFZO67E2.js.map → chunk-DPLCEMEC.js.map} +0 -0
  53. /package/dist/{chunk-HTLHMXAL.js.map → chunk-FBQBBAPZ.js.map} +0 -0
  54. /package/dist/{chunk-4Y7A25UG.js.map → chunk-IXBIAX76.js.map} +0 -0
@@ -1,208 +0,0 @@
1
- /**
2
- * Performance test for the memory management system
3
- */
4
-
5
- import { MemorySystem } from './index';
6
- import * as fs from 'fs';
7
- import * as path from 'path';
8
-
9
- async function runPerformanceTest() {
10
- console.log('🧪 Starting Hivemind Memory System Performance Test\n');
11
-
12
- const startTime = Date.now();
13
- const workspaceRoot = path.join(__dirname, '../../test-workspace');
14
-
15
- // Create test workspace
16
- if (!fs.existsSync(workspaceRoot)) {
17
- fs.mkdirSync(workspaceRoot, { recursive: true });
18
- }
19
-
20
- // Initialize memory system
21
- const memory = new MemorySystem({
22
- agentId: 'test-agent-001',
23
- agentName: 'TestAgent',
24
- workspaceRoot,
25
- memoryURL: 'http://localhost:3434',
26
- context: 'performance-test',
27
- maxContextTokens: 8000,
28
- dashboardPort: 9487
29
- });
30
-
31
- // Track metrics
32
- const metrics = {
33
- messagesProcessed: 0,
34
- contextBuildTime: [] as number[],
35
- memoryUsage: [] as number[],
36
- errors: 0
37
- };
38
-
39
- // Set up event listeners
40
- memory.on('error', (error) => {
41
- console.error('❌ Error:', error);
42
- metrics.errors++;
43
- });
44
-
45
- memory.on('context-built', (data) => {
46
- console.log(`📝 Context built: ${data.contextLength} chars, ${data.sections} sections`);
47
- });
48
-
49
- memory.on('started', () => {
50
- console.log('✅ Memory system started\n');
51
- });
52
-
53
- memory.on('dashboard-started', ({ port }) => {
54
- console.log(`🌐 Dashboard available at http://localhost:${port}\n`);
55
- });
56
-
57
- try {
58
- // Start the system
59
- await memory.start();
60
-
61
- // Test 1: Message processing
62
- console.log('📊 Test 1: Message Processing');
63
- const messages = [
64
- { role: 'user' as const, content: 'Can you help me debug the authentication system in src/auth/login.ts?' },
65
- { role: 'assistant' as const, content: 'I\'ll help you debug the authentication system. Let me look at src/auth/login.ts...' },
66
- { role: 'user' as const, content: 'The error happens when users try to login with OAuth' },
67
- { role: 'assistant' as const, content: 'I see. Let me check the OAuth configuration in src/auth/oauth.ts and src/config/oauth.json' }
68
- ];
69
-
70
- for (const message of messages) {
71
- const startContext = Date.now();
72
- const context = await memory.processMessage(message);
73
- const contextTime = Date.now() - startContext;
74
-
75
- metrics.contextBuildTime.push(contextTime);
76
- metrics.messagesProcessed++;
77
-
78
- console.log(` - Processed ${message.role} message in ${contextTime}ms (context: ${context.length} chars)`);
79
- }
80
-
81
- // Test 2: Research ingestion
82
- console.log('\n📊 Test 2: Research Ingestion');
83
- const researchContent = `
84
- # Understanding TypeScript Decorators
85
-
86
- Decorators are a powerful feature in TypeScript that allow you to modify classes and their members.
87
-
88
- ## Key Points
89
- - Decorators use the @ symbol
90
- - They can be applied to classes, methods, properties, and parameters
91
- - Decorators are executed at runtime
92
- - Multiple decorators can be composed
93
-
94
- ## Common Use Cases
95
- - Logging and monitoring
96
- - Validation
97
- - Dependency injection
98
- - Route handling in web frameworks
99
-
100
- ## Example
101
- \`\`\`typescript
102
- @Injectable()
103
- class UserService {
104
- @Log()
105
- async getUser(id: string) {
106
- return this.db.findUser(id);
107
- }
108
- }
109
- \`\`\`
110
- `;
111
-
112
- await memory.addResearch(researchContent, {
113
- title: 'TypeScript Decorators Guide',
114
- sourceType: 'markdown'
115
- });
116
- console.log(' - Added research document');
117
-
118
- // Test 3: Command tracking
119
- console.log('\n📊 Test 3: Command Tracking');
120
- const commands = [
121
- { cmd: 'git status', output: 'On branch main\nnothing to commit', success: true },
122
- { cmd: 'git pull origin main', output: 'Already up to date.', success: true },
123
- { cmd: 'npm test', output: 'Test suite failed', success: false },
124
- { cmd: 'npm test -- --fix', output: 'All tests passed', success: true }
125
- ];
126
-
127
- for (const { cmd, output, success } of commands) {
128
- await memory.trackCommand(cmd, 'debugging auth system', output, success);
129
- console.log(` - Tracked command: ${cmd} (${success ? '✓' : '✗'})`);
130
- }
131
-
132
- // Test 4: Task sharing
133
- console.log('\n📊 Test 4: Task Management');
134
- const taskId = await memory.shareTask({
135
- description: 'Fix OAuth authentication bug',
136
- status: 'active',
137
- progress: 45,
138
- notes: ['Users report 401 errors', 'Might be related to token expiration']
139
- });
140
- console.log(` - Created shared task: ${taskId}`);
141
-
142
- // Test 5: Insight sharing
143
- await memory.shareInsight('OAuth tokens need refresh logic to handle expiration gracefully');
144
- console.log(' - Shared insight about OAuth tokens');
145
-
146
- // Test 6: Memory usage
147
- console.log('\n📊 Test 6: Memory Usage');
148
- for (let i = 0; i < 5; i++) {
149
- const usage = process.memoryUsage();
150
- metrics.memoryUsage.push(usage.heapUsed);
151
- console.log(` - Heap used: ${(usage.heapUsed / 1024 / 1024).toFixed(2)} MB`);
152
-
153
- // Process more messages to see memory growth
154
- await memory.processMessage({
155
- role: 'user',
156
- content: `Test message ${i}: Working on feature ${i}`
157
- });
158
-
159
- await new Promise(resolve => setTimeout(resolve, 1000));
160
- }
161
-
162
- // Test 7: Context building performance with large content
163
- console.log('\n📊 Test 7: Large Context Performance');
164
- const largeMessage = 'x'.repeat(1000) + ' Can you analyze this large codebase?';
165
- const largeStart = Date.now();
166
- const largeContext = await memory.processMessage({
167
- role: 'user',
168
- content: largeMessage
169
- });
170
- const largeTime = Date.now() - largeStart;
171
- console.log(` - Large message processed in ${largeTime}ms (context: ${largeContext.length} chars)`);
172
-
173
- // Get final state
174
- const state = await memory.getState();
175
- console.log('\n📊 Final System State:');
176
- console.log(` - Memory episodes: ${state.memory?.episodes || 0}`);
177
- console.log(` - Active tasks: ${state.tasks?.length || 0}`);
178
- console.log(` - Working set files: ${state.workingSet?.length || 0}`);
179
- console.log(` - Background processors: ${state.processors || 0}`);
180
-
181
- // Calculate statistics
182
- const avgContextTime = metrics.contextBuildTime.reduce((a, b) => a + b, 0) / metrics.contextBuildTime.length;
183
- const maxMemory = Math.max(...metrics.memoryUsage);
184
- const minMemory = Math.min(...metrics.memoryUsage);
185
-
186
- console.log('\n📈 Performance Summary:');
187
- console.log(` - Total runtime: ${((Date.now() - startTime) / 1000).toFixed(2)}s`);
188
- console.log(` - Messages processed: ${metrics.messagesProcessed}`);
189
- console.log(` - Avg context build time: ${avgContextTime.toFixed(2)}ms`);
190
- console.log(` - Memory usage: ${(minMemory / 1024 / 1024).toFixed(2)} - ${(maxMemory / 1024 / 1024).toFixed(2)} MB`);
191
- console.log(` - Errors encountered: ${metrics.errors}`);
192
-
193
- // Stop the system
194
- await memory.stop();
195
- console.log('\n✅ Memory system stopped successfully');
196
-
197
- } catch (error) {
198
- console.error('\n❌ Test failed:', error);
199
- process.exit(1);
200
- }
201
-
202
- // Clean up test workspace
203
- fs.rmSync(workspaceRoot, { recursive: true, force: true });
204
- console.log('\n🧹 Cleaned up test workspace');
205
- }
206
-
207
- // Run the test
208
- runPerformanceTest().catch(console.error);
@@ -1,312 +0,0 @@
1
- /**
2
- * Agent Sync - Shares knowledge between multiple Hivemind agents
3
- */
4
-
5
- import { BackgroundProcessor } from './background-processor';
6
- import { EventEmitter } from 'events';
7
- import axios from 'axios';
8
-
9
- export interface AgentKnowledge {
10
- agentId: string;
11
- agentName: string;
12
- context: string;
13
- tasks: SharedTask[];
14
- insights: string[];
15
- capabilities: string[];
16
- lastSync: Date;
17
- }
18
-
19
- export interface SharedTask {
20
- id: string;
21
- description: string;
22
- status: 'active' | 'completed' | 'blocked';
23
- assignedTo: string;
24
- dependencies: string[];
25
- progress: number;
26
- notes: string[];
27
- }
28
-
29
- export interface SyncMessage {
30
- type: 'task-update' | 'insight' | 'handoff' | 'capability';
31
- fromAgent: string;
32
- toAgent?: string; // Optional for broadcasts
33
- payload: any;
34
- timestamp: Date;
35
- }
36
-
37
- export class AgentSync extends BackgroundProcessor {
38
- private agentId: string;
39
- private agentName: string;
40
- private otherAgents: Map<string, AgentKnowledge> = new Map();
41
- private syncQueue: SyncMessage[] = [];
42
- private sharedTasks: Map<string, SharedTask> = new Map();
43
- private syncEndpoints: Map<string, string> = new Map(); // agentId -> endpoint
44
-
45
- constructor(agentId: string, agentName: string) {
46
- super('agent-sync', 30000); // Sync every 30 seconds
47
- this.agentId = agentId;
48
- this.agentName = agentName;
49
- }
50
-
51
- async process(): Promise<void> {
52
- // Process outgoing sync messages
53
- await this.processSyncQueue();
54
-
55
- // Pull updates from other agents
56
- await this.pullUpdates();
57
-
58
- // Check for stale tasks that might need handoff
59
- await this.checkHandoffs();
60
-
61
- this.emit('sync-complete', {
62
- agentsKnown: this.otherAgents.size,
63
- sharedTasks: this.sharedTasks.size,
64
- queuedMessages: this.syncQueue.length
65
- });
66
- }
67
-
68
- /**
69
- * Register another agent for syncing
70
- */
71
- async registerAgent(agentId: string, agentName: string, endpoint: string): Promise<void> {
72
- this.syncEndpoints.set(agentId, endpoint);
73
- this.otherAgents.set(agentId, {
74
- agentId,
75
- agentName,
76
- context: 'unknown',
77
- tasks: [],
78
- insights: [],
79
- capabilities: [],
80
- lastSync: new Date()
81
- });
82
- }
83
-
84
- /**
85
- * Share a task with other agents
86
- */
87
- async shareTask(task: Omit<SharedTask, 'id'>): Promise<string> {
88
- const taskId = `${this.agentId}-${Date.now()}`;
89
- const sharedTask: SharedTask = {
90
- id: taskId,
91
- ...task
92
- };
93
-
94
- this.sharedTasks.set(taskId, sharedTask);
95
-
96
- // Broadcast task to other agents
97
- this.queueSync({
98
- type: 'task-update',
99
- fromAgent: this.agentId,
100
- payload: sharedTask,
101
- timestamp: new Date()
102
- });
103
-
104
- return taskId;
105
- }
106
-
107
- /**
108
- * Share an insight learned during work
109
- */
110
- async shareInsight(insight: string, context?: string): Promise<void> {
111
- this.queueSync({
112
- type: 'insight',
113
- fromAgent: this.agentId,
114
- payload: { insight, context },
115
- timestamp: new Date()
116
- });
117
- }
118
-
119
- /**
120
- * Announce a new capability
121
- */
122
- async announceCapability(capability: string): Promise<void> {
123
- this.queueSync({
124
- type: 'capability',
125
- fromAgent: this.agentId,
126
- payload: { capability },
127
- timestamp: new Date()
128
- });
129
- }
130
-
131
- /**
132
- * Request handoff of a task to another agent
133
- */
134
- async requestHandoff(taskId: string, toAgent: string, reason: string): Promise<void> {
135
- const task = this.sharedTasks.get(taskId);
136
- if (!task) return;
137
-
138
- this.queueSync({
139
- type: 'handoff',
140
- fromAgent: this.agentId,
141
- toAgent,
142
- payload: { taskId, task, reason },
143
- timestamp: new Date()
144
- });
145
- }
146
-
147
- private queueSync(message: SyncMessage): void {
148
- this.syncQueue.push(message);
149
- }
150
-
151
- private async processSyncQueue(): Promise<void> {
152
- while (this.syncQueue.length > 0) {
153
- const message = this.syncQueue.shift();
154
- if (!message) continue;
155
-
156
- if (message.toAgent) {
157
- // Direct message to specific agent
158
- await this.sendToAgent(message.toAgent, message);
159
- } else {
160
- // Broadcast to all agents
161
- for (const agentId of this.syncEndpoints.keys()) {
162
- if (agentId !== this.agentId) {
163
- await this.sendToAgent(agentId, message);
164
- }
165
- }
166
- }
167
- }
168
- }
169
-
170
- private async sendToAgent(agentId: string, message: SyncMessage): Promise<void> {
171
- const endpoint = this.syncEndpoints.get(agentId);
172
- if (!endpoint) return;
173
-
174
- try {
175
- await axios.post(`${endpoint}/sync`, message, {
176
- timeout: 5000,
177
- headers: {
178
- 'X-Agent-ID': this.agentId,
179
- 'X-Agent-Name': this.agentName
180
- }
181
- });
182
- } catch (error) {
183
- this.emit('sync-error', { agentId, error });
184
- }
185
- }
186
-
187
- private async pullUpdates(): Promise<void> {
188
- for (const [agentId, endpoint] of this.syncEndpoints) {
189
- if (agentId === this.agentId) continue;
190
-
191
- try {
192
- const response = await axios.get(`${endpoint}/sync/updates`, {
193
- params: {
194
- since: this.otherAgents.get(agentId)?.lastSync.toISOString()
195
- },
196
- timeout: 5000,
197
- headers: {
198
- 'X-Agent-ID': this.agentId
199
- }
200
- });
201
-
202
- if (response.data.updates) {
203
- await this.processUpdates(agentId, response.data.updates);
204
- }
205
- } catch (error) {
206
- this.emit('pull-error', { agentId, error });
207
- }
208
- }
209
- }
210
-
211
- private async processUpdates(fromAgent: string, updates: SyncMessage[]): Promise<void> {
212
- const agentKnowledge = this.otherAgents.get(fromAgent);
213
- if (!agentKnowledge) return;
214
-
215
- for (const update of updates) {
216
- switch (update.type) {
217
- case 'task-update':
218
- const task = update.payload as SharedTask;
219
- this.sharedTasks.set(task.id, task);
220
- agentKnowledge.tasks = agentKnowledge.tasks.filter(t => t.id !== task.id);
221
- agentKnowledge.tasks.push(task);
222
- break;
223
-
224
- case 'insight':
225
- const { insight } = update.payload;
226
- if (!agentKnowledge.insights.includes(insight)) {
227
- agentKnowledge.insights.push(insight);
228
- }
229
- break;
230
-
231
- case 'capability':
232
- const { capability } = update.payload;
233
- if (!agentKnowledge.capabilities.includes(capability)) {
234
- agentKnowledge.capabilities.push(capability);
235
- }
236
- break;
237
-
238
- case 'handoff':
239
- if (update.toAgent === this.agentId) {
240
- await this.handleHandoff(update.payload);
241
- }
242
- break;
243
- }
244
- }
245
-
246
- agentKnowledge.lastSync = new Date();
247
- }
248
-
249
- private async handleHandoff(payload: any): Promise<void> {
250
- const { taskId, task, reason } = payload;
251
-
252
- // Accept the handoff
253
- task.assignedTo = this.agentName;
254
- this.sharedTasks.set(taskId, task);
255
-
256
- this.emit('handoff-received', { taskId, task, reason });
257
-
258
- // Acknowledge the handoff
259
- this.queueSync({
260
- type: 'task-update',
261
- fromAgent: this.agentId,
262
- payload: task,
263
- timestamp: new Date()
264
- });
265
- }
266
-
267
- private async checkHandoffs(): Promise<void> {
268
- // Check for tasks that might need handoff
269
- for (const task of this.sharedTasks.values()) {
270
- if (task.assignedTo === this.agentName && task.status === 'blocked') {
271
- // Check if another agent might be better suited
272
- const betterAgent = this.findBetterAgent(task);
273
- if (betterAgent) {
274
- await this.requestHandoff(
275
- task.id,
276
- betterAgent,
277
- 'Task blocked, another agent may have required capabilities'
278
- );
279
- }
280
- }
281
- }
282
- }
283
-
284
- private findBetterAgent(task: SharedTask): string | null {
285
- // Simple heuristic: find agent with relevant capabilities
286
- for (const [agentId, knowledge] of this.otherAgents) {
287
- // Check if agent has capabilities mentioned in task notes
288
- for (const note of task.notes) {
289
- for (const capability of knowledge.capabilities) {
290
- if (note.toLowerCase().includes(capability.toLowerCase())) {
291
- return agentId;
292
- }
293
- }
294
- }
295
- }
296
- return null;
297
- }
298
-
299
- /**
300
- * Get knowledge about other agents
301
- */
302
- async getAgentKnowledge(): Promise<AgentKnowledge[]> {
303
- return Array.from(this.otherAgents.values());
304
- }
305
-
306
- /**
307
- * Get all shared tasks
308
- */
309
- async getSharedTasks(): Promise<SharedTask[]> {
310
- return Array.from(this.sharedTasks.values());
311
- }
312
- }