Skip to content

Version 2.1.3: an optional host for sharing a record - #47

Merged
mwhitham merged 26 commits into
mainfrom
bb/design-scalable-athlete-data-sharing-thr_n5qt6rnvua
Nov 24, 2026
Merged

mwhitham merged 26 commits into
mainfrom
bb/design-scalable-athlete-data-sharing-thr_n5qt6rnvua

Conversation

@mwhitham

Copy link
Copy Markdown
Owner

Version 2.1.3 adds an optional host program for sharing a record, coach authorship in the record, and two storage backends. The ath command line does not depend on the host and works as before.

What this adds

  • ath-host, a second program in host/. It serves athletes' records over HTTPS. Every record operation goes through the Athletic Standard library.
  • Coach authorship (D255) and SQL migration step 7.
  • Two storage backends: native SQLite files in one folder, or libSQL databases written through a local working copy (D268, D269).
  • Sign-in through any OpenID Connect provider (D260). Grants with three permissions, and revocation that stops a waiting write (D262). Retries that write once (D261).
  • Moves between hosts with one writer at every step (D267), and backups with a trial restore (D264).
  • An athlete can disconnect one app from a record, and connect it again from another app (D270).
  • The API description, schema/host-api/1/openapi.json (OpenAPI 3.1). It is generated from the same table the host builds its routes from, and every request body is checked against its shape (D266, D271).
  • Clients: connectHost in the npm package, a starter app, an MCP example, and a Swift example.

The plan, decisions D254 to D271, the storage study, and the build evidence are in build-history/v2.1.3/. The guide for operators and app developers is docs/hosting.md.

The release workflow fix

This branch includes the fix from #46 (commit 01d09ff), so #46 is not needed once this is merged.

Version

Merging moves main from 2.1.2 to 2.1.3. Version 2.1.2 has no tag. If it is not released before this is merged, the next npm release is 2.1.3, which includes everything in 2.1.2.

Checks

  • cargo fmt --check and cargo clippy --all-targets -- -D warnings pass.
  • cargo test: 786 passed, 0 failed, 15 ignored.
  • npm ci, npm run typecheck, npm test: 101 passed, 1 skipped (a Windows-only test).
  • examples/host-mcp: 7 passed. examples/host-swift: 4 passed on macOS.

Not verified

  • A real libSQL server or a hosted libSQL service. An ignored test in host/tests/host_api.rs runs every scenario against one, with the ATH_QUALIFY_* variables.
  • Sign-in through WorkOS AuthKit or Keycloak. The tests use a fixed test-only signing key.
  • The Swift client on iOS, the container image, the Litestream recipe, and the API description in an outside OpenAPI linter.

Not built in 2.1.3

  • Per-athlete encryption keys on the libSQL backend.
  • Routing between several machines in directory mode.
  • Applying a refresh change by change on a device.
  • Attachment staging keys with an orphan cleanup job.
  • The limits in spec section 6.10 beyond body size and upload expiry.

🤖 Generated with Claude Code

mwhitham and others added 26 commits November 23, 2026 16:57
Record the 2.1.3 plan, decisions D254-D267, the hosted-storage study, and the
local hosting experiments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A record's author, or a revision's actor, can now be a human coach, with
the name shown when they wrote it and an ID a host assigned (D255). A coach
may write only coaching notes, training plans, and planned sessions, and
cannot delete a record, so the two-tier wall holds. A package with a coach
author must declare 2.1.3 or later.

Migration step 7 adds three internal tables and changes no athlete row
(D261 to D263): a change log, which triggers fill with the database
revision each write commits; write receipts; and the access epoch. None is
exported. An erasure leaves one value-free change-log row for the record,
and a restore into an empty database starts a new log. The SQL contract
lists the change-log triggers apart from the enforcement triggers.

The JSON Schema, the Zod compatibility schemas, SPEC.md, the skills, and
the demo database follow, and every skill names 2.1.3. Version 2.1.3
departs from the rule that a patch version adds no field; D254 and SPEC.md
section 13 record the exception.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The libSQL backend runs each operation on a local working copy with the
library unchanged, records the changed rows with the SQLite session
extension, and commits them to the server in one guarded transaction. This
keeps one code path for the record rules and avoids a network round trip for
every statement. Step 2 is marked done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Store::capture runs any library operation unchanged and records, in order,
every row it inserted, updated, or deleted, using temporary triggers on the
writing connection. replay_statements turns that record into plain SQL that
any SQLite-compatible server can run; replay and commit_replicated run it in
one transaction that first checks the database revision and access epoch.
build_working_copy fills a new database from another database's rows.

Migration 007 gains internal_replication_log, which a host keeps in a remote
database so other working copies can catch up; erasing a record empties it.
The new code is behind the changesets feature (D268).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A write can carry a host request receipt, stored in the same transaction, and
can require the access epoch it read before a grant check (D261, D262).
Store::changes_since reads the change log and says when it no longer reaches
back far enough (D263).

The replay rules gain what a server needs: the change log replays with
INSERT OR IGNORE so the server's own triggers and the sender agree; the access
epoch stays on the server; schema_scripts builds an empty database without
the two header settings a libSQL server makes read-only (D258). A capture now
survives a package restore, which changes temp_store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ath-host is a second package in the workspace. It checks OpenID Connect access
tokens, keeps a directory of people, athlete records, grant offers, and
grants, and serves version 1 of the host API: owner reads, writes, uploads,
export, and change lists; grant offers and revocation; and a coach roster,
workout summaries, notes, and programs under the three grants (D260-D262).
Every write carries an Idempotency-Key and a receipt.

In directory mode each athlete has a native SQLite file. In remote mode each
athlete has a database on a libSQL server and attachments in an S3-compatible
bucket; the host runs every operation on a working copy and commits the
recorded rows in one guarded transaction (D268). The tests run both modes,
using a local file in place of the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A move has one writer at every step (D267): the source freezes the record and
records the package digest, the destination keeps the uploaded package staged,
the source retires its writer and issues a single-use activation code, and
the destination activates only after the source confirms that code for the
destination's address and the same digest.

ath-host backup writes each athlete's package after a trial restore; ath-host
restore replaces one athlete's record, applies every erasure recorded since,
and raises the access epoch (D264). Erasures are noted before they are applied
and finished when the host starts.

An ignored test runs every host scenario against a real libSQL server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A failed attachment upload or a commit that fails partway leaves the server
unchanged, and a retry with the same key writes once. A restart deletes
working copies and leftover staging folders, and uploads expire after an
hour. A large package restore for one athlete does not hold up a small write
for another. An ignored test times the main operations at 100,000 records.

In remote mode, insertions now go to the server in scripts of up to 500
statements, one round trip each, as spec section 5.2 asks; updates and
deletions still run one at a time so their row counts are checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The session extension named in D268 would need bindgen and libclang in every
build. Temporary triggers need nothing extra, keep the order of the writes,
and roll back with the transaction. The spec now names the libSQL client as
part of ath-host only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A JavaScript program can now read and write a record on an ath-host
with an explicit host address and the signed-in person's access token.
The host checks that person's grants on every request, and the program
never receives a database credential (D266). openDatabase still refuses
database URLs, as REMOTE-TARGETS.md describes.

The connection has one method for each operation of API version 1.
Every write sends an Idempotency-Key. The client makes one when the
caller gives none, and a thrown HostError carries the key so a retry
can reuse it. Errors carry the HTTP status and the host's stable code.

The tests start the real ath-host from target/debug (or the one named
by ATH_HOST_EXECUTABLE) with a test key server, and run an owner's
record with a photo and a coach's grant through revocation. They skip
with a message when the host program is missing. The public-API test
lists connectHost and HostError as reviewed additions since 2.1.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
examples/host-starter/coach.mjs gives an app developer a working
program to copy. With a host address and a coach's token from the
environment, it shows who runs the host, accepts an athlete's offer,
lists the roster, reads the latest workout summaries, and adds a note
that cites the latest workout. It prints each step in plain words, and
prints the note's request key so a retry adds no second note.

The npm host tests build the package and run the program twice against
a real ath-host, so it keeps working as the client changes. It is not
published.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
examples/host-mcp lets an MCP client read a coached athlete's workout
summaries and add a coaching note with two tools,
list_workout_summaries and add_coaching_note. Each tool calls the host
with the signed-in person's token through connectHost, so the host
applies that person's grants and the server never sees a database
credential (D266). A refusal becomes a tool error in plain words, and a
note whose reply was lost is sent again with the same request key.

The server runs over stdio with the token from the environment, as the
MCP authorization specification asks of stdio servers. The README
describes how a remote MCP server would use the host's
protected-resource metadata (RFC 9728) and the MCP authorization flow,
without passing the client's token on to the host.

It has its own package.json and lockfile and is not published. Its
tests start a real ath-host, connect an in-memory MCP client and a
stdio client, and call both tools as a coach through revocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…where.

Coach routes read the access epoch before looking the athlete up, and athlete
IDs reached storage unchecked. An unknown ID then answered differently from
an unshared one, and a crafted ID could name a path outside the data folder or
another database address. Every ID must now be one this host issues, storage
refuses any other, and coach routes confirm the athlete is shared with the
caller before touching storage. The epoch is still read before the deciding
grant check (D262).

Requests that change the directory now honour an Idempotency-Key too, a 401
names the protected-resource metadata (RFC 9728), unknown routes answer in
JSON, and an athlete can list and cancel pending grant offers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/hosting.md explains how to run ath-host and how apps call it: choosing
a backend, every configuration field with two example files, running on one
machine, remote mode with libSQL servers and S3-compatible buckets, sign-in
recipes for WorkOS AuthKit and Keycloak, the version 1 API, grants, backups,
security, and limits. Anyone can then run a host or write a client without
reading the source. The guide describes the code as it is now and marks what
the 2.1.3 plan has not built yet. The provider recipes have not been run
against live accounts, and the guide says so.

A host test parses the two example configurations, so a change to the
configuration format fails the tests until the guide is updated. README.md and
docs/architecture.md link to the guide, and the architecture table names
host/ as the owner of hosting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
host/Dockerfile builds ath-host with the toolchain that rust-toolchain.toml
names and runs it as its own user, with the data folder as a volume and the
configuration file path as an argument. It stops the host with SIGINT, the
signal on which the host finishes open requests. An operator can then run a
host on any machine with a container runtime, without installing Rust.

.dockerignore keeps build output, installed packages, and Git history out of
the build context. It also keeps the file types .gitignore treats as health
data out of every image layer. No file the build reads has one of those
endings.

docs/hosting.md gains section 4.7: how to build and run the image, and how to
run setup and invite in each storage mode. Docker was not available where this
was written, so the image has not been built or run, and the guide says so. A
build of ath-host from a copy of the repository filtered by .dockerignore
succeeded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The data folder is now owner-only and the directory database, which holds
the receipt key, is readable by its owner alone. Only `serve` removes working
copies and leftover staging and finishes erasures, so `setup`, `invite`, and
`backup` can run beside a serving host. `restore` refuses to run while a host
is using the data folder. The storage study no longer says `ath stats`
reports a record's size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Step 9 of 2.1.3 adds clients that reach records only through the host
API (D266). This package shows an app developer how to call API version
1 from Swift on macOS 14 and iOS 17.

- AthleticStandardHost: a small HostClient on URLSession with async and
  await. It covers capabilities, me, the roster, workout summaries with
  paging, coaching notes with an Idempotency-Key the caller reuses on
  retry, and grant offers, acceptance, and revocation. Errors carry the
  host's stable code. JSON uses sorted keys, because the host compares
  the bytes of a retried write.
- host-example: runs the coach flow against a host URL and token from
  the environment and says what it did in plain words.
- Tests start a real ath-host in directory mode and sign tokens with the
  fixed Ed25519 key from the host's own tests. They cover a grant offer,
  acceptance with the coach app, the roster, two pages of workouts from
  the restored demo record, a note sent twice with one key, revocation,
  and the command-line program.
- The README explains sign-in through the system browser with PKCE (RFC
  8252), the token audience, and that the host applies the athlete's
  grants, so an app never holds database credentials.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r errors in JSON.

A retry is compared by its parsed JSON with sorted keys, so the same request
written in another order is still a retry. The Authorization scheme name is
not case-sensitive. Every error answer is JSON with a stable code, including
ones the web framework makes, such as a malformed query. The workout cursor
is the start time and ID of the last workout shown, so a workout deleted
between pages does not end the listing early. `serve` prints the address it
opened. These came from building the Swift example against the host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The evidence lists every check, what each test file shows, timings at
100,000 records, which storage options passed, what was not verified, and
what 2.1.3 does not build. Progress, the build-history index, and AGENTS.md
now describe 2.1.3 as built and not released.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/hosting.md now describes the host as it is after build step 8 and the
review fixes, so an operator or app developer can follow it without reading
the source:

- Moving a record between hosts: the five steps, the move routes, what the
  destination must reach, and what the source keeps.
- ath-host backup and ath-host restore, erasure notes that are finished when
  the host starts, and how to apply erasures again after a provider restore.
- Retries for every change sent with an Idempotency-Key, compared with JSON
  keys sorted, and the requests left out.
- Athlete ID checks, the sign-in challenge header, JSON for every error, the
  workout cursor, pending and cancelled grant offers, and upload expiry.
- Owner-only permissions on the data folder and host.sqlite, which commands
  can run while the host serves, and remote commits in scripts.
- How to run the ignored test against a real libSQL server and the scale
  test, and links to the npm, Swift, starter, and MCP examples.

The guide still says what is not built or not run: the Litestream recipe,
provider recipes against live accounts, a live libSQL server, attachment
cleanup in the bucket, per-athlete keys, and routing between machines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…kups private.

A record with a photo moves from a directory-mode host to a remote-mode host,
takes a write there, and moves back to a directory-mode host with the photo
intact, as build step 8 asks. Backup files are now written readable by their
owner only, because each holds a whole record.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first /release run for 2.1.2 stopped in its first step. For a missing
tag, gh api prints GitHub's Not Found body on standard output, and the
step read that body as the commit the tag names. Both tag checks now read
the matching-refs list, which is empty when there is no tag, and stop on
any other failure instead of treating it as no tag.

The report job ran only after the first step set release to true, so the
refused run left no comment on the pull request. It now also runs when
that step fails.

No version change: main is still 2.1.2 with no tag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The host now keeps the apps an owner has used with each record. An app
joins on first use. A disconnected app's next request for that record
gets 403 app_disconnected, and it cannot connect itself again. The last
connected app cannot be disconnected. A disconnection raises the access
epoch, and owner writes now carry the same epoch guard as coach writes,
so a waiting write from that app fails (D270).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`Components` writes shapes as parts of a larger document, such as an API
description. A shape given a name is written once and referenced
everywhere else. The published record schemas come out byte for byte
the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The host's routes now come from a single table in host/src/operations.rs,
and every request and response body is a Rust type with a published
shape in host/src/shapes.rs. The same table and shapes generate
schema/host-api/1/openapi.json (OpenAPI 3.1), which cargo test --test
generated checks. Request bodies are checked against their shapes, and
every reply in the host tests is checked against the description
(D266, D271).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mwhitham
mwhitham merged commit a3d3eba into main Nov 24, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in ATH: Athletic Standard Nov 24, 2026
@github-actions

Copy link
Copy Markdown

v2.1.3 is ready to release. main now holds version 2.1.3, which has no tag yet.

To release it, comment /release on this pull request. Only a repository admin's comment works.

The release then runs by itself:

  1. The full check runs on Linux, macOS, and Windows. This takes a while.
  2. The tested commit is tagged v2.1.3, and the native archives become a GitHub release.
  3. The npm package is staged. Nobody can install it yet.
  4. This pull request gets a comment saying how to approve it on npm with your two-factor code.

You can also start it from Actions → Release cross-platform → Run workflow on main, with publish ticked, on the website or in GitHub Mobile.

@mwhitham

Copy link
Copy Markdown
Owner Author

/release

@github-actions

Copy link
Copy Markdown

Started the release of v2.1.3 from main (a3d3eba). Follow it under Release cross-platform. The full check takes a while. When it finishes, this pull request gets a comment saying how to approve the npm package.

@github-actions

Copy link
Copy Markdown

The release of v2.1.3 did not finish. Nothing is public on npm.

Open the release run to see which step failed. Fix it in a new pull request, merge it, and comment /release on that pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant