164 lines
10 KiB
Markdown
164 lines
10 KiB
Markdown
# AGENTS.md — Keysat workspace
|
||
|
||
Self-hosted, Bitcoin-native software licensing service running as a StartOS 0.4.x
|
||
package, with four wire-compatible SDKs and a public landing/docs site.
|
||
|
||
This file holds whole-repo, every-session facts. Subsystem detail lives in scoped
|
||
guides under `docs/guides/` (symlinked to `.claude/rules/` so Claude Code
|
||
auto-loads each when you edit matching files). **Before editing a subsystem, read
|
||
its guide** — see the index below.
|
||
|
||
## Stack
|
||
|
||
- **Daemon**: Rust 1.88, `axum`, `sqlx` + SQLite, Ed25519 signing.
|
||
- **Wrapper**: TypeScript, `@start9labs/start-sdk ^1.3.2`, `@vercel/ncc` bundle, Node 22.
|
||
- **SDKs**: TS (npm), Rust (crates.io), Python (PyPI), Go (proxy.golang.org).
|
||
- **Platform**: StartOS 0.4.0.x (LXC under the hood — commands/paths reflect that, not Docker).
|
||
- **Payment providers**: BTCPay Server (required dep); Zaprite (optional, gated by `zaprite_payments`).
|
||
|
||
## Subsystem guides (read before editing the area)
|
||
|
||
- Before editing the daemon source, read `docs/guides/daemon-architecture.md`.
|
||
- Before editing payment / provider / merchant-profile code or migrations 0020–0022, read `docs/guides/payments.md`.
|
||
- Before touching self-license or tier-gating code, read `docs/guides/licensing-tiers.md`.
|
||
- Before changing the LIC1 wire format, crypto, or crosscheck fixtures, read `docs/guides/crypto-wire-format.md`.
|
||
- Before building, bumping the version, or editing the StartOS wrapper, read `docs/guides/startos-packaging.md`.
|
||
- Before editing the admin SPA (`web/index.html`), read `docs/guides/admin-ui.md`.
|
||
- Before editing public site/docs copy, read `docs/guides/website-copy.md`.
|
||
- **Before building or changing any user-facing UI (landing, docs, admin SPA), read `design/DESIGN.md` and `design/tokens.tokens.json` and conform to them** — the brand contract; pull colors/type/space/radii/shadows from the tokens, never hardcode off-scale values.
|
||
- Before adding/altering tests or relying on lint/CI, read `docs/guides/testing.md`.
|
||
|
||
## Build / test / run (quick ref)
|
||
|
||
From `licensing-service-startos/`: `make x86` | `make arm` | `make universal` |
|
||
`make install` | `make clean` | `npm run check`. From
|
||
`licensing-service-startos/licensing-service/`: `cargo check` | `cargo build
|
||
--release` | `cargo test` | `cargo test --test <suite>` | `cargo test <name>`.
|
||
Details, the version-bump-before-build rule, and release scripts:
|
||
`docs/guides/startos-packaging.md`. Test suites, the no-CI / formatting-not-enforced
|
||
status, and known-failing tests: `docs/guides/testing.md`.
|
||
|
||
## Directory layout
|
||
|
||
```
|
||
licensing-service-startos/ daemon + StartOS wrapper (s9pk package source)
|
||
licensing-service/src/ Rust daemon → guides/daemon-architecture.md
|
||
licensing-service/migrations/ SQLite migrations (numbered, additive)
|
||
licensing-service/web/index.html embedded admin SPA → guides/admin-ui.md
|
||
licensing-service/tests/ integration suites → guides/testing.md
|
||
startos/ wrapper TS → guides/startos-packaging.md
|
||
Dockerfile Makefile s9pk.mk build pipeline
|
||
keysat-xyz-landing/ keysat-docs/ keysat-registry-landing/ public sites → guides/website-copy.md
|
||
licensing-client-{rust,ts,python,go}/ the four SDK source repos
|
||
activate-license-template/ Tauri desktop template for license activation
|
||
design/ design contract (DESIGN.md + tokens.tokens.json) + brand/ assets; original Claude Design system archived in design/_imports/
|
||
plans/ design specs (multi-provider-payment-model.md, keysat-smtp-emails.md)
|
||
tests/crosscheck/ cross-language LIC1 verifier → guides/crypto-wire-format.md
|
||
```
|
||
|
||
Note: the daemon (`licensing-service-startos`, repo `keysat`), each SDK, and
|
||
`plans/` are **separate git repos** — commit code/plan changes in their own repo.
|
||
The root `Licensing` repo (`keysat-root`) tracks only `AGENTS.md` + `docs/guides/`
|
||
+ `.claude/rules/` + `EVALUATION.md` (the latest full-eval report; overwritten
|
||
each run, history in git log). **Remotes differ per repo**: the daemon's `main` tracks
|
||
**GitHub** (`origin`, the public upstream) with a `gitea` backup — plain `git push`
|
||
goes to GitHub, so also `git push gitea main`; root + plans are **Gitea-only**.
|
||
Run `git remote -v` (full) and check what the branch tracks before pushing.
|
||
|
||
## Conventions (whole-repo)
|
||
|
||
- Daemon licensed `LicenseRef-Keysat-1.0` (custom, source-available); SDKs MIT.
|
||
- Commits in imperative mood, body only when the "why" isn't obvious. **Sign as
|
||
Keysat (Grant), not Claude** — git user is `Keysat`.
|
||
- Direct push to `main` + run `~/.keysat/publish.sh` is the authorized release flow
|
||
until launch.
|
||
- Never rewrite user-facing copy outside the explicit scope of a request.
|
||
|
||
## Never
|
||
|
||
- **No AI co-authorship** on commits or PRs (no "Co-Authored-By", no "Generated with…").
|
||
- **Don't push `--no-verify`** or bypass hooks unless explicitly authorized.
|
||
- **Don't commit built artifacts** (`*.s9pk`, `keysat-*.s9pk`, `javascript/`) or
|
||
**secrets** — reference env-var names; real values live in `~/.keysat/filebrowser.env`
|
||
and `/data/keysat-license.txt` outside the repo.
|
||
|
||
## Memory references
|
||
|
||
Operator-specific memories at `~/.claude/projects/-Users-macpro-Projects-keysat/memory/`
|
||
(scan before a major change): `keysat_release_workflow.md`,
|
||
`no_unauthorized_copy_changes.md`, `keysat_admin_ui_pill_convention.md`,
|
||
`startos_lxc.md`, `startos_registry_icon_unrenderable.md`, `keysat_open_threads.md`.
|
||
|
||
## Open TODOs
|
||
|
||
- `riscv` build target is unverified and not declared in the manifest (so
|
||
`make universal` excludes it); revisit only if a riscv StartOS target appears.
|
||
- StartOS Community Registry submission criteria — Start9 hasn't published the
|
||
checklist; reach out directly when ready.
|
||
- Registry icon doesn't render in the StartOS marketplace (see `guides/startos-packaging.md`).
|
||
- Split `audit:read` out of the blanket `:read` scope into its own tier so a
|
||
Read-only scoped key can read dashboards/licenses but NOT the full audit log
|
||
(`api/api_keys.rs::Role::grants`). Deferred from the scoped-keys session.
|
||
- **Operator action (manual; needs the master admin key — a read-only key can't
|
||
write):** grant `unlimited_merchant_profiles` to the **Pro and Patron** tiers on
|
||
the live master. Confirmed 2026-06-16 against `licensing.keysat.xyz` that the slug
|
||
is absent from all three keysat policies (Creator/Pro/Patron), from the master's
|
||
own Patron self-license, and from the product `entitlements_catalog`. Steps: add
|
||
the slug to the keysat product `entitlements_catalog`, then to the Pro + Patron
|
||
policy entitlements (admin UI), then re-issue the master self-license so it takes
|
||
effect.
|
||
|
||
## Current state (2026-06-16)
|
||
|
||
- **Live (registry/canonical)**: `registry.keysat.xyz` + `files.keysat.xyz/keysat.s9pk`
|
||
publish **`0.2.0:57`** — universal multi-arch (x86_64 + aarch64), GitHub release
|
||
`v0.2.0-57`. Migrations 0020–0023; four SDKs published; `keysat.xyz` +
|
||
`docs.keysat.xyz` deployed.
|
||
- **Live server `immense-voyage.local` still runs `:56`** — `:57` shipped to the registry
|
||
this session, but the box wasn't redeployed (that publish run predated this session's
|
||
change adding `make install` as `publish.sh` step 5). Run `make install` from
|
||
`licensing-service-startos/` once to catch the box up to `:57`; future `publish.sh` runs
|
||
now deploy to the live host automatically (best-effort, non-fatal).
|
||
- **Shipped this session as `:57`** (feature `d5885d1`, bump `069cf1e`; pushed
|
||
origin+gitea) — **`merchant-onboard` scoped-key role** for least-privilege self-serve
|
||
onboarding: read + `products:write` + `policies:write` + `licenses:write` (create
|
||
product → define policies/tiers → issue licenses, no master key). New `Role` variant
|
||
only — the catalog write scopes already existed and were enforced since `:55`;
|
||
`grants()` matches scope strings explicitly (never `:write` suffix) so it can't widen
|
||
into settings/payment/profile/webhook writes, and every master-only op stays behind
|
||
`require_admin`. Migration 0023 widens the `scoped_api_keys` role CHECK (no FKs → plain
|
||
rebuild). **Caveat**: covers catalog + manual issuance fully, but payment-provider
|
||
connect stays master-only, so buyer-paid purchase still needs a one-time operator step.
|
||
See `src/api/api_keys.rs`.
|
||
|
||
- **Work queue (next, in order)**:
|
||
1. Deploy `:57` to `immense-voyage.local` (`make install`) when ready.
|
||
2. Operator data action (needs master key): grant `unlimited_merchant_profiles` to
|
||
Pro/Patron on the live master (see Open TODOs).
|
||
3. 3 remaining multi-profile UIs (rail picker, per-profile SMTP, rail-pref editor) —
|
||
see ROADMAP.
|
||
4. Split `audit:read` out of the blanket `:read` scope into its own tier (Open TODOs).
|
||
|
||
- **P2 (unfixed, deferred pending user's call)**: `set_product_entitlements_catalog`
|
||
has no `rows_affected` guard — a bad product-id silently 200s with stale data (latent
|
||
since migration 0014; the new profile writer guards this correctly); no rate-limit on
|
||
`/v1/purchase`+`/v1/redeem` (bucket keys on spoofable `X-Forwarded-For`); `422`/`415`
|
||
return plain-text not JSON (breaks SDK `JSON.parse`); product `slug` unvalidated;
|
||
`GET /v1/admin/products` 405 vs OpenAPI; dep advisories (`sqlx`→≥0.8.1
|
||
RUSTSEC-2024-0363, `rustls-webpki`→≥0.103.12); no CI, fmt/clippy/prettier unenforced.
|
||
|
||
- **P3+ (bulk or later decision)**: `/v1/purchase` 400 vs `/v1/btcpay/webhook` 503 for
|
||
the same no-provider cause; undocumented required `kind` on discount-codes;
|
||
field-naming drift (`license_id`/`id`, machines `key` vs `license_key`,
|
||
`redeem`/`purchase` `product` vs `validate` `product_slug`); migration
|
||
`_sqlx_migrations` allowlist foot-gun; 2 KB unauth Zaprite payload WARN-log;
|
||
outbound-webhook SSRF (operator-only); re-register master Zaprite webhook at the
|
||
path-keyed URL; registry icon non-render (platform limit); design-contract conformance
|
||
(see ROADMAP); optional fmt/prettier standalone commit.
|
||
|
||
- **Tests/build**: `cargo check` + `npm run check` (tsc) clean (1 intentional
|
||
deprecation warning); full suite green — unit 10, api **57** (incl. the
|
||
merchant-onboard onboard-chain + master-only-denial test), subscriptions 7, upgrades 9,
|
||
worker 3, crosscheck 4, migrations 9 (through 0023). No new clippy warnings. FK
|
||
enforcement confirmed — sqlx pool sets `foreign_keys(true)` per connection.
|