import { parsePlaybookStatement } from "../../../../playbooks/types.js"; import { getNode, updateNode, } from "../../../../plugins/defaults/memory/graph/store.js"; import type { ToolContext, ToolExecutionResult, } from "../../../../tools/types.js"; export async function executePlaybookDelete( input: Record, _context: ToolContext, ): Promise { const playbookId = input.playbook_id as string; if (!playbookId || typeof playbookId !== "string") { return { content: "Error: playbook_id is required and must be a string", isError: true, }; } try { const existing = getNode(playbookId); if ( !existing || !existing.sourceConversations.some((s) => s.startsWith("playbook:")) || existing.fidelity === "gone" ) { return { content: `Error: Playbook with ID "${playbookId}" not found`, isError: true, }; } // Extract trigger label from content const newlineIdx = existing.content.indexOf("\n"); const statement = newlineIdx !== -1 ? existing.content.slice(newlineIdx + 1) : ""; const playbook = parsePlaybookStatement(statement); const triggerLabel = playbook?.trigger ?? existing.content.split("\n")[0]; // Soft-delete by setting fidelity to "gone" updateNode(existing.id, { fidelity: "gone" }); return { content: `Playbook deleted (ID: ${existing.id}, trigger: "${triggerLabel}").`, isError: false, }; } catch (err) { const msg = err instanceof Error ? err.message : String(err); return { content: `Error deleting playbook: ${msg}`, isError: true }; } } export { executePlaybookDelete as run };