techne-sdk 0.12.0

TechneSDK's logic written once: version ranking (eventState) and offline record verification over the published check, shipped to TypeScript as WebAssembly; with opt-in atproto plumbing (service auth, DID resolution, signed labels, proven record fetches, PDS password sessions) behind the `crypto` and `net` features.
Documentation
# techne-sdk

TechneSDK for apps on the Techne platform: sign in, `put`, query, `useEvent` and the read-time check.

- **npm:** one package, `techne-sdk`, with subpaths.
- **Rust:** the crate `techne-sdk` (`crates/techne-sdk`). It holds the logic that must give the platform's answers exactly: the check, the version ranking (`eventState`) and `put`'s private-first, public-last plan. The npm package runs the same crate as WebAssembly, or as wasm2js on hosts without WebAssembly (Hermes). Opt-in features add the atproto plumbing services share (no platform crate either): `crypto` for service-auth JWTs, signed labels, record proofs and service-account passwords, and `net` for DID resolution, verified record fetches and PDS password sessions.

The SDK depends on two things only: the published lexicons (the `lexicons` repo at a tag) and the platform's published API. It contains no platform code.

## Install

```sh
npm i techne-sdk          # optional peers: react >= 19 for techne-sdk/react, and @tanstack/react-query 5 too for techne-sdk/react/query
```

Every import goes through the package's `exports`, so the resolver has to read them:

- TypeScript: `moduleResolution` `node16`, `nodenext` or `bundler`. Under the old `node` (node10) mode the subpath types do not resolve.
- React Native: Metro with package exports on (`unstable_enablePackageExports`, the default from Expo SDK 53). `techne-sdk/wasm` loads the check through `techne-sdk/wasm/load`, whose `react-native` condition picks the wasm2js build (Hermes has no WebAssembly); that file is ESM that calls Metro's `require`.

| Import | What it holds |
|---|---|
| `techne-sdk` (also `techne-sdk/generated`) | the generated XRPC client (`AtpBaseClient`) and every lexicon type |
| `techne-sdk/lexicons` | the generated lexicon dictionary (`schemaDict`, `schemas`, `lexicons`, `ids`): every lexicon document the client was built from, for reading descriptions at run time (large; keep it server side) |
| `techne-sdk/types/<nsid path>` | one lexicon's types, e.g. `techne-sdk/types/social/scenius/getContactInvite` |
| `techne-sdk/react` | `TechneProvider` / `useTechne` (the client in React), and `useEvent(uri)`: one commons event or place as its versions, with the check's verdict (React only) |
| `techne-sdk/react/query` | the client's reads as hooks over TanStack Query (`useRecordQuery`, `useRecord`, `useVersions`, `defaultQueryClient`); needs `@tanstack/react-query` |
| `techne-sdk/versions` | the same state without React: `eventState`, `verifyAnswer`, version labels |
| `techne-sdk/auth` | sign-in ("Sign in with Techne"): `signIn`, `signUp`, `restore`, `signOut`, `clientMetadata`, `scopes`, `appKey`, `appSpace`, `ownAppSpace`, `WHOLE_STORE` (browser OAuth); the account page: `openAccountSettings`, `accountSettingsUrl` |
| `techne-sdk/session` | a session the app holds itself, for React Native as well as the browser (plain JS, no native module): phone sign-in through the platform's door (`startPhoneSignIn`, `finishPhoneSignIn`), `OwnSession` (`did` + `fetchHandler` for `connect`, refresh, `signOut`, the device credential's proofs), DPoP helpers; `adoptHeldSession` (deprecated) |
| `techne-sdk/connect` | `connect(session, platform?)` / `connectHosted(did, fetchHandler)` / `connectAnonymous(platform?)`: the client over one session, with its reads (`query`, `get`, `versions`, their options forms) and `put`; `bind(clients)` over clients made elsewhere |
| `techne-sdk/put` | `put(techne, records, { deletes })`: the one write, deletes included (public deletes hinted to the platform); each of `records` is `{ record, rkey?, space? }` (`record` the body with its `$type`; `rkey` derived when absent: the lexicon's literal key, else a TID from the record's `createdAt` and CID, and with neither `put` throws before writing anything; `space` only for a private record); `put(techne, [], { deletes })` for deletes alone. Its `status` is never `valid`: `invalid` with the reason (not counted; `not curated: no lexicon`, another app's own type, is written all the same) or `pending` (not refused: indexed when the hint answered, so it reads back by URI, but not yet in the commons' curated view; a failed hint is `pending` too, and the record comes by the relay); `curation` says per record whether it is `curated`, `notCurated` (why) or still `pending`, and `{ wait: ms }` waits for the curated record |
| `techne-sdk/query` | the platform's generic queries: `listRecords`, `getRecords`, `compose` (several steps in one `composeRecords` call), hosts (`hostsOf`, `hostSteps`/`hostsFrom`) |
| `techne-sdk/links` | link tokens: create, redeem, check, revoke |
| `techne-sdk/wasm` | the check itself: `validate`, `decide`, `verify` (`validate` knows the built-in lexicons only; a runtime type is checked by the platform on write) |
| `techne-sdk/catalog` | the browsable lexicon catalog |
| `techne-sdk/nsid`, `techne-sdk/nsid.json` | every NSID as a constant (`NSID`, `METHOD`) |

Datetime fields are plain strings: send `Date.prototype.toISOString()` (UTC, trailing `Z`).

Reading one event (the platform's `getVersions` is public, so an anonymous client will do):

```tsx
import { AtpBaseClient } from 'techne-sdk'
import { useEvent } from 'techne-sdk/react'

const platform = new AtpBaseClient({ service: 'https://<platform host>' })
const load = async (uri: string) => (await platform.pub.techne.draft.commons.getVersions({ uri })).data

function Event({ uri }: { uri: string }) {
  const { loading, error, fields } = useEvent(uri, { load })
  if (loading) return <p>Loading</p>
  if (error) return <p>Could not load it</p>
  return <h1>{String(fields?.name?.value ?? '')}</h1>
}
```

Pass `{ claims }` too, and `verification` holds the check's answer for every record (valid, signer, chain verified).

## Reading without signing in

Public records need no account. `connectAnonymous()` reads the platform directly (it resolves
`did:web:techne.computer` on the first read); `put` on it rejects.

```ts
import { connectAnonymous } from 'techne-sdk/connect'
import type { Query } from 'techne-sdk/query'

const techne = connectAnonymous()
const near: Query = { view: 'curated', where: { all: [
  { type: { is: 'pub.techne.draft.place' } },
  { location: { near: { point: '40.015,-105.27', within: '2km' } } },
] } }
let page = await techne.query(near, { limit: 10 })
for (;;) {
  for (const item of page.items) console.log(item.uri, item.curated, item.record)
  if (!page.cursor) break
  page = await techne.query(near, { limit: 10, cursor: page.cursor })
}
```

- **Paging:** `limit` defaults to 50. Keep it at 500 or less: `query` accepts up to 50000, but past 500 the
  platform reads page after page and charges every row to your budget (below). Keep paging until `cursor` is absent: a page can be shorter than
  `limit` and still have one. `{ count: true }` adds `count` and `capped` (counting stops at 1000).
- **Two views:** every query names its view, and there is no default (a query naming none is refused with
  `ViewRequired`). `view: 'curated'` reads the commons' listed records: one curated record per thing, merged
  from its sources by a curator the commons root trusts, moderated (an event only inside the supported areas).
  A type no curator covers is refused with `NotCurated`, naming the type, rather than answered as an empty list.
  `view: 'asWritten'` reads every public record as its author wrote it: each source copy and the curated record
  (counts in this view hold both copies of a curated thing). A private record reads the same in both. To mix
  them in one list, give each branch its own: `{ any: [{ view: 'curated', where: events }, { view:
  'asWritten', where: mine }] }`. Every item says whether it is `curated`, and its `author`. The platform
  guide's "Two views" section says who curates and how versions merge.
- **Limits:** each statement times out after 5 s (`query` then throws a `ComposeStepError` with status 500 and a
  message starting `query read:`); a `near` over a dense area can approach it, so page `near` small. `query` sends `composeRecords`, which has a row
  budget per signed-in DID and answers 429 `RateLimitExceeded` past it; `query` retries twice, then throws.
  Anonymous callers get one such budget per client IP only where the server is set up to know the client's IP
  (the platform's `AUTH_RATE_LIMIT_CLIENT_IP`); where it is not, all anonymous callers share one budget ten times
  that size, so another anonymous reader can use up yours.
- **Without the SDK:** `/xrpc/*` (and `/.well-known/did.json`) on the platform answers CORS for any origin, so a page can `fetch`
  `https://techne.computer/xrpc/pub.techne.draft.query.listRecords?query=<JSON>&limit=10` directly. The routes
  under `/xrpc/_*` (the agent consent flow and the change stream) are not methods and get no CORS. (CORS is live
  on staging since 2026-11-24 and reaches techne.computer with the first platform release after that; until
  then a browser page reads techne.computer through its own server.)

The builder guide's `reading-public-data` section (https://techne.computer/docs/reading-public-data.md) has the
query rules and the other read servers.

## Scripts and agents

A script with no browser signs in with a password and hands the agent to `connect`, which takes anything with a
`did` and a `fetchHandler`:

```ts
import { AtpAgent } from '@atproto/api'
import { connect } from 'techne-sdk/connect'

const agent = new AtpAgent({ service: 'https://<the account PDS>' })
await agent.login({ identifier: '<handle>', password: process.env.PASSWORD! })
const techne = connect(
  { did: agent.assertDid, fetchHandler: (url, init) => agent.fetchHandler(url, init) },
  'did:web:techne.computer',
)
```

Only an account with a password can do this; techne.town accounts sign in with a code and have no password they know. The guide's
`scripts-and-datasets` section covers testing and publishing a dataset (places, `source` sidecars at
`appKey(uri)` (it hashes any string, a record's AT-URI here), attribution, `publisher`).

## In a browser

The package is ES modules plus WebAssembly. A bundler (Vite, esbuild, webpack 5) handles both. With no build
step, `import { connectAnonymous } from 'https://esm.sh/techne-sdk@<version>/connect'` loads it: about 75 modules,
2.7 MB in all, the WebAssembly inlined in one 1.7 MB module.

## Types for any type

The generated client covers the platform's own lexicons. For a community draft, a requested type or any other
published NSID, print its types:

```sh
npx techne-sdk types pub.techne.draft.c.<id>.toolListing > src/toolListing.ts
```

It asks the platform's registry (`registry.getType`) first, then atproto lexicon resolution (the NSID's
`_lexicon` TXT record, then the schema record on that DID's PDS). `--platform <url>` (or `TECHNE_PLATFORM_URL`)
picks the platform; `--out <file>` writes the file. A ref to another document comes out as `unknown`, with the
ref in a comment.

## Sign in with Techne

`techne-sdk/auth` signs a person in from the browser. Each app is its own atproto OAuth client, the way "Sign in with Google" works: the app serves its client metadata at its client id, the person signs in at their own PDS, and the app keeps the session (an `OAuthSession`, with `did` and `fetchHandler`) that `connect` takes. It runs on `@atproto/oauth-client-browser`, loaded the first time it is used.

```ts
import { clientMetadata, restore, signIn, TECHNE_PLATFORM_DID } from 'techne-sdk/auth'
import { connect } from 'techne-sdk/connect'

const clientId = 'https://cafes.example/oauth-client-metadata.json'

// Serve this JSON at clientId (a static file or a route).
const metadata = clientMetadata({ clientId, clientName: 'Cafe finder' })

// On every page load: finishes a sign-in when the page is the redirect back, else restores a kept session.
const session = await restore({ clientId })
if (!session) await signIn({ clientId, handle: 'alice' }) // alice.techne.town, once techne.town is live (see below)
else {
  const techne = connect(session, TECHNE_PLATFORM_DID)
}
```

- **Who:** with no `handle`, the sign-in starts at the default PDS (techne.town), which asks who you are. A bare name (`alice`) is a handle on the default handle domain. A full handle, a DID or a PDS URL from any PDS is used as given. `signUp({ clientId })` opens the PDS's create-account screen.
- **Scopes:** `scopes({ clientId })` is what it asks for by default, least privilege: `atproto`; the platform's `authPermissioned` permission set with the platform as its audience (the `permissioned.*` calls: private writes, reads and deletes); the app's own private space by its exact key, `ownAppSpace(clientId)` = `space:pub.techne.draft.space.private?skey=<appKey>` (ask for your own space this way: a keyless `space.private` scope, or `skey=*`, is every app's private data, and the consent page shows it as a red warning); and an `rpc:<nsid>?aud=<platform>%23atproto_appview` scope for each generic read the SDK makes signed in: `query.listRecords`, `query.countRecords` and `query.getRecords` (`techne-sdk/query`, `put`'s curation answer) and `registry.getType` and `registry.listTypes`. The platform narrows those reads by the token's space scopes, so they reach public data and the app's own space. An app passes the types it writes as `types: [nsid, ...]`, and each adds a `repo:<nsid>` scope (create, update, delete), as the platform's own least-privilege list does, plus `rpc:pub.techne.draft.sync.indexRecord` so `put` can hint the platform what it wrote (a pending type's records are indexed no other way); without `types` the app writes no public record. `query.composeRecords` is not in the default (the SDK makes no such call); an app that calls it asks for `everything: 'read'`. Everything the person can reach (their personal space, their circles, beacons shared with them) is an opt-in: `everything: 'read'` adds the `authRead` set and `space:*?authority=*&action=read` (`WHOLE_STORE_READ`), `everything: 'write'` adds `authRead`, `authWrite`, `space:*?authority=*&manage=create&manage=update` (`WHOLE_STORE`) and a `repo:` scope for the public records outside `pub.techne.*` (`community.lexicon.*`, `org.hypercerts.funding.receipt`; then our own public types need no `types` entry). The sets reach no space on Techne's PDS; the `space:` scope, asked for by name, does. The consent page shows those with a large warning; ask only if the app needs them. Pass the same `types` and `everything` to `signIn` and `clientMetadata`, since the PDS refuses a request beyond what the metadata declares. Pass `scope` to ask for other scopes, and pass it to both. An app that publishes its own community type (`pub.techne.draft.c.*`) as the signed-in person passes `publish: true`, which adds `rpc:pub.techne.draft.registry.publishType` (publishing a type is a public act). The type's NSID is the registry's answer, so its `repo:` scope can be asked for only after publishing: publish once (a setup sign-in with `publish: true`), then sign in with the published NSID in `types`.
- **A private record names its space:** a record of a type with no public home is written privately, and it must name the `space` it is for; `put` throws `PutError` (`InvalidRequest`) with nothing written when one does not, as the platform's `permissioned.putRecords` refuses it. A record only the person reads goes in their own `space.personal`: `` { record, space: `at://${did}/pub.techne.draft.space.personal/self` } ``. Public records name no space and go to the person's PDS.
- **The app's private space:** `appSpace(session.did, clientId)` is `at://{did}/pub.techne.draft.space.private/{appKey}`, where `appKey(clientId)` is the client id hashed (base32, lowercase, no padding, of its SHA-256; the platform's `sidecar_rkey`). Write there with `put(techne, [{ record, space: appSpace(did, clientId) }])` and read with `permissioned.listRecords({ space })`. Only that person reads it, through a token whose `space:` scopes cover it or one with no scope claim at all (below). In development the client id is the loopback client's, `resolveClientId(options)` with the same options `signIn` took: it carries the scope, so it changes with the port, `types` and `everything`, and so does the space. Its scope names the space type without a key (an id cannot carry its own hash), which is every app's private space: Techne's PDS no longer narrows it to the loopback app's own, and the consent page shows the red every-app warning. That is development only; a hosted app asks with `ownAppSpace(clientId)`. The browser keeps one stored session per origin, so a page that switches between client ids (other `types`, another port's id) signs out first; `restore` hands back whichever session the origin holds.
- **Development:** on `localhost` or `127.0.0.1` you can leave `clientId` out. The SDK then uses atproto's loopback client, so you don't need to host anything.
- **Sessions:** the library refreshes tokens itself. `restore` returns the session, `null` when nobody is signed in, and rejects when a sign-in or refresh failed. `signOut({ clientId, session })` revokes the session. `onSessionDeleted` tells you when the library drops a session. A `state` passed to `signIn` comes back from `redirectState({ clientId })` on the page the redirect lands on.
- **Accounts on another server:** the Techne sign-in page also takes a handle from any server. When the account lives elsewhere, the page sends the person back to your redirect URI with `error=login_required&login_hint=<handle>`, and `restore` starts the sign-in again at that handle's server, with your `state` and the scope your client metadata declares; `restore` does not settle while the page navigates there. You write nothing for it; it is one reason to sign in through `signIn` and not hand-roll the OAuth. (The SDK sends its own `state`, `techne-sdk:<n>:<yours>`; `redirectState`, and the error `restore` rejects with, hand back yours.)
- **The account page and Delete account:** people manage their account (profile, ways to sign in, devices and apps, Delete account) on the account page at their PDS's sign-in host, never inside an app. `openAccountSettings()` opens it in a new tab; call it from the tap's handler. `openAccountSettings({ section: 'delete' })` opens it at Delete account: that is the link for Apple's account-deletion rule (the app still deletes its own data itself). There is no API that deletes an account. Sections are `'profile'`, `'methods'` and `'delete'`. Pass `session` (from `restore`) and it answers `false` without opening anything when the person signed in at another server, which has no Techne account page. Pass `open: (url) => …` to open it elsewhere (an in-app browser sheet in React Native). `accountSettingsUrl(options)` is the address alone. The host comes from the PDS's OAuth metadata, so a move of the sign-in host changes nothing for you. An app on a platform session (`connectHosted`) passes `techne` too, and the page opens already signed in through the platform's one-time link (`identity.openAccountPage`) where the platform and this SDK carry it; otherwise the page asks for a code.
- **Another deployment:** `platform` names the platform's DID (`TECHNE_PLATFORM_DID` by default). `pds`, `plcUrl` and `handleDomain` name the PDS people sign in at, its PLC directory and its handle domain. Pass them the same way to every `techne-sdk/auth` call that takes them (`signIn`, `signUp`, `restore`, `signOut`, `redirectState`, …): the OAuth client is made once per client id with the first call's values. `connect(session, platform)` takes only the platform: the user's PDS resolves its DID. `connectAnonymous(platform, { plcUrl })` takes the PLC directory too, since it resolves a did:plc platform itself.

**Before the Techne release:** the techne.town defaults (`TECHNE_PLATFORM_DID`, the techne.town PDS and handle domain) go live at the Techne release. Until then, `signIn()` without `pds` fails: pass `pds`, `plcUrl`, `handleDomain` and `platform` explicitly, and ask the Techne team for the current staging values.

## A session the app holds (React Native)

`techne-sdk/session` is for an app that signs people in through the platform's phone door and keeps the
session on the device, Beacon's way. It needs no browser and no native module: DPoP is ES256 in plain
JavaScript (`@noble/curves`), so it runs on Hermes. The host provides `crypto.getRandomValues` (React Native:
import `react-native-get-random-values` once at the entry).

```ts
import { OwnSession, startPhoneSignIn, finishPhoneSignIn, type TokenStore } from 'techne-sdk/session'
import { connect, TECHNE_PLATFORM_DID } from 'techne-sdk/connect'

const store: TokenStore = { get, set, delete: del }  // e.g. one expo-secure-store key holding JSON.stringify(data)
const options = { platformUrl, store, lock, onEnded: () => showSignIn() }

const pending = await startPhoneSignIn({ platformUrl, phone })        // texts the code
const { session: data, created } = await finishPhoneSignIn(pending, code, { platformUrl, device: { platform: 'ios' } })
const session = await OwnSession.signedIn(data, options)              // on later launches: OwnSession.restore(options)
const techne = connect(session, TECHNE_PLATFORM_DID)
```

- **Sign-in:** the device makes the DPoP key and the PKCE pair and signs every proof; the platform runs the
  door and answers the tokens bound to that key, plus a narrow device credential. A `UseDpopNonce` answer is
  signed again once, with the same code. A refusal is an `OwnSessionError` whose `code` is the platform's error
  (`OwnSessionUnavailable`: sign in the old way; `InvalidRequest`: wrong code; `CodeExpired`; `RateLimitExceeded`
  with `retryAfter`).
- **Calls** to the PDS carry the access token and a proof per request; a `use_dpop_nonce` answer is signed again
  once, an `invalid_token` one refreshes and sends again.
- **Refresh** goes through the platform (`refreshOwnSession`), five minutes before expiry by default; a call
  waits for it only when the access token has less than 30 seconds left, otherwise it goes on with the current
  token while the refresh runs behind it. The PDS
  rotates the refresh token every time and ends the whole session if an old one comes back, so: one refresh at
  a time in the process, and across processes under `lock` (give one if the app runs more than one JavaScript
  process, such as a background task); inside it the store is read again and a set another process rotated is
  taken; the new set is saved before it is used; a refresh that got no answer is sent again unchanged for up
  to 50 seconds, which the platform answers from its 60-second window (each send is given up 5 seconds before
  that window closes). A store that holds a set under another DPoP key (the person signed out and in again in
  another process) ends this session without touching the store. `onEnded` is called when the session is
  over (`SessionEnded`: sign in again); a session that ends that way (say the grant was revoked on the account
  page) also signs its device credential out, best effort, so the platform drops the phone's push token.
- **The device credential** (push registration, the device list, `signOutDevice`, the change stream) goes only
  with a proof of the session's key: `new AtpBaseClient(session.deviceFetchHandler)` for the calls,
  `session.deviceHeaders('GET', wssUrl)` for the WebSocket's headers.
- **Sign-out:** `session.signOut()` revokes the grant and the device credential (each given up after 10
  seconds) and clears the store, whatever the network says; when the store holds another key's set it leaves
  that set and the store alone.
- **Moving an older install** (deprecated, removed when the platform stops holding sessions):
  `adoptHeldSession({ platformUrl, deviceSession, did, store })` takes over the session the platform holds for
  a device signed in with a full `rsds_` credential (`WrongAccount` when it is not `did`'s); save its answer
  with `OwnSession.signedIn` at once. The tokens are kept even when the issuer's metadata does not answer. With
  `store`, the session is saved there (only when the store is empty) before the issuer's metadata is fetched,
  so an app killed meanwhile restores it on its next launch; then open it with `OwnSession.restore`, not
  `signedIn` (the store may hold a newer set by then), and `signedIn` the answer only when `restore` finds
  nothing. A request that got no answer (network, a send
  over 15 seconds, 502/504) is sent again for up to 50 seconds, for a platform that keeps the answer for the
  same device credential; `NetworkError` after that.

## Do it the atproto way

The platform's builder guide (`get_app_guide`) has the same notes.

- **Read a record from its own PDS.** Resolve the repo's DID and call `com.atproto.repo.getRecord` on the
  `#atproto_pds` service its document names. `didDocumentUrl(did)` from `techne-sdk/connect` gives the
  document's address (the PLC directory for a did:plc, `did.json` for a did:web). Cache the resolution. Never
  assume a repo lives on the Techne PDS. In Rust, `techne_sdk::fetch::fetch_verified` with a
  `techne_sdk::did::CommonDidKeyResolver` (feature `net`) does this and verifies the record's proof.
- **A backend writes as an identity only under that identity's grant.** The grant is a token in the request,
  or the identity's own OAuth grant to that service (narrow, visible to the person, revocable). Holding an
  account's keys is not a grant.
- **Custodial collectives are a named exception.** The platform holds a collective's key today, and
  `writeAsCollective` relies on that. The exception goes once a collective can grant the platform like any
  account. Build nothing new that depends on the platform holding the key.
- **Something the collective says is written as the collective:** `techne.writeAsCollective(input)`, and the
  collective's policy decides. Shared work of its members is different. It goes in a space the collective
  shares, and each member writes their part into their own repo (`put` with a `space`).
- **The client that holds the permission makes every write of an action, while the person waits.** That
  covers the person's own record and any write as the collective. The platform makes no background write
  because of something a person did.
- **Link grants are the example.** An app holding its own session redeems the link at the person's identity
  PDS (`pub.techne.draft.identity.redeemLinkToken`), then calls `pub.techne.draft.identity.claimLinkGrant`
  through that PDS in the same action. The platform writes the grant's record in that request and never
  later. `transition:generic` covers that call today; an app that drops it needs
  `rpc:pub.techne.draft.identity.claimLinkGrant?aud=did:web:techne.computer%23atproto_appview`. This SDK
  has no wrapper for `claimLinkGrant` yet; `redeemLink` from `techne-sdk/links` calls the platform, which
  opens only links from before link tokens for such an app.

## Where we differ from atproto

The platform follows atproto where atproto has an answer. These are the places it does not, today. The platform's builder guide (`get_app_guide`) has the same list.

- **Spaces.** A space has the shape of atproto proposal 0016: its address is `at://{authority}/{spaceType}/{key}`, each space type is a 0016 space declaration, and apps ask for spaces with 0016 `space:` scopes. atproto has not shipped 0016 yet. Read is all or nothing per space: there is no per-record read grant inside a space.
- **Collectives.** atproto has no account that several people write as. A collective here is an account whose key the platform holds. A person who manages it writes as it with `techne.writeAsCollective(input)` (`pub.techne.draft.identity.writeAsCollective`). It goes through their own PDS with `atproto-proxy: did:web:techne.computer#atproto_appview`, and the app's scope needs `rpc:pub.techne.draft.identity.writeAsCollective?aud=did:web:techne.computer%23atproto_appview`. `com.atproto.repo.applyWrites` with a collective's `repo`, sent through the person's PDS, is refused: the PDS answers it itself. The platform's own `applyWrites` still takes it for older app builds and is deprecated. Writes to one of the collective's private spaces go through `pub.techne.draft.permissioned.putRecords` (`put` with a `space`) and a `space:` scope that covers that space.
- **Tokens with no scope claim.** In 0016 a token reaches only the spaces its `space:` scopes name. Here a token that carries no scope claim at all reaches the whole store of its own user, every app's private space included: a token from a PDS that does not grant `space:` scopes, an agent token minted without a `space:` scope (public-only ones excepted), and the sessions Techne's own apps use today. An OAuth grant on techne.town always carries the claim, so one that names no `space:` scope reaches no space. This is temporary. It ends when Techne's own apps hold their own OAuth sessions (platform item 659c31df); after that, no claim means no space.
- **App approval.** 0016 lets an app into a space only when the person may read it and the space's authority has approved the app (`appAccess`). The platform checks only the first. The `appAccess` records and requests exist, but no read or write checks them yet, so a person's consent is enough for now.

## Layout

| Path | What |
|---|---|
| `src/` | the TypeScript package. `src/generated/`, `src/catalog/catalog.gen.ts` and `src/wasm/*.gen.*` are generated and committed |
| `src/types-cli/` | the `techne-sdk types <nsid>` bin: resolve (`resolve.ts`), emit (`emit.ts`), golden files in `testdata/` (`UPDATE_GOLDEN=1 npm run test:types-cli`) |
| `crates/techne-sdk/` | the Rust crate, with the shared fixtures (`fixtures/cases.json`) both languages must answer identically |
| `inputs/` | the codegen inputs, copied by `scripts/inputs-sync.mjs` and pinned in `inputs.pin.json`: `inputs/lexicons/` (the lexicons repo at `lexicons.tag`) and `inputs/platform-api/` (the platform's routed method lexicons, the atproto methods it serves and its NSID rename map, at `platformApi.rev`) |
| `lexicons-base/` | standard atproto repo-op lexicons the generated client needs |
| `dev-pds/` | a real atproto PDS and PLC in one Node process, for end-to-end runs against a platform |
| `scripts/` | codegen (`gen.sh`), the WebAssembly build (`build-wasm.sh`), the package build (`build.mjs`), the gate |

## Changing it

Re-pinning a lexicon or platform API change, rebuilding the generated code and WebAssembly, and the gate
are in [wiki/development/inputs-and-codegen.md](https://github.com/technefoundation/sdk/blob/main/wiki/development/inputs-and-codegen.md) and
[wiki/development/gate-and-tests.md](https://github.com/technefoundation/sdk/blob/main/wiki/development/gate-and-tests.md).

## Releasing

See [RELEASING.md](https://github.com/technefoundation/sdk/blob/main/RELEASING.md).