refactor(server): read workspace state, briefings and workspaces from the memory contract (P1.5)
- Workspace state, the "Workspace Now" block, the home briefing and the proactive handlers read the workspace's memory through server.memory: decisions are memories of kind 'decision', critical ones or ones worded as decisions; summaries list memories most important first. They no longer open workspace .mind files, so the builders are async and ProactiveContext carries `memory` instead of `getWorkspaceMindDb`. - The home briefing counts extracted personal facts that are neither confirmed nor archived as awaiting review (memory-status.ts). - Workspace routes count memories through the contract, seed template starter memories with remember() in the background (origin 'workspace-template'), export memories through list(), and deleting a workspace forgets its memory scope and clears its awareness items before the directory is removed; the delete is refused if forgetting fails. agentState.releaseWorkspace() replaces closeWorkspaceMind for callers. - The command palette searches personal memory and the active workspace's memory (UF-033). - chat.ts drops the MindDB-flake diagnostics; the mind cache they guarded no longer serves chat turns.
This commit is contained in:
@@ -6,12 +6,11 @@
|
||||
* (B8 / PRD §12.1 "greeting with user name") — unit + via inject.
|
||||
* - applyPriorityRanking(): recency + bounded pending-item boost
|
||||
* (PRD §12.1 "ranked by recency and priority") — unit.
|
||||
* - needsReviewCount (J08/D6): personal-mind frames with metadata status
|
||||
* 'unreviewed' are counted; the count matches what the Memory Center
|
||||
* "Needs review" view lists.
|
||||
* - needsReviewCount (J08/D6): extracted personal facts that are neither
|
||||
* confirmed nor archived are counted.
|
||||
*
|
||||
* Scaffolding follows memory-center.test.ts: Fastify inject + MindDB(':memory:')
|
||||
* + plain-object decorators, plus an in-memory waggle.db for the profile card.
|
||||
* Scaffolding: Fastify inject + an in-memory memory store + 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
|
||||
@@ -20,14 +19,14 @@
|
||||
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import Fastify from 'fastify';
|
||||
import { MindDB, IdentityLayer, WaggleDB } from '@waggle/core';
|
||||
import { IdentityLayer, WaggleDB } from '@waggle/core';
|
||||
import { createInMemoryMemoryStore, PERSONAL_SCOPE, workspaceScope, type MemoryStore } from '@waggle/memory-contract';
|
||||
import {
|
||||
homeRoutes,
|
||||
personalizeGreeting,
|
||||
applyPriorityRanking,
|
||||
type RecentWorkspaceCard,
|
||||
} from '../../src/local/routes/home.js';
|
||||
import { memoryCenterRoutes } from '../../src/local/routes/memory-center.js';
|
||||
import {
|
||||
buildUpcomingSchedules,
|
||||
type CronScheduleLike,
|
||||
@@ -43,7 +42,7 @@ interface TestWorkspace {
|
||||
}
|
||||
|
||||
function createTestServer(
|
||||
db: MindDB,
|
||||
memory: MemoryStore,
|
||||
workspaces: TestWorkspace[] = [],
|
||||
cronSchedules: CronScheduleLike[] = [],
|
||||
) {
|
||||
@@ -51,18 +50,7 @@ function createTestServer(
|
||||
const waggleDb = new WaggleDB(':memory:');
|
||||
server.decorate('waggleDb', waggleDb);
|
||||
server.addHook('onClose', async () => waggleDb.close());
|
||||
server.decorate('multiMind', {
|
||||
personal: db,
|
||||
getFrameStore: () => undefined,
|
||||
search: () => [],
|
||||
workspace: undefined,
|
||||
setWorkspace: () => {},
|
||||
});
|
||||
server.decorate('agentState', {
|
||||
getWorkspaceMindDb: () => undefined,
|
||||
activateWorkspaceMind: () => undefined,
|
||||
listWorkspaces: () => [],
|
||||
});
|
||||
server.decorate('memory', memory);
|
||||
server.decorate('workspaceManager', {
|
||||
list: () => workspaces,
|
||||
get: (id: string) => workspaces.find((w) => w.id === id),
|
||||
@@ -73,7 +61,6 @@ function createTestServer(
|
||||
});
|
||||
// localConfig intentionally absent — see file header.
|
||||
server.register(homeRoutes);
|
||||
server.register(memoryCenterRoutes);
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -128,17 +115,16 @@ describe('applyPriorityRanking (P2 — recency + pending boost)', () => {
|
||||
});
|
||||
|
||||
describe('GET /api/home/briefing (P2 — J08 needsReviewCount + greeting)', () => {
|
||||
let db: MindDB;
|
||||
let memory: MemoryStore;
|
||||
let server: ReturnType<typeof Fastify>;
|
||||
|
||||
afterEach(async () => {
|
||||
await server.close();
|
||||
db.close();
|
||||
});
|
||||
|
||||
function boot(workspaces: TestWorkspace[] = []) {
|
||||
db = new MindDB(':memory:');
|
||||
server = createTestServer(db, workspaces);
|
||||
memory = createInMemoryMemoryStore();
|
||||
server = createTestServer(memory, workspaces);
|
||||
}
|
||||
|
||||
it('empty mind → needsReviewCount 0, isFirstRun true', async () => {
|
||||
@@ -150,35 +136,25 @@ describe('GET /api/home/briefing (P2 — J08 needsReviewCount + greeting)', () =
|
||||
expect(briefing.needsReviewCount).toBe(0);
|
||||
});
|
||||
|
||||
it('counts only personal-mind memories with status unreviewed', async () => {
|
||||
it('counts extracted personal facts that are neither confirmed nor archived', async () => {
|
||||
boot();
|
||||
// Seed via the same routes the product uses: create (status active) then
|
||||
// flip one to unreviewed — the C33 harvest lifecycle state.
|
||||
const m1 = await server.inject({
|
||||
method: 'POST', url: '/api/memory',
|
||||
payload: { content: 'Imported fact awaiting review.' },
|
||||
const extracted = (text: string, metadata: Record<string, unknown> = {}) => memory.remember({
|
||||
scope: PERSONAL_SCOPE, text, origin: 'extraction', source: 'agent_inferred', kind: 'profile', metadata,
|
||||
});
|
||||
expect(m1.statusCode).toBe(200);
|
||||
const m2 = await server.inject({
|
||||
method: 'POST', url: '/api/memory',
|
||||
payload: { content: 'Already-reviewed fact.' },
|
||||
await extracted('Prefers short answers.');
|
||||
await extracted('Lives in Belgrade.');
|
||||
await extracted('Works on Waggle.', { confirmedAt: '2026-10-24T10:00:00.000Z' });
|
||||
await extracted('Used to live in Novi Sad.', { archived: true });
|
||||
// Memories the user saved are not up for review.
|
||||
await memory.remember({ scope: PERSONAL_SCOPE, text: 'Saved by the user.', source: 'user_stated' });
|
||||
// Workspace memories are not counted: the "Needs review" view is personal.
|
||||
await memory.remember({
|
||||
scope: workspaceScope('w1'), text: 'Workspace fact.', origin: 'extraction', source: 'agent_inferred',
|
||||
});
|
||||
expect(m2.statusCode).toBe(200);
|
||||
|
||||
const patch = await server.inject({
|
||||
method: 'PATCH', url: `/api/memory/${m1.json().id}`,
|
||||
payload: { status: 'unreviewed' },
|
||||
});
|
||||
expect(patch.statusCode).toBe(200);
|
||||
|
||||
const res = await server.inject({ method: 'GET', url: '/api/home/briefing' });
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.json().needsReviewCount).toBe(1);
|
||||
|
||||
// The count must agree with what the deep-linked "Needs review" view shows
|
||||
// — same query the Memory Center fires (status filter + limit=200).
|
||||
const list = await server.inject({ method: 'GET', url: '/api/memory?status=unreviewed&limit=200' });
|
||||
expect(list.json().count).toBe(1);
|
||||
expect(res.json().needsReviewCount).toBe(2);
|
||||
});
|
||||
|
||||
it('briefing slices recent workspaces to 6, newest first (route-level ranking wiring)', async () => {
|
||||
@@ -220,12 +196,11 @@ describe('GET /api/home/briefing (P2 — J08 needsReviewCount + greeting)', () =
|
||||
});
|
||||
|
||||
describe('upNext schedule aggregation (global jobs dedup + future-only)', () => {
|
||||
let db: MindDB;
|
||||
let memory: MemoryStore;
|
||||
let server: ReturnType<typeof Fastify>;
|
||||
|
||||
afterEach(async () => {
|
||||
await server.close();
|
||||
db.close();
|
||||
});
|
||||
|
||||
const FUTURE = new Date(Date.now() + 60 * 60 * 1000).toISOString();
|
||||
@@ -248,8 +223,7 @@ describe('upNext schedule aggregation (global jobs dedup + future-only)', () =>
|
||||
}));
|
||||
|
||||
it('a global schedule surfaces once across multiple workspaces, not once per workspace', async () => {
|
||||
db = new MindDB(':memory:');
|
||||
server = createTestServer(db, threeWorkspaces, [
|
||||
server = createTestServer(createInMemoryMemoryStore(), threeWorkspaces, [
|
||||
globalSchedule(1, 'Memory compaction', FUTURE),
|
||||
]);
|
||||
const res = await server.inject({ method: 'GET', url: '/api/home/briefing' });
|
||||
@@ -260,8 +234,7 @@ describe('upNext schedule aggregation (global jobs dedup + future-only)', () =>
|
||||
});
|
||||
|
||||
it('past-due schedules never display as upcoming', async () => {
|
||||
db = new MindDB(':memory:');
|
||||
server = createTestServer(db, threeWorkspaces, [
|
||||
server = createTestServer(createInMemoryMemoryStore(), threeWorkspaces, [
|
||||
globalSchedule(1, 'Memory compaction', PAST),
|
||||
globalSchedule(2, 'Harvest sync', FUTURE),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user