feat: surface system presence for the agent

This commit is contained in:
Peter Steinberger
2025-12-09 02:25:37 +01:00
parent 317f666d4c
commit 1969e78d54
10 changed files with 202 additions and 3 deletions

View File

@@ -0,0 +1,33 @@
// Lightweight in-memory queue for human-readable system events that should be
// prefixed to the next main-session prompt/heartbeat. We intentionally avoid
// persistence to keep events ephemeral.
type SystemEvent = { text: string; ts: number };
const MAX_EVENTS = 20;
const queue: SystemEvent[] = [];
let lastText: string | null = null;
export function enqueueSystemEvent(text: string) {
const cleaned = text.trim();
if (!cleaned) return;
if (lastText === cleaned) return; // skip consecutive duplicates
lastText = cleaned;
queue.push({ text: cleaned, ts: Date.now() });
if (queue.length > MAX_EVENTS) queue.shift();
}
export function drainSystemEvents(): string[] {
const out = queue.map((e) => e.text);
queue.length = 0;
lastText = null;
return out;
}
export function peekSystemEvents(): string[] {
return queue.map((e) => e.text);
}
export function hasSystemEvents() {
return queue.length > 0;
}