Skip to content

feat(drive/docs): add poll subcommand with state-file for changes + comments #690

@sebsnyk

Description

@sebsnyk

Motivation

Not every consumer can host an HTTPS endpoint (corporate firewalls, ephemeral laptops). A polling alternative — interval-based changes.list + comments diff — is the no-infra path. It is straightforward to script today but bookkeeping the page token between runs is tedious; baking a poll subcommand with a state file makes it one command.

Pairs with (but does not replace) a future gog drive changes serve push-notification receiver — poll is for the no-infra case, serve is for real-time.

Depends on

  • feat(comments): add --since=<RFC3339> filter on docs/drive comments list #688 --since=<RFC3339> filter on comments list. The gog docs comments poll surface proposed below reduces to: persist last-seen modifiedTime in the state file, call comments list --since=<last-seen> each tick, fire --on-new per result, advance the watermark. Without --since the polling loop has to either list-all-and-filter-client-side (wasteful, and pagination-heavy on large docs) or maintain a per-comment-ID seen-set (state explosion). With --since it is a trivial wrapper. The drive changes poll half is self-contained (it uses changes.list pageToken semantics, which are already complete in v0.21).

Repro

# Today, polling:
TOKEN=$(cat ~/.gogcli-state/token || gog drive changes start-token | jq -r .startPageToken)
while sleep 30; do
  RESP=$(gog drive changes list --token "$TOKEN" -j)
  echo "$RESP" | jq '.changes'
  TOKEN=$(echo "$RESP" | jq -r .newStartPageToken)
  echo "$TOKEN" > ~/.gogcli-state/token
done

# Wanted:
gog drive changes poll --state-file ~/.gogcli-state/drive.json --interval 30s --on-change ./handle.sh

Proposed surface

gog drive changes poll [flags]
  --state-file=PATH       Persist pageToken (created on first call from changes.startPageToken)
  --interval=DUR          Poll interval (default 60s)
  --on-change="<cmd>"     Shell command per non-empty result
  --filter-file=<id>      Short-circuit when changes do not touch this file
  --drive=STRING          Shared-drive id
  --max-iterations=INT    Stop after N iterations (default 0 = forever)

gog docs comments poll <docId> [flags]
  --state-file=PATH       Persist last-seen modifiedTime (consumes --since from #688)
  --interval=DUR
  --include-resolved
  --on-new="<cmd>"        Shell command per new comment; comment JSON on stdin

Acceptance criteria

  • State file atomically updated (write to .tmp, rename).
  • First invocation with a missing/empty state-file calls changes.startPageToken automatically.
  • --on-change / --on-new invocations are sequential (no overlap).
  • Graceful shutdown on SIGINT/SIGTERM persists state before exiting.
  • docs comments poll reuses the --since implementation from feat(comments): add --since=<RFC3339> filter on docs/drive comments list #688; no separate listing path.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low-risk cleanup, docs, polish, ergonomics, or speculative feature.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🌊 off-meta tidepoolIssue quality rating does not apply to this item.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions