refactor(memory): run agent recall, memory tools and the server on the memory contract (P1.5)
- Orchestrator, memory tools, context loader and pattern write-back use a MemoryStore and a workspace scope instead of MindDB layers; the knowledge graph tools, cognify, memory linker and feedback handler are gone (graph hidden in v1, ADR-0002). - The server opens one mem0 store in <dataDir>/memory/, embedded by the in-process model on first use, and extracts facts about the user in the background with the model the user chose (memoryExtraction setting). - Legacy .mind memories are copied into the store once, in the background; the legacy files are only read. - Weaver consolidation, harvest, wiki, memory import, memory lanes, vector backfill and index reconciliation are removed; agent runs, loops, sub-agent results, connector fetch and the failed-turn capture write through the contract. Workspace sessions no longer hold a mind handle. - FileIndexer and the install audit move to waggle.db; recall date helpers and the reranker are copied into core. - The CLI REPL opens the same memory store.
This commit is contained in:
@@ -11,15 +11,14 @@
|
||||
* "always allow" grants land in Phase B.3.
|
||||
*/
|
||||
|
||||
import type { MindDB } from '@waggle/core';
|
||||
import { HybridSearch } from '@waggle/core';
|
||||
import { workspaceScope, type MemoryStore } from '@waggle/memory-contract';
|
||||
import type { ToolDefinition } from './tools.js';
|
||||
|
||||
export interface CrossWorkspaceToolDeps {
|
||||
/** The workspace this tool instance is running in (the "source"). */
|
||||
sourceWorkspaceId: string;
|
||||
/** Returns the MindDB for the requested workspace, or null if unknown / closed. */
|
||||
getMindForWorkspace: (workspaceId: string) => MindDB | null;
|
||||
/** Memory of every workspace; this tool reads only the target workspace's scope. */
|
||||
memory: MemoryStore;
|
||||
/** Returns the list of known workspace IDs + display names (for discovery). */
|
||||
listWorkspaces: () => Array<{ id: string; name: string }>;
|
||||
/** Returns a file listing for the given workspace (workspace-scoped path). */
|
||||
@@ -36,12 +35,10 @@ export interface CrossWorkspaceToolDeps {
|
||||
* that need binary should extend this signature before wiring it).
|
||||
*/
|
||||
readWorkspaceFile?: (workspaceId: string, relativePath: string) => Promise<string>;
|
||||
/** The embedder used for semantic search. */
|
||||
embedder: import('@waggle/core').Embedder;
|
||||
}
|
||||
|
||||
export function createCrossWorkspaceTools(deps: CrossWorkspaceToolDeps): ToolDefinition[] {
|
||||
const { sourceWorkspaceId, getMindForWorkspace, listWorkspaces, listWorkspaceFiles, readWorkspaceFile, embedder } = deps;
|
||||
const { sourceWorkspaceId, memory, listWorkspaces, listWorkspaceFiles, readWorkspaceFile } = deps;
|
||||
|
||||
const readOtherWorkspace: ToolDefinition = {
|
||||
name: 'read_other_workspace',
|
||||
@@ -49,7 +46,7 @@ export function createCrossWorkspaceTools(deps: CrossWorkspaceToolDeps): ToolDef
|
||||
'Search memory in another workspace. READ-ONLY — never writes.',
|
||||
'Use when the user references something they worked on in a different project.',
|
||||
'Requires the target workspace ID. Call list_workspaces first if unsure.',
|
||||
'Returns ranked memory frames with the target workspace explicitly named',
|
||||
'Returns ranked memories with the target workspace explicitly named',
|
||||
'so you can cite the source clearly ("In Workspace B, you decided...").',
|
||||
'First use on a new target workspace prompts the user for approval.',
|
||||
].join(' '),
|
||||
@@ -94,9 +91,8 @@ export function createCrossWorkspaceTools(deps: CrossWorkspaceToolDeps): ToolDef
|
||||
});
|
||||
}
|
||||
|
||||
const mind = getMindForWorkspace(targetId);
|
||||
if (!mind) {
|
||||
const known = listWorkspaces();
|
||||
const known = listWorkspaces();
|
||||
if (!known.some(w => w.id === targetId)) {
|
||||
return JSON.stringify({
|
||||
error: `Workspace "${targetId}" not found or not accessible.`,
|
||||
knownWorkspaces: known.map(w => ({ id: w.id, name: w.name })),
|
||||
@@ -104,9 +100,8 @@ export function createCrossWorkspaceTools(deps: CrossWorkspaceToolDeps): ToolDef
|
||||
}
|
||||
|
||||
try {
|
||||
const search = new HybridSearch(mind, embedder);
|
||||
const results = await search.search(query, { limit, profile: 'balanced' });
|
||||
const targetName = listWorkspaces().find(w => w.id === targetId)?.name ?? targetId;
|
||||
const results = await memory.search(query, { scopes: [workspaceScope(targetId)], limit });
|
||||
const targetName = known.find(w => w.id === targetId)?.name ?? targetId;
|
||||
|
||||
if (results.length === 0) {
|
||||
return JSON.stringify({
|
||||
@@ -120,10 +115,10 @@ export function createCrossWorkspaceTools(deps: CrossWorkspaceToolDeps): ToolDef
|
||||
}
|
||||
|
||||
const matches = results.map(r => ({
|
||||
content: r.frame.content.slice(0, 500),
|
||||
importance: r.frame.importance,
|
||||
createdAt: r.frame.created_at,
|
||||
score: r.finalScore,
|
||||
content: r.text.slice(0, 500),
|
||||
importance: r.importance,
|
||||
createdAt: r.createdAt,
|
||||
score: r.score,
|
||||
}));
|
||||
|
||||
return JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user