chadtmiller.com/group-host
atmosphere group host
0
0
Moderation takes typed subjects and events, and reports come to the group
crates/group-host/src/group.rs+2−2
| @@ -33,7 +33,7 @@ pub fn did_rkey(did: &str) -> String { | ||
} | ||
| ||
/// What the labeler every group starts with says: the labels the host | ||
/// acts on, and reports about records. | ||
/// acts on, and reports about accounts and records. | ||
fn labeler(at: &str) -> Value { | ||
let reasons = ["Spam", "Violation", "Misleading", "Sexual", "Rude", "Other"] | ||
.map(|r| format!("com.atproto.moderation.defs#reason{r}")); | ||
| @@ -41,7 +41,7 @@ fn labeler(at: &str) -> Value { | ||
"$type": format!("{NS}.labeler"), | ||
"policies": {"labelValues": ["!hide", "!takedown"]}, | ||
"reasonTypes": reasons, | ||
"subjectTypes": ["record"], | ||
"subjectTypes": ["account", "record"], | ||
"createdAt": at, | ||
}) | ||
} | ||
crates/group-host/src/lexicons.rs+1−1
| @@ -46,6 +46,7 @@ pub const FILES: &[&str] = &[ | ||
lexicon!("fyi/opensocial/createAppPassword"), | ||
lexicon!("fyi/opensocial/createGroup"), | ||
lexicon!("fyi/opensocial/createInvite"), | ||
lexicon!("fyi/opensocial/createReport"), | ||
lexicon!("fyi/opensocial/createSpace"), | ||
lexicon!("fyi/opensocial/deactivateGroup"), | ||
lexicon!("fyi/opensocial/declaration"), | ||
| @@ -120,7 +121,6 @@ pub const FILES: &[&str] = &[ | ||
lexicon!("upstream/com/atproto/label/defs"), | ||
lexicon!("upstream/com/atproto/managedspace/checkUserAccess"), | ||
lexicon!("upstream/com/atproto/managedspace/policy"), | ||
lexicon!("upstream/com/atproto/moderation/createReport"), | ||
lexicon!("upstream/com/atproto/moderation/defs"), | ||
lexicon!("upstream/com/atproto/repo/strongRef"), | ||
lexicon!("upstream/com/atproto/server/defs"), | ||
crates/group-host/src/lib.rs+1−1
| @@ -392,7 +392,7 @@ pub fn router(host: Arc<Host>) -> Router { | ||
post(moderation::resolve_subject), | ||
) | ||
.route( | ||
"/xrpc/com.atproto.moderation.createReport", | ||
"/xrpc/fyi.opensocial.createReport", | ||
post(moderation::create_report), | ||
) | ||
.route( | ||
crates/group-host/src/moderation.rs+257−149
406 lines changed: not loaded until asked for.
crates/group-host/src/store.rs+14−0
| @@ -399,6 +399,20 @@ pub const MIGRATIONS: &[&str] = &[ | ||
ALTER TABLE assistant_client ADD COLUMN connected INTEGER NOT NULL DEFAULT 0; | ||
UPDATE assistant_client SET connected = 1 | ||
WHERE id IN (SELECT client_id FROM assistant_grant); | ||
", | ||
// A moderation event says which version of a record it is about, the | ||
// rule a report cites and the label record written; resolving, | ||
// escalating and noting are each a status set, a note beside it. | ||
" | ||
ALTER TABLE mod_event ADD COLUMN cid TEXT; | ||
ALTER TABLE mod_event ADD COLUMN rule TEXT; | ||
ALTER TABLE mod_event ADD COLUMN uri TEXT; | ||
ALTER TABLE mod_event ADD COLUMN status TEXT; | ||
UPDATE mod_event SET kind = 'status', status = 'resolved' WHERE kind = 'resolve'; | ||
UPDATE mod_event SET kind = 'status', status = 'escalated' WHERE kind = 'escalate'; | ||
UPDATE mod_event SET kind = 'status', status = coalesce((SELECT p.status FROM mod_event p | ||
WHERE p.grp = mod_event.grp AND p.subject = mod_event.subject AND p.seq < mod_event.seq | ||
AND p.status IS NOT NULL ORDER BY p.seq DESC LIMIT 1), 'open') WHERE kind = 'note'; | ||
", | ||
]; | ||
| ||
crates/group-host/tests/groups.rs+1−1
| @@ -54,7 +54,7 @@ async fn starts_a_group_with_its_spaces() { | ||
); | ||
assert_eq!( | ||
record(&meta, "labeler", "self")["subjectTypes"], | ||
json!(["record"]) | ||
json!(["account", "record"]) | ||
); | ||
assert_eq!( | ||
record(&members, "access", "self")["grants"], | ||
crates/group-host/tests/members.rs+1−1
| @@ -427,7 +427,7 @@ async fn one_put_out_reads_no_more() { | ||
); | ||
assert_eq!(record(&h, &did, "membership", &bob.did), None); | ||
// The ejection stays in the group's queue, on him, with its reason. | ||
let events = h.host.store.events(&did, &bob.did).unwrap(); | ||
let events = h.host.store.events(&did, &bob.did, None, 0, 100).unwrap(); | ||
assert_eq!(events.len(), 1); | ||
assert_eq!(events[0].kind, "eject"); | ||
assert_eq!(events[0].actor.as_deref(), Some(dave.did.as_str())); | ||
crates/group-host/tests/moderation.rs+376−170
546 lines changed: not loaded until asked for.
crates/group-host-mcp/src/lib.rs+5−1
| @@ -129,7 +129,11 @@ impl Docs { | ||
copy( | ||
def, | ||
&mut s, | ||
&[("maxLength", "maxLength"), ("format", "format")], | ||
&[ | ||
("maxLength", "maxLength"), | ||
("format", "format"), | ||
("enum", "enum"), | ||
], | ||
); | ||
if let Some(known) = def["knownValues"].as_array() { | ||
let known: Vec<&str> = known.iter().filter_map(Value::as_str).collect(); | ||
crates/group-host-mcp/tests/protocol.rs+6−3
| @@ -48,10 +48,13 @@ fn makes_a_tool_of_each_method_without_its_group() { | ||
assert_eq!(role["type"], "object"); | ||
assert_eq!(role["properties"]["role"]["type"], "string"); | ||
| ||
// Known values said in words, beside what the lexicon says. | ||
// Known values said in words, beside what the lexicon says; a closed | ||
// set, as JSON Schema's own. | ||
let policy = &tool("updateProfile").input_schema["properties"]["joinPolicy"]; | ||
let said = policy["description"].as_str().unwrap(); | ||
assert!(said.contains("One of: "), "{said}"); | ||
let status = &tool("listSubjects").input_schema["properties"]["status"]; | ||
let said = status["description"].as_str().unwrap(); | ||
assert!(said.contains("One of: open"), "{said}"); | ||
assert_eq!(status["enum"], json!(["open", "escalated", "resolved"])); | ||
let limit = &tool("listSubjects").input_schema["properties"]["limit"]; | ||
assert_eq!(limit["type"], "integer"); | ||
assert!(limit.get("maximum").is_some()); | ||
docs/design/membership.md+3−2
| @@ -153,8 +153,9 @@ With no membership they hold no roles, so the access records grant them | ||
nothing. | ||
| ||
An ejection is then kept in the group's [moderation](moderation.md) | ||
queue, as an `eject` event on the member's DID: who put them out, and the | ||
`reason`, if `ejectMember` was given one. Leaving keeps nothing there. | ||
queue, as an `ejectEvent` on the member's DID, with who put them out. | ||
The host keeps the `reason` `ejectMember` was given beside it, but does | ||
not answer it. Leaving keeps nothing there. | ||
| ||
What they wrote stays in their own repos at their own PDSes. The group's | ||
index forgets it at once, and drops on each sync any writer a space no | ||
docs/design/moderation.md+66−29
| @@ -17,7 +17,7 @@ is (see [membership](membership.md)). Four of the host's actions are | ||
about moderation: | ||
| ||
- `mod.read`: see the queue and a subject's history. | ||
- `mod.resolve`: resolve, escalate or add a note to a subject. | ||
- `mod.resolve`: resolve or escalate a subject, with a note. | ||
- `label`: write a label. | ||
- `takedown`: write the labels that ask for content to be hidden or | ||
taken down. | ||
| @@ -92,48 +92,85 @@ already done about it. The queue answers that. It is the host's own, | ||
kept in its database rather than published in the group's repo, and only | ||
those with `mod.read` see it. | ||
| ||
A subject in the queue is a record, by its URI, or an account, by its | ||
DID. It has a status: `open`, `escalated` or `resolved`. Its events are | ||
kept in order, each with a kind (`report`, `label`, `negate`, `resolve`, | ||
`escalate`, `note`, `eject`), the actor, and what applies of a reason, | ||
value and note. A subject enters the queue with its first report, label | ||
or ejection, opened. An ejection is kept on the member's DID, with who | ||
put them out and the reason `ejectMember` was given. | ||
| ||
`listSubjects` lists the queue, latest changed first, filtered by status | ||
if asked. Every event moves a subject to the top. `getSubjectHistory` | ||
shows one subject with its events. `resolveSubject` acts on a subject | ||
already in the queue: `resolve` sets it `resolved`, `escalate` sets it | ||
`escalated`, and `note` keeps a note without changing the status. A | ||
note is 300 characters at most. | ||
A subject is an account, sent and answered as | ||
`fyi.opensocial.defs#accountSubject` with its `did`, or a record, as | ||
`fyi.opensocial.defs#recordSubject` with its `uri` and, optionally, the | ||
`cid` of one version. The queue keeps a record as a whole, by its URI; | ||
the version a report or label names stays on that event. A subject has a | ||
status: `open`, `escalated` or `resolved`. | ||
| ||
Its history is a list of events, each with an `id`, `createdAt`, who did | ||
it as `createdBy`, and one of four kinds as `event`: | ||
| ||
- `reportEvent`: someone reported it, with a `reasonType`, an optional | ||
`reason` and the `rule` it cites, if any. | ||
- `statusEvent`: a moderator set its `status`, with an optional `note`. | ||
- `labelEvent`: a label was written, by the label record's `uri` and its | ||
`val`. A negation is a label taken back, so it is answered with | ||
`deleted: true` and the negating record's `uri`. | ||
- `ejectEvent`: the member was put out of the group. It says nothing | ||
more; the host keeps the reason `ejectMember` was given, but does not | ||
answer it. | ||
| ||
A subject enters the queue with its first report, label or ejection, | ||
opened. | ||
| ||
`listSubjects` lists the subjects of one status, `open` unless asked, | ||
latest changed first. Every event moves a subject to the top. | ||
`getSubjectHistory` answers a subject's events, oldest first, a page at a | ||
time, and with a `cid` only those about that version. A subject nothing | ||
has happened to has no events. `resolveSubject` sets a subject already in | ||
the queue `resolved` or `escalated`, with an optional note of 2,000 | ||
characters at most. Setting the status a subject has keeps the note, so a | ||
note is added that way. It answers the subject as the queue now has it. | ||
Escalating is only a status, for a group to give its own meaning; no one | ||
is told. | ||
| ||
A resolved subject should come back when someone reports it again. A | ||
label is a moderator's own act, so it should not undo a resolution. So | ||
only a report reopens a resolved subject; a label or an ejection opens a | ||
subject nobody reported, and leaves a resolved one resolved. An escalated subject stays | ||
escalated through new reports. | ||
subject nobody reported, and leaves a resolved one resolved. An | ||
escalated subject stays escalated through new reports. | ||
| ||
Deleting a group deletes its queue. | ||
| ||
## Reports | ||
Details: | ||
| ||
Anyone signed in may report, member or not. A reporter needs no role and | ||
need not be able to read the space. A report arrives at | ||
`com.atproto.moderation.createReport`, by service auth or the console's | ||
session. | ||
- A subject that is neither a DID nor a record in one of the group's | ||
spaces is `InvalidSubject`. Resolving one never in the queue is | ||
`SubjectNotFound`. | ||
- A page is 50 events or subjects unless `limit` says, 100 at most; the | ||
`cursor` an answer gives asks for the next. | ||
| ||
## Reports | ||
| ||
A report here is of a record, by its URI. The record must be in a space | ||
hosted here. The report goes into the queue of the group that is that | ||
space's authority, as a `report` event with the reporter, a `reasonType` | ||
and an optional `reason`. Nobody is notified: the report waits in the | ||
queue for a moderator. | ||
A report comes from someone who can see what they report, so a group | ||
hears from the people its content reaches and not from strangers. A | ||
report arrives at `fyi.opensocial.createReport`, by service auth or the | ||
console's session. It names the `group`, the subject, a `reasonType`, | ||
and optionally a `reason` and the `rule` it cites. It needs no role. | ||
| ||
The subject is an account that is a member of the group, or a record in | ||
one of the group's spaces hosted here. The reporter must be able to read | ||
the space the subject is in: a record's own space, or for an account the | ||
members space, where its labels go. The report goes into the group's | ||
queue as a `reportEvent`, and is answered with its `id` and `createdAt`. | ||
Nobody is notified: the report waits in the queue for a moderator. | ||
| ||
The group's labeler, in its meta space, says what reports it takes. Each | ||
of its lists, when present, limits them: `reasonTypes` the reasons, | ||
`subjectTypes` the kinds of subject (`account`, `record`), and | ||
`subjectCollections` the collections a reported record may be in. A new | ||
group's labeler takes reports of accounts and records, for the common | ||
reasons, of any collection. | ||
| ||
Details: | ||
| ||
- A report of an account is refused; a URI outside a space hosted here | ||
is `NotHosted`. | ||
- A group not hosted here is `GroupNotFound`. A subject the reporter | ||
cannot read, that is not in the group, or of a kind or collection the | ||
labeler does not take, is `InvalidSubject`; a reason it does not take | ||
is `InvalidRequest`. | ||
- A `rule` must be a record's URI in the group's meta space. | ||
- The host does not check that the reported record exists or that its | ||
CID matches. | ||
- Limits and the answer's fields are in [the API | ||