diff --git a/.env.example b/.env.example index f89f39090..18dbd3a67 100644 --- a/.env.example +++ b/.env.example @@ -14,27 +14,39 @@ GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= # ── Optional ───────────────────────────────────────────────────────────────── -# Timezone for cron jobs and schedule display (e.g. America/New_York) -COCKPIT_DEFAULT_TIMEZONE=Europe/Zurich +# Timezone for cron jobs and schedule display (e.g. America/New_York). +# Reads APP_DEFAULT_TIMEZONE first, then COCKPIT_DEFAULT_TIMEZONE (legacy). +APP_DEFAULT_TIMEZONE=Europe/Zurich + +# Locale for date/time formatting. APP_LOCALE preferred, COCKPIT_LOCALE accepted. +APP_LOCALE=de-CH # Docker only — Postgres password (must match DATABASE_URL above) POSTGRES_PASSWORD=changeme +# ── Brand alias scheme ─────────────────────────────────────────────────────── +# Every env var below is read as APP_ first, then COCKPIT_ as a +# legacy fallback (mirror of scripts/_brand.sh:_brand_env). Set whichever +# prefix matches your environment — both work, APP_* takes precedence. + # ── Daemon ⇄ Cloud bridge ──────────────────────────────────────────────────── -# When the local daemon talks to a remote Cockpit (e.g. cockpitapp.vercel.app) -# it authenticates with a bearer token. Two paths exist: +# When the local daemon talks to a remote app instance, it authenticates with +# a bearer token. Two paths exist: # # 1. Mint a per-user ck_* token from /settings (preferred, multi-tenant safe). -# 2. Use COCKPIT_DAEMON_TOKEN as a shared bearer — single-tenant only. +# 2. Use APP_DAEMON_TOKEN as a shared bearer — single-tenant only. # -# To enable path (2), set BOTH of these on the *server* (Vercel / wherever -# Cockpit is hosted). The flag is required because the token maps to the -# "default" user and must not be on by accident in multi-tenant deployments. -COCKPIT_DAEMON_TOKEN= -COCKPIT_ALLOW_LEGACY_DAEMON_TOKEN= +# To enable path (2), set BOTH of these on the *server*. The flag is required +# because the token maps to the "default" user and must not be on by accident +# in multi-tenant deployments. +APP_DAEMON_TOKEN= +APP_ALLOW_LEGACY_DAEMON_TOKEN= # Set to 1 in the local daemon's environment when a local Next.js dev server -# is running alongside a different cloud Cockpit (e.g. cockpitapp.vercel.app). -# Without this, the daemon prefers localhost:3000 (the local server's DB) and -# the cloud control panel's runtime state goes stale. -COCKPIT_DAEMON_FORCE_REMOTE= +# is running alongside a different cloud deployment. Without this, the daemon +# prefers localhost:3000 (the local server's DB) and the cloud control +# panel's runtime state goes stale. +APP_DAEMON_FORCE_REMOTE= + +# Override the daemon's remote base URL (defaults to APP_DOMAIN from brand.ts). +APP_BASE_URL= diff --git a/scripts/_brand.sh b/scripts/_brand.sh new file mode 100644 index 000000000..c66735448 --- /dev/null +++ b/scripts/_brand.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Single source of truth for the product brand on the shell side. +# Mirrors src/config/brand.ts on the TypeScript side. To rebrand the entire +# product, edit this file + src/config/brand.ts + the vercel.json alias + +# DNS at the registrar — that's it. +# +# Sourced by: cockpit-daemon.sh, agent-hook-bridge.sh, cockpit-beacon-window.sh, +# install-*.sh, beacon.py (via _beacon_config.py). + +# Display name. Appears in log lines, install prompts. +APP_NAME="Cockpit" + +# Lowercase kebab-case identifier. Used in /tmp/-* paths, env var +# prefixes, package names. Changing this requires migrating any on-disk +# state (running daemons should be restarted). +APP_SLUG="cockpit" + +# Canonical hostname for the remote deployment. Used by the daemon when no +# local server is reachable. Override via COCKPIT_BASE_URL / APP_BASE_URL. +APP_DOMAIN="cockpitapp.vercel.app" + +# Resolve an env var by name with both APP_* and COCKPIT_* prefixes, in that +# order, falling back to a default. Used to migrate env-var names gradually +# without breaking machines that already export COCKPIT_*. +# _brand_env DAEMON_TOKEN "" → $APP_DAEMON_TOKEN || $COCKPIT_DAEMON_TOKEN || "" +_brand_env() { + local suffix="$1" default="${2:-}" + local app_var="APP_${suffix}" legacy_var="COCKPIT_${suffix}" + echo "${!app_var:-${!legacy_var:-$default}}" +} + +# Convenience: build /tmp paths through APP_SLUG so a rename moves them +# automatically. Usage: _brand_tmp "run-${tab}" → /tmp/cockpit-run- +_brand_tmp() { + echo "/tmp/${APP_SLUG}-${1}" +} diff --git a/scripts/agent-hook-bridge.sh b/scripts/agent-hook-bridge.sh index ca1355221..eb1730def 100755 --- a/scripts/agent-hook-bridge.sh +++ b/scripts/agent-hook-bridge.sh @@ -8,11 +8,14 @@ if [ -z "$MODE" ]; then fi SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# Source brand SSOT (APP_NAME, APP_SLUG, _brand_env, _brand_tmp). +# shellcheck source=_brand.sh +source "$SCRIPT_DIR/_brand.sh" # Wire-format prefixes — must match CUSTOM_CHOICE_PREFIX / SWITCH_CHOICE_PREFIX in src/lib/constants/control.ts readonly CUSTOM_CHOICE_PREFIX="custom:" readonly SWITCH_CHOICE_PREFIX="switch:" -# Override via COCKPIT_URL env var for non-default ports or remote deployments. -readonly COCKPIT_URL="${COCKPIT_URL:-http://localhost:3000}" +# Override via APP_URL / APP_BASE_URL env var for non-default ports or remote deployments. +readonly APP_BASE_URL="$(_brand_env URL "http://localhost:3000")" python3 "$SCRIPT_DIR/sync-agent-runtime-config.py" >/dev/null 2>&1 || true # shellcheck source=/dev/null source "$SCRIPT_DIR/agent-hook-lib.sh" @@ -20,14 +23,19 @@ source "$SCRIPT_DIR/agent-hook-lib.sh" LOG=/tmp/agent-hooks.log log() { echo "[$(date '+%H:%M:%S')] ${MODE}: $*" >> "$LOG"; } -# Read per-user beacon settings from the Cockpit API (uses daemon token for auth). -# Falls back to Python file reader when Cockpit is offline. -_BEACON_TOKEN="${COCKPIT_DAEMON_TOKEN:-$(grep -m1 '^COCKPIT_DAEMON_TOKEN=' "$SCRIPT_DIR/../.env.local" 2>/dev/null | cut -d= -f2-)}" +_token_from_env_or_file() { + local key="$1" + echo "$(_brand_env "$key" "$(grep -m1 "^COCKPIT_${key}=" "$SCRIPT_DIR/../.env.local" 2>/dev/null | cut -d= -f2-)")" +} + +# Read per-user beacon settings from the API (uses daemon token for auth). +# Falls back to Python file reader when the app is offline. +_BEACON_TOKEN="$(_token_from_env_or_file DAEMON_TOKEN)" _BEACON_SETTINGS_JSON="" if [ -n "$_BEACON_TOKEN" ]; then _BEACON_SETTINGS_JSON=$(curl -sf --max-time 2 \ -H "Authorization: Bearer ${_BEACON_TOKEN}" \ - "${COCKPIT_URL}/api/beacon-settings" 2>/dev/null || true) + "${APP_BASE_URL}/api/beacon-settings" 2>/dev/null || true) fi if [ -n "$_BEACON_SETTINGS_JSON" ]; then @@ -60,25 +68,25 @@ patch_project_state() { local field="$2" local iso_now token iso_now=$(date -Iseconds) - token="${COCKPIT_DAEMON_TOKEN:-$(grep -m1 '^COCKPIT_DAEMON_TOKEN=' "$SCRIPT_DIR/../.env.local" 2>/dev/null | cut -d= -f2-)}" - curl -sf -X PATCH "${COCKPIT_URL}/api/project-states/${tab_name}" \ + token="$(_token_from_env_or_file DAEMON_TOKEN)" + curl -sf -X PATCH "${APP_BASE_URL}/api/project-states/${tab_name}" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${token}" \ -d "{\"tabName\":\"${tab_name}\",\"${field}\":\"${iso_now}\"}" &>/dev/null & } # Finishes an orchestration_runs row with the captured handoff so dispatch -# can learn from outcomes. The run id was written to /tmp/cockpit-run- +# can learn from outcomes. The run id was written to $(_brand_tmp "run-") # at dispatch time. Fire-and-forget — never blocks the stop hook. finish_orchestration_run() { local tab_name="$1" local session_file="$2" - local run_sentinel="/tmp/cockpit-run-${tab_name}" + local run_sentinel="$(_brand_tmp "run-${tab_name}")" [ -f "$run_sentinel" ] || return 0 local run_id token done_line next_line tests_line todos_line health_line run_id=$(cat "$run_sentinel" 2>/dev/null | tr -d '[:space:]') [ -z "$run_id" ] && return 0 - token="${COCKPIT_DAEMON_TOKEN:-$(grep -m1 '^COCKPIT_DAEMON_TOKEN=' "$SCRIPT_DIR/../.env.local" 2>/dev/null | cut -d= -f2-)}" + token="$(_token_from_env_or_file DAEMON_TOKEN)" done_line=""; next_line=""; tests_line=""; todos_line=""; health_line="" if [ -f "$session_file" ]; then done_line=$(grep -m1 '^done:' "$session_file" 2>/dev/null | sed 's/^done:[[:space:]]*//') @@ -92,7 +100,7 @@ finish_orchestration_run() { --arg d "$done_line" --arg n "$next_line" --arg t "$tests_line" \ --arg td "$todos_line" --arg h "$health_line" \ '{summary: {done: $d, next: $n, tests: $t, todos: $td, health: $h}}') - curl -sf -X POST "${COCKPIT_URL}/api/orchestration/runs/${run_id}/finish" \ + curl -sf -X POST "${APP_BASE_URL}/api/orchestration/runs/${run_id}/finish" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${token}" \ -d "$payload" &>/dev/null & @@ -131,7 +139,7 @@ switch_agent_and_continue() { case "$agent" in codex|gemini) - prompt_file="/tmp/cockpit-${agent}-prompt-$(date +%s)-$$.txt" + prompt_file="$(_brand_tmp "${agent}-prompt-$(date +%s)-$$.txt")" printf '%s' "$prompt" > "$prompt_file" runner="$SCRIPT_DIR/run-${agent}-task.sh" command=$(printf "bash %q %q %q %q %q" "$runner" "$tab_name" "$project_dir" "$prompt_file" "$([ "$agent" = "gemini" ] && echo auto || echo gpt-5.4)") @@ -224,7 +232,7 @@ handle_stop() { # Moon toggle in the control panel. We skip the popup entirely; the web-app # ReadyBanner already short-circuits its countdown to 0 in sleep mode, so # the auto-inject loop runs from the browser side as long as Cockpit is open. - if [ -f /tmp/cockpit-sleep-mode ]; then + if [ -f "$(_brand_tmp 'sleep-mode')" ]; then log "sleep mode on — skipping popup (web-app ReadyBanner handles auto-inject)" exit 0 fi diff --git a/scripts/cockpit-daemon.sh b/scripts/cockpit-daemon.sh index cecf60c05..11ca352db 100755 --- a/scripts/cockpit-daemon.sh +++ b/scripts/cockpit-daemon.sh @@ -16,30 +16,34 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# Source brand SSOT (APP_NAME, APP_SLUG, APP_DOMAIN, _brand_env, _brand_tmp). +# shellcheck source=_brand.sh +source "$SCRIPT_DIR/_brand.sh" + # Source shared zellij helpers (inject_prompt, etc.) # shellcheck source=agent-hook-lib.sh source "$SCRIPT_DIR/agent-hook-lib.sh" 2>/dev/null || { - echo "[daemon] ERROR: cannot source agent-hook-lib.sh" >&2 + echo "[${APP_SLUG}-daemon] ERROR: cannot source agent-hook-lib.sh" >&2 exit 1 } _LOCAL_URL="http://localhost:3000" -_REMOTE_URL="${COCKPIT_BASE_URL:-https://cockpitapp.vercel.app}" -POLL_INTERVAL="${COCKPIT_POLL_INTERVAL:-8}" -PUSH_INTERVAL="${COCKPIT_PUSH_INTERVAL:-2}" -DRY_RUN="${COCKPIT_DRY_RUN:-0}" -TOKEN="${COCKPIT_DAEMON_TOKEN:-}" +_REMOTE_URL="$(_brand_env BASE_URL "https://${APP_DOMAIN}")" +POLL_INTERVAL="$(_brand_env POLL_INTERVAL 8)" +PUSH_INTERVAL="$(_brand_env PUSH_INTERVAL 2)" +DRY_RUN="$(_brand_env DRY_RUN 0)" +TOKEN="$(_brand_env DAEMON_TOKEN "")" CONF_FILE="${AGENT_PROJECTS_CONF:-${CLAUDE_PROJECTS_CONF:-$HOME/.config/agent-projects.conf}}" # Cache file shared between the main poll loop and the background push loop. -_URL_CACHE="/tmp/cockpit-daemon-url-$$" +_URL_CACHE="$(_brand_tmp "daemon-url-$$")" _URL_TTL=30 # re-detect every 30 s if [ -z "$TOKEN" ]; then - echo "[daemon] ERROR: COCKPIT_DAEMON_TOKEN is not set" >&2 + echo "[${APP_SLUG}-daemon] ERROR: ${APP_SLUG^^}_DAEMON_TOKEN is not set" >&2 exit 1 fi -log() { echo "[daemon] $(date '+%H:%M:%S') $*"; } +log() { echo "[${APP_SLUG}-daemon] $(date '+%H:%M:%S') $*"; } # Returns the best available base URL: local server if reachable, else remote. # Result is cached in $_URL_CACHE for $_URL_TTL seconds so we don't probe on @@ -55,11 +59,12 @@ _base_url() { echo "$cached"; return fi fi - # COCKPIT_DAEMON_FORCE_REMOTE=1 skips the local probe entirely. Use this when - # a local dev server is running with a different DB than the remote — without - # it, the daemon prefers local and remote runtime state goes stale (the - # control panel on cockpitapp.vercel.app shows daemonLastPushedAt frozen). - if [ "${COCKPIT_DAEMON_FORCE_REMOTE:-0}" = "1" ]; then + # APP_DAEMON_FORCE_REMOTE=1 (or COCKPIT_DAEMON_FORCE_REMOTE=1 legacy) skips + # the local probe entirely. Use this when a local dev server is running with + # a different DB than the remote — without it, the daemon prefers local and + # remote runtime state goes stale (the cloud control panel shows + # daemonLastPushedAt frozen). + if [ "$(_brand_env DAEMON_FORCE_REMOTE 0)" = "1" ]; then url="$_REMOTE_URL" elif curl -sf --max-time 0.8 "$_LOCAL_URL/api/health" >/dev/null 2>&1; then url="$_LOCAL_URL" @@ -72,9 +77,9 @@ _base_url() { # Warm the cache at startup, retrying briefly so the local app has time to boot. _init_base_url() { - if [ "${COCKPIT_DAEMON_FORCE_REMOTE:-0}" = "1" ]; then + if [ "$(_brand_env DAEMON_FORCE_REMOTE 0)" = "1" ]; then echo "$(date +%s) $_REMOTE_URL" > "$_URL_CACHE" - log "COCKPIT_DAEMON_FORCE_REMOTE=1 — using $_REMOTE_URL (skipping local probe)" + log "DAEMON_FORCE_REMOTE=1 — using $_REMOTE_URL (skipping local probe)" return fi local i=0 @@ -124,7 +129,7 @@ mark_done() { _is_user_typing_in_tab() { local tab="$1" now now=$(date +%s) - for f in /tmp/cockpit-typing-*; do + for f in "$(_brand_tmp 'typing-')"*; do [ -f "$f" ] || continue local ftab fts ftab=$(sed -n '1p' "$f" 2>/dev/null | xargs 2>/dev/null) @@ -213,7 +218,7 @@ execute_inject() { rm -f "/tmp/agent-closing-${tab}" "/tmp/claude-closing-${tab}" # Cancel any open web-beacon popup for this tab (mirrors cancelActiveBeaconSessions). # Sets choice:"" so the React beacon client knows to self-close. - local _bdir="/tmp/cockpit-beacon" + local _bdir="$(_brand_tmp 'beacon')" if [ -d "$_bdir" ]; then for _bf in "$_bdir"/*.json; do [ -f "$_bf" ] || continue @@ -665,7 +670,7 @@ while true; do # In cloud mode the run row was created on the server side; here we just # land the id where the stop hook expects to read it. if [ -n "$run_id" ]; then - printf '%s' "$run_id" > "/tmp/cockpit-run-${tab}" + printf '%s' "$run_id" > "$(_brand_tmp "run-${tab}")" fi execute_inject "$id" "$tab" "$prompt" "$prompt_key" "$prompt_label" ;; diff --git a/src/app/api/beacon/route.ts b/src/app/api/beacon/route.ts index 7f37af7de..5af5525be 100644 --- a/src/app/api/beacon/route.ts +++ b/src/app/api/beacon/route.ts @@ -7,8 +7,9 @@ import { isAgentId, looksLikeAgentCapacityIssue, resolveNextAvailableAgent, type import { DEFAULT_BEACON_COUNTDOWN_S, DEFAULT_POPUP_MODE } from "@/lib/constants/control"; import { getApiUserId } from "@/lib/session"; import { getBeaconSettings } from "@/db/queries/beacon-settings"; +import { APP_SLUG } from "@/config/brand"; -const BEACON_DIR = "/tmp/cockpit-beacon"; +const BEACON_DIR = `/tmp/${APP_SLUG}-beacon`; export type BeaconSession = { id: string; diff --git a/src/app/api/beacon/sse/route.ts b/src/app/api/beacon/sse/route.ts index 91024001b..87aacac28 100644 --- a/src/app/api/beacon/sse/route.ts +++ b/src/app/api/beacon/sse/route.ts @@ -4,11 +4,12 @@ import { execSync } from "child_process"; import type { BeaconSession } from "@/app/api/beacon/route"; import { isRuntimeAvailable } from "@/lib/runtime"; import { parseProjectsConf } from "@/lib/agent-config"; +import { APP_SLUG } from "@/config/brand"; export const runtime = "nodejs"; export const dynamic = "force-dynamic"; -const BEACON_DIR = "/tmp/cockpit-beacon"; +const BEACON_DIR = `/tmp/${APP_SLUG}-beacon`; const POLL_MS = 150; const KEEPALIVE_MS = 20_000; diff --git a/src/app/api/beacon/transcribe/route.ts b/src/app/api/beacon/transcribe/route.ts index 6ee45d39b..15fe6bd92 100644 --- a/src/app/api/beacon/transcribe/route.ts +++ b/src/app/api/beacon/transcribe/route.ts @@ -15,10 +15,10 @@ const execFileAsync = promisify(execFile); // Resolve scripts/transcribe.py for both deployment modes: // • `npm run dev` → cwd = repo root → scripts/transcribe.py -// • cockpit-app.service → cwd = .next/standalone → ../../scripts/transcribe.py -// COCKPIT_SCRIPTS_DIR can override (e.g. when the standalone bundle is moved). +// • -app.service → cwd = .next/standalone → ../../scripts/transcribe.py +// APP_SCRIPTS_DIR (or legacy COCKPIT_SCRIPTS_DIR) can override (e.g. when the standalone bundle is moved). function resolveTranscribePy(): string { - const envDir = process.env.COCKPIT_SCRIPTS_DIR; + const envDir = process.env.APP_SCRIPTS_DIR ?? process.env.COCKPIT_SCRIPTS_DIR; const candidates = [ envDir && join(envDir, "transcribe.py"), join(process.cwd(), "scripts/transcribe.py"), diff --git a/src/app/api/control/auto-continue/route.ts b/src/app/api/control/auto-continue/route.ts index f46be5576..cd000078a 100644 --- a/src/app/api/control/auto-continue/route.ts +++ b/src/app/api/control/auto-continue/route.ts @@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server"; import { writeFileSync, unlinkSync } from "fs"; import { readJsonBody, z } from "@/lib/api/route-helpers"; import { getApiUserId } from "@/lib/session"; +import { APP_SLUG } from "@/config/brand"; const Body = z.object({ tab: z.string().max(200), @@ -9,9 +10,9 @@ const Body = z.object({ }); // Sentinel file read by the beacon hook bridge on init so it respects the -// web-app pause state even when Cockpit is not running at popup open time. +// web-app pause state even when the app server is not running at popup open time. function sentinelPath(tab: string) { - return `/tmp/cockpit-auto-continue-${tab.toLowerCase()}`; + return `/tmp/${APP_SLUG}-auto-continue-${tab.toLowerCase()}`; } export async function POST(req: NextRequest) { diff --git a/src/app/api/control/sleep-mode/route.ts b/src/app/api/control/sleep-mode/route.ts index cd96f7b89..dd20b3b79 100644 --- a/src/app/api/control/sleep-mode/route.ts +++ b/src/app/api/control/sleep-mode/route.ts @@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server"; import { writeFileSync, unlinkSync } from "fs"; import { readJsonBody, z } from "@/lib/api/route-helpers"; import { getApiUserId } from "@/lib/session"; +import { APP_SLUG } from "@/config/brand"; const Body = z.object({ enabled: z.boolean(), @@ -10,7 +11,7 @@ const Body = z.object({ // Daemon-readable sentinel. agent-hook-bridge.sh:handle_stop can short-circuit // the popup launch entirely while this file exists, so the user really doesn't // see anything pop while they're away. -const SENTINEL = "/tmp/cockpit-sleep-mode"; +const SENTINEL = `/tmp/${APP_SLUG}-sleep-mode`; export async function POST(req: NextRequest) { const userId = await getApiUserId(); diff --git a/src/app/api/project/bootstrap/route.ts b/src/app/api/project/bootstrap/route.ts index 7d6d54a52..468dab81f 100644 --- a/src/app/api/project/bootstrap/route.ts +++ b/src/app/api/project/bootstrap/route.ts @@ -5,6 +5,7 @@ import { readJsonBody, z } from "@/lib/api/route-helpers"; import { auth } from "@/auth"; import { createUserProject } from "@/db/queries/user-projects"; import { isRuntimeAvailable } from "@/lib/runtime"; +import { APP_NAME } from "@/config/brand"; import os from "os"; import path from "path"; import fs from "fs"; @@ -107,12 +108,12 @@ export async function POST(req: NextRequest) { } } - // ── 5. Register project in Cockpit DB ──────────────────────────────────── + // ── 5. Register project in ${APP_NAME} DB ──────────────────────────────── try { await createUserProject({ userId: session.user.id, name, dirPath: dir, gitUrl: gitUrl || undefined }); - steps.push({ step: "Register in Cockpit", ok: true }); + steps.push({ step: `Register in ${APP_NAME}`, ok: true }); } catch { - steps.push({ step: "Register in Cockpit", ok: false, detail: "Non-fatal — project still created" }); + steps.push({ step: `Register in ${APP_NAME}`, ok: false, detail: "Non-fatal — project still created" }); } // ── Build the initial Claude Code brief ─────────────────────────────────── @@ -137,7 +138,7 @@ export async function POST(req: NextRequest) { ` \`\`\`bash`, ` npx create-next-app@latest . --typescript --tailwind --app --src-dir --import-alias "@/*" --yes`, ` \`\`\``, - `2. Follow Cockpit's engineering standards (CLAUDE.md if present, or use: Drizzle ORM, server components, semantic design tokens, no \`any\`).`, + `2. Follow ${APP_NAME}'s engineering standards (CLAUDE.md if present, or use: Drizzle ORM, server components, semantic design tokens, no \`any\`).`, `3. Build the core MVP — ship something playable within this session.`, `4. Set up Vercel: \`vercel --yes\` — get a live URL.`, dbUrl ? `5. Add DATABASE_URL to \`.env.local\` and \`vercel env add DATABASE_URL\`.` : `5. Create a Neon/Supabase database and add DATABASE_URL.`, diff --git a/src/app/beacon/live/BeaconLiveClient.tsx b/src/app/beacon/live/BeaconLiveClient.tsx index 994698387..f4f5a8251 100644 --- a/src/app/beacon/live/BeaconLiveClient.tsx +++ b/src/app/beacon/live/BeaconLiveClient.tsx @@ -6,6 +6,7 @@ import Link from "next/link"; import { ArrowRight } from "lucide-react"; import type { BeaconSession } from "@/app/api/beacon/route"; import { BeaconPageClient } from "@/app/beacon/[id]/BeaconClient"; +import { APP_NAME } from "@/config/brand"; export function BeaconLiveClient({ initialSession = null }: { initialSession?: BeaconSession | null }) { const [session, setSession] = useState(initialSession); @@ -55,7 +56,7 @@ export function BeaconLiveClient({ initialSession = null }: { initialSession?: B if (!session) { return (
- Cockpit + {APP_NAME}

No agent session waiting

This window will fill in the moment one stops.

diff --git a/src/app/invite/layout.tsx b/src/app/invite/layout.tsx index 509c56f2e..25cbafb63 100644 --- a/src/app/invite/layout.tsx +++ b/src/app/invite/layout.tsx @@ -1,5 +1,6 @@ import type { Metadata } from "next"; -export const metadata: Metadata = { title: "Join Cockpit" }; +import { APP_NAME } from "@/config/brand"; +export const metadata: Metadata = { title: `Join ${APP_NAME}` }; export default function InviteLayout({ children }: { children: React.ReactNode }) { return <>{children}; } diff --git a/src/app/setup/page.tsx b/src/app/setup/page.tsx index cb7e6096f..5a67e7b7a 100644 --- a/src/app/setup/page.tsx +++ b/src/app/setup/page.tsx @@ -5,6 +5,7 @@ import { useRouter } from "next/navigation"; import Link from "next/link"; import { postJson } from "@/lib/api/fetch"; import { ROUTES } from "@/config/auth"; +import { APP_NAME } from "@/config/brand"; import { AuthShell, AuthCard, AuthField, AuthInput, AuthSubmitButton, AuthIconBadge, AuthHeading, } from "@/components/auth/AuthShell"; @@ -40,7 +41,7 @@ export default function SetupPage() { ✦} - title="Set up Cockpit" + title={`Set up ${APP_NAME}`} description="Create your admin account to get started." /> diff --git a/src/app/u/[username]/page.tsx b/src/app/u/[username]/page.tsx index 6ebcf4c5a..57eada351 100644 --- a/src/app/u/[username]/page.tsx +++ b/src/app/u/[username]/page.tsx @@ -13,6 +13,7 @@ import { CockpitMark } from "@/components/shell/CockpitMark"; import { getPublicProjects } from "@/db/queries/user-projects"; import { listThoughts } from "@/lib/thoughts-content"; import { HEALTH_TAG_STYLE } from "@/config/ui"; +import { APP_NAME } from "@/config/brand"; import type { DevLogEntry } from "@/db/schema/user-projects"; export async function generateMetadata({ @@ -22,10 +23,10 @@ export async function generateMetadata({ }): Promise { const { username } = await params; const user = await getUser(username); - if (!user) return { title: "Not Found — Cockpit" }; + if (!user) return { title: `Not Found — ${APP_NAME}` }; return { - title: `${user.name ?? username} — Cockpit`, - description: `${user.name ?? username}'s builder profile on Cockpit`, + title: `${user.name ?? username} — ${APP_NAME}`, + description: `${user.name ?? username}'s builder profile on ${APP_NAME}`, }; } diff --git a/src/app/whitepaper/page.tsx b/src/app/whitepaper/page.tsx index 794200a53..3f994e0fd 100644 --- a/src/app/whitepaper/page.tsx +++ b/src/app/whitepaper/page.tsx @@ -5,9 +5,10 @@ import type { Metadata } from "next"; import { PublicSurface } from "@/components/public/PublicSurface"; import { parseThoughtBlocks } from "@/lib/thoughts-content"; import { ROUTES } from "@/config/auth"; +import { APP_NAME } from "@/config/brand"; export const metadata: Metadata = { - title: "Whitepaper — Cockpit", + title: `Whitepaper — ${APP_NAME}`, description: "A technical architecture for sustained autonomous execution across many projects simultaneously.", }; @@ -146,7 +147,7 @@ export default function WhitepaperPage() { {/* Footer CTA */}

Ready to close the execution gap?

-

Start using Cockpit as your builder operating system.

+

Start using {APP_NAME} as your builder operating system.

Get started → diff --git a/src/auth.config.ts b/src/auth.config.ts index 5bdcec6ac..042cdf403 100644 --- a/src/auth.config.ts +++ b/src/auth.config.ts @@ -35,8 +35,9 @@ export const authConfig = { // routes enforce the real auth check via getApiUserId/getBearerUserId. const authHeader = request.headers.get("authorization") ?? ""; if (authHeader.startsWith("Bearer ck_")) return true; - const daemonToken = process.env.COCKPIT_DAEMON_TOKEN; - const legacyAllowed = process.env.COCKPIT_ALLOW_LEGACY_DAEMON_TOKEN === "1"; + // Edge runtime — inline the alias logic instead of importing to keep the bundle tiny. + const daemonToken = process.env.APP_DAEMON_TOKEN ?? process.env.COCKPIT_DAEMON_TOKEN; + const legacyAllowed = (process.env.APP_ALLOW_LEGACY_DAEMON_TOKEN ?? process.env.COCKPIT_ALLOW_LEGACY_DAEMON_TOKEN) === "1"; if (legacyAllowed && daemonToken && authHeader === `Bearer ${daemonToken}`) return true; // On Vercel, the Edge Runtime sees the deployment URL (cockpit-orangecat.vercel.app) diff --git a/src/components/auth/SignInForm.tsx b/src/components/auth/SignInForm.tsx index a38ced37d..900c00f9f 100644 --- a/src/components/auth/SignInForm.tsx +++ b/src/components/auth/SignInForm.tsx @@ -4,6 +4,7 @@ import { signIn } from "next-auth/react"; import { useState, Suspense } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { ROUTES } from "@/config/auth"; +import { APP_NAME } from "@/config/brand"; import { AuthShell, AuthCard, AuthField, AuthInput, AuthSubmitButton, AuthDivider, AuthHeading, AuthSecondaryButton, @@ -111,7 +112,7 @@ function FormInner({ {/* Mode tabs — only show owner key tab when LOCAL_AUTH_PASSWORD is configured */} diff --git a/src/components/control/bootstrap-modal-steps.tsx b/src/components/control/bootstrap-modal-steps.tsx index a1b3dcca0..0ff839393 100644 --- a/src/components/control/bootstrap-modal-steps.tsx +++ b/src/components/control/bootstrap-modal-steps.tsx @@ -2,6 +2,7 @@ import { Loader2, Sparkles, CheckCircle, XCircle, Copy, Rocket, ArrowLeft } from "lucide-react"; import { cn } from "@/lib/utils"; +import { APP_NAME } from "@/config/brand"; export interface Brief { name: string; @@ -201,7 +202,7 @@ export function CreatingStep({ name }: { name: string }) {

{name}

-

GitHub repo · git init · Neon database · Cockpit registration

+

GitHub repo · git init · Neon database · {APP_NAME} registration

); diff --git a/src/components/control/project-intent-panel.tsx b/src/components/control/project-intent-panel.tsx index bbfdd38b5..ca669ab61 100644 --- a/src/components/control/project-intent-panel.tsx +++ b/src/components/control/project-intent-panel.tsx @@ -5,6 +5,7 @@ import { Eraser, Loader2 } from "lucide-react"; import { useMicComposer } from "@/hooks/use-mic-composer"; import { postJson } from "@/lib/api/fetch"; import { PRIMARY_INTENTS, ACTION_INTENTS, MORE_INTENTS } from "@/config/control-intents"; +import { APP_NAME } from "@/config/brand"; import type { OrchestrationTaskIntentId } from "@/lib/orchestration"; import type { ProjectState } from "@/lib/control-types"; import { PromptInput } from "./prompt-input"; @@ -84,8 +85,8 @@ export function IntentButtonPanel({ autoContinueEnabled, onToggleAutoContinue, statusLabel: autoContinueEnabled - ? "Auto-continue ready: Cockpit can send the next queued prompt when the agent waits." - : "Auto-continue paused: Cockpit will wait for you before sending more work.", + ? `Auto-continue ready: ${APP_NAME} can send the next queued prompt when the agent waits.` + : `Auto-continue paused: ${APP_NAME} will wait for you before sending more work.`, }; const recentPrompts = project.recentCustomPrompts.slice(0, isRunning ? 3 : 5); diff --git a/src/components/settings/AgentTokenSettings.tsx b/src/components/settings/AgentTokenSettings.tsx index fdb5f9686..49543e3ed 100644 --- a/src/components/settings/AgentTokenSettings.tsx +++ b/src/components/settings/AgentTokenSettings.tsx @@ -3,6 +3,7 @@ import { useState, useEffect } from "react"; import { Copy, Check, Plus, Trash2, Loader2, Terminal } from "lucide-react"; import { postJson, deleteJson } from "@/lib/api/fetch"; +import { APP_NAME } from "@/config/brand"; type TokenMeta = { id: string; @@ -68,7 +69,7 @@ export function AgentTokenSettings() {

Agent Tokens

- Authenticate the Cockpit agent daemon on any machine. Run{" "} + Authenticate the {APP_NAME} agent daemon on any machine. Run{" "} npx @cockpit/agent init {" "} diff --git a/src/config/brand.ts b/src/config/brand.ts index 23a36e62e..57c22386e 100644 --- a/src/config/brand.ts +++ b/src/config/brand.ts @@ -1,3 +1,25 @@ -export const APP_NAME = "Cockpit"; -export const APP_KICKER = "Personal Systems"; +// Single source of truth for the product brand on the TypeScript side. +// scripts/_brand.sh mirrors APP_NAME / APP_SLUG / APP_DOMAIN for shell. +// To rebrand the entire product, edit this file + scripts/_brand.sh + the +// vercel.json alias + DNS at the registrar — that's it. +// +// Conventions: +// APP_NAME Display string. Appears in , sidebar, marketing. +// APP_SLUG Lowercase kebab. Used in URLs, file paths, env-var prefixes. +// APP_DOMAIN Canonical hostname (no scheme). Used in callbacks, emails, copy. + +export const APP_NAME = "Cockpit"; +export const APP_SLUG = "cockpit"; +export const APP_DOMAIN = "cockpitapp.vercel.app"; +export const APP_KICKER = "Personal Systems"; export const APP_DESCRIPTION = "Command your agents, projects, and personal systems from one workspace."; + +// Helpers — never hardcode these patterns in components. +export const APP_URL = `https://${APP_DOMAIN}`; +export const APP_PROFILE_URL = (username: string) => `${APP_DOMAIN}/u/${username}`; + +// Email "From" address. Kept separate from APP_DOMAIN because the email host +// is usually a different domain than the app host (vercel.app is hostable but +// not a deliverable email domain). Override via EMAIL_FROM env var. +export const APP_EMAIL_FROM = `${APP_NAME} <noreply@${APP_SLUG}.app>`; +export const APP_TAGLINE = "your life operating system"; diff --git a/src/lib/agent-config.ts b/src/lib/agent-config.ts index 908058fd9..d668cef9f 100644 --- a/src/lib/agent-config.ts +++ b/src/lib/agent-config.ts @@ -18,6 +18,7 @@ */ import fs from "fs"; import path from "path"; +import { APP_SLUG } from "@/config/brand"; // Lazy accessors — evaluated at request time, not module load time. // Module-level path.join(process.env.HOME, …) causes Turbopack's NFT tracer @@ -46,7 +47,7 @@ export const stateFile = { prompt: (tab: string) => path.join("/tmp", /*turbopackIgnore: true*/ `agent-current-prompt-${tab}`), lock: (tab: string) => path.join("/tmp", /*turbopackIgnore: true*/ `agent-stop-active-${tab}`), queue: (tab: string) => path.join("/tmp", /*turbopackIgnore: true*/ `agent-queue-${tab}`), - run: (tab: string) => path.join("/tmp", /*turbopackIgnore: true*/ `cockpit-run-${tab}`), + run: (tab: string) => path.join("/tmp", /*turbopackIgnore: true*/ `${APP_SLUG}-run-${tab}`), // Legacy names — no new files are written with these names; only used to delete stale on-disk files. claudeReady: (tab: string) => path.join("/tmp", /*turbopackIgnore: true*/ `claude-ready-${tab}`), diff --git a/src/lib/brand-env.ts b/src/lib/brand-env.ts new file mode 100644 index 000000000..6e60f96ed --- /dev/null +++ b/src/lib/brand-env.ts @@ -0,0 +1,13 @@ +// Brand-prefixed env-var resolver. Reads APP_<KEY> first, then COCKPIT_<KEY> +// (legacy), then returns the default. Lets the app rename its brand prefix +// without breaking machines that already export COCKPIT_*-prefixed variables. +// +// Mirror of scripts/_brand.sh:_brand_env so shell + TS resolve identically. +export function envAlias(key: string, fallback = ""): string { + return process.env[`APP_${key}`] ?? process.env[`COCKPIT_${key}`] ?? fallback; +} + +// Boolean form — "1" means true, anything else is false. +export function envAliasBool(key: string): boolean { + return envAlias(key) === "1"; +} diff --git a/src/lib/constants.ts b/src/lib/constants.ts index d29f17026..22bf52d57 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -1,5 +1,7 @@ import { homedir } from "os"; import path from "path"; +import { envAlias } from "./brand-env"; +import { APP_SLUG } from "@/config/brand"; export const HOME = homedir(); const OPENCLAW_DIR = `${HOME}/.openclaw`; @@ -7,25 +9,25 @@ const WORKSPACE_DIR = `${OPENCLAW_DIR}/workspace`; export const TOOLS_DIR = `${WORKSPACE_DIR}/tools`; export const CRON_FILE = path.join(HOME, ".openclaw", "cron", "jobs.json"); -export const DEFAULT_USER_NAME = process.env.COCKPIT_DEFAULT_USER_NAME ?? "George"; +export const DEFAULT_USER_NAME = envAlias("DEFAULT_USER_NAME", "George"); /** External ID of the owner entity — used to exclude the user from people queries */ -export const DEFAULT_USER_EXTERNAL_ID = process.env.COCKPIT_DEFAULT_USER_EXTERNAL_ID ?? "george"; -export const TELEGRAM_CHAT_ID = process.env.COCKPIT_TELEGRAM_CHAT_ID ?? ""; +export const DEFAULT_USER_EXTERNAL_ID = envAlias("DEFAULT_USER_EXTERNAL_ID", "george"); +export const TELEGRAM_CHAT_ID = envAlias("TELEGRAM_CHAT_ID"); export const OPENCLAW_GATEWAY_URL = process.env.OPENCLAW_GATEWAY_URL ?? "http://127.0.0.1:18789"; -/** Source attribution for rows created via the Cockpit UI. Distinguishes - * manual-from-app rows from the seeded knowledge.sqlite + contact-resolver +/** Source attribution for rows created via the app UI. Distinguishes + * manual-from-app rows from seeded knowledge.sqlite + contact-resolver * imports so future audit/cleanup queries can filter by origin. */ -export const SOURCE_COCKPIT_UI = "cockpit-ui"; +export const SOURCE_COCKPIT_UI = `${APP_SLUG}-ui`; /** How many days of history the /habits page (and its heatmap) covers. */ export const HABIT_HISTORY_DAYS = 30; /** Default timezone for schedule-related operations (cron jobs, calendar). */ -export const DEFAULT_TIMEZONE = process.env.COCKPIT_DEFAULT_TIMEZONE ?? "Europe/Zurich"; +export const DEFAULT_TIMEZONE = envAlias("DEFAULT_TIMEZONE", "Europe/Zurich"); /** Locale used for date/time formatting throughout the app. */ -export const APP_LOCALE = process.env.COCKPIT_LOCALE ?? "de-CH"; +export const APP_LOCALE = envAlias("LOCALE", "de-CH"); /** Lookahead windows for the /today summary cards. */ export const GOALS_DUE_SOON_DAYS = 14; diff --git a/src/lib/daemon-auth.ts b/src/lib/daemon-auth.ts index 3cfc0ca6e..c88b2df20 100644 --- a/src/lib/daemon-auth.ts +++ b/src/lib/daemon-auth.ts @@ -1,6 +1,7 @@ import { NextRequest } from "next/server"; import { getDefaultUser } from "@/db/queries/users"; import { validateAgentToken } from "@/db/queries/agent-tokens"; +import { envAlias, envAliasBool } from "./brand-env"; function extractBearer(req: NextRequest): string | null { const auth = req.headers.get("authorization") ?? ""; @@ -8,21 +9,18 @@ function extractBearer(req: NextRequest): string | null { } function legacyDaemonTokenEnabled(): boolean { - return Boolean( - process.env.COCKPIT_DAEMON_TOKEN && - process.env.COCKPIT_ALLOW_LEGACY_DAEMON_TOKEN === "1", - ); + return Boolean(envAlias("DAEMON_TOKEN")) && envAliasBool("ALLOW_LEGACY_DAEMON_TOKEN"); } /** - * Returns true if the request carries a valid COCKPIT_DAEMON_TOKEN bearer credential. + * Returns true if the request carries a valid daemon token bearer credential. * @deprecated Use ck_* agent tokens. This path only resolves when - * COCKPIT_ALLOW_LEGACY_DAEMON_TOKEN=1 is set — it always maps to the "default" - * user and is not multi-tenant safe. + * APP_ALLOW_LEGACY_DAEMON_TOKEN=1 (or COCKPIT_ALLOW_LEGACY_DAEMON_TOKEN=1) is + * set — it always maps to the "default" user and is not multi-tenant safe. */ export function isDaemonRequest(req: NextRequest): boolean { if (!legacyDaemonTokenEnabled()) return false; - return extractBearer(req) === process.env.COCKPIT_DAEMON_TOKEN; + return extractBearer(req) === envAlias("DAEMON_TOKEN"); } /** Looks up the default user's ID for daemon-authenticated requests. */ @@ -45,7 +43,7 @@ export async function getBearerUserId(req: NextRequest): Promise<string | null> return result?.userId ?? null; } - if (legacyDaemonTokenEnabled() && bearer === process.env.COCKPIT_DAEMON_TOKEN) { + if (legacyDaemonTokenEnabled() && bearer === envAlias("DAEMON_TOKEN")) { return getDaemonUserId(); } diff --git a/src/lib/email.ts b/src/lib/email.ts index 9d20a826e..679de584e 100644 --- a/src/lib/email.ts +++ b/src/lib/email.ts @@ -1,5 +1,6 @@ import { Resend } from "resend"; import { ROUTES } from "@/config/auth"; +import { APP_NAME, APP_EMAIL_FROM, APP_TAGLINE } from "@/config/brand"; // Lazy — Resend throws at construction if key is empty string, which breaks next build let _resend: Resend | null = null; @@ -8,7 +9,7 @@ function getResend(): Resend { return _resend; } -const FROM = process.env.EMAIL_FROM ?? "Cockpit <noreply@cockpit.app>"; +const FROM = process.env.EMAIL_FROM ?? APP_EMAIL_FROM; export function appUrl(): string { return process.env.NEXTAUTH_URL ?? process.env.APP_URL ?? "http://localhost:3000"; @@ -45,7 +46,7 @@ function emailShell(content: string): string { <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> - <title>Cockpit + ${APP_NAME} @@ -53,7 +54,7 @@ function emailShell(content: string): string {
- ⚡ Cockpit + ⚡ ${APP_NAME}
@@ -63,7 +64,7 @@ function emailShell(content: string): string {
- Cockpit — your life operating system
+ ${APP_NAME} — ${APP_TAGLINE}
${url.replace(/^https?:\/\//, "")}
@@ -88,46 +89,46 @@ function small(text: string): string { // ─── Templates ─────────────────────────────────────────────────────────────── export function verifyEmailTemplate(verifyUrl: string, name: string) { - const subject = "Verify your Cockpit email"; + const subject = `Verify your ${APP_NAME} email`; const html = emailShell(`

Verify your email

- ${p(`Hi ${name}, welcome to Cockpit. Click the button below to verify your email address and activate your account.`)} + ${p(`Hi ${name}, welcome to ${APP_NAME}. Click the button below to verify your email address and activate your account.`)}
${btn(verifyUrl, "Verify email →")}
${small(`Or paste this link in your browser:
${verifyUrl}`)} - ${small("This link expires in 24 hours. If you didn't create a Cockpit account, you can safely ignore this email.")} + ${small(`This link expires in 24 hours. If you didn't create a ${APP_NAME} account, you can safely ignore this email.`)} `); - const text = `Hi ${name}, verify your Cockpit email:\n\n${verifyUrl}\n\nThis link expires in 24 hours.`; + const text = `Hi ${name}, verify your ${APP_NAME} email:\n\n${verifyUrl}\n\nThis link expires in 24 hours.`; return { subject, html, text }; } export function welcomeEmailTemplate(name: string) { const url = appUrl(); - const subject = "Welcome to Cockpit"; + const subject = `Welcome to ${APP_NAME}`; const html = emailShell(`

You're in, ${name} ⚡

- ${p("Cockpit is your command center for everything that matters — projects, goals, habits, people, money, and AI agents.")} + ${p(`${APP_NAME} is your command center for everything that matters — projects, goals, habits, people, money, and AI agents.`)} ${p("Here's what to do first:")}
  • Add your projects and connect GitHub
  • Set up your daily habits and goals
  • Dispatch your first AI agent from the Control panel
-
${btn(url + ROUTES.APP_HOME, "Open Cockpit →")}
+
${btn(url + ROUTES.APP_HOME, `Open ${APP_NAME} →`)}
${small("Questions? Reply to this email — we read everything.")} `); - const text = `Welcome to Cockpit, ${name}!\n\nOpen your dashboard: ${url}${ROUTES.APP_HOME}`; + const text = `Welcome to ${APP_NAME}, ${name}!\n\nOpen your dashboard: ${url}${ROUTES.APP_HOME}`; return { subject, html, text }; } export function resetPasswordEmailTemplate(resetUrl: string) { - const subject = "Reset your Cockpit password"; + const subject = `Reset your ${APP_NAME} password`; const html = emailShell(`

Reset your password

- ${p("Someone requested a password reset for your Cockpit account. Click the button below to set a new password.")} + ${p(`Someone requested a password reset for your ${APP_NAME} account. Click the button below to set a new password.`)}
${btn(resetUrl, "Reset password →")}
${small(`Or paste this link in your browser:
${resetUrl}`)} ${small("This link expires in 2 hours. If you didn't request this, you can safely ignore this email — your password won't change.")} `); - const text = `Reset your Cockpit password:\n\n${resetUrl}\n\nThis link expires in 2 hours. If you didn't request this, ignore it.`; + const text = `Reset your ${APP_NAME} password:\n\n${resetUrl}\n\nThis link expires in 2 hours. If you didn't request this, ignore it.`; return { subject, html, text }; } diff --git a/src/lib/session.ts b/src/lib/session.ts index 5fc00a74d..33fdc1b8b 100644 --- a/src/lib/session.ts +++ b/src/lib/session.ts @@ -4,6 +4,7 @@ import { auth } from "@/auth"; import { DEFAULT_USER_NAME } from "@/lib/constants"; import { ROUTES } from "@/config/auth"; import { validateAgentToken } from "@/db/queries/agent-tokens"; +import { envAlias, envAliasBool } from "@/lib/brand-env"; /** * Returns the authenticated user's ID, or null if there is no session. @@ -59,13 +60,13 @@ export async function getApiUserId(): Promise { } // Legacy env-var token → "default" user. Opt-in only; not multi-tenant safe. - const envToken = process.env.COCKPIT_DAEMON_TOKEN; - const legacyAllowed = process.env.COCKPIT_ALLOW_LEGACY_DAEMON_TOKEN === "1"; + const envToken = envAlias("DAEMON_TOKEN"); + const legacyAllowed = envAliasBool("ALLOW_LEGACY_DAEMON_TOKEN"); if (envToken && legacyAllowed && bearer === envToken) { if (!warnedDeprecatedDaemonToken) { warnedDeprecatedDaemonToken = true; console.warn( - "[session] COCKPIT_DAEMON_TOKEN is deprecated and unsafe in multi-tenant deployments. " + + "[session] DAEMON_TOKEN bearer is deprecated and unsafe in multi-tenant deployments. " + "Mint a ck_* agent token from /settings and use it instead.", ); }