MCPcopy Index your code
hub / github.com/anus-dev/ANUS / MemoryToolInvocation

Class MemoryToolInvocation

packages/core/src/tools/memoryTool.ts:201–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201class MemoryToolInvocation extends BaseToolInvocation<
202 SaveMemoryParams,
203 ToolResult
204> {
205 private static readonly allowlist: Set<string> = new Set();
206
207 getDescription(): string {
208 const memoryFilePath = getGlobalMemoryFilePath();
209 return `in ${tildeifyPath(memoryFilePath)}`;
210 }
211
212 override async shouldConfirmExecute(
213 _abortSignal: AbortSignal,
214 ): Promise<ToolEditConfirmationDetails | false> {
215 const memoryFilePath = getGlobalMemoryFilePath();
216 const allowlistKey = memoryFilePath;
217
218 if (MemoryToolInvocation.allowlist.has(allowlistKey)) {
219 return false;
220 }
221
222 const currentContent = await readMemoryFileContent();
223 const newContent = computeNewContent(currentContent, this.params.fact);
224
225 const fileName = path.basename(memoryFilePath);
226 const fileDiff = Diff.createPatch(
227 fileName,
228 currentContent,
229 newContent,
230 'Current',
231 'Proposed',
232 DEFAULT_DIFF_OPTIONS,
233 );
234
235 const confirmationDetails: ToolEditConfirmationDetails = {
236 type: 'edit',
237 title: `Confirm Memory Save: ${tildeifyPath(memoryFilePath)}`,
238 fileName: memoryFilePath,
239 filePath: memoryFilePath,
240 fileDiff,
241 originalContent: currentContent,
242 newContent,
243 onConfirm: async (outcome: ToolConfirmationOutcome) => {
244 if (outcome === ToolConfirmationOutcome.ProceedAlways) {
245 MemoryToolInvocation.allowlist.add(allowlistKey);
246 }
247 },
248 };
249 return confirmationDetails;
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()), {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected