1 Commits
Author SHA1 Message Date
CatoandClaude Opus 5 04cedba195 Loki's public face belongs to the tenants who agreed to be on it (#798)
* fix(setup): the documented local setup produced a broken app

Followed README.md and .env.example exactly on a clean checkout and got an
app that renders but cannot read a session. Three separate gaps, each on the
documented path:

- AUTH_TRUST_HOST was undocumented. src/auth.ts gates trustHost on it, and
  scripts/hetzner/gen-env.sh writes it on the box — but .env.example, the
  README's "minimum local .env.local", docker-compose.yml and loki-app.sh all
  omitted it. Unset, Auth.js answers EVERY /api/auth/session with 500
  UntrustedHost. Verified: 500 before, 200 after, nothing else changed.
  The auth.ts comment claimed the local production server set it; it did not.

- The compose db image has no pgvector. knowledge-embeddings.ts declares
  vector(384), so `drizzle-kit push` dies on the first table with
  `type "vector" does not exist` and leaves an EMPTY database — which reads
  like a broken checkout rather than a missing extension. Switched to
  pgvector/pgvector:pg17 and added an initdb script that creates it before
  the migrate service runs.

- drizzle.config.ts never loaded .env.local, though a dozen scripts under
  scripts/db and scripts/test do. `pnpm run db:push` therefore threw
  "DATABASE_URL is required" at someone who had just set DATABASE_URL where
  the README told them to. An exported variable still wins, so CI and the box
  are unaffected.

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

* fix(projects): the empty state named a button that does not exist

A new account with no projects is told to "Register your first project with
'New project' above". There is no "New project" control on the page — the
button reads "Add", and the dialog it opens is titled "Add Project". The
component file is called NewProjectButton.tsx, which is most likely where the
copy came from.

Found by signing up as a new user and following the onboarding instruction
literally: the first thing the product asks you to do names a control you
cannot find. Now says "Add", matching what is rendered.

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

* feat(fleet): a project reaches Loki's public catalogue only by consent

/fleet is unauthenticated and speaks for the PRODUCT, not for a user. It
resolved a single account — getSelfImprovementTarget(), "whoever owns the
oldest entity named loki" — and published every project that account had.
Two things were wrong with that in a multi-tenant product:

  1. No decision was ever recorded. A project was on a public page because it
     existed. Every other public surface here already goes through
     getPublicProjects (the landing hero, /u/[username]); /fleet was the only
     one reading the unfiltered query.
  2. WHICH account got published was a side effect of the self-improvement
     loop's notion of "which product am I improving". Reseed that entity and
     the next-oldest match's whole project list becomes Loki's front page.

So consent is now a stored property of the project:

- user_projects.listed_publicly, DEFAULT FALSE. The default is the point —
  signing up must never enrol a tenant in the product's shop window.
- getPubliclyListedProjects() reads consent instead of ownership, across all
  accounts, which is also what makes the page meaningful with more than one
  user. /fleet no longer selects by owner at all.
- A per-project toggle on the project workspace, beside the existing
  "Publish to OrangeCat" opt-in and reversible from the same control.
- 0075 backfills the account publishing the catalogue today, so the live page
  is unchanged for it while everyone else starts at false.

Also: FleetRegisterNote told EVERY account "19 sites are hosted on the box
with no project here" — apps.conf describes one box and is a file in this
repo, so a brand-new user was being told about sites they do not own. It now
renders only for the account that operates that box.

A user's own profile (/u/[username]) is deliberately untouched: that page is
the user speaking about themselves, and it was already scoped.

scripts/test/public-catalogue-consent.ts pins all of it — swapping the query
back is a one-word change, and a comment cannot hold that line.

Verified against a real database: consent false -> absent from /fleet,
true -> present, toggled both ways through the UI.

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

* feat(public): what a signed-out visitor sees is a decision, not an accident

Answers "whose projects does a stranger see on Loki?" — with three tiers
instead of three different hardcoded owner lookups.

THE PROBLEM. Loki is multi-tenant and the founder is tenant #1, but every
public surface resolved an owner and published whatever that account held:

  - the landing hero  → getHeroFleetSnapshot(getDefaultUser())
  - /fleet            → getSelfImprovementTarget()  (fixed in the last commit)
  - the /projects note→ nothing at all

Three answers to one question is three chances to be wrong, and the landing
was the worst of them: it never consulted consent at all. Verified locally —
a project with listed_publicly = false was rendering in the hero console.
It also ordered by a hardcoded FLAGSHIPS = ["loki", "orangecat"], the ad-hoc
version of "featured", which could only ever name the founder's own projects.
The same list sat in /u/[username], where it reordered EVERY tenant's profile
by two names they will never have.

THE MODEL. src/db/queries/public-visibility.ts is now the one place that says
what a signed-out visitor may see:

  1. AGGREGATE  — fleet-wide counts. Identify nobody, need no consent, and
                  grow honestly as Loki gains users.
  2. CATALOGUE  — /fleet: projects whose OWNER opted in (listed_publicly).
  3. SHOWCASE   — landing hero: the catalogue narrowed to what the OPERATOR
                  featured (featured_at). Curated space cannot be first-come.

Two gates because they answer to different people: consent is the tenant's
and may be withdrawn; featuring is the operator's editorial act. The showcase
predicate is BUILT ON the catalogue predicate, so revoking consent drops a
project off the homepage immediately even while it is still featured —
verified all three ways against a real database.

This is the doctrine site_feedback.featured_at already had ("raw visitor text
NEVER auto-publishes"). Projects now work the way feedback already did.

Featuring is authorized by isSiteOperator (users.is_default — the account made
at /setup, so it means "runs this instance" for self-hosters too) and lives on
its own query rather than riding patchProject, because it is the one project
field a tenant must not set for themselves. It also refuses to feature a
project whose owner has not consented.

UI: two separate controls on the project workspace, deliberately not merged —
"List publicly" (owner) and "Feature" (operator, shown only to them, and
explaining itself when consent is missing).

ALSO, from auditing the public pages at 320/390/768/1440:

- /fleet had 19 sub-44px tap targets — every one the site address that is the
  whole point of the row, and the only sub-44px targets left on any public
  route. .ui-public-fleet-site was missing from the touch floor AND was an
  inline box, where min-height does nothing. Both fixed; now zero.
- The responsive auditor EXCLUDED public routes, deferring to `smoke` "which
  already covers them" — smoke asserts HTTP status, which says nothing about a
  layout. So the pages a stranger sees first were the only ones with no
  responsive coverage. They are in the auditor now and need no session, so a
  session is required only when authenticated pages are requested.

No horizontal overflow at any width, before or after.

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

* fix(fleet): a phone spent a screenful on filters before the catalogue

Measured at 390x844: the first project row sat at y=1020px. Four facet rows
(Where / Kind / For / Missing) took 366px of that, so you scrolled past more
than a screen of controls before seeing any of the thing they control — on a
page whose entire job is to show a catalogue.

The rows now live in a <details> that is collapsed below md and forced open
from md up, so desktop is unchanged and the phone leads with content:
first row y=1020 -> 699. The summary carries a count of active facets,
because a filter you cannot see is one you forget you set — and then an empty
result reads as a broken page rather than a narrowed one.

<details> rather than state, because this page deliberately ships no
JavaScript ("the address bar is the state") and a filter panel that needed a
bundle to open would be the one thing on it that did.

One trap worth recording: hiding the closed panel has to be EXPLICIT. The UA
sheet hides a closed <details>'s children with display:none, but author styles
outrank the UA sheet and .ui-fleet-facet-row is `@apply flex` — so the first
version rendered a toggle that changed nothing, with the element correctly
reporting open=false while all four rows stayed visible. Verified both states
at both widths after the fix.

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

* feat(public): credit the builder, ask before publishing, stop renting the box

Four things, all following from the same rule: Loki is multi-tenant, so its
public face belongs to the tenants who agreed to be on it.

1. ATTRIBUTION. A showcased project now carries a byline — @handle linked to
   /u/[handle], display name when there is no handle, and NOTHING when there is
   neither, because a stand-in label is a name we would be inventing for
   somebody. Showing a tenant's work unattributed reads as "our projects",
   which is untrue and is the opposite of why a showcase exists; being credited
   and linked is also most of what a tenant gets back for consenting. Joined in
   the query rather than fetched per row.

2. LOKI ASKS. Consent was reachable only from a toggle nobody knew about, and a
   control nobody finds collects exactly one answer. The empty catalogue that
   follows is what gets "fixed" by widening the query again — the bug 0075
   removed. So the project workspace now invites the owner once, and
   listing_prompt_dismissed_at takes no for an answer: per project (declining
   for a client build says nothing about the open-source one beside it) and in
   the database (a refusal that resets on a new device is a product that nags).
   The rule lives in src/lib/listing-invitation.ts, pure and unit-tested. The
   bar is repo + active, deliberately NOT a live URL: /fleet's own facets list
   "Being built" beside "Live", so requiring a deployment would ask only the
   projects that least need the exposure.

3. THE BOX IS NOT THE FLEET. apps.conf describes ONE box and is a file in this
   repo, and unmatched entries MINTED rows — so a Loki with one consented
   project still published 19 sites belonging to someone the viewer has never
   heard of. buildFleetRegister now takes includeUnlinkedSites, true only for
   the operator, for whom those rows are the entire point (the register read
   sideways is a to-do list). A hosted app still ENRICHES a project that
   exists, so a consented project keeps its real address either way; only row
   creation is gated, because only row creation publishes something nobody
   asked to publish. Verified: operator sees 20 projects / 19 sites, the public
   sees 1 / 0.

4. THE COPY. "This is the studio's whole catalogue" was true when one account
   was the whole fleet. It now says what the page is: projects their owners
   chose to show.

Also, from re-auditing: .ui-public-fleet-name (the row's PRIMARY link) measured
21px tall on a phone. It had been invisible to every previous audit because
while the page listed hosted sites alone, nothing in a row was a link at all —
the fix in 3 is what made a real project row render and the gap appear. Same
cause as .ui-public-fleet-site last time: the coarse-pointer floor sets
min-height, which does nothing to an inline box.

Every public page: zero horizontal overflow and zero sub-44px targets at
320/390/768/1440.

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

* fix(home): the hero console had an empty third column

Making the hero tenant-agnostic dropped "runs this week", because the old one
counted getRecentOrchestrationRuns(userId) — one account's week, which is not a
number a visitor should be shown. But the console's metric row is grid-cols-3,
so removing it left a visibly empty third of the panel. Caught by looking at
the rendered page rather than the diff.

Restored fleet-wide, counted the same way as the other two: it is the metric
that answers "is anything actually happening here", and an aggregate across
every tenant identifies nobody, so it needs no consent and grows with the
product instead of describing one account.

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

* fix(footer): the studio's sites were labelled as Loki's fleet

Every public page's footer lists 14 sites generated from apps.conf under
"Part of the fleet — 14 more sites". apps.conf describes ONE box, the
studio's, and several of those sites belong to clients — so on a multi-tenant
Loki the label told every visitor that one account's client work was what Loki
is. Same error as the /fleet lede, and the same fix: say whose they are.

"Built by the studio" now, and the link beside it points at the tenants'
catalogue by its real name rather than calling it "the whole register".

Deliberately a COPY change and nothing more. The links themselves stay, all
14 of them: they are real work, several had no inbound link from anywhere
before this block existed, and the cross-linking is the entire reason it is
here. Removing them would trade a genuine asset to fix a sentence. Only the
claim was wrong.

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

* fix(home): the hero console looked broken with nothing featured

0076 deliberately does not backfill a feature stamp — featuring is an
editorial act nobody has performed yet — so the live hero will really render
with zero project rows until someone features something. I had asserted that
was fine without looking at it. It was not.

The bar carries mb-4 + border-b and the metrics carry mt-4 + border-t, so with
no rows between them the panel drew TWO horizontal lines with 32px of nothing
in between: the shape of content that failed to load, on the first screen of
the product.

The metrics now sit flush under the bar's own border in that state, which is a
panel with nothing to list rather than a panel that broke. Verified in both
states: with rows the divider is back and the flush class is absent.

Not fixed by falling back to showing consented-but-unfeatured projects, which
was the tempting option: the invitation asks permission for the public fleet
page specifically, so putting those projects in the hero would take more than
the owner agreed to.

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

* fix(fleet): an empty catalogue told visitors to clear filters they never set

With nothing listed, /fleet rendered "Nothing matches that. Clear the filters →"
— to a visitor who had set no filters, offering a link that changes nothing.
That is the FIRST thing a freshly self-hosted Loki ever says on that page, and
it reads as a fault rather than an empty shelf.

Two states now, told apart by `rows` (the whole catalogue, before the query)
rather than `result.rows` (after it):

  nothing listed at all → says so, and says why: owners choose which of their
                          projects appear, and nothing is published without
                          them saying so. Links to what Loki does.
  filtered away        → unchanged: "Nothing matches that" + clear the filters.

Found by putting the local database into the state a new install starts in,
rather than only the state mine happened to be in.

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-09-20 06:30:17 -07:00