feat: distinguish system events from user messages

System events (heartbeats, cron triggers, webhooks, channel events)
now render as subtle inline notifications instead of full user bubbles.
Detection based on content patterns ([EVENT], [cron:], [HEARTBEAT], etc.).
This commit is contained in:
Nicolas Varrot
2026-02-12 16:49:16 +00:00
parent a17fbf134a
commit 581675d00c
4 changed files with 61 additions and 2 deletions

29
src/lib/systemEvent.ts Normal file
View File

@@ -0,0 +1,29 @@
/**
* Detect whether a user-role message is actually a system event
* (heartbeat, webhook, cron, channel event, etc.) rather than
* a real human message.
*/
const SYSTEM_PATTERNS: RegExp[] = [
// Explicit markers
/^\[EVENT\b/i,
/\[from:\s*[^\]]*\(system\)\]/i,
/^\[HEARTBEAT\b/i,
/^\[cron:/i,
/^\[hook:/i,
/^\[webhook:/i,
/^\[sms-inbound\b/i,
/^\[teamspeak\b/i,
// Heartbeat prompt pattern (the standard OpenClaw heartbeat)
/^Read HEARTBEAT\.md if it exists/,
// System event envelope: [source:xxx]
/^\[source:\s*\w+\]/i,
];
export function isSystemEvent(text: string): boolean {
const trimmed = text.trim();
if (!trimmed) return false;
return SYSTEM_PATTERNS.some(pat => pat.test(trimmed));
}