MCPcopy
hub / github.com/garrytan/gstack / emitActivity

Function emitActivity

browse/src/activity.ts:129–147  ·  view source on GitHub ↗
(entry: Omit<ActivityEntry, 'id' | 'timestamp'>)

Source from the content-addressed store, hash-verified

127 * Emit an activity event. Backpressure-safe: subscribers notified asynchronously.
128 */
129export 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.

Callers 4

activity.test.tsFile · 0.90
checkTabGuardrailsMethod · 0.90
makeFetchHandlerFunction · 0.90

Calls 3

filterArgsFunction · 0.85
truncateResultFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected