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

A site's pages read a group's spaces whole, with an SDK

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:site/spaces

A group's site can now read the group's spaces whole, in the visitor's browser, with a new @opensocial/sdk built on atproto's lex-space, so a page can list, count and thread what members wrote with no index in the host. This branch sits on site/reports and site/writes (at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/group-host/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.pull/3n2hmbla3oq6n); until they merge, its diff shows their commits too. It changes who may call the host's space-read routes from a browser (CORS): that part wants a careful look.

Claude Opus 5.5

What changes

The SDK (packages/sdk, @opensocial/sdk). For apps on group hosts, in lex-space's own shape: GroupClient.open(agent, group) (by DID or handle) with getGroup, members(), join, leave, report; GroupSpace, lex-space's SpaceClient for one of the group's spaces plus the records it read kept, and read on from each writer's head after (writers({cursor}), pullRepo), with an optional store to keep them between visits; listActorGroups, listActorInvites. Writes take lex-space's order (put(ns, value, {rkey})). A writer whose host fails keeps their last records and is retried next time; only a failure to list the writers fails a read. The host's methods are asked through the member's PDS (service the host's #opensocial).

A site's spaces. A site's record, and putSite, may name spaces: the space types its pages read whole as the visitor. Its sign-in asks space:<type>?authority=<group>&action=read for each. The host's page answers with the SDK, one GroupSpace per space, kept in IndexedDB at the address's origin. opensocial site publish --spaces and the site_publish tool take them.

The kit in the SDK's shape. A page asks a space as an app asks the SDK: os.space(uri) answers an object with sync(), records({collections}), onChange(fn), create(collection, value, {rkey}), put(collection, value, {rkey}) and delete(collection, {rkey}), which replace os.create, os.put and os.delete (space, collection, rkey, record). The kit moved from crates/group-host/src/site_kit.js to web/shell/kit.js, beside the host's page that answers it; web/shell/protocol.ts lists the messages between them once, and npm run check in web/ now type-checks the shell and the kit against it (it checked neither before).

CORS on the space-read routes. getRecord, listRecords, getRepo, getLatestCommit, listRepoOps, getBlob, listBlobs, authorizeSpaceSync and listWriters answer any origin, allowing the headers a space credential and a MAC travel in, so a browser can read a space as any app does. The notify methods stay closed to browsers. Each of these calls is authorized by a space credential bound to the caller's key, or a delegation token, never a cookie.

The console's site form keeps a site's spaces and acts under Advanced, and sends them when it publishes.

Docs. The sites design page (why a site reads spaces in the browser, and to what size that fits), the site kit, the API, command and MCP references, a new reference for the SDK, the overview and AGENTS.md's layout. CI, the Dockerfile and just fmt/lint install, check and format the SDK.

Why

The host was growing an index of every space, with counts, links and orders, to answer pages' questions (parked, not in this pull). Measured against a group host world, reading every member's repo directly, as lex-space does, is fine up to a few thousand records in a space (a first read of 0.5-0.8 s for ~2,000 records; views worked out in the browser in a couple of milliseconds), and reading on after is cheap at any size. So for groups of ordinary size, the host stays the group's PDS and authority and keeps no copy of its spaces: the access record decides what each visitor reads at every repo, and an app or a site reads the same way, with one SDK.

How it was checked

  • packages/sdk: 16 vitest tests (reading on with new, edited and deleted records; a removed writer; a gap falling back to a snapshot; an unavailable repo; one writer failing while the rest are kept; two syncs at once; collection filters; the store round trip; writes' order).
  • tests/sites.rs: a site with only spaces is live, asks a read scope per type, its config carries them; a repeated or empty type is refused. tests/spaces.rs: a page anywhere may read a space (CORS), and a syncer's read answers its origin.
  • e2e: the group host's flows (37) and the Hall's (commons-site, 9), whose rooms now read only through os.records.
  • The console form looked at with just look on desktop and phone, and critiqued.
  • just lex, just docs, just lint, the coverage run (no test failed; nothing this branch added uncovered).

Shortcomings

  • The first read on each device downloads every member's repo in the space: about 3-4 s and ~70 MB at ~19,000 records in the measurement. Past a few thousand records a group wants an index beside the host. Not yet measured over a real network with members on several PDSes.
  • Records are ordered by their writer's createdAt, which a writer chooses.
  • A page learns of new records when it reads again; nothing is pushed.
  • The SDK does not yet act as the group (getGroupAuth); fyi.opensocial.participate lacks getGroup, listMembers and getActorGroups, so an app asking only for it cannot make every SDK call.
  • lex-space hashes every record twice when it snapshots a repo, about half of a first read's time in the browser; a pull to lex-space.

Review

Start with the CORS change (crates/group-host/src/space_api.rs, cors, and lib.rs's space_routes): is opening these routes to any origin right? Then web/shell/shell.ts's records ask and its error mapping, and packages/sdk/src/group-space.ts's sync.

Approved

The pull adds @opensocial/sdk, space reads in a site's pages, and CORS on the space-read routes. I read AGENTS.md and the CORS change (space_api::cors and space_routes in lib.rs). I did not read the SDK, the shell, the console form or the docs. The diff is large because it includes the two pulls it sits on.

CORS. I found no problem with opening these routes to any origin.

  • A search of space_api.rs found no cookie handling. The routes take a space credential bound to the caller's key, a MAC, or a delegation token. A cross-origin page therefore gets nothing from the visitor's session, and * without credentials is right.
  • authorizeSpaceSync takes notify. A page could register a notify endpoint through it, but any server client can already do that. The endpoint must be https and the token is capped at 512 bytes.
  • The notify methods stay on the closed routes, as the body says.
  • cors sets the headers on every response, including errors, and answers any OPTIONS request with 204 before routing. That is fine for these routes.

One thing to keep in mind: the allow-headers list must cover every header the SDK and lex-space send. If a browser read fails preflight, look there first. The e2e flows you list appear to cover it.

Approving.

Approved

The change since my approval at 34d1d75 is two commits. One moves the site publish flag parsing onto its own line. The other replaces os.records, os.onRecords and os.create/put/delete with os.space(uri), and moves the kit to web/shell/kit.js. I read web/shell/kit.js and web/shell/shell.ts in full. I did not re-read the docs, the SDK or the type definitions.

The CORS change I approved is untouched by these two commits.

The refactor holds up:

  • The shell still checks every ask against the site's declaration. sync needs a space of a declared type, and create, put and delete need a declared (space, collection). All of them need a session.
  • The kit's sync pairs correctly with the shell's records push. A push that arrives before the reply sets what the kit holds, and the first sync fires the listeners once if no push did.
  • drop() clears the shell's spaces, and signing out also deletes the member's kept records from IndexedDB.

One small thing, not a blocker. After a sign-out the kit's os.space(...).records() still returns what the page already held. The page reloads on the next sign-in, so this only matters to a page that keeps showing records after the visitor signs out.

Approved

My approval at 1b9f571 stands. Since then the pull only moves how CI builds the space alpha, so the e2e flows that write in a space run on it. I read the whole diff since that commit. It touches no product code, so the CORS change and the SDK I approved are unchanged.

  • harness/alpha.sh is the alpha build lifted out of test.yml. It is the same steps, with the same skip when ATPROTO_COMMIT and BUILD match what was built. It sets its own PATH, so the e2e workflow can call it.
  • e2e.yml now runs that script and caches /opt/atproto. It sets GROUP_HOST_DEV_ENV, and alpha.sh is added to the pull's paths.
  • harness/e2e/setup.mjs stops the world and throws if GROUP_HOST_DEV_ENV is set but the build speaks no spaces. That prevents the space-writing flows from being silently skipped in CI.
  • docs/development.md matches the change.
Approved

My approval at 542a8ea stands. The head, 44b0c64, has no differences from that commit, so only the pull's title or body changed. The code I approved is the same, including the CORS change, the SDK and the kit. Nothing in the new text contradicts what I reviewed.

Approved

My approval at 542a8ea stands. This head has the same code as my last review, which found no differences from that commit, so only the title or body changed. I did not re-read the diff this round. The CORS change, the SDK and the kit I approved are unchanged, and nothing in the current description contradicts them.

Approved

Carried forward: the change this pull makes at ed69081950a0471d9ef67045fc44a1297cb13b59 is the one reviewed at 59e482b82ba96ff5c103dc3434e4fd89ad70a35b, so that review stands. What is new comes from its base.

Merged as 4c278aa