diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..b3cc6da7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,28 @@ +# The container build needs the Rust sources, skills, mappings, and SQL files. Leave +# out build output, installed packages, and Git history, which only make the build +# context larger. +.git +target +**/node_modules +packages/npm/native +packages/npm/schema +packages/npm/skills +packages/npm/pack-output +performance/generated +performance/results/local + +# Real health data never enters an image. These rules follow .gitignore. No file the +# build reads has one of these endings. +.private-data +private-validation +validation-data +**/*.ath.json +**/*.ath.sqlite +**/*.ath.sqlite-wal +**/*.ath.sqlite-shm +**/*.fit +**/*.gpx +**/*.tcx +**/*.xml +**/*.zip +**/*.csv diff --git a/.github/workflows/release-cross-platform.yml b/.github/workflows/release-cross-platform.yml index 6bf12617..46f0504b 100644 --- a/.github/workflows/release-cross-platform.yml +++ b/.github/workflows/release-cross-platform.yml @@ -59,6 +59,25 @@ jobs: GH_TOKEN: ${{ github.token }} PUBLISH: ${{ github.event_name == 'push' || inputs.publish }} run: | + # The commit a tag names, or nothing when there is no such tag. + # `gh api` prints GitHub's "Not Found" body on standard output for a + # missing ref, so `git/ref/tags/` cannot tell "no tag" from a tag. + # The matching-refs list is empty instead. Any other failure stops the + # step: `|| return 1` passes the failure out of `$(...)`, where + # `bash -e` does not apply, so an outage is never read as "no tag". + tag_commit() { + local found type sha + found="$(gh api "repos/$GITHUB_REPOSITORY/git/matching-refs/tags/$1" \ + --jq ".[] | select(.ref == \"refs/tags/$1\") | .object | \"\\(.type) \\(.sha)\"")" || return 1 + [ -n "$found" ] || return 0 + type="${found%% *}" + sha="${found#* }" + if [ "$type" = tag ]; then + gh api "repos/$GITHUB_REPOSITORY/git/tags/$sha" --jq .object.sha + else + printf '%s\n' "$sha" + fi + } version="$(node -p "require('./packages/npm/package.json').version")" tag="v$version" echo "tag=$tag" >> "$GITHUB_OUTPUT" @@ -67,13 +86,17 @@ jobs: echo "Full check only; nothing will be released." exit 0 fi + if ! printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "::error::packages/npm/package.json has version $version, which is not X.Y.Z." + exit 1 + fi if [ "$GITHUB_REF_TYPE" = tag ]; then if [ "$GITHUB_REF_NAME" != "$tag" ]; then echo "::error::The tag $GITHUB_REF_NAME does not name version $version." exit 1 fi elif [ "$GITHUB_REF" = refs/heads/main ]; then - existing="$(gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$tag" --jq .object.sha 2>/dev/null || true)" + existing="$(tag_commit "$tag")" if [ -n "$existing" ] && [ "$existing" != "$GITHUB_SHA" ]; then echo "::error::$tag already names commit $existing. Raise the version in packages/npm/package.json to release $GITHUB_SHA." exit 1 @@ -150,7 +173,26 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - existing="$(gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$TAG" --jq .object.sha 2>/dev/null || true)" + # The commit a tag names, or nothing when there is no such tag. + # `gh api` prints GitHub's "Not Found" body on standard output for a + # missing ref, so `git/ref/tags/` cannot tell "no tag" from a tag. + # The matching-refs list is empty instead. Any other failure stops the + # step: `|| return 1` passes the failure out of `$(...)`, where + # `bash -e` does not apply, so an outage is never read as "no tag". + tag_commit() { + local found type sha + found="$(gh api "repos/$GITHUB_REPOSITORY/git/matching-refs/tags/$1" \ + --jq ".[] | select(.ref == \"refs/tags/$1\") | .object | \"\\(.type) \\(.sha)\"")" || return 1 + [ -n "$found" ] || return 0 + type="${found%% *}" + sha="${found#* }" + if [ "$type" = tag ]; then + gh api "repos/$GITHUB_REPOSITORY/git/tags/$sha" --jq .object.sha + else + printf '%s\n' "$sha" + fi + } + existing="$(tag_commit "$TAG")" if [ -z "$existing" ]; then gh api "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/tags/$TAG" -f sha="$GITHUB_SHA" --silent echo "Tagged $GITHUB_SHA as $TAG." @@ -168,7 +210,9 @@ jobs: report: name: Report on the pull request needs: [version, validate, publish] - if: always() && needs.version.outputs.release == 'true' + # Also when deciding failed, before `release` was set, so a refused + # release is reported too. A run with `publish` off never fails there. + if: always() && (needs.version.outputs.release == 'true' || needs.version.result == 'failure') runs-on: ubuntu-latest permissions: contents: read diff --git a/AGENTS.md b/AGENTS.md index 92e42fab..85cd39c9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -20,12 +20,13 @@ Read these before making decisions — they are the project's memory and outrank 4. **`build-history/v2.0.0/spec.md`** — version 2.0.0. The program, the record, and the database share that version. Garmin and Strava imports and calculation skill files are described there. 5. **`build-history/v2.1.0/spec.md`** — version 2.1.0. Mapping files (`mappings/`, `ath import --mapping`), migration step 4, and `field_basis` are described there. 6. **`build-history/v2.1.1/spec.md`** — version 2.1.1: the complete native rebuild, SQL migration step 5, and the npm launcher and JavaScript client. Its `appendix/` holds the 2.1.0 reference evidence (D218): the command inventory, deliberate behavior changes, semantic rules, public API inventory, and test disposition. -7. **`build-history/v2.1.2/spec.md`** — version 2.1.2, the current version: repaired calculation methods, SQL migration step 6, session effort and strength-set fields, and the three kinds of skill (tool, calculation, coaching) with the CrossFit and HYROX coaching skills. -8. **`build-history/*/decisions.md`** — every decision with the alternatives that were rejected and why (D1 onward, numbered continuously across version folders). Do not relitigate these without new information; if a decision is superseded, append a new D-number in the current version's file. Don't rewrite earlier entries. Don't create addendum files. -9. **`build-history/*/appendix/`** — the long-form studies that informed decisions. Link each study from its D-number. Do not move the decision into the appendix, and do not trim the study down to the decision line. -10. **`build-history/*/progress.md`** — what's done and what's next. -11. **`docs/connections.md`** — per-provider data research (what WHOOP/Oura/Garmin/Apple Health each provide via which path). -12. **`SPEC.md`** — the public field-level format reference. The normative model for version 2.1.2 is the Rust model in `src/model/` with its semantic checks. JSON Schema and the npm protocol declarations are generated from it. The Zod schemas in `packages/npm/src/schema.ts` are 2.1.x compatibility code for JavaScript callers (D209); they mirror the Rust model, including the 2.1.2 optional fields (D238, D239), are tested against the Rust validator, and are not where records are designed. +7. **`build-history/v2.1.2/spec.md`** — version 2.1.2: repaired calculation methods, SQL migration step 6, session effort and strength-set fields, and the three kinds of skill (tool, calculation, coaching) with the CrossFit and HYROX coaching skills. +8. **`build-history/v2.1.3/spec.md`** — version 2.1.3, the current version: an optional host program (`ath-host`, in `host/`) for sharing a record, human coach authorship, SQL migration step 7, and two storage backends — native SQLite files, and libSQL databases written through a local working copy (D268, D269). Its `appendix/` holds the hosted-storage study, the hosting experiments, and the build evidence. `docs/hosting.md` is the guide for operators and app developers. +9. **`build-history/*/decisions.md`** — every decision with the alternatives that were rejected and why (D1 onward, numbered continuously across version folders). Do not relitigate these without new information; if a decision is superseded, append a new D-number in the current version's file. Don't rewrite earlier entries. Don't create addendum files. +10. **`build-history/*/appendix/`** — the long-form studies that informed decisions. Link each study from its D-number. Do not move the decision into the appendix, and do not trim the study down to the decision line. +11. **`build-history/*/progress.md`** — what's done and what's next. +12. **`docs/connections.md`** — per-provider data research (what WHOOP/Oura/Garmin/Apple Health each provide via which path). +13. **`SPEC.md`** — the public field-level format reference. The normative model for version 2.1.3 is the Rust model in `src/model/` with its semantic checks. JSON Schema and the npm protocol declarations are generated from it. The Zod schemas in `packages/npm/src/schema.ts` are 2.1.x compatibility code for JavaScript callers (D209); they mirror the Rust model, including the 2.1.2 optional fields (D238, D239) and the 2.1.3 coach author (D255), are tested against the Rust validator, and are not where records are designed. For v1 storage, IDs, revisions, import behavior, and final schema names, D82–D105 supersede the relevant parts of D4, D25, D36, D40, D43, D48, D62, D64, and D65. The old decisions still @@ -36,7 +37,7 @@ D83's native use of Zod and D93's local libSQL adapter. - **The two-tier wall:** measured records and athlete reports never mix. Measured records require a `source` reference; athlete reports structurally cannot claim one. Never weaken this. - **`build-history/` is append-only.** New plans get a new version folder, named for the format version it produces (`v0.2.0/`, `v1.0.0/`). D-numbers continue across folders — D25 follows D24. Within a version, append new decisions to `decisions.md`. Supporting research goes in `appendix/` and is linked from the D-number. Don't rewrite earlier D-numbers or earlier version folders. A draft that was not approved goes, unchanged, into the `appendix/` of the version that replaced it, as `draft-/` (D224). -- **The Rust model is the source of truth.** After changing the model (`src/model/`), a command or its help (`src/cli/`), or a protocol operation (`src/protocol/`), run `ATH_WRITE_GENERATED=1 cargo test --test generated` and commit the regenerated files: JSON Schema in `schema/2.1.2/` and `schema/athleticstandard.schema.json`, `packages/npm/src/generated/protocol.ts`, `skills/athletic-standard/references/cli.md` (D80), and the demo database in `examples/demo-athlete/`. `cargo test --test generated` fails when a committed copy is behind. Generators never rewrite a published historical schema, `spec/sql/`, or `tests/fixtures/`. +- **The Rust model is the source of truth.** After changing the model (`src/model/`), a command or its help (`src/cli/`), a protocol operation (`src/protocol/`), or a host API operation or body (`host/src/operations.rs`, `host/src/shapes.rs`), run `ATH_WRITE_GENERATED=1 cargo test --test generated` and commit the regenerated files: JSON Schema in `schema/2.1.3/` and `schema/athleticstandard.schema.json`, `packages/npm/src/generated/protocol.ts`, `skills/athletic-standard/references/cli.md` (D80), the host API description in `schema/host-api/1/` (D266), and the demo database in `examples/demo-athlete/`. `cargo test --test generated` fails when a committed copy is behind. Generators never rewrite a published historical schema, `spec/sql/`, or `tests/fixtures/`. - **Naming:** "Athletic Standard" in prose; `athleticstandard` for the npm package, file extension, and version field; `ath` is the CLI command; `AthleticStandard` in code identifiers. - **Keep the repo impersonal:** no personal objectives, audience/positioning framing, or individual names in committed content. - **Never commit real health data.** Real exports stay outside Git, including private repositories. Public tests use only the synthetic files listed in `tools/public-data-allowlist.json`; `tests/public_data.rs` enforces the list and the `.gitignore` rules. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f8d68aee..8fd516c6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,7 +59,7 @@ npm test ## Generated files -JSON Schema, the npm protocol module, the skill's command reference, and the demo database are generated from the Rust sources. After changing the record model, a command or its help, or a protocol operation, regenerate them and commit the result: +JSON Schema, the npm protocol module, the skill's command reference, the host API description (`schema/host-api/1/openapi.json`), and the demo database are generated from the Rust sources. After changing the record model, a command or its help, a protocol operation, or a host API operation or body, regenerate them and commit the result: ```sh ATH_WRITE_GENERATED=1 cargo test --test generated diff --git a/Cargo.lock b/Cargo.lock index 1169f51d..7b850e4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,6 +78,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "anyhow" +version = "1.0.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902" + [[package]] name = "arbitrary" version = "1.5.0" @@ -87,9 +93,42 @@ dependencies = [ "derive_arbitrary", ] +[[package]] +name = "async-stream" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "async-trait" +version = "0.1.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "athleticstandard" -version = "2.1.2" +version = "2.1.3" dependencies = [ "chrono", "chrono-tz", @@ -107,18 +146,121 @@ dependencies = [ "zip", ] +[[package]] +name = "athleticstandard-host" +version = "2.1.3" +dependencies = [ + "athleticstandard", + "axum", + "chrono", + "jsonwebtoken", + "libsql", + "rusqlite", + "rusty-s3", + "serde", + "serde_json", + "sha2", + "tokio", + "ureq", + "url", + "uuid", + "zip", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" +[[package]] +name = "axum" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90" +dependencies = [ + "axum-core", + "bytes", + "form_urlencoded", + "futures-util", + "http 1.5.0", + "http-body 1.1.0", + "http-body-util", + "hyper 1.13.0", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower 0.5.3", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http 1.5.0", + "http-body 1.1.0", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "base16ct" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64" version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + [[package]] name = "bitflags" version = "2.13.2" @@ -141,6 +283,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" dependencies = [ "hybrid-array", + "zeroize", ] [[package]] @@ -155,6 +298,15 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "bytes" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c" +dependencies = [ + "serde", +] + [[package]] name = "bzip2" version = "0.5.2" @@ -211,7 +363,7 @@ checksum = "a6139a8597ed92cf816dfb33f5dd6cf0bb93a6adc938f11039f371bc5bcd26c3" dependencies = [ "chrono", "chrono-tz-build", - "phf", + "phf 0.12.1", "uncased", ] @@ -222,8 +374,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7d8d1efd5109b9c1cd3b7966bd071cdfb53bb6eb0b22a473a68c2f70a11a1eb" dependencies = [ "parse-zoneinfo", - "phf_codegen", - "phf_shared", + "phf_codegen 0.12.1", + "phf_shared 0.12.1", "uncased", ] @@ -278,6 +430,12 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + [[package]] name = "colorchoice" version = "1.0.5" @@ -296,12 +454,28 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -350,6 +524,23 @@ version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" +[[package]] +name = "crypto-bigint" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "914c195c4d7fbc5ed7f88d14cbf85914d5c664967658d43404b263913a477e82" +dependencies = [ + "cpubits", + "ctutils", + "getrandom 0.4.3", + "hybrid-array", + "num-traits", + "rand_core 0.10.1", + "serdect", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.7" @@ -366,7 +557,56 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ + "getrandom 0.4.3", "hybrid-array", + "rand_core 0.10.1", +] + +[[package]] +name = "crypto-primes" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3633a51a39c69ebbaa4feaa694bd83d241e4093901c84a0963b19d9bb3f0cf8f" +dependencies = [ + "crypto-bigint", + "rand_core 0.10.1", +] + +[[package]] +name = "ctutils" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f" +dependencies = [ + "cmov", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5eed333089e2e1c1ac8c6c0398e5e2497b4c9926ca6d0365ed1e099afa5bc23" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "curve25519-dalek-derive", + "digest 0.11.3", + "fiat-crypto", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", ] [[package]] @@ -375,6 +615,17 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac6b926516df9c60bfa16e107b21086399f8285a44ca9711344b9e553c5146e2" +[[package]] +name = "der" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a996a108feb8b427a6e12fcf6af4aa83409b79d72c15337d7741368131ee004" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "deranged" version = "0.5.9" @@ -412,6 +663,8 @@ dependencies = [ "block-buffer 0.12.1", "const-oid", "crypto-common 0.2.2", + "ctutils", + "zeroize", ] [[package]] @@ -425,6 +678,71 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "ecdsa" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0681a4fc24c767085329728d8dfba959af91228aa4610cca4f8ce317ba46ae0" +dependencies = [ + "der", + "digest 0.11.3", + "elliptic-curve", + "rfc6979", + "signature", + "spki", + "zeroize", +] + +[[package]] +name = "ed25519" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29fcf32e6c73d1079f83ab4d782de2d81620346a5f38c6237a86a22f8368980a" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ebaa1a2bf1290ab3bfe5a7b771d050ebffab2711c19a81691c683a5144a25de" +dependencies = [ + "curve25519-dalek", + "ed25519", + "sha2", + "subtle", + "zeroize", +] + +[[package]] +name = "either" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" + +[[package]] +name = "elliptic-curve" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900f37e7e18d74a2347389af6cd69e3a30d5cc9e697f40004865679aa75e9c7c" +dependencies = [ + "base16ct", + "crypto-bigint", + "crypto-common 0.2.2", + "digest 0.11.3", + "ff", + "group", + "hybrid-array", + "pem-rfc7468", + "pkcs8", + "rand_core 0.10.1", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "equivalent" version = "1.0.3" @@ -459,6 +777,22 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" +[[package]] +name = "ff" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f686ab92a9fb0eaf188f6c6c87b89490baa6fdb0db4544ba4dc47f7942489f" +dependencies = [ + "rand_core 0.10.1", + "subtle", +] + +[[package]] +name = "fiat-crypto" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cd1e32ddd350061ae6edb1b082d7c54915b5c672c389143b9a63403a109f24" + [[package]] name = "find-msvc-tools" version = "0.1.15" @@ -476,6 +810,12 @@ dependencies = [ "zlib-rs", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "foldhash" version = "0.2.0" @@ -484,19 +824,78 @@ checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" [[package]] name = "form_urlencoded" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e" dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", + "futures-sink", +] + [[package]] name = "futures-core" version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + [[package]] name = "futures-task" version = "0.3.34" @@ -509,8 +908,13 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "slab", ] @@ -559,6 +963,37 @@ dependencies = [ "cfg-if", "libc", "r-efi 6.0.0", + "rand_core 0.10.1", +] + +[[package]] +name = "group" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fd1a1c7a5206c5b7a3f5a0d7ccd3ff85d0c8f5133d62a02680255b0004af5f4" +dependencies = [ + "ff", + "rand_core 0.10.1", + "subtle", +] + +[[package]] +name = "h2" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", ] [[package]] @@ -595,12 +1030,166 @@ dependencies = [ ] [[package]] -name = "hybrid-array" -version = "0.4.15" +name = "hmac" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" +dependencies = [ + "digest 0.11.3", +] + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http 1.5.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http 1.5.0", + "http-body 1.1.0", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hybrid-array" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" dependencies = [ + "subtle", "typenum", + "zeroize", +] + +[[package]] +name = "hyper" +version = "0.14.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http 0.2.12", + "http-body 0.4.6", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2 0.5.10", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229c6ff5584df4c6becbfe00567128bac768c8cd32ebc8a8366bd81ed072e8f3" +dependencies = [ + "atomic-waker", + "bytes", + "futures-core", + "http 1.5.0", + "http-body 1.1.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "399c78f9338483cb7e630c8474b07268983c6bd5acee012e4211f9f7bb21b070" +dependencies = [ + "futures-util", + "http 0.2.12", + "hyper 0.14.32", + "log", + "rustls 0.22.4", + "rustls-native-certs", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "webpki-roots 0.26.11", +] + +[[package]] +name = "hyper-util" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff" +dependencies = [ + "bytes", + "http 1.5.0", + "http-body 1.1.0", + "hyper 1.13.0", + "pin-project-lite", + "tokio", + "tower-service", ] [[package]] @@ -750,18 +1339,83 @@ dependencies = [ "generic-array", ] +[[package]] +name = "instant-xml" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0201956651e8e4b5a78978dd2840bbb3797227a262a74f47b3576ef053b53bb" +dependencies = [ + "instant-xml-macros", + "xmlparser", +] + +[[package]] +name = "instant-xml-macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f38f6d268cc5e23813c7b2b5bae70317626bf4a95c6de1136b96a221c45148f" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" +[[package]] +name = "jiff" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e77cbfb9fff4798e283c2d69dff39fc2c45e7da017e5ce95b654e46ea41236" +dependencies = [ + "jiff-core", + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", +] + +[[package]] +name = "jiff-core" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b46a105a9874634dd96231021526bf24ca04955a5998c59a9c7666e634b7b8" +dependencies = [ + "log", +] + +[[package]] +name = "jiff-static" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9067a0b23e5be3147d56b2dcf652b18e6b1364caca93fb157653b6fbcab23a9" +dependencies = [ + "jiff-core", + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "jobserver" version = "0.1.35" @@ -783,12 +1437,92 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "jsonwebtoken" +version = "12.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f347a975eb5fa8f5c4eadce6c1152c11c326cf32cf839fb64ff12d5cb8f4ce8b" +dependencies = [ + "base64 0.23.1", + "ed25519-dalek", + "getrandom 0.4.3", + "hmac 0.13.0", + "js-sys", + "p256", + "p384", + "pem", + "rsa", + "serde", + "serde_json", + "sha2", + "signature", + "simple_asn1", + "zeroize", +] + [[package]] name = "libc" version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" +[[package]] +name = "libsql" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bca1704194048f0f0bbc8a8e05ba85c0c67628b03bd59346dd2fdd946a1588" +dependencies = [ + "async-stream", + "async-trait", + "base64 0.21.7", + "bitflags", + "bytes", + "fallible-iterator", + "futures", + "http 0.2.12", + "hyper 0.14.32", + "hyper-rustls", + "libsql-hrana", + "libsql-sqlite3-parser", + "serde", + "serde_json", + "thiserror 1.0.69", + "tokio", + "tokio-util", + "tower 0.4.13", + "tracing", +] + +[[package]] +name = "libsql-hrana" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ceb7fa4a6b75b9eeffe2a375bde04ee8f48910d135a83ffd4191ddfd346c25c" +dependencies = [ + "base64 0.21.7", + "bytes", + "prost", + "serde", +] + +[[package]] +name = "libsql-sqlite3-parser" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a90128c708356af8f7d767c9ac2946692c9112b4f74f07b99a01a60680e413" +dependencies = [ + "bitflags", + "cc", + "fallible-iterator", + "indexmap", + "log", + "memchr", + "phf 0.11.3", + "phf_codegen 0.11.3", + "phf_shared 0.11.3", + "uncased", +] + [[package]] name = "libsqlite3-sys" version = "0.40.0" @@ -839,12 +1573,34 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "md-5" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69b6441f590336821bb897fb28fc622898ccceb1d6cea3fde5ea86b090c4de98" +dependencies = [ + "cfg-if", + "digest 0.11.3", +] + [[package]] name = "memchr" version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +[[package]] +name = "mime" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5848f5a9e8117cf94f2f90faac24a87ff81600ff8628c1e3deaab572e76bfa1" + [[package]] name = "miniz_oxide" version = "0.9.1" @@ -855,12 +1611,42 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "mio" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20521a903f02b0a573cd6840e9d0a5a0cc043d361fe924092cd70f8556cc9c4a" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "num-bigint" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-conv" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" +[[package]] +name = "num-integer" +version = "0.1.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b" +dependencies = [ + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -882,6 +1668,39 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" +[[package]] +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "p256" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c9239b2dbc807adbbe147e8cf72ea7450c3a0aabe62cb8e75ff4ec22e1f72a" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primefield", + "primeorder", + "sha2", +] + +[[package]] +name = "p384" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d17b851e6b3e378ab4ecb07fa2ed23f4d15f075735f8fec9fa1e7bdce5f8301f" +dependencies = [ + "ecdsa", + "elliptic-curve", + "fiat-crypto", + "primefield", + "primeorder", + "sha2", +] + [[package]] name = "parse-zoneinfo" version = "0.4.1" @@ -895,7 +1714,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ "digest 0.10.7", - "hmac", + "hmac 0.12.1", +] + +[[package]] +name = "pem" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d354a98a3d1251555de99e8fdd8afda05573c31b82f59063a7b0a29b5527f120" +dependencies = [ + "base64 0.23.1", + "serde_core", +] + +[[package]] +name = "pem-rfc7468" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9" +dependencies = [ + "base64ct", ] [[package]] @@ -904,6 +1742,15 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" +[[package]] +name = "phf" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" +dependencies = [ + "phf_shared 0.11.3", +] + [[package]] name = "phf" version = "0.12.1" @@ -911,7 +1758,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7" dependencies = [ "phf_macros", - "phf_shared", + "phf_shared 0.12.1", +] + +[[package]] +name = "phf_codegen" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a" +dependencies = [ + "phf_generator 0.11.3", + "phf_shared 0.11.3", ] [[package]] @@ -920,8 +1777,18 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efbdcb6f01d193b17f0b9c3360fa7e0e620991b193ff08702f78b3ce365d7e61" dependencies = [ - "phf_generator", - "phf_shared", + "phf_generator 0.12.1", + "phf_shared 0.12.1", +] + +[[package]] +name = "phf_generator" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" +dependencies = [ + "phf_shared 0.11.3", + "rand", ] [[package]] @@ -931,7 +1798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2cbb1126afed61dd6368748dae63b1ee7dc480191c6262a3b4ff1e29d86a6c5b" dependencies = [ "fastrand", - "phf_shared", + "phf_shared 0.12.1", ] [[package]] @@ -940,14 +1807,24 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d713258393a82f091ead52047ca779d37e5766226d009de21696c4e667044368" dependencies = [ - "phf_generator", - "phf_shared", + "phf_generator 0.12.1", + "phf_shared 0.12.1", "proc-macro2", "quote", "syn 2.0.119", "uncased", ] +[[package]] +name = "phf_shared" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" +dependencies = [ + "siphasher", + "uncased", +] + [[package]] name = "phf_shared" version = "0.12.1" @@ -958,18 +1835,73 @@ dependencies = [ "uncased", ] +[[package]] +name = "pin-project" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6c2123f4708bbd422630a6dae7c03f678b1ce1f1c99e4c4b3beac69c8174cc9" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "358938fd6df944c1e44bb328b60fb275f13c804aac47ba26a1165d45a3f87756" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "pin-project-lite" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +[[package]] +name = "pkcs1" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6250dd7321adbe93d12b750aee0ced159fd13e77f625edcdf1cb6f83cd99f650" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "portable-atomic-util" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" +dependencies = [ + "portable-atomic", +] + [[package]] name = "potential_utf" version = "0.1.6" @@ -985,6 +1917,33 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958" +[[package]] +name = "primefield" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c555a6e4eb7d4e158fcb028c835c3b8642206ddc279b5c6b202ef9a8bdb592f4" +dependencies = [ + "crypto-bigint", + "crypto-common 0.2.2", + "ff", + "rand_core 0.10.1", + "subtle", + "zeroize", +] + +[[package]] +name = "primeorder" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c9f42978c78a00e3d68f69fc03e57a234debae69da4020a4fb588fcdcd07b06" +dependencies = [ + "elliptic-curve", + "once_cell", + "primefield", + "serdect", + "wnaf", +] + [[package]] name = "proc-macro2" version = "1.0.107" @@ -994,6 +1953,29 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prost" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "quick-xml" version = "0.37.5" @@ -1024,6 +2006,37 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c" +dependencies = [ + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rfc6979" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4a459cddafb3fe76b31fd8f1108007566c40301feb64dc7b54656eb7388172b" +dependencies = [ + "crypto-bigint", + "hmac 0.13.0", +] + [[package]] name = "ring" version = "0.17.14" @@ -1038,13 +2051,34 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rsa" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e77fd77e0dea28b3011fd62d15445b7de7959333b0276d930e03be0f755699" +dependencies = [ + "const-oid", + "crypto-bigint", + "crypto-common 0.2.2", + "crypto-primes", + "digest 0.11.3", + "hmac 0.13.0", + "pkcs1", + "pkcs8", + "rand_core 0.10.1", + "sha2", + "signature", + "spki", + "zeroize", +] + [[package]] name = "rsqlite-vfs" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "353b74f9810d5b085b6c42c9d86a5f0fdb795553235cdd48753b32e3809d18a7" dependencies = [ - "thiserror", + "thiserror 2.0.21", ] [[package]] @@ -1062,6 +2096,15 @@ dependencies = [ "sqlite-wasm-rs", ] +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "1.1.6" @@ -1075,6 +2118,20 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "rustls" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" +dependencies = [ + "log", + "ring", + "rustls-pki-types", + "rustls-webpki 0.102.8", + "subtle", + "zeroize", +] + [[package]] name = "rustls" version = "0.23.46" @@ -1085,11 +2142,33 @@ dependencies = [ "once_cell", "ring", "rustls-pki-types", - "rustls-webpki", + "rustls-webpki 0.103.17", "subtle", "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5bfb394eeed242e909609f56089eecfe5fda225042e8b171791b9c95f5931e5" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "rustls-pki-types" version = "1.16.0" @@ -1099,6 +2178,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustls-webpki" version = "0.103.17" @@ -1116,12 +2206,89 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" +[[package]] +name = "rusty-s3" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c091b4ca9c4d51c1a959fa746cc74f5a612a2242070a4ae7b14e22b04c71f8c" +dependencies = [ + "base64 0.23.1", + "hmac 0.13.0", + "instant-xml", + "jiff", + "md-5", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "url", + "zeroize", +] + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + [[package]] name = "ryu-js" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04d056b875a9d2e6cb9a61d127afee9ac5999b9f87bcb32079d1318e505be714" +[[package]] +name = "schannel" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cb23c424d8ee841bb4d813677ca237e2a610067d594fec130f87d6093495ab5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "sec1" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56d437c2f19203ce5f7122e507831de96f3d2d4d3be5af44a0b0a09d8a80e4d" +dependencies = [ + "base16ct", + "ctutils", + "der", + "hybrid-array", + "subtle", + "zeroize", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + [[package]] name = "serde" version = "1.0.229" @@ -1167,6 +2334,39 @@ dependencies = [ "zmij", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serdect" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66cf8fedced2fcf12406bcb34223dffb92eaf34908ede12fed414c82b7f00b3e" +dependencies = [ + "base16ct", + "serde", +] + [[package]] name = "sha1" version = "0.10.7" @@ -1195,12 +2395,44 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "signature" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d567dcbaf0049cb8ac2608a76cd95ff9e4412e1899d389ee400918ca7537f5" +dependencies = [ + "digest 0.11.3", + "rand_core 0.10.1", +] + [[package]] name = "simd-adler32" version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" +[[package]] +name = "simple_asn1" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d585997b0ac10be3c5ee635f1bab02d512760d14b7c468801ac8a01d9ae5f1d" +dependencies = [ + "num-bigint", + "num-traits", + "thiserror 2.0.21", + "time", +] + [[package]] name = "siphasher" version = "1.0.4" @@ -1219,6 +2451,36 @@ version = "1.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "149309498a5f7334b12ddae0cad8aba81ce785fe91755068867e017cf98fee46" +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "spki" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef958a98b9d5da290cfc78946e9f3e61e1e62a18db0d92cac0b83cc161491a9" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "sqlite-wasm-rs" version = "0.6.3" @@ -1269,6 +2531,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + [[package]] name = "synstructure" version = "0.14.0" @@ -1303,13 +2571,33 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + [[package]] name = "thiserror" version = "2.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.21", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", ] [[package]] @@ -1334,6 +2622,7 @@ dependencies = [ "powerfmt", "serde_core", "time-core", + "time-macros", ] [[package]] @@ -1342,6 +2631,16 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" +[[package]] +name = "time-macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tinystr" version = "0.8.5" @@ -1352,6 +2651,127 @@ dependencies = [ "zerovec", ] +[[package]] +name = "tokio" +version = "1.54.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.6.5", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "tokio-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" +dependencies = [ + "rustls 0.22.4", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "libc", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" version = "1.20.1" @@ -1385,21 +2805,23 @@ version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" dependencies = [ - "base64", + "base64 0.22.1", "flate2", "log", "once_cell", - "rustls", + "rustls 0.23.46", "rustls-pki-types", + "serde", + "serde_json", "url", "webpki-roots 0.26.11", ] [[package]] name = "url" -version = "2.5.8" +version = "2.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a" dependencies = [ "form_urlencoded", "idna", @@ -1430,9 +2852,9 @@ checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6" [[package]] name = "uuid" -version = "1.29.2" +version = "1.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bed99139f7dac9b5cfe5f17be4d66dc7079a34dee1d74bcc77217119240e267c" +checksum = "3c14b15dffa2f4bd712103e857140aa04a4f2ff6e955c77d7eb8e53ee02a3b64" dependencies = [ "getrandom 0.4.3", "js-sys", @@ -1451,6 +2873,15 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "want" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" @@ -1675,12 +3106,30 @@ version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" +[[package]] +name = "wnaf" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "795ca18b3fdb5e62bf982199278341ddcf7ebf7d32e25e212ad05d496e95f6fa" +dependencies = [ + "ff", + "group", + "hybrid-array", + "primefield", +] + [[package]] name = "writeable" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" +[[package]] +name = "xmlparser" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" + [[package]] name = "xz2" version = "0.1.7" @@ -1802,7 +3251,7 @@ dependencies = [ "deflate64", "flate2", "getrandom 0.3.4", - "hmac", + "hmac 0.12.1", "indexmap", "lzma-rs", "memchr", diff --git a/Cargo.toml b/Cargo.toml index f2cad53d..8d3c4c93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,17 @@ [package] name = "athleticstandard" -version = "2.1.2" +version = "2.1.3" edition = "2021" rust-version = "1.95" description = "Athletic Standard: a local-first SQLite record of an athlete's training and recovery data" license = "MIT" publish = false +[workspace] +members = [".", "host"] +default-members = [".", "host"] +resolver = "2" + [lib] name = "athleticstandard" path = "src/lib.rs" @@ -38,6 +43,15 @@ ureq = "2.12" uuid = { version = "1.29", features = ["v7"] } zip = "2.2" +[[test]] +name = "replica" +required-features = ["changesets"] + +[features] +# Record the rows a write changes and replay them on another copy (D268). +# Only the host program turns this on. +changesets = [] + [profile.release] lto = "thin" codegen-units = 4 diff --git a/README.md b/README.md index def3a64f..62eec8fe 100644 --- a/README.md +++ b/README.md @@ -86,9 +86,17 @@ The JSON schemas are exported as `athleticstandard/json-schema`, `athleticstandard/skill`. The retired prerelease JSON runtime is not part of the v1 package API. +A program that works with a record on an `ath-host` server uses `connectHost` from +`athleticstandard`. It takes the host's address and the signed-in person's access +token. The host checks that person's grants on every request. The program never +receives a database credential, and `openDatabase` still refuses database URLs. +[`examples/host-starter/`](examples/host-starter/) runs a coach's steps with it. +[`examples/host-mcp/`](examples/host-mcp/) is a small MCP server that reads workout +summaries and adds coaching notes with it. + ## Upgrade a database -A database from version 1.0.0, 2.0.0, 2.1.0, or 2.1.1 upgrades with `ath migrate`. The +A database from version 1.0.0, 2.0.0, 2.1.0, 2.1.1, or 2.1.2 upgrades with `ath migrate`. The command shows a preview first. It makes a verified backup with SQLite's own backup interface before the first schema write. Opening a database never migrates it without confirmation. To go back, restore the backup; it does not contain work recorded after @@ -373,6 +381,18 @@ when the manifest needs one. Importing an exported package is explicit and uses the same preview-then-`--yes` workflow as a provider import. +## Share a record through a host + +Local use needs no host. A host lets a coach read workout summaries and add notes +and programming while the athlete's device is off. `ath-host` is a separate, optional +program that serves many athletes' records over HTTPS. The athlete grants each coach, +through a named app, only the permissions the athlete chooses, and can revoke them. +The athlete can export the complete record at any time, and it opens in ordinary +`ath`. + +[`docs/hosting.md`](docs/hosting.md) explains how to run a host and how apps call it. +`ath-host` is not in the release archives or the npm package. Build it from source. + ## Predict and grade Inside an agent harness, ask the database for prediction evidence: @@ -418,9 +438,10 @@ keeps the ID. Evidence names both the record ID and revision. The format defines 24 record types for profile data, sources, measurements, sessions, athlete reports, nutrition, attachments, benchmarks, predictions, plans, goals, and saved authored work. [`SPEC.md`](SPEC.md) is the public field reference. -The generated JSON Schemas are in [`schema/2.1.2/`](schema/2.1.2/). The published -2.0.0, 2.1.0, and 2.1.1 schemas stay in [`schema/2.0.0/`](schema/2.0.0/), -[`schema/2.1.0/`](schema/2.1.0/), and [`schema/2.1.1/`](schema/2.1.1/). +The generated JSON Schemas are in [`schema/2.1.3/`](schema/2.1.3/). The published +2.0.0, 2.1.0, 2.1.1, and 2.1.2 schemas stay in [`schema/2.0.0/`](schema/2.0.0/), +[`schema/2.1.0/`](schema/2.1.0/), [`schema/2.1.1/`](schema/2.1.1/), and +[`schema/2.1.2/`](schema/2.1.2/). How the code is organized, and the path of one import and one correction to disk, is in [`docs/architecture.md`](docs/architecture.md). diff --git a/SPEC.md b/SPEC.md index 89b1f2db..00cf812d 100644 --- a/SPEC.md +++ b/SPEC.md @@ -1,14 +1,14 @@ -# Athletic Standard Format Specification v2.1.2 +# Athletic Standard Format Specification v2.1.3 **Status:** current format **Live local file:** `athlete.ath.sqlite` **Portable package:** `athlete.ath.json` plus generated files **Normative model:** the Rust record model in [`src/model/`](src/model/) and its semantic checks -**Generated JSON Schemas:** [`schema/2.1.2/`](schema/2.1.2/), generated from that -model. The published 2.0.0, 2.1.0, and 2.1.1 schemas stay in -[`schema/2.0.0/`](schema/2.0.0/), [`schema/2.1.0/`](schema/2.1.0/), and -[`schema/2.1.1/`](schema/2.1.1/). +**Generated JSON Schemas:** [`schema/2.1.3/`](schema/2.1.3/), generated from that +model. The published 2.0.0, 2.1.0, 2.1.1, and 2.1.2 schemas stay in +[`schema/2.0.0/`](schema/2.0.0/), [`schema/2.1.0/`](schema/2.1.0/), +[`schema/2.1.1/`](schema/2.1.1/), and [`schema/2.1.2/`](schema/2.1.2/). Version 2.0.0 adds workout names, descriptions, text results, heart-rate samples, strength sets, route points, and `supplied_fields` for names the @@ -32,6 +32,12 @@ A version 2.1.1 database upgrades with `ath migrate` to SQL schema step 6, which adds one nullable column. The calculation methods that changed, and the coaching skills, are in [`build-history/v2.1.2/spec.md`](build-history/v2.1.2/spec.md). +Version 2.1.3 adds one author variant: a human coach can author and change coaching +notes, training plans, and planned sessions (sections 4.3 and 5.1). A version 2.1.2 +database upgrades with `ath migrate` to SQL schema step 7, which adds four internal +tables (section 7.3). The optional host program that uses them is planned in +[`build-history/v2.1.3/spec.md`](build-history/v2.1.3/spec.md). + Athletic Standard is an open, local-first record for one athlete's training and recovery data. SQLite is the sole live local record. JSON is an explicit, complete package for export, import, inspection, and backup. @@ -172,8 +178,23 @@ event time inside `data`. } ``` +```json +{ + "author_type": "coach", + "coach": "Coach name when written", + "coach_id": "6f1c2e4a-3b5d-4c7e-9f80-1a2b3c4d5e6f" +} +``` + `agent_version` is optional. Tool versions are semantic versions. +The coach actor is new in 2.1.3. `coach` is a nonempty name. `coach_id` is a +lowercase UUID in the 8-4-4-4-12 form, assigned by the host that accepted the change. +The name and ID record who wrote the change. They grant no access. A coach may change +only `coaching_note`, `training_plan`, and `planned_session` records. A coach cannot +change a measured record, an athlete report, or any other record type, and cannot +delete a record. + ### 4.4 Normal deletion A deletion has: @@ -243,6 +264,11 @@ have `agent_version` and `model_version`. A tool author requires `author_type: "tool"`, `tool`, `tool_version`, and `calculation_version`. +A coach author has the same fields as the coach actor (section 4.3): `author_type: +"coach"`, `coach`, and `coach_id`. Only `coaching_note`, `training_plan`, and +`planned_session` records may have a coach author. A `prediction_result_link` cannot +name a coach as `created_by`. + ### 5.2 Input timestamp receipts Source and report times preserve source text in an input receipt: @@ -805,7 +831,7 @@ The athlete's original nutrition claim remains in the linked source-free |---|---| | `application_marker` | `ATH1` | | `sql_schema_version` | Positive SQL migration version | -| `athleticstandard_version` | `2.1.2` | +| `athleticstandard_version` | `2.1.3` | | `database_id` | Stable UUIDv7 database ID | | `created_at` | Database creation timestamp | @@ -889,6 +915,33 @@ prediction-result links, grades, attachments, plans, nutrition interpretations, and workout completion links. Measured rows require a source foreign key. Athlete-report and nutrition tables have no source column. +### 7.3 Internal tables + +Internal tables hold program state, not athlete records. A JSON package never +includes them, and direct SQL writers must not write them. `spec/sql/contract.json` +lists them under `internal_tables`, with a note for each. + +| Table | Since | Holds | +|---|---|---| +| `internal_pending_file_operations` | step 5 | Attachment file work that a SQL transaction cannot include | +| `internal_change_log` | step 7 | One row for each record revision, deletion, and erasure, with the database revision that committed it | +| `internal_write_receipts` | step 7 | One row for each write request a host accepted, with a keyed digest of the request and its result | +| `internal_access_state` | step 7 | One row with the access epoch, which revoking a host grant raises | +| `internal_replication_log` | step 7 | In a database a host keeps on a remote server: the changeset of each committed write, so other working copies can catch up. Empty on a local file | + +Triggers fill `internal_change_log` in the same transaction as the change, so a +direct SQL writer that follows the published recipes is included. A row names the +record ID, the record revision (0 for an erasure), and the kind of change. It holds +no health value and has no foreign key. An erasure removes the record's earlier rows +and leaves one erasure row, so the log keeps no more about an erased record than its +marker does (section 4.5). A restore into an empty database starts a new log. `internal_write_receipts` holds no request body. +A database that never connects to a host keeps an empty receipt table and an access +epoch of 0. + +`internal_replication_log` holds earlier row values, so a trigger deletes every row +when any record is erased. A host that finds a gap in the log rebuilds its working +copy instead of catching up. + ## 8. Portable JSON package An export directory may contain: @@ -1004,16 +1057,19 @@ Validation refuses: - an import key without its current record; - one import key resolving to two records; - an erasure marker whose record still exists; -- duplicate or unsafe package paths. +- duplicate or unsafe package paths; +- a coach author or actor on a record type a coach cannot write, or as `deleted_by`; +- a coach author or actor in a package that declares a version before 2.1.3. The generated JSON Schemas give exhaustive object validation: -- [`schema/2.1.2/athleticstandard.schema.json`](schema/2.1.2/athleticstandard.schema.json) -- [`schema/2.1.2/measurement-series.schema.json`](schema/2.1.2/measurement-series.schema.json) -- [`schema/2.1.2/export-manifest.schema.json`](schema/2.1.2/export-manifest.schema.json) +- [`schema/2.1.3/athleticstandard.schema.json`](schema/2.1.3/athleticstandard.schema.json) +- [`schema/2.1.3/measurement-series.schema.json`](schema/2.1.3/measurement-series.schema.json) +- [`schema/2.1.3/export-manifest.schema.json`](schema/2.1.3/export-manifest.schema.json) -The published 2.0.0, 2.1.0, and 2.1.1 schemas stay in [`schema/2.0.0/`](schema/2.0.0/), -[`schema/2.1.0/`](schema/2.1.0/), and [`schema/2.1.1/`](schema/2.1.1/). A schema checks +The published 2.0.0, 2.1.0, 2.1.1, and 2.1.2 schemas stay in +[`schema/2.0.0/`](schema/2.0.0/), [`schema/2.1.0/`](schema/2.1.0/), +[`schema/2.1.1/`](schema/2.1.1/), and [`schema/2.1.2/`](schema/2.1.2/). A schema checks structure only. It cannot show that a package's history or relationships are valid; the import checks those. @@ -1025,6 +1081,10 @@ The two-tier wall is structural. Measured records require `source_id`. Authored records are a third class. They name an author and exact evidence. They are not measurements and are not athlete reports. +A coach writes authored advice, like an agent. A coach can author or change only +coaching notes, training plans, and planned sessions, so a coach is never the author +or actor of a measured record or an athlete report. + Calculations remain separate by quantity and source unless the operation explicitly compares sources. Device baselines exclude `manual` sources. RMSSD and SDNN never share a calculation. Temperature quantities and activity-specific distances also @@ -1045,7 +1105,7 @@ A v1 package import: and erasure markers; - refuses unknown fields and records it cannot represent; - does not delete a local record merely because the package omits it; -- accepts a `2.0.0`, `2.1.0`, `2.1.1`, or `2.1.2` package; +- accepts a `2.0.0`, `2.1.0`, `2.1.1`, `2.1.2`, or `2.1.3` package; - refuses prerelease Athletic Standard versions below `1.0.0`. An empty destination at database revision zero adopts the package database ID and @@ -1112,17 +1172,20 @@ backup operation. A closed, checkpointed database may be copied. ## 13. Version behavior -The program, the record, and the database use one version, `2.1.2` (D152, D184, -D208, D227). The portable document, generated series files, export manifest, and -live database metadata all carry that version. - -A minor version only adds optional fields. A patch version adds no field. Version -2.1.2 is a recorded exception (D227): it adds optional fields and the -`session_effort` report type, and removes or changes nothing. A `2.0.0` record has -no `field_basis` and stays valid, and every 2.1.1 record is valid 2.1.2 data. -`ath migrate` moves a `2.0.0`, `2.1.0`, or `2.1.1` database to `2.1.2` without -changing its records. Software before 2.1.1 refuses a database at SQL schema step 5, -and software before 2.1.2 refuses one at step 6. +The program, the record, and the database use one version, `2.1.3` (D152, D184, +D208, D227, D254). The portable document, generated series files, export manifest, +and live database metadata all carry that version. + +A minor version only adds optional fields. A patch version adds no field. Versions +2.1.2 and 2.1.3 are recorded exceptions. Version 2.1.2 (D227) adds optional fields +and the `session_effort` report type, and removes or changes nothing. Version 2.1.3 +(D254) adds one author variant and four internal tables, and removes or changes +nothing. A `2.0.0` record has no `field_basis` and stays valid, and every 2.1.1 and +2.1.2 record is valid 2.1.3 data. A package with a coach author declares 2.1.3 or +later. `ath migrate` moves a `2.0.0`, `2.1.0`, `2.1.1`, or `2.1.2` database to +`2.1.3` without changing its records. Software before 2.1.1 refuses a database at SQL +schema step 5, software before 2.1.2 refuses one at step 6, and software before 2.1.3 +refuses one at step 7. Normative package and record data objects are strict. Unknown fields are rejected. The v1 importer refuses Athletic Standard `0.x` documents without modifying them. diff --git a/build-history/README.md b/build-history/README.md index f464aa79..28e6578b 100644 --- a/build-history/README.md +++ b/build-history/README.md @@ -40,6 +40,7 @@ build-history/ | [v2.1.0](v2.1.0/spec.md) | Released. This is the installed software until 2.1.1 is released. | | [v2.1.1](v2.1.1/spec.md) | Built, not yet released: the complete native rebuild. See its [decisions](v2.1.1/decisions.md), [progress](v2.1.1/progress.md), and [release evidence](v2.1.1/appendix/release-evidence.md). | | [v2.1.2](v2.1.2/spec.md) | Built, not released: calculation repairs, session effort, the CrossFit and HYROX coaching skills, and setup guidance in every skill. See its [decisions](v2.1.2/decisions.md) and [progress](v2.1.2/progress.md). | +| [v2.1.3](v2.1.3/spec.md) | Built, not released: an optional host for sharing a record, coach authorship, and native and libSQL storage backends. See its [decisions](v2.1.3/decisions.md), [progress](v2.1.3/progress.md), [storage study](v2.1.3/appendix/hosted-storage-options.md), and [build evidence](v2.1.3/appendix/release-evidence.md). | ## Drafts that were not approved diff --git a/build-history/v2.1.3/appendix/hosted-storage-options.md b/build-history/v2.1.3/appendix/hosted-storage-options.md new file mode 100644 index 00000000..626794af --- /dev/null +++ b/build-history/v2.1.3/appendix/hosted-storage-options.md @@ -0,0 +1,331 @@ +# Where a hosted record can live: options and how to choose + +This study supports D256–D259, D264 and D265. It compares the ways to store athlete +records on a server that many athletes share. It also compares the places the host +program can run. Facts were checked on 2026-11-23 against each vendor's own +documentation. Services change often. Check the current documentation before you +rely on a limit. + +The study does not recommend a vendor. It explains what version 2.1.3 builds and +why, and it gives the questions a developer or operator should answer before +choosing. + +## 1. What the record needs from storage + +These requirements come from the record format and the existing library. They are +the same for every operator. + +| # | Requirement | Why | +|---|---|---| +| R1 | Runs the existing SQL schema and record rules unchanged: STRICT tables, triggers, deferred foreign keys, revision chains, erasure. | The library is the only place record rules live (D210). A second implementation of those rules would drift. | +| R2 | Keeps one database per athlete, for any number of athletes. | A database is the unit of isolation, export, restore, and moving (D256). | +| R3 | Restores one athlete to an earlier moment without changing anyone else. | A shared restore would roll back other athletes or bring back revoked access. | +| R4 | Keeps the complete portable package possible. | The athlete must be able to leave with everything (D82). | +| R5 | Can be reached by a Rust program running on an ordinary server. | The host calls the Rust library for every record operation (D257). | +| R6 | Lets an operator lock each athlete's database with its own key, where wanted. | It limits what a copied disk or backup reveals. | +| R7 | Can be run without any vendor. | Anyone can run their own host. | +| R8 | Is mature enough to hold a health record. | Losing or corrupting a record cannot be undone. | + +Two further facts shape the choice: + +- **Every SQL statement over a network is a round trip.** A local SQLite call takes + microseconds. A call to a database in the same region takes milliseconds. The + library's writes run many statements. Large imports must be sent in batches. +- **The library speaks to SQLite through one crate, rusqlite, in 31 files.** Any + remote option needs a second backend behind the storage interface (D257). The + record rules stay in one place either way. + +## 2. Summary + +"Yes" means documented by the vendor or shown by a test in this study. "No" means +documented as unavailable. "Not stated" means the documentation does not say. + +| Option | R1 SQL rules | R2 many databases | R3 restore one | R5 Rust from any server | R6 own keys | R7 self-run | R8 maturity | +|---|---|---|---|---|---|---|---| +| Native SQLite directory | Yes | Yes, limited by disk | With Litestream | Yes (in process) | Not in 2.1.3 | Yes | SQLite | +| Turso Cloud, libSQL engine | Expected; to qualify (D258) | Yes, no database limit except on the no-cost plan | Yes, 1–90 days by plan | Yes, `libsql` crate | Yes, on its two highest plans | No | Years in production | +| Turso Cloud, Turso engine | To qualify | Yes | Yes | Yes, `turso_serverless` crate | Yes | No | "Early preview" on the cloud | +| Self-run libSQL server (`sqld`) | Expected | Yes, as namespaces | With its S3 backup | Yes, `libsql` crate | Not checked | Yes | Last release 2025-02-14 | +| Bunny Database | Expected (libSQL) | 50 databases of 1 GB in preview | Not documented | Yes, `libsql` crate | Not stated | No | Public preview | +| Cloudflare Durable Objects (SQLite) | Partly: no `BEGIN` or `SAVEPOINT` in `sql.exec` | Yes, unlimited objects, 10 GB each | Yes, 30 days | No: code must run in a Worker | No | No | Generally available | +| Cloudflare D1 | Partly: transactions only through `batch()` | Up to 1,000,000, 10 GB each | Yes, 30 days | Only by a rate-limited HTTP API | No | No | Generally available | +| SQLite Cloud | Expected | Not stated | Yes, 24 hours by default | No Rust SDK | Not stated | No | Not stated | +| Turso Sync on a file written by rusqlite | No: writes not seen | — | — | — | — | — | Failed in test | +| rqlite, dqlite | No | No | — | — | — | Yes | Active | +| Postgres services (Supabase, Neon, Prisma Postgres, Nile) | No: second SQL model | Varies | Varies | Yes | Mostly no | Partly | Mature | +| Device sync engines (PowerSync, ElectricSQL) | Not a store | — | — | — | — | — | — | + +## 3. The options in detail + +### 3.1 Native SQLite files in a directory + +Each athlete gets a private directory with `athlete.ath.sqlite` and its +`attachments/` folder. The host opens the file in process with the same library the +CLI uses. + +- **Fits R1, R4, R5, R7 and R8 without new code.** It is the reference + implementation. Every existing test already covers it. +- **One writer per disk.** SQLite allows one writer per file, and only one host + process may own a directory. More host machines need a routing table that says + which machine serves which athlete. Moving an athlete follows the move protocol + (D267). +- **Disk size limits the number of athletes per machine.** For example, a Railway + volume holds up to 1 TB without contacting Railway, and a service can have only + one volume ([Railway volumes](https://docs.railway.com/volumes/reference)). +- **Backups need a separate tool.** Litestream copies each change in a directory of + SQLite databases to S3-compatible storage within about a second. It restores one + database at a time to a chosen moment ([directory replication](https://litestream.io/guides/directory/)). + Version 0.5.18 was released on 2026-11-03. + - Litestream needs WAL mode and wants to control checkpoints + ([tips and caveats](https://litestream.io/tips/)). The library uses WAL for + writes. Its `close()` runs a truncating checkpoint, and a fresh restore briefly + switches the journal mode. The host must keep connections open and must be + tested with Litestream before the recipe is published. + - Litestream does not copy attachments. The host copies each attachment when it is + uploaded. + - Litestream 0.5.x has no client-side encryption. Only bucket-level encryption is + available ([configuration](https://litestream.io/reference/config/)). +- **Per-athlete keys are possible but not in 2.1.3.** rusqlite can be built with + SQLCipher (`bundled-sqlcipher`). No source confirms that Litestream can replicate + an encrypted file. Version 2.1.3 does not offer this (D264). + +### 3.2 Turso Cloud + +Turso Cloud hosts SQLite-compatible databases reached over the network. It offers +two engines ([Turso Cloud](https://docs.turso.tech/turso-cloud)): + +- **libSQL**, a fork of SQLite that Turso describes as "battle-tested in production + on Turso Cloud for years". Rust programs reach it with the `libsql` crate + (0.10.0, October 2026) with the `remote` feature + ([Rust reference](https://docs.turso.tech/sdk/rust/reference)). +- **Turso**, a rewrite of SQLite in Rust. On Turso Cloud these databases are in + "early preview". Rust programs reach them with `turso_serverless`. The engine + dropped its beta warning in July 2026 and has not reached 1.0. Its maintainers + advise keeping independent backups ([repository](https://github.com/tursodatabase/turso)). + +Facts that matter here: + +- **Database count.** Turso's no-cost plan allows 100 databases. Its other plans + have no database limit. An idle database costs only its storage. +- **Restore.** Each database can be restored to an earlier moment. The window is + 1 to 90 days depending on plan. +- **Own keys.** A database can be encrypted with a key the operator supplies. The + key is passed on each connection and Turso does not store it. It is available on + Turso's two highest plans. A key cannot be changed in place yet + ([encryption](https://docs.turso.tech/cloud/encryption)). +- **Differences from local SQLite** ([limitations](https://docs.turso.tech/cloud/limitations)): + `application_id` and `user_version` are read-only. `journal_mode` and + `busy_timeout` are not supported. The library already treats its metadata table + as authoritative (D93), so the remote backend reads the header values and does + not write them. +- **Not stated in the documentation:** whether `PRAGMA foreign_keys` holds for every + statement on a remote connection, and whether the SQLite online backup API is + available. The JavaScript libSQL client used by 2.1.0 lost the setting between + statements ([remote targets](../../../packages/npm/REMOTE-TARGETS.md)). The + qualification suite tests both (D258). +- **Regions.** The pages read do not list Turso's regions. Place the host and the + databases in the same region and measure the round trip. +- **Ownership.** Supabase announced on 2026-10-02 that it is acquiring Turso. It + says Turso keeps operating its platform and that nothing changes for existing + users ([announcement](https://supabase.com/blog/supabase-is-acquiring-turso)). + +### 3.3 A self-run libSQL server + +The libSQL server (`sqld`) serves many databases ("namespaces") and can back them up +to S3 ([libSQL](https://github.com/tursodatabase/libsql)). It speaks the same +protocol as Turso Cloud's libSQL databases, so the same backend reaches it. Its last +release was v0.24.32 on 2025-02-14, and its maintainers point new projects to the +Turso engine. It is useful for tests and for operators who want the remote mode +without a vendor. It is a weak choice for new production use because it is no longer +actively released. + +### 3.4 Bunny Database + +Bunny Database is built on libSQL and is reached with the same `libsql` crate +([Rust](https://bunny.net/docs/database/connect/rust)). It has been in public preview +since 2026-02-03. Preview accounts are limited to 50 databases of 1 GB each, raised +on request ([limits](https://docs.bunny.net/database/limits)). It documents no +per-database restore, and up to 10 seconds of writes can be lost when its main server +fails ([durability](https://bunny.net/docs/database/durability-and-consistency)). +It is worth testing again when it leaves preview. + +### 3.5 Cloudflare Durable Objects with SQLite storage + +Each Durable Object has its own SQLite database. Objects are unlimited, each holds up +to 10 GB, and each can be restored to any moment in the last 30 days +([limits](https://developers.cloudflare.com/durable-objects/platform/limits/), +[SQLite storage](https://developers.cloudflare.com/durable-objects/api/sqlite-storage-api/)). +It became generally available on 2025-04-07. + +It does not fit this library as built: + +- Code that uses the database must run inside a Cloudflare Worker. Rust runs there + only as WebAssembly through the `worker` crate, without rusqlite. +- `sql.exec` cannot run `BEGIN` or `SAVEPOINT`. Transactions use the storage API's + own functions, so the store's transaction code would change. +- Keys are managed by Cloudflare + ([data security](https://developers.cloudflare.com/durable-objects/reference/data-security/)). + +Using it means moving the host into Cloudflare, not pointing an existing host at a +database. It is the closest match after Turso for operators who already run on +Cloudflare. + +### 3.6 Cloudflare D1 + +D1 offers up to 1,000,000 databases per account, 10 GB each, and a 30-day restore +([limits](https://developers.cloudflare.com/d1/platform/limits/)). Outside a Worker it +is reached through Cloudflare's HTTP API, which Cloudflare limits to 1,200 requests +every 5 minutes per user ([API limits](https://developers.cloudflare.com/fundamentals/api/reference/limits/)). +A Worker can bind about 5,000 databases. D1 also charges for each database above an +included 100,000. Multi-statement transactions are only available through +`batch()`. These limits rule it out for a host that serves many athletes from +outside Cloudflare. + +### 3.7 SQLite Cloud + +SQLite Cloud (now at sqlite.ai) hosts SQLite databases. Its documentation recommends a +separate database for each tenant ([overview](https://docs.sqlitecloud.io/docs/overview)). +It restores one database to the second, with 24 hours of history by default +([backups](https://docs.sqlitecloud.io/docs/backups)). It has an extension for syncing +copies to devices. It has SDKs for C, Go, JavaScript, PHP, Python and Swift, and none +for Rust. Its documentation does not state a database count limit, a size limit, or +support for keys supplied by the operator. Those questions need an answer from the +vendor before it can be considered. + +### 3.8 Turso Sync on a file written by rusqlite + +Turso Sync keeps a local file and pushes and pulls logical changes. Its conflict rule +is "last push wins", and it only sees changes made through its own connection +([Sync usage](https://docs.turso.tech/sync/usage)). In this study's test, stock `ath` +saved a record into a Sync-created file and Sync reported zero changes to push +([experiments](hosting-experiments.md), test 2). It cannot carry writes made by the +library as built, and last-push-wins conflicts with revision checks (D261). + +### 3.9 rqlite, dqlite and LiteFS + +- **rqlite** serves one database per cluster and does not support explicit + `BEGIN`/`COMMIT` ([FAQ](https://rqlite.io/docs/faq/)). +- **dqlite** is a C library with Go bindings and its own network protocol + ([dqlite](https://github.com/canonical/dqlite)). +- **LiteFS Cloud** shut down on 2024-10-15. Fly.io says it cannot support LiteFS + itself, which is still before 1.0 ([notice](https://community.fly.io/t/sunsetting-litefs-cloud/20829), + [LiteFS](https://docs.fly.io/litefs)). + +None fits a database per athlete with the library's transactions. + +### 3.10 Postgres services + +Supabase, Neon, Prisma Postgres and Nile host Postgres. They are mature, but Postgres +is not SQLite. In this study's test, Postgres rejected the first migration because of +`STRICT` ([experiments](hosting-experiments.md), test 3). A translated schema worked, +but it would be a second SQL model to maintain beside the library (D210, D257). +Their database-per-tenant support also varies: Neon limits projects unless an +account is approved for more, Prisma Postgres allows 1,000 databases, and Nile keeps +tenants as rows in shared tables. + +### 3.11 Device sync engines + +PowerSync keeps SQLite on the device and syncs it with Postgres, MongoDB, MySQL or +SQL Server on the server. Its Rust SDK is in beta. ElectricSQL sends data from +Postgres to devices and leaves writes to your own API. Neither hosts a database per +athlete. Either could sit beside a host later. Neither replaces one. + +## 4. Where the host program runs + +The host is one executable, usually shipped as a container (D265). What it needs +depends on the storage backend. + +| Backend | The host needs | Number of copies | +|---|---|---| +| Native directory | A persistent disk and a long-running process. | One per disk. More machines need routing. | +| libSQL remote | A long-running process with network access. No disk. | As many as needed. | + +Places researched: + +- **A container host with disks, such as Railway.** A service can have one volume. + A service with a volume cannot run replicas, and a redeploy causes a short outage. + Without a volume, a service can run many replicas, up to 42 depending on plan. + Railway encrypts volumes, backups and buckets at rest. Volume backups restore the + whole volume, and wiping a volume deletes its backups + ([volumes](https://docs.railway.com/volumes/reference), + [backups](https://docs.railway.com/volumes/backups), + [security](https://docs.railway.com/enterprise/security)). +- **Supabase Edge Functions.** They run TypeScript, or Rust compiled to + WebAssembly. Each request gets 2 seconds of CPU time, 256 MB of memory and at most + 400 seconds. There is no persistent disk + ([limits](https://supabase.com/docs/guides/functions/limits)). The host cannot run + there as built, and large imports would not fit. Supabase Compute, announced in + October 2026, runs any container. It is a private alpha in one region with no + persistent disk, "for evaluation, not production" + ([alpha](https://supabase.com/blog/supabase-compute-private-alpha)). +- **Cloudflare Workers.** Rust runs only as WebAssembly. See section 3.5. +- **Any machine with Docker.** A rented server or a computer at home works for + either backend. The operator owns updates, disks and network access. + +Attachments need an S3-compatible bucket in remote mode. Railway buckets, Supabase +Storage, Amazon S3 and Cloudflare R2 all speak the S3 protocol. Railway buckets and +Supabase Storage do not keep earlier versions of an object, so a deleted file is gone +unless it was copied elsewhere ([Railway buckets](https://docs.railway.com/storage-buckets), +[Supabase S3](https://supabase.com/docs/guides/storage/s3/compatibility)). + +## 5. What 2.1.3 builds, and why + +Version 2.1.3 builds two database backends (D257): + +1. **Native SQLite directory.** It needs no new dependency, it is what every + existing test covers, and anyone can run it on one machine. It is the reference + that every other backend is compared with. +2. **libSQL remote.** It is the only remote family that meets R1 to R6 together. One + crate reaches three services (Turso Cloud, a self-run libSQL server, Bunny + Database), so the backend is not tied to one vendor's API. Host copies hold no + record data, so an operator can add copies without moving athletes. + +Version 2.1.3 does not build the others: + +- Durable Objects and D1 would need the host to run inside Cloudflare, or would hit + API limits from outside. A Workers-based host is a separate project. +- SQLite Cloud has no Rust client and no stated limits. +- Postgres services need a second SQL model. +- Turso Sync cannot see rusqlite writes and uses last-push-wins. +- rqlite, dqlite and LiteFS do not fit a database per athlete. + +## 6. How to choose for your own host + +Answer these questions in order. + +1. **Do you need anyone but the athlete to reach the record?** If not, use `ath` with + a local file. You need no host. +2. **Will one machine hold every record you expect?** Estimate each record's size from + your own data: the size of its `.ath.sqlite` file and `attachments/` folder. If one + disk holds them all, the native directory backend is the simplest choice. Add + Litestream and a scheduled package export. +3. **Do you need more than one copy of the host running at once, or no disks to + manage?** Use the libSQL remote backend. Choose a provider that has passed the + qualification suite (D258), and put it in the same region as the host. +4. **Must every part run on machines you control?** Use the native directory backend, + or a self-run libSQL server if you accept its release status. Several native hosts + need a routing table and the move protocol. +5. **Do you need each athlete locked with a separate key?** Use the libSQL remote + backend with a provider that accepts keys you supply, and keep the keys in a key + service outside the host. The native backend does not offer this in 2.1.3. +6. **Who can read the records?** Whoever runs the host and its storage can read them. + Per-athlete keys limit what a stolen disk or backup reveals. They do not stop + someone who controls the running host. Tell athletes who runs the host and the + storage when they connect. + +Measure before you commit. Run the qualification suite against your account and +region. Time a workout save and a large import. + +## 7. What would change this decision + +- A provider that passes the qualification suite with a different protocol. It gets + a backend behind the same interface. +- Turso-engine databases leaving early preview on Turso Cloud. They would then be + qualified with `turso_serverless`. +- Bunny Database leaving preview with documented per-database restore. +- Litestream confirming support for encrypted SQLite files. The native backend could + then offer per-athlete keys. +- Supabase Compute becoming generally available with a persistent disk. It would + become another place the host can run. +- A change in Turso's terms or operation after the acquisition. The libSQL backend + also reaches other servers, and every athlete can be exported and moved. diff --git a/build-history/v2.1.3/appendix/hosting-experiments.md b/build-history/v2.1.3/appendix/hosting-experiments.md new file mode 100644 index 00000000..01f18b4d --- /dev/null +++ b/build-history/v2.1.3/appendix/hosting-experiments.md @@ -0,0 +1,143 @@ +# Hosting experiments on version 2.1.2 + +These local experiments informed D256, D257, D259, D261 and D263. They ran on +2026-11-22 and 2026-11-23 against commit 073f9bc on macOS arm64. All athlete data was +synthetic. No live cloud account was used. Database, HTTP and object-storage servers +ran on the same machine. The comparison of services is in +[hosted-storage-options.md](hosted-storage-options.md). + +## Fixture + +The checked-in demo database: 491,520 bytes, 25 current records, 26 revisions, one +attachment, and one heart-rate series. SQLite listed 43 tables, 60 indexes, 16 +triggers and 5 views. Its package was four files totalling 61,028 bytes. + +The demo attachment is 68 bytes, which says little about media transfer. The tests +also used an invented 1024 × 683 PNG of 2,099,567 bytes, and a valid PNG padded to +the 26,214,400-byte attachment limit. + +## 1. A Rust host over the library, one directory per athlete + +A 33-line test server called the library unchanged. Each athlete had a private +directory. The server resolved the directory from the signed-in athlete, never from +the request. + +- Two athletes had records with identical IDs. Each athlete's credentials could read + and change only their own record. +- A Swift client on macOS and a separate agent request corrected the same workout + from the same revision. One succeeded. The other received a conflict. Exactly one + revision was added. +- A write lock held on one athlete did not delay a write for another athlete. +- A test coach credential could read selected workout fields. It could not correct a + record, read the profile, or reach the other athlete. +- An official MCP SDK client called a tool through the same server, and the same + athlete check applied. +- A device copy edited offline replayed a stale correction on reconnect. The host + refused it, and both values stayed readable. An unrelated offline edit applied. + +**What it shows:** the library's revision checks already give safe shared writes +when every write goes through one host. Separation between athletes depended on the +server's own checks. + +## 2. Turso Sync around a file written by rusqlite + +The Turso 0.8.4 local sync server and Sync client were seeded with the demo. Stock +`ath` then added one athlete report to the synced file. `ath` saved it and could read +it. On reopening, the Sync client found 26 local records and zero pending changes. A +fresh client pulled 25 records. + +A separate two-client test of conflicting edits kept the last push. No stale-revision +response was produced. + +**What it shows:** Sync cannot carry writes made by the library as built. Its +conflict rule replaces the library's revision check (D261). + +## 3. The same edit written through Turso's own client + +In a fresh copy, the same report was written through Turso's client: the record, +its revision, its typed row and the database revision. Sync saw four pending +changes, and the second client received the report. After the attachment and the +two file header values were supplied, stock `ath` exported the receiving copy. All +four package files matched a stock export byte for byte. + +**What it shows:** a SQLite-compatible engine can hold the record exactly. Writes +must go through that engine's own connection. That is what the libSQL backend does +(D257). The libSQL remote protocol itself was not tested here. The qualification +suite does that (D258). + +## 4. Postgres + +Postgres rejected the first migration at `STRICT`. A small translated model loaded +the fixture rows. Row-level security with separate login roles hid other athletes' +rows. A translated workout correction kept its history, and stock `ath` restored the +exported result. + +**What it shows:** Postgres can enforce the rules only through a second SQL model +maintained beside the library (D257). + +## 5. A report with a photo, a retry, and a refresh + +The test made a report with the 2,099,567-byte photo. The photo went to an +S3-compatible test server. The rows went into a database through Turso's client, with +a receipt in the same transaction. + +- A truncated upload left the database at revision 3, with no report and no + attachment. +- A complete upload whose reply was then discarded, followed by a retry, left one + report, one attachment and one receipt at revision 4. +- A reader fetched the changed rows and the photo. It detected a partial download and + accepted the intact retry. +- The updated copy passed `ath check`. Its five-file export matched the reference + export byte for byte. A clean import restored the photo intact. + +**What it shows:** upload, verify, then commit with a receipt gives a safe retry +(D259, D261). + +## 6. Export, restore, and files beside the record + +After edits and the 2 MB attachment, the record was exported, restored into a new +workspace, checked and exported again. Every package file matched byte for byte. + +A separate test stopped a workspace and recovered the whole folder. It brought back an +extra report written beside the database, which the standard package does not +include. + +**What it shows:** the package carries the record exactly. A host backup must also +list any supported extra files separately. + +## 7. Two copies with the same revision and different contents + +Two copies were restored from the same package. Each received a different note +through stock `ath`. Both then reported the same database ID and the same database +revision. Their package manifests differed. + +**What it shows:** a refresh that compares only the database ID and revision can +silently overwrite local work. A refresh must compare content (D263). + +## 8. Attachments stored inside the database + +Two attachments stored as BLOBs through Sync kept their bytes. The file sizes and the +byte counts the Sync SDK reported were: + +| File | Sent by the uploading client | Received by a new client | +|---:|---:|---:| +| 2,099,567 | 2,801,287 | 2,121,664 | +| 26,214,400 | 34,954,398 | 26,306,540 | + +The S3 test client moved the same 2,099,567-byte payload unchanged. + +**What it shows:** BLOBs work but add transfer, enlarge every database copy, and +still need ordinary files for export and erasure (D259). + +## Limits of this evidence + +- Everything ran on one machine with synthetic data. +- No live provider account, region or network latency was measured. +- The libSQL remote protocol, provider tokens, per-database keys and provider + restores were not tested. +- The test server implemented one coach read grant and returned one conflict code for + every write error. +- Live sign-in, an iOS device and a remote MCP authorization flow were not tested. + +The qualification suite (D258) and the build steps in the [spec](../spec.md) cover +these. diff --git a/build-history/v2.1.3/appendix/release-evidence.md b/build-history/v2.1.3/appendix/release-evidence.md new file mode 100644 index 00000000..ff197354 --- /dev/null +++ b/build-history/v2.1.3/appendix/release-evidence.md @@ -0,0 +1,88 @@ +# Version 2.1.3 build evidence + +This is the evidence from building 2.1.3 (spec section 9 and build step 10). It was +gathered on 2026-11-23 on an Apple silicon Mac (arm64) running macOS 26.6.2, with Rust +1.100.0, Node 25.6.1, and Swift 6.4. All data was synthetic. No live provider account +was used. + +## 1. Checks + +| Check | Result | +|---|---| +| `cargo fmt --check` | Passes. | +| `cargo clippy --all-targets -- -D warnings` | Passes, for the library, the CLI, and `ath-host`. | +| `cargo test` | 786 passed, 0 failed, 15 ignored. The six `cli_terminal` tests need a real terminal; they pass outside the build sandbox. | +| `npm ci`, `npm run typecheck`, `npm test` | 101 passed, 1 skipped (a Windows-only test). Includes the host client run against a real `ath-host`. | +| `examples/host-mcp`: `npm test` | 7 passed, against a real `ath-host`. | +| `examples/host-swift`: `swift test` | 4 passed on macOS, against a real `ath-host`. | + +## 2. What the tests cover + +| Area | Where | What it shows | +|---|---|---| +| Version 2.1.3, migration 007, coach authors | `tests/record_2_1_3.rs`, `tests/migration.rs` | A coach note survives export and restore byte for byte. Coach authors are refused on measured records and athlete reports. The change log matches each committed revision. | +| Recording and replaying writes (D268, D269) | `tests/replica.rs` | Create, correct, delete, erase, and a whole package restore replay onto another copy with the same rows and the same export. A replay from an old revision or access epoch is refused. A server's log is contiguous, and an erasure clears it. The schema scripts build the same schema as a new file. | +| The host API, both modes | `host/tests/host_api.rs` | A report with a photo is saved and opened on another device. Retries return the first answer. A coach sees and adds only what was granted. A revocation blocks a waiting write. Two host copies share one record. Forged IDs look like records that are not shared. | +| Moves and backups (D264, D267) | `host/tests/moves.rs` | A move has one writer at every step, and an activation code works once, only for the destination and digest it names. A record with a photo moves from directory mode to remote mode and back, intact. A restore from an older backup keeps later erasures. An unfinished erasure is finished on start. | +| Disconnecting one app (D270) | `host/tests/host_api.rs`, `packages/npm/test/host.test.ts` | One athlete uses two apps with one record. After the athlete disconnects one, its next read or write is refused, its list hides the record, and it cannot connect itself again. The last connected app cannot be disconnected. The access epoch rises, so a waiting owner write fails. The other app connects it again. | +| The API description (D266, D271) | `host/tests/generated.rs`, `host/tests/support/mod.rs`, `host/tests/hosting_guide.rs` | `schema/host-api/1/openapi.json` matches its generator, and its record references resolve to the published schemas. Every reply in the host tests matches the shape the description gives for its operation. The guide lists every operation. | +| Failures | `host/tests/faults.rs` | A failed attachment upload and a commit that fails partway leave the server unchanged, and a retry writes once. A restart clears working copies and leftover staging. An expired upload cannot be used. | +| Clients | `packages/npm/test/host.test.ts`, `examples/host-mcp/test`, `examples/host-swift/Tests` | The npm client, the starter, the MCP tools, and the Swift client run the owner and coach flows against the host. | + +## 3. Timings at 100,000 records + +`host/tests/scale.rs`, release build. The workload is 100,000 invented athlete reports, +not the project's 100,000- and 3-million-record performance workloads, which need the +2.1.0 generator. The package was 2.7 MB. The remote mode used a local file in place of +the server, so these times include no network. + +| Operation | Directory mode | Remote mode | +|---|---:|---:| +| First transfer (upload and restore the package) | 6.3 s | 20.1 s | +| Export | 1.8 s | 1.4 s | +| Refresh with nothing changed | 5 ms | 2 ms | +| One write | 7 ms | 8 ms | +| Refresh after one note | 3 ms | 3 ms | +| Backup with a trial restore | 10.2 s | 9.6 s | +| One-athlete restore | 6.3 s | not offered | +| A second host copy builds its working copy | — | 7.3 s | + +A small write for a second athlete during a 3,000-record restore for the first took +3.8 ms in directory mode and 17.8 ms in remote mode, and finished before the restore. + +In remote mode the first transfer records every row, replays it on the working copy, +and commits it to the server. Insertions are sent in scripts of up to 500 statements, +so 100,000 records take about a thousand round trips, not hundreds of thousands. A +real server adds one network round trip per script. + +## 4. What passed, by storage option + +| Option | Status | +|---|---| +| Native directory | Passed every test above. | +| Remote mode with a local file in place of the server | Passed every test above. | +| A self-run libSQL server | Not run. `host_api.rs` has an ignored qualification test for it. Running the downloaded server binary was not allowed in this build environment. | +| Turso Cloud, libSQL-engine databases | Not run. Needs an account; the same qualification test applies. | +| Bunny Database | Not run; in preview (D258). | +| S3-compatible buckets | Tested with a stand-in bucket that ignores signatures. No real bucket was used. | + +## 5. Not verified + +- Sign-in through WorkOS AuthKit or Keycloak. Tokens in the tests are signed by a fixed + test-only Ed25519 key. +- The Swift client on iOS. Only macOS ran; Xcode was not set up for iOS builds here. +- The container image. Docker was not running, so `host/Dockerfile` was not built. +- The Litestream recipe. No Litestream binary was run. +- The API description in an outside OpenAPI linter. Downloading one was not allowed + here. The tests check its references and check every reply against it. + +## 6. Not built in 2.1.3 + +- Per-athlete encryption keys on the libSQL backend (D264). +- Routing between several machines in directory mode (spec 6.1). +- Applying a refresh change by change on a device (D263). The host lists the changes; + a device refreshes by downloading the full package and checking its digest. +- Attachments through a staging key with signed download links and an orphan cleanup + job (D259). Attachments go to their final key before the commit; a failed commit can + leave an unused object. +- The limits in spec 6.10 beyond the request body size and upload expiry. diff --git a/build-history/v2.1.3/decisions.md b/build-history/v2.1.3/decisions.md new file mode 100644 index 00000000..136dbdb6 --- /dev/null +++ b/build-history/v2.1.3/decisions.md @@ -0,0 +1,539 @@ +# v2.1.3 decisions + +Decisions continue after D253. Earlier decisions stay as they are. The plan is +[spec.md](spec.md). The storage research is in +[hosted-storage-options.md](appendix/hosted-storage-options.md), and the local +experiments are in [hosting-experiments.md](appendix/hosting-experiments.md). + +## D254. Sharing a record ships as 2.1.3, through an optional host program + +The program, npm package, record package, and database metadata use 2.1.3. D152's +single version rule stays. The SQL migration step becomes 7. The maintainer chose +2.1.3 for this work on 2026-11-22. + +Sharing is a separate executable, `ath-host`. It calls the library for every record +operation. The `ath` CLI is built without it and works as before: one local file, no +account, no network (D75). Running a host is a choice an operator makes. + +Version 2.1.3 adds one author variant (D255) and three internal tables. The published +version rule says a patch adds no fields (D96; SPEC.md section 13). As with D227, +this is an exception made by the maintainer's choice. SPEC.md section 13 records it. +Every 2.1.2 record and package stays valid 2.1.3 data. A 2.1.2 program refuses a +2.1.3 database by its SQL step. + +This ends the deferral of sharing in D96. `ath share` stays a placeholder. Sharing +happens through a host, not through a command that sends files. + +Rejected alternatives: + +- Put the host inside `ath`. Rejected because the CLI would gain network code, + sign-in, and dependencies that local users never need. +- Use 2.2.0, which the version rule suggests. Not chosen: the maintainer chose 2.1.3. + The change is mechanical if it is made later. +- Share by sending files between devices. Rejected because a coach must be able to + read and add while the athlete's device is off. + +## D255. A coach is a record author + +`RecordActor` and `AuthoredRecordAuthor` gain a `coach` variant with two fields: +`coach`, the display name when the record was written, and `coach_id`, an opaque +UUID assigned by the host that accepted the write. + +A coach may author `coaching_note`, `training_plan`, and `planned_session` records +and their revisions. A coach cannot author a measured record or an athlete report. +The two-tier wall holds: coach work is authored advice, like agent advice (D228). + +The name and ID are history, not credentials. A host grants rights only from its own +sign-in. A matching name or ID at a new host gives no access. + +Notes and plans must keep their author after the athlete changes coach or host. +Today a coach's note can only be labelled as written by the athlete, an agent, or a +tool. All three are wrong. + +The SQL `author_type` columns have no CHECK constraint, so no table is rebuilt. + +Rejected alternatives: + +- Store coach identity only on the host. Rejected because the author would be lost + when the record leaves the host. +- Record the coach as an agent. Rejected because it misstates who wrote the advice. +- Use the coach's email address as the ID. Rejected because email addresses change + and identify a person outside the record. + +## D256. One database per athlete in every hosted mode + +Every storage backend keeps each athlete's record in its own database. The host's +directory of accounts, grants, clients, and record locations is a separate database. +A request names a host-assigned resource ID. The host resolves it to a database only +after the access check. A record's database ID is not proof of ownership. + +A database is already the unit the library validates, migrates, exports, restores, +and erases. Keeping it as the unit of hosting means one athlete can be restored, +moved, or deleted without touching another. A fault in one athlete's database cannot +change another's rows. It also matches how the services in the study scale: by number +of databases, not size of one database. + +Rejected alternatives: + +- One shared database with an athlete column on every row. Rejected because every + query would need a filter that the schema does not have, a restore would roll back + every athlete, and the package format is per athlete. +- Several athletes in one directory. Rejected because the library places attachments + in a folder beside the database, so athletes would share it (experiment 1). + +## D257. The library gets a storage interface with two database backends + +The store's SQL calls go through one internal interface in `src/store/`. Two backends +implement it in 2.1.3: + +- **Native**: a local SQLite file through bundled rusqlite. Every build has it. +- **libSQL remote**: a database on a server that speaks the libSQL protocol, through + the `libsql` crate. Only `ath-host` has it, behind the `libsql-remote` Cargo + feature. + +The library stays synchronous. The host runs storage work on blocking worker threads. +The record rules stay in one place: the encoder, the revision checks, and the +migrations are the same code on both backends. + +Native is the reference. It needs no new dependency, every existing test covers it, +and anyone can run it on one machine. + +libSQL remote is the second backend because it is the only remote family that meets +the study's requirements R1–R6 together: SQLite rules, unlimited databases per +account, restore of one database, a Rust client from any server, and keys supplied +by the operator. One crate reaches three services (Turso Cloud, a self-run libSQL +server, and Bunny Database), so the backend is not tied to one vendor's API. Host +copies hold no record data, so an operator can add copies without moving athletes. +D93 already planned a hosted libSQL adapter on the same domain operations. D210 +removed libSQL only from local use, and local use keeps rusqlite. + +Rejected alternatives (details in the study): + +- Postgres services (Supabase, Neon, Prisma Postgres, Nile). Rejected because + Postgres rejects the schema and needs a second SQL model (experiment 4). +- Cloudflare Durable Objects. Not built in 2.1.3 because the host would have to run + inside a Worker as WebAssembly, without rusqlite and without `BEGIN`. +- Cloudflare D1. Rejected because, from outside Cloudflare, it is reached only + through an HTTP API limited to 1,200 requests every 5 minutes. +- SQLite Cloud. Not built because it has no Rust client and states no database count + or size limits. +- Turso Sync of a file written by rusqlite. Rejected because Sync did not see the + write (experiment 2), and its conflict rule is last push wins. +- rqlite, dqlite, LiteFS. Rejected because they do not fit one database per athlete + with the library's transactions, and LiteFS Cloud has shut down. +- Make the library asynchronous. Rejected because the CLI and every existing caller + would change for a need only the host has. +- Let the host write rows with its own SQL. Rejected because it would be a second + copy of the record rules (D210). + +## D258. A storage provider is supported only after the qualification suite + +A backend or provider is listed as supported only after a named, reproducible run of +the qualification suite in spec section 8 passes. The report names the provider, +engine, region, crate versions, and date. + +The first runs are a local libSQL server in continuous integration and Turso Cloud +libSQL-engine databases in a manual run. Turso-engine databases on Turso Cloud stay +unlisted while Turso calls them early preview. Bunny Database stays unlisted while it +is in preview. + +On a libSQL server, the remote backend: + +- reads `application_id` and `user_version` but never writes them. Turso Cloud makes + them read-only, and the metadata table is authoritative (D93); +- skips `journal_mode` and `busy_timeout`, which Turso Cloud does not support; +- runs each write as one interactive transaction on one connection, and refuses to + open a database where a dangling reference is not rejected; +- replaces the verified local backup before a migration with a provider restore point + plus a complete package export, and refuses to migrate if either fails (D124); +- sends large imports in batches inside one transaction. + +Turso's documentation does not say whether foreign keys hold on every remote +statement. The JavaScript client in 2.1.0 lost that setting between statements +([remote targets](../../packages/npm/REMOTE-TARGETS.md)). The suite tests it rather +than assuming it. + +Rejected alternatives: + +- List providers from their documentation. Rejected because the documentation leaves + the foreign-key and backup questions open. +- Qualify Turso-engine databases first. Not chosen because they are in early preview + on Turso Cloud, while libSQL has years in production there. + +## D259. Attachments live in a directory or an S3-compatible bucket + +The native backend keeps attachments in the folder beside the database, as today. The +remote mode keeps them in any S3-compatible bucket under `/attachments/`. + +An upload goes to a staging key first. The host checks length, media type, and +SHA-256, then commits the record that names the file, then moves the file to its final +key. Downloads use short-lived signed links issued after the permission check. A +cleanup job removes staged files that no committed record names. + +The S3 protocol is the common interface of every bucket service the study found, so +operators can choose any of them. Upload, verify, then commit gives a safe retry +(experiment 5). + +Rejected alternatives: + +- Store attachments as database BLOBs. Rejected because they add transfer, enlarge + every copy and backup of the database, and still need ordinary files for export and + erasure (experiment 8). +- A vendor's own file API. Rejected because it ties the host to one vendor. + +## D260. Sign-in is provider-neutral OpenID Connect + +The host accepts OAuth access tokens from one configured OpenID Connect provider. It +checks issuer, signature, expiry, intended API, and client. It maps the issuer and +subject to a host principal. Email is never the identity. + +Native apps sign in through the system browser with the authorization code flow and +PKCE (RFC 8252). The host publishes protected-resource metadata (RFC 9728) so CLI, +mobile, and MCP clients can find the provider. + +Two recipes are tested with the same API tests: a hosted provider (WorkOS AuthKit) +and a self-run provider (Keycloak). Other providers that meet the same checks work +without code changes. + +The operator claims the first owner with a one-time local setup command. An athlete +accepts their own invitation. An invitation from a coach cannot make anyone an owner. + +Rejected alternatives: + +- Build accounts and passwords into the host. Rejected because account recovery and + multi-factor sign-in are hard to do safely, and providers already do them. +- Support one provider only. Rejected because an operator must be able to run every + part without a vendor. +- Let the sign-in provider decide record access. Rejected because only the athlete's + grant can give access (D262). + +## D261. Shared edits go through the host + +While a record is connected to a host, edits that others should see are sent to the +host. The host checks the grant, the expected revision, and the request ID, and +commits through the library. Devices refresh from accepted changes (D263). Shared +edits need a connection. + +Every accepted request writes a receipt in the same transaction as the change. A +repeated request with the same ID and body returns the original result. The same ID +with a different body is a conflict. A stale correction is refused, and the client +keeps the person's version for review. + +The library's revision checks already make shared writes safe when one place accepts +them (experiment 1). Coaches only add notes and programming, so concurrent offline +editing by several people is not needed. + +Rejected alternatives: + +- Sync database files between devices and the host. Rejected because the tested sync + did not see library writes, and last-push-wins discards a stale edit instead of + keeping it for review (experiment 2). +- Merge offline edits automatically. Rejected as unnecessary for append-only coach + work, and unsafe for corrections to measured data. + +## D262. Grants are checked on every request; revocation raises an access epoch + +The athlete grants a named coach, through a named app, any of three permissions: read +workout summaries, add coach notes, add programming. Nothing is selected until the +athlete approves. The host checks the current grant on every request, including +lists, counts, searches, attachments, and queued work. + +Revoking a grant raises an access epoch stored in the athlete's database. A coach +write commits only if the epoch it checked is still current, in the same transaction. +A write ordered after the revocation fails. + +The grant directory and the athlete's database are separate databases, so one +transaction cannot cover both. The epoch puts the deciding value inside the athlete's +database. This works the same when several host copies serve one athlete. + +Rejected alternatives: + +- Check the grant only when the request starts. Rejected because a write could commit + after the athlete revoked access. +- Route every grant change and write for an athlete through one process. Rejected as + the only mechanism because the remote mode allows many host copies. +- Let a "read training" grant return full workout JSON. Rejected because workouts hold + routes and heart-rate data that the summary grant does not cover. + +## D263. A device refresh compares content, not only the database revision + +A device keeps an ordinary SQLite copy. It remembers the database revision and the +deterministic package manifest digest of the last copy it verified. Before applying +host changes, it checks that the local file still matches that digest. If it does not, +the device keeps the local file, downloads the hosted copy beside it, and asks the +owner. It never chooses a winner by itself. + +Changes come from `internal_change_log` and are applied through the library with their +revisions unchanged. If a change is missing or cannot be applied, the device falls +back to a verified full package. + +Two copies with different notes reported the same database ID and revision +(experiment 7). Comparing only those numbers would overwrite the athlete's work. + +Rejected alternatives: + +- Replace the device copy with the hosted copy on every refresh. Rejected because it + discards offline local work. +- Copy raw rows into the device database. Rejected because it bypasses the library's + checks. + +## D264. Backups, restores, and keys depend on the backend + +Native backend: Litestream copies each athlete database to S3-compatible storage. The +host copies each attachment when it is uploaded. A scheduled job exports each +athlete's complete package to storage with separate credentials. The Litestream recipe +is published only after it is tested with the library's checkpoints and restores. + +libSQL remote backend: the provider's per-database restore, plus the same scheduled +package export, plus a copy of the attachment bucket. + +Every restore is one athlete. It starts isolated, invalidates sessions, and replays +later erasures and revocations before it serves requests. + +Per-athlete keys: the libSQL backend passes a per-database key when the provider +supports it. The host reads keys from a key service the operator configures, never +from its own directory database. The native backend has no per-athlete encryption in +2.1.3. SQLCipher is a rusqlite build option, but no source confirms that Litestream +can replicate an encrypted file. + +Whoever runs the host and its storage can read records. Keys limit what a copied disk +or backup reveals. The host tells the athlete who runs the host and the storage when +they connect. + +Rejected alternatives: + +- Rely only on a provider's volume snapshots. Rejected because they restore every + athlete at once, and on some hosts wiping the volume deletes them. +- Rely only on a provider's database restore. Rejected because the Turso engine's + maintainers advise independent backups, and the package is the format an athlete + can open anywhere. +- Offer native encryption in 2.1.3. Deferred until backups of encrypted files are + tested. + +## D265. The host is one long-running program + +`ath-host` is one executable, shipped with a container definition. It needs a +long-running process. The native backend also needs a persistent disk, and only one +copy may own that disk. The remote backend needs no disk, and any number of copies +may run. + +Large provider imports take minutes and hundreds of megabytes. A program that runs +per request with seconds of CPU time cannot do them. + +Rejected alternatives: + +- Supabase Edge Functions. Rejected because each request gets 2 seconds of CPU time, + 256 MB of memory, and no persistent disk. +- Cloudflare Workers. Rejected for 2.1.3 because Rust runs there only as WebAssembly, + without rusqlite. +- Supabase Compute. Not a target while it is a private alpha "for evaluation, not + production" with no persistent disk. + +## D266. Clients reach records only through the host API + +Apps, the npm client, Swift code, and MCP tools talk to the host's versioned HTTPS +API. They never receive database credentials. The npm client gains an explicit host +connection. Its handling of `libsql:` and other database URLs stays as +[REMOTE-TARGETS.md](../../packages/npm/REMOTE-TARGETS.md) describes. + +The API description is generated from the Rust definitions, like the npm protocol +declarations, and `cargo test --test generated` checks it. Version 1 contains only operations whose permission and output +were reviewed. A local command becomes remote only after that review. + +A database credential would let a client bypass grants, receipts, and the access +epoch. + +Rejected alternatives: + +- Give each app a database token limited to one athlete. Rejected because the token + would expose the whole database, beyond any grant. +- Expose the local worker protocol over the network. Rejected because some of its + operations take local file paths. + +## D267. A move between hosts has one writer at every step + +Moving a record to another host follows five steps: connect an empty destination, +freeze the source, verify and restore privately at the destination, retire the source +writer with a single-use activation bound to this transfer, then activate the +destination. At most one host accepts writes at any moment. A lost reply is retried +with the same transfer ID. + +If the source cannot be reached, the owner can restore from a device copy or backup. +That copy is labelled a recovered fork, because software cannot prove an unreachable +host stopped writing. + +Changing coach never moves a record. It changes grants only. + +Rejected alternatives: + +- Copy the database and switch clients at once. Rejected because writes made during + the copy would be lost or duplicated. +- Let the destination activate after a timeout. Rejected because a timer cannot prove + the source stopped. + +## D268. A remote write runs on a local working copy and commits as one changeset + +The libSQL backend does not send the library's SQL statements to the server one at a +time. The host keeps a working copy of each active athlete's database on local +temporary disk. The library runs every operation against that copy, unchanged. +SQLite's session extension records the rows a write changed. The host then commits +those row changes to the remote database in one transaction. The transaction first +checks that the remote database revision and access epoch still equal the values the +working copy started from. If either has moved, the host refreshes the copy and runs +the request again. The receipt makes the second run safe (D261). + +The host sends rows in a fixed order: deletions with children first, then insertions +with parents first, then updates, with the database revision raised last. That is the +order the store itself writes in. Foreign keys are deferred to commit. All 43 tables +have primary keys, which the session extension requires. Every trigger before 2.1.3 +only checks rows and never writes them. The 2.1.3 change-log triggers compute the same +rows on the server as on the working copy, so the server builds its own change log. + +A working copy is a cache. The host builds it by copying every table from the server, +keeps it current from `internal_replication_log`, a log of committed changesets kept in +the remote database, and may delete it at any time. Host copies keep no durable state. +An erasure deletes the replication log in the same transaction, because the log holds +earlier row values, and every working copy older than the erasure is rebuilt. Idle +working copies are deleted after a set time and when the host starts. + +This supersedes the part of D257 that routes the store's SQL calls through one +interface with two backends. The native backend is the library's own store. D257's +choice of the libSQL protocol and its rejected alternatives stand. Spec sections 5.1, +5.2 and 6.1 describe the result. + +The reasons come from the build: + +- The library calls SQLite in about 340 places, including streamed reads during + export. Routing each one through a network interface changes all of them, and every + statement becomes a network round trip. An import of the 100,000-record workload + would need hundreds of thousands of round trips. +- The record rules run in one place, unchanged. Experiments 3 and 5 showed that rows + written by the library and sent to a SQLite-compatible engine export byte for byte + like the original ([experiments](appendix/hosting-experiments.md)). +- The server checks every row again: its STRICT types, triggers and foreign keys run + on each replayed row. +- Reads are local, so calculations and views also work in remote mode. + +Rejected alternatives: + +- Route every SQL call through an interface, as D257 first said. Rejected for the + reasons above. +- Replay the SQL text recorded by a statement trace. Rejected because functions such as + the current time give different results on replay, and trigger statements appear in + the trace. +- Use libSQL embedded replicas for the working copy. Rejected as the only mechanism + because writes would still need a second path, and it ties the backend to one + replication protocol. The changeset works with any SQLite-compatible server. +- Rebuild a stale working copy from scratch every time. Rejected as the only path + because several host copies serving one athlete would each copy the whole database + after every write by another copy. It remains the fallback when the log has a gap. + +## D269. A write's rows are recorded with temporary triggers + +`Store::capture` records each inserted, updated, and deleted row with temporary +triggers on the writing connection. It does not use SQLite's session extension, which +D268 named. A changeset is a JSON list of row changes in the order they were made. +This supersedes D268 only on how rows are recorded. The rest of D268 stands. + +The session extension needs SQLite built with the pre-update hook, and the Rust +binding then generates its bindings at build time with `bindgen` and `libclang`. That +would add a C toolchain requirement to every build of the workspace, including the +release builds for each platform. Temporary triggers need nothing beyond the SQLite +the library already bundles. + +Temporary triggers also keep the exact order of the writes, so a replay needs no +sorting by table. They live only on the connection that runs the write and only for +that write. Their rows are in a temporary table, so a change rolled back inside the +operation is rolled back from the record too. + +The capture sets `temp_store` to MEMORY first. A package restore sets that setting, +and changing it deletes every temporary table and trigger. Setting it first makes the +restore's change no change. + +Rejected alternatives: + +- The session extension. Rejected for the build requirement above, and because a + changeset groups changes by table, which the schema's checks do not always accept + in that order. +- Diff the database before and after. Rejected because it reads every table for every + write. + +## D270. An athlete can disconnect one app from a record + +The host keeps a list of the apps an owner has used with each record. An app joins the +list the first time the owner uses it with that record. The app that creates a record +is its first entry. The owner can list the apps, disconnect one, and connect a +disconnected one again. + +A disconnected app's next owner request for that record is refused with +`403 app_disconnected`. Its record list no longer shows the record. The app cannot +connect itself again. The owner connects it again from another app that is still +connected. + +The host refuses to disconnect a record's last connected app, so the owner always +keeps a way in. One statement checks this, so two disconnections at the same moment +cannot both succeed. + +A disconnection raises the access epoch, as a revocation does (D262). Owner writes now +read the epoch between two owner checks and commit only if it is unchanged. So an +owner write from that app that was already waiting fails, like a coach write after a +revocation. This covers record creation, correction, deletion, erasure, and package +restore. + +A coach's access is already tied to one app by the grant. The athlete ends it by +revoking the grant. A disconnection does not change grants. + +This is the success test in spec section 1: two independently registered apps use the +same record, and the athlete can disconnect either one. The sign-in provider can end +an app's sessions, but it cannot say which records an app may reach. Sign-in decides +who the person is; only the host knows which of the person's records an app used. + +Rejected alternatives: + +- Leave app control to the sign-in provider and `allowed_clients`. Rejected because + `allowed_clients` applies to every person on the host, and a provider's session + revocation does not stop an app that can sign in again. +- Refuse tokens issued before the disconnection, and let a fresh sign-in reconnect. + Rejected because an app that holds a refresh token can get a fresh token without + the person, so the disconnection would not hold. +- Require the owner to approve every new app before first use. Rejected because the + provider already asks the person to approve the app at sign-in. A second approval + would need an approval screen in an app that is already connected. + +## D271. The API description is OpenAPI 3.1, built from one operation table + +This carries out D266. `host/src/operations.rs` lists every operation once: its method, +path, caller, query parameters, bodies, success status, and retry rule, with its +handler. The host builds its router from that table, and the generator builds +`schema/host-api/1/openapi.json` from the same table. An operation cannot be served +without being described. + +Each request and response body is one Rust type with a published shape, declared with +the library's `model_object!` in `host/src/shapes.rs`. Handlers read and return those +types. Each JSON request body is checked against its shape before the host reads it, +so the description is also the rule the host enforces. A body that does not match +gets `400 invalid`. + +The description is OpenAPI 3.1, because its schemas are JSON Schema draft 2020-12, +the same draft as the published record schemas. Records and revisions are not copied +into it. They point to the published package and measurement-series schemas of the +current record format, by relative path. The library's JSON Schema writer gained +`Components`, which writes several shapes into one document and turns each named +shape into a reference. The published record schemas come out byte for byte the same. + +Three checks keep the description true. `cargo test --test generated` compares it +with the committed copy. Like the current record schemas, it is a generated file, so +`tests/published_files.rs` does not pin its bytes until 2.1.3 is released. The host tests check every reply against the shape the +description gives for its operation, with the library's validator. A guide test checks +that `docs/hosting.md` lists every operation. + +Rejected alternatives: + +- Derive the description with an OpenAPI crate such as `utoipa`. Rejected because it + would add a second schema system beside the library's model shapes, and the record + shapes already have a published JSON Schema. +- Write the description by hand. Rejected because it drifts from the routes, which is + what D266 rules out. +- Copy the record schemas into the description. Rejected because it would publish a + second copy of more than 16,000 lines of record schema that could disagree with the + first. diff --git a/build-history/v2.1.3/progress.md b/build-history/v2.1.3/progress.md new file mode 100644 index 00000000..db140f86 --- /dev/null +++ b/build-history/v2.1.3/progress.md @@ -0,0 +1,110 @@ +# v2.1.3 progress + +Status: **built; not released**. Evidence: [release-evidence.md](appendix/release-evidence.md). The plan is [spec.md](spec.md). + +| Step | What | Status | +|---|---|---| +| 1 | Plan, decisions D254–D267, storage study, hosting experiments | done | +| 2 | Version 2.1.3, migration 007, coach authorship | done | +| 3 | Changeset capture in the library (D268) | done | +| 4 | libSQL remote backend: working copies, guarded commits, replication log, qualification suite | built; live run pending | +| 5 | `ath-host` native directory mode: connect, read, write, attachments, refresh, restore | done | +| 6 | Sign-in and grants | done; provider recipes in step 9 | +| 7 | Remote mode with object storage and several host copies | done with a stand-in server; live run pending | +| 8 | Moves and backups | done; Litestream recipe untested | +| 9 | Clients, starter, `docs/hosting.md`, container and setup guide | done; iOS and container not run | +| 10 | Scale and fault runs, release evidence | done | + +The experiments in step 1 ran on 2.1.2 with synthetic data on one machine +([hosting-experiments.md](appendix/hosting-experiments.md)). No live provider, region, +or network latency has been measured yet. Steps 4 and 7 do that. + +Step 2 notes: + +- An erasure removes that record's earlier rows from `internal_change_log` and leaves one + `erasure` row with no values, so the log never outlives an erasure. +- The change-log triggers are listed under a new `internal_triggers` key in + `spec/sql/contract.json`, because they enforce nothing. +- Records carry no version, so the 2.1.3 gate on coach authors runs on the package + document, in Rust and in Zod. +- A 2.1.2 program refuses a step-7 database by its version check ("Unsupported Athletic + Standard database version: 2.1.3"). This was checked by hand with a 2.1.2 build. + +D268 changes how the libSQL backend writes. Steps 3 and 4 follow it. + +Step 3 notes: + +- Changes are recorded with temporary triggers on the writing connection, not with + SQLite's session extension. The session extension needs `bindgen` and `libclang` in + every build, including the release builds for each platform. Temporary triggers need + nothing extra, keep the exact order of the writes, and roll back with the transaction. +- A changeset is JSON. No replicated column holds a binary value, so JSON carries every + value exactly. +- `tests/replica.rs` runs with `--features changesets`. Step 4 adds the host to the + workspace, which turns the feature on for the default `cargo test`. +- Migration 007 gained `internal_replication_log`, with the revision each changeset + started from, and a trigger that empties it when a record is erased. + +Steps 4 to 7 notes: + +- `ath-host` is a second package in the workspace (`host/`). The `ath` CLI does not + depend on it. The libSQL client lives only in the host. +- Remote mode follows D268: the library runs every operation on a working copy, and + the host commits the recorded rows to the server in one guarded transaction. The + same commit code runs against a local SQLite file standing in for the server + (`local_server` storage), which is how the tests run without a network. +- Host copies that share athletes' databases also share the host directory. In remote + mode it is a libSQL database; in the stand-in mode it is a file in the shared folder. +- `host/tests/host_api.rs` covers, in both modes: a report with a photo saved and + opened on another device; retries and request-ID conflicts; a coach who sees and + adds only what was granted; a program; a revocation that blocks a waiting write; and + two host copies sharing one record, including catching up from the replication log + and rebuilding after an erasure. +- Not yet run: the remote backend against a real libSQL server, and sign-in through a + real provider. Tokens in the tests are signed by a fixed test-only key. + +Step 8 notes: + +- A move is driven by the owner's app: `move/freeze` on the source, the package + uploaded to an `incoming` record on the destination, `move/retire` on the source, + then `move/activate` on the destination, which asks the source to confirm the + single-use code for its own address and the digest of the package it holds (D267). +- `ath-host backup` writes each athlete's package as a zip after a trial restore and + check. `ath-host restore` replaces one athlete's record in directory mode, then + applies every erasure recorded since and raises the access epoch. In remote mode, use + the provider's restore for that athlete's database. +- Every erasure is noted in the host directory before it is applied. The host finishes + unfinished erasures when it starts (D264). +- The Litestream recipe is documented but not run: no Litestream binary was run in + this build. +- `host_api.rs` has an ignored qualification test that runs every scenario against a + real libSQL server with two host copies and prints timings. It needs a server + address and token in `ATH_QUALIFY_*` variables. + +Steps 9 and 10 notes: + +- The npm package exports `connectHost` and `HostError` (`packages/npm/src/host.ts`). + `examples/host-starter`, `examples/host-mcp`, and `examples/host-swift` are not + published. +- `docs/hosting.md` is the guide for operators and app developers; `host/Dockerfile` + builds the host image. +- Building the clients found a security bug, fixed before this step closed: coach + routes read storage before looking the athlete up, and athlete IDs reached storage + unchecked. IDs are now checked everywhere, and an unknown ID answers like an unshared + one. +- The [release evidence](appendix/release-evidence.md) lists what passed, the timings, + what was not verified, and what 2.1.3 does not build. + +After step 10: + +- An athlete can disconnect one app from a record and connect it again from another + (D270). The host keeps each record's apps in its directory. A disconnection raises + the access epoch, and owner writes now carry the epoch guard that coach writes use. + A guarded write in remote mode now retries after a revision conflict; the retry + checks the epoch again first. +- The API description is generated into `schema/host-api/1/openapi.json` (D266, + D271). The router and the description come from one operation table, and request + bodies are checked against their published shapes. The description was not run + through an outside OpenAPI linter: downloading one was not allowed in this build + environment. Its references are checked by a test, and every test reply is checked + against it. diff --git a/build-history/v2.1.3/spec.md b/build-history/v2.1.3/spec.md new file mode 100644 index 00000000..d0be2a95 --- /dev/null +++ b/build-history/v2.1.3/spec.md @@ -0,0 +1,422 @@ +# Athletic Standard 2.1.3 — an optional host for sharing a record + +Status: **approved direction; not built; not released**. Nothing in this plan runs a +hosted service, publishes a package, or lists a skill. + +Today a record lives in one file on one machine. An athlete who works with a coach has +no supported way to let the coach read selected training, or add a note, while the +athlete's device is off. Version 2.1.3 adds an optional host program, `ath-host`. It +serves many athletes' records through a documented HTTPS API. Each athlete keeps a +complete copy that opens offline in ordinary `ath`. Local use does not change and needs +no account (D75, D254). + +The program, the npm package, the record package, and the database metadata use 2.1.3 +(D254). The SQL migration step becomes 7. + +The research behind the storage choices is in +[hosted-storage-options.md](appendix/hosted-storage-options.md). The local experiments +are in [hosting-experiments.md](appendix/hosting-experiments.md). + +## 1. The result + +| Person | What they can do | What success looks like | +|---|---|---| +| Athlete using `ath` alone | Nothing changes. | It works offline with no account. | +| Athlete who connects a host | Upload an existing record, keep a device copy, and refresh it. | Records, history, series, and attachments arrive. The device shows when it last refreshed. A refresh never overwrites local work silently. | +| Athlete working with a coach | Grant a named coach, through a named app, any of three permissions. Revoke them. | The coach sees only what was granted. The next request after a revocation fails. Past coach notes keep their author. | +| Coach | See a roster of the athletes who granted access. Read workout summaries. Add notes and programming. | The coach cannot correct, delete, or export the athlete's history. | +| Host operator | Run the host on one machine or on several, with either storage backend. | Setup, backup, and restore work from the written guide on a clean machine. | +| App developer | Sign a person in, connect to their host, and read and write within grants. | Two independently registered apps use the same record. The athlete can disconnect either one. | +| Athlete leaving a host | Export the complete record, or move it to another host. | The copy opens in stock 2.1.3. Old credentials give no access at the new host. | + +## 2. Scope + +In 2.1.3: + +- Human coach authorship in the record (D255). +- A storage interface in the library, with a native SQLite backend and a libSQL remote + backend (D257, D258). +- Attachments in a local directory or an S3-compatible bucket (D259). +- `ath-host`: sign-in, grants, the versioned API, write receipts, device refresh, moves + between hosts, backups, and limits (D256, D260–D265, D267). +- Clients: a host connection in the npm package, a Swift example, and a small MCP server + (D266). +- `docs/hosting.md`, a guide for operators and developers written from the storage + study. +- A container definition and a setup guide for one machine. + +Not in 2.1.3: + +- A running hosted service. The build ships software and guides. +- Automatic merging of offline edits made by several people (D261). +- Direct database sync between a device and a host database (D261). +- Postgres or any other non-SQLite backend (D257). +- Per-athlete encryption keys on the native backend (D264). +- Changes to calculation methods, skills, or the model gateway key. + +## 3. Who owns what + +| Part | Owns | Does not own | +|---|---|---| +| Library (`src/`) | The record model, validation, revisions, the single encoder, migrations, export and restore, the storage interface and both backends. | Accounts, grants, network requests. | +| `ath` CLI | Local commands, unchanged. Built without the remote backend. | Hosting. | +| `ath-host` | Token checks, grants, the API, receipts, refresh, moves, backups, and limits. It calls the library for every record operation. | Record rules. It never writes record tables with its own SQL. | +| Clients | The sign-in flow, the user interface, and API calls. | Permission decisions. The host makes them. | + +There is one set of record rules (D210). The host and every backend use it. + +## 4. The record in 2.1.3 + +### 4.1 Coach authorship (D255) + +`RecordActor` and `AuthoredRecordAuthor` gain: + +```json +{ "author_type": "coach", "coach": "Display name when written", "coach_id": "6f1c…" } +``` + +The host that accepted the write assigns `coach_id`, an opaque UUID. A coach may author +`coaching_note`, `training_plan`, and `planned_session` records and their revisions. A +coach cannot author a measured record or an athlete report. The two-tier wall holds. + +The Rust model, semantic checks, JSON Schema, npm protocol declarations, and Zod +compatibility schemas gain the variant. The SQL `author_type` columns have no CHECK +constraint, so no table is rebuilt. + +### 4.2 Migration 007 + +`007-version-2-1-3.sql` sets the metadata to 2.1.3 and SQL schema 7. It adds four +internal tables and changes no athlete-owned row (D211): + +- `internal_change_log`: one row for each record revision, deletion, and erasure, with + the database revision that committed it. Triggers fill it in the same transaction, so + direct SQL writers are included. The host reads it to answer "what changed since + revision N" (D263). +- `internal_write_receipts`: one row for each accepted host request: actor, app, + operation, request ID, a keyed digest of the request, and the resulting IDs and + revisions. It holds no request body and no health values (D261). +- `internal_access_state`: one row holding the access epoch (D262). Revoking a grant + raises it. +- `internal_replication_log`: in a database a host keeps on a remote server, the + changeset of each committed write, with the revision it started from (D268). An + erasure deletes every row. It stays empty on a local file. + +None of the four is exported in a package. All are listed in `spec/sql/contract.json` +as internal, like `internal_pending_file_operations`. A local database that never +connects to a host uses only the change log and the access row. + +On the native backend, the migration keeps the preview, verified backup, confirmation, +and rollback rules (D124, D211). On the libSQL backend, a provider restore point and a +complete package export replace the verified backup (D258). + +### 4.3 Versions + +- Records and packages written as 1.0.0 through 2.1.2 stay valid. Packages from 2.0.0 + onward still import. +- A package that contains a coach author declares 2.1.3. A 2.1.2 program refuses it + with its existing message. +- A 2.1.2 program refuses a 2.1.3 database by its SQL step. +- `schema/2.1.3/` is generated. `schema/2.1.2/` is not rewritten. +- SPEC.md section 13 records the version-rule exception (D254). + +## 5. Storage + +### 5.1 Two backends (D257, D268) + +| Backend | Where the athlete database lives | How a write reaches it | Built into | +|---|---|---|---| +| Native | A local SQLite file, opened through bundled rusqlite. | The library writes it directly. | Every build. | +| libSQL remote | A database on a server that speaks the libSQL protocol. | The library writes a local working copy. The host commits the changed rows to the server in one transaction. | `ath-host` only. The `ath` CLI never links the libSQL client. | + +The library stays synchronous and keeps one code path. It gains a way to run a write +while recording its changed rows with temporary triggers (D269). That is behind the +library's `changesets` Cargo feature, which only `ath-host` turns on. The CLI gains no +network code and no dependency. + +### 5.2 The libSQL backend (D258, D268) + +**Working copies.** The host keeps a working copy of each active athlete's database on +local temporary disk. It builds the copy by copying every table from the server. It +keeps the copy current from `internal_replication_log` in the remote database. It +rebuilds the copy when the log has a gap, deletes idle copies after a set time, and +deletes all copies when it starts. + +**A write.** + +1. Bring the working copy to the server's current database revision. +2. Run the library operation on the copy while recording its changeset. +3. On the server, in one transaction: check the database revision and access epoch, + apply deletions (children first), insertions (parents first), then updates, with + the database revision raised last; append the changeset to the replication log. +4. If the check fails, discard the copy's change, refresh, and run the request again. + The receipt makes the second run safe. + +An erasure deletes the replication log in the same transaction. + +**Differences from local SQLite.** + +- `application_id` and `user_version` are read but never written on the server. The + metadata table is authoritative (D93). +- `journal_mode` and `busy_timeout` are not sent. The server manages both. +- The backend refuses to open a database where a dangling reference is not rejected. +- The SQLite online backup API is not used on the server. Section 4.2 says what + replaces it before a migration. +- A large write is sent in batches inside its one transaction. + +### 5.3 Attachments (D259) + +- **Directory store:** the folder beside the database, as today. +- **Object store:** any S3-compatible bucket, under `/attachments/`. + An upload goes to a staging key. The host checks length, media type, and SHA-256, + commits the record that names the file, then moves the file to its final key. + Downloads use short-lived signed links issued after the permission check. A cleanup + job removes staged files that no committed record names. + +Attachments are never database BLOBs. + +### 5.4 One database per athlete (D256) + +Each athlete has one database in every backend. The host directory (principals, grants, +registered clients, record locations, routing) is a separate database on the same +backend. A request names a host-assigned resource ID. The host resolves it after the +access check. + +### 5.5 Choosing a backend + +| | Native directory | libSQL remote | +|---|---|---| +| Runs on | One machine with a persistent disk. | Any machine with network access, plus a libSQL server or service. | +| Copies of the host | One per disk. More machines need routing (section 6.1). | Any number. | +| Athletes per host | Limited by disk size. | Limited by the provider. | +| Backups | Litestream, attachment copies, scheduled package export. | Provider restore, attachment bucket copy, scheduled package export. | +| Per-athlete keys | Not in 2.1.3. | Where the provider supports them. | +| Each operation | In process. | In process on a working copy, plus a few round trips to commit. | +| Vendor needed | No. | No, if you run a libSQL server yourself. | + +The [study](appendix/hosted-storage-options.md) section 6 gives the questions to ask. + +## 6. The host + +### 6.1 Modes + +**Native directory mode.** One host process owns a data directory: + +``` +/host.sqlite directory: principals, grants, clients, locations +/athletes//athlete.ath.sqlite +/athletes//attachments/ +/staging/ uploads and imports before validation +``` + +A process lock on each athlete directory allows one writer. Several machines can each +own a set of athletes. The directory names the machine that serves each athlete, and a +request for another machine's athlete is forwarded or redirected. Only one machine +accepts writes for an athlete at a time (D267). + +**Remote mode.** Host copies keep no durable record data, only working copies that can +be deleted at any time (D268). Any copy can serve any athlete. The libSQL server orders +writes to each database. The revision check, receipts, and the access epoch handle +races between copies (D261, D262). + +### 6.2 Sign-in (D260) + +- One configured OpenID Connect provider. The host checks issuer, signature, expiry, + audience, and client, and maps issuer and subject to a principal. +- Native apps use the system browser with authorization code and PKCE (RFC 8252). +- The host publishes protected-resource metadata (RFC 9728) for CLI, mobile, and MCP + clients. MCP clients follow the MCP authorization specification. +- Tested recipes: WorkOS AuthKit and Keycloak, with the same API tests. +- `ath-host setup` claims the first owner once, on the machine. Athletes accept their + own invitations. A coach's invitation cannot make anyone an owner. +- Recovery uses the provider plus an owner recovery procedure the operator documents. + Recovery rotates sessions. + +### 6.3 Grants (D262) + +| Grant | Allowed | Excluded | +|---|---|---| +| Read workout summaries | List current workouts: record ID, revision, start and end, activity type. | Routes, descriptions, raw samples, source IDs, reports, attachments, extensions, full record JSON. | +| Add coach notes | Append a note with optional title. Evidence links only to revisions visible under the read grant. | Reading other notes, correction, deletion. | +| Add programming | Create plans and planned sessions with schedule and blocks. Link sessions only to plans this coach and app created for this athlete. | Personal records, completion flags, completed workout links, deletion, editing existing plans. | + +- Nothing is selected until the athlete approves. +- The owner keeps full reads, exports, corrections, imports, deletion, and erasure. +- Lists are filtered by grant before counting, sorting, and paging. Attachments, links, + evidence, and derived values follow the same rule. +- Errors, IDs, counts, and timing do not reveal another athlete's records. +- Caches are keyed to the grant version or not shared. +- Revocation raises the access epoch. A write ordered after it fails. Data already + delivered cannot be recalled. + +### 6.4 Writes and retries (D261) + +Example: a coach adds a note. + +1. The app sends `POST /v1/athletes/{id}/notes` with an `Idempotency-Key` header. +2. The host checks the token and the grant, and reads the access epoch. +3. The library commits the note, its first revision, the change-log row, and the receipt + in one transaction. The commit fails if the epoch changed. +4. The response has the record ID and revision. Repeating the request returns the same + result. The same key with a different body is a conflict. + +Corrections name the expected revision. A stale correction is refused, and the client +keeps the person's version for review. Imports keep the whole-database revision check +and an owner-only preview bound to the file digest and database revision. + +### 6.5 API version 1 + +Operations: host capabilities; owner connect, export, refresh, log, correct, import +preview and apply, delete, erase; grant list, create, and revoke; app list, disconnect, +and reconnect (D270); coach roster, workout summaries, note, and programming; +attachment upload and download link; move steps (D267). + +Stable error codes: expired sign-in, missing permission, disconnected app (D270), +unknown resource, stale revision, request-ID conflict, host moving, limit reached. + +The description is generated from the Rust definitions into `schema/host-api/1/`, and +`cargo test --test generated` checks it (D266). It is OpenAPI 3.1, built from the same +operation table as the router (D271). + +### 6.6 Device refresh (D263) + +1. The first connection downloads a verified full package. +2. Later refreshes ask for changes since the device's database revision. The host reads + `internal_change_log` and returns record revisions, deletions, and erasures in + order, with any new attachments. +3. Before applying, the device checks that its file still matches the manifest digest it + last verified. If not, it keeps the local file, downloads the hosted copy beside it, + and asks the owner. +4. The library applies the changes with revisions unchanged. Attachments are checked by + SHA-256. +5. The device computes the new manifest digest and compares it with the host's. +6. A gap or failure falls back to a full package. + +A managed app directory switches complete copies atomically. A file other programs may +open gets a verified sibling copy and a coordinated handoff. + +### 6.7 Moving between hosts (D267) + +| Step | Who accepts writes | On failure | +|---|---|---| +| Owner connects an empty destination. The source may pre-copy files. | Source | The destination cannot show the staged record. | +| Owner freezes the source. It finishes accepted work and signs its final manifest digest and transfer ID. | Neither | Before release, the owner can abort and reopen the source. | +| The destination verifies every file, restores privately, runs `ath check`, and reports ready. | Neither | Resume from the last verified step. Show which host is waiting. | +| The source retires its writer and records a single-use activation for this transfer, destination, and digest. The destination activates once. | Destination | A lost reply is retried with the same transfer ID. The source cannot reopen by itself. | +| The device reconnects and the owner reviews grants. | Destination | Keep an owner recovery copy until cleanup is confirmed. | + +A restore from a device copy when the source cannot be reached is a separate action. It +is labelled a recovered fork. + +### 6.8 Backups and restore (D264) + +- **Native:** Litestream for each athlete database. Attachment copies on upload. A + scheduled package export of each athlete to storage with separate credentials. The + host keeps connections open and avoids truncating checkpoints while Litestream runs. + The recipe is published after the test in step 8 passes. +- **Remote:** the provider's per-database restore, a copy of the attachment bucket, and + the same scheduled package export. +- **Every restore:** one athlete, isolated first, sessions invalidated, later erasures + and revocations replayed from ordered recovery records before serving. If those + records are missing, the restore waits for the owner. +- **Erasure:** the host records an erase intent before applying it, replays unfinished + intents after a failure, and applies erasure to staged copies. + +### 6.9 Security and trust (D264) + +- Whoever runs the host and its storage can read records. The connect screen names who + runs the host and the storage. +- TLS on every connection. Storage encryption at rest is the provider's or the + operator's. +- Per-athlete keys on the libSQL backend where the provider supports them. Keys come + from a key service the operator configures. They are never stored in the directory + database. +- Backup credentials are separate from the host's credentials. +- Logs hold no credentials, request bodies, or health values. + +### 6.10 Limits + +For each athlete: total and expanded upload bytes, page size, job duration, concurrent +jobs, and temporary disk. Uploads expire and can be cancelled. Jobs have opaque IDs, and +only the requester can read their results. A large job for one athlete must not delay a +small write for another. + +## 7. Clients (D266) + +- **npm:** a host client with an explicit host URL and token. Local behavior and + [REMOTE-TARGETS.md](../../packages/npm/REMOTE-TARGETS.md) do not change. +- **Swift:** an example client for macOS and the iOS simulator: sign-in, roster, read a + workout summary, add a note. +- **MCP:** a small server with `list_workout_summaries` and `add_coaching_note`. It acts + with the signed-in person's grants and uses MCP authorization. +- **Starter:** a JavaScript example app that does the same flow. + +## 8. Qualification suite (D258) + +A backend or provider is listed as supported after a named run of this suite passes: + +1. Migrations 001–007 run. STRICT tables, triggers, and foreign keys are enforced. A + dangling reference is refused on the remote connection. +2. The library's write tests pass on the backend: create, correction with stale + detection, deletion, erasure, import preview and apply, receipts. +3. Two writers correct the same record from the same revision. One conflicts. +4. With identical record IDs in two athletes' databases, neither athlete's request + reaches the other. Where the provider has database-scoped credentials, one athlete's + credential cannot open another's database. +5. An export from the backend equals a native export of the same content, byte for byte. +6. Restoring one database to an earlier moment leaves every other database unchanged. A + package restore onto a clean machine passes `ath check`. +7. A network drop during a transaction leaves no partial write. A retry with the same + request ID returns the original result. +8. Timings for a workout save, a 28-day evidence read, and an import of the + 100,000-record workload, with region, hardware, and crate versions. + +First runs: a local libSQL server in continuous integration, and Turso Cloud +libSQL-engine databases in a manual run. + +## 9. Verification + +Before any commit, the four checks in [AGENTS.md](../../AGENTS.md) pass. The build adds: + +- Host tests with two athletes, two coaches, two apps, revocation during a queued write, + and guessed IDs. +- The qualification suite against a local libSQL server. +- Fault tests: stop the process around a note commit, an attachment publication, an + import, each move step, and a restore. Disk full. Staging cleanup after restart. +- Scale runs with the 100,000- and 3-million-record workloads: peak memory, disk + high-water mark, first transfer, unchanged refresh, one-note refresh, and one-athlete + restore time. A small write for a second athlete completes during a large job. +- Regenerated files: `schema/2.1.3/`, `schema/athleticstandard.schema.json`, + `schema/host-api/1/`, `packages/npm/src/generated/protocol.ts`, + `skills/athletic-standard/references/cli.md`, and the demo database. + +## 10. Build order + +Each step ends in something a person can do. A screenshot, a mocked provider, or a +successful sign-in alone does not finish a step. + +| Step | Work | Done when | +|---|---|---| +| 1 | This plan, D254–D267, and the storage study. | Approved. | +| 2 | Version 2.1.3, migration 007, coach authorship. | A coach-authored note survives export and restore. A 2.1.2 program refuses the database. All existing tests pass. | +| 3 | Changeset capture in the library (D268). | A write recorded as a changeset and applied to an empty copy gives the same export, byte for byte. Every existing test passes with no change in CLI behavior. | +| 4 | The libSQL remote backend: working copies, guarded commits, the replication log, and the qualification suite. | The suite passes against a local libSQL server in continuous integration. | +| 5 | `ath-host` in native directory mode: owner connect, read, write with receipts, attachments, device refresh, restore. | An owner saves a report with a photo on one device and opens both on another. | +| 6 | Sign-in and grants: both recipes, three grants, access epoch, roster. | Two coaches, two apps, two athletes. A revocation during a queued write blocks it. | +| 7 | Remote mode with the object store, and several host copies. | Steps 5 and 6 pass in remote mode. A named run of the suite passes against one provider. | +| 8 | Moves and backups: the move protocol, the Litestream recipe, scheduled exports, restore drills. | A record moves native to remote and back. One athlete is restored without changing another. | +| 9 | Clients and guides: npm host client, Swift example, MCP server, starter, `docs/hosting.md`, container and setup guide. | A developer follows the guide from a clean checkout and completes the flow. | +| 10 | Scale and fault runs, release evidence. | The report lists which backends and providers passed and which clients ran. | + +## 11. References + +- [Storage options and how to choose](appendix/hosted-storage-options.md) +- [Hosting experiments](appendix/hosting-experiments.md) +- [Architecture](../../docs/architecture.md) · [Store](../../src/store/mod.rs) · + [Attachments](../../src/files/attachments.rs) · [Export](../../src/package/export.rs) · + [Restore](../../src/package/restore.rs) · [Erasure](../../src/package/erase.rs) +- [OAuth 2.0 for native apps (RFC 8252)](https://www.rfc-editor.org/rfc/rfc8252) · + [Protected resource metadata (RFC 9728)](https://www.rfc-editor.org/rfc/rfc9728) · + [MCP authorization](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization) +- [Turso Rust reference](https://docs.turso.tech/sdk/rust/reference) · + [Turso Cloud limitations](https://docs.turso.tech/cloud/limitations) · + [Litestream](https://litestream.io/guides/directory/) diff --git a/docs/architecture.md b/docs/architecture.md index 08778caa..52f266bc 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1,7 +1,7 @@ # Architecture -Athletic Standard is one Rust library and one `ath` executable. This document -names who owns each job and follows two ordinary operations from input to the +Athletic Standard is one Rust library, the `ath` executable, and the optional +`ath-host` program. This document names who owns each job and follows two ordinary operations from input to the database file. It describes the current code. Read `build-history/` for why a choice was made; read this to find where to change something. @@ -27,6 +27,8 @@ Paths below are relative to the repository root. | Limits on untrusted input | `src/input_policy.rs` | nothing | | Arguments, help, prompts, rendering | `src/cli/` | everything above | | The npm launcher, JavaScript client, and Zod compatibility facade | `packages/npm/` | the `ath` executable | +| Hosting many athletes' records: sign-in checks, grants, the HTTPS API, write receipts, working copies, attachment buckets | `host/` (`ath-host`) | the library with its `changesets` feature | +| The npm host connection (`connectHost`) | `packages/npm/src/host.ts` | the host API | Rules that keep this table true: @@ -40,6 +42,10 @@ Rules that keep this table true: arithmetic, or history rule. It parses, calls one library operation, and renders the result. - Local record commands never start a network client or a credential store. +- `host/` never writes record tables with its own SQL. It calls the library for + every record operation. In remote mode it sends the row changes the library + recorded (D268). [`hosting.md`](hosting.md) is the guide for operators and app + developers. ## The one record encoder diff --git a/docs/hosting.md b/docs/hosting.md new file mode 100644 index 00000000..2e20d664 --- /dev/null +++ b/docs/hosting.md @@ -0,0 +1,1171 @@ +# Hosting records with ath-host + +`ath-host` is an optional program that serves many athletes' records over HTTPS. An +athlete can let a coach read workout summaries and add notes and programming. Apps +reach the records through a versioned API. This guide is for people who run a host +and for people who write apps that call one. + +The guide describes the code in [`host/`](../host/) as it is now. Version 2.1.3 is +not finished. Where the [2.1.3 plan](../build-history/v2.1.3/spec.md) asks for +something the code does not do yet, the guide says so. The decisions behind the host +are D254–D268 in [decisions.md](../build-history/v2.1.3/decisions.md). + +## 1. What ath-host is and is not + +- **It is a separate program.** The `ath` command does not contain it and does not + need it. Local use needs no account, no network, and no host (D75, D254). +- **It keeps one database per athlete** (D256). Each one is an ordinary Athletic + Standard database, the same as a local `athlete.ath.sqlite`. A separate directory + database holds the people, records, invitations, and grants the host knows about. +- **It calls the Athletic Standard library for every record operation.** It has no + record rules of its own. The two-tier wall, revisions, deletion, and erasure work + as they do in `ath`. +- **It trusts one sign-in provider that the operator chooses** (D260). It has no + passwords or accounts of its own. +- **The project does not run a host.** It ships the program and this guide. Whoever + runs a host is responsible for it and for the records on it. +- **It is not in the release archives or the npm package.** Build it from source + (section 4.1), or build the container image (section 4.7). + +What is built today: + +| Part | State | +|---|---| +| Directory mode: one machine, records in a folder | Built and covered by tests. | +| Remote mode: databases on a libSQL server, attachments in an S3-compatible bucket | Built. Tested against a local stand-in for the server and the bucket. A test against a real libSQL server exists but has not been run (section 5.6). | +| Sign-in checks | Built. Tested with a fixed test key. The recipes in section 6 have not been run against live provider accounts. | +| Grants, revocation, coach notes, and programming | Built and covered by tests. | +| Moves between hosts (section 9) | Built and covered by tests between two hosts in directory mode. | +| `ath-host backup` and `ath-host restore` (section 10) | Built and covered by tests. `restore` works in directory mode only. | +| A Litestream recipe | Not published. It has not been run with the library (D264). | +| Clients: the npm host client `connectHost`, a starter app, and an example MCP server | Built. See section 7. | +| A generated description of the API in `schema/host-api/1/` (D266) | Not built. Section 7 is written from `host/src/api.rs` and `host/src/moves.rs`. | + +## 2. Choosing a backend + +The host keeps records in one of two ways, called backends: + +- **Directory mode** keeps each athlete's database and attachments in a folder on the + host's own disk. One host process owns the folder. +- **Remote mode** keeps each athlete's database on a server that speaks the libSQL + protocol, and attachments in an S3-compatible bucket. The host keeps only temporary + working copies, so several copies of the host can serve the same athletes. + +Answer these questions in order. Section 6 of the +[storage study](../build-history/v2.1.3/appendix/hosted-storage-options.md) gives +the facts behind each one. + +1. **Does anyone but the athlete need to reach the record?** If not, use `ath` with a + local file. You do not need a host. +2. **Will one disk hold every record you expect?** Estimate from the size of real + databases: the `.ath.sqlite` file and its `attachments/` folder. If one disk holds + them all, directory mode is the simplest choice. +3. **Do you need more than one copy of the host running at once, or no disk to + manage?** Use remote mode. Put the host and the database server in the same + region. Every request makes at least one network round trip to the server, and + every write makes several. +4. **Must every part run on machines you control?** Use directory mode, or remote + mode with a libSQL server you run yourself (section 5.3). The self-run server is + no longer actively released. +5. **Do you need each athlete's database locked with its own key?** Neither mode + offers this in the host yet. The plan allows it in remote mode where the provider + supports it (D264). +6. **Who can read the records?** Whoever runs the host and its storage. Write that in + `operator_disclosure` (section 3). + +No storage provider is listed as supported yet. A provider is listed only after a +named run of the qualification suite passes (D258, spec section 8). + +## 3. Configuration + +The host reads one JSON file, named with `--config`. The file never holds a secret. +Every field whose name ends in `_env` names an environment variable, and the host +reads the secret from that variable when it starts. A missing variable stops the host +with `the environment variable NAME is not set`. + +Unknown fields are refused. A misspelled field stops the host instead of being +ignored. + +### 3.1 Top-level fields + +| Field | Required | Meaning | +|---|---|---| +| `listen` | Yes | Address and port to listen on, such as `127.0.0.1:8080`. The host speaks plain HTTP. Put TLS in front of it (section 4.4). | +| `public_url` | Yes | The address clients use, such as `https://records.example.org`. The host publishes it as `resource` in its protected-resource metadata (section 6.4). | +| `data_directory` | Yes | The host's own folder. A relative path is read from the folder that holds the configuration file. In directory mode it holds every record. In remote mode it holds working copies and staged files. | +| `storage` | Yes | Where records live. An object whose `kind` is `directory`, `libsql`, or `local_server` (section 3.2). | +| `sign_in` | Yes | The sign-in provider (section 3.4). | +| `operator_disclosure` | Yes | Text shown to an athlete when they connect: who runs this host and who runs its storage (D264). The API returns it from `/v1/capabilities`, from `/v1/athletes/{id}`, and when a record is created. | +| `open_enrollment` | No, default `false` | When `true`, any signed-in person can create a record. When `false`, a person needs a code from `ath-host invite`. | +| `limits` | No | Size and time limits (section 3.5). Every field has a default. | + +### 3.2 `storage` + +**`"kind": "directory"`** has no other fields. Records live in +`data_directory/athletes/`. + +**`"kind": "libsql"`** keeps records on a libSQL server: + +| Field | Meaning | +|---|---| +| `url_template` | The address of one athlete's database, with `{database}` where the database name goes. The host fills in `ath-` and 32 hexadecimal characters, taken from the record's resource ID. | +| `directory_url` | The address of the host's directory database. It must exist before the host starts. | +| `token_env` | The variable that holds the access token for every database, the directory included. | +| `provision` | How a new athlete's database is created (section 3.3). | +| `attachments` | The S3-compatible bucket for attachment files (section 3.3). | + +**`"kind": "local_server"`** exists for the tests. Each athlete's "server" database +is a file in the folder named by `directory`, and `attachments` names a bucket. It +runs the same commit code as remote mode without a network. Do not use it to serve +athletes. + +### 3.3 `provision` and `attachments` + +`provision` is an object whose `kind` is one of: + +| `kind` | Other fields | What the host does for a new record | +|---|---|---| +| `existing` | None | Nothing. The database must already answer at its address (section 5.4). | +| `turso` | `organization`, `group`, `platform_token_env` | Asks Turso's Platform API to create the database in that organization and group. `platform_token_env` names the variable that holds a Platform API token (section 5.2). | +| `sqld_admin` | `admin_url` | Asks a self-run libSQL server to create the database as a namespace, through its admin address (section 5.3). | + +`attachments` describes an S3-compatible bucket: + +| Field | Meaning | +|---|---| +| `endpoint` | The bucket service's address, such as `https://ACCOUNT_ID.r2.cloudflarestorage.com`. A path in the address is kept as a prefix of every object address. | +| `bucket` | The bucket name. | +| `region` | The region name the service expects, such as `auto` or `eu-west-1`. | +| `access_key_env` | The variable that holds the access key ID. | +| `secret_key_env` | The variable that holds the secret key. | +| `path_style` | Default `true`: addresses of the form `endpoint/bucket/key`. Set `false` for addresses with the bucket in the host name. Section 5.5 lists the value for common services. | + +### 3.4 `sign_in` + +| Field | Required | Meaning | +|---|---|---| +| `issuer` | Yes | The provider's issuer, exactly as it appears in the `iss` claim of its tokens. | +| `audience` | Yes | The value the `aud` claim must contain. Use the same value as `public_url`, so clients that ask for a token for the host get one the host accepts. | +| `jwks_uri` | No | Where to read the provider's public signing keys. When absent, the host reads `jwks_uri` from `/.well-known/openid-configuration`. | +| `allowed_clients` | No, default empty | The client IDs of the apps the host accepts. When the list is empty, any app the provider issued a token to is accepted. Grants still name the app. | + +### 3.5 `limits` + +| Field | Default | Meaning | +|---|---|---| +| `body_bytes` | `67108864` (64 MiB) | The largest request body. It bounds package uploads and attachment uploads. | +| `page_size` | `200` | The largest number of items in one list response. Keep it at 10,000 or less: the library refuses longer record lists. | +| `working_copy_idle_seconds` | `900` | Remote mode: how long an unused working copy is kept before it is deleted. | + +### 3.6 Example: directory mode + +```json +{ + "listen": "127.0.0.1:8080", + "public_url": "https://records.example.org", + "data_directory": "/var/lib/ath-host", + "operator_disclosure": "This host is run by Example Rowing Club on a server the club manages. Records and their backups are stored on that server's disk.", + "open_enrollment": false, + "storage": { "kind": "directory" }, + "sign_in": { + "issuer": "https://sign-in.example.org/realms/athletes", + "audience": "https://records.example.org", + "allowed_clients": ["athlete-app", "coach-app"] + }, + "limits": { + "body_bytes": 67108864, + "page_size": 200, + "working_copy_idle_seconds": 900 + } +} +``` + +This file names no secret, so it needs no environment variables. + +### 3.7 Example: remote mode with an S3-compatible bucket + +```json +{ + "listen": "0.0.0.0:8080", + "public_url": "https://records.example.org", + "data_directory": "/var/lib/ath-host", + "operator_disclosure": "This host is run by Example Rowing Club. Records are stored in Turso Cloud databases, and attachment files in a Cloudflare R2 bucket.", + "open_enrollment": false, + "storage": { + "kind": "libsql", + "url_template": "libsql://{database}-example-org.turso.io", + "directory_url": "libsql://ath-host-directory-example-org.turso.io", + "token_env": "ATH_HOST_DATABASE_TOKEN", + "provision": { + "kind": "turso", + "organization": "example-org", + "group": "athletes", + "platform_token_env": "ATH_HOST_TURSO_PLATFORM_TOKEN" + }, + "attachments": { + "endpoint": "https://ACCOUNT_ID.r2.cloudflarestorage.com", + "bucket": "athlete-attachments", + "region": "auto", + "access_key_env": "ATH_HOST_BUCKET_ACCESS_KEY", + "secret_key_env": "ATH_HOST_BUCKET_SECRET_KEY", + "path_style": true + } + }, + "sign_in": { + "issuer": "https://example.authkit.app", + "audience": "https://records.example.org", + "jwks_uri": "https://example.authkit.app/oauth2/jwks", + "allowed_clients": [] + } +} +``` + +This file needs four environment variables: `ATH_HOST_DATABASE_TOKEN`, +`ATH_HOST_TURSO_PLATFORM_TOKEN`, `ATH_HOST_BUCKET_ACCESS_KEY`, and +`ATH_HOST_BUCKET_SECRET_KEY`. The names are your choice. The file only has to name +them. + +## 4. Running on one machine + +### 4.1 Build + +Install the Rust toolchain named in `rust-toolchain.toml`, then build from the +repository root: + +```sh +cargo build --release -p athleticstandard-host +``` + +The executable is `target/release/ath-host`. + +### 4.2 Commands + +```text +ath-host serve --config +ath-host setup --config --issuer --subject [--name ] +ath-host invite --config [--days ] +ath-host backup --config --output +ath-host restore --config --athlete --package +ath-host version +``` + +- `serve` runs the host until it receives an interrupt signal (SIGINT, or Ctrl-C). + It then stops taking connections and finishes open requests. SIGTERM ends it at + once, without finishing them, so configure your service manager to stop it with + SIGINT. When it starts, it deletes what the last process left: working copies, + staged uploads, and temporary export, package, and restore folders. It also + finishes any erasure that an earlier run noted but did not complete (section 10.4). + It then prints the address it listens on, with the real port when `listen` names + port 0. +- `setup` claims the first owner (section 4.5). +- `invite` makes an invitation code (section 4.6). +- `backup` writes each athlete's complete package as a zip (section 10.2). +- `restore` replaces one athlete's record from such a zip, in directory mode only + (section 10.3). +- `version` prints `ath-host 2.1.3`. + +`setup`, `invite`, and `backup` can run while the host serves. They do not delete the +host's working copies or staged files. In remote mode, give `backup` its own data +folder: copy the configuration file and change `data_directory`. `backup` builds a +working copy of every athlete in its data folder, and two processes must not share +one working copy. `restore` refuses to run while a host serves the data folder. + +### 4.3 The data folder + +In directory mode the data folder looks like this: + +```text +/.ath-host.lock held by the running host +/host.sqlite the directory: people, records, invitations, grants, settings, remembered answers, erasures +/athletes//athlete.ath.sqlite one athlete's database +/athletes//attachments/ that athlete's attachment files +/athletes/.replaced-