feat(selfhost): a copy of Loki is a copy — own hostname, own OrangeCat, a complete env contract

- APP_DOMAIN reads NEXT_PUBLIC_APP_DOMAIN (fallback loki.orangecat.ch), so
  callbacks, emails and copy carry a fork's own name; brand-sync still
  holds the shell mirror to the fallback.
- orangeCatProjectUrl() in config/orangecat.ts replaces the literal
  https://orangecat.ch/projects/… in three components, built on
  NEXT_PUBLIC_ORANGECAT_URL.
- .env.example names every variable src/ reads — 68 were not named, so a
  fork found Google sign-in, embeddings, the Telegram bot or the daemon
  token only by grepping process.env — each with the file that reads it,
  and scripts/test/env-example-covers-src.ts (picked up by test:unit) fails
  when one is missing. A comment that mentions a variable is not a read.
- README: "Run your own copy" — docker compose up, /setup, hostname,
  optional OrangeCat, agents on your own machine, the env contract; the
  name and identity are not part of the licence.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TtBnGxwf5ddXTzRNyjHVP7
This commit is contained in:
Claude committed 2026-10-03 07:57:22 +00:00
1 parent 85ca56c82d
commit 070f951b56
8 files changed
+176 -4

No files matched your search

+73
View File
@@ -179,3 +179,76 @@ DEMO_ACCESS_ENABLED=
# the database holds more than one user, because guessing wrong sends a client's
# site feedback to a stranger.
LOKI_OWNER_EMAIL=you@example.com
# ── Everything else src/ reads (optional — a feature is off until its key is set) ──
# Generated contract, enforced by scripts/test/env-example-covers-src.ts: a
# variable the code reads must be named here, with the file that reads it, so a
# copy of this repo never discovers a switch by grepping. Leave unset to keep
# the feature off; read the named file for what the value means.
# AGENT_PROJECTS_CONF= # src/lib/agent-config.ts
# AGENT_PROMPTS_FILE= # src/lib/agent-config.ts
# APP_SCRIPTS_DIR= # src/app/api/beacon/transcribe/route.ts
# APP_SESSIONS_DIR= # src/lib/session-paths.ts
# APP_URL= # src/lib/email.ts
# COCKPIT_ALLOW_LEGACY_DAEMON_TOKEN= # src/auth.config.ts
# COCKPIT_DAEMON_TOKEN= # src/auth.config.ts
# COCKPIT_SCRIPTS_DIR= # src/app/api/beacon/transcribe/route.ts
# CRON_SECRET= # src/app/api/health/route.ts
# DATABASE_POOL_URL= # src/lib/db-url.ts
# DEPLOY_KEY_PATH= # src/lib/site-cd-local.ts
# DEV_ROOT= # src/lib/site-cd-local.ts
# EMBEDDINGS_API_KEY= # src/lib/rag/embeddings.ts
# EMBEDDINGS_BASE_URL= # src/lib/rag/embeddings.ts
# EMBEDDINGS_DIM= # src/lib/rag/embeddings.ts
# EMBEDDINGS_MODEL= # src/lib/rag/embeddings.ts
# FEEDBACK_WIDGET_TOKEN= # src/app/layout.tsx
# GITHUB_REPO_OWNER= # src/config/github-owner.ts
# GITHUB_TOKEN= # src/lib/agent-execution/box-workspace.ts
# GOG_BIN= # src/lib/actions/calendar-event.ts
# GOOGLE_CLIENT_ID= # src/auth.ts
# GOOGLE_CLIENT_SECRET= # src/auth.ts
# GROQ_API_KEY= # src/lib/actions/calendar-event.ts
# GROQ_VISION_MODEL= # src/config/vision-models.ts
# HETZNER_STATE_FILE= # src/config/hetzner.ts
# HOSTED_RUNNER_DRAIN_MS= # src/lib/orchestration/settle-background-work.ts
# LOKI_ALLOW_LEGACY_DAEMON_TOKEN= # src/auth.config.ts
# LOKI_BOX_DEV_ROOT= # src/app/api/projects/[id]/route.ts
# LOKI_CLOUD_BUILDER_USER_IDS= # src/lib/execution-access.ts
# LOKI_DAEMON_TOKEN= # src/auth.config.ts
# LOKI_EXECUTOR= # src/lib/agent-execution/index.ts
# LOKI_GATEWAY_DEVICE_KEY_B64= # src/lib/openclaw-gateway.ts
# LOKI_MCP_RESOURCE= # src/config/mcp.ts
# LOKI_MODEL= # src/lib/agent/llm.ts
# LOKI_PARALLEL_DISPATCH= # src/lib/orchestration/parallel-run.ts
# LOKI_PERSONAL_SESSION_KEY= # src/app/api/loki/route.ts
# LOKI_REGISTER_SITE_SCRIPT= # src/lib/site-cd-local.ts
# LOKI_REPO_ROOT= # src/lib/site-cd-local.ts
# LOKI_SANDBOX_DOCKER_ARGS= # src/lib/agent-execution/sandbox.ts
# LOKI_SITES_BASE_DOMAIN= # src/lib/site-cd.ts
# LOKI_SITE_CD_AUTO= # src/lib/site-cd-local.ts
# LOKI_TOOL_LOOP= # src/lib/loki-core.ts
# LOKI_WORKFLOW_OWNER= # src/lib/site-cd.ts
# LOKI_WORKTREES_ROOT= # src/lib/agent-execution/worktree-workspace.ts
# LOKI_WORKTREE_DISPATCH= # src/lib/agent-execution/worktree-workspace.ts
# NEXTAUTH_SECRET= # src/lib/actions/action-link.ts
# NEXTAUTH_URL= # src/lib/email.ts
# NEXT_PUBLIC_APP_DOMAIN= # src/config/brand.ts
# NEXT_PUBLIC_BUILD_SHA= # src/components/shell/AppFooter.tsx
# NEXT_PUBLIC_ECOSYSTEM_BITCOIN_ADDRESS= # src/config/ecosystem.ts
# NEXT_PUBLIC_ECOSYSTEM_LIGHTNING_ADDRESS= # src/config/ecosystem.ts
# NEXT_PUBLIC_LOKI_BRIDGE_URL= # src/lib/event-stream.ts
# OPENCLAW_CONTACTS_PATH= # src/app/api/people/sync/openclaw/route.ts
# OPENCLAW_GATEWAY_TOKEN= # src/lib/openclaw-gateway.ts
# OPENCLAW_GATEWAY_URL= # src/lib/constants.ts
# OPENCLAW_KNOWLEDGE_JSON= # src/app/api/people/sync/openclaw/route.ts
# OPENROUTER_API_KEY= # src/lib/loki-core.ts
# ORANGECAT_BASE_URL= # src/lib/register/orangecat.ts
# ORANGECAT_PAY_URL_PERSONAL= # src/lib/oc-pay.ts
# ORANGECAT_PAY_URL_PRO= # src/lib/oc-pay.ts
# ORANGECAT_PAY_URL_TEAM= # src/lib/oc-pay.ts
# PRIVATE_ZONE_PIN_HASH= # src/lib/private-zone.ts
# RUNTIME_AVAILABLE= # src/instrumentation.ts
# TELEGRAM_BOT_TOKEN= # src/lib/actions/telegram-send.ts
# TRANSCRIBE_LOCAL_AVAILABLE= # src/app/api/beacon/transcribe/route.ts
# X1_CONSUMER_KEY= # src/lib/auth-providers.ts
# X1_CONSUMER_SECRET= # src/lib/auth-providers.ts
+28
View File
@@ -174,6 +174,34 @@ or `openclaw`.
See [docs/development/cloud-local-workflows.md](docs/development/cloud-local-workflows.md)
for the full matrix of browser-only vs local-runtime workflows.
## Run your own copy
Loki is MIT. A copy runs anywhere Docker runs, and nothing points at bitbaum's
infrastructure that an environment variable cannot repoint.
```bash
git clone https://github.com/bitbaum/loki && cd loki
cp .env.example .env.local # fill DATABASE_URL, AUTH_SECRET, AUTH_TRUST_HOST=true
docker compose up -d # pgvector Postgres, schema, the app on :3000
```
Then open `/setup` to create the first user. From there:
- **Your hostname**: `NEXT_PUBLIC_APP_DOMAIN` (and `NEXTAUTH_URL`). Callbacks,
emails and copy build on it (`src/config/brand.ts`); `loki.orangecat.ch` is
only the fallback.
- **OrangeCat is optional**: `NEXT_PUBLIC_ORANGECAT_URL` points links at your
own copy or stays unset; sign-in works with GitHub or e-mail alone.
- **Agents run on your machine** via the Fleet Runner (`desktop/`) or on any
box you give the runner script; the Hetzner builder is bitbaum's, not a
requirement.
- **The contract is `.env.example`**: every variable `src/` reads is named
there with the file that reads it, and `scripts/test/env-example-covers-src.ts`
fails CI when one is not. A feature whose key is empty is off, not broken.
The Loki name and visual identity are not part of the licence; a copy should
carry its own (`src/config/brand.ts` is one file).
## Important Docs
- [Business model](docs/business-model.md)
+53
View File
@@ -0,0 +1,53 @@
/**
* `.env.example` is the contract a copy of this repo is configured from. Every
* variable `src/` reads must be named there, with the file that reads it.
*
* Before this gate, 70 of them were not: a fork found the switch for Google
* sign-in, embeddings, the Telegram bot or the daemon token only by grepping
* `process.env`. A variable may be documented commented out (`# KEY=`): the
* contract is the NAME and where it is read, not a value. Dynamic reads
* (`process.env[name]`) are the helpers that take the name as an argument and
* are not caught here by design.
*/
import assert from "node:assert/strict";
import { readFileSync, readdirSync, statSync } from "node:fs";
import { join } from "node:path";
const NOT_CONFIG = new Set([
"NODE_ENV",
"NEXT_RUNTIME",
"HOME",
"PATH",
"NEXT_PUBLIC_",
"NEXT_PUBLIC_X",
]);
function* files(dir: string): Generator<string> {
for (const name of readdirSync(dir)) {
const p = join(dir, name);
if (statSync(p).isDirectory()) yield* files(p);
else if (/\.tsx?$/.test(name)) yield p;
}
}
const example = readFileSync(".env.example", "utf8");
const named = new Set([...example.matchAll(/^#?\s*([A-Z0-9_]+)=/gm)].map((m) => m[1]));
const read = new Map<string, string>();
for (const file of files("src")) {
for (const line of readFileSync(file, "utf8").split("\n")) {
// A comment that mentions a variable is not a read of it.
if (/^\s*(\/\/|\*|\/\*)/.test(line)) continue;
for (const m of line.matchAll(/process\.env\.([A-Z0-9_]+)/g)) {
if (!read.has(m[1])) read.set(m[1], file);
}
}
}
const missing = [...read]
.filter(([k]) => !named.has(k) && !NOT_CONFIG.has(k))
.map(([k, f]) => `${k} (read by ${f})`);
assert.deepEqual(
missing,
[],
`add each to .env.example (a \`# KEY=\` line with the reader is enough):\n${missing.join("\n")}`,
);
console.log(`env-example-covers-src: ${read.size} variables read, all named`);
+2 -1
View File
@@ -1,4 +1,5 @@
import type { Metadata } from "next";
import { orangeCatProjectUrl } from "@/config/orangecat";
import type { ReactNode } from "react";
import Link from "next/link";
import {
@@ -501,7 +502,7 @@ function Row({
label="OrangeCat"
href={
orangecatLive.has(r.orangecat.projectId)
? `https://orangecat.ch/projects/${r.orangecat.projectId}`
? orangeCatProjectUrl(r.orangecat.projectId)
: null
}
external
@@ -1,6 +1,7 @@
"use client";
import { useEffect, useState } from "react";
import { orangeCatProjectUrl } from "@/config/orangecat";
import { Cat } from "lucide-react";
type PublishState =
@@ -141,7 +142,7 @@ export function OrangeCatPublishButton({ projectId }: { projectId: string }) {
return (
<span className="inline-flex flex-wrap items-center gap-1.5">
<a
href={`https://orangecat.ch/projects/${state.orangecatProjectId}`}
href={orangeCatProjectUrl(state.orangecatProjectId)}
target="_blank"
rel="noreferrer"
className="ui-btn-ghost min-h-11 gap-1.5"
+4 -1
View File
@@ -37,7 +37,10 @@
export const APP_NAME = "Loki";
export const APP_SLUG = "loki";
export const APP_DOMAIN = "loki.orangecat.ch";
// Overridable so a copy of this repo serves its own name: NEXT_PUBLIC_ so the
// client bundle agrees with the server. `loki.orangecat.ch` is only bitbaum's.
// scripts/_brand.sh mirrors the fallback for shell; set APP_DOMAIN there too.
export const APP_DOMAIN = process.env.NEXT_PUBLIC_APP_DOMAIN ?? "loki.orangecat.ch";
// Was "Personal Systems" — the life-OS kicker that outlived the pivot and sat
// beside the logo on every page. Fleet rule: everything is beta; say so where
// the name is (2026-10-01 copy sweep).
+12
View File
@@ -14,6 +14,18 @@
* (ORANGECAT_API_BASE / ORANGECAT_OAUTH_ISSUER). */
export const ORANGECAT_BASE_FALLBACK = "https://orangecat.ch";
/** The public OrangeCat origin for links a person clicks (nav, project
* pages). NEXT_PUBLIC_ so the client bundle agrees with the server. */
export const ORANGECAT_PUBLIC_ORIGIN = (
process.env.NEXT_PUBLIC_ORANGECAT_URL ?? ORANGECAT_BASE_FALLBACK
).replace(/\/+$/, "");
/** A project's public page on OrangeCat. Was the literal
* `https://orangecat.ch/projects/…` in three components. */
export function orangeCatProjectUrl(projectId: string): string {
return `${ORANGECAT_PUBLIC_ORIGIN}/projects/${encodeURIComponent(projectId)}`;
}
/**
* The OrangeCat authorization server — the `iss` every OrangeCat token carries,
* and the origin its OIDC discovery and JWKS hang off. "Login with OrangeCat",
+2 -1
View File
@@ -1,4 +1,5 @@
import type { RegisterRow } from "./build";
import { orangeCatProjectUrl } from "@/config/orangecat";
import { PUBLIC_IDENTITY_ATTRS, type PublicIdentityAttr } from "@/config/project-attrs";
import type { RepoRecords } from "./repo-records";
@@ -190,7 +191,7 @@ export function layerFor(row: RegisterRow): MapLayer {
}
function orangecatUrl(row: RegisterRow): string | null {
return row.orangecat ? `https://orangecat.ch/projects/${row.orangecat.projectId}` : null;
return row.orangecat ? orangeCatProjectUrl(row.orangecat.projectId) : null;
}
function solonUrl(row: RegisterRow): string | null {