mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 11:07:40 +01:00
refactor(brand): broker the brand through one TS + one shell SSOT
Audit before this commit: 642 case-insensitive 'cockpit' refs across 119
files; only 2 callers actually used src/config/brand.ts. A rename was an
hour of careful sed touching things like email templates, auth UI copy,
/tmp paths, env var names, log prefixes — easy to miss one.
After this commit: every UI string, every /tmp sentinel, every env var,
and every shell log prefix derives from one of two files:
src/config/brand.ts APP_NAME · APP_SLUG · APP_DOMAIN · APP_EMAIL_FROM
APP_KICKER · APP_DESCRIPTION · APP_TAGLINE
APP_URL · APP_PROFILE_URL(username)
scripts/_brand.sh $APP_NAME · $APP_SLUG · $APP_DOMAIN
_brand_env <KEY> <default> → $APP_<KEY> || $COCKPIT_<KEY>
_brand_tmp <name> → /tmp/$APP_SLUG-<name>
UI broker (TS): SignInForm, project-intent-panel, bootstrap-modal-steps,
AgentTokenSettings, setup/page, whitepaper/page, /u/[username]/page,
invite/layout, beacon/live/BeaconLiveClient, api/project/bootstrap, and
src/lib/email all import APP_NAME from brand.ts. /tmp paths in
agent-config:stateFile.run, control/sleep-mode/route, control/auto-continue/route,
beacon/route, beacon/sse/route derive from APP_SLUG.
Shell broker: cockpit-daemon.sh and agent-hook-bridge.sh source _brand.sh,
read env via _brand_env (so APP_DAEMON_TOKEN and APP_BASE_URL work alongside
the existing COCKPIT_* names), write /tmp paths via _brand_tmp, log under
[$APP_SLUG-daemon] / [$APP_SLUG-bridge].
Env aliases (TS): src/lib/brand-env.ts mirrors _brand_env. src/lib/constants,
src/lib/daemon-auth, src/lib/session, src/auth.config (Edge), and
api/beacon/transcribe all resolve env via the alias scheme. Existing
COCKPIT_*-prefixed env vars on machines in the wild keep working — APP_*
takes precedence when both are set.
To rebrand the entire product after this commit: edit APP_NAME / APP_SLUG /
APP_DOMAIN in src/config/brand.ts AND in scripts/_brand.sh, swap the
vercel.json alias, point DNS at the new registrar. That's it — no other
code touches the name.
Out of scope (deliberately): content/* essays and whitepaper.md (editorial
voice, not mechanical), README.md (would distract from this commit's
purpose), .env example DATABASE_URL (config value, not code), file names
themselves (CockpitMark.tsx, cockpit-daemon.sh — those become git mv after
a chosen new name).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
27 files changed
+226
-112
No files matched your search
+26
-14
@@ -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_<KEY> first, then COCKPIT_<KEY> 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=
|
||||
@@ -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/<slug>-* 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-<tab>
|
||||
_brand_tmp() {
|
||||
echo "/tmp/${APP_SLUG}-${1}"
|
||||
}
|
||||
@@ -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-<tab>
|
||||
# can learn from outcomes. The run id was written to $(_brand_tmp "run-<tab>")
|
||||
# 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
|
||||
|
||||
+24
-19
@@ -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"
|
||||
;;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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>-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"),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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.`,
|
||||
|
||||
@@ -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<BeaconSession | null>(initialSession);
|
||||
@@ -55,7 +56,7 @@ export function BeaconLiveClient({ initialSession = null }: { initialSession?: B
|
||||
if (!session) {
|
||||
return (
|
||||
<div className="flex h-screen flex-col items-center justify-center gap-6 bg-surface-base p-8 select-none">
|
||||
<Image src="/icon.svg" alt="Cockpit" width={56} height={56} className="opacity-60" />
|
||||
<Image src="/icon.svg" alt={APP_NAME} width={56} height={56} className="opacity-60" />
|
||||
<div className="text-center">
|
||||
<p className="text-sm font-medium text-text-secondary">No agent session waiting</p>
|
||||
<p className="mt-1 text-xs text-text-tertiary">This window will fill in the moment one stops.</p>
|
||||
|
||||
@@ -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}</>;
|
||||
}
|
||||
@@ -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() {
|
||||
<AuthShell>
|
||||
<AuthHeading
|
||||
badge={<AuthIconBadge>✦</AuthIconBadge>}
|
||||
title="Set up Cockpit"
|
||||
title={`Set up ${APP_NAME}`}
|
||||
description="Create your admin account to get started."
|
||||
/>
|
||||
|
||||
|
||||
@@ -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<Metadata> {
|
||||
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}`,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */}
|
||||
<div className="mt-24 border-t border-white/[0.08] pt-16 text-center">
|
||||
<p className="mb-2 text-sm font-medium text-white/60">Ready to close the execution gap?</p>
|
||||
<p className="mb-8 text-sm text-white/30">Start using Cockpit as your builder operating system.</p>
|
||||
<p className="mb-8 text-sm text-white/30">Start using {APP_NAME} as your builder operating system.</p>
|
||||
<div className="flex flex-wrap items-center justify-center gap-3">
|
||||
<Link href={ROUTES.SIGN_IN} className="ui-public-primary-action">
|
||||
Get started →
|
||||
|
||||
+3
-2
@@ -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)
|
||||
|
||||
@@ -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({
|
||||
<AuthShell>
|
||||
<AuthHeading
|
||||
title="Welcome back"
|
||||
description="Sign in to your Cockpit account."
|
||||
description={`Sign in to your ${APP_NAME} account.`}
|
||||
/>
|
||||
|
||||
{/* Mode tabs — only show owner key tab when LOCAL_AUTH_PASSWORD is configured */}
|
||||
|
||||
@@ -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 }) {
|
||||
<Loader2 className="h-8 w-8 animate-spin text-accent-text" />
|
||||
<div className="text-center">
|
||||
<p className="font-medium text-text-primary">{name}</p>
|
||||
<p className="mt-1 text-sm text-text-tertiary">GitHub repo · git init · Neon database · Cockpit registration</p>
|
||||
<p className="mt-1 text-sm text-text-tertiary">GitHub repo · git init · Neon database · {APP_NAME} registration</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
<section className="ui-settings-section">
|
||||
<h2 className="font-medium text-text-primary">Agent Tokens</h2>
|
||||
<p className="text-sm text-text-tertiary">
|
||||
Authenticate the Cockpit agent daemon on any machine. Run{" "}
|
||||
Authenticate the {APP_NAME} agent daemon on any machine. Run{" "}
|
||||
<code className="rounded bg-surface-raised px-1 py-0.5 font-mono text-xs text-text-secondary">
|
||||
npx @cockpit/agent init
|
||||
</code>{" "}
|
||||
|
||||
+24
-2
@@ -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 <title>, 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";
|
||||
@@ -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}`),
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
+10
-8
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+16
-15
@@ -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</title>
|
||||
<title>${APP_NAME}</title>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;">
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 16px;">
|
||||
@@ -53,7 +54,7 @@ function emailShell(content: string): string {
|
||||
<table width="540" cellpadding="0" cellspacing="0" style="max-width:540px;width:100%;">
|
||||
<!-- Header -->
|
||||
<tr><td style="background:#09090b;padding:20px 32px;border-radius:12px 12px 0 0;text-align:center;">
|
||||
<span style="color:#ffffff;font-size:17px;font-weight:700;letter-spacing:-0.3px;">⚡ Cockpit</span>
|
||||
<span style="color:#ffffff;font-size:17px;font-weight:700;letter-spacing:-0.3px;">⚡ ${APP_NAME}</span>
|
||||
</td></tr>
|
||||
<!-- Body -->
|
||||
<tr><td style="background:#ffffff;padding:40px 32px;border-radius:0 0 12px 12px;color:#09090b;">
|
||||
@@ -63,7 +64,7 @@ function emailShell(content: string): string {
|
||||
<!-- Footer -->
|
||||
<table width="540" cellpadding="0" cellspacing="0" style="max-width:540px;width:100%;margin-top:20px;">
|
||||
<tr><td style="text-align:center;color:#71717a;font-size:12px;line-height:1.6;">
|
||||
Cockpit — your life operating system<br>
|
||||
${APP_NAME} — ${APP_TAGLINE}<br>
|
||||
<a href="${url}" style="color:#71717a;text-decoration:underline;">${url.replace(/^https?:\/\//, "")}</a>
|
||||
</td></tr>
|
||||
</table>
|
||||
@@ -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(`
|
||||
<h2 style="margin:0 0 8px 0;font-size:22px;font-weight:700;color:#09090b;">Verify your email</h2>
|
||||
${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.`)}
|
||||
<div style="text-align:center;">${btn(verifyUrl, "Verify email →")}</div>
|
||||
${small(`Or paste this link in your browser:<br><a href="${verifyUrl}" style="color:#6b7280;word-break:break-all;">${verifyUrl}</a>`)}
|
||||
${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(`
|
||||
<h2 style="margin:0 0 8px 0;font-size:22px;font-weight:700;color:#09090b;">You're in, ${name} ⚡</h2>
|
||||
${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:")}
|
||||
<ul style="margin:0 0 16px 0;padding-left:20px;color:#374151;font-size:15px;line-height:1.8;">
|
||||
<li>Add your projects and connect GitHub</li>
|
||||
<li>Set up your daily habits and goals</li>
|
||||
<li>Dispatch your first AI agent from the Control panel</li>
|
||||
</ul>
|
||||
<div style="text-align:center;">${btn(url + ROUTES.APP_HOME, "Open Cockpit →")}</div>
|
||||
<div style="text-align:center;">${btn(url + ROUTES.APP_HOME, `Open ${APP_NAME} →`)}</div>
|
||||
${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(`
|
||||
<h2 style="margin:0 0 8px 0;font-size:22px;font-weight:700;color:#09090b;">Reset your password</h2>
|
||||
${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.`)}
|
||||
<div style="text-align:center;">${btn(resetUrl, "Reset password →")}</div>
|
||||
${small(`Or paste this link in your browser:<br><a href="${resetUrl}" style="color:#6b7280;word-break:break-all;">${resetUrl}</a>`)}
|
||||
${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 };
|
||||
}
|
||||
+4
-3
@@ -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<string | null> {
|
||||
}
|
||||
|
||||
// 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.",
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user