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:
@@ -363,9 +363,11 @@ describe('Local Server Mode', () => {
|
||||
(SELECT COUNT(*) FROM memory_frames) AS frames,
|
||||
(SELECT COUNT(*) FROM memory_frames_fts) AS indexed,
|
||||
(SELECT COUNT(*) FROM knowledge_entities) AS entities,
|
||||
(SELECT COUNT(*) FROM knowledge_relations) AS relations,
|
||||
(SELECT COUNT(*) FROM awareness) AS awareness
|
||||
(SELECT COUNT(*) FROM knowledge_relations) AS relations
|
||||
`).get() as Record<string, number>,
|
||||
awareness: (server.waggleDb.getDatabase().prepare(
|
||||
'SELECT COUNT(*) AS count FROM awareness_items',
|
||||
).get() as { count: number }).count,
|
||||
auditEvents: (getAuditDb(tmpDir).prepare(
|
||||
'SELECT COUNT(*) AS count FROM audit_events',
|
||||
).get() as { count: number }).count,
|
||||
@@ -403,9 +405,11 @@ describe('Local Server Mode', () => {
|
||||
(SELECT COUNT(*) FROM memory_frames) AS frames,
|
||||
(SELECT COUNT(*) FROM memory_frames_fts) AS indexed,
|
||||
(SELECT COUNT(*) FROM knowledge_entities) AS entities,
|
||||
(SELECT COUNT(*) FROM knowledge_relations) AS relations,
|
||||
(SELECT COUNT(*) FROM awareness) AS awareness
|
||||
(SELECT COUNT(*) FROM knowledge_relations) AS relations
|
||||
`).get() as Record<string, number>,
|
||||
awareness: (server.waggleDb.getDatabase().prepare(
|
||||
'SELECT COUNT(*) AS count FROM awareness_items',
|
||||
).get() as { count: number }).count,
|
||||
auditEvents: (getAuditDb(tmpDir).prepare(
|
||||
'SELECT COUNT(*) AS count FROM audit_events',
|
||||
).get() as { count: number }).count,
|
||||
@@ -566,7 +570,9 @@ describe('Local Server Mode', () => {
|
||||
const counts = () => ({
|
||||
sessions: (db.prepare('SELECT COUNT(*) AS count FROM sessions').get() as { count: number }).count,
|
||||
frames: (db.prepare('SELECT COUNT(*) AS count FROM memory_frames').get() as { count: number }).count,
|
||||
awareness: (db.prepare('SELECT COUNT(*) AS count FROM awareness').get() as { count: number }).count,
|
||||
awareness: (server.waggleDb.getDatabase().prepare(
|
||||
'SELECT COUNT(*) AS count FROM awareness_items',
|
||||
).get() as { count: number }).count,
|
||||
auditEvents: (getAuditDb(tmpDir).prepare(
|
||||
'SELECT COUNT(*) AS count FROM audit_events',
|
||||
).get() as { count: number }).count,
|
||||
@@ -610,9 +616,7 @@ describe('Local Server Mode', () => {
|
||||
kind: 'task',
|
||||
});
|
||||
expect(new FrameStore(server.multiMind.personal).getById(Number(body.frameId))?.content).toBe(content);
|
||||
const awareness = server.multiMind.personal.getDatabase().prepare(
|
||||
'SELECT content FROM awareness WHERE id = ?',
|
||||
).get(body.awarenessId) as { content: string } | undefined;
|
||||
const awareness = new waggleCore.AwarenessLayer(server.waggleDb).get(body.awarenessId);
|
||||
expect(awareness?.content).toBe(content);
|
||||
});
|
||||
|
||||
@@ -1011,7 +1015,7 @@ describe('Local Server Mode', () => {
|
||||
model: 'anthropic/claude-sonnet-4-6',
|
||||
input: 'Charge after UTC midnight on a trace started before it',
|
||||
});
|
||||
firstServer.multiMind.personal.getDatabase().prepare(`
|
||||
firstServer.waggleDb.getDatabase().prepare(`
|
||||
UPDATE execution_traces SET created_at = datetime('now', '-1 day') WHERE id = ?
|
||||
`).run(midnightTraceId);
|
||||
firstServer.traceStore.recordCost(
|
||||
@@ -1031,7 +1035,7 @@ describe('Local Server Mode', () => {
|
||||
input: 'Recover a later settlement whose ledger write failed',
|
||||
});
|
||||
firstServer.traceStore.recordCost(recoveredTraceId, 0.018);
|
||||
firstServer.multiMind.personal.getDatabase().prepare(`
|
||||
firstServer.waggleDb.getDatabase().prepare(`
|
||||
CREATE TRIGGER fail_test_trace_spend
|
||||
BEFORE INSERT ON execution_trace_spend
|
||||
WHEN NEW.trace_id = ${recoveredTraceId}
|
||||
@@ -1039,7 +1043,7 @@ describe('Local Server Mode', () => {
|
||||
`).run();
|
||||
expect(() => firstServer.traceStore.recordCost(recoveredTraceId, 0.018))
|
||||
.toThrow('simulated ledger failure');
|
||||
firstServer.multiMind.personal.getDatabase().prepare('DROP TRIGGER fail_test_trace_spend').run();
|
||||
firstServer.waggleDb.getDatabase().prepare('DROP TRIGGER fail_test_trace_spend').run();
|
||||
firstServer.traceStore.finalize(recoveredTraceId, {
|
||||
outcome: 'abandoned',
|
||||
output: 'second settlement ledger write failed',
|
||||
|
||||
Reference in New Issue
Block a user