@sesamespace/hivemind 0.10.0 → 0.11.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 (48) hide show
  1. package/.pnpmrc.json +1 -0
  2. package/AUTO-DEBUG-DESIGN.md +267 -0
  3. package/AUTOMATIC-MEMORY-MANAGEMENT.md +109 -0
  4. package/DASHBOARD-PLAN.md +206 -0
  5. package/MEMORY-ENHANCEMENT-PLAN.md +211 -0
  6. package/TOOL-USE-DESIGN.md +173 -0
  7. package/dist/{chunk-FBQBBAPZ.js → chunk-4C6B2AMB.js} +2 -2
  8. package/dist/{chunk-FK6WYXRM.js → chunk-4YXOQGQC.js} +2 -2
  9. package/dist/{chunk-IXBIAX76.js → chunk-K6KL2VD6.js} +2 -2
  10. package/dist/{chunk-BHCDOHSK.js → chunk-LYL5GG2F.js} +3 -3
  11. package/dist/{chunk-M3A2WRXM.js → chunk-OB6OXLPC.js} +430 -2
  12. package/dist/chunk-OB6OXLPC.js.map +1 -0
  13. package/dist/{chunk-DPLCEMEC.js → chunk-ZA4NWNS6.js} +2 -2
  14. package/dist/commands/fleet.js +3 -3
  15. package/dist/commands/init.js +3 -3
  16. package/dist/commands/start.js +3 -3
  17. package/dist/commands/watchdog.js +3 -3
  18. package/dist/dashboard.html +100 -60
  19. package/dist/index.js +2 -2
  20. package/dist/main.js +6 -6
  21. package/dist/start.js +1 -1
  22. package/docs/TOOL-PARITY-PLAN.md +191 -0
  23. package/package.json +23 -24
  24. package/src/memory/dashboard-integration.ts +295 -0
  25. package/src/memory/index.ts +187 -0
  26. package/src/memory/performance-test.ts +208 -0
  27. package/src/memory/processors/agent-sync.ts +312 -0
  28. package/src/memory/processors/command-learner.ts +298 -0
  29. package/src/memory/processors/memory-api-client.ts +105 -0
  30. package/src/memory/processors/message-flow-integration.ts +168 -0
  31. package/src/memory/processors/research-digester.ts +204 -0
  32. package/test-caitlin-access.md +11 -0
  33. package/dist/chunk-M3A2WRXM.js.map +0 -1
  34. package/install.sh +0 -162
  35. package/packages/memory/Cargo.lock +0 -6480
  36. package/packages/memory/Cargo.toml +0 -21
  37. package/packages/memory/src/src/context.rs +0 -179
  38. package/packages/memory/src/src/embeddings.rs +0 -51
  39. package/packages/memory/src/src/main.rs +0 -887
  40. package/packages/memory/src/src/promotion.rs +0 -808
  41. package/packages/memory/src/src/scoring.rs +0 -142
  42. package/packages/memory/src/src/store.rs +0 -460
  43. package/packages/memory/src/src/tasks.rs +0 -321
  44. /package/dist/{chunk-FBQBBAPZ.js.map → chunk-4C6B2AMB.js.map} +0 -0
  45. /package/dist/{chunk-FK6WYXRM.js.map → chunk-4YXOQGQC.js.map} +0 -0
  46. /package/dist/{chunk-IXBIAX76.js.map → chunk-K6KL2VD6.js.map} +0 -0
  47. /package/dist/{chunk-BHCDOHSK.js.map → chunk-LYL5GG2F.js.map} +0 -0
  48. /package/dist/{chunk-DPLCEMEC.js.map → chunk-ZA4NWNS6.js.map} +0 -0
@@ -0,0 +1,211 @@
1
+ # Memory Enhancement Plan — Automatic Context Management
2
+
3
+ ## Vision
4
+ Transform Hivemind's memory system from passive storage to active context management. Background processes continuously organize, index, and surface relevant information without agent intervention.
5
+
6
+ ## Core Enhancements
7
+
8
+ ### 1. Code Context Tracking
9
+ **Background Process:** `code-indexer`
10
+ - Monitors file access patterns (which files the agent reads/writes)
11
+ - Extracts key structures: functions, classes, interfaces, schemas
12
+ - Maintains a "working set" of active code elements
13
+ - Updates git commit context automatically
14
+ - Indexes by: project, language, purpose, last-accessed
15
+
16
+ **Data Structure:**
17
+ ```json
18
+ {
19
+ "type": "code_context",
20
+ "project": "hivemind",
21
+ "file": "packages/runtime/src/agent.ts",
22
+ "elements": [
23
+ {
24
+ "name": "processMessage",
25
+ "type": "function",
26
+ "signature": "(msg: Message): Promise<Response>",
27
+ "purpose": "Core message processing loop",
28
+ "dependencies": ["memory-client", "router"]
29
+ }
30
+ ],
31
+ "last_accessed": "2024-01-15T10:30:00Z",
32
+ "access_count": 15,
33
+ "git_context": {
34
+ "branch": "feature/memory-enhancement",
35
+ "last_commit": "abc123",
36
+ "modified": true
37
+ }
38
+ }
39
+ ```
40
+
41
+ ### 2. Web Research Digestion
42
+ **Background Process:** `research-digester`
43
+ - Monitors web fetch/browse operations
44
+ - Extracts key concepts, APIs, solutions
45
+ - Links research to active tasks/projects
46
+ - Builds knowledge graph of related concepts
47
+ - Identifies patterns across multiple sources
48
+
49
+ **Data Structure:**
50
+ ```json
51
+ {
52
+ "type": "research_insight",
53
+ "url": "https://docs.example.com/api",
54
+ "project": "sesame-integration",
55
+ "extracted": {
56
+ "key_concepts": ["OAuth flow", "webhook endpoints"],
57
+ "code_examples": ["const auth = await getToken()..."],
58
+ "warnings": ["Rate limit: 100 req/min"],
59
+ "related_to": ["auth-implementation", "rate-limiting"]
60
+ },
61
+ "timestamp": "2024-01-15T09:00:00Z",
62
+ "referenced_count": 3
63
+ }
64
+ ```
65
+
66
+ ### 3. Task State Management
67
+ **Background Process:** `task-tracker`
68
+ - Monitors agent actions and maps to task progress
69
+ - Detects task transitions (started, blocked, completed)
70
+ - Tracks dependencies and blockers
71
+ - Identifies patterns in task completion
72
+ - Surfaces relevant context when returning to a task
73
+
74
+ **Data Structure:**
75
+ ```json
76
+ {
77
+ "type": "task_state",
78
+ "id": "implement-dashboard",
79
+ "project": "hivemind",
80
+ "status": "in_progress",
81
+ "progress": {
82
+ "completed": ["setup routes", "basic UI"],
83
+ "current": "implement request filtering",
84
+ "next": ["add export functionality", "write tests"]
85
+ },
86
+ "context": {
87
+ "key_files": ["src/dashboard/server.js", "src/dashboard/index.html"],
88
+ "recent_decisions": ["use server-sent events for real-time updates"],
89
+ "blockers": [],
90
+ "time_spent": "3.5 hours"
91
+ },
92
+ "last_updated": "2024-01-15T11:00:00Z"
93
+ }
94
+ ```
95
+
96
+ ### 4. Tool Usage Patterns
97
+ **Background Process:** `command-learner`
98
+ - Tracks successful command sequences
99
+ - Identifies common patterns and workflows
100
+ - Builds "recipes" for common tasks
101
+ - Learns from failures and corrections
102
+ - Suggests optimizations
103
+
104
+ **Data Structure:**
105
+ ```json
106
+ {
107
+ "type": "tool_pattern",
108
+ "name": "github-push-workflow",
109
+ "triggers": ["git push", "push changes"],
110
+ "sequence": [
111
+ {"tool": "git_status", "check": "has_changes"},
112
+ {"tool": "git_add", "params": {"files": "."}}
113
+ {"tool": "git_commit", "params": {"message": "<generated>"}},
114
+ {"tool": "git_push", "params": {"remote": "origin"}}
115
+ ],
116
+ "success_rate": 0.95,
117
+ "last_used": "2024-01-15T10:00:00Z",
118
+ "variations": ["with-specific-files", "force-push"]
119
+ }
120
+ ```
121
+
122
+ ### 5. Cross-Agent Awareness
123
+ **Background Process:** `agent-sync`
124
+ - Monitors Sesame channels for other agent activity
125
+ - Extracts "public knowledge" from agent interactions
126
+ - Tracks handoff points and collaboration patterns
127
+ - Maintains agent capability registry
128
+ - Identifies complementary skills
129
+
130
+ **Data Structure:**
131
+ ```json
132
+ {
133
+ "type": "agent_knowledge",
134
+ "agent": "bailey",
135
+ "capabilities": ["rust development", "system architecture"],
136
+ "current_focus": ["hivemind dashboard", "memory optimization"],
137
+ "collaboration_points": [
138
+ {
139
+ "task": "dashboard-implementation",
140
+ "status": "bailey-implementing",
141
+ "handoff_ready": "2024-01-16"
142
+ }
143
+ ],
144
+ "last_seen": "2024-01-15T11:30:00Z"
145
+ }
146
+ ```
147
+
148
+ ## Implementation Architecture
149
+
150
+ ### Background Process Framework
151
+ ```typescript
152
+ interface BackgroundProcess {
153
+ name: string;
154
+ interval: number; // milliseconds
155
+ async run(context: ProcessContext): Promise<void>;
156
+ async shouldRun(context: ProcessContext): Promise<boolean>;
157
+ }
158
+
159
+ class ProcessManager {
160
+ private processes: Map<string, BackgroundProcess>;
161
+ private memory: MemoryClient;
162
+
163
+ async start() {
164
+ for (const [name, process] of this.processes) {
165
+ setInterval(async () => {
166
+ if (await process.shouldRun(this.context)) {
167
+ await process.run(this.context);
168
+ }
169
+ }, process.interval);
170
+ }
171
+ }
172
+ }
173
+ ```
174
+
175
+ ### Memory Indexing Strategy
176
+ 1. **Write-through cache**: All observations written immediately to L2
177
+ 2. **Background indexing**: Processes run every 30s-5min depending on type
178
+ 3. **Smart batching**: Group related updates to minimize memory churn
179
+ 4. **Relevance scoring**: Continuously update scores based on access patterns
180
+ 5. **Compression**: Older entries compressed/summarized, recent kept detailed
181
+
182
+ ### Context Injection
183
+ When building LLM prompts, the system will:
184
+ 1. Query active task state
185
+ 2. Include relevant code context (files, functions being worked on)
186
+ 3. Add recent research/documentation insights
187
+ 4. Include tool patterns for likely next actions
188
+ 5. Add cross-agent awareness if collaborating
189
+
190
+ ### Local Processing Power Usage
191
+ - **Embedding generation**: Ollama with local models (no API calls)
192
+ - **Pattern matching**: Rust-based processors for speed
193
+ - **Index management**: LanceDB for vector operations
194
+ - **File watching**: Native OS APIs for efficiency
195
+ - **Git operations**: libgit2 bindings for speed
196
+
197
+ ## Benefits
198
+ 1. **Zero cognitive load**: Agents don't think about memory management
199
+ 2. **Rich context**: Every request includes highly relevant information
200
+ 3. **Learning system**: Gets better at predicting needed context over time
201
+ 4. **Collaborative**: Agents automatically aware of each other's work
202
+ 5. **Efficient**: Background processing keeps LLM calls focused
203
+
204
+ ## Next Steps
205
+ 1. Implement the background process framework in TypeScript
206
+ 2. Create the first processor: `code-indexer`
207
+ 3. Test with real agent workflows
208
+ 4. Add remaining processors incrementally
209
+ 5. Optimize based on dashboard metrics
210
+
211
+ This system will make every Hivemind agent dramatically more capable without any changes to their prompts or behavior.
@@ -0,0 +1,173 @@
1
+ # Hivemind Tool Use — Architecture Design
2
+
3
+ ## Current State
4
+
5
+ The LLM client does simple chat completions: `messages[] → response.content`. No tool/function calling.
6
+
7
+ ## Goal
8
+
9
+ Full agentic tool-use loop matching OpenClaw capabilities, with Hivemind's memory system as a differentiator.
10
+
11
+ ## Architecture
12
+
13
+ ### 1. Tool Calling Protocol (OpenAI-compatible, works with OpenRouter)
14
+
15
+ The OpenAI chat completions API supports `tools` (function definitions) and `tool_choice`. When the model wants to use a tool, it returns a `tool_calls` array instead of (or alongside) content. We then execute the tool, append the result as a `tool` role message, and call the model again.
16
+
17
+ ```
18
+ User message
19
+
20
+ LLM (with tools defined)
21
+
22
+ If tool_calls → execute tools → append results → call LLM again (loop)
23
+ If content only → return response
24
+ ```
25
+
26
+ This is a **while loop**, not a single call. The model may chain multiple tool calls before producing a final text response.
27
+
28
+ ### 2. Key Data Structures
29
+
30
+ ```typescript
31
+ interface ToolDefinition {
32
+ name: string;
33
+ description: string;
34
+ parameters: JSONSchema; // JSON Schema for function params
35
+ }
36
+
37
+ interface ToolCall {
38
+ id: string;
39
+ type: "function";
40
+ function: { name: string; arguments: string }; // arguments is JSON string
41
+ }
42
+
43
+ interface ToolResult {
44
+ tool_call_id: string;
45
+ role: "tool";
46
+ content: string; // result as string
47
+ }
48
+
49
+ // Extended message types
50
+ interface AssistantMessage {
51
+ role: "assistant";
52
+ content: string | null;
53
+ tool_calls?: ToolCall[];
54
+ }
55
+
56
+ interface ToolMessage {
57
+ role: "tool";
58
+ tool_call_id: string;
59
+ content: string;
60
+ }
61
+ ```
62
+
63
+ ### 3. Tool Registry
64
+
65
+ A simple registry where tools are registered with:
66
+ - Name
67
+ - Description (for the LLM)
68
+ - JSON Schema for parameters
69
+ - Executor function: `(params: any) => Promise<string>`
70
+
71
+ ```typescript
72
+ class ToolRegistry {
73
+ private tools: Map<string, { def: ToolDefinition; exec: (params: any) => Promise<string> }>;
74
+
75
+ register(name, description, schema, executor): void;
76
+ getDefinitions(): ToolDefinition[]; // For LLM API call
77
+ execute(name: string, params: any): Promise<string>; // Run a tool
78
+ }
79
+ ```
80
+
81
+ ### 4. The Agentic Loop (in Agent.processMessage)
82
+
83
+ ```
84
+ 1. Build messages (system + history + user)
85
+ 2. Call LLM with tools
86
+ 3. While response has tool_calls:
87
+ a. For each tool_call: execute, collect result
88
+ b. Append assistant message (with tool_calls) to messages
89
+ c. Append tool result messages
90
+ d. Call LLM again with updated messages
91
+ 4. Return final text content
92
+ 5. Store in memory (include tool usage summary)
93
+ ```
94
+
95
+ **Safety limits:**
96
+ - Max iterations per turn (e.g., 25)
97
+ - Max total tokens per turn
98
+ - Tool execution timeout (per tool)
99
+ - Dangerous command confirmation (optional)
100
+
101
+ ### 5. Phase 1 Tools
102
+
103
+ #### `shell` (exec)
104
+ - Run a shell command, return stdout/stderr
105
+ - Working directory: `~/hivemind/workspace`
106
+ - Timeout: 30s default, configurable
107
+ - Safety: no `rm -rf /` etc.
108
+
109
+ #### `read_file`
110
+ - Read file contents (with optional offset/limit for large files)
111
+ - Returns text content or error
112
+
113
+ #### `write_file`
114
+ - Write content to a file (creates dirs if needed)
115
+ - Returns success/failure
116
+
117
+ #### `edit_file`
118
+ - Find and replace exact text in a file
119
+ - oldText → newText pattern (surgical edits)
120
+
121
+ #### `web_search`
122
+ - Search via Brave API
123
+ - Returns titles, URLs, snippets
124
+
125
+ #### `web_fetch`
126
+ - Fetch URL, extract markdown
127
+ - Returns readable content
128
+
129
+ ### 6. Memory Integration
130
+
131
+ Tool calls and results should be stored in memory, but summarized:
132
+ - Don't store full file contents in L2 episodes
133
+ - Store: "Used shell to run `git status`, found 3 modified files"
134
+ - L3 promotion can learn patterns: "For git operations, agent uses shell tool"
135
+
136
+ ### 7. Config
137
+
138
+ ```toml
139
+ [tools]
140
+ enabled = true
141
+ max_iterations = 25
142
+ shell_timeout_s = 30
143
+ workspace = "workspace"
144
+
145
+ [tools.web_search]
146
+ api_key = "" # or from vault
147
+ ```
148
+
149
+ ### 8. Implementation Order
150
+
151
+ 1. **ToolRegistry class** — registration, definitions, execution
152
+ 2. **LLMClient.chatWithTools()** — extended chat that handles tool_calls
153
+ 3. **Agentic loop in Agent** — the while loop with safety limits
154
+ 4. **shell tool** — most impactful, enables everything
155
+ 5. **File tools** — read/write/edit
156
+ 6. **Web tools** — search/fetch
157
+ 7. **Memory integration** — summarize tool usage in episodes
158
+
159
+ ### 9. OpenRouter Compatibility
160
+
161
+ OpenRouter passes through tool definitions to the underlying model. Most models support tools:
162
+ - Claude: Native tool_use
163
+ - GPT-4: Native function_calling
164
+ - Gemini: Native function declarations
165
+
166
+ The OpenAI-compatible format works for all of them through OpenRouter.
167
+
168
+ ### 10. Safety Considerations
169
+
170
+ - **Sandbox**: Tools run on the agent's machine. File access should be scoped to workspace.
171
+ - **Confirmation**: Optionally require human approval for destructive operations.
172
+ - **Logging**: All tool calls logged to request logger for debugging.
173
+ - **Rate limiting**: Prevent runaway tool loops.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  FleetManager
3
- } from "./chunk-IXBIAX76.js";
3
+ } from "./chunk-K6KL2VD6.js";
4
4
 
5
5
  // packages/cli/src/commands/fleet.ts
6
6
  function formatUptime(seconds) {
@@ -183,4 +183,4 @@ Commands:
183
183
  export {
184
184
  runFleetCommand
185
185
  };
186
- //# sourceMappingURL=chunk-FBQBBAPZ.js.map
186
+ //# sourceMappingURL=chunk-4C6B2AMB.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SesameClient,
3
3
  getClaudeCodeOAuthToken
4
- } from "./chunk-M3A2WRXM.js";
4
+ } from "./chunk-OB6OXLPC.js";
5
5
 
6
6
  // packages/cli/src/commands/init.ts
7
7
  import { resolve, dirname } from "path";
@@ -436,4 +436,4 @@ Options:
436
436
  export {
437
437
  runInitCommand
438
438
  };
439
- //# sourceMappingURL=chunk-FK6WYXRM.js.map
439
+ //# sourceMappingURL=chunk-4YXOQGQC.js.map
@@ -7,7 +7,7 @@ import {
7
7
  SesameClient2 as SesameClient,
8
8
  WORKER_ROUTES,
9
9
  createLogger
10
- } from "./chunk-M3A2WRXM.js";
10
+ } from "./chunk-OB6OXLPC.js";
11
11
 
12
12
  // packages/runtime/src/watchdog.ts
13
13
  import { execSync } from "child_process";
@@ -1095,4 +1095,4 @@ export {
1095
1095
  WorkerMemorySync,
1096
1096
  PrimaryMemorySync
1097
1097
  };
1098
- //# sourceMappingURL=chunk-IXBIAX76.js.map
1098
+ //# sourceMappingURL=chunk-K6KL2VD6.js.map
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Watchdog
3
- } from "./chunk-IXBIAX76.js";
3
+ } from "./chunk-K6KL2VD6.js";
4
4
  import {
5
5
  defaultSentinelConfig,
6
6
  loadConfig
7
- } from "./chunk-M3A2WRXM.js";
7
+ } from "./chunk-OB6OXLPC.js";
8
8
 
9
9
  // packages/cli/src/commands/watchdog.ts
10
10
  import { resolve } from "path";
@@ -76,4 +76,4 @@ Options:
76
76
  export {
77
77
  runWatchdogCommand
78
78
  };
79
- //# sourceMappingURL=chunk-BHCDOHSK.js.map
79
+ //# sourceMappingURL=chunk-LYL5GG2F.js.map