MCPcopy Create free account
hub / github.com/PatrickSys/codebase-context / handle

Function handle

src/tools/get-memory.ts:38–123  ·  view source on GitHub ↗
(
  args: Record<string, unknown>,
  ctx: ToolContext
)

Source from the content-addressed store, hash-verified

36};
37
38export async function handle(
39 args: Record<string, unknown>,
40 ctx: ToolContext
41): Promise<ToolResponse> {
42 const { category, type, query } = args as {
43 category?: MemoryCategory;
44 type?: MemoryType;
45 query?: string;
46 };
47
48 try {
49 const memoryPath = ctx.paths.memory;
50 const allMemories = await readMemoriesFile(memoryPath);
51
52 if (allMemories.length === 0) {
53 return {
54 content: [
55 {
56 type: 'text',
57 text: JSON.stringify(
58 {
59 status: 'success',
60 message:
61 "No team conventions recorded yet. Use 'remember' to build tribal knowledge or memory when the user corrects you over a repeatable pattern.",
62 memories: [],
63 count: 0
64 },
65 null,
66 2
67 )
68 }
69 ]
70 };
71 }
72
73 const filtered = filterMemories(allMemories, { category, type, query });
74 const limited = applyUnfilteredLimit(filtered, { category, type, query }, 20);
75
76 // Enrich with confidence decay
77 const enriched = withConfidence(limited.memories);
78 const staleCount = enriched.filter((m) => m.stale).length;
79
80 return {
81 content: [
82 {
83 type: 'text',
84 text: JSON.stringify(
85 {
86 status: 'success',
87 count: enriched.length,
88 totalCount: limited.totalCount,
89 truncated: limited.truncated,
90 ...(staleCount > 0 && {
91 staleCount,
92 staleNote: `${staleCount} memor${staleCount === 1 ? 'y' : 'ies'} below 30% confidence. Consider reviewing or removing.`
93 }),
94 message: limited.truncated
95 ? 'Showing 20 most recent. Use filters (category/type/query) for targeted results.'

Callers

nothing calls this directly

Calls 4

readMemoriesFileFunction · 0.85
filterMemoriesFunction · 0.85
applyUnfilteredLimitFunction · 0.85
withConfidenceFunction · 0.85

Tested by

no test coverage detected