Project Files
src / tools / forget_doc.ts
/**
* forget_doc — delete a notes document.
*/
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 { globalConfigSchematics } from "../config.js";
import { formatToolMetaBlock } from "../core-bundle.mjs";
export function createForgetDocTool(ctl: ToolsProviderController): Tool {
return tool({
name: "forget_doc",
description: `Permanently delete a note from the notes directory.
This action cannot be undone. Always use find_doc 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 getter: any =
(ctl as any).getGlobalPluginConfig || (ctl as any).getGlobalConfig;
const gcfg = getter ? getter.call(ctl, globalConfigSchematics) : null;
const notesDirectory: string = gcfg?.get("notesDirectory") ?? "";
if (!notesDirectory) {
return "Error: Notes Directory is not configured. The initial plugin setup has not been completed yet — start a new chat and follow the setup guide, then set Notes Directory in the plugin global settings.";
}
const filePath = path.join(notesDirectory, args.filename);
if (!fs.existsSync(filePath)) {
return `Error: File not found — "${args.filename}". Nothing was deleted.`;
}
try {
await fs.promises.unlink(filePath);
return `Deleted "${args.filename}".`;
} catch (err) {
return `Error: ${err instanceof Error ? err.message : String(err)}`;
}
},
});
}