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:
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import * as os from 'node:os';
|
||||
import { MindDB, WorkspaceManager, AwarenessLayer } from '@waggle/core';
|
||||
import { MindDB, WaggleDB, WorkspaceManager, AwarenessLayer, workspaceDataScope } from '@waggle/core';
|
||||
import {
|
||||
generateMorningBriefing,
|
||||
checkStaleWorkspaces,
|
||||
@@ -14,12 +14,19 @@ import {
|
||||
describe('Proactive Handlers', () => {
|
||||
let tmpDir: string;
|
||||
let wsManager: WorkspaceManager;
|
||||
let waggleDb: WaggleDB;
|
||||
const mindDbs = new Map<string, MindDB>();
|
||||
|
||||
/** Awareness items of one workspace, kept in waggle.db under its scope. */
|
||||
function workspaceAwareness(workspaceId: string): AwarenessLayer {
|
||||
return new AwarenessLayer(waggleDb, workspaceDataScope(workspaceId));
|
||||
}
|
||||
|
||||
function makeContext(): ProactiveContext {
|
||||
return {
|
||||
dataDir: tmpDir,
|
||||
workspaceManager: wsManager,
|
||||
waggleDb,
|
||||
getWorkspaceMindDb: (workspaceId: string) => {
|
||||
const existing = mindDbs.get(workspaceId);
|
||||
if (existing) return existing;
|
||||
@@ -39,6 +46,7 @@ describe('Proactive Handlers', () => {
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-proactive-'));
|
||||
wsManager = new WorkspaceManager(tmpDir);
|
||||
waggleDb = WaggleDB.openInDataDir(tmpDir);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -46,6 +54,7 @@ describe('Proactive Handlers', () => {
|
||||
try { db.close(); } catch { /* already closed */ }
|
||||
}
|
||||
mindDbs.clear();
|
||||
waggleDb.close();
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
@@ -73,13 +82,9 @@ describe('Proactive Handlers', () => {
|
||||
it('includes workspace summaries when pending items exist', () => {
|
||||
const ws = wsManager.create({ name: 'My Research', group: 'Work' });
|
||||
|
||||
// Initialize the mind DB (write actual data so MindDB opens it properly)
|
||||
const mindPath = path.join(tmpDir, 'workspaces', ws.id, 'workspace.mind');
|
||||
const db = new MindDB(mindPath);
|
||||
const awareness = new AwarenessLayer(db);
|
||||
const awareness = workspaceAwareness(ws.id);
|
||||
awareness.add('task', 'Review paper draft', 1);
|
||||
awareness.add('pending', 'Waiting for feedback', 0);
|
||||
mindDbs.set(ws.id, db);
|
||||
|
||||
const ctx = makeContext();
|
||||
const result = generateMorningBriefing(ctx);
|
||||
@@ -182,19 +187,13 @@ describe('Proactive Handlers', () => {
|
||||
const ws2 = wsManager.create({ name: 'Project B', group: 'Work' });
|
||||
|
||||
// Add awareness items to ws1
|
||||
const mindPath1 = path.join(tmpDir, 'workspaces', ws1.id, 'workspace.mind');
|
||||
const db1 = new MindDB(mindPath1);
|
||||
const awareness1 = new AwarenessLayer(db1);
|
||||
const awareness1 = workspaceAwareness(ws1.id);
|
||||
awareness1.add('task', 'Fix bug #123', 1);
|
||||
awareness1.add('task', 'Write tests', 0);
|
||||
mindDbs.set(ws1.id, db1);
|
||||
|
||||
// Add awareness items to ws2
|
||||
const mindPath2 = path.join(tmpDir, 'workspaces', ws2.id, 'workspace.mind');
|
||||
const db2 = new MindDB(mindPath2);
|
||||
const awareness2 = new AwarenessLayer(db2);
|
||||
const awareness2 = workspaceAwareness(ws2.id);
|
||||
awareness2.add('pending', 'Waiting for review', 0);
|
||||
mindDbs.set(ws2.id, db2);
|
||||
|
||||
const ctx = makeContext();
|
||||
const result = checkPendingTasks(ctx);
|
||||
@@ -218,13 +217,10 @@ describe('Proactive Handlers', () => {
|
||||
|
||||
it('sets high priority when many pending items', () => {
|
||||
const ws = wsManager.create({ name: 'Busy Project', group: 'Work' });
|
||||
const mindPath = path.join(tmpDir, 'workspaces', ws.id, 'workspace.mind');
|
||||
const db = new MindDB(mindPath);
|
||||
const awareness = new AwarenessLayer(db);
|
||||
const awareness = workspaceAwareness(ws.id);
|
||||
for (let i = 0; i < 5; i++) {
|
||||
awareness.add('task', `Task ${i}`, 1);
|
||||
}
|
||||
mindDbs.set(ws.id, db);
|
||||
|
||||
const ctx = makeContext();
|
||||
const result = checkPendingTasks(ctx);
|
||||
|
||||
Reference in New Issue
Block a user