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:
shumeiko.it
2026-10-23 14:31:28 +02:00
parent 20567ecb10
commit ad2ca875cb
65 changed files with 6131 additions and 201 deletions

View File

@@ -11,7 +11,8 @@
* "Needs review" view lists.
*
* Scaffolding follows memory-center.test.ts: Fastify inject + MindDB(':memory:')
* + plain-object decorators. localConfig is intentionally absent → the
* + plain-object decorators, plus an in-memory waggle.db for the profile card.
* localConfig is intentionally absent → the
* buildWorkspaceState call inside the briefing loop throws and is absorbed by
* the route's per-workspace try/catch (pendingCount degrades to 0), and
* emitAuditEvent stays a safe no-op.
@@ -19,7 +20,7 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import Fastify from 'fastify';
import { MindDB, IdentityLayer } from '@waggle/core';
import { MindDB, IdentityLayer, WaggleDB } from '@waggle/core';
import {
homeRoutes,
personalizeGreeting,
@@ -47,6 +48,9 @@ function createTestServer(
cronSchedules: CronScheduleLike[] = [],
) {
const server = Fastify({ logger: false });
const waggleDb = new WaggleDB(':memory:');
server.decorate('waggleDb', waggleDb);
server.addHook('onClose', async () => waggleDb.close());
server.decorate('multiMind', {
personal: db,
getFrameStore: () => undefined,
@@ -196,7 +200,7 @@ describe('GET /api/home/briefing (P2 — J08 needsReviewCount + greeting)', () =
it('greets by name when identity is seeded (B8)', async () => {
boot([{ id: 'w1', name: 'Alpha', group: 'Personal', created: new Date().toISOString() }]);
new IdentityLayer(db).create({
new IdentityLayer(server.waggleDb).create({
name: 'Marko', role: 'Founder', department: 'Egzakta',
personality: '', capabilities: '', system_prompt: '',
});