import { customPolicies, allow, instruct } from "failproofai";
customPolicies.add({
name: "slack-on-idle",
description: "Alert Slack when the agent is waiting for input",
match: { events: ["Notification"] },
fn: async (ctx) => {
const webhookUrl = process.env.SLACK_WEBHOOK_URL;
if (!webhookUrl) return allow();
const message = String(ctx.payload?.message ?? "Agent is waiting");
const project = ctx.session?.cwd ?? "unknown";
try {
await fetch(webhookUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
text: `*${message}*\nProject: \`${project}\``,
}),
signal: AbortSignal.timeout(5000),
});
} catch {
// never block the agent if Slack is unreachable
}
return allow();
},
});