Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 94 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,16 @@ Tags the poller adds itself:
| --- | --- |
| `routed:mention` | Discord: the message mentions the agent's bot. GitHub: the text contains `@<app slug>`. |
| `routed:reply` | Discord: the message replies to one of the bot's messages. |
| `routed:assigned` | GitHub: the agent is an assignee. |
| `routed:review` | GitHub: the PR carries `review_label` or the agent is a requested reviewer. |
| `routed:assigned` | GitHub: the agent is an assignee, or a trusted person put `assigned:<tag>` on the item (see Work handed over by label). |
| `routed:review` | GitHub: the PR carries `review_label` or the agent is a requested reviewer, or a trusted person put `review:<tag>` on the PR (see Work handed over by label). |
| `mine` | GitHub: a comment, review or event on an issue or PR the agent authored. |
| `claimed` | GitHub: activity on an item handed to the agent by label (see Work handed over by label). |
| `released` | GitHub: the closing note of such an item. Drop the claim. |
| `untrusted-label` | GitHub: the label was applied by someone GitHub does not report as having triage, write, maintain or admin access to that repository, or by any app or bot. Not followed. |

Tags starting `routed:` are addressed to the agent. `mine` is activity on its own work.
`claimed`, `released` and `untrusted-label` do not start with `routed:`, so they do not
call for attention by themselves: they inform. `released` tells the agent to drop a claim.
Untagged records are context. Rules can add more tags (see Configuration).

## Tools
Expand Down Expand Up @@ -163,9 +168,10 @@ tick, and unknown fields are rejected.
| Field | Default | Rule |
| --- | --- | --- |
| `broker` | required | Name of a service binding to a github-broker `Feed`. Same rule as above. |
| `repos` | required | `owner/name`. Not empty, no duplicates. |
| `repos` | required | `owner/name`. No duplicates. Not empty unless `labels` is set. |
| `every_secs` | `300` | Minimum `60`. |
| `review_label` | none | A label that means "review this". When set it must not be empty. |
| `review_label` | none | A label that means "review this". When set it must not be empty, and with `labels` it must not be `assigned:<tag>` or `review:<tag>` (in any case): those labels already route, with a trust check. |
| `labels` | none | `{ "org": "your-org", "tag": "claude" }`. Also finds work handed over by label across the whole organisation; see Work handed over by label. `tag` is 1-32 characters of `a-z`, `0-9`, `-`. |
| `skip_self` | `true` | As above. |
| `keep` | `"all"` | `"all"` or `"tagged"`. |
| `rules` | `[]` | See below. |
Expand Down Expand Up @@ -217,7 +223,7 @@ purges it.
{ "when": { "body_contains": ["deploy"] }, "then": { "tag": "deploy" } }
] },
{ "type": "github", "broker": "GITHUB", "every_secs": 300,
"repos": ["your-org/your-repo"], "review_label": "review:claude",
"repos": ["your-org/your-repo"], "review_label": "needs-review",
"skip_self": true, "keep": "tagged", "rules": [] }
]
},
Expand All @@ -232,14 +238,96 @@ purges it.
}
```

## Work handed over by label

A person hands work to an agent by labelling an item. With `labels` set on a GitHub source
(for example `"labels": { "org": "your-org", "tag": "claude" }`), mailroom searches the
whole organisation, not only `repos`, for two labels:

- `assigned:<tag>` on an open issue or pull request (`assigned:claude`);
- `review:<tag>` on an open pull request (`review:claude`).

`<tag>` belongs to one mailbox. The source gets one more poll target,
`github:<broker>:labels:<org>`, on the source's `every_secs`; `mailbox_info` lists it like
any other. Put `labels` on the same source that lists the organisation's repositories in
`repos`: only that source's repo polls learn which items are claimed, and so only they
tag the claimed activity.

Label names match in any case (`Assigned:Claude` is `assigned:claude`); the claim record
shows the name as GitHub has it.

**Who is trusted.** The label counts only when the person who applied it can write to the
repository: GitHub reports their `permission` as `admin` or `write`, or their role as
`admin`, `maintain`, `write` or `triage`. Anyone else, and anyone GitHub cannot find, is
untrusted. A GitHub App's bot is never a trusted labeler (GitHub reports no access for
it, and a login containing `[bot]` is untrusted without a lookup), so one agent cannot
hand work to another. There is no allowlist. A failed permission lookup fails the poll
and is retried; it never decides trust.

Trust is decided per label, by the item's events and never by the search alone. For each
label that the search shows, the newest `labeled` event decides, and it counts only if no
later `unlabeled` event removed it, even when the search still lists the item. An item is
trusted while at least one label that counts was applied by a trusted person. If a
trusted claim stops being trusted (its trusted label was removed while an untrusted one
stays, or it was removed and put back by an untrusted person), the agent gets a closing
note, `released: label removed`, and the claim is kept as untrusted: not followed, no
more activity.

**What the agent receives.**

- A *claim record* when a trusted person first puts the label on an item: kind `event`,
title `labeled <label>`, the item's title as body, the labeler as actor, and
`routed:assigned` (for `assigned:<tag>`) or `routed:review` (for `review:<tag>`). This is
the mail that calls for attention. If the labeler is untrusted the record carries only
`untrusted-label`, and the item is not followed.
- While the label stays, the item's activity (comments, review comments, reviews and
`assigned`, `labeled`, `review_requested`, `closed`, `merged`, `reopened` events), tagged
`claimed` after any other tags (`routed:mention`, `mine`). This includes repositories
that are not in `repos`. In a repository that is in `repos`, the poll that makes the
claim (or makes it trusted) mails what happened since the trusted label, once; from then
on the per-repo poll carries the activity and adds `claimed` the same way. Nothing
older than the trusted label is mailed; activity at or after it is, and the inbox drops
repeats.
- A *closing note* when the item closes, loses its label, or is gone: title
`released: closed`, `released: label removed` or `released: gone`, tag `released`. Drop
the claim. Putting the label back is a new assignment with a fresh claim record. While a
trusted label still stands, removing the other label mails nothing; when the trusted one
is removed and only an untrusted one remains, the closing note is written.
- Reopening: an item released by closing and then reopened with its label still on it is
handed over again. Its claim record is keyed to the label event and the reopen together
and carries the reopen's time; the closing note after it is keyed the same way.

Nothing whose actor is the mailbox's own bot is mailed when `skip_self` is true. Items
already labelled when `labels` is first turned on are mailed once, on the first poll.

**Limits.** At most 20 new or changed items are read per poll (the longest-waiting first;
the rest wait for the next poll), and at most 20 vanished claims are checked per poll.
Once a poll has made 60 requests after the search it starts no further item or lookup;
what was not reached waits for the next poll with its state untouched. Events, comments,
review comments and reviews are read in pages of 100, at most 10 pages. If an item's
events fill all ten pages the newest are missing, so nothing is decided for that item in
that poll and a `gap` record says so; a tenth full page of comments adds a `gap` record
too. An item that was moved to another repository is released as `gone`. The
search reads one page of 100; more matches produce a `gap` record. The broker's `Feed`
must allow `/search/issues` (brokers 0.5.0 or later); against an older broker only the
labels target fails.

Example (a mailbox watching one repository and the whole organisation):

```jsonc
{ "type": "github", "broker": "GITHUB", "repos": ["your-org/your-repo"],
"keep": "tagged", "labels": { "org": "your-org", "tag": "claude" } }
```

## What is polled, and what is missed

Polling is REST only: a cron trigger fires every minute, and each target (a channel or a
repo) is polled when it is next due, about `every_secs` after its last attempt. There is no gateway listener and no
webhook.

- **First contact emits nothing.** The first poll of a target records its current position
and produces no records. History is never replayed.
and produces no records. History is never replayed. The labels target is the exception:
items already labelled are mailed on its first poll.
- **Discord messages.** Each poll reads the latest 50 messages of the channel. If all 50
are new it pages back, up to 5 pages. If the last position is still not reached it
appends one `gap` record saying messages may have been skipped, then continues from the
Expand Down
2 changes: 1 addition & 1 deletion crates/logic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mailroom-logic"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
license = "MIT"

Expand Down
Loading
Loading