MCPcopy
hub / github.com/Doorman11991/smallcode / loadForTask

Method loadForTask

bin/memory.js:106–129  ·  view source on GitHub ↗
(taskDescription)

Source from the content-addressed store, hash-verified

104
105 // Load relevant memory for a task (keyword-based retrieval)
106 loadForTask(taskDescription) {
107 if (this.objects.size === 0) return [];
108
109 const words = taskDescription.toLowerCase().split(/\s+/);
110 const scored = [];
111
112 for (const obj of this.objects.values()) {
113 let score = 0;
114 const text = `${obj.title} ${obj.content} ${obj.tags.join(' ')}`.toLowerCase();
115
116 for (const word of words) {
117 if (word.length < 3) continue;
118 if (text.includes(word)) score += 1;
119 if (obj.title.toLowerCase().includes(word)) score += 3;
120 if (obj.tags.some(t => t.includes(word))) score += 2;
121 }
122
123 if (score > 0) scored.push({ obj, score });
124 }
125
126 // Sort by relevance, return top matches
127 scored.sort((a, b) => b.score - a.score);
128 return scored.slice(0, 5).map(s => s.obj);
129 }
130
131 // Get all objects of a type
132 byType(type) {

Callers 5

getMemoryContextFunction · 0.80
handleMCPToolCallFunction · 0.80
getMemoryContextFunction · 0.80
executeToolFunction · 0.80
executeMemoryToolFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected