feat: add programmatic alerting for worker lifecycle events (#16) (#17)

Adds notification system for full visibility into the DevClaw pipeline:

Events and targets:
- workerStart: Posted to project group when worker spawns/resumes
- workerComplete: Posted to project group when DEV done/QA pass/fail/refine
- heartbeat: Posted to orchestrator DM with tick summary

Implementation:
- New lib/notify.ts module with buildMessage() and sendMessage()
- Integrated into task_pickup, task_complete, and heartbeat_tick
- Uses OpenClaw gateway to invoke message tool

Configuration (optional):
- orchestratorDm: Chat ID for heartbeat notifications
- notifications.heartbeatDm: Enable/disable heartbeat DM (default: true)
- notifications.workerStart: Enable/disable start notifications (default: true)
- notifications.workerComplete: Enable/disable completion notifications (default: true)

Notifications fail silently (logged but don't break main flow).
This commit is contained in:
Lauren ten Hoor
2026-02-10 00:40:44 +08:00
committed by GitHub
parent c88071db0e
commit d40aa41b16
5 changed files with 354 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ import {
readProjects,
} from "../projects.js";
import type { ToolContext } from "../types.js";
import { notify, getNotificationConfig } from "../notify.js";
const execFileAsync = promisify(execFile);
@@ -266,6 +267,42 @@ export function createTaskCompleteTool(api: OpenClawPluginApi) {
output.announcement = `🤔 QA REFINE #${issueId}${summary ? `${summary}` : ""}. Awaiting human decision.`;
}
// Send notification to project group
const pluginConfig = api.pluginConfig as Record<string, unknown> | undefined;
const notifyConfig = getNotificationConfig(pluginConfig);
// Determine next state for the notification
let nextState: string | undefined;
if (role === "dev" && result === "done") {
nextState = "QA queue";
} else if (role === "qa" && result === "pass") {
nextState = "Done!";
} else if (role === "qa" && result === "fail") {
nextState = "back to DEV";
} else if (role === "qa" && result === "refine") {
nextState = "awaiting human decision";
}
await notify(
{
type: "workerComplete",
project: project.name,
groupId,
issueId,
role,
result,
summary,
nextState,
},
{
workspaceDir,
config: notifyConfig,
groupId,
// Channel detection: default to telegram if not available
channel: "telegram",
},
);
// Audit log
await auditLog(workspaceDir, "task_complete", {
project: project.name,