Skip to content

feat: --watch flag for meshd status --json (live streaming JSON) #1

Description

@gitcoder89431

Summary

Add a --watch flag to meshd status --json that streams newline-delimited JSON on state change instead of a one-shot output.

Motivation

The current --json flag works for one-shot scripts but Quickshell widgets need to poll on a timer, which is janky and wastes CPU. A --watch mode would make widgets fully reactive with zero overhead — they just read stdin.

Proposed Behavior

meshd status --json --watch
# streams a new JSON line every time state changes (device connects, file syncs, conflict detected, etc.)
# powered by /rest/events?since=<n> under the hood

Output format (newline-delimited JSON):

{"devices":[{"name":"MacBook","status":"online","completion":100}],"syncing":false,"conflicts":0}
{"devices":[{"name":"MacBook","status":"syncing","completion":73}],"syncing":true,"conflicts":0}

Implementation Notes

  • Subscribe to /rest/events?since=<n> (long-poll, already used by the TUI)
  • On each relevant event, re-fetch /rest/db/status and emit a new JSON line to stdout
  • Relevant event types: StateChanged, DeviceConnected, DeviceDisconnected, FolderCompletion, LocalChangeDetected
  • Exits cleanly on ctrl+c / SIGTERM

Use Cases

  • Quickshell / EWW / Waybar widgets that show sync status in a bar
  • Shell scripts that wait for sync to complete before proceeding
  • Agent workflows polling for file propagation confirmation

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions