@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.
- package/README.md +2 -1
- package/dist/{chunk-MLY4VFOO.js → chunk-BHCDOHSK.js} +3 -3
- package/dist/{chunk-PFZO67E2.js → chunk-DPLCEMEC.js} +2 -2
- package/dist/{chunk-HTLHMXAL.js → chunk-FBQBBAPZ.js} +2 -2
- package/dist/{chunk-NSTTILSN.js → chunk-FK6WYXRM.js} +79 -2
- package/dist/chunk-FK6WYXRM.js.map +1 -0
- package/dist/{chunk-LJHJGDKY.js → chunk-ICSJNKI6.js} +62 -2
- package/dist/chunk-ICSJNKI6.js.map +1 -0
- package/dist/{chunk-4Y7A25UG.js → chunk-IXBIAX76.js} +2 -2
- package/dist/{chunk-ZM7RK5YV.js → chunk-M3A2WRXM.js} +560 -37
- package/dist/chunk-M3A2WRXM.js.map +1 -0
- package/dist/commands/fleet.js +3 -3
- package/dist/commands/init.js +3 -3
- package/dist/commands/start.js +3 -3
- package/dist/commands/upgrade.js +1 -1
- package/dist/commands/watchdog.js +3 -3
- package/dist/dashboard.html +873 -131
- package/dist/index.js +2 -2
- package/dist/main.js +375 -7
- package/dist/main.js.map +1 -1
- package/dist/start.js +1 -1
- package/install.sh +162 -0
- package/package.json +24 -23
- package/packages/memory/Cargo.lock +6480 -0
- package/packages/memory/Cargo.toml +21 -0
- package/packages/memory/src/src/context.rs +179 -0
- package/packages/memory/src/src/embeddings.rs +51 -0
- package/packages/memory/src/src/main.rs +887 -0
- package/packages/memory/src/src/promotion.rs +808 -0
- package/packages/memory/src/src/scoring.rs +142 -0
- package/packages/memory/src/src/store.rs +460 -0
- package/packages/memory/src/src/tasks.rs +321 -0
- package/.pnpmrc.json +0 -1
- package/AUTO-DEBUG-DESIGN.md +0 -267
- package/DASHBOARD-PLAN.md +0 -206
- package/MEMORY-ENHANCEMENT-PLAN.md +0 -211
- package/TOOL-USE-DESIGN.md +0 -173
- package/dist/chunk-LJHJGDKY.js.map +0 -1
- package/dist/chunk-NSTTILSN.js.map +0 -1
- package/dist/chunk-ZM7RK5YV.js.map +0 -1
- package/docs/TOOL-PARITY-PLAN.md +0 -191
- package/src/memory/dashboard-integration.ts +0 -295
- package/src/memory/index.ts +0 -187
- package/src/memory/performance-test.ts +0 -208
- package/src/memory/processors/agent-sync.ts +0 -312
- package/src/memory/processors/command-learner.ts +0 -298
- package/src/memory/processors/memory-api-client.ts +0 -105
- package/src/memory/processors/message-flow-integration.ts +0 -168
- package/src/memory/processors/research-digester.ts +0 -204
- package/test-caitlin-access.md +0 -11
- /package/dist/{chunk-MLY4VFOO.js.map → chunk-BHCDOHSK.js.map} +0 -0
- /package/dist/{chunk-PFZO67E2.js.map → chunk-DPLCEMEC.js.map} +0 -0
- /package/dist/{chunk-HTLHMXAL.js.map → chunk-FBQBBAPZ.js.map} +0 -0
- /package/dist/{chunk-4Y7A25UG.js.map → chunk-IXBIAX76.js.map} +0 -0
package/docs/TOOL-PARITY-PLAN.md
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
# Hivemind Tool Parity Plan
|
|
2
|
-
|
|
3
|
-
*Goal: Bring Hivemind tool capabilities to parity with OpenClaw/Pi, then beyond.*
|
|
4
|
-
|
|
5
|
-
*Created: 2026-03-01 | Last updated: 2026-03-01*
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Context
|
|
10
|
-
|
|
11
|
-
OpenClaw uses [Pi](https://github.com/badlogic/pi-mono/) as its underlying coding agent (see [Armin's article](https://lucumr.pocoo.org/2026/1/31/pi/)). Pi provides 4 core tools: `read`, `write`, `edit`, `bash`. OpenClaw layers orchestration on top: messaging, scheduling, sub-agents, browser control, vision, TTS, device control, and more.
|
|
12
|
-
|
|
13
|
-
Hivemind is a **headless messaging agent** (not a TUI coding agent like Pi), but it needs equivalent capabilities. Hivemind's competitive edge is its **3-layer semantic memory** (L2 episodic + L3 semantic), which neither Pi nor OpenClaw have.
|
|
14
|
-
|
|
15
|
-
**Principle: Build, don't integrate.** Study Pi's source for inspiration, write our own implementations. No external dependency risk, tailored to our headless/messaging paradigm.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## What's Already Implemented ✅
|
|
20
|
-
|
|
21
|
-
### Core Tools (shipped in v0.6.0-v0.7.2)
|
|
22
|
-
| Tool | Status | Notes |
|
|
23
|
-
|------|--------|-------|
|
|
24
|
-
| `shell` | ✅ Shipped | Workspace-scoped, configurable timeout |
|
|
25
|
-
| `read_file` | ✅ Shipped | With offset/limit for large files |
|
|
26
|
-
| `write_file` | ✅ Shipped | Auto-creates directories |
|
|
27
|
-
| `edit_file` | ✅ Shipped | Exact-match find-and-replace |
|
|
28
|
-
| `list_files` | ✅ Shipped | Directory listing |
|
|
29
|
-
| `web_search` | ✅ Shipped | Brave Search API |
|
|
30
|
-
| `web_fetch` | ✅ Shipped | URL → readable text |
|
|
31
|
-
|
|
32
|
-
### Memory Tools (shipped in v0.7.0)
|
|
33
|
-
| Tool | Status | Notes |
|
|
34
|
-
|------|--------|-------|
|
|
35
|
-
| `memory_search` | ✅ Shipped | L2 semantic search per context |
|
|
36
|
-
| `memory_contexts` | ✅ Shipped | List all contexts |
|
|
37
|
-
| `memory_l3` | ✅ Shipped | View promoted knowledge |
|
|
38
|
-
| `memory_cross_search` | ✅ Shipped | Search across all contexts |
|
|
39
|
-
|
|
40
|
-
### Infrastructure (shipped in v0.7.0)
|
|
41
|
-
| Feature | Status | Notes |
|
|
42
|
-
|---------|--------|-------|
|
|
43
|
-
| Agentic tool-use loop | ✅ Shipped | OpenAI-compatible function calling via OpenRouter, max 25 iterations |
|
|
44
|
-
| Tool registry | ✅ Shipped | Pluggable registration system |
|
|
45
|
-
| Session persistence | ✅ Shipped | JSONL per context, survives restarts |
|
|
46
|
-
| Lossless compaction | ✅ Shipped | Saves episodes to L2 before summarizing |
|
|
47
|
-
| MEMORY.md | ✅ Shipped | Global + per-context agent-managed memory files |
|
|
48
|
-
| Skills discovery | ✅ Shipped | Auto-scan workspace/skills/*/SKILL.md |
|
|
49
|
-
| Events system | ✅ Shipped | File-based immediate/one-shot/periodic scheduling |
|
|
50
|
-
| Token budget management | ✅ Shipped | Context limit + response reserve |
|
|
51
|
-
| Dashboard | ✅ Shipped | Request inspector, memory browser, context overview |
|
|
52
|
-
| Service install | ✅ Shipped | launchd services (agent + memory daemon + watchdog) |
|
|
53
|
-
| One-line installer | ✅ Shipped | `curl -sL api.sesame.space/api/v1/hivemind/install | bash -s -- <key>` |
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
## What's Not Implemented Yet
|
|
58
|
-
|
|
59
|
-
### Tier 1 — Essential (Phase 1-2) ✅ COMPLETE
|
|
60
|
-
|
|
61
|
-
| # | Tool/Feature | Status | Tools Added |
|
|
62
|
-
|---|-------------|--------|------------|
|
|
63
|
-
| 1 | **Event/scheduling tools** | ✅ Shipped | `create_event`, `list_events`, `delete_event` |
|
|
64
|
-
| 2 | **Enhanced Sesame messaging** | ✅ Shipped | `send_message` |
|
|
65
|
-
| 3 | **Sub-agent spawning** | ✅ Shipped | `spawn_agent`, `list_agents`, `kill_agent` |
|
|
66
|
-
| 4 | **Web browsing** | ✅ Shipped | `browse` (extract/screenshot/click/type/evaluate) |
|
|
67
|
-
|
|
68
|
-
### Tier 2 — Important (Phase 3) ✅ COMPLETE
|
|
69
|
-
|
|
70
|
-
| # | Tool/Feature | Status | Tools Added |
|
|
71
|
-
|---|-------------|--------|------------|
|
|
72
|
-
| 5 | **Image/vision analysis** | ✅ Shipped | `analyze_image` |
|
|
73
|
-
| 6 | **Git operations** | ✅ Shipped | `git_status`, `git_diff`, `git_commit`, `git_log`, `git_push` |
|
|
74
|
-
| 7 | **Cross-context messaging** | ⬚ Deferred | (existing cross-context search covers most cases) |
|
|
75
|
-
|
|
76
|
-
### Tier 3 — System & Mac Capabilities ✅ COMPLETE
|
|
77
|
-
|
|
78
|
-
| # | Tool/Feature | Status | Tools Added |
|
|
79
|
-
|---|-------------|--------|------------|
|
|
80
|
-
| 8 | **System management** | ✅ Shipped | `system_info`, `process_list`, `process_kill`, `service_control`, `disk_usage`, `network_info` |
|
|
81
|
-
| 9 | **macOS automation** | ✅ Shipped | `run_applescript`, `notify`, `clipboard_read`, `clipboard_write`, `open_url`, `screenshot` |
|
|
82
|
-
| 10 | **Data handling** | ✅ Shipped | `sqlite_query`, `archive_create`, `archive_extract`, `pdf_extract` |
|
|
83
|
-
| 11 | **HTTP server/client** | ✅ Shipped | `http_serve`, `http_stop`, `http_request` |
|
|
84
|
-
| 12 | **File watching** | ✅ Shipped | `watch_start`, `watch_stop`, `watch_list` |
|
|
85
|
-
|
|
86
|
-
### Tier 4 — Future (not yet implemented)
|
|
87
|
-
|
|
88
|
-
| # | Tool/Feature | What It Does | Notes |
|
|
89
|
-
|---|-------------|-------------|-------|
|
|
90
|
-
| 13 | **Skills/extensions system** | Formalized hot-reloadable skills with tool registration | Inspired by Pi's extension system |
|
|
91
|
-
| 14 | **TTS** | Text-to-speech output via API | ElevenLabs API |
|
|
92
|
-
| 15 | **SSH** | Remote machine access | Could use shell + ssh CLI |
|
|
93
|
-
|
|
94
|
-
---
|
|
95
|
-
|
|
96
|
-
## Implementation Plan
|
|
97
|
-
|
|
98
|
-
### Phase 1: Event Tools + Enhanced Messaging
|
|
99
|
-
**Estimate: 1-2 coding sessions**
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
packages/runtime/src/tools/
|
|
103
|
-
events.ts — NEW: create_event, list_events, delete_event
|
|
104
|
-
messaging.ts — NEW: send_message (to any Sesame channel/user)
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
**Event tools:** Wrap the existing `EventsWatcher` infrastructure. Agent can create one-shot (reminders) and periodic (cron-like) events. Events fire as messages processed by the agent.
|
|
108
|
-
|
|
109
|
-
**Messaging tools:** Use existing Sesame SDK to send messages to arbitrary channels. Agent can proactively reach out, not just reply to incoming messages.
|
|
110
|
-
|
|
111
|
-
**Dependencies:** None new. Uses existing EventsWatcher + Sesame SDK.
|
|
112
|
-
|
|
113
|
-
### Phase 2: Sub-agents + Web Browsing
|
|
114
|
-
**Estimate: 3-4 coding sessions**
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
packages/runtime/src/tools/
|
|
118
|
-
spawn.ts — NEW: spawn_agent, list_agents, kill_agent
|
|
119
|
-
browser.ts — NEW: browse_url, browser_action
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
**Sub-agents:** Fork a new agent process with `hivemind start --context <name> --task "<prompt>"`. Parent tracks child PIDs. Results reported back via Sesame message or shared file. Timeout and cleanup built in.
|
|
123
|
-
|
|
124
|
-
**Web browsing:** Headless Playwright for full web interaction. Agent can navigate, click, fill forms, extract content from JS-rendered pages. Single dependency (`playwright`), but it's the right tool for this — curl/fetch can't handle SPAs, authentication flows, or dynamic content.
|
|
125
|
-
|
|
126
|
-
**Why Playwright:** We considered avoiding it (heavy dep), but web browsing is a core capability for agents that need to "do anything a human can do on a computer." Pi/OpenClaw use it. The alternative (shell + curl) only handles static pages.
|
|
127
|
-
|
|
128
|
-
### Phase 3: Vision + Git
|
|
129
|
-
**Estimate: 1-2 coding sessions**
|
|
130
|
-
|
|
131
|
-
```
|
|
132
|
-
packages/runtime/src/tools/
|
|
133
|
-
vision.ts — NEW: analyze_image
|
|
134
|
-
git.ts — NEW: git_status, git_diff, git_commit, git_push
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
**Vision:** Single HTTP call to OpenRouter with vision-capable model. Accept image URL or base64.
|
|
138
|
-
|
|
139
|
-
**Git:** Thin wrappers around git CLI with structured output. Reduces token usage vs raw `shell` git output. Safety: confirmation before push.
|
|
140
|
-
|
|
141
|
-
### Phase 4: Skills/Extensions System
|
|
142
|
-
**Estimate: 2-3 coding sessions**
|
|
143
|
-
|
|
144
|
-
Formalize the existing skills discovery into a proper extension system:
|
|
145
|
-
- Skills can register new tools dynamically
|
|
146
|
-
- Hot-reload on file change (inspired by Pi's extension system)
|
|
147
|
-
- Agent can write and install its own skills
|
|
148
|
-
- Skills persist across restarts
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
## Architecture Notes
|
|
153
|
-
|
|
154
|
-
### Tool Registration Pattern
|
|
155
|
-
All tools follow the existing registry pattern:
|
|
156
|
-
```typescript
|
|
157
|
-
// Each tool file exports a register function
|
|
158
|
-
export function registerEventTools(registry: ToolRegistry, dataDir: string): void {
|
|
159
|
-
registry.register("create_event", description, schema, executor);
|
|
160
|
-
// ...
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### Security Model
|
|
165
|
-
- **Shell:** Workspace-scoped, configurable timeout (existing)
|
|
166
|
-
- **Files:** Scoped to workspace (existing)
|
|
167
|
-
- **Messaging:** Authenticated via existing Sesame connection
|
|
168
|
-
- **Sub-agents:** Inherit parent permissions, isolated context
|
|
169
|
-
- **Events:** File-based, local only
|
|
170
|
-
- **Browser:** Sandboxed Playwright instance, no persistent state
|
|
171
|
-
- **Git:** Confirmation before push
|
|
172
|
-
|
|
173
|
-
### What Hivemind Has That OpenClaw/Pi Don't
|
|
174
|
-
- **3-layer semantic memory** (L2 episodic + L3 semantic with automatic promotion)
|
|
175
|
-
- **Cross-context knowledge sharing** with isolation by default
|
|
176
|
-
- **Memory-augmented responses** (every LLM call enriched with relevant history)
|
|
177
|
-
- **Dashboard** for debugging LLM calls + memory state
|
|
178
|
-
- **Token budget management** with configurable limits
|
|
179
|
-
|
|
180
|
-
This isn't just parity — it's parity + memory, which is the competitive edge.
|
|
181
|
-
|
|
182
|
-
---
|
|
183
|
-
|
|
184
|
-
## Superseded Documents
|
|
185
|
-
|
|
186
|
-
- `TOOL-USE-DESIGN.md` (root) — Original tool architecture design. **Fully implemented** in v0.6.0-v0.7.2. Kept for historical reference.
|
|
187
|
-
- `DASHBOARD-PLAN.md` (root) — Dashboard design. **Fully implemented**. Kept for reference.
|
|
188
|
-
|
|
189
|
-
---
|
|
190
|
-
|
|
191
|
-
*This is the authoritative plan for Hivemind tool development. Update this document as phases complete.*
|
|
@@ -1,295 +0,0 @@
|
|
|
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
|
-
}
|
package/src/memory/index.ts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
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';
|