Project Files
src / tools / forget.ts
/**
* forget — delete a playbook document and remove it from the index.
*/
import { tool, type Tool, type ToolsProviderController } from "@lmstudio/sdk";
// @ts-ignore — zod/lib re-export chain breaks with NodeNext; runtime is fine
import { z } from "zod";
import path from "node:path";
import fs from "node:fs";
import type { IndexManager } from "../indexManager.js";
import { formatToolMetaBlock } from "../helpers/pluginMeta.js";
export function createForgetTool(
_ctl: ToolsProviderController,
index: IndexManager
): Tool {
return tool({
name: "forget",
description: `Permanently delete a playbook document and remove it from the search index.
This action cannot be undone. Always call recall first to confirm the exact filename.
Use this tool when:
- The user explicitly asks to remove a note
- A document is outdated and should no longer appear in search results
Returns:
- Confirmation with the deleted filename
- An error if the file does not exist
${formatToolMetaBlock()}`,
parameters: {
filename: z
.string()
.describe("Filename of the document to delete (e.g. 'my-note.md')."),
},
implementation: async (args) => {
const filePath = path.join(index.getPlaybookDirectory(), args.filename);
if (!fs.existsSync(filePath)) {
return `Error: File not found — "${args.filename}". Nothing was deleted.`;
}
try {
await index.deleteFile(filePath);
return `Deleted "${args.filename}".`;
} catch (err) {
return `Error: ${err instanceof Error ? err.message : String(err)}`;
}
},
});
}