feat: add system event detection for OpenClaw subagent and gateway messages (#8)
Add detection patterns for OpenClaw-specific system messages so they render as subtle inline notifications instead of full chat bubbles: - [System Message] — subagent completion notifications - [Queued announce messages — batched system messages - System: [timestamp] — gateway events (e.g. WhatsApp connected) - Pre-compaction memory flush — internal memory prompts Includes 6 test cases (5 positive matches + 1 negative for mid-sentence false positive prevention). Co-authored-by: togotago <drewmfleury@gmail.com>
This commit is contained in:
@@ -57,6 +57,18 @@ describe('isSystemEvent', () => {
|
||||
expect(isSystemEvent(' [EVENT] test')).toBe(true);
|
||||
expect(isSystemEvent('\n[cron:x] task')).toBe(true);
|
||||
});
|
||||
|
||||
it('detects [System Message] markers (subagent completion notifications)', () => {
|
||||
expect(isSystemEvent('[System Message] Subagent spark completed: task done')).toBe(true);
|
||||
expect(isSystemEvent('[system message] something happened')).toBe(true);
|
||||
expect(isSystemEvent('[SYSTEM MESSAGE] All caps')).toBe(true);
|
||||
expect(isSystemEvent(' [System Message] with leading whitespace')).toBe(true);
|
||||
expect(isSystemEvent('\t[System Message] tab-prefixed')).toBe(true);
|
||||
});
|
||||
|
||||
it('does not falsely detect [System Message] mid-sentence', () => {
|
||||
expect(isSystemEvent('Hello [System Message] this is not a system event')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('stripWebhookScaffolding', () => {
|
||||
|
||||
@@ -20,6 +20,18 @@ const SYSTEM_PATTERNS: RegExp[] = [
|
||||
|
||||
// System event envelope: [source:xxx]
|
||||
/^\[source:\s*\w+\]/i,
|
||||
|
||||
// OpenClaw subagent completion notifications
|
||||
/^\[System Message\]/i,
|
||||
|
||||
// Queued announce messages (batched system messages)
|
||||
/^\[Queued announce messages/i,
|
||||
|
||||
// Gateway system notifications (e.g. "System: [2026-02-18 ...] WhatsApp gateway connected.")
|
||||
/^System:\s*\[\d{4}-\d{2}-\d{2}/,
|
||||
|
||||
// Pre-compaction memory flush prompts
|
||||
/^Pre-compaction memory flush/i,
|
||||
];
|
||||
|
||||
export function isSystemEvent(text: string): boolean {
|
||||
|
||||
Reference in New Issue
Block a user