Skip to content

Rules

Rules do something with new items that meet their conditions: mark as read, star, save to Raindrop.io, or send to Readwise Reader or MyMind. Their conditions are the same as a filter rule’s: words, words an item doesn’t have, a source, a kind of YouTube video. A filter rule hides an item; a rule acts on it. Code: services/action-rules.ts, the page in routes/(app)/settings/rules (Settings → Rules).

A rule

  • Conditions: one to five, and an item has to meet all of them, exactly as in filters.md: words anywhere, in the title, in the text or by author (whole words, any case), a source you follow, or a YouTube Short or live stream.

  • Actions: one or more, each at most once:

    • Mark as read. The item still goes through the AI pipeline. To keep it from the AI, mute it with a filter rule.
    • Star. The item is in Starred, in the starred feed, and kept when old content is pruned, as if you had starred it.
    • Save to Raindrop.io, into a collection (default: the one set under Raindrop.io) with tags. Needs a Raindrop connection.
    • Send to Readwise Reader, into a location (default: the one set under Readwise Reader) with tags. Needs a Readwise connection.
    • Send to MyMind, into a space (default: the one set under MyMind) with tags. Needs a MyMind connection.

    A star or a Raindrop save can also send the item on to Readwise Reader and MyMind, if their routing says so. A rule’s own Readwise or MyMind action sends whatever the routing says, with its location, space and tags.

  • Name: optional. Without one, the rule is named after its actions and conditions: “Mark as read and star: “svelte” in the title”. It’s renamed with them, unless you gave it a name.

  • On or off. No expiry: a rule runs until you turn it off or delete it.

At most 200 rules per user. Rules are per user: one user’s rule never touches another user’s items.

When rules run

  • On new items only, when they reach your stream, in the same transaction that hands them out (addItems), right after the filter rules. A rule doesn’t run on the items already in your stream when you add it, and changing or deleting it undoes nothing. That’s the difference from Mute: a filter rule can give its items back, but a star or a bookmark can’t be taken back for you. The editor’s preview says how many items the conditions match now, as a check of the conditions.
  • Not on a new subscription’s first items. Following a source, or an OPML import, would otherwise star or bookmark its back catalog.
  • A muted item runs no rule.
  • Before the AI. Rules run when an item arrives, before the gate has judged it, so an item the gate later filters out is still starred or saved. Each item of a story is matched on its own.
  • Paused sources too. A source you paused still hands you new items while someone else follows it, and your rules run on them.
  • Every rule that matches runs, oldest first. Two rules on one item both do their part.
  • Each rule counts the items it ran on, and when it last did (applied_count, last_applied_at): “Ran on 12 items, last Nov 16”.

Saving to Raindrop

A rule never calls Raindrop while items arrive. It queues the save (item_saves, status saving, due now), and the scheduler sends it on its next round, within a minute, as it retries failed saves: at most 20 a round, retried the same way when Raindrop fails for a passing reason. The bookmark button shows the pulsing “saving” state meanwhile. An item saved before keeps its save; an item without a link isn’t saved. With SCHEDULER_ENABLED=false, queued saves wait.

Adding a Raindrop action, or turning such a rule on, needs a connection (422 otherwise). If you disconnect later, the rule skips the save and shows “Raindrop.io isn’t connected” until you connect again; its other actions keep running.

Sending to Readwise Reader or MyMind

The same way: the rule queues the item (item_saves, trigger rule), and the scheduler sends it within a minute, retried as forwarding.md says. It needs a connection, and shows “Readwise Reader isn’t connected” or “MyMind isn’t connected” after a disconnect. A rule that stars an item and sends it to Readwise in one: the rule’s send wins over the routing’s, so its location and tags count.

Storage

action_rules holds the rules: name, conditions and actions (JSON, as in the API), enabled, applied_count, last_applied_at (migration 0028_action_rules). Actions write to the item as you would: user_items.read_at, user_items.starred_at, a row in item_saves.

API

GET /api/v1/rules rules: newest first. Each has id, name, description (the conditions in words), conditions, actions, actionsDescription, enabled, status (active, paused), appliedCount, lastAppliedAt, warnings (raindrop_not_connected, readwise_not_connected, mymind_not_connected)
POST /api/v1/rules { name?, conditions, actions, enabled? } → 201 { rule }. Runs on items that arrive from now on
PATCH /api/v1/rules/:id Any of name, conditions, actions, enabled → { rule }
DELETE /api/v1/rules/:id 204. Items it ran on keep what it did
POST /api/v1/rules/preview { conditions } → { count, items }: the items the conditions match now, muted ones left out. Changes nothing

A condition is a filter rule’s (filters.md). An action is { type: 'read' }, { type: 'star' }, { type: 'raindrop', collectionId?, tags? }, { type: 'readwise', location?, tags? } or { type: 'mymind', spaceId?, tags? }. Invalid rules answer 422 with error: 'invalid'; an unknown rule 404. Writing, the preview included, needs a session or a write token.

The SDK: actionRules(), createActionRule(), updateActionRule(), deleteActionRule(), previewActionRule().

Adding an action

An action is one entry in ACTIONS in action-rules.ts (its label, how it’s checked, and the SQL it runs on the matched items), one in RULE_ACTION_TYPES and RuleAction (schema.ts), one in the SDK’s ruleAction (and the most actions in its ruleActions), and a switch on the page. An action runs inside the arrival transaction, so it has to be plain SQL: anything that talks to another service queues work for the scheduler, as the Raindrop save does.

Not yet

  • Running a rule on the items already there, once, on request.
  • More actions: a tag, a vote.
  • The agent creating rules (“star everything from Simon Willison”), on this API.