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,17 +2,20 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import { MindDB } from '@waggle/core';
|
||||
import { MindDB, WaggleDB } from '@waggle/core';
|
||||
import { buildWorkspaceNowBlock, formatWorkspaceNowPrompt, type WorkspaceNowBlock } from '../../src/local/routes/workspace-context.js';
|
||||
|
||||
describe('workspace-context', () => {
|
||||
let tmpDir: string;
|
||||
let waggleDb: WaggleDB;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-ctx-test-'));
|
||||
waggleDb = WaggleDB.openInDataDir(tmpDir);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
waggleDb.close();
|
||||
// On Windows, SQLite WAL files may keep handles open briefly; best-effort cleanup
|
||||
try {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
@@ -92,6 +95,7 @@ describe('workspace-context', () => {
|
||||
|
||||
const result = buildWorkspaceNowBlock({
|
||||
dataDir: tmpDir,
|
||||
waggleDb,
|
||||
workspaceId: 'does-not-exist',
|
||||
wsManager,
|
||||
activateWorkspaceMind: noopActivate,
|
||||
@@ -112,6 +116,7 @@ describe('workspace-context', () => {
|
||||
|
||||
const result = buildWorkspaceNowBlock({
|
||||
dataDir: tmpDir,
|
||||
waggleDb,
|
||||
workspaceId: 'empty-ws',
|
||||
wsManager,
|
||||
activateWorkspaceMind: noopActivate,
|
||||
@@ -134,6 +139,7 @@ describe('workspace-context', () => {
|
||||
|
||||
const result = buildWorkspaceNowBlock({
|
||||
dataDir: tmpDir,
|
||||
waggleDb,
|
||||
workspaceId: 'zero-ws',
|
||||
wsManager,
|
||||
activateWorkspaceMind: noopActivate,
|
||||
@@ -169,6 +175,7 @@ describe('workspace-context', () => {
|
||||
|
||||
const result = buildWorkspaceNowBlock({
|
||||
dataDir: tmpDir,
|
||||
waggleDb,
|
||||
workspaceId: 'rich-ws',
|
||||
wsManager,
|
||||
activateWorkspaceMind,
|
||||
@@ -217,6 +224,7 @@ describe('workspace-context', () => {
|
||||
|
||||
const result = buildWorkspaceNowBlock({
|
||||
dataDir: tmpDir,
|
||||
waggleDb,
|
||||
workspaceId: 'capped-ws',
|
||||
wsManager,
|
||||
activateWorkspaceMind: noopActivate,
|
||||
|
||||
Reference in New Issue
Block a user