@sesamespace/hivemind 0.8.10 → 0.8.12

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/dist/index.js CHANGED
@@ -3,8 +3,10 @@ import {
3
3
  PrimaryClient,
4
4
  PrimaryMemorySync,
5
5
  Watchdog,
6
- WorkerMemorySync
7
- } from "./chunk-A5LMEJIN.js";
6
+ WorkerMemorySync,
7
+ createLogger,
8
+ setLogLevel
9
+ } from "./chunk-HDYEAKN5.js";
8
10
  import {
9
11
  Agent,
10
12
  CompactionManager,
@@ -49,12 +51,14 @@ export {
49
51
  WorkerServer,
50
52
  buildMessages,
51
53
  buildSystemPrompt,
54
+ createLogger,
52
55
  defaultSentinelConfig,
53
56
  estimateMessageTokens,
54
57
  estimateTokens,
55
58
  getClaudeCodeOAuthToken,
56
59
  getModelContextWindow,
57
60
  loadConfig,
61
+ setLogLevel,
58
62
  startPipeline,
59
63
  startWorker
60
64
  };
package/dist/main.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-OVRYYS5I.js";
8
8
  import {
9
9
  runFleetCommand
10
- } from "./chunk-SMUG64N7.js";
10
+ } from "./chunk-XQZU3ULO.js";
11
11
  import {
12
12
  runServiceCommand
13
13
  } from "./chunk-IJRAVHQC.js";
@@ -16,8 +16,8 @@ import {
16
16
  } from "./chunk-LJHJGDKY.js";
17
17
  import {
18
18
  runWatchdogCommand
19
- } from "./chunk-F6EMICWP.js";
20
- import "./chunk-A5LMEJIN.js";
19
+ } from "./chunk-NCJW2AOK.js";
20
+ import "./chunk-HDYEAKN5.js";
21
21
  import "./chunk-OG6GPQDK.js";
22
22
 
23
23
  // packages/cli/src/main.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sesamespace/hivemind",
3
- "version": "0.8.10",
3
+ "version": "0.8.12",
4
4
  "description": "Cognitive architecture for AI agents with multi-layered memory",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -15,7 +15,9 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@sesamespace/sdk": "^0.1.6",
18
- "smol-toml": "^1.6.0"
18
+ "smol-toml": "^1.6.0",
19
+ "axios": "^1.7.9",
20
+ "express": "^4.21.2"
19
21
  },
20
22
  "devDependencies": {
21
23
  "tsup": "^8.5.1"
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Dashboard Integration - Exposes memory system state to the Hivemind dashboard
3
+ */
4
+
5
+ import { EventEmitter } from 'events';
6
+ import express from 'express';
7
+ import { MessageFlowIntegration } from './processors/message-flow-integration';
8
+ import { ResearchDigester } from './processors/research-digester';
9
+ import { CommandLearner } from './processors/command-learner';
10
+ import { AgentSync } from './processors/agent-sync';
11
+
12
+ export interface DashboardConfig {
13
+ port?: number;
14
+ messageFlow: MessageFlowIntegration;
15
+ researchDigester?: ResearchDigester;
16
+ commandLearner?: CommandLearner;
17
+ agentSync?: AgentSync;
18
+ }
19
+
20
+ export class DashboardIntegration extends EventEmitter {
21
+ private app: express.Application;
22
+ private messageFlow: MessageFlowIntegration;
23
+ private researchDigester?: ResearchDigester;
24
+ private commandLearner?: CommandLearner;
25
+ private agentSync?: AgentSync;
26
+
27
+ constructor(config: DashboardConfig) {
28
+ super();
29
+
30
+ this.messageFlow = config.messageFlow;
31
+ this.researchDigester = config.researchDigester;
32
+ this.commandLearner = config.commandLearner;
33
+ this.agentSync = config.agentSync;
34
+
35
+ this.app = express();
36
+ this.setupRoutes();
37
+ }
38
+
39
+ private setupRoutes(): void {
40
+ this.app.use(express.json());
41
+
42
+ // Memory system overview
43
+ this.app.get('/api/memory/overview', async (req, res) => {
44
+ try {
45
+ const state = await this.messageFlow.getState();
46
+ const overview = {
47
+ ...state,
48
+ research: this.researchDigester ? {
49
+ entries: (await this.researchDigester['research']).size,
50
+ topics: Array.from(this.researchDigester['topicIndex'].keys())
51
+ } : null,
52
+ commands: this.commandLearner ? {
53
+ patterns: this.commandLearner['patterns'].size,
54
+ categories: Array.from(this.commandLearner['categoryIndex'].keys())
55
+ } : null,
56
+ agents: this.agentSync ? {
57
+ known: (await this.agentSync.getAgentKnowledge()).length,
58
+ sharedTasks: (await this.agentSync.getSharedTasks()).length
59
+ } : null
60
+ };
61
+ res.json(overview);
62
+ } catch (error) {
63
+ res.status(500).json({ error: error.message });
64
+ }
65
+ });
66
+
67
+ // Working set - currently active code files
68
+ this.app.get('/api/memory/working-set', async (req, res) => {
69
+ try {
70
+ const state = await this.messageFlow.getState();
71
+ res.json({
72
+ files: state.workingSet,
73
+ totalFiles: state.workingSet.length
74
+ });
75
+ } catch (error) {
76
+ res.status(500).json({ error: error.message });
77
+ }
78
+ });
79
+
80
+ // Active tasks
81
+ this.app.get('/api/memory/tasks', async (req, res) => {
82
+ try {
83
+ const state = await this.messageFlow.getState();
84
+ const sharedTasks = this.agentSync ? await this.agentSync.getSharedTasks() : [];
85
+
86
+ res.json({
87
+ localTasks: state.tasks,
88
+ sharedTasks: sharedTasks,
89
+ total: state.tasks.length + sharedTasks.length
90
+ });
91
+ } catch (error) {
92
+ res.status(500).json({ error: error.message });
93
+ }
94
+ });
95
+
96
+ // Research entries
97
+ this.app.get('/api/memory/research', async (req, res) => {
98
+ if (!this.researchDigester) {
99
+ return res.json({ entries: [], topics: [] });
100
+ }
101
+
102
+ try {
103
+ const recent = await this.researchDigester.getRecent(20);
104
+ res.json({
105
+ entries: recent,
106
+ topics: Array.from(this.researchDigester['topicIndex'].keys())
107
+ });
108
+ } catch (error) {
109
+ res.status(500).json({ error: error.message });
110
+ }
111
+ });
112
+
113
+ // Search research
114
+ this.app.get('/api/memory/research/search', async (req, res) => {
115
+ if (!this.researchDigester) {
116
+ return res.json({ results: [] });
117
+ }
118
+
119
+ try {
120
+ const { q } = req.query;
121
+ const results = await this.researchDigester.search(q as string);
122
+ res.json({ results });
123
+ } catch (error) {
124
+ res.status(500).json({ error: error.message });
125
+ }
126
+ });
127
+
128
+ // Command patterns
129
+ this.app.get('/api/memory/commands', async (req, res) => {
130
+ if (!this.commandLearner) {
131
+ return res.json({ patterns: [], categories: [] });
132
+ }
133
+
134
+ try {
135
+ const patterns = Array.from(this.commandLearner['patterns'].values());
136
+ const categories = Array.from(this.commandLearner['categoryIndex'].keys());
137
+
138
+ res.json({
139
+ patterns: patterns.sort((a, b) => b.usageCount - a.usageCount),
140
+ categories
141
+ });
142
+ } catch (error) {
143
+ res.status(500).json({ error: error.message });
144
+ }
145
+ });
146
+
147
+ // Command suggestions
148
+ this.app.get('/api/memory/commands/suggest', async (req, res) => {
149
+ if (!this.commandLearner) {
150
+ return res.json({ suggestions: [] });
151
+ }
152
+
153
+ try {
154
+ const { context, category } = req.query;
155
+ const suggestions = await this.commandLearner.getSuggestions(
156
+ context as string || '',
157
+ category as string
158
+ );
159
+ res.json({ suggestions });
160
+ } catch (error) {
161
+ res.status(500).json({ error: error.message });
162
+ }
163
+ });
164
+
165
+ // Agent knowledge
166
+ this.app.get('/api/memory/agents', async (req, res) => {
167
+ if (!this.agentSync) {
168
+ return res.json({ agents: [] });
169
+ }
170
+
171
+ try {
172
+ const agents = await this.agentSync.getAgentKnowledge();
173
+ res.json({ agents });
174
+ } catch (error) {
175
+ res.status(500).json({ error: error.message });
176
+ }
177
+ });
178
+
179
+ // Memory timeline - recent activity
180
+ this.app.get('/api/memory/timeline', async (req, res) => {
181
+ try {
182
+ const timeline = [];
183
+
184
+ // Add recent tasks
185
+ const state = await this.messageFlow.getState();
186
+ for (const task of state.tasks) {
187
+ timeline.push({
188
+ type: 'task',
189
+ timestamp: task.lastUpdate,
190
+ description: task.description,
191
+ metadata: { state: task.state }
192
+ });
193
+ }
194
+
195
+ // Add recent research
196
+ if (this.researchDigester) {
197
+ const research = await this.researchDigester.getRecent(5);
198
+ for (const entry of research) {
199
+ timeline.push({
200
+ type: 'research',
201
+ timestamp: entry.timestamp,
202
+ description: entry.title,
203
+ metadata: { url: entry.url, topics: entry.relatedTopics }
204
+ });
205
+ }
206
+ }
207
+
208
+ // Add recent commands
209
+ if (this.commandLearner) {
210
+ const patterns = Array.from(this.commandLearner['patterns'].values())
211
+ .sort((a, b) => b.lastUsed.getTime() - a.lastUsed.getTime())
212
+ .slice(0, 5);
213
+
214
+ for (const pattern of patterns) {
215
+ timeline.push({
216
+ type: 'command',
217
+ timestamp: pattern.lastUsed,
218
+ description: pattern.description,
219
+ metadata: { pattern: pattern.pattern, category: pattern.category }
220
+ });
221
+ }
222
+ }
223
+
224
+ // Sort by timestamp
225
+ timeline.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime());
226
+
227
+ res.json({ timeline: timeline.slice(0, 50) });
228
+ } catch (error) {
229
+ res.status(500).json({ error: error.message });
230
+ }
231
+ });
232
+
233
+ // Context preview - what would be included in next request
234
+ this.app.post('/api/memory/context-preview', async (req, res) => {
235
+ try {
236
+ const { message } = req.body;
237
+ const context = await this.messageFlow.processMessage({
238
+ role: 'user',
239
+ content: message,
240
+ timestamp: new Date()
241
+ });
242
+
243
+ res.json({
244
+ context,
245
+ length: context.length,
246
+ sections: this.analyzeContextSections(context)
247
+ });
248
+ } catch (error) {
249
+ res.status(500).json({ error: error.message });
250
+ }
251
+ });
252
+ }
253
+
254
+ private analyzeContextSections(context: string): any[] {
255
+ const sections = [];
256
+ const lines = context.split('\n');
257
+ let currentSection = null;
258
+ let currentContent = [];
259
+
260
+ for (const line of lines) {
261
+ if (line.startsWith('## ')) {
262
+ if (currentSection) {
263
+ sections.push({
264
+ title: currentSection,
265
+ lines: currentContent.length,
266
+ characters: currentContent.join('\n').length
267
+ });
268
+ }
269
+ currentSection = line.substring(3);
270
+ currentContent = [];
271
+ } else {
272
+ currentContent.push(line);
273
+ }
274
+ }
275
+
276
+ if (currentSection) {
277
+ sections.push({
278
+ title: currentSection,
279
+ lines: currentContent.length,
280
+ characters: currentContent.join('\n').length
281
+ });
282
+ }
283
+
284
+ return sections;
285
+ }
286
+
287
+ async start(port: number = 9486): Promise<void> {
288
+ return new Promise((resolve) => {
289
+ this.app.listen(port, () => {
290
+ this.emit('started', { port });
291
+ resolve();
292
+ });
293
+ });
294
+ }
295
+ }
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Hivemind Memory System - Automatic context management for all agents
3
+ */
4
+
5
+ import { MessageFlowIntegration, MessageFlowConfig } from './processors/message-flow-integration';
6
+ import { ResearchDigester } from './processors/research-digester';
7
+ import { CommandLearner } from './processors/command-learner';
8
+ import { AgentSync } from './processors/agent-sync';
9
+ import { DashboardIntegration } from './dashboard-integration';
10
+ import { EventEmitter } from 'events';
11
+
12
+ export interface MemorySystemConfig {
13
+ agentId: string;
14
+ agentName: string;
15
+ workspaceRoot: string;
16
+ memoryURL?: string;
17
+ context?: string;
18
+ maxContextTokens?: number;
19
+ dashboardPort?: number;
20
+ syncEndpoints?: Map<string, string>; // Other agents to sync with
21
+ }
22
+
23
+ export class MemorySystem extends EventEmitter {
24
+ private messageFlow: MessageFlowIntegration;
25
+ private researchDigester: ResearchDigester;
26
+ private commandLearner: CommandLearner;
27
+ private agentSync: AgentSync;
28
+ private dashboard?: DashboardIntegration;
29
+ private config: MemorySystemConfig;
30
+
31
+ constructor(config: MemorySystemConfig) {
32
+ super();
33
+ this.config = config;
34
+
35
+ // Initialize core message flow
36
+ this.messageFlow = new MessageFlowIntegration({
37
+ workspaceRoot: config.workspaceRoot,
38
+ memoryURL: config.memoryURL,
39
+ context: config.context,
40
+ maxContextTokens: config.maxContextTokens
41
+ });
42
+
43
+ // Initialize processors
44
+ this.researchDigester = new ResearchDigester();
45
+ this.commandLearner = new CommandLearner();
46
+ this.agentSync = new AgentSync(config.agentId, config.agentName);
47
+
48
+ // Register processors with message flow
49
+ this.messageFlow['processManager'].register('research-digester', this.researchDigester);
50
+ this.messageFlow['processManager'].register('command-learner', this.commandLearner);
51
+ this.messageFlow['processManager'].register('agent-sync', this.agentSync);
52
+
53
+ // Set up event forwarding
54
+ this.setupEventForwarding();
55
+
56
+ // Register sync endpoints if provided
57
+ if (config.syncEndpoints) {
58
+ for (const [agentId, endpoint] of config.syncEndpoints) {
59
+ this.agentSync.registerAgent(agentId, agentId, endpoint);
60
+ }
61
+ }
62
+ }
63
+
64
+ private setupEventForwarding(): void {
65
+ // Forward errors
66
+ this.messageFlow.on('error', (error) => this.emit('error', error));
67
+ this.researchDigester.on('error', (error) => this.emit('error', { source: 'research', error }));
68
+ this.commandLearner.on('error', (error) => this.emit('error', { source: 'commands', error }));
69
+ this.agentSync.on('error', (error) => this.emit('error', { source: 'sync', error }));
70
+
71
+ // Forward interesting events
72
+ this.messageFlow.on('context-built', (data) => this.emit('context-built', data));
73
+ this.researchDigester.on('research-digested', (entry) => this.emit('research-added', entry));
74
+ this.commandLearner.on('patterns-updated', (stats) => this.emit('commands-updated', stats));
75
+ this.agentSync.on('handoff-received', (handoff) => this.emit('task-handoff', handoff));
76
+ }
77
+
78
+ /**
79
+ * Start the memory system
80
+ */
81
+ async start(): Promise<void> {
82
+ // Start message flow (which starts all processors)
83
+ await this.messageFlow.start();
84
+
85
+ // Start dashboard if port specified
86
+ if (this.config.dashboardPort) {
87
+ this.dashboard = new DashboardIntegration({
88
+ port: this.config.dashboardPort,
89
+ messageFlow: this.messageFlow,
90
+ researchDigester: this.researchDigester,
91
+ commandLearner: this.commandLearner,
92
+ agentSync: this.agentSync
93
+ });
94
+
95
+ await this.dashboard.start(this.config.dashboardPort);
96
+ this.emit('dashboard-started', { port: this.config.dashboardPort });
97
+ }
98
+
99
+ this.emit('started');
100
+ }
101
+
102
+ /**
103
+ * Stop the memory system
104
+ */
105
+ async stop(): Promise<void> {
106
+ await this.messageFlow.stop();
107
+ this.emit('stopped');
108
+ }
109
+
110
+ /**
111
+ * Process a message and get enriched context
112
+ */
113
+ async processMessage(message: {
114
+ role: 'user' | 'assistant';
115
+ content: string;
116
+ metadata?: Record<string, any>;
117
+ }): Promise<string> {
118
+ return this.messageFlow.processMessage({
119
+ ...message,
120
+ timestamp: new Date(),
121
+ context: this.config.context
122
+ });
123
+ }
124
+
125
+ /**
126
+ * Add research content (from web pages, PDFs, etc.)
127
+ */
128
+ async addResearch(content: string, metadata?: {
129
+ url?: string;
130
+ title?: string;
131
+ sourceType?: 'web' | 'pdf' | 'markdown' | 'other';
132
+ }): Promise<void> {
133
+ await this.researchDigester.addContent(content, metadata);
134
+ }
135
+
136
+ /**
137
+ * Track a command execution
138
+ */
139
+ async trackCommand(command: string, context: string, output?: string, success: boolean = true): Promise<void> {
140
+ await this.commandLearner.trackCommand(command, context, output, success);
141
+ }
142
+
143
+ /**
144
+ * Share a task with other agents
145
+ */
146
+ async shareTask(task: {
147
+ description: string;
148
+ status: 'active' | 'completed' | 'blocked';
149
+ dependencies?: string[];
150
+ progress?: number;
151
+ notes?: string[];
152
+ }): Promise<string> {
153
+ return this.agentSync.shareTask({
154
+ ...task,
155
+ assignedTo: this.config.agentName,
156
+ dependencies: task.dependencies || [],
157
+ progress: task.progress || 0,
158
+ notes: task.notes || []
159
+ });
160
+ }
161
+
162
+ /**
163
+ * Share an insight
164
+ */
165
+ async shareInsight(insight: string, context?: string): Promise<void> {
166
+ await this.agentSync.shareInsight(insight, context);
167
+ }
168
+
169
+ /**
170
+ * Get current system state
171
+ */
172
+ async getState(): Promise<any> {
173
+ return this.messageFlow.getState();
174
+ }
175
+ }
176
+
177
+ // Export all components for advanced usage
178
+ export { MessageFlowIntegration } from './processors/message-flow-integration';
179
+ export { BackgroundProcessor, ProcessManager } from './processors/background-processor';
180
+ export { CodeIndexer } from './processors/code-indexer';
181
+ export { TaskTracker } from './processors/task-tracker';
182
+ export { ResearchDigester } from './processors/research-digester';
183
+ export { CommandLearner } from './processors/command-learner';
184
+ export { AgentSync } from './processors/agent-sync';
185
+ export { ContextManager } from './processors/context-manager';
186
+ export { MemoryAPIClient } from './processors/memory-api-client';
187
+ export { DashboardIntegration } from './dashboard-integration';