MCPcopy Create free account
hub / github.com/anus-dev/ANUS / execute

Method execute

packages/core/src/tools/memoryTool.ts:252–308  ·  view source on GitHub ↗
(_signal: AbortSignal)

Source from the content-addressed store, hash-verified

250 }
251
252 async execute(_signal: AbortSignal): Promise<ToolResult> {
253 const { fact, modified_by_user, modified_content } = this.params;
254
255 try {
256 if (modified_by_user && modified_content !== undefined) {
257 // User modified the content in external editor, write it directly
258 await fs.mkdir(path.dirname(getGlobalMemoryFilePath()), {
259 recursive: true,
260 });
261 await fs.writeFile(
262 getGlobalMemoryFilePath(),
263 modified_content,
264 'utf-8',
265 );
266 const successMessage = `Okay, I've updated the memory file with your modifications.`;
267 return {
268 llmContent: JSON.stringify({
269 success: true,
270 message: successMessage,
271 }),
272 returnDisplay: successMessage,
273 };
274 } else {
275 // Use the normal memory entry logic
276 await MemoryTool.performAddMemoryEntry(
277 fact,
278 getGlobalMemoryFilePath(),
279 {
280 readFile: fs.readFile,
281 writeFile: fs.writeFile,
282 mkdir: fs.mkdir,
283 },
284 );
285 const successMessage = `Okay, I've remembered that: "${fact}"`;
286 return {
287 llmContent: JSON.stringify({
288 success: true,
289 message: successMessage,
290 }),
291 returnDisplay: successMessage,
292 };
293 }
294 } catch (error) {
295 const errorMessage =
296 error instanceof Error ? error.message : String(error);
297 console.error(
298 `[MemoryTool] Error executing save_memory for fact "${fact}": ${errorMessage}`,
299 );
300 return {
301 llmContent: JSON.stringify({
302 success: false,
303 error: `Failed to save memory. Detail: ${errorMessage}`,
304 }),
305 returnDisplay: `Error saving memory: ${errorMessage}`,
306 };
307 }
308 }
309}

Callers

nothing calls this directly

Calls 3

getGlobalMemoryFilePathFunction · 0.85
mkdirMethod · 0.80
performAddMemoryEntryMethod · 0.80

Tested by

no test coverage detected