agent-working-memory 0.6.1 → 0.7.1
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 +27 -8
- package/dist/adapters/common.d.ts.map +1 -1
- package/dist/adapters/common.js +9 -1
- package/dist/adapters/common.js.map +1 -1
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +108 -10
- package/dist/api/routes.js.map +1 -1
- package/dist/cli.js +103 -103
- package/dist/core/auto-tagger.d.ts +29 -0
- package/dist/core/auto-tagger.d.ts.map +1 -0
- package/dist/core/auto-tagger.js +139 -0
- package/dist/core/auto-tagger.js.map +1 -0
- package/dist/core/hebbian.d.ts +25 -1
- package/dist/core/hebbian.d.ts.map +1 -1
- package/dist/core/hebbian.js +71 -3
- package/dist/core/hebbian.js.map +1 -1
- package/dist/core/query-expander.d.ts.map +1 -1
- package/dist/core/query-expander.js.map +1 -1
- package/dist/core/reranker.d.ts.map +1 -1
- package/dist/core/reranker.js.map +1 -1
- package/dist/engine/activation.d.ts +22 -4
- package/dist/engine/activation.d.ts.map +1 -1
- package/dist/engine/activation.js +136 -73
- package/dist/engine/activation.js.map +1 -1
- package/dist/engine/consolidation.d.ts +1 -0
- package/dist/engine/consolidation.d.ts.map +1 -1
- package/dist/engine/consolidation.js +149 -9
- package/dist/engine/consolidation.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp.js +123 -84
- package/dist/mcp.js.map +1 -1
- package/dist/storage/sqlite.d.ts +17 -0
- package/dist/storage/sqlite.d.ts.map +1 -1
- package/dist/storage/sqlite.js +73 -0
- package/dist/storage/sqlite.js.map +1 -1
- package/dist/types/engram.d.ts +2 -0
- package/dist/types/engram.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapters/common.ts +9 -1
- package/src/api/routes.ts +723 -600
- package/src/cli.ts +719 -719
- package/src/core/auto-tagger.ts +168 -0
- package/src/core/hebbian.ts +84 -3
- package/src/core/query-expander.ts +0 -1
- package/src/core/reranker.ts +0 -1
- package/src/engine/activation.ts +136 -70
- package/src/engine/consolidation.ts +165 -9
- package/src/index.ts +199 -199
- package/src/mcp.ts +1134 -1099
- package/src/storage/sqlite.ts +77 -0
- package/src/types/engram.ts +2 -0
package/src/storage/sqlite.ts
CHANGED
|
@@ -329,6 +329,83 @@ export class EngramStore {
|
|
|
329
329
|
return (this.db.prepare(query).all(...params) as any[]).map(r => this.rowToEngram(r));
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
+
/**
|
|
333
|
+
* Get engrams across multiple agents (workspace-scoped recall).
|
|
334
|
+
* Used when workspace mode is enabled for hive memory sharing.
|
|
335
|
+
*/
|
|
336
|
+
getEngramsByAgents(agentIds: string[], stage?: EngramStage, includeRetracted: boolean = false): Engram[] {
|
|
337
|
+
if (agentIds.length === 0) return [];
|
|
338
|
+
if (agentIds.length === 1) return this.getEngramsByAgent(agentIds[0], stage, includeRetracted);
|
|
339
|
+
|
|
340
|
+
const placeholders = agentIds.map(() => '?').join(',');
|
|
341
|
+
let query = `SELECT * FROM engrams WHERE agent_id IN (${placeholders})`;
|
|
342
|
+
const params: any[] = [...agentIds];
|
|
343
|
+
|
|
344
|
+
if (stage) {
|
|
345
|
+
query += ' AND stage = ?';
|
|
346
|
+
params.push(stage);
|
|
347
|
+
}
|
|
348
|
+
if (!includeRetracted) {
|
|
349
|
+
query += ' AND retracted = 0';
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return (this.db.prepare(query).all(...params) as any[]).map(r => this.rowToEngram(r));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* BM25 search across multiple agents (workspace-scoped).
|
|
357
|
+
*/
|
|
358
|
+
searchBM25WithRankMultiAgent(agentIds: string[], query: string, limit: number = 10): { engram: Engram; bm25Score: number }[] {
|
|
359
|
+
if (agentIds.length === 0) return [];
|
|
360
|
+
if (agentIds.length === 1) return this.searchBM25WithRank(agentIds[0], query, limit);
|
|
361
|
+
|
|
362
|
+
const sanitized = query
|
|
363
|
+
.replace(/[^\w\s]/g, '')
|
|
364
|
+
.split(/\s+/)
|
|
365
|
+
.filter(w => w.length > 1)
|
|
366
|
+
.map(w => `"${w}"`)
|
|
367
|
+
.join(' OR ');
|
|
368
|
+
|
|
369
|
+
if (!sanitized) return [];
|
|
370
|
+
|
|
371
|
+
try {
|
|
372
|
+
const placeholders = agentIds.map(() => '?').join(',');
|
|
373
|
+
const rows = this.db.prepare(`
|
|
374
|
+
SELECT e.*, rank FROM engrams e
|
|
375
|
+
JOIN engrams_fts ON e.rowid = engrams_fts.rowid
|
|
376
|
+
WHERE engrams_fts MATCH ? AND e.agent_id IN (${placeholders}) AND e.retracted = 0
|
|
377
|
+
ORDER BY rank
|
|
378
|
+
LIMIT ?
|
|
379
|
+
`).all(sanitized, ...agentIds, limit) as any[];
|
|
380
|
+
|
|
381
|
+
return rows.map(r => ({
|
|
382
|
+
engram: this.rowToEngram(r),
|
|
383
|
+
bm25Score: Math.abs(r.rank ?? 0) / (1 + Math.abs(r.rank ?? 0)),
|
|
384
|
+
}));
|
|
385
|
+
} catch {
|
|
386
|
+
return [];
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Get all distinct agent IDs that share a workspace (requires coord_agents table).
|
|
392
|
+
* Returns just the queried agentId if coordination tables don't exist.
|
|
393
|
+
*/
|
|
394
|
+
getWorkspaceAgentIds(agentId: string, workspace: string): string[] {
|
|
395
|
+
try {
|
|
396
|
+
const rows = this.db.prepare(
|
|
397
|
+
`SELECT DISTINCT id FROM coord_agents WHERE workspace = ? AND status != 'dead'`
|
|
398
|
+
).all(workspace) as Array<{ id: string }>;
|
|
399
|
+
const ids = rows.map(r => r.id);
|
|
400
|
+
// Ensure the querying agent is always included
|
|
401
|
+
if (!ids.includes(agentId)) ids.push(agentId);
|
|
402
|
+
return ids;
|
|
403
|
+
} catch {
|
|
404
|
+
// No coordination tables — fall back to single agent
|
|
405
|
+
return [agentId];
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
332
409
|
/**
|
|
333
410
|
* Touch an engram: increment access count, update last_accessed, and
|
|
334
411
|
* nudge confidence upward. Each retrieval is weak evidence the memory
|
package/src/types/engram.ts
CHANGED
|
@@ -186,6 +186,8 @@ export interface ActivationQuery {
|
|
|
186
186
|
internal?: boolean; // Skip access count increment, Hebbian update, and event logging (for system calls)
|
|
187
187
|
memoryType?: MemoryType; // Filter by memory type (episodic, semantic, procedural)
|
|
188
188
|
mode?: QueryMode; // Pipeline mode — 'auto' by default
|
|
189
|
+
workspace?: string; // Search across all agents in this workspace (hive mode). If unset, agent-scoped only.
|
|
190
|
+
bm25Only?: boolean; // Skip embedding — fast text-only retrieval for bulk/benchmark scenarios
|
|
189
191
|
}
|
|
190
192
|
|
|
191
193
|
/**
|