Automations¶
An OpenCode automation reads a source with tools.gws.events_list, keeps its cursor in the automation's durable state, and re-reads from it on the next run. The bus event is only a nudge; the cursor is the truth.
| Source | Method | Provider floor | Suggested | Signals |
|---|---|---|---|---|
gws.gmail | tools.gws.events_list | 1 min | 2 min | bus |
gws.calendar | tools.gws.events_list | 1 min | 10 min | bus |
A timer recipe¶
// every 10 minutes
const state = (await tools.gws.events_list({ source: "calendar", account: "work" })) // no cursor: the first window
// keep state.cursor; on the next run:
const next = await tools.gws.events_list({ source: "calendar", account: "work", cursor: state.cursor })
- Pass the previous answer's
cursorto continue; without one, a read starts atsinceor 24 hours ago. - A cursor is bound to the plugin, source, account and scope. Another account's cursor is
CURSOR_INVALID; start again without one. - Keep the state per account and source.
events_listnever merges two accounts' windows. gws.gmailsuggests every 2 minutes, andgws.calendarevery 10; both are reads with no provider cost. Do not poll faster than the provider's floor.- A
changedevent onrpc.gws.changedsays a declared source changed after one of the plugin's writes. Re-read the named capability through RPC, or wait for the timer; the event carries no content. - A page with
failed[]holds the cursor back: the next run reads the same window again. A page withrefused[]moved past those items for good. - On
gws.gmail, a message whosefromaddress matches the signed-in mailbox owner marks thatfromactor withself: true. While following Gmail history: - Permanently deleted non-noise messages (
messagesDeleted) return inremovals[]withreason: "deleted". - Non-noise messages moved to trash or spam (
TRASHorSPAMadded) return inremovals[]withreason: "withheld". RemovingTRASHorSPAMre-lists a restored non-noise message as an event (on an inbox-narrowed feed, whenINBOXis present). - On an inbox-narrowed feed (
scope.queryset to"in:inbox"or"label:inbox"), non-noise messages that leaveINBOXreturn inremovals[]withreason: "withheld", and messages moved intoINBOXare listed as events. - On the whole-mailbox feed (no
scope.query), archiving or returning a message toINBOXre-lists the message with its updatedlabelsandhash, without emitting a removal. Archiving an older message triggers onemessages.getfetch to re-list it with its updated labels, so bulk archives spread those fetches across pages. - Drafts, Promotions, Social and other noise messages never emit removals.
- When
failed[]holds the cursor back, the page still delivers its otherremovals[](excluding any failed id), and the next run delivers them again.
The attention feed¶
gws.gmail.attention is a snapshot, not an event feed: a client reads it through tools.gws.gmail_attention when it draws the person's attention feed, with no cursor. It returns the unread inbox threads that ask the person, each with its sender, thread id and Gmail permalink and never its body. The action route calls gws.mail.reply or gws.mail.archive with the item's id; both are denied to agents, so an agent replies with gws_reply and archives with gws_label_thread.
Gmail: one search, and the newest matches¶
gws.gmail takes a scope with two keys:
queryis one Gmail search, such as"in:inbox"or"label:work is:unread". The plugin adds its noise filter (-in:drafts -category:promotions -category:social) and, whensinceis given, itsafter:bound.orderis"oldest"(the default: the feed, every match fromsinceforwards) or"newest"(the newest matches of the window, then what arrives).
// the newest 20 inbox mail, with no guessed time window
const page = await tools.gws.events_list({ source: "gmail", account: "work", limit: 20, scope: { query: "in:inbox", order: "newest" } })
// page.events is oldest first, as every page is; render it reversed
- A newest read carries the newest events that fit its page. When
sincenames a window the page did not carry whole, it saysgap: { reason: "window-truncated", since }; withoutsince, its window has no lower bound, so the newest mail in the mailbox is listed. - An inbox-only search (
"in:inbox"or"label:inbox") follows Gmail history withlabelId: "INBOX", for both"oldest"and"newest"orders. Other searches cannot run in history, so they read the search again on the next call; a newest read resumes after the newest event it listed. Pass the cursor as usual. - A cursor is bound to the scope it was issued under: one from another query or order is
CURSOR_INVALID, and the reader starts again without one.