18 Commits
Author SHA1 Message Date
CatoandClaude Opus 5.5 a6d33c92dd perf(ci): main does not re-verify a tree its pull request already verified (#1298)
CI runs verify on a PR and again on main before deploying. When the base did
not move while the PR was open, the squash commit's tree is byte-for-byte the
tree the PR's CI tested (refs/pull/N/merge) — 18 of 30 recent merges. The PR
job now records the tree it verified as an artifact (verified-tree-<sha>),
for PRs from this repository only; main looks HEAD's tree up and skips the
Verify step on an exact match. Build, smoke tests and the artifact CD ships
still run. Any doubt — no match, an API error, a fork, unreadable output —
means verify runs as before; the script always exits 0.

9 tests run the real script against a fake gh/git, including every
fail-safe path; mutation-proved (dropping the same-repository filter fails).
Fields checked against the live artifacts API.


Claude-Session: https://claude.ai/code/session_01Nx1u7uUWsgi3MagxbmQmPN

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 09:03:02 -07:00
Cato 14fd09774f fix(ci): pass repo to CD live-sha guard (#1123) 2026-09-23 08:45:46 -07:00
Cato baa5af1f4e fix(ci): authenticate CD live-sha guard (#1122) 2026-09-23 15:25:04 +00:00
Cato 2444f16586 fix(ci): route deploys through one verified handoff (#1121) 2026-09-23 08:03:42 -07:00
Cato 10bd7ef099 fix(ci): reuse verified bundle and skip duplicate deploys (#1115) 2026-09-23 02:42:03 -07:00
5c909fd8dd ci: fail when a uses: points at a redirect, so there is no third time (#803)
Twice in two days an owner change stopped every merge and every deploy
in this repo: `maonakamoto` → `catomean` on 2026-08-26, then the move to
the `bitbaum` org, fixed in #800. Each fix pointed at a name that became
a redirect the next time.

Both outages were invisible in every place anyone looks. GitHub redirects
a renamed owner for the REST API and for git remotes, so `gh api` answers
and `git push` works; the Actions resolver is the one consumer that does
not follow the redirect. It fails before any step exists, with "This run
likely failed because of a workflow file issue" and no readable log,
while pull requests stay green, clean and mergeable. The red run is on
main, under a workflow nobody opens. Work simply stops shipping.

Two instances is where the rule says stop fixing instances. This asks the
REST API what each referenced repo is really called and fails when that
disagrees with what the workflow says — that disagreement IS the bug,
because REST resolves the redirect and Actions does not.

A static allowlist could not catch it: after a rename the workflow file
and the allowlist would both hold the same stale name and agree with each
other. Only asking GitHub what the repo is called today can tell.

Lives in CI rather than in `npm run verify`, which is the offline SSOT
bundle and must stay deterministic; without a token this skips rather
than passing quietly. A non-200 that is not a 404 exits 2 — could-not-look
is never reported as looks-fine.

Proven by mutation: restoring `catomean/dotfiles` fails with the
canonical name to use. Also fixes the last CLAUDE.md reference to the
2026-08-26 owner.


Claude-Session: https://claude.ai/code/session_012dpTLxh5GJWeWTF1UEvcD5

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-28 07:40:48 +00:00
b9fb22114a chore(sites): remove hosted sites — OrangeCat is not the host (#785)
I built this on a wrong premise: that <name>.orangecat.ch means membership in
OrangeCat. It does not. It is an address on a domain George happens to own,
which is why petvity has a site and no profile, and why sinktattoo moved to its
own domain without moving a line of code.

Every site in this studio is its own repository from birth — aslan-tattoo,
kivvi, vitareba, petvity, botsmann, all of them. That is not an accident of
history, it is the property that makes a site handover-able, and a site that
lives inside this codebase can never be handed to anyone. Substrata was the only
violation, and it was mine.

Removed: the group_features 'site' feature, the profile-site renderer, the
positional host resolution and its reserved-subdomain list, the publish API, the
tls-check endpoint, the catch-all Caddy block, and Substrata's configs. Substrata
moves to its own repository, with its own design system — it currently renders in
OrangeCat's tokens and OrangeCat's orange, which is the visible form of the same
mistake.

The RLS policy needs its own DROP: deleting a migration file does not undo a
policy that already ran on production, and an anonymous SELECT grant is not
something to leave behind because nothing writes that row any more.

Kept, because they were never about hosted sites:
  - rateLimitDomainSearch — /api/v1/domains still fans one request out to 24
    registry lookups for an anonymous caller
  - the bounded RDAP result cache, keyed by caller input in a process that runs
    for weeks
  - clientIp(), collapsing the third copy of the x-forwarded-for read
  - the CodeQL fix for the URL substring test
  - type-check:scripts, which is why scripts/ is type-checked at all

verify green: 244 suites, 2406 tests.

Co-authored-by: Mao Nakamoto <georgy.butaev@revamp-it.ch>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 12:13:30 +00:00
370ccce976 feat(sites): make publishing a website a row, not a deploy (#783)
* feat(groups): a trading company whose whole book is singularity materials

Substrate Materials is a company profile with exactly one focus: the
physical inputs a technological singularity actually consumes. Software
is not the constraint — purified tin, neon, polysilicon, ruthenium,
transformer steel and rare-earth metal are, and each has a chokepoint, a
lead time and a counterparty.

The profile is a `group` (label 'company', public so a counterparty can
read the book before sending an RFQ), its own actor_type 'group' actor,
and a 15-line catalogue of `user_products` owned by that actor. Follows
the Revive My Old Ride convention: copy defined once in config, a
separate owner-gated seed writes it to the live DB.

What makes "solely focused" a rule rather than a slogan is the inclusion
test. A material is listed only if it moves one of three curves —
compute per joule, joules delivered, or actuation. Everything else is
declined, and the test is enforced: every listing must sit on a desk,
every desk on a curve, and no desk may sit empty.

- src/config/singularity-materials.ts — SSOT: mandate, exclusion rule,
  five desks, the catalogue, compliance stance, group + product payloads
- scripts/seed-singularity-materials.ts — idempotent, owner-gated seed
  (group by slug, actor by group_id, listings by (actor_id, title))
- test gating the payloads against the live CHECK constraints, the label
  / feature / governance registries, and the mandate itself

Treasury is deliberately not enabled: GROUP_FEATURES.treasury requires a
bitcoin_address the company does not yet have. Prices are indicative
reference levels, and every listing says so — a budgeting number, not a
quote. Export-controlled lines carry the licence and end-use conditions.

The seed has not been run; it needs the box's service-role key.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9GDWaBWYHCZ9iNwmfZ41

* feat(groups): make the map the product — Substrate as an open research firm

Reframes the trading company into what it should have been from the start:
an open-source research firm covering the chokepoints between here and a
technological singularity, with a trading desk on the materials it knows
best. The asset is the map, not the book — trading a commodity and
researching a robotics company are the same work, so the map is the
product and the desk is one way to monetise it.

Two tests now gate the universe instead of one. A node must move a curve
(compute per joule, joules delivered, actuation) AND actually gate it, on
concentration, substitutability, lead time and demand inelasticity. The
unit of coverage is a chokepoint node, not an asset class — a node can be
a material, company, person, machine or process. That is what lets the
firm reach robotics, AI hardware and additive manufacturing without
becoming "everything": you arrive at them by tracing a chain you were
already mapping, so the graph grows by traversal rather than ambition.

Phase 1 is the producers of the fifteen: 92 producer leads across 85
distinct companies, for every material on the desk. Each row asserts a
name, a jurisdiction and a step in the chain, and nothing else. There is
no field for capacity, share, revenue or quality — those are the claims
that go stale in a quarter and move markets when wrong, and the research
phase is what adds them with a citation. Every row therefore starts at
source: null, which reads as an unverified lead; coverage is measured by
how many rows have a source, not by how many rows exist.

Disclosure is written now, before any position exists, because a firm
that publishes on what it trades and intends to own cannot install that
rule credibly afterwards.

- src/config/substrate.ts — firm: curves, chokepoint screen, node types,
  four phases, desks, catalogue, compliance, disclosure, group payload
- src/config/substrate-coverage.ts — Phase 1 universe + coverageProgress()
- tests: the schema gates, plus coverage follows the book both ways and
  no producer row can carry an unsourced claim it has no field for

Renamed from singularity-materials — the firm is no longer materials-only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9GDWaBWYHCZ9iNwmfZ41

* feat(domains): a profile spins up a whole website on its own hostname

/domains has been selling this sentence — "a working site, hosted and
managed at yourname.orangecat.ch" — with no mechanism behind it. This is
the mechanism, proved end to end on Substrate.

A request arriving on a hosted site's host is rewritten onto
/sites/<slug> and answered by a standalone website built from that
profile's own structured data. Rewrite, not redirect: the visitor's URL
bar keeps saying substrate.orangecat.ch, which is the entire point of
what is being sold. The path form keeps working on any host, so a site
is previewable before its DNS exists.

The website is not separately authored. Substrate's mandate, desks,
catalogue and coverage universe already existed as config because the
profile needed them; the five pages are those same objects rendered for
a different audience. Change the profile and the site changes with it —
and the map page cannot quietly drop the "unverified lead" caveat,
because the only data it has is the data the tests hold to source: null.

Adding a site is an entry in HOSTED_SITES plus a builder returning
SitePage[]. Pages are data, sections come from one closed set of shapes,
and one renderer serves every hosted site — which is what stops fifty
customer sites becoming fifty stylesheets.

- src/config/sites.ts — host → profile, pure and DB-free (edge hot path)
- src/config/site-content.ts — page/section model + per-site dispatch
- src/config/site-substrate.ts — Substrate's five pages, from its config
- src/middleware.ts — the host rewrite
- routes.ts + AppShell — 'site' is a fourth surface, not a chrome
  override, so a hosted site can never grow OrangeCat's header on
  somebody else's domain
- metadata uses title.absolute, so the tab says "Substrate", not
  "Substrate | OrangeCat"
- formatChf so a ruthenium quote reads CHF 15’000, in the listing the
  seed writes and on the site alike

Verified against a running server: the host rewrite resolves for
substrate.orangecat.ch, www., and substrate.localhost; orangecat.ch
itself is untouched; an unknown path under a site host 404s.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9GDWaBWYHCZ9iNwmfZ41

* feat(domains): domain availability search, shared by OrangeCat and FleetCrown

Finding a name is the rung before the two services /domains already
sells — somebody with no domain cannot buy hosting for one. This adds
the check, as a public keyless v1 endpoint both products call rather
than a widget one of them owns.

THE RULE THIS IS BUILT AROUND

The obvious implementation asks a redirector for a domain and treats 404
as available. That implementation reports ORANGECAT.CH — this project's
own production domain — as free, because .ch operates no public RDAP
service and a redirector cannot distinguish "no such domain" from "no
such registry". The same false positive hits .io and .co.

So a TLD earns a definitive answer only by appearing in IANA's RDAP
bootstrap. Everything else — unsupported TLD, timeout, transport error,
odd status, bootstrap unreachable — is `unknown`, surfaced as "check
manually" with the reason. `unregistered` is reachable by exactly one
path: a bootstrapped registry that answered 404. Even then the copy says
premium pricing, registry reservations and trademark conflicts are not
visible here. A search tool that guesses is worse than one that admits
the gap, because the guess is what someone acts on.

- src/config/domain-search.ts — SSOT: bootstrap URL, TLDs, patterns,
  timeouts, and the status copy
- src/services/domains/availability.ts — bootstrap-gated RDAP lookup,
  cached, batched at a polite concurrency
- src/services/domains/suggest.ts — bare name across every TLD first,
  variants after; a caller may narrow the TLD list
- GET /api/v1/domains — registered in PUBLIC_API_INTEGRATION_ENDPOINTS
  beside search and demand, so FleetCrown gets it as a contract
- /domains grows a search box above the offer it feeds

19 tests, none touching the network, including one per no-RDAP TLD that
fails if the feature ever reports one of them as free.

Verified live: substrataintel.com and .ai unregistered; orangecat.ai and
orangecatlabs.com registered; orangecat.ch correctly unresolved rather
than free.

Note for deploy: the box needs outbound HTTPS to rdap.org and
data.iana.org, or every lookup degrades to "check manually".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9GDWaBWYHCZ9iNwmfZ41

* feat(sites): Substrata Intel at substrataintel.orangecat.ch, designed properly

Renames the firm to Substrata Intel (files and slug follow, so a reader
never finds substrate.ts exporting a company called something else) and
gives the hosted site a design rather than a stylesheet.

TWO CORRECTIONS TO THE BRIEF, BOTH CHECKED

No domain is bought. The site runs on the free subdomain the platform
already offers. And it is orangecat.CH, not .com: orangecat.com is
registered to someone and serves nothing, while every part of this
platform — CD, Caddy, the /domains copy, SITES_BASE_DOMAIN — is .ch.

THE DESIGN

Editorial, not marketing. Space Grotesk for display, IBM Plex Mono for
anything a reader compares down a column, Inter for prose at measure.
Monochrome surfaces; the warm accent appears exactly twice, on the
current nav item and the coverage bar; status colour only on status.

- Hero replaces the generic title block on the home page: eyebrow, one
  display statement, and a lead cut to two paragraphs. The two that were
  dropped are said better by the phase block and the desk page, and a
  lead nobody finishes is not a lead.
- Coverage meter. The single most important number on the site now has a
  picture, and at 0 of 92 that picture is an empty bar. Drawn from the
  same data as the map, so it cannot flatter the work.
- The map gets a jump index — fifteen tables without one is a scroll,
  not a document — and every anchor is tested to land on a real table.
- Tables are table-fixed with declared widths. Auto layout sized each of
  the fifteen to its own longest cell, so one long company name shifted
  every column out of line with the table above it.
- Status cells carry a dot. "Unverified lead" and "Sourced" are the two
  words on this site a reader must never skim past.
- Sections are numbered, headings sit on a hanging number, cards are
  top-ruled rather than boxed.
- Masthead is one row at every width; the nav scrolls sideways on a
  phone instead of wrapping, because a two-row sticky header ate a third
  of a 390px screen.

Renderer split into focused section components under components/sites/
sections/, dispatched from one place. Three new section kinds — hero,
meter, index — available to every future hosted site, not just this one.

Verified against a running server at 1280 and 390: the host rewrite
answers on substrataintel.orangecat.ch, the tab reads "Substrata Intel",
and orangecat.ch itself is untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9GDWaBWYHCZ9iNwmfZ41

* refactor(sites): the firm is Substrata, at substrata.orangecat.ch

"Intel" was only ever a workaround for substrata.com being taken. On our
own subdomain there is no scarcity to work around, so the name is just
Substrata — config files, slug, subdomain and site all follow, and the
wordmark is one word again.

ORANGECAT.COM IS NOT OURS — DNS, not opinion:

  orangecat.ch   -> 167.233.22.31   (bitbaum, this platform)
  orangecat.com  -> 222.122.39.84   (KRNIC space, unrelated party)

So substrata.orangecat.com cannot be built: it would point a customer
site at somebody else's domain. The site is on .ch, where the CD, Caddy
and every line of the /domains copy already live. No multi-base-domain
plumbing was added for a .com we do not own — that is a constant to
change on the day it becomes true, not an abstraction to carry until then.

Also: the domain-search placeholder was one customer's name. It is
"yourname" now, matching the /domains copy.

Verified against a running server — substrata.orangecat.ch and
substrata.localhost both rewrite, the tab reads "Substrata", the retired
substrataintel host correctly no longer resolves as a site, and
orangecat.ch itself is untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9GDWaBWYHCZ9iNwmfZ41

* feat(substrata): no trading desk, and chokepoints that are not materials

Two corrections, both of which the site was getting wrong.

THE DESK DOES NOT EXIST

Standing a regulated commodities book up is a long road through
licensing, and none of it has been walked. Until then, prices, units,
lot sizes and invitations to deal are advertising a capability the firm
does not have — which is the single biggest untruth a page can carry,
and the one everything else here was built to prevent.

So the desk page is gone, along with every price, every unit, and the
product listings the seed wrote. The fifteen materials remain as
research subjects, keeping the part that was always research — why each
gates a curve, and which grade actually ships — folded into the map
where it belongs. The group advertises no marketplace, because there is
nothing to sell. `SCOPE.today` says plainly: we publish research, we do
not trade, broker, quote or arrange movement, and nothing here is an
offer or advice.

Disclosure keeps its rules even though there is nothing to declare —
a disclosure policy is only credible before it is needed — and now
opens by saying so. A desk survives only as a phase marked not-started,
described as an intention rather than a service.

Two tests keep it that way: one asserts a material carries no price,
unit or lot-size field, and one greps the config and the site builder
for dealing language. A config that quietly regrows a price field is a
config that puts an offer in front of a reader nobody may sell to.

MATERIALS ARE NOT THE ONLY CHOKEPOINT

The node taxonomy admitted machines, processes, companies and people
from the start, and then the universe contained nothing but materials.
Fourteen non-material chokepoints now sit alongside them: EUV scanners
with one supplier, projection optics that are a chokepoint inside a
chokepoint, packaging capacity allocated years ahead, HBM stacking
yield, transformer slots, interconnection queues, turbine order books,
magnet sintering, precision drives — and process engineers, the
constraint nobody can buy.

They enter on the same two tests and carry the same claim limits: what
the node is and why it gates, nothing about capacity, share or price,
every row unverified until sourced. A test now fails if the universe
ever collapses back to one kind of node, so "a node can be anything"
stays a fact about the coverage rather than a line in the config.

Rendered as cards, not a table: a grid of names and country codes scans
nicely and says nothing, and the claim IS the reason it gates.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9GDWaBWYHCZ9iNwmfZ41

* feat(substrata): thesis, how to act on it, and the ledger to becoming the fund

Readers will want to do something with this research. Two new pages serve
that without crossing a line the firm has no licence to cross.

THE LINE, AND WHERE IT ACTUALLY IS

Publishing an impersonal, generally-circulated view is research.
Telling a particular person what to buy is advice, and advice is
licensed nearly everywhere. Less obviously: taking a fee for an
introduction is what converts "here is who the brokers are" into
regulated intermediation — introducing broker, tied agent, finder — in
Switzerland, the EU and the US alike. Being unpaid is not a detail of
that arrangement; it is the whole of what keeps it lawful.

So there is no referral list. `PARTNERS` is empty behind a flag, and the
gate is documented: a name appears only with an executed agreement AND
confirmation that the introduction itself needs no licence. The page
says so rather than leaving a blank space, because volunteering
somebody's name as an endorsement they never gave is the easier thing
to do and the wrong one.

WHAT THE PAGES DO INSTEAD

Six routes by which anyone acts in these markets, described as market
structure and not endorsement, each carrying what it does NOT give you
— the real failure mode here is misleading by omission, and a reader
who takes a commodity ETF as exposure to seven-nines tin has been
misled by what nobody said. One route is not financial at all:
for an industrial reader the highest-return action is usually
procurement, and the map is a supplier list as much as a research
product.

A thesis, six claims, each with a falsifier. A thesis without one is a
slogan, and a slogan cannot be scored — which also makes the track
record possible later.

A readiness ledger: nine requirements to manage money rather than only
publish, at 1 done and 2 in progress. Same discipline as the coverage
meter, and the licence line still reads not started, which is the whole
reason the other two pages are written the way they are.

Tests hold the line rather than good intentions: no partner may appear
while the gate is shut; every route must state its limitation; and the
whole site is grepped for directive language ("we recommend", "you
should buy", "guaranteed", "risk-free"). These erode quietly, one
helpful sentence at a time.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9GDWaBWYHCZ9iNwmfZ41

* feat(substrata): the participant directory, graded by scarcity

The ask was everyone in the singularity chain, seen through scarcity.
102 participants across ten layers, ore to buyer, each graded.

THE GRADE IS THE PRODUCT

A directory of everyone in a supply chain is a phone book. What makes
this research is the last column: chokepoint, concentrated, or
competitive. Grading participants "competitive" is not filler — it is
what makes "chokepoint" mean anything, and several well-known names are
in the list precisely because they are not constraints. A map where
every node is critical is a map nobody has read, so a test fails if all
three grades are not in use, and another fails if chokepoints ever
exceed half the list.

On the demand side the grade reads the other way: when a handful of
firms account for most of the world's orders, that concentration is a
scarcity fact about the chain too, pointing upstream instead of down.

Same claim limits as everywhere: name, layer, jurisdiction, role and a
scarcity judgement. Nothing about revenue, capacity or share, and every
row unsourced until an analyst attaches a source.

The page leads with the 24 that actually bind, as cards carrying the
reasoning, then the full directory as per-layer tables behind a jump
index.

ALSO

- Dropped the defensive framing from Acting. The limits are three
  plain lines now, and the "why there is no referral list" section is
  gone: a directory nobody paid to be in is the point, not a caveat.
- Domain aliases wired ahead of ownership. substrata.ch (intended home,
  appears free — .ch publishes no RDAP so a registrar has to confirm)
  and substrataintel.com (the .com fallback; substrata.com is taken).
  A host only reaches the check if DNS already points here, so listing
  them early costs nothing and means the site works the hour one is
  bought, with no deploy.
- The readiness ledger became definitions instead of a table. Three
  columns where one holds a paragraph is a table that scrolls sideways
  on a phone and is read by nobody.
- The nav is a client component for one reason: at eight sections the
  active item sat off-screen on a phone, so a visitor on a deep page saw
  no indication of where they were. It scrolls itself into view now.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9GDWaBWYHCZ9iNwmfZ41

* docs(seed): the seed header still described a firm that no longer exists

It said "Substrate", promised a trading desk, and claimed the script had
to run on the box. All three were stale: the firm is Substrata, there is
no desk, and the seed is PostgREST calls rather than psql — so it runs
from any machine that can reach supabase.orangecat.ch over HTTPS, no SSH
and no tunnel needed. That last one matters, because believing otherwise
is what makes a two-minute task look like it needs a maintenance window.

Also notes that the service-role key bypasses RLS, so the machine running
it is privileged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9GDWaBWYHCZ9iNwmfZ41

* fix(sites): close the five defects the architecture audit found

CodeQL was red on this branch with six alerts, which is why the PR could not
merge. All six were real but shallow: five unused locals, and one substring
test on a URL (`url.includes('data.iana.org')`) that also matches
`data.iana.org.evil.example`. It sat in a test — the worst place for it, since
tests are what the next lookup gets copied from.

The other four are the ones that mattered:

**60 KB of dead payload on every page load.** `SiteNav` is a client component
and was taking `SitePage[]`. Every prop crossing that boundary is serialised
into the RSC payload, so all eight Substrata pages shipped the entire site —
92 producer rows, 102 participants — to render eight links. Measured: 60.1 KB
carried, 0.33 KB used. It now takes `SiteNavItem[]`, the narrowest shape that
answers its question.

**A public keyless amplifier with no rate limit.** One request to
`/api/v1/domains` fans out to as many as 24 outbound RDAP lookups, and varying
the query defeats the cache. The cost of abuse was never our CPU — it was this
box's IP being throttled by the registries we depend on. Now behind
`rateLimitDomainSearch` (10 per 5 min), modelled on the ask-cat limiter, which
exists for exactly this shape: an expensive downstream call for an anonymous
caller.

**An unbounded cache keyed by caller input.** `resultCache` grew for as long as
the process did, and on the box that is weeks. The TTL did not bound it —
expired entries are only noticed when the same key returns, which an
enumerating caller never does. Capped, with a TTL sweep before LRU eviction,
and a test that fails if the cap stops holding.

**A seed that would break on the box, not in CI.** `seed-substrata.ts` used an
untyped client and five `as string` casts, so a column rename would surface by
hand, months later. Bound to the generated `Database` type; the casts are gone
because they are no longer needed.

Also collapsed the third copy of the x-forwarded-for read in rate-limit.ts into
`clientIp()`. A per-IP limiter is only as correct as its notion of "IP".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* feat(sites): publishing a website stops being a code change

A hosted site was an entry in a hardcoded array plus a hand-written builder.
That means every customer costs a pull request, a CI run and a deploy before
their domain resolves — which is the opposite of what /domains sells. Three
changes make an ordinary site cost nothing:

**Host resolution is positional, not a list.** `siteSlugForHost` asks whether a
Host header is SHAPED like a hosted site — one non-reserved label on
orangecat.ch — and never touches the database, because it runs in edge
middleware on every request to the whole app. Whether a site EXISTS is decided
downstream by the page, which is allowed to query. An unclaimed slug rewrites
and 404s, which is the safe direction.

That trade needs a reserved list to be safe, so there is one, and it is
load-bearing twice over: `supabase`/`bridge`/`fleetcrown` already serve
something else on this box, and `security.orangecat.ch` under our own
certificate is a phish, not a website. RESERVED_SUBDOMAINS covers both, and the
tests assert every entry refuses.

**A site is a row in a table that already exists.** `group_features` has
group_id, enabled, an audit column and a `config` jsonb, and its own header
already says adding a feature needs no code. Publishing a website is a
capability a group switches on, exactly like treasury. A `hosted_sites` table
would have duplicated all four columns and created a second answer to "what has
this group turned on". The new migration adds one RLS policy so a published site
is world-readable — the database decides "published", not TypeScript, and
`enabled = false` unpublishes instantly. jsonb is `any` wearing a hat, so it is
validated at the boundary with a per-field `.catch`: one malformed alias host
costs that alias, never the customer's website.

**An ordinary site has no builder.** `site-profile.ts` renders any group from
the profile it already filled in. Nothing is authored twice and nothing is
invented — no Support block without an address, no nav on a one-page site. The
dispatch that was a `switch` is now a map holding only the exceptions, because
that is what a bespoke builder is: Substrata's research corpus is not
profile-shaped, and it stays in the repository so it renders statically without
a database at all.

Net: a new site is a row and zero lines of code. 216 config tests green.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* feat(sites): a certificate for any customer domain, with no ssh

Positional host resolution gets a site routed. It does not get it a TLS
certificate, and without one the site is unreachable — so this is the other half
of "spinning up a site costs no infrastructure work".

The alternative was a wildcard certificate: a DNS-01 challenge, an Infomaniak
API token living on the box, a Caddy DNS plugin — and it still would not cover a
customer's own domain. On-demand TLS needs none of it and inverts the
relationship correctly: Caddy asks OrangeCat whether a hostname is real before
ordering a certificate, and OrangeCat already knows, because a site is a row.

`/api/internal/tls-check` is that gate, and it is written as a gate. Every 200 is
an ACME order and Let's Encrypt rate-limits an account that fails them, so
anyone who points a hostname here and requests it is spending our issuance
budget. Reserved subdomains are refused before any query runs, and a lookup that
throws denies — a database blip must not become an open certificate mint. Six
tests hold exactly those cases, including the fail-closed one.

The Caddy block lives in `deployment/caddy/` rather than only on the box,
because configuration that exists only on a box is configuration nobody can
review. `install-hosted-sites-caddy.sh` refuses to run until the ask endpoint
answers 200, backs up the Caddyfile, validates before reloading, and re-checks
the neighbours afterwards — one bad Caddyfile takes down all twenty-odd apps.

**RESERVED_SUBDOMAINS was wrong, and now cannot be.** Written by hand, it held
seven labels. The box is serving twenty-two. Fourteen live hostnames —
kivvi, vitareba, solon, supabase among them — were claimable as site slugs the
moment resolution became positional. The list is now generated from Caddy into
`deployment/reserved-hosts.txt`, and `check:reserved-hosts` is in `verify`, so
the next app deployed on this box fails the build until it is reserved. The gate
was tested by deleting an entry and confirming it goes red.

Live Caddyfile deliberately untouched: the ask endpoint is not deployed yet, and
enabling on-demand TLS before it exists would deny every request. Install after
the deploy.

438 tests green.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* docs(sites): the runbook for turning a group into a website

Two audiences. Somebody publishing a site needs to know it is one row and no
deploy — and that the minute before it answers is a named constant, not a
mystery. Somebody deploying a new app on bitbaum needs to know why the build
suddenly fails on reserved hosts, because that failure is the whole point of
the gate and it will look like a bug the first time.

Both one-time infrastructure steps are written down with the reasoning kept,
including the one that cannot be automated from here: no Infomaniak API
credentials exist on a developer machine, so the wildcard A record is a human
action, once, forever.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(verify): type-check the scripts, so the seed's types mean something

The previous commit said binding seed-substrata.ts to the generated `Database`
type 'moves that failure to npm run type-check'. That was not true as
configured: tsconfig.json excludes scripts/**/*.ts so Next does not compile
them, and the side effect was that verify never looked at them at all. The
binding was decoration.

A seed is exactly the wrong place for that gap. It runs by hand, on the box,
months after the migration that broke it — the one script whose schema drift
surfaces in front of a person rather than in CI.

scripts/ was already at zero errors, so this gate starts green. Verified it
bites by mistyping a column name and watching it go red.

Deliberately not extended to __tests__: 119 pre-existing type errors live there
and fixing them is real work that does not belong to whichever change happens to
notice. Recorded rather than silently skipped.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* feat(sites): publish a website with one call, not one INSERT

Everything underneath already worked off a single row, but the only way to
write that row was SQL. That is not "a few clicks" — it is a DBA. This is the
endpoint FleetCrown and the group settings UI call:

  GET    /api/groups/[slug]/site   status, address, eligibility
  PUT    /api/groups/[slug]/site   publish (upsert, so it also reconfigures)
  DELETE /api/groups/[slug]/site   unpublish, keeping the configuration

Three decisions worth naming:

**PUT is an upsert.** "Create a site" and "configure a site" would be two
states to reason about where the database has one row.

**GET answers `url` even when unpublished**, plus `eligible` and `reason`. It
costs nothing and it is the difference between a button that says "Publish" and
one that says "Publish at acme.orangecat.ch" — and between a group learning its
slug is reserved before it clicks or after.

**DELETE disables, it does not delete.** `enabled = false` is what both the RLS
policy and the resolver read, and keeping the row keeps the config, so taking a
site down for a week does not lose its custom domain.

The refusals are the tested part, because the worst failure here is a site that
exists in the database and never answers on the internet — the button said it
worked. A slug that is not a legal DNS label, a slug that already belongs to
infrastructure (`supabase`, `fleetcrown`) or invites a phish (`security`), and
a private group whose site RLS would hide from every visitor.

`check:sizes` refused the first version at 229 lines, which was the right
complaint: the route was doing domain work. Rules and writes now live in
services/sites/publish.ts, which imports nothing from `next/` — that one
`revalidateTag` import dragged Next's entire server runtime into any test that
touched these rules, and dropping a framework cache is the HTTP layer's job.

verify green: 250 suites, 2494 tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Mao Nakamoto <georgy.butaev@revamp-it.ch>
2026-08-27 08:42:17 +00:00
GandClaude Opus 5 dfa67843a6 ci: call the central auto-merge sweep — its coverage moved first (#719)
This repo was the last of the two deliberately excluded from the fleet rollout.
Its copy of auto-merge-sweep.sh shipped merges by re-arming CI so that cd.yml
(workflow_run on CI) would fire — a chain with a known hole: a CI run started by
GITHUB_TOKEN emits no workflow_run event, so CD never fires for an automated
merge. The canonical sweep closes that with a RECONCILER, enabled here via
`deploy_workflow: cd.yml`: every sweep compares main's tip against the last
successful cd.yml run and dispatches it directly when they differ. The
`post-main` hand-off in ci.yml stays as a second path; the reconciler is the
net under both.

THE TESTS MOVED BEFORE THE SCRIPT WAS DELETED. This repo was one of only two in
the fleet that ever wrote tests for the sweep, and its suite covered four things
the canonical suite did not — the in-progress defer, the stale-run wait, and
the full red-base carve-out set (green-on-failing-jobs merges; no coverage
refused; PARTIAL coverage refused). All of it is now in
dotfiles/scripts/ci/test-auto-merge-sweep.sh (17 cases, mutation-proven),
ported in maonakamoto/dotfiles#34 so no assertion is lost between the two
commits.

One block of auto-merge-base-guard.test.ts was NOT about the sweep: the source
assertions on refresh-e2e-reset-tokens.mjs (fixture keyed on GITHUB_RUN_ATTEMPT,
leftover fixture cleared instead of failed on). That script stays in this repo,
so its guard stays too — moved to e2e-reset-fixture.test.ts, its own file,
because the thing it tests no longer shares context with a script this repo no
longer carries.

Verified before deleting the local copy: diffed it against the canonical and
accounted for every differing line — all of them are main_* vs base_* naming
for identical logic, the cancelled-rerun the canonical generalises, and the CI
re-arm the canonical does via REARM_WORKFLOWS. The update-branch behaviour this
repo's branch-currency tests pinned is in the canonical verbatim.

CLAUDE.md repointed: the policy section and the two-hand-offs section both named
scripts/ci/auto-merge-sweep.sh, which would have become a lie the moment this
merged.

Fleet duplication: 8 copies -> 7.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 13:04:17 +00:00
e55e9e013b fix(ci): declare the failing-job list before the branch that can skip it (#652)
#650 declared it inside the `else` of the "does the base have CI history?"
check, but `set -u` is on and the merge site always reads it. On a base branch
with no CI history the sweep took the "proceeding" path and died:

  [auto-merge] no CI history for main — proceeding
  auto-merge-sweep.sh: line 246: main_red_jobs: unbound variable

That is auto-merge dead for every PR in the repo, not a degraded path. Latent
here because main has CI history, but one fresh repo away from being real — the
same defect shipped to the fleet ports and has been corrected there too.

Caught only because the case was executed rather than reasoned about, so the
regression test runs the real script against a `gh` reporting no CI history.

Co-authored-by: Georgy Butaev <georgy.butaev@revamp-it.ch>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 10:44:32 +00:00
18bc7b7968 fix(ci): a red base must not trap the PR that repairs it (#650)
"Never merge onto red" is right for an unrelated change — a broken base
should not quietly collect more of them. It deadlocks the repo when the
PR *is* the repair: the fix cannot travel the path its own redness
blocks, and only a human can move it.

Seen in maonakamoto/aoz-housing on 2026-08-07: E2E red on master, the fix
sitting green in a PR, every sweep refusing politely. Same shape as the
cancelled-base deadlock this script already learned — a guard correct
about the code and wrong about the queue.

Now the sweep identifies WHICH jobs are red and lets a PR through only if
its own checks pass every one of them. Not a weakening: a PR's checks run
on the merge result (refs/pull/N/merge), so green-on-those-jobs is direct
evidence the post-merge base is better than the pre-merge base. Still
refused: a PR that does not cover the failing jobs, one that covers only
some, and a base failure whose jobs cannot be identified at all.

Co-authored-by: Georgy Butaev <georgy.butaev@revamp-it.ch>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 09:39:37 +00:00
fccb97d26d fix(ci): keep branches current, and stop skipping conflicts in silence (#645)
Two failures on the same PR today, both the merge train optimising for merging
and having nothing to say about NOT merging.

#639 went CONFLICTING while main moved on. The sweep's mergeability check
treated that exactly like "not ready yet" and passed over it in silence, every
sweep, indefinitely. But a conflicted PR is not waiting for anything — nothing
else will unstick it, so silence is the wrong answer. It now says so on stderr
and writes a line into GITHUB_STEP_SUMMARY, where it is actually seen.

Nothing kept branches current either, so a PR was proven against a main that
had already moved several merges earlier, and the conflict surfaced hours after
the merge that caused it. A clean-but-BEHIND PR is now brought up to date via
the update-branch endpoint before it is considered — one per sweep, for the
same reason only one PR is merged per sweep. Its checks then re-run against the
main it will actually land on, which is what the one-car-per-sweep rule was
always trying to guarantee, and conflicts surface on the next sweep instead of
the next day.

Gated by auto-merge-branch-currency.test.ts, which drives the real script
against a fake gh, and mutation-tested: removing either guard fails 3 of its 4
cases. The conflict warning goes to stderr on purpose, so the harness merges
the streams — a test reading only stdout would miss the signal it exists to
check.

Uses `gh api -X PUT .../update-branch` rather than `gh pr update-branch`, which
does not exist in older gh (2.46 on this box).

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 07:15:43 +00:00
f96c71611e fix(ci): the merge train deadlocked, and its retry path could never have worked (#642)
* fix(ci): a cancelled base run deadlocked the merge train

Five green PRs sat unmerged for seven hours tonight behind one line:

    [auto-merge] main CI is cancelled — refusing to merge onto a broken base

Refusing a red base is correct. A CANCELLED run is not a red base — it
carries no verdict about the code at all. And it is unrecoverable: the
only thing that produces a new CI run on main is a merge, and merges are
precisely what the guard is blocking. A GitHub Actions outage cancelled
main's run, and the queue could not clear itself. It took a human
`gh run rerun` to move.

This script had ALREADY learned this lesson for PR checks — the
`re-running cancelled run` branch below was added after #603 and #604
stranded the same way — and left the identical hole on the base branch.
Same shape as the top-up settlement bug earlier today: a class retired on
one path and left open on its sibling. Enumerate both sides, or the
backstop only covers the half you were looking at.

So: on `cancelled`, re-run the base run and let the next sweep judge the
real result. A genuine `failure` still blocks, because that IS a verdict.
The existing `status != completed` check keeps re-runs from stacking.

Tested against the real script with a fake `gh` on PATH rather than a
description of it — cancelled re-runs and merges nothing, failure neither
re-runs nor merges, in-progress defers, and a run belonging to an older
commit still waits. Verified non-vacuous: stubbing the new branch out
turns the first test red.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(ci): a re-run could never succeed, so no retry path was ever a recovery path

Re-running main's outage-cancelled CI turned a stalled merge queue into a
genuinely RED main:

    createUser for reset fixture failed AuthApiError:
    A user with this email address has already been registered  (422 email_exists)

`refresh-e2e-reset-tokens.mjs` mints `e2e-reset-${GITHUB_RUN_ID}@…`, and
GITHUB_RUN_ID is **stable across a re-run**. So the second attempt of any
run that reached fixture bootstrap tried to create a user the first
attempt had already created, and the job exited 1.

The consequence is bigger than one red run: **re-running CI could never
succeed**, which silently disabled every recovery mechanism built on
re-running — including this repo's own cancelled-run retry for PRs, added
after #603/#604 stranded, which therefore cannot have worked in any case
where the cancelled run got this far. The retry existed; the thing it
retried was guaranteed to fail. That is the third instance today of a
recovery path nobody had exercised.

It also makes the base-branch retry in the previous commit unsafe on its
own — it would have converted "deadlocked" into "permanently red". The
two belong together.

Fix: key the fixture on the ATTEMPT (`GITHUB_RUN_ID-GITHUB_RUN_ATTEMPT`),
and treat a leftover of the same tag as something to clear rather than
fail on — this fixture is disposable by definition. Anything that makes
CI unrunnable twice in a row disables the recovery paths we depend on.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 23:15:38 +00:00
f46a76b2e3 fix(ci): deploy after bot merges instead of stalling silently (#617)
CD and Main Red Alert both trigger on `workflow_run` of CI. GitHub does not
emit that event when the CI run was itself created with the default
GITHUB_TOKEN — which is exactly how the auto-merge sweep re-arms CI after a
bot merge (a GITHUB_TOKEN push triggers nothing, hence the dispatch).

So both consumers are dead on the automated path, and dead silently: CI green,
no check red, nothing deployed. 14 verified commits sat on main for eight hours
on 2026-08-04 while the box served the Aug-4 15:12 build. Auto-merge only
survived because it has a cron; CD and the red-main alert have no fallback.

A dispatched CI run now does the handoff itself, in a new `post-main` job:
files/closes the red-main issue, then dispatches CD. The push path is left
untouched — its `workflow_run` fires normally and is the better path there
(CD downloads the exact artifact CI built). One trigger per path, never two.

The dispatch is verified rather than assumed: if no CD run appears within 60s,
the job fails. Red main halts the merge train, which is the correct response to
"we can no longer ship".

Alert policy moved to scripts/ci/main-red-alert.sh so the two callers share one
definition instead of drifting copies.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 10:13:12 +00:00
67b6bcded2 fix(ci): re-run cancelled checks instead of stranding the PR forever (#614)
A CANCELLED check is not a verdict, it is noise. CI runs with
`concurrency: cancel-in-progress`, so a newer run on the same ref kills an
older one — and nothing ever re-runs it. The PR is then permanently
not-green, the sweep skips it on every pass, and it sits in the queue
until a human notices. #603 and #604 stranded exactly this way and had to
be re-run by hand.

Now a PR whose only non-green checks are cancelled gets those runs
re-triggered, and a later sweep judges the real result.

Deliberately narrow: if any check is a genuine FAILURE/TIMED_OUT/ERROR the
retry is skipped entirely, so this can never paper over a real failure or
loop on one. Verified against fixtures for cancelled-only, cancelled plus
a real failure, and a failing external status (Snyk-style) — only the
first retries.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-04 15:32:46 +00:00
31973e8a24 fix(ci): stop the auto-merge re-arm from leaving main red (#613)
* fix(ci): poll for mergeability instead of reading "not computed yet" as "no"

The first live sweep merged nothing: every PR reported mergeable=UNKNOWN.

GitHub computes mergeability lazily and invalidates it for every open PR
whenever the base branch moves. The fast path runs on CI-completion — that
is, moments after a merge just moved main — so it is precisely the case
where nothing has been recomputed yet. Treating UNKNOWN as "not mergeable"
meant the workflow_run trigger could never merge anything and the whole
train silently degraded to the 10-minute cron.

Poll the PR until GitHub has an answer (6 tries, 5s apart) and only then
decide. Verified against #608, which reported UNKNOWN during the sweep and
MERGEABLE/CLEAN once asked again a few seconds later.

The check gates stay where they were, on the cheap list query; only the
mergeability question — the one that is racy by design — gets re-asked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(ci): stop the auto-merge re-arm from leaving main red

Two bugs the first live merge exposed, both mine.

1. A dispatched CI run scans all of git history for secrets.
   gitleaks scans the incoming commits on push and pull_request, but a
   workflow_dispatch has no such range, so it falls back to the full ~2.6k
   commit history and fails on ~173 pre-existing findings (2025-era .env
   commits) that only a history rewrite can clear. Auto-merge dispatches CI
   on main after every merge — a GITHUB_TOKEN push triggers nothing — so
   every automated merge left main red, and CD, which chains off green CI,
   never deployed. Skip the scan on workflow_dispatch only. Coverage is
   unchanged: every commit is still scanned in its PR before it can merge.
   Baselining those findings instead would mean allowlisting real historical
   credentials, which .gitleaksignore explicitly forbids.

2. The green-base guard read the newest CI run without checking which
   commit it belonged to. Right after a merge that run is still the previous
   commit's — and green — so the guard would wave a second merge onto a tip
   nothing had verified. Require the run's headSha to equal the current tip.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-04 16:48:31 +02:00
d05d992a7b fix(ci): poll for mergeability instead of reading "not computed yet" as "no" (#611)
The first live sweep merged nothing: every PR reported mergeable=UNKNOWN.

GitHub computes mergeability lazily and invalidates it for every open PR
whenever the base branch moves. The fast path runs on CI-completion — that
is, moments after a merge just moved main — so it is precisely the case
where nothing has been recomputed yet. Treating UNKNOWN as "not mergeable"
meant the workflow_run trigger could never merge anything and the whole
train silently degraded to the 10-minute cron.

Poll the PR until GitHub has an answer (6 tries, 5s apart) and only then
decide. Verified against #608, which reported UNKNOWN during the sweep and
MERGEABLE/CLEAN once asked again a few seconds later.

The check gates stay where they were, on the cheap list query; only the
mergeability question — the one that is racy by design — gets re-asked.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-04 14:24:21 +00:00
8a705f1f94 ci: green PRs merge and deploy themselves (#609)
Nobody reviews PRs on this repo and nobody wants to be in the merge loop,
so the policy moves into the repo where it is visible and revocable
instead of depending on whoever happens to be at a keyboard.

auto-merge.yml sweeps open PRs on every CI completion, plus a 10-minute
safety net for PRs whose last check reports off-cycle (Snyk, CodeQL).
scripts/ci/auto-merge-sweep.sh holds the policy: merge only a non-draft,
unlabelled, fully green, cleanly mergeable PR — and only onto a main
whose own CI is green and finished.

Two deliberate constraints, both load-bearing:

- One PR per sweep. A PR's checks prove that PR against the main it
  branched from, not against the eleven PRs queued beside it. Merging a
  batch would put a combination onto main that nothing ever built, so the
  train advances one car per sweep and each is verified on main first.
- An explicit `gh workflow run ci.yml --ref main` after any merge. A push
  made with the default GITHUB_TOKEN does not trigger workflows, and CD
  chains off CI, so without this the merge lands and never deploys.

Signal "not ready" with a draft PR or a hold/no-automerge/do-not-merge/wip
label; both wait indefinitely without needing a human.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-04 16:09:39 +02:00