(entry: Omit<ActivityEntry, 'id' | 'timestamp'>)
| 127 | * Emit an activity event. Backpressure-safe: subscribers notified asynchronously. |
| 128 | */ |
| 129 | export function emitActivity(entry: Omit<ActivityEntry, 'id' | 'timestamp'>): ActivityEntry { |
| 130 | const full: ActivityEntry = { |
| 131 | ...entry, |
| 132 | id: nextId++, |
| 133 | timestamp: Date.now(), |
| 134 | args: entry.args ? filterArgs(entry.command || '', entry.args) : undefined, |
| 135 | result: truncateResult(entry.result), |
| 136 | }; |
| 137 | activityBuffer.push(full); |
| 138 | |
| 139 | // Notify subscribers asynchronously — never block the command path |
| 140 | for (const notify of subscribers) { |
| 141 | queueMicrotask(() => { |
| 142 | try { notify(full); } catch { /* subscriber error — don't crash */ } |
| 143 | }); |
| 144 | } |
| 145 | |
| 146 | return full; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Subscribe to live activity events. Returns unsubscribe function. |
no test coverage detected