~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Two example apps: reading a group, and joining one

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:examples/apps

Two small apps under examples/ show how to use a group host the way any app would, on atproto's own TypeScript packages (@atproto/oauth-client-node, @atproto/lex, @atproto/lex-space). read-a-group signs in as a group and reads it, as Grain does; join-a-group joins one for a person, from their own PDS.

Claude Opus 5.5

What changes

examples/read-a-group. One file, main.ts. It reads the group's profile from its meta space as anyone may, then signs in as the group with the loopback client and an admin's approval in the console. With that session it reads the meta and members spaces by delegation token and credential (lex-space's SpaceReader, which checks the MACs), and calls org.atgrp.listJoinRequests, typed by lex build from lexicons/. As Grain does, it keeps the session only from an approver who holds include:org.atgrp.authManageAdmin. It reads member from the token answer through a fetch wrapper, since the OAuth client drops the field; any other approver gets the session given back. It prints the rules, marks members with no confirmation, and hides a member the group took down with its own unexpired !takedown label.

examples/join-a-group. One file, main.ts. Signed in to the person's own PDS, it makes their inbox (a memberspace with publicWrite), or finds the one they have. It reads the group's invite there, then asks the host with org.atgrp.requestJoin through the PDS (atproto-proxy: <host DID>#atgrp, the host's DID from its describeServer). Once admitted, it writes an org.atgrp.confirmation in its own repo in the group's members space. It asks for three explicit scopes instead of include:org.atgrp.authParticipate, which a PDS grants only where it can read that set's lexicon; the README says so.

Checks and docs. just fmt, the format hook and the web check now cover examples/. The web check installs and typechecks each example (npm run check: lex build, then tsc), and just lint does the same for every app under examples/. The examples' generated lexicons/ and node_modules are ignored. README.md, AGENTS.md, docs/design/README.md (the pieces) and docs/development.md (the checks) name them.

Why

Grain proved the flow; these show it in the least code an app needs, with the packages an atproto app would use, for someone building against a group host. Writing them found a host bug, the null cursor on a list's last page, which landed on its own as A list's last page names no cursor, never null. They also found one upstream: l.space() can't type a space of several collections, which bluesky-social/atproto#6085 fixes. Until it ships, both examples declare the two group space types with l.space(...) and leave them out of lex build.

How it was checked

Each ran end to end against a local world: the space alpha's reference PDS and PLC (harness/pds.mjs), this host, and a group seeded by atgrp group seed, with members, a pending request, a takedown label and a confirmation.

  • read-a-group approved by alice, an admin: the profile signed out and signed in, both rules, members with roles and confirmed or not, the taken-down member hidden, and the pending request.
  • read-a-group approved by bob, a member but not an admin: refused, session given back, exit 1.
  • A signed-out read of a space only members read fails with XrpcResponseError SpaceNotFound, which is the error read-a-group catches. This was checked against the members space; no group's meta was made members-only.
  • join-a-group, signing in at the PDS's own page with Playwright: carol, not invited, gets her inbox made and her request left waiting. Carol, once invited, has the invite read from her inbox, is admitted and confirms. Bob, invited before he had an inbox, is admitted from the host's own list and confirms. read-a-group afterwards shows both as confirmed members.
  • Both examples pass npm run check; oxfmt --check and node harness/docs.mjs pass.

Shortcomings

  • Neither example was run on just dev; their READMEs' instructions for it follow from harness/dev.mjs.
  • The examples pin the spaces alpha packages (0.0.0-spaces-alpha-20261124235736), as the console does.
  • read-a-group reads the spaces with SpaceReader, not SpaceClient: SpaceClient reads the signed-in account's own repo with its session, which this host doesn't take for a group's repo in a space.
Asked for changes

This adds two example apps, read-a-group and join-a-group. It also adds checks for them in the web workflow and just lint, extends just fmt and the format hook to examples/, and updates the docs.

Must change: the head conflicts with main in README.md. Every check on this pull (web, check, test, lexicons, e2e, docs) failed with "conflicts with main … merge main into it" without running. So the new npm run check steps for both examples and the docs checks have not run on this head. Merge main into the branch, resolve README.md, and let the checks run.

I read both main.ts files and the workflow, Justfile, .gitignore, hook and package.json/tsconfig.json changes, and found no bugs. I did not read the READMEs, the two lockfiles, or the doc edits in AGENTS.md, docs/design/README.md and docs/development.md.

What I checked in the code:

  • read-a-group reads the members space before it decides whether the approver is an admin. That is fine, because the session is signed out and process.exit(1) runs before anything is printed from it.
  • join-a-group handles the SpaceAlreadyExists case for the inbox.
  • Both scope lists match what each app calls.
  • The web.yml paths and cache entries cover examples/.
Approved

My earlier review asked for one thing: merge main into the branch and resolve the README.md conflict. The head 0ca14155 is that merge, and the pull now shows as a fast-forward onto main, so this is done.

The checks for this head have started. lexicons and e2e passed as skipped, and web, test, docs and check were still queued or running when I looked. Those checks include the new npm run check typecheck of both examples. I didn't read their results, so wait for them to pass before merging. I found no problems in the example code in the first round, and the only commit added since is the merge of main.

Approved

My last review approved this at 0ca14155. The only change since is ebbd1b1d, which rewraps one api.text(...) call in harness/diagrams.mjs. It changes no behavior, and it answers the format failure that the web check reported at 0ca14155. The checks that matter for the pull have started on the new head. docs, check and lexicons passed, and e2e passed as skipped. web and test were still running when I looked. web includes the new npm run check typecheck of both examples, which was skipped at 0ca14155 because format failed first. Wait for it to pass before merging. I found no problems in the example code.

Merged as 4ece933