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:
@@ -335,6 +335,8 @@ export interface AgentState {
|
||||
getWorkspaceMindDb: (workspaceId: string) => import('@waggle/core').MindDB | null;
|
||||
/** Close and remove a workspace MindDB from cache. Used before workspace deletion to prevent EBUSY. */
|
||||
closeWorkspaceMind: (workspaceId: string) => void;
|
||||
/** Close a workspace's live sessions and detach it from the shared orchestrator. Used before workspace deletion. */
|
||||
releaseWorkspace: (workspaceId: string) => void;
|
||||
/** List all workspaces (id + name). Used by global memory search. */
|
||||
listWorkspaces: () => Array<{ id: string; name: string }>;
|
||||
/** Currently active workspace ID (null = personal only) */
|
||||
@@ -1301,6 +1303,9 @@ export async function buildLocalServer(config: Partial<LocalConfig> = {}) {
|
||||
setActiveWorkspaceId(null);
|
||||
}
|
||||
};
|
||||
// Until the legacy mind cache is removed, releasing a workspace also closes
|
||||
// its cached mind so the workspace directory can be deleted (A6 EBUSY).
|
||||
const releaseWorkspace = closeWorkspaceMind;
|
||||
|
||||
const getWorkspaceMindDb = (workspaceId: string): MindDB | null => {
|
||||
if (!wsManager.get(workspaceId)) return null;
|
||||
@@ -1328,6 +1333,7 @@ export async function buildLocalServer(config: Partial<LocalConfig> = {}) {
|
||||
activateWorkspaceMind: activateWorkspaceMind,
|
||||
getWorkspaceMindDb,
|
||||
closeWorkspaceMind,
|
||||
releaseWorkspace,
|
||||
listWorkspaces: () => wsManager.list().map(w => ({ id: w.id, name: w.name })),
|
||||
activeWorkspaceId,
|
||||
subagentOrchestrator: null,
|
||||
@@ -1418,7 +1424,7 @@ export async function buildLocalServer(config: Partial<LocalConfig> = {}) {
|
||||
const proactiveCtx: ProactiveContext = {
|
||||
dataDir: fullConfig.dataDir,
|
||||
workspaceManager: wsManager,
|
||||
getWorkspaceMindDb,
|
||||
memory,
|
||||
waggleDb,
|
||||
};
|
||||
|
||||
@@ -1456,12 +1462,12 @@ export async function buildLocalServer(config: Partial<LocalConfig> = {}) {
|
||||
try {
|
||||
switch (proactiveConfig.action) {
|
||||
case 'morning_briefing': {
|
||||
const briefing = generateMorningBriefing(proactiveCtx);
|
||||
const briefing = await generateMorningBriefing(proactiveCtx);
|
||||
if (briefing) emitProactive(briefing);
|
||||
break;
|
||||
}
|
||||
case 'stale_workspace_check': {
|
||||
const staleAlerts = checkStaleWorkspaces(proactiveCtx);
|
||||
const staleAlerts = await checkStaleWorkspaces(proactiveCtx);
|
||||
for (const alert of staleAlerts) emitProactive(alert);
|
||||
break;
|
||||
}
|
||||
@@ -1471,7 +1477,7 @@ export async function buildLocalServer(config: Partial<LocalConfig> = {}) {
|
||||
break;
|
||||
}
|
||||
case 'capability_suggestion': {
|
||||
const suggestion = suggestCapabilities(proactiveCtx);
|
||||
const suggestion = await suggestCapabilities(proactiveCtx);
|
||||
if (suggestion) emitProactive(suggestion);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user