Skip to content

feat(clipcatctl): add tail subcommand to follow clipboard history#1049

Open
futpib wants to merge 4 commits into
xrelkd:developfrom
futpib:feat/clipcatctl-tail
Open

feat(clipcatctl): add tail subcommand to follow clipboard history#1049
futpib wants to merge 4 commits into
xrelkd:developfrom
futpib:feat/clipcatctl-tail

Conversation

@futpib
Copy link
Copy Markdown
Contributor

@futpib futpib commented May 10, 2026

  • Add server-streaming Subscribe RPC on the Manager service, backed by a tokio::sync::broadcast channel in ClipboardManager that fires on every insert_inner.
  • Add clipcatctl tail [-f] [-n N] [--no-id]: prints last N entries (default 10) and exits, or follows with -f.
  • Resilient to clipcatd restarts: reconnect with exponential backoff (100ms -> 5s), catch-up via persisted history filtered by last-seen timestamp, dedupe with a bounded LRU (cap 1024).
  • Subscribe is opened before the catch-up list to buffer any insert in the gap; printed_ids dedupes the overlap.
  • Output format is byte-identical to clipcatctl list via a shared format_metadata_line helper.

Enables hook scripts (issue #1036) to subscribe to new clip events and call clipcatctl to act on them.

@futpib futpib marked this pull request as draft May 10, 2026 14:38
@futpib futpib force-pushed the feat/clipcatctl-tail branch 4 times, most recently from e59600d to 1169a1c Compare May 10, 2026 15:35
futpib added 2 commits May 10, 2026 19:52
Add a server-streaming `Subscribe` RPC on the `Manager` service backed by
a `tokio::sync::broadcast` channel in `ClipboardManager`. The channel
fires once for every `insert_inner` call, so subscribers see new clips
inserted via the `Insert` and `Update` RPCs as well as those captured
from the OS clipboard by the watcher.

Lagging subscribers are skipped with a warning rather than terminated,
so the stream stays usable across slow consumers.
Expose the new server-streaming `Subscribe` RPC through the `Manager`
client trait, returning a `Stream<Item = Result<ClipEntryMetadata, _>>`
type alias re-exported as `SubscribeStream` for downstream consumers.
Errors from the underlying gRPC stream are mapped to a new
`SubscribeClipError` variant that mirrors the existing per-RPC error
types.
@futpib futpib force-pushed the feat/clipcatctl-tail branch from 1169a1c to 7bc5ee9 Compare May 10, 2026 15:52
futpib added 2 commits May 10, 2026 20:04
Add `clipcatctl tail [-n N] [-f] [--no-id]` for printing recent clips
and (optionally) streaming new ones, modeled on GNU `tail`. With `-f`,
the command subscribes to the new server-streaming `Subscribe` RPC and
keeps printing as clips arrive.

The follow loop is resilient to `clipcatd` restarts: it reconnects with
exponential backoff (100ms -> 5s) and on each reconnect catches up via
`list` filtered by the last-seen timestamp, deduping seen ids through a
bounded LRU. Subscribe is opened before the catch-up `list` so any clip
inserted during the gap is buffered in the broadcast receiver and the
LRU drops it as a duplicate.

Output is byte-identical to `clipcatctl list` via a shared
`format_metadata_line` helper.
- Add `clipcatctl tail` to the command summary table.
- Add an Integration section showing how to drive an out-of-band shell
  hook from `clipcatctl tail -f`. The example appends a trimmed copy
  of each newly inserted single-line text clip and uses `-n 0` so the
  hook reacts only to future clips, not the existing history.
@futpib futpib force-pushed the feat/clipcatctl-tail branch from 7bc5ee9 to d96aa59 Compare May 10, 2026 16:04
@futpib futpib marked this pull request as ready for review May 10, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant