get_memory
Retrieve your project's conventions, decisions, and gotchas. Filter by category, type, or keyword. Use before proposing patterns or libraries to ensure alignment with team practices.
Instructions
Routes to the active/current project automatically when known. Retrieves team conventions, architectural decisions, and known gotchas. CALL BEFORE suggesting patterns, libraries, or architecture.
Filters: category (tooling/architecture/testing/dependencies/conventions), type (convention/decision/gotcha), query (keyword search).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | Filter by category | |
| type | No | Filter by memory type | |
| query | No | Keyword search across memory and reason | |
| project | No | Optional project selector for this call. Accepts a project root path, file path, file:// URI, or a relative subproject path under a configured root. | |
| project_directory | No | Deprecated compatibility alias for older clients. Prefer project. |
Implementation Reference
- src/tools/get-memory.ts:38-123 (handler)The main handler function for get_memory. Reads memories from file, applies filters (category/type/query), limits to 20 unfiltered results, enriches with confidence decay, and returns JSON response.
export async function handle( args: Record<string, unknown>, ctx: ToolContext ): Promise<ToolResponse> { const { category, type, query } = args as { category?: MemoryCategory; type?: MemoryType; query?: string; }; try { const memoryPath = ctx.paths.memory; const allMemories = await readMemoriesFile(memoryPath); if (allMemories.length === 0) { return { content: [ { type: 'text', text: JSON.stringify( { status: 'success', message: "No team conventions recorded yet. Use 'remember' to build tribal knowledge or memory when the user corrects you over a repeatable pattern.", memories: [], count: 0 }, null, 2 ) } ] }; } const filtered = filterMemories(allMemories, { category, type, query }); const limited = applyUnfilteredLimit(filtered, { category, type, query }, 20); // Enrich with confidence decay const enriched = withConfidence(limited.memories); const staleCount = enriched.filter((m) => m.stale).length; return { content: [ { type: 'text', text: JSON.stringify( { status: 'success', count: enriched.length, totalCount: limited.totalCount, truncated: limited.truncated, ...(staleCount > 0 && { staleCount, staleNote: `${staleCount} memor${staleCount === 1 ? 'y' : 'ies'} below 30% confidence. Consider reviewing or removing.` }), message: limited.truncated ? 'Showing 20 most recent. Use filters (category/type/query) for targeted results.' : undefined, memories: enriched }, null, 2 ) } ] }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify( { status: 'error', message: 'Failed to retrieve memories.', error: error instanceof Error ? error.message : String(error) }, null, 2 ) } ] }; } } - src/tools/get-memory.ts:11-36 (schema)Tool definition with inputSchema: accepts optional category, type, and query filters.
export const definition: Tool = { name: 'get_memory', description: 'Retrieves team conventions, architectural decisions, and known gotchas.\n' + 'CALL BEFORE suggesting patterns, libraries, or architecture.\n\n' + 'Filters: category (tooling/architecture/testing/dependencies/conventions), type (convention/decision/gotcha), query (keyword search).', inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'Filter by category', enum: ['tooling', 'architecture', 'testing', 'dependencies', 'conventions'] }, type: { type: 'string', description: 'Filter by memory type', enum: ['convention', 'decision', 'gotcha', 'failure'] }, query: { type: 'string', description: 'Keyword search across memory and reason' } } } }; - src/tools/index.ts:55-57 (registration)Tool registered as d10 in the TOOLS array, with project selector wrapper applied.
export const TOOLS: Tool[] = [d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11].map( withProjectSelector ); - src/tools/index.ts:83-84 (registration)Dispatch case routing 'get_memory' to the handler (h10) imported from get-memory.ts.
case 'get_memory': return h10(args, ctx); - src/memory/store.ts:98-105 (helper)Reads and parses the memories JSON file. Returns empty array on any error.
export async function readMemoriesFile(memoryPath: string): Promise<Memory[]> { try { const content = await fs.readFile(memoryPath, 'utf-8'); return normalizeMemories(JSON.parse(content)); } catch { return []; } }