Commit Graph
1 Commits
Author SHA1 Message Date
Cursor AgentandTom Huang 16ac3b549d feat(plugins): plugin event ring buffer + SSE tail (Phase 4)
Plan II1.

apps/daemon/src/plugins/events.ts ships a small in-memory FIFO
ring buffer for plugin lifecycle events. Producers call
recordPluginEvent({ kind, pluginId, details? }); consumers either
pull pluginEventSnapshot(since?) for a one-shot read or call
subscribePluginEvents(cb) for a live feed (returns an unsubscribe
callback).

The buffer is capped at 1000 entries — older events fall off the
head. State resets on daemon restart (events survive the run,
not the boot).

PluginEventKind union covers the lifecycle vocabulary:
  plugin.installed / .upgraded / .uninstalled
  plugin.trust-changed / .applied
  plugin.snapshot-pruned / .marketplace-refreshed

Producer hooks:
  installer.installFromLocalFolder() emits 'plugin.installed' on
    success with { version, sourceKind, source, trust, warnings }.
  installer.uninstallPlugin() emits 'plugin.uninstalled' on
    successful row removal.

(Apply / snapshot-prune / trust-changed hooks are wiring in
incrementally in subsequent slices; the producer surface is
documented in events.ts.)

apps/daemon/src/server.ts: new GET /api/plugins/events SSE route.
On open: emits the buffered backlog as 'event: backlog' entries,
then forwards every newly-recorded event as 'event: plugin' with
the same shape. Optional ?since=<id> trims the backlog.

CLI: `od plugin events tail [-f] [--since <id>] [--json]`.
Default mode drains the backlog + idles 200ms before exiting;
-f / --follow keeps the connection open and prints live events.
JSON mode emits one event per line for easy piping into jq.

Daemon tests: 1787 \u2192 1797 (+10 cases on plugins-events-buffer:
monotonic id + epoch ms, multi-record id sequence, optional
details field, full snapshot vs. since filter, snapshot copy
semantics, subscriber forwarding, unsubscribe stops forwarding,
listener-exception isolation, 1000-cap eviction).

Co-authored-by: Tom Huang <1043269994@qq.com>
2026-05-09 17:55:39 +00:00