@gloaming/poke 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +136 -2
  3. package/daemon.js +175 -0
  4. package/drizzle/20261123093322_init/migration.sql +38 -0
  5. package/drizzle/20261123093322_init/snapshot.json +330 -0
  6. package/drizzle/20261123101024_poll_cursors_and_secrets/migration.sql +8 -0
  7. package/drizzle/20261123101024_poll_cursors_and_secrets/snapshot.json +382 -0
  8. package/drizzle/20261123124858_owner_trust/migration.sql +5 -0
  9. package/drizzle/20261123124858_owner_trust/snapshot.json +382 -0
  10. package/drizzle/20261123130247_looks/migration.sql +7 -0
  11. package/drizzle/20261123130247_looks/snapshot.json +413 -0
  12. package/drizzle/20261123133921_look_states/migration.sql +4 -0
  13. package/drizzle/20261123133921_look_states/snapshot.json +444 -0
  14. package/drizzle/20261123140834_pattern_states/migration.sql +7 -0
  15. package/drizzle/20261123140834_pattern_states/snapshot.json +495 -0
  16. package/drizzle/20261123141452_source_cursors/migration.sql +4 -0
  17. package/drizzle/20261123141452_source_cursors/snapshot.json +526 -0
  18. package/drizzle/20261124082939_replies/migration.sql +7 -0
  19. package/drizzle/20261124082939_replies/snapshot.json +581 -0
  20. package/package.json +24 -4
  21. package/poke-skill.md +104 -0
  22. package/poke.js +301 -0
  23. package/presets/bluesky.json +22 -0
  24. package/presets/docker-events.json +18 -0
  25. package/presets/github-releases.json +22 -0
  26. package/presets/gmail.json +27 -0
  27. package/presets/home-assistant.json +23 -0
  28. package/presets/journald-over-ssh.json +27 -0
  29. package/presets/kubectl-watch.json +22 -0
  30. package/presets/log-file.json +24 -0
  31. package/presets/mastodon.json +27 -0
  32. package/presets/modbus.json +40 -0
  33. package/presets/mqtt.json +28 -0
  34. package/presets/ntfy.json +28 -0
  35. package/presets/onvif.json +23 -0
  36. package/presets/serial.json +31 -0
  37. package/presets/status-page.json +18 -0
  38. package/presets/syslog.json +24 -0
  39. package/types/discord/main.js +35 -0
  40. package/types/discord/type.json +47 -0
  41. package/types/imap/main.js +134 -0
  42. package/types/imap/type.json +54 -0
  43. package/types/presence/main.js +35 -0
  44. package/types/presence/type.json +27 -0
  45. package/types/slack/main.js +35 -0
  46. package/types/slack/type.json +52 -0
  47. package/types/system/run.sh +19 -0
  48. package/types/system/system-events.swift +153 -0
  49. package/types/system/type.json +18 -0
@@ -0,0 +1,22 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "bluesky",
4
+ "description": "Bluesky posts, likes or follows from the public Jetstream firehose",
5
+ "flags": "--stream --websocket 'wss://jetstream2.us-east.bsky.network/subscribe?wantedCollections=<COLLECTION>&wantedDids=<DID>' --path commit --type-from json:commit.operation",
6
+ "placeholders": {
7
+ "COLLECTION": {
8
+ "description": "The record type: app.bsky.feed.post, app.bsky.feed.like or app.bsky.graph.follow",
9
+ "example": "app.bsky.feed.post"
10
+ },
11
+ "DID": {
12
+ "description": "The account to follow, as its did:plc:… (look it up at https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=<handle>)",
13
+ "example": "did:plc:z72i7hdynmk6r22z27h6tvur"
14
+ }
15
+ },
16
+ "tools": [],
17
+ "secrets": [],
18
+ "notes": [
19
+ "Without `&wantedDids=…` it is every account on Bluesky: thousands of Events a minute, which the rate cap drops; keep a filter.",
20
+ "`--path commit` leaves out identity and account messages; the Event type is `create`, `update` or `delete`, and `value.record.text` is a post's text."
21
+ ]
22
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "docker-events",
4
+ "description": "Docker container, image, network and volume events from the local engine",
5
+ "flags": "--stream --command 'docker events --format \"{{json .}}\"' --type-from json:Action",
6
+ "placeholders": {},
7
+ "tools": [
8
+ {
9
+ "name": "docker",
10
+ "install": "Docker Desktop, OrbStack or colima"
11
+ }
12
+ ],
13
+ "secrets": [],
14
+ "notes": [
15
+ "Each event's object (`Type`, `Action`, `Actor.Attributes.name`, …) is the payload, and its `Action` the Event type (`start`, `die`, `health_status: unhealthy`, …).",
16
+ "Narrow it in the command: `docker events --filter type=container --filter event=die --format \"{{json .}}\"`."
17
+ ]
18
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "github-releases",
4
+ "description": "New releases of a GitHub repository",
5
+ "flags": "--look feed --url 'https://github.com/<OWNER>/<REPO>/releases.atom' --every 15m",
6
+ "placeholders": {
7
+ "OWNER": {
8
+ "description": "The repository's owner",
9
+ "example": "oven-sh"
10
+ },
11
+ "REPO": {
12
+ "description": "The repository",
13
+ "example": "bun"
14
+ }
15
+ },
16
+ "tools": [],
17
+ "secrets": [],
18
+ "notes": [
19
+ "Each new release is an `entry` Event with its title and link; `--match '^v?\\d+\\.\\d+\\.\\d+$'` skips pre-releases named like `v1.2.0-rc.1`.",
20
+ "Use `/tags.atom` for tags, `/commits/<branch>.atom` for commits."
21
+ ]
22
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "gmail",
4
+ "description": "New mail in a Gmail or Google Workspace inbox, over IMAP with an app password; read-only",
5
+ "flags": "--type imap --option host=imap.gmail.com --option user=<ADDRESS> --option 'password=${GMAIL_APP_PASSWORD}'",
6
+ "placeholders": {
7
+ "ADDRESS": {
8
+ "description": "The Gmail address",
9
+ "example": "me@gmail.com"
10
+ }
11
+ },
12
+ "tools": [],
13
+ "secrets": [
14
+ {
15
+ "name": "GMAIL_APP_PASSWORD",
16
+ "description": "An app password: Google Account, Security, 2-Step Verification (must be on), App passwords; make one named poke and pipe its 16 letters into `poke secrets set GMAIL_APP_PASSWORD`. The account's own password is refused"
17
+ }
18
+ ],
19
+ "notes": [
20
+ "Each new mail is a `mail` Event: `from`, `fromName`, `to`, `subject`, `date`, `text` (up to 6000 characters), `attachments` (name, type and size) and `cut` when the mail was larger than what was read. The attachments themselves are kept as the Event's files (`--keep-days N`, default 7), except for a mail larger than what was read.",
21
+ "What is in the inbox when the Source first connects is the starting point and is not reported; mail that arrives while poke is down is reported on reconnect (up to 200).",
22
+ "Nothing is marked read: the mailbox is opened read-only and mail is fetched with BODY.PEEK.",
23
+ "Narrow it with `--option from=@bank.example` or `--option 'subject=statement|invoice'`. A sender can be forged: mail is always untrusted, and the Source cannot be raised to owner Trust.",
24
+ "Another folder: `--option 'mailbox=[Gmail]/All Mail'`.",
25
+ "Replies (opt-in, by SMTP, to the addresses you allow): add `--reply-secret GMAIL_APP_PASSWORD --reply-to <ADDRESS> --reply '{ printf \"From: %s\\r\\nTo: %s\\r\\nSubject: Re: your mail\\r\\n\\r\\n\" <ADDRESS> \"$POKE_REPLY_TO\"; cat; } | curl -sS --ssl-reqd --url smtps://smtp.gmail.com:465 --mail-from <ADDRESS> --mail-rcpt \"$POKE_REPLY_TO\" -T - -K /dev/fd/3 3<<EOF\nuser = \"<ADDRESS>:$GMAIL_APP_PASSWORD\"\nEOF'`. An agent then answers a mail with `poke reply <name> --event <id>` (to its Reply-To or sender) only when that address is on a `--reply-to`; the password reaches curl through a file descriptor, never its command line."
26
+ ]
27
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "home-assistant",
4
+ "description": "Home Assistant state changes over its WebSocket API",
5
+ "flags": "--stream --websocket 'wss://<HOST>/api/websocket' --hello '{\"type\":\"auth\",\"access_token\":\"${HA_TOKEN}\"}' --hello '{\"id\":1,\"type\":\"subscribe_events\",\"event_type\":\"state_changed\"}' --path event --type-from json:event.event_type",
6
+ "placeholders": {
7
+ "HOST": {
8
+ "description": "Home Assistant's address; use ws:// for a plain http one",
9
+ "example": "homeassistant.local:8123"
10
+ }
11
+ },
12
+ "tools": [],
13
+ "secrets": [
14
+ {
15
+ "name": "HA_TOKEN",
16
+ "description": "A long-lived access token from your Home Assistant profile page"
17
+ }
18
+ ],
19
+ "notes": [
20
+ "The two hello messages log in and subscribe on every connect. `--path event` leaves out the replies to them, so only events are reported, as `state_changed`.",
21
+ "`poke on <SOURCE> --where 'value.data.entity_id=binary_sensor.front_door'` follows one entity; `event_type` can be any Home Assistant event."
22
+ ]
23
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "journald-over-ssh",
4
+ "description": "A Linux machine's journal, followed over SSH: one Event per log entry",
5
+ "flags": "--stream --command 'ssh -o BatchMode=yes -o ServerAliveInterval=30 <HOST> journalctl -f -n0 -o json -u <UNIT>'",
6
+ "placeholders": {
7
+ "HOST": {
8
+ "description": "The machine, as ssh knows it (an alias in ~/.ssh/config works)",
9
+ "example": "pi@raspberrypi.local"
10
+ },
11
+ "UNIT": {
12
+ "description": "The systemd unit to follow",
13
+ "example": "nginx"
14
+ }
15
+ },
16
+ "tools": [
17
+ {
18
+ "name": "ssh",
19
+ "install": "ships with macOS; the host must accept your key without a prompt"
20
+ }
21
+ ],
22
+ "secrets": [],
23
+ "notes": [
24
+ "Each entry's JSON object (`MESSAGE`, `PRIORITY`, `_SYSTEMD_UNIT`, …) is the payload; `poke on <SOURCE> --where 'PRIORITY<=3'` keeps errors.",
25
+ "Drop `-u <UNIT>` to follow the whole journal. When ssh drops, poke reconnects and reports `down` after three quick failures."
26
+ ]
27
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "kubectl-watch",
4
+ "description": "Kubernetes events from the current context: pods failing, scheduling, pulling",
5
+ "flags": "--stream --command 'kubectl get events -A --watch-only -o json | jq -c --unbuffered \"{reason, type, message, object: (.involvedObject.kind + \\\"/\\\" + .involvedObject.namespace + \\\"/\\\" + .involvedObject.name)}\"' --type-from json:reason",
6
+ "placeholders": {},
7
+ "tools": [
8
+ {
9
+ "name": "kubectl",
10
+ "install": "brew install kubectl"
11
+ },
12
+ {
13
+ "name": "jq",
14
+ "install": "brew install jq"
15
+ }
16
+ ],
17
+ "secrets": [],
18
+ "notes": [
19
+ "`kubectl --watch -o json` prints objects across several lines; `jq -c` makes one line of each, so each Kubernetes event is one poke Event.",
20
+ "Use `--context <name>` or `-n <namespace>` in the command to pick a cluster or namespace; `poke on <SOURCE> --where 'type=Warning'` keeps the warnings."
21
+ ]
22
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "log-file",
4
+ "description": "New lines in a log file that match a pattern",
5
+ "flags": "--stream --command 'tail -n0 -F <FILE>' --match '<PATTERN>'",
6
+ "placeholders": {
7
+ "FILE": {
8
+ "description": "The log file; it may not exist yet, and may be rotated",
9
+ "example": "/var/log/system.log"
10
+ },
11
+ "PATTERN": {
12
+ "description": "A regular expression a line must match; its first group, if any, is the value",
13
+ "example": "error|fail"
14
+ }
15
+ },
16
+ "tools": [
17
+ {
18
+ "name": "tail",
19
+ "install": "ships with macOS"
20
+ }
21
+ ],
22
+ "secrets": [],
23
+ "notes": ["`tail -F` follows the file across rotation. Lines are `line` Events `{line, value}`."]
24
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "mastodon",
4
+ "description": "New posts on a Mastodon hashtag or your home timeline, over its streaming API",
5
+ "flags": "--stream --sse 'https://<INSTANCE>/api/v1/streaming/hashtag?tag=<TAG>' --event update --token-secret MASTODON_TOKEN",
6
+ "placeholders": {
7
+ "INSTANCE": {
8
+ "description": "Your Mastodon server",
9
+ "example": "mastodon.social"
10
+ },
11
+ "TAG": {
12
+ "description": "The hashtag, without #",
13
+ "example": "caturday"
14
+ }
15
+ },
16
+ "tools": [],
17
+ "secrets": [
18
+ {
19
+ "name": "MASTODON_TOKEN",
20
+ "description": "An access token with read scope, from Preferences > Development"
21
+ }
22
+ ],
23
+ "notes": [
24
+ "Use `/api/v1/streaming/user` for your home timeline and notifications (add `--event notification` for only those).",
25
+ "Each post's JSON (`content`, `account.acct`, `url`) is the Event's `value`."
26
+ ]
27
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "modbus",
4
+ "description": "Modbus TCP registers read again and again: an Event when their values change",
5
+ "flags": "--look command --command 'mbpoll -1 -q -t <TYPE> -r <REGISTER> -c <COUNT> <HOST>' --every <EVERY>",
6
+ "placeholders": {
7
+ "TYPE": {
8
+ "description": "The register type: 0 coils, 1 discrete inputs, 3 input registers, 4 holding registers",
9
+ "example": "4"
10
+ },
11
+ "REGISTER": {
12
+ "description": "The first register, counted from 1",
13
+ "example": "1"
14
+ },
15
+ "COUNT": {
16
+ "description": "How many registers",
17
+ "example": "2"
18
+ },
19
+ "HOST": {
20
+ "description": "The Modbus TCP device's address",
21
+ "example": "192.168.1.50"
22
+ },
23
+ "EVERY": {
24
+ "description": "How often to read",
25
+ "example": "30s"
26
+ }
27
+ },
28
+ "tools": [
29
+ {
30
+ "name": "mbpoll",
31
+ "install": "brew install mbpoll"
32
+ }
33
+ ],
34
+ "secrets": [],
35
+ "notes": [
36
+ "A change of the output (or of mbpoll's exit code, e.g. when the device stops answering) is a `changed` Event with the value before and after.",
37
+ "`--match 'Register \\[(\\d+)\\]:\\s*(\\d+)'` watches one value instead of the whole output.",
38
+ "For Modbus RTU over a serial line add `-m rtu -b <baud>` and give the device path instead of the host."
39
+ ]
40
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "mqtt",
4
+ "description": "Messages on MQTT topics: one Event per message, its topic and payload as fields",
5
+ "flags": "--stream --command 'mosquitto_sub -h <BROKER> -t \"<TOPIC>\" -F %j'",
6
+ "placeholders": {
7
+ "BROKER": {
8
+ "description": "The broker's host name",
9
+ "example": "test.mosquitto.org"
10
+ },
11
+ "TOPIC": {
12
+ "description": "A topic filter; + and # are wildcards (write $SYS topics as \\$SYS, since the command runs in sh)",
13
+ "example": "poke-demo/#"
14
+ }
15
+ },
16
+ "tools": [
17
+ {
18
+ "name": "mosquitto_sub",
19
+ "install": "brew install mosquitto"
20
+ }
21
+ ],
22
+ "secrets": [],
23
+ "notes": [
24
+ "Each message is a `line` Event whose payload is `{tst, topic, qos, retain, payloadlen, payload}`; filter with `poke on <SOURCE> --where 'topic=home/door'`.",
25
+ "For a broker that needs a login, put `-u <user> -P <password>` (or `--cafile`) in `~/.config/mosquitto_sub`, which mosquitto_sub reads by itself, so no password is in the declaration.",
26
+ "Add `-t` once per topic to follow several."
27
+ ]
28
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "ntfy",
4
+ "description": "Messages published to an ntfy topic (ntfy.sh or your own server)",
5
+ "flags": "--stream --sse 'https://<SERVER>/<TOPIC>/sse' --event message",
6
+ "placeholders": {
7
+ "SERVER": {
8
+ "description": "The ntfy server",
9
+ "example": "ntfy.sh"
10
+ },
11
+ "TOPIC": {
12
+ "description": "The topic; on ntfy.sh anyone who knows it can publish, so pick a long one",
13
+ "example": "poke-demo-topic"
14
+ }
15
+ },
16
+ "tools": [],
17
+ "secrets": [
18
+ {
19
+ "name": "NTFY_TOKEN",
20
+ "description": "Only for a protected topic: an access token, added as `--token-secret NTFY_TOKEN`"
21
+ }
22
+ ],
23
+ "notes": [
24
+ "Each message is a `message` Event whose `value` is ntfy's JSON (`id`, `time`, `topic`, `title`, `message`); `--path message` keeps only the text.",
25
+ "poke resumes with Last-Event-ID after a reconnect, and ntfy replays what it holds since then.",
26
+ "Publish with `curl -d hello https://<SERVER>/<TOPIC>`."
27
+ ]
28
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "kind": "recipe",
3
+ "name": "onvif",
4
+ "description": "ONVIF camera events (motion, tampering, line crossing): written as a Source type",
5
+ "steps": [
6
+ "ONVIF speaks SOAP with WS-Security digest logins and a pull-point subscription, which no Stream or Look declaration can say, so an agent writes it as a `told` Source type (docs/source-type-protocol.md).",
7
+ "type.json: name `onvif`, mode `told`, options `host` (string, required), `user` (string, required) and `password` (string, secret, required).",
8
+ "The process: GetCapabilities on `http://<host>/onvif/device_service` to find the Events service; CreatePullPointSubscription; then PullMessages in a loop (Timeout PT60S), renewing the subscription before its termination time.",
9
+ "Sign each request with a UsernameToken digest: base64(sha1(nonce + created + password)), from the PASSWORD environment variable.",
10
+ "For each NotificationMessage write `{\"event\":{\"type\":\"<topic's last part, e.g. MotionAlarm>\",\"payload\":{\"topic\":…,\"source\":…,\"data\":…}}}`; write a `status` line after each successful pull and exit non-zero when the camera stops answering, so poke restarts it.",
11
+ "`poke types add <dir>`, `poke secrets set CAMERA_PASSWORD`, then `poke sources add <SOURCE> --type onvif --option host=<ip> --option user=<user> --option 'password=${CAMERA_PASSWORD}'`."
12
+ ],
13
+ "tools": [],
14
+ "secrets": [
15
+ {
16
+ "name": "CAMERA_PASSWORD",
17
+ "description": "The camera user's password, passed as the `password` option `${CAMERA_PASSWORD}`"
18
+ }
19
+ ],
20
+ "notes": [
21
+ "Many cameras also offer RTSP and HTTP snapshots; poke does not watch video, only the events the camera reports."
22
+ ]
23
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "serial",
4
+ "description": "Lines a device writes to a serial port, such as an Arduino or a meter",
5
+ "flags": "--stream --command 'stty -f <DEVICE> <BAUD> raw && exec cat <DEVICE>'",
6
+ "placeholders": {
7
+ "DEVICE": {
8
+ "description": "The serial device",
9
+ "example": "/dev/cu.usbmodem1101"
10
+ },
11
+ "BAUD": {
12
+ "description": "The line speed",
13
+ "example": "9600"
14
+ }
15
+ },
16
+ "tools": [
17
+ {
18
+ "name": "stty",
19
+ "install": "ships with macOS"
20
+ },
21
+ {
22
+ "name": "cat",
23
+ "install": "ships with macOS"
24
+ }
25
+ ],
26
+ "secrets": [],
27
+ "notes": [
28
+ "On Linux `stty` takes `-F` instead of `-f`.",
29
+ "A device that writes JSON lines gives each line's object as the payload; `--type-from json:<field>` names the Event type from it."
30
+ ]
31
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "status-page",
4
+ "description": "A service's status page (Atlassian Statuspage): an Event when its overall status changes",
5
+ "flags": "--look http --url 'https://<PAGE>/api/v2/status.json' --path status.indicator --every 5m",
6
+ "placeholders": {
7
+ "PAGE": {
8
+ "description": "The status page's host",
9
+ "example": "www.githubstatus.com"
10
+ }
11
+ },
12
+ "tools": [],
13
+ "secrets": [],
14
+ "notes": [
15
+ "`status.indicator` is `none`, `minor`, `major` or `critical`; a change is a `changed` Event with both values.",
16
+ "For each incident instead, use the page's feed: `--look feed --url 'https://<PAGE>/history.atom'`."
17
+ ]
18
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "kind": "declaration",
3
+ "name": "syslog",
4
+ "description": "Syslog messages sent to this Mac over UDP: one Event per message",
5
+ "flags": "--stream --command 'nc -lku <PORT>'",
6
+ "placeholders": {
7
+ "PORT": {
8
+ "description": "The UDP port the devices send to (514 needs root, so use a high one)",
9
+ "example": "5514"
10
+ }
11
+ },
12
+ "tools": [
13
+ {
14
+ "name": "nc",
15
+ "install": "ships with macOS"
16
+ }
17
+ ],
18
+ "secrets": [],
19
+ "notes": [
20
+ "`nc` binds the port, not poke: the daemon binds no ports (ADR 0004). Point each device's remote syslog at this Mac's address and the port.",
21
+ "Each message is a `line` Event `{line}`; `--match '<(\\d+)>'` keeps only lines with a priority and makes it the value.",
22
+ "Try it with `printf '<14>hello\\n' | nc -u -w1 127.0.0.1 <PORT>`."
23
+ ]
24
+ }