13 Commits

Author SHA1 Message Date
a017d0bc60 feat(console): Rithub self-serve provisioning + public landing page
Closes backlog item 4: Rithub (apps/gitea, live at git.ereboslab.com) had
zero discovery or signup surface. A signed-in Console session now
provisions a dedicated Gitea user, private org and first repo in one call
(lib/gitea.ts, admin API with sudo= impersonation), via a new public
/rithub landing page and POST /api/v1/rithub/provision route. Signed out,
the CTA goes through the same cross-sell sign-in bridge as items 1/2;
signed in, it closes the loop item 5's OIDC provider opened ("one sign-in,
not a second account").

Verified against a real gitea/gitea:1.23 container: user/org/repo creation,
sudo impersonation, slug-collision retries and the route's idempotency
check all confirmed live. tsc clean, npm test 167/167, npm run test:bundle
3/3 (including a full client build).
2026-10-24 00:45:01 +03:00
977520fc00 feat(console): Mint billing accounts, OIDC SSO for Rithub, Relay vs. OpenRouter page
- Apps tab: one-click Mint ledger account per app (POST /v1/accounts
  already existed on Mint; the gap was the UI), db/migrations/0012.
- Console is now a real OIDC provider for Rithub (Gitea) SSO: RS256
  id_token + self-contained access_token over the authorization-code
  grant, single-use codes (db/migrations/0013), discovery/jwks/
  authorize/token/userinfo routes. A visitor who isn't signed in yet
  is bounced through existing sign-in and lands back on /oidc/authorize
  automatically. Gated on RAILYARD_OIDC_SIGNING_KEY/RAILYARD_OIDC_CLIENTS
  (scripts/gen-oidc-key.mjs generates the former); unset, every /oidc/*
  route is a clean 503.
- Public, numbers-backed /compare/relay-vs-openrouter page with a
  spend-tier pricing table and a Console-signup CTA using the existing
  cross-sell attribution bridge.

Verified: tsc clean, full `npm test` (167) and `npm run test:bundle`
(3) green; a scratch script exercised the OIDC code/token/userinfo
flow end to end against real generated RSA keys (found and fixed a
missing email_verified claim); `next dev` used to curl every new
route live (discovery, jwks, authorize's 400s and sign-in detour,
token validation, userinfo auth, the comparison page, the mint-account
API).
2026-10-23 16:52:45 +03:00
bfb052c74e fix(gitea): deploy Rithub to production, point the Nav Code link back at it
Rithub (apps/gitea) was proven locally on 2026-10-15 but never shipped, so
the Nav's "Code" link 404'd and an earlier fix (b16fd286) papered over it by
pointing at the public GitHub mirror instead. Deployed it for real:

- docker compose stack live on railyard-box (/srv/railyard-gitea): web on
  host port 3350, Postgres on 5434 (3300/3400/3100/5433 were already taken
  by rago/mint/relay/the shared Postgres), admin account created.
- Fronted by Caddy (infra-box/caddy/sites/gitea.caddy, CADDY_SITES += gitea)
  with a Let's Encrypt cert, not the Cloudflare Tunnel the original RUNBOOK
  draft proposed -- every other box service (rago/relay/mint/errors) already
  uses plain Caddy + a proxied Cloudflare DNS A record, so this follows that
  proven pattern instead of a new one.
- DNS: git.ereboslab.com -> 130.61.113.116 (not git.railyard.ereboslab.com --
  no other service here uses a "railyard." prefix; corrected throughout
  apps/gitea's docs and defaults).
- Verified live: https://git.ereboslab.com/ 200s, title "Rithub (by
  Railyard)", logo/branding assets 200.

Nav.tsx/config.ts default back to the real URL; RAILYARD_GIT_URL still
overrides it. SSH-over-2222 still needs the one OCI security list rule
(owner step, documented in deploy/RUNBOOK.md) -- HTTPS clone/push and the
web UI work today without it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 23:32:58 +03:00
b16fd286b4 fix(console): point the Nav Code link at the live GitHub repo, not a dead subdomain
apps/gitea (Rithub) was proven locally on 2026-10-15 but never shipped to
railyard-box: no gitea container/env on the box, no DNS for
git.railyard.ereboslab.com, and the box-tunnel TUNNEL_TOKEN that would
publish it is still blank. The Nav's "Code" link has been pointing there
since 97827bb4/8d3ab266, so it 404s for every console user.

caelum0x/railyard is public now (README/LICENSE/CONTRIBUTING shipped for
OSS distribution), so point the default at that real, live repo instead.
RAILYARD_GIT_URL still overrides it once apps/gitea actually deploys.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 13:45:14 +03:00
8d3ab26668 feat(console): link the Nav to Railyard's code hosting (Rithub/Gitea)
Adds Config.gitUrl (RAILYARD_GIT_URL, default
https://git.railyard.ereboslab.com) and a "Code" entry in the main Nav —
an external link, since apps/gitea runs native accounts (no Railyard
session/SSO integration yet, see apps/gitea's TODO(railyard-sso)).

Verified: npm run typecheck clean, npm test 159/159 (was 159 baseline, no
new test count change — the existing Nav.tsx copy-lint test covers the new
link text).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 03:13:22 +03:00
f4486bda26 feat(flags): targeting by property, cohort or segment and % rollouts on a stable hash (QY1.3, I10, A19)
- packages/openfeature-railyard/src/targeting.mjs: one dependency-free
  evaluator (sync SHA-1, rollout hash = parseInt(sha1("<flag>.<id>")[0:15])
  / 0xfffffffffffffff, inside when <= rollout/100; ordered rules, all
  conditions of a rule must match, first match wins with its own value).
  Property operators follow the reference matcher of posthog-node (MIT):
  exact/is_not (lists, true/false by truthiness), icontains, regex, gt/gte/
  lt/lte (numeric, else text), is_set/is_not_set. Segments are named sets of
  property conditions per environment (Flagsmith segment shape, BSD-3);
  cohorts are product analytics cohort ids. Byte copies with .d.mts types in
  apps/console/lib/flags and apps/product-analytics/src/flags (drift test).
- Console: rules and segments live in Railyard's store for both backends
  (migration 0009: railyard.flag_targeting, railyard.flag_segments, bounded
  checks, cascade, RLS, no anon), so the table fallback and the Flagsmith
  backend have the same rule features. setFlag validates rules and segment
  references; a used segment cannot be removed; branches copy rules and
  segments. The read endpoint takes ?id, ?props (JSON, 2 KB) and ?cohorts,
  answers each flag for that person and ships {on, value, rules} plus the
  segments used, so SDKs evaluate locally; without a person a targeted flag
  reads off (old clients stay safe). Flags screen: rules per flag (everyone,
  a property, a segment; cohorts only with RAILYARD_REPLAY_LIVE) with a
  share, and segments. POST /api/flags/segments.
- Product analytics /flags: evaluates targeted flags with the person's
  stored properties (request person_properties override) and cohort
  membership (through person overrides).
- OpenFeature providers and the client: evaluation context targetingKey +
  attributes (+ cohorts) resolve per person; cached starts keep rules.
- Contract fixture: flags items carry targeting (additive, version 2).

Tests
- openfeature 16/16: SHA-1 vs node crypto, rollout shares within bounds
  over 10 000 ids and monotonic growth, operators, rules, validation, read
  answer, client and both providers vs the evaluator, cached start, drift.
- console 142/142 incl. both backends with the same 20 rule sets, segments,
  isolation, read-endpoint context, 0009 migration on a scratch PG, and
  10 000 ids x 20 rule sets: provider local == read endpoint (0 mismatches).
- product analytics test/qy 10/10 incl. 10 000 ids x 20 rule sets: provider
  local == /flags from stored people and cohorts (0 mismatches), and the
  unmodified posthog-node local evaluation agreeing on all 18 non-cohort
  sets for 10 000 ids (0 mismatches, 0 undecided); a3 experiments unchanged.
- contract 6/6; console and PA tsc clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:09:54 +03:00
cbadc84dd5 merge: product analytics (A1-A3) into main after Wave P3
# Conflicts:
#	apps/console/components/Nav.tsx
2026-09-30 09:19:37 +03:00
ea3199891b feat(console): product analytics screens (events feed, first-event proof, people, setup, privacy) and one nav line (A1)
The console signs a 5-minute HS256 org token with WebCrypto (no new
dependency) and reads the service; screens refresh every 10 seconds while
live, show capMessage at the cap, export a person as JSON and request a
deletion that stays visible until done. Copy passes the vendored denylist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 03:58:54 +03:00
5ccd834941 feat(watch): uptime checks with a public status page per app and owner email through Rally Send (PY2.2)
RYP-E4, dispatch 4.2 PY2.2 (Railyard side):
- lib/watch: checks (public https app addresses only; IPs, private names and
  our own hosts refused), 20 per org, a status page slug each. The box 1
  agent reads GET /api/v1/watch/agent/checks (ids and URLs only, bearer
  WATCH_AGENT_TOKEN) and posts results to /api/v1/watch/agent/results.
  Two failures in a row turn a check red; each change emails the owner once
  through Rally Send (product railyard, from status@, idempotency key per
  change; a failed send is retried on the next result). Older, unknown and
  future results change nothing.
- /status/<slug>: live results only (state, share of the last checks, bars),
  the check's name and never its address or any host or vendor name.
- The Watch screen: add by address, pause or resume, open the status page.
- Bridge route uptime (contract cases, uptime_check_keys): a check for the
  given address, or the app's latest live deploy; the first result is the
  slot's proof (check_result).
- Gated on RAILYARD_WATCH_LIVE (denylist rule railyard-slot-watch): off, no
  check runs, the pages 404, the nav has no Watch item and the slot answers
  arriving. The copy test lints each gated surface with the flag and proves it
  checks the flag first.
- Migration 0006 (watch_checks, watch_status; https only, history capped at
  90, cascades with the org).

Tests: watch 10/10, bridge 25/25, contract 3/3, migration 7/7 (0006 twice on a
scratch cluster), watch copy 7/7, console 108/108 with the bundle build,
tsc clean, SDK 7/7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 00:24:06 +03:00
332446652a feat(flags): Railyard Flags behind the add-on, the Flags screen and the OpenFeature SDK (PY2.1)
RYP-E2 and SP-E6, dispatch 4.2 PY2.1 (Railyard side):
- lib/flags: flag environments per app environment (a Scribase environment
  or branch), each with a public client key that reads that one environment.
  Two backends, one surface: the unmodified Flagsmith server (one Flagsmith
  organisation per Railyard org, a project per app, an environment per env;
  FLAGS_API_URL + FLAGS_ADMIN_TOKEN) and, as the fallback the dispatch names
  when the box 2 gate keeps Flagsmith down, the console's own tables
  (migration 0005). An environment keeps the backend it was made on.
- A branch environment starts with its parent's flags (copy_from), then
  changes alone.
- GET /api/v1/flags/client?key=: CORS-open, cached 15 s when keyed by URL;
  the first read by an app is the slot's proof (first_flag_read).
- Bridge route flags (contract: id_format, three cases, flags_item_keys);
  BRIDGE_SLOTS.flags landed.
- The Flags screen (nav item) flips with one click and adds a flag by key;
  POST /api/flags writes only the signed-in org's environments.
- packages/openfeature-railyard: a zero-dependency polling client (30 s,
  offline start from storage, back-off) and OpenFeature client and server
  providers, with Expo and Next.js examples.

Tests: flags core 11/11 (both backends, a fake of the Flagsmith API, tenant
isolation, branch copies, a 502 that leaves nothing half made), bridge 19/19,
contract 3/3, migration 6/6 (0005 twice on a scratch cluster), console 85/85
with the bundle build, tsc clean, SDK 7/7 (a flip reaches the app within 60 s
in the worst cache timing on a fake clock; copy lint on docs and the screen).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:58:12 +03:00
1bc04fa81b feat(insights): the Insights fork behind the add-on, site entries, tenant summaries, caps that say what happens (PY1.3)
Railyard side of PY1.3 (RYP-D2, RYP-E1, SC-E3). Acceptance:
1. apps/insights: umami-software/umami v3.4.0 (MIT, commit ec0ff503),
   vendored --depth 1, LICENSE kept, NOTICE added. Fork additions only:
   src/railyard/{ingest,summary,tenancy,api-only}.ts, /v1/ingest/batch (the
   edge collector contract v1, bearer INSIGHTS_INGEST_TOKEN, no IP ever,
   retried batches de-duplicated by migration 90_railyard_ingest_receipts),
   /api/v1/tenants/{org}/summary (bearer INSIGHTS_API_TOKEN), src/proxy.ts
   (INSIGHTS_API_ONLY=1 serves only the Railyard API and the heartbeat).
   Tenant isolation is tested at the API level (an app id owned by another org
   is refused) and at the SQL level (upstream migrations 01-26 plus 90 on a
   throwaway cluster: org B never reads org A's rows, even naming its app).
   Upstream vitest suite: not run on the Mac (pnpm 12.3.4 pinned upstream,
   disk floor); it runs in the image build on box 2 or CI.
2. No upstream product name in anything a customer loads: the page tag, the
   console pages and the fork's additions (tests); the upstream dashboard is
   never served in API-only mode.
3. The console writes the collector's site entry on "Add app", on
   auto-created apps from deploys, and rewrites every entry on add-on, plan or
   pause changes (lib/sites.ts, SITES KV binding). The bridge gains
   `sites` (the project's app, site key, page tag and collector URLs, entry
   written) and the analytics proof is the first event from Insights. The
   console's Insights page shows visitors, events, first event and the
   visit -> signup -> first action funnel.
5. insights-edge/src/caps.ts: at 100% of the cap events are still counted and
   not stored until the next UTC month; the console shows the same message
   from a byte-identical copy (lib/caps.ts, tested).
4 (384 MB at 50 events a second for 10 min) is measured on staging before deploy.

Env: INSIGHTS_API_URL, INSIGHTS_API_TOKEN, SITES KV binding (console);
INSIGHTS_INGEST_TOKEN, INSIGHTS_API_TOKEN, INSIGHTS_API_ONLY (Insights).

Tests: console 54/54 (tsc clean), insights fork 7/7 (incl. SQL isolation),
insights-edge caps + collector + sim 14/14, tests/contract 3/3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:23:38 +03:00
f919636b62 fix(console): one trial per org, no second subscription, refunds and stale subscription events
Wave E verifier (Y-2/Y-3):
- A card check started a fresh 14-day trial every time: cancel or refund,
  pay $1 again (credited back) and get another trial, for $0 net. The
  trial now starts only when trial_ends_at is unset; refunds keep it set
  and a paid plan marks it used. access() sends a card-on-file org that
  used its trial to the plan, and the Billing screen says so.
- startCheckout opened a second plan checkout for an already subscribed
  (or cancelling) org, which bills twice; and a second card check for an
  org with a card on file. Both are refused (BillingError, ?error=already).
- A refund of an older card-check payment kept its dollar credit, and a
  second refund event for the same payment could take it back twice. The
  debit now always applies once per payment, tracked in billing_events.
- subscription.* events of a subscription that is not the org's current
  one (an old one expiring) no longer end or pause the current plan.
- Deploy records normalise the app name the CLI sends (folder 'My Shop'
  -> my-shop) so the second deploy is not a 409; rollback_of must be a
  uuid (was a database error).
Tests: 7 new (fail before, pass after); console 37/37, tsc clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:50:14 +03:00
247e860a16 feat(console): Railyard console with Scribase sign-in and the Dodo test-mode money ladder (RYP-D1, Y-2)
Next.js console for Cloudflare Workers (OpenNext config, wrangler.jsonc)
with data in the console's own Scribase project, schema railyard
(migration 0001: orgs, org_members, apps, deploys, entitlements,
billing_events, api_tokens, device_codes; idempotent, RLS on, no anon
grants).

- Sign-in with Google or GitHub through Scribase Auth (PKCE), user read
  from the auth server, org and entitlements row created, signed
  HttpOnly session.
- Money ladder (pure, immutable): $1 card check credited back to the
  customer wallet, 14-day trial with the plan's limits, $19 a month or
  $190 a year, pause switch and one-click cancel (ends at the next
  billing date; a trial ends now).
- Webhook: Standard Webhooks signature and timestamp verified, replays
  ignored by unique message id, signed checkout metadata, other brands
  ignored, a refund of the card check reverses the credit and the
  trial, a failed wallet call releases the id for the provider's retry.
- Apps, Usage and Billing screens, one primary action each; Add app
  shows the deploy command and the Insights tag in two clicks.
- CLI device-flow login and org-scoped hashed tokens for Y-3.
- Test mode only: the live payment host is refused unless the owner
  sets RAILYARD_DODO_LIVE=1.

Tests (node --test, 25): journey from sign-in to entitlements and the
snippet, refund, pause and cancel, webhook security, ladder, tokens and
org isolation, PostgREST repo, a component test of Add app with the copy
lint, a next build grep for sentinel secrets in the client bundle, and
the migration applied twice on a scratch Postgres.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:35:24 +03:00