- 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.
78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
/**
|
|
* Command palette search (GET /api/command/search): the memory facet searches
|
|
* personal memory and the active workspace's memory through the memory contract.
|
|
*/
|
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import Fastify, { type FastifyInstance } from 'fastify';
|
|
import {
|
|
createInMemoryMemoryStore,
|
|
PERSONAL_SCOPE,
|
|
workspaceScope,
|
|
type MemoryStore,
|
|
} from '@waggle/memory-contract';
|
|
import { commandRoutes } from '../../src/local/routes/command.js';
|
|
|
|
describe('GET /api/command/search — memory facet', () => {
|
|
let dataDir: string;
|
|
let memory: MemoryStore;
|
|
let server: FastifyInstance;
|
|
|
|
async function boot(activeWorkspaceId: string | null): Promise<void> {
|
|
server = Fastify({ logger: false });
|
|
server.decorate('localConfig', { dataDir } as never);
|
|
server.decorate('memory', memory);
|
|
server.decorate('workspaceManager', { list: () => [] } as never);
|
|
server.decorate('agentState', {
|
|
activeWorkspaceId,
|
|
commandRegistry: { search: () => [], list: () => [] },
|
|
} as never);
|
|
await server.register(commandRoutes);
|
|
}
|
|
|
|
async function memoryTitles(url: string): Promise<string[]> {
|
|
const res = await server.inject({ method: 'GET', url });
|
|
expect(res.statusCode).toBe(200);
|
|
return (res.json().results as Array<{ type: string; title: string }>)
|
|
.filter((r) => r.type === 'memory')
|
|
.map((r) => r.title)
|
|
.sort();
|
|
}
|
|
|
|
beforeEach(async () => {
|
|
dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-command-search-'));
|
|
memory = createInMemoryMemoryStore();
|
|
await memory.remember({ scope: PERSONAL_SCOPE, text: 'Personal budget review notes' });
|
|
await memory.remember({ scope: workspaceScope('alpha'), text: 'Alpha budget decision' });
|
|
await memory.remember({ scope: workspaceScope('beta'), text: 'Beta budget draft' });
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await server.close();
|
|
fs.rmSync(dataDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it('searches personal memory and the active workspace, not other workspaces', async () => {
|
|
await boot('alpha');
|
|
expect(await memoryTitles('/api/command/search?q=budget'))
|
|
.toEqual(['Alpha budget decision', 'Personal budget review notes']);
|
|
});
|
|
|
|
it('narrows to one scope when asked', async () => {
|
|
await boot('alpha');
|
|
expect(await memoryTitles('/api/command/search?q=budget&scope=personal'))
|
|
.toEqual(['Personal budget review notes']);
|
|
expect(await memoryTitles('/api/command/search?q=budget&scope=workspace'))
|
|
.toEqual(['Alpha budget decision']);
|
|
});
|
|
|
|
it('searches only personal memory when no workspace is active', async () => {
|
|
await boot(null);
|
|
expect(await memoryTitles('/api/command/search?q=budget'))
|
|
.toEqual(['Personal budget review notes']);
|
|
expect(await memoryTitles('/api/command/search?q=budget&scope=workspace')).toEqual([]);
|
|
});
|
|
});
|