feat(core): give Waggle its own database, apart from memory (P1.5)
Waggle kept its own tables in the memory database. Before the memory
engine can be replaced by mem0 they need a home of their own.
- add WaggleDB (<dataDir>/waggle.db). Automations, notifications, held
actions, skill hashes, thumbs feedback, cost tracking, the profile card
and awareness items live there. Their stores take a WaggleDB, so passing
a memory database is a type error.
- the profile card and awareness items are now per scope ('personal' or
'workspace:<id>') in one table each, instead of one table per .mind file
- on the first start, copy these tables from personal.mind and every
workspace.mind (importLegacyMindData). The legacy files are only read,
each scope is copied once and a table only while its target is empty.
- copy the logger, injection scanner, external-memory ingress guard,
WorkspaceManager and the embedders from @waggle/hive-mind-core into
@waggle/core, which now re-exports its own copies
- point the server, agent orchestrator and CLI at waggle.db; update the
tests that seeded these tables in a memory database
ADR-0007 records the layout and the licensing question about the copied
files.
This commit is contained in:
@@ -6,24 +6,31 @@
|
||||
* that matters — not trivia, but the kind of context that makes
|
||||
* an assistant feel like it was there the whole time.
|
||||
*
|
||||
* This is the crown jewel test: .mind file = portable brain.
|
||||
* This is the crown jewel test: .mind file = portable brain. The profile
|
||||
* card and awareness items persist next to it in waggle.db (ADR-0007).
|
||||
*/
|
||||
import { describe, it, expect, afterAll } from 'vitest';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import * as os from 'node:os';
|
||||
import { MindDB } from '@waggle/core';
|
||||
import { MindDB, WaggleDB } from '@waggle/core';
|
||||
import { Orchestrator } from '@waggle/agent';
|
||||
import { MockEmbedder } from '../../hive-mind-core/tests/mind/helpers/mock-embedder.js';
|
||||
|
||||
const MIND_PATH = path.join(os.tmpdir(), `waggle-hard-memory-${Date.now()}.mind`);
|
||||
const WAGGLE_DB_PATH = path.join(os.tmpdir(), `waggle-hard-memory-${Date.now()}.waggle.db`);
|
||||
let lastDb: MindDB | null = null;
|
||||
let lastWaggleDb: WaggleDB | null = null;
|
||||
|
||||
function cleanup() {
|
||||
lastDb?.close();
|
||||
lastDb = null;
|
||||
for (const f of [MIND_PATH, MIND_PATH + '-wal', MIND_PATH + '-shm']) {
|
||||
try { if (fs.existsSync(f)) fs.unlinkSync(f); } catch { /* ignore */ }
|
||||
lastWaggleDb?.close();
|
||||
lastWaggleDb = null;
|
||||
for (const base of [MIND_PATH, WAGGLE_DB_PATH]) {
|
||||
for (const f of [base, base + '-wal', base + '-shm']) {
|
||||
try { if (fs.existsSync(f)) fs.unlinkSync(f); } catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +44,8 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
it('Session 1: Project kickoff — identity, decisions, architecture', async () => {
|
||||
const db = new MindDB(MIND_PATH);
|
||||
const orch = new Orchestrator({ db, embedder });
|
||||
const waggleDb = new WaggleDB(WAGGLE_DB_PATH);
|
||||
const orch = new Orchestrator({ db, waggleDb, embedder });
|
||||
|
||||
// Set up identity
|
||||
orch.getIdentity().create({
|
||||
@@ -93,6 +101,7 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
kg.createRelation(paymentSvc.id, stripe.id, 'integrates', 1.0);
|
||||
|
||||
db.close();
|
||||
waggleDb.close();
|
||||
});
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -100,7 +109,8 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
it('Session 2: Implementation day — code decisions, bugs found, PR reviews', async () => {
|
||||
const db = new MindDB(MIND_PATH);
|
||||
const orch = new Orchestrator({ db, embedder });
|
||||
const waggleDb = new WaggleDB(WAGGLE_DB_PATH);
|
||||
const orch = new Orchestrator({ db, waggleDb, embedder });
|
||||
|
||||
await orch.executeTool('save_memory', {
|
||||
content: 'Started implementing the charge endpoint. Using chi router with middleware chain: logging → auth → rate-limit → handler. Bob suggested using errgroup for parallel Stripe + fraud-check calls — good idea, adopted it.',
|
||||
@@ -133,6 +143,7 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
kg.createEntity('pr', 'PR #87: Charge handler', { author: 'Bob Kumar', status: 'changes-requested', issue: 'race condition on DB write' });
|
||||
|
||||
db.close();
|
||||
waggleDb.close();
|
||||
});
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -140,7 +151,8 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
it('Session 3: Midweek check-in — credentials arrived, new blocker, scope change', async () => {
|
||||
const db = new MindDB(MIND_PATH);
|
||||
const orch = new Orchestrator({ db, embedder });
|
||||
const waggleDb = new WaggleDB(WAGGLE_DB_PATH);
|
||||
const orch = new Orchestrator({ db, waggleDb, embedder });
|
||||
|
||||
await orch.executeTool('save_memory', {
|
||||
content: 'Alice delivered Stripe production credentials to Vault as promised. Verified access works. Removed from pending items.',
|
||||
@@ -168,6 +180,7 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
});
|
||||
|
||||
db.close();
|
||||
waggleDb.close();
|
||||
});
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -176,7 +189,9 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
it('Session 4 (COLD START): Agent must recall project state without being told', async () => {
|
||||
const db = new MindDB(MIND_PATH);
|
||||
lastDb = db; // Track for cleanup
|
||||
const orch = new Orchestrator({ db, embedder });
|
||||
const waggleDb = new WaggleDB(WAGGLE_DB_PATH);
|
||||
lastWaggleDb = waggleDb;
|
||||
const orch = new Orchestrator({ db, waggleDb, embedder });
|
||||
|
||||
// ─── Test A: Identity survives ───
|
||||
const identity = await orch.executeTool('get_identity', {});
|
||||
@@ -279,5 +294,6 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
expect(prompt).toContain('search_memory');
|
||||
|
||||
db.close();
|
||||
waggleDb.close();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user