@membank/mcp 0.12.0 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -37,13 +37,12 @@ const ResolveReviewArgsSchema = z.object({ id: z.string().min(1) });
37
37
  //#endregion
38
38
  //#region src/synthesis/agent-loop.ts
39
39
  const SYNTHESIS_SYSTEM_PROMPT = "You are a memory synthesizer. Your job is to read the user's stored memories and produce a concise, well-structured summary of what's most important to remember about this user — their preferences, corrections, decisions, and key facts. Pinned memories are higher fidelity and should be weighted more heavily. Exclude transient or ephemeral details. Output plain text suitable for injection into an LLM context window. Be concise — target 200-400 words.";
40
- const MAX_TURNS = 3;
41
40
  var SynthesisAgentLoop = class {
42
41
  #tools;
43
42
  constructor(tools, _config) {
44
43
  this.#tools = tools;
45
44
  }
46
- async run(scope) {
45
+ async run(scope, projectHash) {
47
46
  const mcpServer = createSdkMcpServer({
48
47
  name: "membank-synthesis-tools",
49
48
  version: "1.0.0",
@@ -57,7 +56,8 @@ var SynthesisAgentLoop = class {
57
56
  text: await this.#tools.queryMemory({
58
57
  query: q,
59
58
  limit,
60
- global: isGlobal
59
+ global: isGlobal,
60
+ projectHash
61
61
  })
62
62
  }] };
63
63
  }, { annotations: { readOnlyHint: true } }), tool("get_memory_summary", "Returns aggregate stats: total memories, counts by type, pinned count, review queue size", {}, async () => {
@@ -74,7 +74,6 @@ var SynthesisAgentLoop = class {
74
74
  prompt,
75
75
  options: {
76
76
  model: "claude-haiku-4-5-20251001",
77
- maxTurns: MAX_TURNS,
78
77
  systemPrompt: SYNTHESIS_SYSTEM_PROMPT,
79
78
  mcpServers: { "membank-synthesis-tools": mcpServer },
80
79
  allowedTools: ["query_memory", "get_memory_summary"],
@@ -162,7 +161,8 @@ var SynthesisEngine = class {
162
161
  async #synthesizeScope(scope) {
163
162
  this.#synthRepo.markInFlight(scope);
164
163
  try {
165
- const content = await this.#agentLoop.run(scope);
164
+ const projectHash = scope === "global" ? void 0 : scope;
165
+ const content = await this.#agentLoop.run(scope, projectHash);
166
166
  const sourceHash = this.#synthRepo.computeSourceMemoryHash(scope);
167
167
  this.#synthRepo.saveSynthesis(scope, content, sourceHash);
168
168
  this.#failureCounts.delete(scope);
@@ -202,7 +202,7 @@ function loadSynthesisConfig() {
202
202
  function buildSynthesisTools(repo, query) {
203
203
  return {
204
204
  queryMemory: async (args) => {
205
- const projectHash = args.global === true ? void 0 : (await resolveProject()).hash;
205
+ const projectHash = args.global === true ? void 0 : args.projectHash ?? (await resolveProject()).hash;
206
206
  const results = await query.query({
207
207
  query: args.query,
208
208
  projectHash,
@@ -725,17 +725,24 @@ async function runSynthesis(scope) {
725
725
  if (!isSynthesisEnabled()) throw new Error("Synthesis is not enabled. Run: membank config set synthesis.enabled true");
726
726
  const db = DatabaseManager.open();
727
727
  const embedding = new EmbeddingService();
728
- const repo = new MemoryRepository(db, embedding, new ProjectRepository(db));
728
+ const projects = new ProjectRepository(db);
729
+ const repo = new MemoryRepository(db, embedding, projects);
729
730
  const queryEngine = new QueryEngine(db, embedding, repo);
730
731
  const synthRepo = new SynthesisRepository(db);
731
732
  const agentLoop = new SynthesisAgentLoop(buildSynthesisTools(repo, queryEngine), { enabled: true });
732
- synthRepo.markInFlight(scope);
733
+ let resolvedScope = scope;
734
+ if (scope !== "global" && !/^[0-9a-f]{16}$/.test(scope)) {
735
+ const project = projects.getByName(scope);
736
+ if (project !== void 0) resolvedScope = project.scopeHash;
737
+ }
738
+ const projectHash = resolvedScope === "global" ? void 0 : resolvedScope;
739
+ synthRepo.markInFlight(resolvedScope);
733
740
  try {
734
- const [content, sourceHash] = await Promise.all([agentLoop.run(scope), Promise.resolve(synthRepo.computeSourceMemoryHash(scope))]);
735
- synthRepo.saveSynthesis(scope, content, sourceHash);
741
+ const [content, sourceHash] = await Promise.all([agentLoop.run(resolvedScope, projectHash), Promise.resolve(synthRepo.computeSourceMemoryHash(resolvedScope))]);
742
+ synthRepo.saveSynthesis(resolvedScope, content, sourceHash);
736
743
  return content;
737
744
  } catch (err) {
738
- synthRepo.clearInFlight(scope);
745
+ synthRepo.clearInFlight(resolvedScope);
739
746
  throw err;
740
747
  } finally {
741
748
  db.close();
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["#tools","#synthRepo","#config","#agentLoop","#dirtyScopes","#failureCounts","#running","#debounceLoop","#loopTimer","#inFlightPromises","#synthesizeScope","#scheduleNextCycle"],"sources":["../src/schemas.ts","../src/synthesis/agent-loop.ts","../src/synthesis/engine.ts","../src/server.ts","../src/index.ts"],"sourcesContent":["import { MemoryTypeSchema } from \"@membank/core\";\nimport { z } from \"zod\";\n\nexport const SaveMemoryArgsSchema = z.object({\n content: z.string().min(1),\n type: MemoryTypeSchema,\n tags: z.array(z.string()).optional(),\n global: z.boolean().optional(),\n});\n\nexport const UpdateMemoryArgsSchema = z.object({\n id: z.string().min(1),\n content: z.string().min(1).optional(),\n type: MemoryTypeSchema.optional(),\n tags: z.array(z.string()).optional(),\n});\n\nexport const DeleteMemoryArgsSchema = z.object({\n id: z.string().min(1),\n});\n\nexport const QueryMemoryArgsSchema = z.object({\n query: z.string().min(1),\n type: MemoryTypeSchema.optional(),\n limit: z.number().int().positive().optional(),\n includePinned: z.boolean().optional(),\n global: z.boolean().optional(),\n});\n\nexport const MigrateArgsSchema = z.discriminatedUnion(\"mode\", [\n z.object({ mode: z.literal(\"list\") }),\n z.object({ mode: z.literal(\"run\"), name: z.string().min(1) }),\n]);\n\nexport const PinMemoryArgsSchema = z.object({\n id: z.string().min(1),\n});\n\nexport const ResolveReviewArgsSchema = z.object({\n id: z.string().min(1),\n});\n","import { createSdkMcpServer, query, tool } from \"@anthropic-ai/claude-agent-sdk\";\nimport { z } from \"zod\";\n\nconst SYNTHESIS_SYSTEM_PROMPT =\n \"You are a memory synthesizer. Your job is to read the user's stored memories and produce a concise, well-structured summary of what's most important to remember about this user — their preferences, corrections, decisions, and key facts. Pinned memories are higher fidelity and should be weighted more heavily. Exclude transient or ephemeral details. Output plain text suitable for injection into an LLM context window. Be concise — target 200-400 words.\";\n\nconst MAX_TURNS = 3;\n\nexport interface SynthesisConfig {\n enabled: boolean;\n maxTokensPerRun?: number;\n debounceMs?: number;\n stalenessDays?: number;\n inFlightTimeoutMs?: number;\n}\n\nexport interface SynthesisTools {\n queryMemory: (args: { query: string; limit?: number; global?: boolean }) => Promise<string>;\n getMemorySummary: () => Promise<string>;\n}\n\nexport class SynthesisAgentLoop {\n readonly #tools: SynthesisTools;\n\n constructor(tools: SynthesisTools, _config: SynthesisConfig) {\n this.#tools = tools;\n }\n\n async run(scope: string): Promise<string> {\n const queryMemoryTool = tool(\n \"query_memory\",\n \"Search memories by semantic similarity\",\n {\n query: z.string().describe(\"Search text\"),\n limit: z.number().optional().describe(\"Maximum results to return\"),\n global: z\n .boolean()\n .optional()\n .describe(\"Query global memories only when true, otherwise current project scope\"),\n },\n async ({ query: q, limit, global: isGlobal }) => {\n const result = await this.#tools.queryMemory({\n query: q,\n limit,\n global: isGlobal,\n });\n return { content: [{ type: \"text\" as const, text: result }] };\n },\n { annotations: { readOnlyHint: true } }\n );\n\n const getMemorySummaryTool = tool(\n \"get_memory_summary\",\n \"Returns aggregate stats: total memories, counts by type, pinned count, review queue size\",\n {},\n async () => {\n const result = await this.#tools.getMemorySummary();\n return { content: [{ type: \"text\" as const, text: result }] };\n },\n { annotations: { readOnlyHint: true } }\n );\n\n const mcpServer = createSdkMcpServer({\n name: \"membank-synthesis-tools\",\n version: \"1.0.0\",\n tools: [queryMemoryTool, getMemorySummaryTool],\n });\n\n const isGlobal = scope === \"global\";\n const scopeDescription = isGlobal ? \"global (across all projects)\" : `project scope: ${scope}`;\n\n const prompt = `Synthesize the memories for ${scopeDescription}. Use get_memory_summary first to understand the overall state, then use query_memory to retrieve relevant memories (query with broad terms like \"preferences\", \"corrections\", \"decisions\", \"key facts\"). After gathering information, produce a concise synthesis of the most important things to remember about this user. Output only the synthesis text — no preamble, no metadata.`;\n\n const startTime = Date.now();\n\n const env = Object.fromEntries(\n Object.entries(process.env).filter((e): e is [string, string] => e[1] !== undefined)\n );\n\n const agentQuery = query({\n prompt,\n options: {\n model: \"claude-haiku-4-5-20251001\",\n maxTurns: MAX_TURNS,\n systemPrompt: SYNTHESIS_SYSTEM_PROMPT,\n mcpServers: { \"membank-synthesis-tools\": mcpServer },\n allowedTools: [\"query_memory\", \"get_memory_summary\"],\n permissionMode: \"bypassPermissions\",\n env,\n },\n });\n\n let finalResult = \"\";\n\n for await (const message of agentQuery) {\n if (message.type === \"result\") {\n if (message.subtype === \"success\") {\n finalResult = message.result;\n } else {\n const details =\n \"errors\" in message && Array.isArray(message.errors)\n ? `: ${message.errors.join(\"; \")}`\n : \"\";\n throw new Error(`Synthesis agent failed: ${message.subtype}${details}`);\n }\n }\n }\n\n const durationMs = Date.now() - startTime;\n process.stderr.write(`membank synthesis: scope=${scope} duration=${durationMs}ms\\n`);\n\n if (finalResult === \"\") {\n throw new Error(\"Synthesis agent returned empty result\");\n }\n\n return finalResult;\n }\n}\n","import type { DatabaseManager, SynthesisRepository } from \"@membank/core\";\nimport type { SynthesisAgentLoop, SynthesisConfig } from \"./agent-loop.js\";\n\nconst DEFAULT_DEBOUNCE_MS = 45_000;\nconst DEFAULT_IN_FLIGHT_TIMEOUT_MS = 120_000;\nconst MAX_BACKOFF_MULTIPLIER = 5;\n\nexport class SynthesisEngine {\n readonly #synthRepo: SynthesisRepository;\n readonly #config: SynthesisConfig;\n readonly #agentLoop: SynthesisAgentLoop;\n readonly #dirtyScopes = new Set<string>();\n readonly #failureCounts = new Map<string, number>();\n #running = false;\n #loopTimer: ReturnType<typeof setTimeout> | undefined;\n #inFlightPromises = new Map<string, Promise<void>>();\n\n constructor(\n _db: DatabaseManager,\n synthRepo: SynthesisRepository,\n config: SynthesisConfig,\n agentLoop: SynthesisAgentLoop\n ) {\n this.#synthRepo = synthRepo;\n this.#config = config;\n this.#agentLoop = agentLoop;\n }\n\n async init(): Promise<void> {\n // Clear in_flight_since markers older than the timeout — they belong to a dead process.\n this.#synthRepo.clearStaleInFlight(\n this.#config.inFlightTimeoutMs ?? DEFAULT_IN_FLIGHT_TIMEOUT_MS\n );\n this.#synthRepo.expireStale();\n\n const stale = this.#synthRepo.getExpiredOrDirtyScopes();\n for (const { scope } of stale) {\n this.#dirtyScopes.add(scope);\n }\n\n this.#running = true;\n // Process any scopes discovered at startup immediately, then begin the periodic cycle\n await this.#debounceLoop();\n }\n\n shutdown(): Promise<void> {\n this.#running = false;\n\n if (this.#loopTimer !== undefined) {\n clearTimeout(this.#loopTimer);\n this.#loopTimer = undefined;\n }\n\n const inFlight = [...this.#inFlightPromises.values()];\n if (inFlight.length === 0) return Promise.resolve();\n\n const graceMs = 5_000;\n return Promise.race([\n Promise.allSettled(inFlight).then(() => undefined),\n new Promise<void>((resolve) => setTimeout(resolve, graceMs)),\n ]);\n }\n\n markDirty(scope: string): void {\n this.#dirtyScopes.add(scope);\n }\n\n #scheduleNextCycle(): void {\n if (!this.#running) return;\n const debounceMs = this.#config.debounceMs ?? DEFAULT_DEBOUNCE_MS;\n this.#loopTimer = setTimeout(() => {\n void this.#debounceLoop();\n }, debounceMs);\n }\n\n async #debounceLoop(): Promise<void> {\n const scopesToProcess = [...this.#dirtyScopes];\n\n for (const scope of scopesToProcess) {\n const inFlightTimeoutMs = this.#config.inFlightTimeoutMs ?? DEFAULT_IN_FLIGHT_TIMEOUT_MS;\n const synthesis = this.#synthRepo.getSynthesis(scope);\n\n if (synthesis?.inFlightSince !== null && synthesis?.inFlightSince !== undefined) {\n const inFlightMs = Date.now() - new Date(synthesis.inFlightSince).getTime();\n if (inFlightMs < inFlightTimeoutMs) {\n continue;\n }\n // Stale in-flight — clear it and allow resynthesis\n this.#synthRepo.clearInFlight(scope);\n }\n\n this.#dirtyScopes.delete(scope);\n const promise = this.#synthesizeScope(scope).finally(() => {\n this.#inFlightPromises.delete(scope);\n });\n this.#inFlightPromises.set(scope, promise);\n }\n\n this.#scheduleNextCycle();\n }\n\n async #synthesizeScope(scope: string): Promise<void> {\n this.#synthRepo.markInFlight(scope);\n\n try {\n const content = await this.#agentLoop.run(scope);\n const sourceHash = this.#synthRepo.computeSourceMemoryHash(scope);\n this.#synthRepo.saveSynthesis(scope, content, sourceHash);\n this.#failureCounts.delete(scope);\n } catch (err) {\n const failures = (this.#failureCounts.get(scope) ?? 0) + 1;\n this.#failureCounts.set(scope, failures);\n\n // Exponential backoff: re-queue with multiplied debounce up to MAX_BACKOFF_MULTIPLIER\n const backoffMultiplier = Math.min(failures, MAX_BACKOFF_MULTIPLIER);\n const backoffMs = (this.#config.debounceMs ?? DEFAULT_DEBOUNCE_MS) * backoffMultiplier;\n\n process.stderr.write(\n `membank synthesis: error for scope=${scope} failures=${failures} backoff=${backoffMs}ms: ${err instanceof Error ? err.message : String(err)}\\n`\n );\n\n setTimeout(() => {\n this.#dirtyScopes.add(scope);\n }, backoffMs);\n\n this.#synthRepo.clearInFlight(scope);\n }\n }\n}\n","import { readFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport {\n DatabaseManager,\n EmbeddingService,\n isSynthesisEnabled,\n listMemoryTypes,\n MEMORY_TYPE_VALUES,\n MemoryRepository,\n MIGRATIONS,\n PIN_BUDGET_THRESHOLD,\n ProjectRepository,\n QueryEngine,\n resolveProject,\n runScopeToProjectsMigration,\n SynthesisRepository,\n} from \"@membank/core\";\nimport { Server } from \"@modelcontextprotocol/sdk/server\";\nimport {\n CallToolRequestSchema,\n ErrorCode,\n ListToolsRequestSchema,\n McpError,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { ZodError } from \"zod\";\nimport {\n DeleteMemoryArgsSchema,\n MigrateArgsSchema,\n PinMemoryArgsSchema,\n QueryMemoryArgsSchema,\n ResolveReviewArgsSchema,\n SaveMemoryArgsSchema,\n UpdateMemoryArgsSchema,\n} from \"./schemas.js\";\nimport type { SynthesisConfig, SynthesisTools } from \"./synthesis/index.js\";\nimport { SynthesisAgentLoop, SynthesisEngine } from \"./synthesis/index.js\";\n\nconst SERVER_NAME = \"membank\";\nconst SERVER_VERSION = \"0.1.0\";\n\nexport interface CoreServices {\n db: DatabaseManager;\n embedding: EmbeddingService;\n repo: MemoryRepository;\n query: QueryEngine;\n projects: ProjectRepository;\n synthEngine?: SynthesisEngine;\n}\n\nexport interface ServerOptions {\n dbPath?: string;\n useInMemoryDb?: boolean;\n}\n\nfunction loadSynthesisConfig(): SynthesisConfig {\n const configPath = join(homedir(), \".membank\", \"config.json\");\n try {\n const raw = readFileSync(configPath, \"utf8\");\n const parsed = JSON.parse(raw) as {\n synthesis?: Partial<SynthesisConfig>;\n };\n return {\n enabled: parsed.synthesis?.enabled === true,\n maxTokensPerRun: parsed.synthesis?.maxTokensPerRun,\n debounceMs: parsed.synthesis?.debounceMs,\n stalenessDays: parsed.synthesis?.stalenessDays,\n inFlightTimeoutMs: parsed.synthesis?.inFlightTimeoutMs,\n };\n } catch {\n return { enabled: false };\n }\n}\n\nexport function buildSynthesisTools(repo: MemoryRepository, query: QueryEngine): SynthesisTools {\n return {\n queryMemory: async (args) => {\n const projectHash = args.global === true ? undefined : (await resolveProject()).hash;\n const results = await query.query({\n query: args.query,\n projectHash,\n limit: args.limit ?? 20,\n includePinned: true,\n });\n return JSON.stringify(results);\n },\n getMemorySummary: async () => JSON.stringify(repo.stats()),\n };\n}\n\nexport function initCore(options: ServerOptions = {}): CoreServices {\n const db = options.useInMemoryDb\n ? DatabaseManager.openInMemory()\n : DatabaseManager.open(options.dbPath);\n const embedding = new EmbeddingService();\n const projects = new ProjectRepository(db);\n const repo = new MemoryRepository(db, embedding, projects);\n const query = new QueryEngine(db, embedding, repo);\n\n const synthConfig = loadSynthesisConfig();\n let synthEngine: SynthesisEngine | undefined;\n\n if (synthConfig.enabled) {\n const synthRepo = new SynthesisRepository(db);\n const agentLoop = new SynthesisAgentLoop(buildSynthesisTools(repo, query), synthConfig);\n synthEngine = new SynthesisEngine(db, synthRepo, synthConfig, agentLoop);\n }\n\n return { db, embedding, repo, query, projects, synthEngine };\n}\n\nfunction parseArgs<T>(schema: { parse: (v: unknown) => T }, raw: unknown): T {\n try {\n return schema.parse(raw);\n } catch (e) {\n const msg = e instanceof ZodError ? (e.issues[0]?.message ?? e.message) : String(e);\n throw new McpError(ErrorCode.InvalidParams, msg);\n }\n}\n\nexport function createServer(core: CoreServices): Server {\n const server = new Server(\n { name: SERVER_NAME, version: SERVER_VERSION },\n { capabilities: { tools: {} } }\n );\n\n server.setRequestHandler(ListToolsRequestSchema, () => ({\n tools: [\n {\n name: \"list_memory_types\",\n description: \"Returns the ordered list of memory type values supported by membank.\",\n inputSchema: { type: \"object\", properties: {}, required: [] },\n },\n {\n name: \"save_memory\",\n description:\n \"Save a new memory. Handles deduplication automatically — near-identical memories (cosine similarity >0.92, same type and project) overwrite the existing record.\",\n inputSchema: {\n type: \"object\",\n properties: {\n content: { type: \"string\", description: \"Memory content to save\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"Memory type\",\n },\n tags: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Optional tags\",\n },\n global: {\n type: \"boolean\",\n description: \"Save as a global memory, not tied to any project\",\n },\n },\n required: [\"content\", \"type\"],\n },\n },\n {\n name: \"update_memory\",\n description:\n \"Update the content, type, and/or tags of an existing memory by id. All fields except id are optional.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to update\" },\n content: { type: \"string\", description: \"New content for the memory\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"New type for the memory (reclassification)\",\n },\n tags: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Replacement tags (optional)\",\n },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"delete_memory\",\n description: \"Delete a memory by id.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to delete\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"query_memory\",\n description:\n \"Search memories by semantic similarity. Returns results ranked by confidence score.\",\n inputSchema: {\n type: \"object\",\n properties: {\n query: { type: \"string\", description: \"Search text\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"Filter by memory type\",\n },\n limit: { type: \"number\", description: \"Maximum results to return (default 10)\" },\n includePinned: {\n type: \"boolean\",\n description:\n \"Include pinned memories in results. Pinned memories are already injected into session context, so excluded by default to avoid duplicates.\",\n },\n global: {\n type: \"boolean\",\n description:\n \"Query global memories only. When omitted or false, queries the current project scope.\",\n },\n },\n required: [\"query\"],\n },\n },\n {\n name: \"migrate\",\n description:\n 'List or run named data migrations. Use mode \"list\" to see available migrations; mode \"run\" with a migration name to execute one.',\n inputSchema: {\n type: \"object\",\n properties: {\n mode: {\n type: \"string\",\n enum: [\"list\", \"run\"],\n description: 'Mode: \"list\" to see available migrations, \"run\" to execute one',\n },\n name: {\n type: \"string\",\n description: 'Migration name (required when mode is \"run\")',\n },\n },\n required: [\"mode\"],\n },\n },\n {\n name: \"pin_memory\",\n description:\n \"Pin a memory by id. Pinned memories are always injected into the session context.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to pin\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"unpin_memory\",\n description: \"Unpin a memory by id. Removes the memory from guaranteed session injection.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to unpin\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"get_memory_summary\",\n description:\n \"Returns aggregate stats for session orientation: total memories, counts by type, pinned count, and review queue size.\",\n inputSchema: { type: \"object\", properties: {}, required: [] },\n },\n {\n name: \"list_flagged_memories\",\n description:\n \"List memories that have unresolved dedup review events. These were flagged automatically when a near-duplicate was saved (cosine similarity 0.75–0.92).\",\n inputSchema: { type: \"object\", properties: {}, required: [] },\n },\n {\n name: \"resolve_review\",\n description:\n \"Dismiss all unresolved review events for a memory. Use after reviewing the memory and deciding it should be kept as-is.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to resolve review events for\" },\n },\n required: [\"id\"],\n },\n },\n ],\n }));\n\n server.setRequestHandler(CallToolRequestSchema, async (request) => {\n if (request.params.name === \"list_memory_types\") {\n try {\n return {\n content: [{ type: \"text\", text: JSON.stringify(listMemoryTypes()) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"save_memory\") {\n const args = parseArgs(SaveMemoryArgsSchema, request.params.arguments);\n const projectScope = args.global === true ? undefined : await resolveProject();\n\n try {\n const memory = await core.repo.save({\n content: args.content,\n type: args.type,\n tags: args.tags,\n projectScope,\n });\n\n if (core.synthEngine !== undefined) {\n const scope =\n memory.projects.length > 0 ? (memory.projects[0]?.scopeHash ?? \"global\") : \"global\";\n core.synthEngine.markDirty(scope);\n }\n\n return {\n content: [{ type: \"text\", text: JSON.stringify(memory) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"update_memory\") {\n const args = parseArgs(UpdateMemoryArgsSchema, request.params.arguments);\n\n try {\n const memory = await core.repo.update(args.id, {\n content: args.content,\n type: args.type,\n tags: args.tags,\n });\n\n if (core.synthEngine !== undefined) {\n const scope =\n memory.projects.length > 0 ? (memory.projects[0]?.scopeHash ?? \"global\") : \"global\";\n core.synthEngine.markDirty(scope);\n }\n\n return { content: [{ type: \"text\", text: JSON.stringify(memory) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"delete_memory\") {\n const args = parseArgs(DeleteMemoryArgsSchema, request.params.arguments);\n\n try {\n const exists =\n core.db.db\n .prepare<[string], { id: string }>(`SELECT id FROM memories WHERE id = ?`)\n .get(args.id) !== undefined;\n\n if (!exists) {\n return {\n content: [{ type: \"text\", text: `Memory not found: ${args.id}` }],\n isError: true,\n };\n }\n\n let memoryScopeBeforeDelete: string | undefined;\n if (core.synthEngine !== undefined) {\n const projectRow = core.db.db\n .prepare<[string], { scope_hash: string }>(\n `SELECT p.scope_hash FROM projects p\n JOIN memory_projects mp ON mp.project_id = p.id\n WHERE mp.memory_id = ?`\n )\n .get(args.id);\n memoryScopeBeforeDelete = projectRow?.scope_hash ?? \"global\";\n }\n\n await core.repo.delete(args.id);\n\n if (core.synthEngine !== undefined && memoryScopeBeforeDelete !== undefined) {\n core.synthEngine.markDirty(memoryScopeBeforeDelete);\n }\n\n return {\n content: [{ type: \"text\", text: JSON.stringify({ success: true, id: args.id }) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"query_memory\") {\n const args = parseArgs(QueryMemoryArgsSchema, request.params.arguments);\n const projectHash = args.global === true ? undefined : (await resolveProject()).hash;\n\n try {\n const results = await core.query.query({\n query: args.query,\n type: args.type,\n projectHash,\n limit: args.limit ?? 10,\n includePinned: args.includePinned,\n });\n\n const serialised = results.map((r) => ({\n id: r.id,\n content: r.content,\n type: r.type,\n tags: r.tags,\n projects: r.projects,\n pinned: r.pinned,\n reviewEvents: r.reviewEvents,\n createdAt: r.createdAt,\n updatedAt: r.updatedAt,\n sourceHarness: r.sourceHarness,\n score: r.score,\n }));\n\n return {\n content: [{ type: \"text\", text: JSON.stringify(serialised) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"migrate\") {\n const args = parseArgs(MigrateArgsSchema, request.params.arguments);\n\n if (args.mode === \"list\") {\n return {\n content: [{ type: \"text\", text: JSON.stringify(MIGRATIONS) }],\n };\n }\n\n if (args.name === \"scope-to-projects\") {\n try {\n const result = await runScopeToProjectsMigration(core.projects);\n if (result === null) {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify({ error: \"No project found for current directory.\" }),\n },\n ],\n isError: true,\n };\n }\n return {\n content: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n throw new McpError(\n ErrorCode.InvalidParams,\n `Unknown migration: \"${args.name}\". Available: ${MIGRATIONS.map((m) => m.name).join(\", \")}`\n );\n }\n\n if (request.params.name === \"pin_memory\" || request.params.name === \"unpin_memory\") {\n const args = parseArgs(PinMemoryArgsSchema, request.params.arguments);\n const pinned = request.params.name === \"pin_memory\";\n\n try {\n const memory = core.repo.setPin(args.id, pinned);\n\n if (pinned) {\n const charCount = core.repo.getPinnedCharCount();\n if (charCount > PIN_BUDGET_THRESHOLD && !isSynthesisEnabled()) {\n const result = {\n ...memory,\n pinBudgetWarning: `Pinned memories now use ${charCount} characters (threshold: ${PIN_BUDGET_THRESHOLD}). Consider unpinning older memories or enabling synthesis to compress them.`,\n };\n return { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n }\n }\n\n return { content: [{ type: \"text\", text: JSON.stringify(memory) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"get_memory_summary\") {\n try {\n return { content: [{ type: \"text\", text: JSON.stringify(core.repo.stats()) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"list_flagged_memories\") {\n try {\n const memories = core.repo.listFlagged();\n return { content: [{ type: \"text\", text: JSON.stringify(memories) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"resolve_review\") {\n const args = parseArgs(ResolveReviewArgsSchema, request.params.arguments);\n\n try {\n const exists =\n core.db.db\n .prepare<[string], { id: string }>(`SELECT id FROM memories WHERE id = ?`)\n .get(args.id) !== undefined;\n\n if (!exists) {\n return {\n content: [{ type: \"text\", text: `Memory not found: ${args.id}` }],\n isError: true,\n };\n }\n\n core.repo.resolveReviewEvents(args.id);\n return {\n content: [{ type: \"text\", text: JSON.stringify({ success: true, id: args.id }) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n throw new Error(`Unknown tool: ${request.params.name}`);\n });\n\n return server;\n}\n","import {\n DatabaseManager,\n EmbeddingService,\n isSynthesisEnabled,\n MemoryRepository,\n ProjectRepository,\n QueryEngine,\n SynthesisRepository,\n} from \"@membank/core\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport type { CoreServices } from \"./server.js\";\nimport { buildSynthesisTools, createServer, initCore } from \"./server.js\";\nimport { SynthesisAgentLoop } from \"./synthesis/index.js\";\n\nexport async function startServer(): Promise<void> {\n let core: CoreServices;\n try {\n core = initCore();\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(`membank: failed to initialise core: ${message}\\n`);\n process.exit(1);\n }\n\n if (core.synthEngine !== undefined) {\n try {\n await core.synthEngine.init();\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(`membank: synthesis engine init failed: ${message}\\n`);\n }\n }\n\n const shutdown = async (): Promise<void> => {\n if (core.synthEngine !== undefined) {\n await core.synthEngine.shutdown();\n }\n process.exit(0);\n };\n\n process.on(\"SIGTERM\", () => {\n void shutdown();\n });\n process.on(\"SIGINT\", () => {\n void shutdown();\n });\n\n const server = createServer(core);\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n\nexport async function runSynthesis(scope: string): Promise<string> {\n if (!isSynthesisEnabled()) {\n throw new Error(\"Synthesis is not enabled. Run: membank config set synthesis.enabled true\");\n }\n\n const db = DatabaseManager.open();\n const embedding = new EmbeddingService();\n const projects = new ProjectRepository(db);\n const repo = new MemoryRepository(db, embedding, projects);\n const queryEngine = new QueryEngine(db, embedding, repo);\n const synthRepo = new SynthesisRepository(db);\n const agentLoop = new SynthesisAgentLoop(buildSynthesisTools(repo, queryEngine), {\n enabled: true,\n });\n\n synthRepo.markInFlight(scope);\n try {\n const [content, sourceHash] = await Promise.all([\n agentLoop.run(scope),\n Promise.resolve(synthRepo.computeSourceMemoryHash(scope)),\n ]);\n synthRepo.saveSynthesis(scope, content, sourceHash);\n return content;\n } catch (err) {\n synthRepo.clearInFlight(scope);\n throw err;\n } finally {\n db.close();\n }\n}\n"],"mappings":";;;;;;;;;;AAGA,MAAa,uBAAuB,EAAE,OAAO;CAC3C,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC1B,MAAM;CACN,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACpC,QAAQ,EAAE,SAAS,CAAC,UAAU;CAC/B,CAAC;AAEF,MAAa,yBAAyB,EAAE,OAAO;CAC7C,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE;CACrB,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,UAAU;CACrC,MAAM,iBAAiB,UAAU;CACjC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACrC,CAAC;AAEF,MAAa,yBAAyB,EAAE,OAAO,EAC7C,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,EACtB,CAAC;AAEF,MAAa,wBAAwB,EAAE,OAAO;CAC5C,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE;CACxB,MAAM,iBAAiB,UAAU;CACjC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU;CAC7C,eAAe,EAAE,SAAS,CAAC,UAAU;CACrC,QAAQ,EAAE,SAAS,CAAC,UAAU;CAC/B,CAAC;AAEF,MAAa,oBAAoB,EAAE,mBAAmB,QAAQ,CAC5D,EAAE,OAAO,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AAY,IAAI,kBAAkB;CAExC,MAAM,OAAO,IAAI,iBAAiB,IAAI,WAAW,IAD5B,kBAAkB,GACkB,CAAC;CAC1D,MAAM,cAAc,IAAI,YAAY,IAAI,WAAW,KAAK;CACxD,MAAM,YAAY,IAAI,oBAAoB,GAAG;CAC7C,MAAM,YAAY,IAAI,mBAAmB,oBAAoB,MAAM,YAAY,EAAE,EAC/E,SAAS,MACV,CAAC;CAEF,UAAU,aAAa,MAAM;CAC7B,IAAI;EACF,MAAM,CAAC,SAAS,cAAc,MAAM,QAAQ,IAAI,CAC9C,UAAU,IAAI,MAAM,EACpB,QAAQ,QAAQ,UAAU,wBAAwB,MAAM,CAAC,CAC1D,CAAC;EACF,UAAU,cAAc,OAAO,SAAS,WAAW;EACnD,OAAO;UACA,KAAK;EACZ,UAAU,cAAc,MAAM;EAC9B,MAAM;WACE;EACR,GAAG,OAAO"}
1
+ {"version":3,"file":"index.mjs","names":["#tools","#synthRepo","#config","#agentLoop","#dirtyScopes","#failureCounts","#running","#debounceLoop","#loopTimer","#inFlightPromises","#synthesizeScope","#scheduleNextCycle"],"sources":["../src/schemas.ts","../src/synthesis/agent-loop.ts","../src/synthesis/engine.ts","../src/server.ts","../src/index.ts"],"sourcesContent":["import { MemoryTypeSchema } from \"@membank/core\";\nimport { z } from \"zod\";\n\nexport const SaveMemoryArgsSchema = z.object({\n content: z.string().min(1),\n type: MemoryTypeSchema,\n tags: z.array(z.string()).optional(),\n global: z.boolean().optional(),\n});\n\nexport const UpdateMemoryArgsSchema = z.object({\n id: z.string().min(1),\n content: z.string().min(1).optional(),\n type: MemoryTypeSchema.optional(),\n tags: z.array(z.string()).optional(),\n});\n\nexport const DeleteMemoryArgsSchema = z.object({\n id: z.string().min(1),\n});\n\nexport const QueryMemoryArgsSchema = z.object({\n query: z.string().min(1),\n type: MemoryTypeSchema.optional(),\n limit: z.number().int().positive().optional(),\n includePinned: z.boolean().optional(),\n global: z.boolean().optional(),\n});\n\nexport const MigrateArgsSchema = z.discriminatedUnion(\"mode\", [\n z.object({ mode: z.literal(\"list\") }),\n z.object({ mode: z.literal(\"run\"), name: z.string().min(1) }),\n]);\n\nexport const PinMemoryArgsSchema = z.object({\n id: z.string().min(1),\n});\n\nexport const ResolveReviewArgsSchema = z.object({\n id: z.string().min(1),\n});\n","import { createSdkMcpServer, query, tool } from \"@anthropic-ai/claude-agent-sdk\";\nimport { z } from \"zod\";\n\nconst SYNTHESIS_SYSTEM_PROMPT =\n \"You are a memory synthesizer. Your job is to read the user's stored memories and produce a concise, well-structured summary of what's most important to remember about this user — their preferences, corrections, decisions, and key facts. Pinned memories are higher fidelity and should be weighted more heavily. Exclude transient or ephemeral details. Output plain text suitable for injection into an LLM context window. Be concise — target 200-400 words.\";\n\nexport interface SynthesisConfig {\n enabled: boolean;\n maxTokensPerRun?: number;\n debounceMs?: number;\n stalenessDays?: number;\n inFlightTimeoutMs?: number;\n}\n\nexport interface SynthesisTools {\n queryMemory: (args: {\n query: string;\n limit?: number;\n global?: boolean;\n projectHash?: string;\n }) => Promise<string>;\n getMemorySummary: () => Promise<string>;\n}\n\nexport class SynthesisAgentLoop {\n readonly #tools: SynthesisTools;\n\n constructor(tools: SynthesisTools, _config: SynthesisConfig) {\n this.#tools = tools;\n }\n\n async run(scope: string, projectHash?: string): Promise<string> {\n const queryMemoryTool = tool(\n \"query_memory\",\n \"Search memories by semantic similarity\",\n {\n query: z.string().describe(\"Search text\"),\n limit: z.number().optional().describe(\"Maximum results to return\"),\n global: z\n .boolean()\n .optional()\n .describe(\"Query global memories only when true, otherwise current project scope\"),\n },\n async ({ query: q, limit, global: isGlobal }) => {\n const result = await this.#tools.queryMemory({\n query: q,\n limit,\n global: isGlobal,\n projectHash,\n });\n return { content: [{ type: \"text\" as const, text: result }] };\n },\n { annotations: { readOnlyHint: true } }\n );\n\n const getMemorySummaryTool = tool(\n \"get_memory_summary\",\n \"Returns aggregate stats: total memories, counts by type, pinned count, review queue size\",\n {},\n async () => {\n const result = await this.#tools.getMemorySummary();\n return { content: [{ type: \"text\" as const, text: result }] };\n },\n { annotations: { readOnlyHint: true } }\n );\n\n const mcpServer = createSdkMcpServer({\n name: \"membank-synthesis-tools\",\n version: \"1.0.0\",\n tools: [queryMemoryTool, getMemorySummaryTool],\n });\n\n const isGlobal = scope === \"global\";\n const scopeDescription = isGlobal ? \"global (across all projects)\" : `project scope: ${scope}`;\n\n const prompt = `Synthesize the memories for ${scopeDescription}. Use get_memory_summary first to understand the overall state, then use query_memory to retrieve relevant memories (query with broad terms like \"preferences\", \"corrections\", \"decisions\", \"key facts\"). After gathering information, produce a concise synthesis of the most important things to remember about this user. Output only the synthesis text — no preamble, no metadata.`;\n\n const startTime = Date.now();\n\n const env = Object.fromEntries(\n Object.entries(process.env).filter((e): e is [string, string] => e[1] !== undefined)\n );\n\n const agentQuery = query({\n prompt,\n options: {\n model: \"claude-haiku-4-5-20251001\",\n systemPrompt: SYNTHESIS_SYSTEM_PROMPT,\n mcpServers: { \"membank-synthesis-tools\": mcpServer },\n allowedTools: [\"query_memory\", \"get_memory_summary\"],\n permissionMode: \"bypassPermissions\",\n env,\n },\n });\n\n let finalResult = \"\";\n\n for await (const message of agentQuery) {\n if (message.type === \"result\") {\n if (message.subtype === \"success\") {\n finalResult = message.result;\n } else {\n const details =\n \"errors\" in message && Array.isArray(message.errors)\n ? `: ${message.errors.join(\"; \")}`\n : \"\";\n throw new Error(`Synthesis agent failed: ${message.subtype}${details}`);\n }\n }\n }\n\n const durationMs = Date.now() - startTime;\n process.stderr.write(`membank synthesis: scope=${scope} duration=${durationMs}ms\\n`);\n\n if (finalResult === \"\") {\n throw new Error(\"Synthesis agent returned empty result\");\n }\n\n return finalResult;\n }\n}\n","import type { DatabaseManager, SynthesisRepository } from \"@membank/core\";\nimport type { SynthesisAgentLoop, SynthesisConfig } from \"./agent-loop.js\";\n\nconst DEFAULT_DEBOUNCE_MS = 45_000;\nconst DEFAULT_IN_FLIGHT_TIMEOUT_MS = 120_000;\nconst MAX_BACKOFF_MULTIPLIER = 5;\n\nexport class SynthesisEngine {\n readonly #synthRepo: SynthesisRepository;\n readonly #config: SynthesisConfig;\n readonly #agentLoop: SynthesisAgentLoop;\n readonly #dirtyScopes = new Set<string>();\n readonly #failureCounts = new Map<string, number>();\n #running = false;\n #loopTimer: ReturnType<typeof setTimeout> | undefined;\n #inFlightPromises = new Map<string, Promise<void>>();\n\n constructor(\n _db: DatabaseManager,\n synthRepo: SynthesisRepository,\n config: SynthesisConfig,\n agentLoop: SynthesisAgentLoop\n ) {\n this.#synthRepo = synthRepo;\n this.#config = config;\n this.#agentLoop = agentLoop;\n }\n\n async init(): Promise<void> {\n // Clear in_flight_since markers older than the timeout — they belong to a dead process.\n this.#synthRepo.clearStaleInFlight(\n this.#config.inFlightTimeoutMs ?? DEFAULT_IN_FLIGHT_TIMEOUT_MS\n );\n this.#synthRepo.expireStale();\n\n const stale = this.#synthRepo.getExpiredOrDirtyScopes();\n for (const { scope } of stale) {\n this.#dirtyScopes.add(scope);\n }\n\n this.#running = true;\n // Process any scopes discovered at startup immediately, then begin the periodic cycle\n await this.#debounceLoop();\n }\n\n shutdown(): Promise<void> {\n this.#running = false;\n\n if (this.#loopTimer !== undefined) {\n clearTimeout(this.#loopTimer);\n this.#loopTimer = undefined;\n }\n\n const inFlight = [...this.#inFlightPromises.values()];\n if (inFlight.length === 0) return Promise.resolve();\n\n const graceMs = 5_000;\n return Promise.race([\n Promise.allSettled(inFlight).then(() => undefined),\n new Promise<void>((resolve) => setTimeout(resolve, graceMs)),\n ]);\n }\n\n markDirty(scope: string): void {\n this.#dirtyScopes.add(scope);\n }\n\n #scheduleNextCycle(): void {\n if (!this.#running) return;\n const debounceMs = this.#config.debounceMs ?? DEFAULT_DEBOUNCE_MS;\n this.#loopTimer = setTimeout(() => {\n void this.#debounceLoop();\n }, debounceMs);\n }\n\n async #debounceLoop(): Promise<void> {\n const scopesToProcess = [...this.#dirtyScopes];\n\n for (const scope of scopesToProcess) {\n const inFlightTimeoutMs = this.#config.inFlightTimeoutMs ?? DEFAULT_IN_FLIGHT_TIMEOUT_MS;\n const synthesis = this.#synthRepo.getSynthesis(scope);\n\n if (synthesis?.inFlightSince !== null && synthesis?.inFlightSince !== undefined) {\n const inFlightMs = Date.now() - new Date(synthesis.inFlightSince).getTime();\n if (inFlightMs < inFlightTimeoutMs) {\n continue;\n }\n // Stale in-flight — clear it and allow resynthesis\n this.#synthRepo.clearInFlight(scope);\n }\n\n this.#dirtyScopes.delete(scope);\n const promise = this.#synthesizeScope(scope).finally(() => {\n this.#inFlightPromises.delete(scope);\n });\n this.#inFlightPromises.set(scope, promise);\n }\n\n this.#scheduleNextCycle();\n }\n\n async #synthesizeScope(scope: string): Promise<void> {\n this.#synthRepo.markInFlight(scope);\n\n try {\n const projectHash = scope === \"global\" ? undefined : scope;\n const content = await this.#agentLoop.run(scope, projectHash);\n const sourceHash = this.#synthRepo.computeSourceMemoryHash(scope);\n this.#synthRepo.saveSynthesis(scope, content, sourceHash);\n this.#failureCounts.delete(scope);\n } catch (err) {\n const failures = (this.#failureCounts.get(scope) ?? 0) + 1;\n this.#failureCounts.set(scope, failures);\n\n // Exponential backoff: re-queue with multiplied debounce up to MAX_BACKOFF_MULTIPLIER\n const backoffMultiplier = Math.min(failures, MAX_BACKOFF_MULTIPLIER);\n const backoffMs = (this.#config.debounceMs ?? DEFAULT_DEBOUNCE_MS) * backoffMultiplier;\n\n process.stderr.write(\n `membank synthesis: error for scope=${scope} failures=${failures} backoff=${backoffMs}ms: ${err instanceof Error ? err.message : String(err)}\\n`\n );\n\n setTimeout(() => {\n this.#dirtyScopes.add(scope);\n }, backoffMs);\n\n this.#synthRepo.clearInFlight(scope);\n }\n }\n}\n","import { readFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport {\n DatabaseManager,\n EmbeddingService,\n isSynthesisEnabled,\n listMemoryTypes,\n MEMORY_TYPE_VALUES,\n MemoryRepository,\n MIGRATIONS,\n PIN_BUDGET_THRESHOLD,\n ProjectRepository,\n QueryEngine,\n resolveProject,\n runScopeToProjectsMigration,\n SynthesisRepository,\n} from \"@membank/core\";\nimport { Server } from \"@modelcontextprotocol/sdk/server\";\nimport {\n CallToolRequestSchema,\n ErrorCode,\n ListToolsRequestSchema,\n McpError,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { ZodError } from \"zod\";\nimport {\n DeleteMemoryArgsSchema,\n MigrateArgsSchema,\n PinMemoryArgsSchema,\n QueryMemoryArgsSchema,\n ResolveReviewArgsSchema,\n SaveMemoryArgsSchema,\n UpdateMemoryArgsSchema,\n} from \"./schemas.js\";\nimport type { SynthesisConfig, SynthesisTools } from \"./synthesis/index.js\";\nimport { SynthesisAgentLoop, SynthesisEngine } from \"./synthesis/index.js\";\n\nconst SERVER_NAME = \"membank\";\nconst SERVER_VERSION = \"0.1.0\";\n\nexport interface CoreServices {\n db: DatabaseManager;\n embedding: EmbeddingService;\n repo: MemoryRepository;\n query: QueryEngine;\n projects: ProjectRepository;\n synthEngine?: SynthesisEngine;\n}\n\nexport interface ServerOptions {\n dbPath?: string;\n useInMemoryDb?: boolean;\n}\n\nfunction loadSynthesisConfig(): SynthesisConfig {\n const configPath = join(homedir(), \".membank\", \"config.json\");\n try {\n const raw = readFileSync(configPath, \"utf8\");\n const parsed = JSON.parse(raw) as {\n synthesis?: Partial<SynthesisConfig>;\n };\n return {\n enabled: parsed.synthesis?.enabled === true,\n maxTokensPerRun: parsed.synthesis?.maxTokensPerRun,\n debounceMs: parsed.synthesis?.debounceMs,\n stalenessDays: parsed.synthesis?.stalenessDays,\n inFlightTimeoutMs: parsed.synthesis?.inFlightTimeoutMs,\n };\n } catch {\n return { enabled: false };\n }\n}\n\nexport function buildSynthesisTools(repo: MemoryRepository, query: QueryEngine): SynthesisTools {\n return {\n queryMemory: async (args) => {\n const projectHash =\n args.global === true ? undefined : (args.projectHash ?? (await resolveProject()).hash);\n const results = await query.query({\n query: args.query,\n projectHash,\n limit: args.limit ?? 20,\n includePinned: true,\n });\n return JSON.stringify(results);\n },\n getMemorySummary: async () => JSON.stringify(repo.stats()),\n };\n}\n\nexport function initCore(options: ServerOptions = {}): CoreServices {\n const db = options.useInMemoryDb\n ? DatabaseManager.openInMemory()\n : DatabaseManager.open(options.dbPath);\n const embedding = new EmbeddingService();\n const projects = new ProjectRepository(db);\n const repo = new MemoryRepository(db, embedding, projects);\n const query = new QueryEngine(db, embedding, repo);\n\n const synthConfig = loadSynthesisConfig();\n let synthEngine: SynthesisEngine | undefined;\n\n if (synthConfig.enabled) {\n const synthRepo = new SynthesisRepository(db);\n const agentLoop = new SynthesisAgentLoop(buildSynthesisTools(repo, query), synthConfig);\n synthEngine = new SynthesisEngine(db, synthRepo, synthConfig, agentLoop);\n }\n\n return { db, embedding, repo, query, projects, synthEngine };\n}\n\nfunction parseArgs<T>(schema: { parse: (v: unknown) => T }, raw: unknown): T {\n try {\n return schema.parse(raw);\n } catch (e) {\n const msg = e instanceof ZodError ? (e.issues[0]?.message ?? e.message) : String(e);\n throw new McpError(ErrorCode.InvalidParams, msg);\n }\n}\n\nexport function createServer(core: CoreServices): Server {\n const server = new Server(\n { name: SERVER_NAME, version: SERVER_VERSION },\n { capabilities: { tools: {} } }\n );\n\n server.setRequestHandler(ListToolsRequestSchema, () => ({\n tools: [\n {\n name: \"list_memory_types\",\n description: \"Returns the ordered list of memory type values supported by membank.\",\n inputSchema: { type: \"object\", properties: {}, required: [] },\n },\n {\n name: \"save_memory\",\n description:\n \"Save a new memory. Handles deduplication automatically — near-identical memories (cosine similarity >0.92, same type and project) overwrite the existing record.\",\n inputSchema: {\n type: \"object\",\n properties: {\n content: { type: \"string\", description: \"Memory content to save\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"Memory type\",\n },\n tags: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Optional tags\",\n },\n global: {\n type: \"boolean\",\n description: \"Save as a global memory, not tied to any project\",\n },\n },\n required: [\"content\", \"type\"],\n },\n },\n {\n name: \"update_memory\",\n description:\n \"Update the content, type, and/or tags of an existing memory by id. All fields except id are optional.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to update\" },\n content: { type: \"string\", description: \"New content for the memory\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"New type for the memory (reclassification)\",\n },\n tags: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Replacement tags (optional)\",\n },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"delete_memory\",\n description: \"Delete a memory by id.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to delete\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"query_memory\",\n description:\n \"Search memories by semantic similarity. Returns results ranked by confidence score.\",\n inputSchema: {\n type: \"object\",\n properties: {\n query: { type: \"string\", description: \"Search text\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"Filter by memory type\",\n },\n limit: { type: \"number\", description: \"Maximum results to return (default 10)\" },\n includePinned: {\n type: \"boolean\",\n description:\n \"Include pinned memories in results. Pinned memories are already injected into session context, so excluded by default to avoid duplicates.\",\n },\n global: {\n type: \"boolean\",\n description:\n \"Query global memories only. When omitted or false, queries the current project scope.\",\n },\n },\n required: [\"query\"],\n },\n },\n {\n name: \"migrate\",\n description:\n 'List or run named data migrations. Use mode \"list\" to see available migrations; mode \"run\" with a migration name to execute one.',\n inputSchema: {\n type: \"object\",\n properties: {\n mode: {\n type: \"string\",\n enum: [\"list\", \"run\"],\n description: 'Mode: \"list\" to see available migrations, \"run\" to execute one',\n },\n name: {\n type: \"string\",\n description: 'Migration name (required when mode is \"run\")',\n },\n },\n required: [\"mode\"],\n },\n },\n {\n name: \"pin_memory\",\n description:\n \"Pin a memory by id. Pinned memories are always injected into the session context.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to pin\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"unpin_memory\",\n description: \"Unpin a memory by id. Removes the memory from guaranteed session injection.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to unpin\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"get_memory_summary\",\n description:\n \"Returns aggregate stats for session orientation: total memories, counts by type, pinned count, and review queue size.\",\n inputSchema: { type: \"object\", properties: {}, required: [] },\n },\n {\n name: \"list_flagged_memories\",\n description:\n \"List memories that have unresolved dedup review events. These were flagged automatically when a near-duplicate was saved (cosine similarity 0.75–0.92).\",\n inputSchema: { type: \"object\", properties: {}, required: [] },\n },\n {\n name: \"resolve_review\",\n description:\n \"Dismiss all unresolved review events for a memory. Use after reviewing the memory and deciding it should be kept as-is.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to resolve review events for\" },\n },\n required: [\"id\"],\n },\n },\n ],\n }));\n\n server.setRequestHandler(CallToolRequestSchema, async (request) => {\n if (request.params.name === \"list_memory_types\") {\n try {\n return {\n content: [{ type: \"text\", text: JSON.stringify(listMemoryTypes()) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"save_memory\") {\n const args = parseArgs(SaveMemoryArgsSchema, request.params.arguments);\n const projectScope = args.global === true ? undefined : await resolveProject();\n\n try {\n const memory = await core.repo.save({\n content: args.content,\n type: args.type,\n tags: args.tags,\n projectScope,\n });\n\n if (core.synthEngine !== undefined) {\n const scope =\n memory.projects.length > 0 ? (memory.projects[0]?.scopeHash ?? \"global\") : \"global\";\n core.synthEngine.markDirty(scope);\n }\n\n return {\n content: [{ type: \"text\", text: JSON.stringify(memory) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"update_memory\") {\n const args = parseArgs(UpdateMemoryArgsSchema, request.params.arguments);\n\n try {\n const memory = await core.repo.update(args.id, {\n content: args.content,\n type: args.type,\n tags: args.tags,\n });\n\n if (core.synthEngine !== undefined) {\n const scope =\n memory.projects.length > 0 ? (memory.projects[0]?.scopeHash ?? \"global\") : \"global\";\n core.synthEngine.markDirty(scope);\n }\n\n return { content: [{ type: \"text\", text: JSON.stringify(memory) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"delete_memory\") {\n const args = parseArgs(DeleteMemoryArgsSchema, request.params.arguments);\n\n try {\n const exists =\n core.db.db\n .prepare<[string], { id: string }>(`SELECT id FROM memories WHERE id = ?`)\n .get(args.id) !== undefined;\n\n if (!exists) {\n return {\n content: [{ type: \"text\", text: `Memory not found: ${args.id}` }],\n isError: true,\n };\n }\n\n let memoryScopeBeforeDelete: string | undefined;\n if (core.synthEngine !== undefined) {\n const projectRow = core.db.db\n .prepare<[string], { scope_hash: string }>(\n `SELECT p.scope_hash FROM projects p\n JOIN memory_projects mp ON mp.project_id = p.id\n WHERE mp.memory_id = ?`\n )\n .get(args.id);\n memoryScopeBeforeDelete = projectRow?.scope_hash ?? \"global\";\n }\n\n await core.repo.delete(args.id);\n\n if (core.synthEngine !== undefined && memoryScopeBeforeDelete !== undefined) {\n core.synthEngine.markDirty(memoryScopeBeforeDelete);\n }\n\n return {\n content: [{ type: \"text\", text: JSON.stringify({ success: true, id: args.id }) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"query_memory\") {\n const args = parseArgs(QueryMemoryArgsSchema, request.params.arguments);\n const projectHash = args.global === true ? undefined : (await resolveProject()).hash;\n\n try {\n const results = await core.query.query({\n query: args.query,\n type: args.type,\n projectHash,\n limit: args.limit ?? 10,\n includePinned: args.includePinned,\n });\n\n const serialised = results.map((r) => ({\n id: r.id,\n content: r.content,\n type: r.type,\n tags: r.tags,\n projects: r.projects,\n pinned: r.pinned,\n reviewEvents: r.reviewEvents,\n createdAt: r.createdAt,\n updatedAt: r.updatedAt,\n sourceHarness: r.sourceHarness,\n score: r.score,\n }));\n\n return {\n content: [{ type: \"text\", text: JSON.stringify(serialised) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"migrate\") {\n const args = parseArgs(MigrateArgsSchema, request.params.arguments);\n\n if (args.mode === \"list\") {\n return {\n content: [{ type: \"text\", text: JSON.stringify(MIGRATIONS) }],\n };\n }\n\n if (args.name === \"scope-to-projects\") {\n try {\n const result = await runScopeToProjectsMigration(core.projects);\n if (result === null) {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify({ error: \"No project found for current directory.\" }),\n },\n ],\n isError: true,\n };\n }\n return {\n content: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n throw new McpError(\n ErrorCode.InvalidParams,\n `Unknown migration: \"${args.name}\". Available: ${MIGRATIONS.map((m) => m.name).join(\", \")}`\n );\n }\n\n if (request.params.name === \"pin_memory\" || request.params.name === \"unpin_memory\") {\n const args = parseArgs(PinMemoryArgsSchema, request.params.arguments);\n const pinned = request.params.name === \"pin_memory\";\n\n try {\n const memory = core.repo.setPin(args.id, pinned);\n\n if (pinned) {\n const charCount = core.repo.getPinnedCharCount();\n if (charCount > PIN_BUDGET_THRESHOLD && !isSynthesisEnabled()) {\n const result = {\n ...memory,\n pinBudgetWarning: `Pinned memories now use ${charCount} characters (threshold: ${PIN_BUDGET_THRESHOLD}). Consider unpinning older memories or enabling synthesis to compress them.`,\n };\n return { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n }\n }\n\n return { content: [{ type: \"text\", text: JSON.stringify(memory) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"get_memory_summary\") {\n try {\n return { content: [{ type: \"text\", text: JSON.stringify(core.repo.stats()) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"list_flagged_memories\") {\n try {\n const memories = core.repo.listFlagged();\n return { content: [{ type: \"text\", text: JSON.stringify(memories) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"resolve_review\") {\n const args = parseArgs(ResolveReviewArgsSchema, request.params.arguments);\n\n try {\n const exists =\n core.db.db\n .prepare<[string], { id: string }>(`SELECT id FROM memories WHERE id = ?`)\n .get(args.id) !== undefined;\n\n if (!exists) {\n return {\n content: [{ type: \"text\", text: `Memory not found: ${args.id}` }],\n isError: true,\n };\n }\n\n core.repo.resolveReviewEvents(args.id);\n return {\n content: [{ type: \"text\", text: JSON.stringify({ success: true, id: args.id }) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n throw new Error(`Unknown tool: ${request.params.name}`);\n });\n\n return server;\n}\n","import {\n DatabaseManager,\n EmbeddingService,\n isSynthesisEnabled,\n MemoryRepository,\n ProjectRepository,\n QueryEngine,\n SynthesisRepository,\n} from \"@membank/core\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport type { CoreServices } from \"./server.js\";\nimport { buildSynthesisTools, createServer, initCore } from \"./server.js\";\nimport { SynthesisAgentLoop } from \"./synthesis/index.js\";\n\nexport async function startServer(): Promise<void> {\n let core: CoreServices;\n try {\n core = initCore();\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(`membank: failed to initialise core: ${message}\\n`);\n process.exit(1);\n }\n\n if (core.synthEngine !== undefined) {\n try {\n await core.synthEngine.init();\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(`membank: synthesis engine init failed: ${message}\\n`);\n }\n }\n\n const shutdown = async (): Promise<void> => {\n if (core.synthEngine !== undefined) {\n await core.synthEngine.shutdown();\n }\n process.exit(0);\n };\n\n process.on(\"SIGTERM\", () => {\n void shutdown();\n });\n process.on(\"SIGINT\", () => {\n void shutdown();\n });\n\n const server = createServer(core);\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n\nexport async function runSynthesis(scope: string): Promise<string> {\n if (!isSynthesisEnabled()) {\n throw new Error(\"Synthesis is not enabled. Run: membank config set synthesis.enabled true\");\n }\n\n const db = DatabaseManager.open();\n const embedding = new EmbeddingService();\n const projects = new ProjectRepository(db);\n const repo = new MemoryRepository(db, embedding, projects);\n const queryEngine = new QueryEngine(db, embedding, repo);\n const synthRepo = new SynthesisRepository(db);\n const agentLoop = new SynthesisAgentLoop(buildSynthesisTools(repo, queryEngine), {\n enabled: true,\n });\n\n let resolvedScope = scope;\n if (scope !== \"global\" && !/^[0-9a-f]{16}$/.test(scope)) {\n const project = projects.getByName(scope);\n if (project !== undefined) {\n resolvedScope = project.scopeHash;\n }\n }\n\n const projectHash = resolvedScope === \"global\" ? undefined : resolvedScope;\n\n synthRepo.markInFlight(resolvedScope);\n try {\n const [content, sourceHash] = await Promise.all([\n agentLoop.run(resolvedScope, projectHash),\n Promise.resolve(synthRepo.computeSourceMemoryHash(resolvedScope)),\n ]);\n synthRepo.saveSynthesis(resolvedScope, content, sourceHash);\n return content;\n } catch (err) {\n synthRepo.clearInFlight(resolvedScope);\n throw err;\n } finally {\n db.close();\n }\n}\n"],"mappings":";;;;;;;;;;AAGA,MAAa,uBAAuB,EAAE,OAAO;CAC3C,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC1B,MAAM;CACN,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACpC,QAAQ,EAAE,SAAS,CAAC,UAAU;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AS,cAAc,MAAM,QAAQ,IAAI,CAC9C,UAAU,IAAI,eAAe,YAAY,EACzC,QAAQ,QAAQ,UAAU,wBAAwB,cAAc,CAAC,CAClE,CAAC;EACF,UAAU,cAAc,eAAe,SAAS,WAAW;EAC3D,OAAO;UACA,KAAK;EACZ,UAAU,cAAc,cAAc;EACtC,MAAM;WACE;EACR,GAAG,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@membank/mcp",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,7 +20,7 @@
20
20
  "@anthropic-ai/claude-agent-sdk": "^0.2.131",
21
21
  "@modelcontextprotocol/sdk": "^1.29.0",
22
22
  "zod": "^4.4.3",
23
- "@membank/core": "0.9.2"
23
+ "@membank/core": "0.9.4"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "^25.6.0",