agents-framework 0.3.0__py3-none-any.whl
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.
- agents_framework-0.3.0.dist-info/METADATA +1364 -0
- agents_framework-0.3.0.dist-info/RECORD +50 -0
- agents_framework-0.3.0.dist-info/WHEEL +5 -0
- agents_framework-0.3.0.dist-info/entry_points.txt +2 -0
- agents_framework-0.3.0.dist-info/licenses/LICENSE +661 -0
- agents_framework-0.3.0.dist-info/top_level.txt +1 -0
- framework/__init__.py +0 -0
- framework/__main__.py +9 -0
- framework/action_page.py +1102 -0
- framework/approval_buttons.py +775 -0
- framework/approvals.py +678 -0
- framework/calendar_card.py +276 -0
- framework/cli.py +273 -0
- framework/codex_llm.py +401 -0
- framework/config.py +126 -0
- framework/drafter.py +263 -0
- framework/interfaces.py +96 -0
- framework/llm.py +744 -0
- framework/plugins/__init__.py +147 -0
- framework/plugins/agentmail_source.py +355 -0
- framework/plugins/approval_destination.py +478 -0
- framework/plugins/command_action.py +248 -0
- framework/plugins/digest_destination.py +546 -0
- framework/plugins/email_destination.py +248 -0
- framework/plugins/fanout_destination.py +160 -0
- framework/plugins/github_org_source.py +226 -0
- framework/plugins/github_releases_source.py +420 -0
- framework/plugins/ics_source.py +594 -0
- framework/plugins/llm_scorer.py +411 -0
- framework/plugins/multi_source.py +241 -0
- framework/plugins/reddit_source.py +625 -0
- framework/plugins/regex_scorer.py +93 -0
- framework/plugins/rss_source.py +346 -0
- framework/plugins/signal_destination.py +133 -0
- framework/plugins/slack_destination.py +461 -0
- framework/plugins/slack_draft_action.py +137 -0
- framework/plugins/slack_post_action.py +65 -0
- framework/plugins/slack_workspace_source.py +992 -0
- framework/plugins/twitter_action.py +210 -0
- framework/plugins/websearch_source.py +761 -0
- framework/plugins/wordpress_action.py +413 -0
- framework/proposals.py +246 -0
- framework/registry.py +166 -0
- framework/runlog.py +125 -0
- framework/runner.py +243 -0
- framework/schedule.py +571 -0
- framework/signal_messenger.py +1418 -0
- framework/slack.py +801 -0
- framework/state.py +39 -0
- framework/templating.py +76 -0
|
@@ -0,0 +1,1364 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agents-framework
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Framework for small, single-purpose pain-signal / lead-finding agents.
|
|
5
|
+
License-Expression: AGPL-3.0-or-later
|
|
6
|
+
Project-URL: Homepage, https://github.com/voitta-ai/agents
|
|
7
|
+
Project-URL: Source, https://github.com/voitta-ai/agents
|
|
8
|
+
Project-URL: Releases, https://github.com/voitta-ai/agents/releases
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: requests>=2.31
|
|
13
|
+
Requires-Dist: feedparser>=6.0
|
|
14
|
+
Requires-Dist: httpx>=0.28
|
|
15
|
+
Requires-Dist: icalendar>=6.0
|
|
16
|
+
Requires-Dist: litellm>=1.83
|
|
17
|
+
Requires-Dist: python-dateutil>=2.9
|
|
18
|
+
Requires-Dist: tzdata>=2024.1
|
|
19
|
+
Requires-Dist: markdown-it-py>=3.0
|
|
20
|
+
Provides-Extra: slack-session
|
|
21
|
+
Requires-Dist: pycookiecheat>=0.6; extra == "slack-session"
|
|
22
|
+
Provides-Extra: twitter
|
|
23
|
+
Requires-Dist: requests-oauthlib>=1.3; extra == "twitter"
|
|
24
|
+
Provides-Extra: approvals-buttons
|
|
25
|
+
Requires-Dist: slack_sdk>=3.27; extra == "approvals-buttons"
|
|
26
|
+
Requires-Dist: websocket-client>=1.7; extra == "approvals-buttons"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# agents
|
|
30
|
+
|
|
31
|
+
Framework for small, single-purpose pain-signal / lead-finding agents that run
|
|
32
|
+
as short-lived, cron/launchd-invoked processes (not daemons).
|
|
33
|
+
|
|
34
|
+
## If you arrived here cold
|
|
35
|
+
|
|
36
|
+
An agent here is four pieces and a clock. A **source** it reads, a **scorer**
|
|
37
|
+
that rates what it found, a **destination** that receives whatever cleared the
|
|
38
|
+
bar, and **state** so the next run does not repeat the last one. You declare
|
|
39
|
+
those four in one JSON file and the framework runs them; each piece is a plugin,
|
|
40
|
+
so a new source or destination is a class and a registry entry rather than a
|
|
41
|
+
fork.
|
|
42
|
+
|
|
43
|
+
Three things run on it today:
|
|
44
|
+
|
|
45
|
+
- **Reddit lead-finding** — reads new posts across a list of subreddits, has a
|
|
46
|
+
model judge which of them is somebody describing a problem worth answering,
|
|
47
|
+
and posts what clears the threshold to Slack together with a drafted reply
|
|
48
|
+
that a human sends, edits or discards.
|
|
49
|
+
- **Digests of community Slack workspaces** — workspaces we take part in but do
|
|
50
|
+
not administer, read either through their own notification emails or as the
|
|
51
|
+
logged-in browser user, and summarized.
|
|
52
|
+
- **Weekly release notes** — one signal per GitHub release across an
|
|
53
|
+
organization since the last run.
|
|
54
|
+
|
|
55
|
+
It is worth your time if you want a scored feed out of a noisy source and would
|
|
56
|
+
rather write a config than a service. It is not a general agent framework, an
|
|
57
|
+
orchestrator or a chatbot: nothing here holds a conversation, and an agent does
|
|
58
|
+
not decide to act on its own. Where an action would have consequences outside
|
|
59
|
+
the agent — publishing a post, sending an application — the destination
|
|
60
|
+
proposes and a human approves before anything leaves (see
|
|
61
|
+
[Approval-gated actions](#approval-gated-actions)).
|
|
62
|
+
|
|
63
|
+
### Run one
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
git clone https://github.com/voitta-ai/agents && cd agents
|
|
67
|
+
python3 -m venv .venv && . .venv/bin/activate
|
|
68
|
+
pip install -e .
|
|
69
|
+
|
|
70
|
+
mkdir -p ~/agent-workspaces/reddit-leads
|
|
71
|
+
cp agents/reddit-leads/config.example.json \
|
|
72
|
+
~/agent-workspaces/reddit-leads/config.json
|
|
73
|
+
# Edit that file. Two edits are needed before the first run; the rest is
|
|
74
|
+
# yours.
|
|
75
|
+
#
|
|
76
|
+
# 1. Delete the "drafter" block under "destination". It names three
|
|
77
|
+
# grounding documents by absolute path, and those are placeholders.
|
|
78
|
+
# Grounding files are read when the agent starts and a missing one is
|
|
79
|
+
# refused rather than skipped: a draft makes claims about you, so an
|
|
80
|
+
# unreadable source is a misconfiguration and not a degraded run. Put
|
|
81
|
+
# the block back, with real paths, when you want drafts.
|
|
82
|
+
# 2. Set SLACK_LEADS_WEBHOOK. The webhook URL is deliberately not written
|
|
83
|
+
# in the file -- the route names the environment variable that holds it.
|
|
84
|
+
#
|
|
85
|
+
# After that the subreddits and the scoring rules are yours. The example ships
|
|
86
|
+
# the keyword scorer, which needs no model and no key. Swapping it for
|
|
87
|
+
# "type": "llm" is what the deployment above runs, and that one also needs a
|
|
88
|
+
# model chain: an "llm" block in this file, or a shared one at
|
|
89
|
+
# <workspaces-root>/_shared/llm.json (see LLM waterfall below).
|
|
90
|
+
agent run --workspace ~/agent-workspaces/reddit-leads
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
With those two edits the run goes end to end. The workspace is a directory
|
|
94
|
+
outside any git checkout holding that agent's config, its dedupe state and its
|
|
95
|
+
logs, which is what makes a merge to master not a deploy; see
|
|
96
|
+
[Layout](#layout). When the run looks right,
|
|
97
|
+
`agent install-schedule --workspace <path>` turns the config's `schedule` into
|
|
98
|
+
the launchd job that invokes it from then on; see [Scheduling](#scheduling).
|
|
99
|
+
|
|
100
|
+
## Shape
|
|
101
|
+
|
|
102
|
+
- **Source** — where signals come from (e.g. Reddit RSS). Plugin interface,
|
|
103
|
+
one implementation per source. See `framework/interfaces.py`.
|
|
104
|
+
- **Scorer** — turns raw signals into a score. `regex` is presence-based keyword
|
|
105
|
+
matching; `llm` asks a model through the waterfall in `framework/llm.py` and is
|
|
106
|
+
configured by a prompt rather than rules (issue #9).
|
|
107
|
+
- **Destination** — where scored signals get sent (Slack first; email later).
|
|
108
|
+
Two-tier routing (hot / firehose) is a Slack-destination concern, not a
|
|
109
|
+
framework concern.
|
|
110
|
+
- **State** — the framework's own job: dedupe between runs so a double-fire
|
|
111
|
+
from cron isn't harmful. See `framework/state.py`.
|
|
112
|
+
|
|
113
|
+
## What this framework does *not* own
|
|
114
|
+
|
|
115
|
+
No scheduler daemon. Each agent is invoked run-and-exit (launchd owns the
|
|
116
|
+
clock); the agent declares its cadence as `schedule` in its config, and
|
|
117
|
+
`agent install-schedule` turns that into the launchd job (see Scheduling).
|
|
118
|
+
|
|
119
|
+
No built-in interactivity/HITL loop. [Shmobster](https://github.com/voitta-ai/shmobster)
|
|
120
|
+
is the preferred/default pattern for human-in-the-loop Slack interactivity
|
|
121
|
+
(we own it, it's Slack-native already) — not a hard dependency, just the
|
|
122
|
+
stated default until an agent has a real reason to do something else.
|
|
123
|
+
|
|
124
|
+
## Layout
|
|
125
|
+
|
|
126
|
+
The repo holds code and placeholder examples only:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
framework/ core: plugin interfaces, entrypoint contract, state/dedupe
|
|
130
|
+
agents/<name>/config.example.json one committed, placeholder-only example per agent
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
A deployed agent lives in a **workspace**: one directory per agent, outside any
|
|
134
|
+
git checkout, holding everything that agent owns at runtime. A merge to master
|
|
135
|
+
is then not a deploy, and nothing an agent writes lands in the working tree.
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
<workspaces-root>/ $AGENT_WORKSPACES_ROOT, else ~/agent-workspaces
|
|
139
|
+
_shared/
|
|
140
|
+
llm.json the deployment's LLM waterfall (see below)
|
|
141
|
+
<agent-name>/
|
|
142
|
+
config.json the agent's declaration; the only file a human edits
|
|
143
|
+
state/seen.json SeenStore dedupe state (default; --state overrides)
|
|
144
|
+
state/llm-parked.json vendors parked for budget exhaustion, with expiries
|
|
145
|
+
logs/ run.log / run.error.log (and approvals.*) when scheduled
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
agent run --workspace <workspaces-root>/<agent-name>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
`run` always takes the explicit workspace path; the root default is only for
|
|
153
|
+
helpers that take an agent *name*. Config is JSON: copy an example in as
|
|
154
|
+
`config.json` and fill in real values. A `"_comment"` key anywhere is ignored by
|
|
155
|
+
the framework and by every plugin, and is where decisions worth keeping go.
|
|
156
|
+
|
|
157
|
+
## LLM waterfall
|
|
158
|
+
|
|
159
|
+
Every LLM-backed plugin (the `llm` scorer, the `digest` destination) calls one
|
|
160
|
+
ordered chain of vendors through LiteLLM's Router (`framework/llm.py`, issue
|
|
161
|
+
#44). The chain is `<workspaces-root>/_shared/llm.json`, one per deployment; a
|
|
162
|
+
plugin block with its own `"llm": {...}` of the same shape uses that instead.
|
|
163
|
+
Copy `docs/llm.example.json` to start. Each row names the env var holding its
|
|
164
|
+
key (`api_key_env`), never the key; a `codex/chatgpt/<model>` row runs on the
|
|
165
|
+
ChatGPT subscription with no key, reading the codex CLI's `~/.codex/auth.json`
|
|
166
|
+
(`codex login` when it expires). A vendor that answers with a budget-exhaustion
|
|
167
|
+
error is parked for `budget_park_sec` (or until the date it names, at most 31
|
|
168
|
+
days out) in
|
|
169
|
+
`<workspace>/state/llm-parked.json`; delete an entry to un-park it early.
|
|
170
|
+
Fallbacks and parks print one `llm:` line each on stderr.
|
|
171
|
+
|
|
172
|
+
## Scheduling
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
agent install-schedule --workspace <dir> [--label <label>] [--venv <path>] [--force] [--dry-run]
|
|
176
|
+
agent uninstall-schedule --workspace <dir> [--label <label>] [--force]
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`install-schedule` (macOS) writes `~/Library/LaunchAgents/<label>.plist` from
|
|
180
|
+
the workspace's `config.json` and loads it with `launchctl bootstrap`, booting
|
|
181
|
+
out the loaded job first, so re-running it is how a changed schedule is
|
|
182
|
+
deployed. The label defaults to `com.agents.<agent>`; pass `--label` to keep an
|
|
183
|
+
existing deployment's name, and pass the same `--label` to uninstall. The job
|
|
184
|
+
runs `/bin/bash -lc "exec <venv>/bin/agent run --workspace <dir>"` (the login
|
|
185
|
+
profile supplies credentials), from the workspace, logging to `<dir>/logs/`.
|
|
186
|
+
`--venv` defaults to the venv of the `agent` you ran. `--dry-run` prints the
|
|
187
|
+
plist(s) and does nothing else.
|
|
188
|
+
|
|
189
|
+
A workspace gets one job, two, or three: `agent run` on `schedule`, plus
|
|
190
|
+
`<label>.approvals` on `approvals.schedule` when the config has an `approvals`
|
|
191
|
+
block, plus `<label>.approvals.listen` when that block says `"listen": true`.
|
|
192
|
+
The listener is the one job with no schedule: `KeepAlive` instead of an
|
|
193
|
+
interval (see "Buttons instead of replies"). A job the config no longer asks
|
|
194
|
+
for is removed by the next install.
|
|
195
|
+
|
|
196
|
+
Every generated plist is marked with `AgentsFrameworkManaged` and
|
|
197
|
+
`AgentsFrameworkWorkspace` (the workspace path). Install and uninstall refuse
|
|
198
|
+
to touch a label whose plist lacks the marker, belongs to another workspace, or
|
|
199
|
+
is loaded from somewhere else, and print what it runs; `--force` takes it
|
|
200
|
+
over. If bootstrapping an updated plist fails, the previous plist is put back
|
|
201
|
+
and reloaded, and the error says whether that worked.
|
|
202
|
+
|
|
203
|
+
- `schedule` (required): `"every 30m"` / `"every 4h"` becomes `StartInterval`,
|
|
204
|
+
counted from when the job loaded. A five-field cron string becomes
|
|
205
|
+
`StartCalendarInterval`, aligned to the clock: `"0 */4 * * *"` fires at
|
|
206
|
+
00:00, 04:00, ... 20:00, `"0 14 * * 3"` Wednesdays at 14:00, `"0 17 * * 0"`
|
|
207
|
+
(or `7`) Sundays at 17:00. Fields take numbers, `A-B` ranges and comma lists;
|
|
208
|
+
minute and hour also take `*/N`. Names, `@daily`, stepped ranges, `*/N` in
|
|
209
|
+
the date fields, and restricting both day-of-month and day-of-week are
|
|
210
|
+
rejected. A bad schedule fails before anything is written.
|
|
211
|
+
- `approvals.schedule` (default `"every 5m"`): when the config has an
|
|
212
|
+
`approvals` block, a second job `<label>.approvals` runs `agent approvals`
|
|
213
|
+
on this schedule, logging to `logs/approvals.log`. Removing the block and
|
|
214
|
+
re-installing removes that job; uninstall removes both.
|
|
215
|
+
|
|
216
|
+
Re-installing boots out a job that is mid-pass, which terminates it. For
|
|
217
|
+
`agent run` that costs nothing (undelivered signals are not marked seen), but
|
|
218
|
+
an `agent approvals` pass killed mid-steps leaves its proposal stuck (see
|
|
219
|
+
Approval-gated actions), so avoid re-installing while one is executing.
|
|
220
|
+
|
|
221
|
+
## Agents
|
|
222
|
+
|
|
223
|
+
- `agents/reddit-leads/` — reads new posts from a list of subreddits and
|
|
224
|
+
scores each one for somebody describing a problem worth answering. See
|
|
225
|
+
issue #8.
|
|
226
|
+
- `agents/slack-workspace/` — digests community Slack workspaces we
|
|
227
|
+
participate in but don't administer, via their own notification emails
|
|
228
|
+
forwarded to AgentMail. See issue #19. An inbox that looks empty is usually
|
|
229
|
+
the `trash` label, which the AgentMail listing hides unless `include_trash`
|
|
230
|
+
is set (issue #61).
|
|
231
|
+
- `agents/slack-workspace/` with `transport: session` — reads channels of such
|
|
232
|
+
a workspace as the logged-in browser user (`d` cookie decrypted from the
|
|
233
|
+
local browser store, `xoxc` token scraped per run, nothing stored).
|
|
234
|
+
`channels` takes names or conversation ids (`C...`/`G...`, and `D...` for a
|
|
235
|
+
direct message, which has no name to resolve), and `from_users` keeps only
|
|
236
|
+
the authors named, so a bot's DM reads without your own replies (issue #61).
|
|
237
|
+
On an Enterprise Grid org a user session cannot list channels or ask for
|
|
238
|
+
permalinks, so names raise with ids named as the remedy and links are
|
|
239
|
+
constructed (`meta.permalink_source`); ids work there unchanged (issue #69).
|
|
240
|
+
A signal's `meta` carries `job_url` (the message's first link) and, when a
|
|
241
|
+
bot posts a distinct one, `apply_url`, so a destination can link what the
|
|
242
|
+
message is about rather than only the message (issue #76).
|
|
243
|
+
Read-only by construction: the client refuses every Slack method outside a
|
|
244
|
+
fixed allowlist before any HTTP. Needs `pip install '.[slack-session]'`
|
|
245
|
+
(pycookiecheat). See issue #45.
|
|
246
|
+
- `agents/release-notes/` — one signal per GitHub release across an org since
|
|
247
|
+
the last run, for the weekly release-notes digest. Uses the `github-releases`
|
|
248
|
+
source (issue #46), which keeps its own window in
|
|
249
|
+
`<workspace>/state/github-releases.json` and advances it only after a run has
|
|
250
|
+
delivered (`Source.commit()`, see `docs/PLUGIN-CONTRACT.md`).
|
|
251
|
+
|
|
252
|
+
## Approval-gated actions
|
|
253
|
+
|
|
254
|
+
Some agents end in something that should not happen without a human saying so:
|
|
255
|
+
publishing a post, sending an application. For those the destination is
|
|
256
|
+
`approval`, which wraps the destination that writes the content and records a
|
|
257
|
+
**proposal** instead of posting it (issue #21):
|
|
258
|
+
|
|
259
|
+
```json
|
|
260
|
+
"destination": {
|
|
261
|
+
"type": "approval",
|
|
262
|
+
"webhook_env": "SOME_WEBHOOK",
|
|
263
|
+
"wrap": {"type": "digest", "webhook_env": "SOME_WEBHOOK", "prompt": "..."},
|
|
264
|
+
"actions": ["publish-post"]
|
|
265
|
+
},
|
|
266
|
+
"approvals": {
|
|
267
|
+
"schedule": "every 5m",
|
|
268
|
+
"channel_id": "C0123456789",
|
|
269
|
+
"bot_token_env": "SOME_BOT_TOKEN",
|
|
270
|
+
"trusted_user_ids": ["U0123456789"],
|
|
271
|
+
"hours": 24
|
|
272
|
+
},
|
|
273
|
+
"actions": {
|
|
274
|
+
"publish-post": {
|
|
275
|
+
"steps": [
|
|
276
|
+
{"type": "slack-post", "webhook_env": "SOME_WEBHOOK", "text": "Published: {url}"}
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
The run posts the rendered content plus `Proposal p7-k3f: publish-post. Reply
|
|
283
|
+
"do p7-k3f" or "skip p7-k3f".` and writes the proposal to
|
|
284
|
+
`<workspace>/state/proposals.json`. The proposal is the delivery, so dedupe
|
|
285
|
+
state is marked as usual. Ids are a per-workspace counter plus a random suffix,
|
|
286
|
+
so a reply cannot be typed before the proposal exists; the whole id is required.
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
agent approvals --workspace <workspaces-root>/<agent-name>
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
is the second scheduled entrypoint (`approvals.schedule`, every 5 minutes by
|
|
293
|
+
default, installed as its own job by `install-schedule`). It reads the channel's
|
|
294
|
+
last `hours` of history with the bot token, and for each pending proposal a
|
|
295
|
+
user in `trusted_user_ids` has answered with exactly `do <id>` or `skip <id>`
|
|
296
|
+
**as a top-level channel message posted after the proposal was recorded**,
|
|
297
|
+
claims it (`pending` -> `running`, atomically, so two overlapping passes cannot
|
|
298
|
+
both execute it), runs the named action's `steps` in order or marks it
|
|
299
|
+
skipped, posts one outcome message, and prints `agent=<name> status=ok
|
|
300
|
+
approvals=N executed=N skipped=N failed=N stuck=N`. A failing step stops the
|
|
301
|
+
sequence, leaves the proposal `failed` naming the step, and nothing is retried.
|
|
302
|
+
Anything that is not exactly `do`/`skip` from a trusted user is ignored, and so
|
|
303
|
+
is a reply older than the proposal it names. Replies typed *in a thread* are
|
|
304
|
+
not seen (`conversations.history` returns top-level messages only); reply in
|
|
305
|
+
the channel. The bot token needs `channels:history` (or `groups:history` for a
|
|
306
|
+
private channel) and `chat:write`.
|
|
307
|
+
|
|
308
|
+
A proposal left `running` by a pass that is no longer alive (or claimed more
|
|
309
|
+
than `hours` ago) means that pass died mid-steps. It is never re-run on its
|
|
310
|
+
own: every pass reports it on stderr and as `stuck=N`, and the channel is told
|
|
311
|
+
once which steps the store recorded as done. Re-running it is a manual edit of
|
|
312
|
+
`state/proposals.json`: set its `status` back to `"pending"`, and the next pass
|
|
313
|
+
runs all of its steps again, including any that already happened, if the
|
|
314
|
+
original `do` is still inside the `hours` window (otherwise reply `do` again).
|
|
315
|
+
To close it instead, set `"failed"`.
|
|
316
|
+
|
|
317
|
+
### Buttons instead of replies
|
|
318
|
+
|
|
319
|
+
Replying `do <id>` works, but the case that matters most -- a drafted blog post
|
|
320
|
+
-- wants one click, and a third answer the reply grammar has no room for. With
|
|
321
|
+
`"buttons": true` on the `approval` destination, a proposal is posted as Block
|
|
322
|
+
Kit with three buttons (issue #74):
|
|
323
|
+
|
|
324
|
+
- **Post** runs the action as configured.
|
|
325
|
+
- **Draft** runs the same sequence with the `wordpress-publish` step forced to
|
|
326
|
+
`mode: draft`, and skips every step after it, so the post lands in the editor
|
|
327
|
+
and nothing is announced. An action with no `wordpress-publish` step has
|
|
328
|
+
nothing to draft: the click is refused, to that user only, and the proposal
|
|
329
|
+
stays pending.
|
|
330
|
+
- **Discard** marks the proposal skipped. No step runs.
|
|
331
|
+
|
|
332
|
+
After a click the message is edited in place to say what happened, by whom and
|
|
333
|
+
when, so the channel shows the outcome instead of a stale prompt. Which variant
|
|
334
|
+
ran is recorded on the proposal, next to who decided it and whether it came
|
|
335
|
+
from a button or a reply.
|
|
336
|
+
|
|
337
|
+
A button needs Slack to deliver the click somewhere, which normally means a
|
|
338
|
+
public HTTPS endpoint. Socket Mode dials out instead:
|
|
339
|
+
|
|
340
|
+
```
|
|
341
|
+
agent approvals --listen --workspace <workspaces-root>/<agent-name>
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
is a long-running client holding that connection. It needs an app-level token
|
|
345
|
+
(`xapp-...`, scope `connections:write`, and Socket Mode plus Interactivity
|
|
346
|
+
turned on for the app), named by `approvals.app_token_env` the same way the bot
|
|
347
|
+
token is named by `bot_token_env`. Install it with `"listen": true` in the
|
|
348
|
+
`approvals` block; `install-schedule` then writes a third job,
|
|
349
|
+
`<label>.approvals.listen`, with `KeepAlive` and no interval, so launchd
|
|
350
|
+
restarts it whenever it exits -- a dropped connection or a slept laptop becomes
|
|
351
|
+
a reconnect. The listener is what holds launchd to that: it polls its own
|
|
352
|
+
connection every 30 seconds and exits nonzero once it has been without one for
|
|
353
|
+
three minutes, since a client that has stopped reconnecting on its own would
|
|
354
|
+
otherwise keep the process alive, the job reported as running, and every button
|
|
355
|
+
in the channel dead. It needs `pip install '.[approvals-buttons]'` (slack_sdk,
|
|
356
|
+
websocket-client).
|
|
357
|
+
|
|
358
|
+
#### Which Slack app the listener connects as
|
|
359
|
+
|
|
360
|
+
**One Socket Mode consumer per Slack app.** Slack spreads an app's events and
|
|
361
|
+
interactions across all of that app's open Socket Mode connections, and each
|
|
362
|
+
one goes to only one of them. Whatever else connects with the same `xapp-`
|
|
363
|
+
token takes a share of the traffic. The listener acks every envelope and keeps
|
|
364
|
+
only button clicks, so anything else sent to it is dropped without a trace.
|
|
365
|
+
|
|
366
|
+
- **Never use a chat agent's app.** If `app_token_env` names the app-level
|
|
367
|
+
token of a bot that answers `@`-mentions over Socket Mode, the listener
|
|
368
|
+
silently eats a share of those mentions. The bot sees nothing, logs nothing,
|
|
369
|
+
and its own connection stays healthy, so the miss looks random. This
|
|
370
|
+
happened: a listener on a chat agent's app dropped a share of its
|
|
371
|
+
mentions for a week before anyone traced it.
|
|
372
|
+
- **Use one shared app for the agents' approvals,** not one app per agent. It
|
|
373
|
+
posts the cards (its bot token goes in `bot_token_env`, so the clicks come
|
|
374
|
+
back to the same app) and holds the one Socket Mode connection
|
|
375
|
+
(`app_token_env`). It must be invited to every approval channel. Create it
|
|
376
|
+
from [`docs/slack-app-manifest.yaml`](docs/slack-app-manifest.yaml), which
|
|
377
|
+
carries the full scope set.
|
|
378
|
+
- **One listener per app, serving every workspace on it** (issue #103). Exactly
|
|
379
|
+
one workspace per app sets `"listen": true` and names the others in
|
|
380
|
+
`approvals.listen_for`, as sibling workspace names:
|
|
381
|
+
|
|
382
|
+
```json
|
|
383
|
+
"approvals": {"listen": true, "app_token_env": "SOME_APP_TOKEN",
|
|
384
|
+
"listen_for": ["slack-workspace"], "...": "..."}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
A card's buttons carry `<workspace>/<proposal id>`, and the listener sends
|
|
388
|
+
each click to that workspace's own store, channel, trusted users, bot token
|
|
389
|
+
and actions; only the connection is shared. The other workspaces keep their
|
|
390
|
+
`approvals` block (channel, `bot_token_env`, `trusted_user_ids`) and their
|
|
391
|
+
polling pass, but set no `listen` and need no `app_token_env`. A second
|
|
392
|
+
`"listen": true` on the same app is a second connection, and Slack would split
|
|
393
|
+
the clicks between the two. A served workspace whose config does not load
|
|
394
|
+
stops the listener at startup. Cards posted before #103 carry a bare id; the
|
|
395
|
+
listener finds the one store that holds it, and refuses (pointing at
|
|
396
|
+
`do <id>`) if none or several do.
|
|
397
|
+
|
|
398
|
+
An incoming webhook never receives anything, so webhooks can be shared freely.
|
|
399
|
+
They do not count as consumers.
|
|
400
|
+
|
|
401
|
+
The polling pass stays installed next to it, and is the reason a click that
|
|
402
|
+
never arrives is not a lost proposal: `do <id>` still resolves it. Both paths
|
|
403
|
+
take the same `pending -> running` claim, so a click racing a reply cannot run
|
|
404
|
+
the steps twice -- whichever claims first runs, and the other is told the
|
|
405
|
+
proposal is already spoken for. One consequence to know: a proposal resolved by
|
|
406
|
+
*reply* keeps its buttons, because the webhook that posted it returns no message
|
|
407
|
+
`ts` to edit. Clicking them afterwards runs nothing and says so, to the clicker
|
|
408
|
+
only.
|
|
409
|
+
|
|
410
|
+
One operator action to know about: a proposal carries no channel of its own, so
|
|
411
|
+
changing `approvals.channel_id` while proposals are still pending strands them.
|
|
412
|
+
Their buttons refuse as "wrong channel", visibly only to whoever clicked, and
|
|
413
|
+
the reply path will not see a `do` either, since it reads only the configured
|
|
414
|
+
channel's history. Resolve what is pending before moving an agent to a new
|
|
415
|
+
approval channel, or edit `state/proposals.json` and let the next run propose
|
|
416
|
+
them again.
|
|
417
|
+
|
|
418
|
+
### A link instead of Slack: the action page
|
|
419
|
+
|
|
420
|
+
Both paths above need a Slack account in the agent's workspace. The people who
|
|
421
|
+
decide on leads are not all in Slack and do not all want to be, which is the
|
|
422
|
+
reason Signal became a second interface at all. So a proposal can also carry a
|
|
423
|
+
link: a blurb goes to whatever surface the person reads, the link opens a page
|
|
424
|
+
with the same verdicts the buttons offer, and the decision happens there
|
|
425
|
+
(issue #124).
|
|
426
|
+
|
|
427
|
+
```json
|
|
428
|
+
"approvals": {
|
|
429
|
+
"channel_id": "C0123456789",
|
|
430
|
+
"bot_token_env": "SOME_BOT_TOKEN",
|
|
431
|
+
"trusted_user_ids": ["U0123456789"],
|
|
432
|
+
"action_page": {
|
|
433
|
+
"base_url": "https://example.invalid/leads",
|
|
434
|
+
"bind": "127.0.0.1",
|
|
435
|
+
"port": 8731,
|
|
436
|
+
"post_label": "Draft outreach"
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
`base_url` is how the link reads to whoever receives it, which is not
|
|
442
|
+
necessarily how the process is reached: a tunnel or a reverse proxy sits in
|
|
443
|
+
between, so the two are separate keys and nothing guesses. It is the only one a
|
|
444
|
+
posting run needs; `bind` and `port` are read by the listener that serves the
|
|
445
|
+
page. `post_label` renames the first verdict, for the same reason the card can.
|
|
446
|
+
A workspace with no `action_page` behaves exactly as before and posts no link.
|
|
447
|
+
|
|
448
|
+
The page is served by the same long-running process as the buttons:
|
|
449
|
+
|
|
450
|
+
```
|
|
451
|
+
agent approvals --listen --workspace <workspaces-root>/<agent-name>
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
`--listen` now needs *either* an app-level token (for buttons) or an
|
|
455
|
+
`action_page` (for links), or both. A deployment that wants only links needs no
|
|
456
|
+
Slack app, no app token and no Socket Mode.
|
|
457
|
+
|
|
458
|
+
**The surfaces do not need reconciling, because there is only one of them.**
|
|
459
|
+
The same lead announced to a Slack channel and a Signal group is one proposal
|
|
460
|
+
with one link, so resolving it resolves it everywhere by construction. There is
|
|
461
|
+
no cross-surface state to converge, no window in which two surfaces both act,
|
|
462
|
+
and no half-closed item. A further surface -- email, SMS, a web digest -- needs
|
|
463
|
+
only to render a blurb and a URL, and needs no way to send a decision back,
|
|
464
|
+
which is what made approving from Signal expensive (that is issue #121, a
|
|
465
|
+
receive loop on an account only one process can hold; a link needs none of it).
|
|
466
|
+
|
|
467
|
+
A tap, a button click and a `do <id>` reply all take the proposal through the
|
|
468
|
+
same `pending -> running` claim, so no two of them can run the steps. Verified
|
|
469
|
+
against this implementation: eight concurrent taps on one link run the action
|
|
470
|
+
exactly once and tell the other seven the proposal is already spoken for, and a
|
|
471
|
+
tap is refused for a proposal the polling pass has already claimed, in both
|
|
472
|
+
directions.
|
|
473
|
+
|
|
474
|
+
Resolving from the page **edits the Block Kit card in place**, so a lead closed
|
|
475
|
+
by a link does not keep live buttons in Slack. That needs the message `ts`,
|
|
476
|
+
which only the API transport returns, so a card posted through a webhook gets a
|
|
477
|
+
separate outcome message instead. Clicking a stale card was always safe -- the
|
|
478
|
+
claim refuses it -- but a reader scrolling the channel had no way to tell the
|
|
479
|
+
lead was decided, which is the kind of thing that erodes trust in the channel
|
|
480
|
+
rather than breaking anything.
|
|
481
|
+
|
|
482
|
+
Two reporting consequences of a second process resolving proposals:
|
|
483
|
+
|
|
484
|
+
- `agent approvals` prints `elsewhere=N`, the proposals a button or a link
|
|
485
|
+
resolved inside the `hours` window. Without it a pass reports
|
|
486
|
+
`approvals=0 executed=0 ... stuck=0` -- a quiet agent -- while the listener
|
|
487
|
+
works through leads in a different log.
|
|
488
|
+
- A claim made by the page records `claimed_via: "link"`, and the stuck check
|
|
489
|
+
treats a live pid as proving nothing for those. The pid it records is the
|
|
490
|
+
*listener's*, which outlives any one request by design, so the test that
|
|
491
|
+
catches a polling pass dying mid-steps could never fire for a link claim: a
|
|
492
|
+
tap whose steps ran and then failed to be written sat invisible for the whole
|
|
493
|
+
`hours` window. Link claims are judged on age alone, with a 15-minute bound,
|
|
494
|
+
and a request that raises after claiming closes the proposal as failed on its
|
|
495
|
+
way out rather than leaving it `running`.
|
|
496
|
+
|
|
497
|
+
#### The URL is the credential
|
|
498
|
+
|
|
499
|
+
This is the part to decide deliberately. The reply path trusts a Slack user id
|
|
500
|
+
and so does the button path; a link has no identity behind it. Whoever holds
|
|
501
|
+
the URL can act, and in a group chat that means every member, anyone who joins
|
|
502
|
+
later and scrolls back, and any device backup. Choose it for a group whose
|
|
503
|
+
members would all have been in `trusted_user_ids` anyway.
|
|
504
|
+
|
|
505
|
+
What bounds it:
|
|
506
|
+
|
|
507
|
+
- The link carries its own 32-byte `secrets.token_urlsafe` token, compared with
|
|
508
|
+
`secrets.compare_digest` -- **not** the proposal id, which is short by design
|
|
509
|
+
(a counter plus three random base-36 characters: ample against someone typing
|
|
510
|
+
`do p10` into a channel, nowhere near enough for something reachable over
|
|
511
|
+
HTTP).
|
|
512
|
+
- A token resolves exactly one proposal, never the store, and is useless
|
|
513
|
+
against any other lead.
|
|
514
|
+
- Single use falls out of the claim: the first verdict moves the proposal off
|
|
515
|
+
`pending`, and every later request is told what it already is. There is no
|
|
516
|
+
separate "token spent" state to get out of step.
|
|
517
|
+
- A miss returns one identical page whether the token is wrong or the workspace
|
|
518
|
+
is not served, so the page is not an oracle for guessing tokens.
|
|
519
|
+
- The token must not leak outward. The page sends `Referrer-Policy:
|
|
520
|
+
no-referrer` and marks links `rel="noreferrer noopener"`, because the blurb is
|
|
521
|
+
about somebody else's web page and a plain anchor would hand the token to that
|
|
522
|
+
site in the `Referer` header. The default request logging is turned off, since
|
|
523
|
+
the request line contains the token. It is still in the reader's browser
|
|
524
|
+
history and in the logs of whatever the request passes through, so `base_url`
|
|
525
|
+
should point at something private -- a tailnet address, or a tunnel you
|
|
526
|
+
control, not a public host.
|
|
527
|
+
- **No link is written onto a Slack card that already has buttons.** The buttons
|
|
528
|
+
do the same job there and better, and putting the token in the message would
|
|
529
|
+
store it in Slack, in push notifications and in email digests, and re-post it
|
|
530
|
+
verbatim when a button resolves the proposal. A card with no buttons
|
|
531
|
+
(`buttons: false`) does carry the link. Not because a Slack reader needs it --
|
|
532
|
+
the same line already says `Reply "do pX" or "skip pX"`, which is the reply
|
|
533
|
+
path and needs no token -- but because that message is also how the lead
|
|
534
|
+
reaches somebody who is *not* in Slack, which is the whole reason the page
|
|
535
|
+
exists. It is a real cost knowingly taken: the token is then in Slack's
|
|
536
|
+
message history, its push notifications, its email digests and its search
|
|
537
|
+
index, and it stays valid until the proposal is resolved. Set `buttons: true`
|
|
538
|
+
for a channel where everyone can click, and no token is written.
|
|
539
|
+
- Nothing records a `decided_by` for a link verdict. The other two paths store
|
|
540
|
+
the Slack user id that acted; a link has no identity behind it, and a value
|
|
541
|
+
there would read as an actor in the store. `decided_via: "link"` is the whole
|
|
542
|
+
truth, and for a group of several people that is all the audit trail there
|
|
543
|
+
is -- which is part of what is being chosen.
|
|
544
|
+
|
|
545
|
+
#### A GET must never act
|
|
546
|
+
|
|
547
|
+
This is the correctness condition for the whole design, not a preference.
|
|
548
|
+
Signal, Slack and iMessage all build link previews by fetching the URL **from
|
|
549
|
+
the recipient's device**. A link whose GET resolves the proposal would be
|
|
550
|
+
resolved by the message rendering on somebody's phone, before a human has read
|
|
551
|
+
it -- the same mechanism that made "unsubscribe" links unusable for a decade,
|
|
552
|
+
courtesy of corporate mail scanners.
|
|
553
|
+
|
|
554
|
+
So `GET` and `HEAD` render and change nothing; only `POST` resolves. The POST
|
|
555
|
+
carries a form token the GET minted, which also stops a third-party page
|
|
556
|
+
driving a verdict on a reader's behalf. A restart of the listener between the
|
|
557
|
+
GET and the POST invalidates that token and the page says to reload: the cost of
|
|
558
|
+
keeping no server-side session.
|
|
559
|
+
|
|
560
|
+
The blurb is a scraped post, which is to say attacker-controlled text. It is
|
|
561
|
+
HTML-escaped and rendered as preformatted text, the only anchor is the lead's
|
|
562
|
+
own URL after an `http`/`https` scheme check, and no Markdown becomes markup --
|
|
563
|
+
a stored cross-site scripting bug on a page that resolves proposals would hand
|
|
564
|
+
over both the token and the verdict.
|
|
565
|
+
|
|
566
|
+
#### This is not an internet-facing server
|
|
567
|
+
|
|
568
|
+
`bind` defaults to loopback and a non-loopback bind prints a warning at
|
|
569
|
+
startup, because the page has no authentication beyond the link token and no
|
|
570
|
+
rate limiting worth the name. Put it behind a tailnet or a tunnel you control.
|
|
571
|
+
|
|
572
|
+
Two properties are worth knowing rather than discovering. Responses are
|
|
573
|
+
HTTP/1.0, so every one closes its connection: with keep-alive, any handler that
|
|
574
|
+
answers *without* reading the request body becomes a request-smuggling
|
|
575
|
+
primitive, because the unread bytes are parsed as the next request on that
|
|
576
|
+
connection -- an adversarial review got a POST to a nonexistent token to
|
|
577
|
+
execute a verdict framed in its body, and the same trick through a connection-
|
|
578
|
+
pooling proxy returns the next victim's page, which contains their link token.
|
|
579
|
+
One connection per response removes the whole class, including the paths
|
|
580
|
+
`BaseHTTPRequestHandler` answers by itself where there is nothing to drain
|
|
581
|
+
from. `Transfer-Encoding` is refused outright for the same reason.
|
|
582
|
+
|
|
583
|
+
And concurrency is capped at 64 connections. Enough held connections therefore
|
|
584
|
+
make the page unavailable rather than exhausting the machine's threads -- which
|
|
585
|
+
would take the Socket Mode listener in the same process down with it. A
|
|
586
|
+
per-client cap would be the usual answer and is the wrong one here: behind a
|
|
587
|
+
proxy every connection arrives from the proxy.
|
|
588
|
+
|
|
589
|
+
The 15-second handler timeout is **not** a request deadline, and this was
|
|
590
|
+
measured rather than assumed: it is a per-socket-operation timeout, so a client
|
|
591
|
+
that sends one byte every ten seconds resets it on every byte and holds its
|
|
592
|
+
slot for as long as it likes. An idle connection is reclaimed after 15s; a
|
|
593
|
+
trickling one is not. Sixty-four of those hold every slot and the person who
|
|
594
|
+
needs to approve something gets a refused connection until they stop. The cap
|
|
595
|
+
still does its real job -- the listener in the same process survives -- but the
|
|
596
|
+
page does not recover on its own while a slow client is deliberate about it.
|
|
597
|
+
This is accepted rather than solved, for the same reason as the per-client cap:
|
|
598
|
+
the fix is a request deadline the standard library does not offer here, and the
|
|
599
|
+
page is reachable only from loopback or a private tunnel.
|
|
600
|
+
|
|
601
|
+
An unauthenticated request is also not free. Every request reads the whole
|
|
602
|
+
store once under the store's lock, before any credential check -- a bogus token
|
|
603
|
+
costs the same read as a real one -- and that is the same lock the Slack button
|
|
604
|
+
path and the `agent approvals` pass take. Flooding the page therefore slows
|
|
605
|
+
those down: measured on a 547 KB store, 64 concurrent bogus-token requests took
|
|
606
|
+
a `transition()` from 10ms to 494ms at the 95th percentile. One read per
|
|
607
|
+
request rather than two is what the code does now; the rest is the same
|
|
608
|
+
accepted exposure as above.
|
|
609
|
+
|
|
610
|
+
### Drafting several things at once: `digest` fields
|
|
611
|
+
|
|
612
|
+
An action whose steps publish a post *and* announce it needs more than one
|
|
613
|
+
piece of text, and a digest that writes one blob of prose has only `{body_md}`
|
|
614
|
+
to give them. `fields` (issue #63) asks the model for a JSON object instead,
|
|
615
|
+
and every key becomes a template name for the steps:
|
|
616
|
+
|
|
617
|
+
```json
|
|
618
|
+
"wrap": {
|
|
619
|
+
"type": "digest",
|
|
620
|
+
"webhook_env": "SOME_WEBHOOK",
|
|
621
|
+
"prompt": "...",
|
|
622
|
+
"min_score": 60,
|
|
623
|
+
"fields": {
|
|
624
|
+
"title": "A post title, under 70 characters.",
|
|
625
|
+
"body_md": "The post itself, Markdown.",
|
|
626
|
+
"blurb_twitter": "Under 240 characters, plain text, no hashtags."
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
A step can then say `{"type": "twitter-post", "text": "{blurb_twitter}"}`. The
|
|
632
|
+
values are descriptions for the model, not defaults, and `body_md` has to be
|
|
633
|
+
one of them. `empty`, `footer`, `items` and `model` are refused as field names:
|
|
634
|
+
`render()` sets those itself, and a field named `empty` would make a written
|
|
635
|
+
digest look like a quiet run and be dropped. Without a `fields` key the digest
|
|
636
|
+
behaves exactly as before: one prose summary in `body_md`.
|
|
637
|
+
|
|
638
|
+
The proposal message shows the model's `title` and `body_md`, then lists the
|
|
639
|
+
other fields under `also drafted:` with their text, so what is approved is what
|
|
640
|
+
goes out. If the model does not come back with a JSON object carrying every
|
|
641
|
+
field (or any of them is empty), the run asks once more and then fails without
|
|
642
|
+
recording a proposal — nothing is marked seen, so the next run drafts again
|
|
643
|
+
rather than publishing half an announcement.
|
|
644
|
+
|
|
645
|
+
Alongside the drafted fields, `render()` returns values the digest computed from
|
|
646
|
+
the signals rather than from the reply (issue #75), as `meta_values` and as
|
|
647
|
+
plain template names. The first is `repos`: the distinct `meta["repo"]` of the
|
|
648
|
+
items the model was shown, comma-separated, so a release-notes post can be
|
|
649
|
+
tagged with the repos that actually released. Use those for anything that must
|
|
650
|
+
not move when the model phrases its answer differently — a taxonomy, a routing
|
|
651
|
+
key — and a drafted field for prose. `meta_values` and `repos` are refused as
|
|
652
|
+
field names, so a config cannot end up asking the model for a value it already
|
|
653
|
+
has.
|
|
654
|
+
|
|
655
|
+
`min_score` (default 0, no gate) drops signals scoring below it before the
|
|
656
|
+
model sees them, and they are not in the item count either. They are still
|
|
657
|
+
marked seen. With a gate set, the item list the model reads also carries each
|
|
658
|
+
item's score and the scorer's reasons; without one it does not, so a digest
|
|
659
|
+
configured before this existed reads exactly the prompt it always did.
|
|
660
|
+
|
|
661
|
+
### Events from a digest's items: `calendar_card`
|
|
662
|
+
|
|
663
|
+
A digest can say that a post announced ten events; it cannot hand them over.
|
|
664
|
+
`calendar_card` makes the `digest` destination post a second message after a
|
|
665
|
+
non-empty digest, with one row per event the run's items announce: the title
|
|
666
|
+
linked to its join URL, the start in `timezone`, and an "Add to calendar"
|
|
667
|
+
button that opens Google Calendar with the event prefilled. Nothing is created
|
|
668
|
+
until the reader saves it, and a link button needs no listener, so it works
|
|
669
|
+
through an incoming webhook.
|
|
670
|
+
|
|
671
|
+
```json
|
|
672
|
+
"calendar_card": {
|
|
673
|
+
"timezone": "America/Los_Angeles",
|
|
674
|
+
"duration_minutes": 60,
|
|
675
|
+
"guests": ["<you>@<domain>", "<you>@<other-domain>"],
|
|
676
|
+
"title": "Events"
|
|
677
|
+
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
`timezone` (IANA, required) is the zone the card shows times in. `guests` are
|
|
681
|
+
added to every event (Google's `add` parameter), which is how one person puts an
|
|
682
|
+
event on several of their own calendars; Google asks whether to send the
|
|
683
|
+
invitations on save. The addresses travel inside the link, so everyone in the
|
|
684
|
+
channel can read them. Posts rarely give an end time, so each event lasts
|
|
685
|
+
`duration_minutes` (default 60), and the card says so.
|
|
686
|
+
|
|
687
|
+
The model only extracts each event's title, date, start and zone as the post
|
|
688
|
+
writes them; the code computes the instant and builds the link, maps US zone
|
|
689
|
+
abbreviations (`EST` is a fixed-offset zoneinfo key, so passing it through would
|
|
690
|
+
put summer events an hour off), and drops events dated implausibly far from the
|
|
691
|
+
run, which is what a wrong guessed year looks like. A card that fails is
|
|
692
|
+
reported in the channel and on stderr, but does not fail the run: the digest is
|
|
693
|
+
already posted.
|
|
694
|
+
|
|
695
|
+
A long announcement may need `max_item_chars` (default 800), the share of each
|
|
696
|
+
item's text the digest model is shown; the card's extraction reads up to 4000
|
|
697
|
+
characters per item regardless.
|
|
698
|
+
|
|
699
|
+
Steps are **action** plugins, the fourth kind (`docs/PLUGIN-CONTRACT.md`).
|
|
700
|
+
Later steps see earlier results by `{name}` templating over the proposal's
|
|
701
|
+
payload merged with each step's returned dict. Shipped:
|
|
702
|
+
|
|
703
|
+
- `command` (`framework/plugins/command_action.py`) — runs an existing tool:
|
|
704
|
+
`{"type": "command", "argv": ["/abs/path/tool", "--text", "{blurb} {url}"],
|
|
705
|
+
"result_format": "json"}`. `argv[0]` must be a literal path (a `{` or `}`
|
|
706
|
+
in it is a config error: the program never comes from proposal data); every
|
|
707
|
+
later element is templated. No shell, so quotes and `$(...)` in post text
|
|
708
|
+
reach the tool as one literal argument. Optional `cwd`, `timeout` (default
|
|
709
|
+
120). At most one of `result_pattern` (regex with named groups, searched in
|
|
710
|
+
stdout; groups become results) or `result_format: "json"` (last non-empty
|
|
711
|
+
stdout line is a JSON object; keys become results); neither means no results. A nonzero exit fails the step
|
|
712
|
+
with the exit code and the last 20 stderr lines, which the outcome message
|
|
713
|
+
posts to the channel; exit 0 with stdout that does not parse as configured
|
|
714
|
+
fails too. Output goes to temporary files, not memory: at most the last
|
|
715
|
+
64 KiB of stderr and the first 1 MiB of stdout are read, and more stdout
|
|
716
|
+
than that with a result mode set fails as too large. Messages name only
|
|
717
|
+
`argv[0]`. See issue #48.
|
|
718
|
+
- `slack-post` (`webhook_env`, `text`).
|
|
719
|
+
- `twitter-post` (`framework/plugins/twitter_action.py`) — tweets `text` (a
|
|
720
|
+
template) through the X API v2 with OAuth 1.0a user context; credentials
|
|
721
|
+
from `TWITTER_API_KEY`, `TWITTER_API_SECRET`, `TWITTER_ACCESS_TOKEN`,
|
|
722
|
+
`TWITTER_ACCESS_SECRET` (names overridable via `api_key_env`,
|
|
723
|
+
`api_secret_env`, `access_token_env`, `access_secret_env`), read when the
|
|
724
|
+
step runs. Over 280 characters is an error before any request. Needs
|
|
725
|
+
`pip install '.[twitter]'`. Returns `tweet_url`. A 2xx never fails the step
|
|
726
|
+
(a body without the id returns `tweet_url: ""` and a stderr notice); a
|
|
727
|
+
failed step may still have posted, so check the account before re-running
|
|
728
|
+
by hand. See issue #48.
|
|
729
|
+
- `wordpress-publish` (`framework/plugins/wordpress_action.py`) — turns
|
|
730
|
+
`payload["title"]` + `payload["body_md"]` (Markdown) into a WordPress.com post
|
|
731
|
+
and returns `{"url", "post_id"}` for later steps. Config:
|
|
732
|
+
`{"type": "wordpress-publish", "site": "<site>.wordpress.com", "mode": "draft",
|
|
733
|
+
"token_env": "WORDPRESS_ACCESS_TOKEN", "categories": ["releases"],
|
|
734
|
+
"tags": ["release-notes", "{repos}"]}`.
|
|
735
|
+
`mode` is `draft` (safety valve; `url` is the preview) or `publish` (`url` is
|
|
736
|
+
the public permalink). The token comes from `token_env`, else the macOS
|
|
737
|
+
Keychain item `wpcom_token` the `wordpress-com-publish` skill writes; missing
|
|
738
|
+
or rejected tokens fail loud naming that skill as the fix. See issue #47.
|
|
739
|
+
`categories` and `tags` entries are templates (issue #75): an entry that
|
|
740
|
+
expands to a comma-separated string becomes separate names, blanks are
|
|
741
|
+
dropped, and duplicates collapse case-insensitively keeping the first
|
|
742
|
+
spelling, so standing tags and per-run `{repos}` can overlap freely.
|
|
743
|
+
|
|
744
|
+
## Operating notes
|
|
745
|
+
|
|
746
|
+
### Reading a run log
|
|
747
|
+
|
|
748
|
+
Every line `agent run` writes is prefixed with the local time and its UTC
|
|
749
|
+
offset:
|
|
750
|
+
|
|
751
|
+
```
|
|
752
|
+
2026-11-18T12:25:04-08:00 agent=leads status=ok fetched=153 new=38 sent=38 unscored=0 seen=12497
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
The prefix is applied to stdout and stderr for the duration of the run, so the
|
|
756
|
+
summary line, the per-signal lines and whatever a source plugin printed all
|
|
757
|
+
carry it, and so does a traceback. Nothing else about the lines changed, so the
|
|
758
|
+
two idioms worth knowing still work:
|
|
759
|
+
|
|
760
|
+
```bash
|
|
761
|
+
# the score distribution of a run. The leading space is load-bearing: without
|
|
762
|
+
# it the `unscored id=` lines match too and inflate the count.
|
|
763
|
+
grep ' scored id=' logs/run.error.log | sed 's/.*score=\([0-9]*\).*/\1/' | sort -n
|
|
764
|
+
|
|
765
|
+
# every run's outcome, oldest first
|
|
766
|
+
grep ' status=' logs/run.log
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
Why it is worth having: seven consecutive failed runs used to produce seven
|
|
770
|
+
byte-identical lines, so the log could not distinguish a day-long outage from a
|
|
771
|
+
few bad runs, and dating one meant reading `state/seen.json`'s mtime and the
|
|
772
|
+
launchd plist instead. Deriving the times from the plist's
|
|
773
|
+
`StartCalendarInterval` is worse than it looks — it yields the times a run
|
|
774
|
+
*should* have had, which is not when it ran.
|
|
775
|
+
|
|
776
|
+
### One signal per comment, not per page
|
|
777
|
+
|
|
778
|
+
The websearch source normally emits one signal per result page. With
|
|
779
|
+
`self_identification` it emits one per passage *inside* the page that contains
|
|
780
|
+
one of those phrases:
|
|
781
|
+
|
|
782
|
+
```json
|
|
783
|
+
"source": {
|
|
784
|
+
"type": "websearch",
|
|
785
|
+
"backend": "firecrawl",
|
|
786
|
+
"queries": ["\"I own a\" invoices paperwork"],
|
|
787
|
+
"fetch_page": true,
|
|
788
|
+
"self_identification": ["I own a", "I run a", "we are a small"],
|
|
789
|
+
"passage_chars": 600
|
|
790
|
+
}
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
This is the comment-level funnel (issue #138). The post-level one was measured
|
|
794
|
+
dead: two search backends each put zero posts at the scoring gate, and a
|
|
795
|
+
1,417-post corpus yielded 2 with real buyer pain, 1,184 of them written by
|
|
796
|
+
vendors. What survived that measurement is the owner who identifies themselves
|
|
797
|
+
in a *comment* under someone else's post, where the post itself is vendor copy.
|
|
798
|
+
|
|
799
|
+
So the passage is the lead and the page is only context. `Signal.text` is the
|
|
800
|
+
passage; the page's title and URL ride in `meta` as `parent_title` and
|
|
801
|
+
`parent_url`. Scoring the whole page would score the vendor's post instead of
|
|
802
|
+
the owner's comment.
|
|
803
|
+
|
|
804
|
+
The passage is a character window around the match, weighted after it by about
|
|
805
|
+
seven to one, not a DOM query — this source refuses to depend on a page's markup
|
|
806
|
+
holding still, and a comment container has no stable shape across sites. The
|
|
807
|
+
window is weighted that way because "I own a ..." introduces the problem rather
|
|
808
|
+
than concluding it; centred, it reached back into the vendor copy above the
|
|
809
|
+
comment. A window can still straddle two comments, and a person reads the lead
|
|
810
|
+
either way.
|
|
811
|
+
|
|
812
|
+
Two matches collapse into one passage only when they read as one person's
|
|
813
|
+
sentence: nothing ends a sentence between them, and they are within
|
|
814
|
+
`same_comment_chars` (200 by default). "I own a bakery and I run a second shop"
|
|
815
|
+
is one lead; a reply ninety characters later, after a full stop, is somebody
|
|
816
|
+
else's. Distance alone is too blunt a test, so passages may overlap — two
|
|
817
|
+
owners talking in one thread are two leads, and the phrase that anchored each
|
|
818
|
+
travels with it.
|
|
819
|
+
|
|
820
|
+
The id is `<page>#p=<hash of the passage>`, because flat text carries no comment
|
|
821
|
+
permalink. An edited comment is therefore a new signal, which is the right way
|
|
822
|
+
round: re-reading one is cheap and missing one is a lost lead.
|
|
823
|
+
|
|
824
|
+
Every run of this mode prints how many pages were read and how many passages
|
|
825
|
+
were found, and names every page it could not read. A sweep where every page
|
|
826
|
+
refused raises instead of reporting zero: "nothing matched" and "nothing could
|
|
827
|
+
be read" are opposite facts that an empty signal count hides, and that
|
|
828
|
+
confusion is the whole failure mode of the scraper this replaced.
|
|
829
|
+
|
|
830
|
+
### Slack renders mrkdwn, not Markdown
|
|
831
|
+
|
|
832
|
+
Everything this repo posts to a Slack webhook goes through one function,
|
|
833
|
+
`framework/slack.py::post_message`, which converts Markdown to Slack's own
|
|
834
|
+
mrkdwn on the way out (issue #73): headings become bold lines, `[text](url)`
|
|
835
|
+
becomes `<url|text>`, `**bold**` becomes `*bold*`, list markers become bullets,
|
|
836
|
+
and code spans and fenced blocks are left exactly as written. Emphasis fires
|
|
837
|
+
only on word boundaries, so `https://example.com/a__b__c` keeps its underscores:
|
|
838
|
+
a URL that lost a pair is a different URL. `__x__` is not treated as bold at all,
|
|
839
|
+
on purpose: what this repo posts is release notes and scorer reasons about code,
|
|
840
|
+
where `__init__` is an ordinary word and `**bold**` is how anyone here writes
|
|
841
|
+
bold. `&`, `<` and `>` become entities in
|
|
842
|
+
literal text, per Slack's own rule, and never inside a link this repo built, a
|
|
843
|
+
blockquote marker or a code block. Text that holds none of those characters and
|
|
844
|
+
no Markdown is posted unchanged. Code in this repo that builds a header writes
|
|
845
|
+
Markdown (`**Title**`) for the same reason: there is one place that renders.
|
|
846
|
+
|
|
847
|
+
A message longer than a Slack block (3000 characters) is posted as **several
|
|
848
|
+
messages in order**, split at a paragraph boundary where there is one, never
|
|
849
|
+
truncated; a split inside a fenced block closes and reopens the fence, and a
|
|
850
|
+
cut inside a line falls between grapheme clusters so an emoji is never halved.
|
|
851
|
+
Parts are numbered (`_(part 2 of 3)_`), because another agent sharing the
|
|
852
|
+
webhook can post between them. Only the
|
|
853
|
+
Slack rendering changes: `body_md` in a recorded proposal, which is what a
|
|
854
|
+
WordPress publish step later sends, stays Markdown.
|
|
855
|
+
|
|
856
|
+
### A feed instead of a sweep: Google Alerts as a source
|
|
857
|
+
|
|
858
|
+
Every other source here pulls, and pays for it — the reddit source in rate
|
|
859
|
+
limits, the websearch source in credits per query. The `rss` source (issue #149)
|
|
860
|
+
is the other shape: something else watches continuously and publishes what it
|
|
861
|
+
found.
|
|
862
|
+
|
|
863
|
+
```json
|
|
864
|
+
"source": {
|
|
865
|
+
"type": "rss",
|
|
866
|
+
"feeds": ["https://www.google.com/alerts/feeds/<alert-id>/<feed-id>"],
|
|
867
|
+
"limit_per_feed": 25
|
|
868
|
+
}
|
|
869
|
+
```
|
|
870
|
+
|
|
871
|
+
A run costs one conditional GET per feed, there is no quota and no terms
|
|
872
|
+
question, and an alert catches things that happened between runs instead of
|
|
873
|
+
sampling at them. Nothing in the plugin is Alerts-specific beyond two
|
|
874
|
+
documented behaviours, and an ordinary blog or forum feed works the same way.
|
|
875
|
+
|
|
876
|
+
**Treat an Alerts feed URL as a credential.** Anyone holding it reads that
|
|
877
|
+
alert. It belongs in the workspace config, which is private, and never in this
|
|
878
|
+
repo — and never in a log either, which is why nothing this source prints names
|
|
879
|
+
a feed by its URL. Feeds are named by their configured `label`, or by position
|
|
880
|
+
when there is none, in stderr, in `meta.feed` and in config errors alike. A
|
|
881
|
+
request failure is reported by its exception type rather than its message,
|
|
882
|
+
because `requests` puts the URL in the message.
|
|
883
|
+
|
|
884
|
+
```json
|
|
885
|
+
"feeds": [
|
|
886
|
+
{"url": "https://www.google.com/alerts/feeds/<alert-id>/<feed-id>", "label": "invoices"},
|
|
887
|
+
"https://forum.example/feed.xml"
|
|
888
|
+
]
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
**Dedupe is namespaced per feed.** An RSS `guid` is unique only inside its own
|
|
892
|
+
feed — `<guid>123</guid>` is legal in two unrelated publishers — while the
|
|
893
|
+
runner's seen store is shared across the agent, so an ordinary feed's signal id
|
|
894
|
+
is its guid behind a stable key derived from the feed URL. Google Alerts entries
|
|
895
|
+
are the deliberate exception and stay unprefixed, so that two *different* alerts
|
|
896
|
+
matching one page collapse to a single lead. Changing a feed's URL re-delivers
|
|
897
|
+
its current entries once; renaming its label does not.
|
|
898
|
+
|
|
899
|
+
Two things about Alerts feeds that are easy to get wrong, both handled:
|
|
900
|
+
|
|
901
|
+
- **Its links are redirectors.** Every entry links to
|
|
902
|
+
`google.com/url?...&url=<the real page>`, so the page the lead lives on is a
|
|
903
|
+
query parameter. Unwrapped, or a reader gets a Google redirect and two alerts
|
|
904
|
+
on one page look like two different pages.
|
|
905
|
+
- **Its guids are per-hit, not per-page.** The entry id is a serial unique to
|
|
906
|
+
that alert's delivery, so two alerts matching one page carry two guids and
|
|
907
|
+
keying dedupe on the guid delivers the page twice. For those entries the
|
|
908
|
+
unwrapped URL is the id instead; every other feed keeps its guid, which is
|
|
909
|
+
what a guid is for.
|
|
910
|
+
|
|
911
|
+
As everywhere else, per-feed counts go to stderr, every failed feed is named,
|
|
912
|
+
and a run where every feed failed raises rather than reporting zero entries.
|
|
913
|
+
|
|
914
|
+
### Two ways to reach Slack, and why the second one matters
|
|
915
|
+
|
|
916
|
+
A Slack destination (`slack`, `digest`) and the `slack-post` action name either
|
|
917
|
+
an incoming webhook or a bot token, exactly one (issue #86):
|
|
918
|
+
|
|
919
|
+
```json
|
|
920
|
+
{"type": "digest", "webhook_env": "SOME_WEBHOOK", "prompt": "..."}
|
|
921
|
+
{"type": "digest", "bot_token_env": "SOME_BOT_TOKEN", "channel_id": "C0123456789",
|
|
922
|
+
"prompt": "...", "username": "release notes", "icon_emoji": ":package:"}
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
Conversion, splitting, footers, part markers and blocks are identical on both.
|
|
926
|
+
Naming both, or neither, fails at build time. Two things differ:
|
|
927
|
+
|
|
928
|
+
- **`username` / `icon_emoji` / `icon_url` (issue #77) only work with a bot
|
|
929
|
+
token.** A modern incoming webhook ignores them: the post returns `ok` and
|
|
930
|
+
the message still arrives under the app's own name, so several agents sharing
|
|
931
|
+
one webhook are indistinguishable however they are configured. Through
|
|
932
|
+
`chat.postMessage` they are honoured, given the bot's `chat:write.customize`
|
|
933
|
+
scope. The keys ride on the payload either way, since a webhook ignoring them
|
|
934
|
+
is not an error.
|
|
935
|
+
- **Only a bot token gets a message `ts` back.** A webhook answers `ok` and
|
|
936
|
+
nothing else, so a message posted through one can never be edited afterwards
|
|
937
|
+
— which is why a proposal announced over a webhook keeps its buttons after it
|
|
938
|
+
has been resolved. With a token, `post_message` returns the `ts` of every
|
|
939
|
+
message it posted and `update_message` can edit it in place.
|
|
940
|
+
|
|
941
|
+
The bot needs `chat:write`, plus `chat:write.customize` for the name and icon,
|
|
942
|
+
and it has to be in the channel `channel_id` names. A route may carry its own
|
|
943
|
+
`channel_id` under one destination-level `bot_token_env`.
|
|
944
|
+
|
|
945
|
+
### Signal is a second interface, on an account of its own
|
|
946
|
+
|
|
947
|
+
A `signal-messenger` destination posts a scored signal to a Signal group
|
|
948
|
+
(issue #120), so an agent's output can land on a phone rather than in a
|
|
949
|
+
channel:
|
|
950
|
+
|
|
951
|
+
```json
|
|
952
|
+
"destination": {
|
|
953
|
+
"type": "signal-messenger",
|
|
954
|
+
"account_env": "AGENTS_SIGNAL_ACCOUNT",
|
|
955
|
+
"group_id_env": "AGENTS_SIGNAL_GROUP_LEADS",
|
|
956
|
+
"min_score": 10
|
|
957
|
+
}
|
|
958
|
+
```
|
|
959
|
+
|
|
960
|
+
**The type is `signal-messenger`, not `signal`.** The `approval` destination
|
|
961
|
+
already has a `mode: "signal"`, meaning one proposal per `Signal` — the
|
|
962
|
+
dataclass every source emits — and in a config that holds both, a destination
|
|
963
|
+
called `signal` reads as that one.
|
|
964
|
+
|
|
965
|
+
**It needs a Signal account this deployment owns.** One process owns a Signal
|
|
966
|
+
account at a time: `signal-cli`'s daemon holds it, and nothing else can open it
|
|
967
|
+
concurrently — the same shape as one Socket Mode consumer per Slack app. So
|
|
968
|
+
these agents register their own number rather than borrowing a conversational
|
|
969
|
+
agent's account and depending on its relay. Register it once with
|
|
970
|
+
`signal-cli register --captcha <token>` (the token comes from
|
|
971
|
+
`signalcaptchas.org/registration/generate.html`, is valid for minutes, and must
|
|
972
|
+
be used from the same external IP as the browser that solved it), then
|
|
973
|
+
`signal-cli verify <code>`. The number and the group id are named by env var,
|
|
974
|
+
never written in config: a `config.example.json` in this repo is public.
|
|
975
|
+
|
|
976
|
+
The dependency is the `signal-cli` binary (`brew install signal-cli`), not a
|
|
977
|
+
Python package, so there is no optional extra to install — a missing binary
|
|
978
|
+
fails when the destination is built, naming it. That is all the build checks:
|
|
979
|
+
an unregistered account or a group id this account is not in costs a subprocess
|
|
980
|
+
and the account lock to verify, so it is left to fail on the first send rather
|
|
981
|
+
than on every run that sends nothing.
|
|
982
|
+
|
|
983
|
+
#### Two transports, because only one process can hold the account
|
|
984
|
+
|
|
985
|
+
`transport` picks how the message leaves. The default, `signal-cli`, is the
|
|
986
|
+
subprocess above. `gateway` sends through a gateway service that owns the
|
|
987
|
+
account and serves every agent behind one daemon:
|
|
988
|
+
|
|
989
|
+
```json
|
|
990
|
+
"destination": {
|
|
991
|
+
"type": "signal-messenger",
|
|
992
|
+
"transport": "gateway",
|
|
993
|
+
"gateway": {
|
|
994
|
+
"url": "http://127.0.0.1:<port>",
|
|
995
|
+
"conversation": "<alias>",
|
|
996
|
+
"token_file": "<workspace>/gateway-token",
|
|
997
|
+
"label": "<the label the gateway prefixes, or omitted>",
|
|
998
|
+
"repeats": false,
|
|
999
|
+
"wait_s": 10
|
|
1000
|
+
},
|
|
1001
|
+
"min_score": 10
|
|
1002
|
+
}
|
|
1003
|
+
```
|
|
1004
|
+
|
|
1005
|
+
They are exclusive and the switch is a flip, not a fallback. Once the
|
|
1006
|
+
gateway's daemon holds the account the subprocess path cannot open it, so a
|
|
1007
|
+
transport that fell back to `signal-cli` would be a second process contending
|
|
1008
|
+
for an account another already has — it would hang and then drop the message,
|
|
1009
|
+
which is worse than refusing.
|
|
1010
|
+
|
|
1011
|
+
**The group id is not in this block.** `conversation` is an alias the gateway
|
|
1012
|
+
maps to the real conversation, so a private group's id stays in the gateway's
|
|
1013
|
+
own config and never reaches a consumer, a consumer's logs or a failure it
|
|
1014
|
+
raises. That is the whole reason for the alias.
|
|
1015
|
+
|
|
1016
|
+
**The token is a file, not an env var.** Two reasons, and the second is the
|
|
1017
|
+
one that decided it: a scheduled run reads the environment launchd gives it
|
|
1018
|
+
rather than a login shell's, and a variable in the environment is inherited by
|
|
1019
|
+
every child the run spawns — and these runs spawn LLM CLIs. The file must be
|
|
1020
|
+
mode 0600; the build refuses a group- or world-readable one, names the mode it
|
|
1021
|
+
found, and says to have the token reissued, because a credential other
|
|
1022
|
+
accounts could read is a credential to treat as disclosed.
|
|
1023
|
+
|
|
1024
|
+
**`wait_s` is what keeps "a clean exit means delivered" true.** The gateway
|
|
1025
|
+
answers `202 queued` the moment it accepts a message, and a queued message can
|
|
1026
|
+
still fail — as an event a run-and-exit agent has already exited before seeing.
|
|
1027
|
+
So the send asks the gateway to hold the response until Signal takes it:
|
|
1028
|
+
`200` means the message left, `502` means refused for good, and `202` means it
|
|
1029
|
+
was still in flight at the deadline, which includes a retry of a message still
|
|
1030
|
+
in flight. Only `200` returns; both others raise, so a caller that marks a
|
|
1031
|
+
signal delivered when the send returns can never mark one that did not arrive.
|
|
1032
|
+
A 5xx other than that 502 is pending rather than refused: the gateway's own
|
|
1033
|
+
refusal is a 502 carrying `send_failed`, and anything else in that range is a
|
|
1034
|
+
crash or a proxy giving up inside the window the gateway spends holding the
|
|
1035
|
+
reply, where the message may already be enqueued.
|
|
1036
|
+
|
|
1037
|
+
**A 409 `message_gone` is retried once under a fresh key.** It means the
|
|
1038
|
+
gateway still holds the idempotency key but has lost the message it names --
|
|
1039
|
+
its data was reset, or a retention it did not have yet removed the row. The
|
|
1040
|
+
key is derived, so every run would compute it again and meet the same 409
|
|
1041
|
+
until it expires: a message that is not delivered and, from this side, cannot
|
|
1042
|
+
be. So the key is moved once, deliberately, and the send retried. The cost is
|
|
1043
|
+
a duplicate if the original did reach the group before the reset, and a
|
|
1044
|
+
duplicate someone can see is better than a silent gap for the rest of the TTL.
|
|
1045
|
+
Once only -- a second `message_gone` under a fresh key is a gateway problem,
|
|
1046
|
+
not a key problem -- and the stderr line says a duplicate is possible. No other
|
|
1047
|
+
409, `key_reused` included, is retried.
|
|
1048
|
+
|
|
1049
|
+
A `200` whose status is `queued` means the gateway did not honour the wait at
|
|
1050
|
+
all -- an older build. That is a hard failure here rather than a pending one,
|
|
1051
|
+
because the gateway writes its idempotency entry when it accepts a message and
|
|
1052
|
+
only the wait loop ever reports a later status: the entry keeps saying
|
|
1053
|
+
`queued`, so every resubmit of that key replays the same answer until it
|
|
1054
|
+
expires and then sends a second copy. Retrying cannot resolve what a gateway
|
|
1055
|
+
build has to.
|
|
1056
|
+
|
|
1057
|
+
A `200` carries no Signal timestamp. Its status is `sent`, `delivered`, `read`
|
|
1058
|
+
or `deleted` -- a retry arriving after Signal has acked sees `delivered` or
|
|
1059
|
+
`read`, and `deleted` is a message that went out and was then deleted -- and
|
|
1060
|
+
all four mean it left. The gateway's published enum has three more, each read
|
|
1061
|
+
by name rather than as something unrecognised: `failed` did not go out even
|
|
1062
|
+
under a 200, and `queued` or `received` mean it has not left, which is the
|
|
1063
|
+
frozen-entry case above. Anything outside the enum raises, naming what this
|
|
1064
|
+
version does know.
|
|
1065
|
+
The handle is the gateway's own `message_id`, which its edit, delete and
|
|
1066
|
+
reaction endpoints take; the gateway keeps the Signal timestamp itself. So
|
|
1067
|
+
`post_message` returns a `message_id` under this transport and a Signal
|
|
1068
|
+
timestamp under the other, and the two are not interchangeable. The pending case raises its own type,
|
|
1069
|
+
`SignalSendPending`, a sibling of the refusal rather than a kind of it,
|
|
1070
|
+
because `except SignalGatewayError` is what a caller writes to mean "refused,
|
|
1071
|
+
give up" and pending must not be caught by it. A read timeout after the request
|
|
1072
|
+
was sent is pending for the same reason -- the gateway may well have queued the
|
|
1073
|
+
message, so calling it a refusal would tell the caller not to retry something
|
|
1074
|
+
in flight. The HTTP timeout therefore has to outlast `wait_s` by a margin,
|
|
1075
|
+
checked when the config is read: a gateway answering a moment after its own
|
|
1076
|
+
deadline is answering 202, and losing that to a socket timeout produces exactly
|
|
1077
|
+
the confusion the distinction exists to avoid. The wait's cap is the gateway's,
|
|
1078
|
+
30 seconds; a larger number in config is refused here rather than silently
|
|
1079
|
+
clamped there.
|
|
1080
|
+
|
|
1081
|
+
The next run resubmits under the same idempotency key, which waits on the
|
|
1082
|
+
message already in flight rather than sending a second copy. **That key is
|
|
1083
|
+
derived from the signal's id, not from the rendered text**, because the text is
|
|
1084
|
+
not stable across runs here: a retry re-scores, `llm_scorer` appends the rung
|
|
1085
|
+
the vendor waterfall landed on to its reasons, and the destination renders
|
|
1086
|
+
those reasons into the message. A different rung would mean a different key,
|
|
1087
|
+
and the part that already reached the group would be posted again -- the one
|
|
1088
|
+
outcome the key exists to prevent. Each part goes under
|
|
1089
|
+
`<signal id>@<footer digest>#<number>-of-<total>`, and a digest of the
|
|
1090
|
+
workspace goes into the key alongside it -- the workspace rather than the
|
|
1091
|
+
whole block, because the block holds tuning an operator changes while chasing
|
|
1092
|
+
a failure, and `wait_s` is the first thing they would raise after a 202.
|
|
1093
|
+
Hashing that in would mean the fix for a pending part changed the keys of the
|
|
1094
|
+
parts that already arrived and posted them again. Both are there because the
|
|
1095
|
+
gateway namespaces its idempotency store by consumer, not by destination: two
|
|
1096
|
+
destinations sharing one token and one conversation are one consumer to it, so
|
|
1097
|
+
the same signal would otherwise key identically from both, and the second
|
|
1098
|
+
one's message would come back as a replay of the first -- reported as
|
|
1099
|
+
delivered, never sent. The footer alone would not settle it, since an empty or
|
|
1100
|
+
shared footer is precisely the colliding case. Two destinations configured
|
|
1101
|
+
identically, in one conversation, sending one signal, still collide, and are
|
|
1102
|
+
the same message -- the one case where a replay is right. Beyond that, give
|
|
1103
|
+
each agent its own gateway consumer and token, which is what that namespacing
|
|
1104
|
+
is for. The total is in there deliberately too: a
|
|
1105
|
+
key naming only the part number would match across runs that split
|
|
1106
|
+
differently, and the worse direction of that is silent. A retry whose text
|
|
1107
|
+
shortened into one part would carry the old part 1's key, the gateway would
|
|
1108
|
+
replay that part, this side would read a 200 and mark the signal delivered,
|
|
1109
|
+
and everything that had been in part 2 would never be sent at all. Including
|
|
1110
|
+
the total makes a different split a different message, which is what it is.
|
|
1111
|
+
What remains is the lesser case: a retry that splits the same way but reads
|
|
1112
|
+
differently keeps the first run's wording for the parts that already arrived
|
|
1113
|
+
and takes the new wording for the rest. Nothing is lost -- the same signal is
|
|
1114
|
+
described either way. A caller with
|
|
1115
|
+
no stable id to offer falls back to hashing the text and its styles.
|
|
1116
|
+
|
|
1117
|
+
Two bounds on the promise. It lasts as long as the gateway's
|
|
1118
|
+
`idempotency_ttl_s`, 24 hours by default, so an agent whose runs are further
|
|
1119
|
+
apart than the TTL gets a fresh key and the resubmit does post a second copy.
|
|
1120
|
+
And a caller that deliberately sends the same signal twice inside the TTL gets
|
|
1121
|
+
the earlier message's outcome replayed -- `duplicate: true`, reported as
|
|
1122
|
+
delivered, with nothing new sent; editing the message does not change that,
|
|
1123
|
+
since the key does not depend on the text. That is right for a retry and wrong for a
|
|
1124
|
+
repeat, and the two cannot be told apart from here, so the flag is written to
|
|
1125
|
+
stderr rather than swallowed. A source that re-lists the same items every run
|
|
1126
|
+
is the shape to watch.
|
|
1127
|
+
|
|
1128
|
+
**A source that re-lists the same items every run needs `repeats: true`.**
|
|
1129
|
+
That is the one case the key cannot infer. A source with `dedupe: false` means
|
|
1130
|
+
to send the same signal again, and the gateway cannot tell that from a retry:
|
|
1131
|
+
both arrive under the same key inside its 24-hour window, and it answers the
|
|
1132
|
+
second by replaying the first -- reported as delivered, never sent, with only
|
|
1133
|
+
a line on stderr. `repeats: true` mixes a per-run value into the key, so each
|
|
1134
|
+
run is its own message. The trade is the cross-run retry guarantee: a
|
|
1135
|
+
repeating destination reports `idempotent = False`, and a partial send then
|
|
1136
|
+
says plainly that resubmitting repeats the parts that did arrive. Today no
|
|
1137
|
+
Signal destination is fed by a non-deduping source, so this is a trap rather
|
|
1138
|
+
than a live fault -- `meetups` is the only workspace with `dedupe: false` and
|
|
1139
|
+
it posts to Slack.
|
|
1140
|
+
|
|
1141
|
+
One caveat on the exception types: `fanout` flattens a child destination's
|
|
1142
|
+
exception into a `RuntimeError`, so a `signal-messenger` behind it loses the
|
|
1143
|
+
pending-versus-refused distinction. No message is lost -- the run fails and the
|
|
1144
|
+
runner marks nothing -- but a caller cannot branch on it there.
|
|
1145
|
+
|
|
1146
|
+
**`label` mirrors the gateway's own setting and has to match it.** The prefix
|
|
1147
|
+
is applied by the gateway from its `consumers.<name>.label`, and it re-checks
|
|
1148
|
+
the length *after* prefixing, so those bytes come out of the same 2000. No
|
|
1149
|
+
endpoint reports that value back, which makes this the one field here that
|
|
1150
|
+
duplicates state we do not own: a label set there and omitted here means every
|
|
1151
|
+
full-size part is refused with `422 too_long`, because the arithmetic looks
|
|
1152
|
+
correct from this side. So a 422 naming `too_long` says that explicitly rather
|
|
1153
|
+
than relaying the gateway's message — a mismatched label is the only thing that
|
|
1154
|
+
explains it. A label longer here than there is merely wasteful. `limit` belongs
|
|
1155
|
+
to the transport for this reason, and the footer is checked against the
|
|
1156
|
+
transport's limit rather than Signal's.
|
|
1157
|
+
|
|
1158
|
+
**Signal takes plain text plus styled ranges, not markup.** Everything this
|
|
1159
|
+
repo sends goes through `framework/signal_messenger.py::post_message`, which is
|
|
1160
|
+
to Signal what `framework/slack.py` is to Slack: code that builds a message
|
|
1161
|
+
writes Markdown, and one place renders it. `to_signal()` returns the text with
|
|
1162
|
+
every marker removed and the `(start, length, STYLE)` ranges that reproduce
|
|
1163
|
+
them, which go out as `--text-style`. Signal accepts BOLD, ITALIC,
|
|
1164
|
+
STRIKETHROUGH, MONOSPACE and SPOILER, and rejects anything else with
|
|
1165
|
+
`Invalid style:`. Headings become bold lines and list markers become bullets,
|
|
1166
|
+
as on Slack. There is no link style — Signal linkifies bare URLs itself — so
|
|
1167
|
+
`[label](url)` renders as `label (url)` and the URL stays visible.
|
|
1168
|
+
|
|
1169
|
+
**Offsets are UTF-16 code units, the limit is UTF-8 bytes.** signal-cli's own
|
|
1170
|
+
help says the first in capitals, and it matters: an emoji is two units, so a
|
|
1171
|
+
message with one ahead of a bold word would otherwise style the wrong letters.
|
|
1172
|
+
The limit is the other unit — `ServiceConfig.MAX_MESSAGE_SIZE_BYTES` is 2000
|
|
1173
|
+
and `ManagerImpl` tests it as `Utf8.size(messageText())` — so `_units()` counts
|
|
1174
|
+
offsets, `_bytes()` counts capacity, and no function mixes them: in `_cut()`
|
|
1175
|
+
the fit test is bytes while the offset it carries forward is units. Counting
|
|
1176
|
+
capacity in units under-counts every non-ASCII character, and the bullet this
|
|
1177
|
+
renderer writes is one unit and three bytes. That mistake is quiet rather than
|
|
1178
|
+
loud: past 2000 bytes signal-cli does not refuse the message, it truncates the
|
|
1179
|
+
text and attaches the remainder as a file, so the send succeeds and the reader
|
|
1180
|
+
gets a cut message with the styled tail inside an attachment.
|
|
1181
|
+
|
|
1182
|
+
A message over Signal's 2000-byte limit is split into several in order,
|
|
1183
|
+
numbered `(part 2 of 3)`, exactly as the Slack path splits on a block limit —
|
|
1184
|
+
and for the same reason, since another message can arrive between the parts.
|
|
1185
|
+
A style range cannot be reopened across messages, so the message is rendered
|
|
1186
|
+
once and the text and its ranges are split together: a bold span that straddles
|
|
1187
|
+
a boundary becomes a bold range at the end of one part and another at the start
|
|
1188
|
+
of the next. A footer is appended after the rendering and never converted,
|
|
1189
|
+
which is the contract the Slack path states — a standing compliance line means
|
|
1190
|
+
the characters it was written with. A footer long enough to leave no room for
|
|
1191
|
+
content is refused where the config is read, before the run has paid for a
|
|
1192
|
+
fetch or an LLM call.
|
|
1193
|
+
|
|
1194
|
+
Two things this destination deliberately does not do. It has no `routes`: the
|
|
1195
|
+
hot/firehose split is a Slack channel pattern, and a Signal group is somebody's
|
|
1196
|
+
phone. And it does not take a digest — `digest` picks its transport at
|
|
1197
|
+
construction, in Slack's shape, so sending one to Signal is a separate piece of
|
|
1198
|
+
work.
|
|
1199
|
+
|
|
1200
|
+
### Reddit over OAuth, and why the RSS feeds stopped working
|
|
1201
|
+
|
|
1202
|
+
The reddit source has two transports, chosen by `auth` in its config block. With
|
|
1203
|
+
`auth` absent or `"none"` it reads the public RSS feeds and needs no credential,
|
|
1204
|
+
which is what v1 shipped with. With `auth: "oauth"` it reads the authenticated
|
|
1205
|
+
JSON API:
|
|
1206
|
+
|
|
1207
|
+
```json
|
|
1208
|
+
"source": {
|
|
1209
|
+
"type": "reddit",
|
|
1210
|
+
"auth": "oauth",
|
|
1211
|
+
"client_id_env": "REDDIT_CLIENT_ID",
|
|
1212
|
+
"client_secret_env": "REDDIT_CLIENT_SECRET",
|
|
1213
|
+
"subreddits": ["smallbusiness", "sweatystartup"],
|
|
1214
|
+
"include_rules": true
|
|
1215
|
+
}
|
|
1216
|
+
```
|
|
1217
|
+
|
|
1218
|
+
Why it exists: from 2026-11-17 every `/new.rss` request from one particular
|
|
1219
|
+
address returned 404 or 429, and the leads agent failed 77 consecutive runs
|
|
1220
|
+
without fetching anything. The two codes shuffled between subreddits that were
|
|
1221
|
+
demonstrably live, so **a Reddit status code describes the caller, not the
|
|
1222
|
+
subreddit** — never re-derive a subreddit list from them. The same change fixes
|
|
1223
|
+
the subreddit-rules fetch, which has 403ed unauthenticated since about 2026-10
|
|
1224
|
+
and had been quietly making every draft treat self-promotion as forbidden.
|
|
1225
|
+
|
|
1226
|
+
The credential is a Reddit app of type **script**. `client_credentials` is the
|
|
1227
|
+
grant for a confidential client and yields app-only access with no user context,
|
|
1228
|
+
which is all a public listing needs — so there is no account password and no
|
|
1229
|
+
refresh token to store. Self-service app creation closed on 2025-11-11; new
|
|
1230
|
+
access goes through Reddit's Data Access Request form.
|
|
1231
|
+
|
|
1232
|
+
Two deliberate refusals, both so that a misconfiguration cannot look like a
|
|
1233
|
+
quiet day on Reddit:
|
|
1234
|
+
|
|
1235
|
+
- **No fallback to RSS.** Missing credentials under `auth: "oauth"` raise at
|
|
1236
|
+
build time rather than reverting to the public feeds, which would turn a
|
|
1237
|
+
credential problem into the very outage this transport escapes.
|
|
1238
|
+
- **`searches` is refused**, not ignored, under `auth: "oauth"`.
|
|
1239
|
+
|
|
1240
|
+
The signal id is identical across both transports: Reddit's fullname
|
|
1241
|
+
(`t3_1abcde`), which its Atom feed already carried in `<id>`. That is
|
|
1242
|
+
load-bearing. Keying the JSON path on anything else — the permalink, say — would
|
|
1243
|
+
make every post ever seen look new, and the first authenticated run would
|
|
1244
|
+
re-send the entire backlog to every destination at once.
|
|
1245
|
+
|
|
1246
|
+
### Secrets live in the environment, never in config
|
|
1247
|
+
|
|
1248
|
+
Each destination names the env var holding its credential (`webhook_env`,
|
|
1249
|
+
`bot_token_env`, `api_key_env`). Real per-agent `config.json` files live in workspaces outside
|
|
1250
|
+
the checkout; only `config.example.json` is committed. The framework itself only
|
|
1251
|
+
ever reads `os.environ` when it builds a destination — how those variables get
|
|
1252
|
+
there is the deployment's business, not this repo's.
|
|
1253
|
+
|
|
1254
|
+
In our own launchd deployment the agents are invoked through `bash -lc`, so the
|
|
1255
|
+
login profile supplies the values and no credential is stored in a plist. If you
|
|
1256
|
+
schedule them another way, whatever wraps them has to load the environment
|
|
1257
|
+
itself; nothing in this repo does it for you.
|
|
1258
|
+
|
|
1259
|
+
### Migrating an existing agent into a workspace
|
|
1260
|
+
|
|
1261
|
+
An agent that was running out of a checkout (`--config <dir>/config.yaml`, state
|
|
1262
|
+
in `<dir>/.seen-<agent>.json`) does not carry its dedupe state over on its own:
|
|
1263
|
+
the workspace default is `<workspace>/state/seen.json`, and an empty one means
|
|
1264
|
+
every signal the source still returns is new again. There is deliberately no
|
|
1265
|
+
fallback read of the legacy path; the cutover is one operator step, done while
|
|
1266
|
+
the scheduler is stopped:
|
|
1267
|
+
|
|
1268
|
+
1. Unload the agent's scheduled job so nothing runs mid-move.
|
|
1269
|
+
2. Create the workspace and write `config.json` from the old YAML.
|
|
1270
|
+
3. Union the old `.seen-<agent>.json` with whatever `state/seen.json` already
|
|
1271
|
+
holds (both are flat JSON arrays of ids) and write the result to
|
|
1272
|
+
`state/seen.json`. If the workspace was hand-run before the cutover, the two
|
|
1273
|
+
files have diverged and neither alone is complete.
|
|
1274
|
+
4. Re-point the scheduled job at `agent run --workspace <workspace>` and load it
|
|
1275
|
+
(`agent install-schedule --workspace <workspace> --label <existing-label> --force`).
|
|
1276
|
+
`--force` is needed once: a hand-written plist has no install-schedule
|
|
1277
|
+
marker, so without it the install refuses and prints what the job runs.
|
|
1278
|
+
Check that output names the job you meant to replace before re-running with
|
|
1279
|
+
`--force`.
|
|
1280
|
+
5. Hand-run once and check the summary line: `new=` should be small (what
|
|
1281
|
+
arrived during the move), not the size of the feed.
|
|
1282
|
+
|
|
1283
|
+
### Slack incoming webhooks do not survive the app being reinstalled
|
|
1284
|
+
|
|
1285
|
+
**This will bite you, and the symptom is misleading.** Removing and re-adding a
|
|
1286
|
+
Slack app permanently invalidates every incoming webhook URL it issued. The app
|
|
1287
|
+
looks healthy afterwards — its bot token still authenticates — but posting to an
|
|
1288
|
+
old URL returns:
|
|
1289
|
+
|
|
1290
|
+
```
|
|
1291
|
+
HTTP 404 no_service
|
|
1292
|
+
```
|
|
1293
|
+
|
|
1294
|
+
The URL in your environment is unchanged, so nothing looks wrong on our side.
|
|
1295
|
+
There is no way to restore the old URL; Slack mints new ones.
|
|
1296
|
+
|
|
1297
|
+
Recovery:
|
|
1298
|
+
|
|
1299
|
+
1. On the Slack app → **Incoming Webhooks** → **Add New Webhook to Workspace**,
|
|
1300
|
+
once per channel the agents post to.
|
|
1301
|
+
2. Update the corresponding env var in your profile.
|
|
1302
|
+
3. Nothing to rebuild or redeploy — but the *scheduler* has to see the new
|
|
1303
|
+
value. Agents read the env var on every run, so with a `bash -lc`-style
|
|
1304
|
+
wrapper that re-sources the profile each tick they recover on their own. If
|
|
1305
|
+
your wrapper captured the environment once at load time, reload it, or you
|
|
1306
|
+
will keep failing delivery while trusting this runbook.
|
|
1307
|
+
|
|
1308
|
+
While the webhook is dead an agent exits non-zero and delivers nothing. The
|
|
1309
|
+
runner marks dedupe state only after delivery succeeds, so an undelivered signal
|
|
1310
|
+
is **not** burned — it is eligible to go out on the next good run.
|
|
1311
|
+
|
|
1312
|
+
That is at-least-once, not durable queueing, and the difference matters during a
|
|
1313
|
+
long outage. There is no stored backlog: recovery depends on the *source* still
|
|
1314
|
+
returning the same signals on the next fetch. A bounded feed makes that
|
|
1315
|
+
time-limited — the reddit source reads the newest `limit_per_feed` entries of a
|
|
1316
|
+
rolling `/new` listing, so items that fall out of that window during a prolonged
|
|
1317
|
+
outage are gone regardless of dedupe state. Short outage, nothing lost; multi-day
|
|
1318
|
+
outage on a busy feed, assume gaps. Durable undelivered storage would be needed
|
|
1319
|
+
for a stronger guarantee, and does not exist today.
|
|
1320
|
+
|
|
1321
|
+
### Verifying a credential without exposing it
|
|
1322
|
+
|
|
1323
|
+
To check which of several similar-looking webhooks a config actually uses,
|
|
1324
|
+
compare hashes rather than values:
|
|
1325
|
+
|
|
1326
|
+
```bash
|
|
1327
|
+
printf '%s' "$SOME_WEBHOOK" | shasum -a 256 | cut -c1-12
|
|
1328
|
+
```
|
|
1329
|
+
|
|
1330
|
+
Equal prefixes mean the same credential. This is how you confirm a deployment is
|
|
1331
|
+
bound to the webhook you think it is, and which of several is safe to delete,
|
|
1332
|
+
without printing a secret into a terminal, a log, or an agent transcript.
|
|
1333
|
+
|
|
1334
|
+
## Releasing
|
|
1335
|
+
|
|
1336
|
+
Releases are tag-on-bump. There is no release workflow to run and no tag to
|
|
1337
|
+
push by hand: `.github/workflows/checks.yml` reads `version` from
|
|
1338
|
+
`pyproject.toml` on every push to master, and if no `v<version>` tag exists it
|
|
1339
|
+
publishes the wheel to PyPI, then creates the tag and the GitHub release.
|
|
1340
|
+
|
|
1341
|
+
The consequence worth knowing before you open a pull request: **a feature PR
|
|
1342
|
+
must leave the version alone.** Bumping it there means the merge publishes,
|
|
1343
|
+
which is almost never what a feature PR intends. A release is its own commit
|
|
1344
|
+
that moves nothing but the version.
|
|
1345
|
+
|
|
1346
|
+
Tag last, deliberately. The tag is the record that a release finished, so a
|
|
1347
|
+
failure partway through leaves no tag and a rerun retries the whole thing. The
|
|
1348
|
+
upload to PyPI is the one step that cannot be undone -- a version there can be
|
|
1349
|
+
yanked but never replaced -- so it is also the one step a rerun skips rather
|
|
1350
|
+
than repeats.
|
|
1351
|
+
|
|
1352
|
+
Notes come from `docs/release-notes/v<version>.md` when that file exists, and
|
|
1353
|
+
are generated from merged pull request titles when it does not. Write the file
|
|
1354
|
+
when a release deserves prose; a release should not block on writing it.
|
|
1355
|
+
|
|
1356
|
+
## Status
|
|
1357
|
+
|
|
1358
|
+
In use rather than finished: the agents above run on a schedule against live
|
|
1359
|
+
sources, while the plugin interfaces are still moving. See the GitHub issues
|
|
1360
|
+
for the tracked build-out plan.
|
|
1361
|
+
|
|
1362
|
+
## License
|
|
1363
|
+
|
|
1364
|
+
AGPL-3.0-or-later -- see [LICENSE](./LICENSE).
|