const DAEMON_URL = process.env.SIGNET_DAEMON_URL || "http://localhost:3850"; async function fetchDaemon(path, body) { const res = await fetch(`${DAEMON_URL}${path}`, { method: "POST", headers: { "Content-Type": "application/json", "x-signet-runtime-path": "legacy", }, body: JSON.stringify({ ...body, runtimePath: "legacy" }), signal: AbortSignal.timeout(5000), }); if (!res.ok) throw new Error(`daemon ${res.status}`); return res.json(); } const handler = async (event) => { // When the plugin runtime path is active, legacy hooks are disabled // to prevent duplicate capture/recall. Set SIGNET_RUNTIME_PATH=plugin // in your environment to use the plugin path exclusively. if (process.env.SIGNET_RUNTIME_PATH === "plugin") return; if (event.type !== "command") return; const args = event.context?.args || ""; switch (event.action) { case "remember": if (!args.trim()) { event.messages.push("Usage: /remember "); return; } try { await fetchDaemon("/api/hooks/remember", { harness: "openclaw", who: "openclaw", content: args.trim(), }); event.messages.push(`saved: ${args.trim().slice(0, 50)}...`); } catch (e) { event.messages.push(`Error: ${e.message}`); } break; case "recall": if (!args.trim()) { event.messages.push("Usage: /recall "); return; } try { const data = await fetchDaemon("/api/hooks/recall", { harness: "openclaw", query: args.trim(), }); if (data.results?.length) { event.messages.push(data.results.map(r => `- ${r.content}`).join("\n")); } else { event.messages.push("No memories found."); } } catch (e) { event.messages.push(`Error: ${e.message}`); } break; case "context": try { const data = await fetchDaemon("/api/hooks/session-start", { harness: "openclaw", }); event.messages.push(data.inject || "no context"); } catch (e) { event.messages.push(`Error: ${e.message}`); } break; } }; export default handler;