mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
Introduce bind presets for deployment setup
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
e1bf9d66a7
commit
2a84e53c1b
35 changed files with 915 additions and 176 deletions
|
|
@ -177,6 +177,14 @@ Open source. Self-hosted. No Paperclip account required.
|
|||
npx paperclipai onboard --yes
|
||||
```
|
||||
|
||||
That quickstart path now defaults to trusted local loopback mode for the fastest first run. To start in authenticated/private mode instead, choose a bind preset explicitly:
|
||||
|
||||
```bash
|
||||
npx paperclipai onboard --yes --bind lan
|
||||
# or:
|
||||
npx paperclipai onboard --yes --bind tailnet
|
||||
```
|
||||
|
||||
If you already have Paperclip configured, rerunning `onboard` keeps the existing config in place. Use `paperclipai configure` to edit settings.
|
||||
|
||||
Or manually:
|
||||
|
|
|
|||
35
cli/src/__tests__/network-bind.test.ts
Normal file
35
cli/src/__tests__/network-bind.test.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { resolveRuntimeBind, validateConfiguredBindMode } from "@paperclipai/shared";
|
||||
|
||||
describe("network bind helpers", () => {
|
||||
it("rejects non-loopback bind modes in local_trusted", () => {
|
||||
expect(
|
||||
validateConfiguredBindMode({
|
||||
deploymentMode: "local_trusted",
|
||||
deploymentExposure: "private",
|
||||
bind: "lan",
|
||||
host: "0.0.0.0",
|
||||
}),
|
||||
).toContain("local_trusted requires server.bind=loopback");
|
||||
});
|
||||
|
||||
it("resolves tailnet bind using the detected tailscale address", () => {
|
||||
const resolved = resolveRuntimeBind({
|
||||
bind: "tailnet",
|
||||
host: "127.0.0.1",
|
||||
tailnetBindHost: "100.64.0.8",
|
||||
});
|
||||
|
||||
expect(resolved.errors).toEqual([]);
|
||||
expect(resolved.host).toBe("100.64.0.8");
|
||||
});
|
||||
|
||||
it("requires a custom bind host when bind=custom", () => {
|
||||
const resolved = resolveRuntimeBind({
|
||||
bind: "custom",
|
||||
host: "127.0.0.1",
|
||||
});
|
||||
|
||||
expect(resolved.errors).toContain("server.customBindHost is required when server.bind=custom");
|
||||
});
|
||||
});
|
||||
|
|
@ -74,6 +74,11 @@ function createExistingConfigFixture() {
|
|||
return { configPath, configText: fs.readFileSync(configPath, "utf8") };
|
||||
}
|
||||
|
||||
function createFreshConfigPath() {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "paperclip-onboard-fresh-"));
|
||||
return path.join(root, ".paperclip", "config.json");
|
||||
}
|
||||
|
||||
describe("onboard", () => {
|
||||
beforeEach(() => {
|
||||
process.env = { ...ORIGINAL_ENV };
|
||||
|
|
@ -105,4 +110,43 @@ describe("onboard", () => {
|
|||
expect(fs.existsSync(`${fixture.configPath}.backup`)).toBe(false);
|
||||
expect(fs.existsSync(path.join(path.dirname(fixture.configPath), ".env"))).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps --yes onboarding on local trusted loopback defaults", async () => {
|
||||
const configPath = createFreshConfigPath();
|
||||
process.env.HOST = "0.0.0.0";
|
||||
process.env.PAPERCLIP_BIND = "lan";
|
||||
|
||||
await onboard({ config: configPath, yes: true, invokedByRun: true });
|
||||
|
||||
const raw = JSON.parse(fs.readFileSync(configPath, "utf8")) as PaperclipConfig;
|
||||
expect(raw.server.deploymentMode).toBe("local_trusted");
|
||||
expect(raw.server.exposure).toBe("private");
|
||||
expect(raw.server.bind).toBe("loopback");
|
||||
expect(raw.server.host).toBe("127.0.0.1");
|
||||
});
|
||||
|
||||
it("supports authenticated/private quickstart bind presets", async () => {
|
||||
const configPath = createFreshConfigPath();
|
||||
|
||||
await onboard({ config: configPath, yes: true, invokedByRun: true, bind: "tailnet" });
|
||||
|
||||
const raw = JSON.parse(fs.readFileSync(configPath, "utf8")) as PaperclipConfig;
|
||||
expect(raw.server.deploymentMode).toBe("authenticated");
|
||||
expect(raw.server.exposure).toBe("private");
|
||||
expect(raw.server.bind).toBe("tailnet");
|
||||
expect(raw.server.host).toBe("0.0.0.0");
|
||||
});
|
||||
|
||||
it("ignores deployment env overrides during --yes quickstart", async () => {
|
||||
const configPath = createFreshConfigPath();
|
||||
process.env.PAPERCLIP_DEPLOYMENT_MODE = "authenticated";
|
||||
|
||||
await onboard({ config: configPath, yes: true, invokedByRun: true });
|
||||
|
||||
const raw = JSON.parse(fs.readFileSync(configPath, "utf8")) as PaperclipConfig;
|
||||
expect(raw.server.deploymentMode).toBe("local_trusted");
|
||||
expect(raw.server.exposure).toBe("private");
|
||||
expect(raw.server.bind).toBe("loopback");
|
||||
expect(raw.server.host).toBe("127.0.0.1");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,24 +1,21 @@
|
|||
import { inferBindModeFromHost } from "@paperclipai/shared";
|
||||
import type { PaperclipConfig } from "../config/schema.js";
|
||||
import type { CheckResult } from "./index.js";
|
||||
|
||||
function isLoopbackHost(host: string) {
|
||||
const normalized = host.trim().toLowerCase();
|
||||
return normalized === "127.0.0.1" || normalized === "localhost" || normalized === "::1";
|
||||
}
|
||||
|
||||
export function deploymentAuthCheck(config: PaperclipConfig): CheckResult {
|
||||
const mode = config.server.deploymentMode;
|
||||
const exposure = config.server.exposure;
|
||||
const auth = config.auth;
|
||||
const bind = config.server.bind ?? inferBindModeFromHost(config.server.host);
|
||||
|
||||
if (mode === "local_trusted") {
|
||||
if (!isLoopbackHost(config.server.host)) {
|
||||
if (bind !== "loopback") {
|
||||
return {
|
||||
name: "Deployment/auth mode",
|
||||
status: "fail",
|
||||
message: `local_trusted requires loopback host binding (found ${config.server.host})`,
|
||||
message: `local_trusted requires loopback binding (found ${bind})`,
|
||||
canRepair: false,
|
||||
repairHint: "Run `paperclipai configure --section server` and set host to 127.0.0.1",
|
||||
repairHint: "Run `paperclipai configure --section server` and choose Local trusted / loopback reachability",
|
||||
};
|
||||
}
|
||||
return {
|
||||
|
|
@ -86,6 +83,6 @@ export function deploymentAuthCheck(config: PaperclipConfig): CheckResult {
|
|||
return {
|
||||
name: "Deployment/auth mode",
|
||||
status: "pass",
|
||||
message: `Mode ${mode}/${exposure} with auth URL mode ${auth.baseUrlMode}`,
|
||||
message: `Mode ${mode}/${exposure} with bind ${bind} and auth URL mode ${auth.baseUrlMode}`,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import * as p from "@clack/prompts";
|
|||
import pc from "picocolors";
|
||||
import { and, eq, gt, isNull } from "drizzle-orm";
|
||||
import { createDb, instanceUserRoles, invites } from "@paperclipai/db";
|
||||
import { inferBindModeFromHost } from "@paperclipai/shared";
|
||||
import { loadPaperclipEnvFile } from "../config/env.js";
|
||||
import { readConfig, resolveConfigPath } from "../config/store.js";
|
||||
|
||||
|
|
@ -40,9 +41,13 @@ function resolveBaseUrl(configPath?: string, explicitBaseUrl?: string) {
|
|||
if (config?.auth.baseUrlMode === "explicit" && config.auth.publicBaseUrl) {
|
||||
return config.auth.publicBaseUrl.replace(/\/+$/, "");
|
||||
}
|
||||
const host = config?.server.host ?? "localhost";
|
||||
const bind = config?.server.bind ?? inferBindModeFromHost(config?.server.host);
|
||||
const host =
|
||||
bind === "custom"
|
||||
? config?.server.customBindHost ?? config?.server.host ?? "localhost"
|
||||
: config?.server.host ?? "localhost";
|
||||
const port = config?.server.port ?? 3100;
|
||||
const publicHost = host === "0.0.0.0" ? "localhost" : host;
|
||||
const publicHost = host === "0.0.0.0" || bind === "lan" ? "localhost" : host;
|
||||
return `http://${publicHost}:${port}`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ function defaultConfig(): PaperclipConfig {
|
|||
server: {
|
||||
deploymentMode: "local_trusted",
|
||||
exposure: "private",
|
||||
bind: "loopback",
|
||||
host: "127.0.0.1",
|
||||
port: 3100,
|
||||
allowedHostnames: [],
|
||||
|
|
|
|||
|
|
@ -3,10 +3,14 @@ import path from "node:path";
|
|||
import pc from "picocolors";
|
||||
import {
|
||||
AUTH_BASE_URL_MODES,
|
||||
BIND_MODES,
|
||||
DEPLOYMENT_EXPOSURES,
|
||||
DEPLOYMENT_MODES,
|
||||
SECRET_PROVIDERS,
|
||||
STORAGE_PROVIDERS,
|
||||
inferBindModeFromHost,
|
||||
resolveRuntimeBind,
|
||||
type BindMode,
|
||||
type AuthBaseUrlMode,
|
||||
type DeploymentExposure,
|
||||
type DeploymentMode,
|
||||
|
|
@ -23,6 +27,7 @@ import { promptLogging } from "../prompts/logging.js";
|
|||
import { defaultSecretsConfig } from "../prompts/secrets.js";
|
||||
import { defaultStorageConfig, promptStorage } from "../prompts/storage.js";
|
||||
import { promptServer } from "../prompts/server.js";
|
||||
import { buildPresetServerConfig } from "../config/server-bind.js";
|
||||
import {
|
||||
describeLocalInstancePaths,
|
||||
expandHomePrefix,
|
||||
|
|
@ -46,6 +51,7 @@ type OnboardOptions = {
|
|||
run?: boolean;
|
||||
yes?: boolean;
|
||||
invokedByRun?: boolean;
|
||||
bind?: BindMode;
|
||||
};
|
||||
|
||||
type OnboardDefaults = Pick<PaperclipConfig, "database" | "logging" | "server" | "auth" | "storage" | "secrets">;
|
||||
|
|
@ -59,6 +65,9 @@ const ONBOARD_ENV_KEYS = [
|
|||
"PAPERCLIP_DB_BACKUP_DIR",
|
||||
"PAPERCLIP_DEPLOYMENT_MODE",
|
||||
"PAPERCLIP_DEPLOYMENT_EXPOSURE",
|
||||
"PAPERCLIP_BIND",
|
||||
"PAPERCLIP_BIND_HOST",
|
||||
"PAPERCLIP_TAILNET_BIND_HOST",
|
||||
"HOST",
|
||||
"PORT",
|
||||
"SERVE_UI",
|
||||
|
|
@ -104,29 +113,62 @@ function resolvePathFromEnv(rawValue: string | undefined): string | null {
|
|||
return path.resolve(expandHomePrefix(rawValue.trim()));
|
||||
}
|
||||
|
||||
function quickstartDefaultsFromEnv(): {
|
||||
function describeServerBinding(server: Pick<PaperclipConfig["server"], "bind" | "customBindHost" | "host" | "port">): string {
|
||||
const bind = server.bind ?? inferBindModeFromHost(server.host);
|
||||
const detail =
|
||||
bind === "custom"
|
||||
? server.customBindHost ?? server.host
|
||||
: bind === "tailnet"
|
||||
? "detected tailscale address"
|
||||
: server.host;
|
||||
return `${bind}${detail ? ` (${detail})` : ""}:${server.port}`;
|
||||
}
|
||||
|
||||
function quickstartDefaultsFromEnv(opts?: { preferTrustedLocal?: boolean }): {
|
||||
defaults: OnboardDefaults;
|
||||
usedEnvKeys: string[];
|
||||
ignoredEnvKeys: Array<{ key: string; reason: string }>;
|
||||
} {
|
||||
const preferTrustedLocal = opts?.preferTrustedLocal ?? false;
|
||||
const instanceId = resolvePaperclipInstanceId();
|
||||
const defaultStorage = defaultStorageConfig();
|
||||
const defaultSecrets = defaultSecretsConfig();
|
||||
const databaseUrl = process.env.DATABASE_URL?.trim() || undefined;
|
||||
const publicUrl =
|
||||
process.env.PAPERCLIP_PUBLIC_URL?.trim() ||
|
||||
process.env.PAPERCLIP_AUTH_PUBLIC_BASE_URL?.trim() ||
|
||||
process.env.BETTER_AUTH_URL?.trim() ||
|
||||
process.env.BETTER_AUTH_BASE_URL?.trim() ||
|
||||
undefined;
|
||||
const deploymentMode =
|
||||
parseEnumFromEnv<DeploymentMode>(process.env.PAPERCLIP_DEPLOYMENT_MODE, DEPLOYMENT_MODES) ?? "local_trusted";
|
||||
const publicUrl = preferTrustedLocal
|
||||
? undefined
|
||||
: (
|
||||
process.env.PAPERCLIP_PUBLIC_URL?.trim() ||
|
||||
process.env.PAPERCLIP_AUTH_PUBLIC_BASE_URL?.trim() ||
|
||||
process.env.BETTER_AUTH_URL?.trim() ||
|
||||
process.env.BETTER_AUTH_BASE_URL?.trim() ||
|
||||
undefined
|
||||
);
|
||||
const deploymentMode = preferTrustedLocal
|
||||
? "local_trusted"
|
||||
: (parseEnumFromEnv<DeploymentMode>(process.env.PAPERCLIP_DEPLOYMENT_MODE, DEPLOYMENT_MODES) ?? "local_trusted");
|
||||
const deploymentExposureFromEnv = parseEnumFromEnv<DeploymentExposure>(
|
||||
process.env.PAPERCLIP_DEPLOYMENT_EXPOSURE,
|
||||
DEPLOYMENT_EXPOSURES,
|
||||
);
|
||||
const deploymentExposure =
|
||||
deploymentMode === "local_trusted" ? "private" : (deploymentExposureFromEnv ?? "private");
|
||||
const bindFromEnv = parseEnumFromEnv<BindMode>(process.env.PAPERCLIP_BIND, BIND_MODES);
|
||||
const customBindHostFromEnv = process.env.PAPERCLIP_BIND_HOST?.trim() || undefined;
|
||||
const hostFromEnv = process.env.HOST?.trim() || undefined;
|
||||
const configuredBindHost = customBindHostFromEnv ?? hostFromEnv;
|
||||
const bind = preferTrustedLocal
|
||||
? "loopback"
|
||||
: (
|
||||
deploymentMode === "local_trusted"
|
||||
? "loopback"
|
||||
: (bindFromEnv ?? (configuredBindHost ? inferBindModeFromHost(configuredBindHost) : "lan"))
|
||||
);
|
||||
const resolvedBind = resolveRuntimeBind({
|
||||
bind,
|
||||
host: hostFromEnv ?? (bind === "loopback" ? "127.0.0.1" : "0.0.0.0"),
|
||||
customBindHost: customBindHostFromEnv,
|
||||
tailnetBindHost: process.env.PAPERCLIP_TAILNET_BIND_HOST?.trim(),
|
||||
});
|
||||
const authPublicBaseUrl = publicUrl;
|
||||
const authBaseUrlModeFromEnv = parseEnumFromEnv<AuthBaseUrlMode>(
|
||||
process.env.PAPERCLIP_AUTH_BASE_URL_MODE,
|
||||
|
|
@ -183,7 +225,9 @@ function quickstartDefaultsFromEnv(): {
|
|||
server: {
|
||||
deploymentMode,
|
||||
exposure: deploymentExposure,
|
||||
host: process.env.HOST ?? "127.0.0.1",
|
||||
bind: resolvedBind.bind,
|
||||
...(resolvedBind.customBindHost ? { customBindHost: resolvedBind.customBindHost } : {}),
|
||||
host: resolvedBind.host,
|
||||
port: Number(process.env.PORT) || 3100,
|
||||
allowedHostnames: Array.from(new Set([...allowedHostnamesFromEnv, ...(hostnameFromPublicUrl ? [hostnameFromPublicUrl] : [])])),
|
||||
serveUi: parseBooleanFromEnv(process.env.SERVE_UI) ?? true,
|
||||
|
|
@ -220,12 +264,49 @@ function quickstartDefaultsFromEnv(): {
|
|||
},
|
||||
};
|
||||
const ignoredEnvKeys: Array<{ key: string; reason: string }> = [];
|
||||
if (preferTrustedLocal) {
|
||||
const forcedLocalReason = "Ignored because --yes quickstart forces trusted local loopback defaults";
|
||||
for (const key of [
|
||||
"PAPERCLIP_DEPLOYMENT_MODE",
|
||||
"PAPERCLIP_DEPLOYMENT_EXPOSURE",
|
||||
"PAPERCLIP_BIND",
|
||||
"PAPERCLIP_BIND_HOST",
|
||||
"HOST",
|
||||
"PAPERCLIP_AUTH_BASE_URL_MODE",
|
||||
"PAPERCLIP_AUTH_PUBLIC_BASE_URL",
|
||||
"PAPERCLIP_PUBLIC_URL",
|
||||
"BETTER_AUTH_URL",
|
||||
"BETTER_AUTH_BASE_URL",
|
||||
] as const) {
|
||||
if (process.env[key] !== undefined) {
|
||||
ignoredEnvKeys.push({ key, reason: forcedLocalReason });
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deploymentMode === "local_trusted" && process.env.PAPERCLIP_DEPLOYMENT_EXPOSURE !== undefined) {
|
||||
ignoredEnvKeys.push({
|
||||
key: "PAPERCLIP_DEPLOYMENT_EXPOSURE",
|
||||
reason: "Ignored because deployment mode local_trusted always forces private exposure",
|
||||
});
|
||||
}
|
||||
if (deploymentMode === "local_trusted" && process.env.PAPERCLIP_BIND !== undefined) {
|
||||
ignoredEnvKeys.push({
|
||||
key: "PAPERCLIP_BIND",
|
||||
reason: "Ignored because deployment mode local_trusted always uses loopback reachability",
|
||||
});
|
||||
}
|
||||
if (deploymentMode === "local_trusted" && process.env.PAPERCLIP_BIND_HOST !== undefined) {
|
||||
ignoredEnvKeys.push({
|
||||
key: "PAPERCLIP_BIND_HOST",
|
||||
reason: "Ignored because deployment mode local_trusted always uses loopback reachability",
|
||||
});
|
||||
}
|
||||
if (deploymentMode === "local_trusted" && process.env.HOST !== undefined) {
|
||||
ignoredEnvKeys.push({
|
||||
key: "HOST",
|
||||
reason: "Ignored because deployment mode local_trusted always uses loopback reachability",
|
||||
});
|
||||
}
|
||||
|
||||
const ignoredKeySet = new Set(ignoredEnvKeys.map((entry) => entry.key));
|
||||
const usedEnvKeys = ONBOARD_ENV_KEYS.filter(
|
||||
|
|
@ -239,6 +320,10 @@ function canCreateBootstrapInviteImmediately(config: Pick<PaperclipConfig, "data
|
|||
}
|
||||
|
||||
export async function onboard(opts: OnboardOptions): Promise<void> {
|
||||
if (opts.bind && !["loopback", "lan", "tailnet"].includes(opts.bind)) {
|
||||
throw new Error(`Unsupported bind preset for onboard: ${opts.bind}. Use loopback, lan, or tailnet.`);
|
||||
}
|
||||
|
||||
printPaperclipCliBanner();
|
||||
p.intro(pc.bgCyan(pc.black(" paperclipai onboard ")));
|
||||
const configPath = resolveConfigPath(opts.config);
|
||||
|
|
@ -293,7 +378,7 @@ export async function onboard(opts: OnboardOptions): Promise<void> {
|
|||
`Database: ${existingConfig.database.mode}`,
|
||||
existingConfig.llm ? `LLM: ${existingConfig.llm.provider}` : "LLM: not configured",
|
||||
`Logging: ${existingConfig.logging.mode} -> ${existingConfig.logging.logDir}`,
|
||||
`Server: ${existingConfig.server.deploymentMode}/${existingConfig.server.exposure} @ ${existingConfig.server.host}:${existingConfig.server.port}`,
|
||||
`Server: ${existingConfig.server.deploymentMode}/${existingConfig.server.exposure} @ ${describeServerBinding(existingConfig.server)}`,
|
||||
`Allowed hosts: ${existingConfig.server.allowedHostnames.length > 0 ? existingConfig.server.allowedHostnames.join(", ") : "(loopback only)"}`,
|
||||
`Auth URL mode: ${existingConfig.auth.baseUrlMode}${existingConfig.auth.publicBaseUrl ? ` (${existingConfig.auth.publicBaseUrl})` : ""}`,
|
||||
`Storage: ${existingConfig.storage.provider}`,
|
||||
|
|
@ -336,7 +421,13 @@ export async function onboard(opts: OnboardOptions): Promise<void> {
|
|||
|
||||
let setupMode: SetupMode = "quickstart";
|
||||
if (opts.yes) {
|
||||
p.log.message(pc.dim("`--yes` enabled: using Quickstart defaults."));
|
||||
p.log.message(
|
||||
pc.dim(
|
||||
opts.bind
|
||||
? `\`--yes\` enabled: using Quickstart defaults with bind=${opts.bind}.`
|
||||
: "`--yes` enabled: using Quickstart defaults.",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
const setupModeChoice = await p.select({
|
||||
message: "Choose setup path",
|
||||
|
|
@ -365,7 +456,9 @@ export async function onboard(opts: OnboardOptions): Promise<void> {
|
|||
if (tc) trackInstallStarted(tc);
|
||||
|
||||
let llm: PaperclipConfig["llm"] | undefined;
|
||||
const { defaults: derivedDefaults, usedEnvKeys, ignoredEnvKeys } = quickstartDefaultsFromEnv();
|
||||
const { defaults: derivedDefaults, usedEnvKeys, ignoredEnvKeys } = quickstartDefaultsFromEnv({
|
||||
preferTrustedLocal: opts.yes === true && !opts.bind,
|
||||
});
|
||||
let {
|
||||
database,
|
||||
logging,
|
||||
|
|
@ -375,6 +468,16 @@ export async function onboard(opts: OnboardOptions): Promise<void> {
|
|||
secrets,
|
||||
} = derivedDefaults;
|
||||
|
||||
if (opts.bind === "loopback" || opts.bind === "lan" || opts.bind === "tailnet") {
|
||||
const preset = buildPresetServerConfig(opts.bind, {
|
||||
port: server.port,
|
||||
allowedHostnames: server.allowedHostnames,
|
||||
serveUi: server.serveUi,
|
||||
});
|
||||
server = preset.server;
|
||||
auth = preset.auth;
|
||||
}
|
||||
|
||||
if (setupMode === "advanced") {
|
||||
p.log.step(pc.bold("Database"));
|
||||
database = await promptDatabase(database);
|
||||
|
|
@ -462,7 +565,13 @@ export async function onboard(opts: OnboardOptions): Promise<void> {
|
|||
);
|
||||
} else {
|
||||
p.log.step(pc.bold("Quickstart"));
|
||||
p.log.message(pc.dim("Using quickstart defaults."));
|
||||
p.log.message(
|
||||
pc.dim(
|
||||
opts.bind
|
||||
? `Using quickstart defaults with bind=${opts.bind}.`
|
||||
: `Using quickstart defaults: ${server.deploymentMode}/${server.exposure} @ ${describeServerBinding(server)}.`,
|
||||
),
|
||||
);
|
||||
if (usedEnvKeys.length > 0) {
|
||||
p.log.message(pc.dim(`Environment-aware defaults active (${usedEnvKeys.length} env var(s) detected).`));
|
||||
} else {
|
||||
|
|
@ -521,7 +630,7 @@ export async function onboard(opts: OnboardOptions): Promise<void> {
|
|||
`Database: ${database.mode}`,
|
||||
llm ? `LLM: ${llm.provider}` : "LLM: not configured",
|
||||
`Logging: ${logging.mode} -> ${logging.logDir}`,
|
||||
`Server: ${server.deploymentMode}/${server.exposure} @ ${server.host}:${server.port}`,
|
||||
`Server: ${server.deploymentMode}/${server.exposure} @ ${describeServerBinding(server)}`,
|
||||
`Allowed hosts: ${server.allowedHostnames.length > 0 ? server.allowedHostnames.join(", ") : "(loopback only)"}`,
|
||||
`Auth URL mode: ${auth.baseUrlMode}${auth.publicBaseUrl ? ` (${auth.publicBaseUrl})` : ""}`,
|
||||
`Storage: ${storage.provider}`,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ interface RunOptions {
|
|||
instance?: string;
|
||||
repair?: boolean;
|
||||
yes?: boolean;
|
||||
bind?: "loopback" | "lan" | "tailnet";
|
||||
}
|
||||
|
||||
interface StartedServer {
|
||||
|
|
@ -58,7 +59,7 @@ export async function runCommand(opts: RunOptions): Promise<void> {
|
|||
}
|
||||
|
||||
p.log.step("No config found. Starting onboarding...");
|
||||
await onboard({ config: configPath, invokedByRun: true });
|
||||
await onboard({ config: configPath, invokedByRun: true, bind: opts.bind });
|
||||
}
|
||||
|
||||
p.log.step("Running doctor checks...");
|
||||
|
|
|
|||
|
|
@ -214,6 +214,8 @@ export function buildWorktreeConfig(input: {
|
|||
server: {
|
||||
deploymentMode: source?.server.deploymentMode ?? "local_trusted",
|
||||
exposure: source?.server.exposure ?? "private",
|
||||
...(source?.server.bind ? { bind: source.server.bind } : {}),
|
||||
...(source?.server.customBindHost ? { customBindHost: source.server.customBindHost } : {}),
|
||||
host: source?.server.host ?? "127.0.0.1",
|
||||
port: serverPort,
|
||||
allowedHostnames: source?.server.allowedHostnames ?? [],
|
||||
|
|
|
|||
156
cli/src/config/server-bind.ts
Normal file
156
cli/src/config/server-bind.ts
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
import {
|
||||
ALL_INTERFACES_BIND_HOST,
|
||||
LOOPBACK_BIND_HOST,
|
||||
inferBindModeFromHost,
|
||||
isAllInterfacesHost,
|
||||
isLoopbackHost,
|
||||
type BindMode,
|
||||
type DeploymentExposure,
|
||||
type DeploymentMode,
|
||||
} from "@paperclipai/shared";
|
||||
import type { AuthConfig, ServerConfig } from "./schema.js";
|
||||
|
||||
type BaseServerInput = {
|
||||
port: number;
|
||||
allowedHostnames: string[];
|
||||
serveUi: boolean;
|
||||
};
|
||||
|
||||
export function inferConfiguredBind(server?: Partial<ServerConfig>): BindMode {
|
||||
if (server?.bind) return server.bind;
|
||||
return inferBindModeFromHost(server?.customBindHost ?? server?.host);
|
||||
}
|
||||
|
||||
export function buildPresetServerConfig(
|
||||
bind: Exclude<BindMode, "custom">,
|
||||
input: BaseServerInput,
|
||||
): { server: ServerConfig; auth: AuthConfig } {
|
||||
const host = bind === "loopback" ? LOOPBACK_BIND_HOST : ALL_INTERFACES_BIND_HOST;
|
||||
|
||||
return {
|
||||
server: {
|
||||
deploymentMode: bind === "loopback" ? "local_trusted" : "authenticated",
|
||||
exposure: "private",
|
||||
bind,
|
||||
customBindHost: undefined,
|
||||
host,
|
||||
port: input.port,
|
||||
allowedHostnames: input.allowedHostnames,
|
||||
serveUi: input.serveUi,
|
||||
},
|
||||
auth: {
|
||||
baseUrlMode: "auto",
|
||||
disableSignUp: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function buildCustomServerConfig(input: BaseServerInput & {
|
||||
deploymentMode: DeploymentMode;
|
||||
exposure: DeploymentExposure;
|
||||
host: string;
|
||||
publicBaseUrl?: string;
|
||||
}): { server: ServerConfig; auth: AuthConfig } {
|
||||
const normalizedHost = input.host.trim();
|
||||
const bind = isLoopbackHost(normalizedHost)
|
||||
? "loopback"
|
||||
: isAllInterfacesHost(normalizedHost)
|
||||
? "lan"
|
||||
: "custom";
|
||||
|
||||
return {
|
||||
server: {
|
||||
deploymentMode: input.deploymentMode,
|
||||
exposure: input.deploymentMode === "local_trusted" ? "private" : input.exposure,
|
||||
bind,
|
||||
customBindHost: bind === "custom" ? normalizedHost : undefined,
|
||||
host: normalizedHost,
|
||||
port: input.port,
|
||||
allowedHostnames: input.allowedHostnames,
|
||||
serveUi: input.serveUi,
|
||||
},
|
||||
auth:
|
||||
input.deploymentMode === "authenticated" && input.exposure === "public"
|
||||
? {
|
||||
baseUrlMode: "explicit",
|
||||
disableSignUp: false,
|
||||
publicBaseUrl: input.publicBaseUrl,
|
||||
}
|
||||
: {
|
||||
baseUrlMode: "auto",
|
||||
disableSignUp: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveQuickstartServerConfig(input: {
|
||||
bind?: BindMode | null;
|
||||
deploymentMode?: DeploymentMode | null;
|
||||
exposure?: DeploymentExposure | null;
|
||||
host?: string | null;
|
||||
port: number;
|
||||
allowedHostnames: string[];
|
||||
serveUi: boolean;
|
||||
publicBaseUrl?: string;
|
||||
}): { server: ServerConfig; auth: AuthConfig } {
|
||||
const trimmedHost = input.host?.trim();
|
||||
const explicitBind = input.bind ?? null;
|
||||
|
||||
if (explicitBind === "loopback" || explicitBind === "lan" || explicitBind === "tailnet") {
|
||||
return buildPresetServerConfig(explicitBind, {
|
||||
port: input.port,
|
||||
allowedHostnames: input.allowedHostnames,
|
||||
serveUi: input.serveUi,
|
||||
});
|
||||
}
|
||||
|
||||
if (explicitBind === "custom") {
|
||||
return buildCustomServerConfig({
|
||||
deploymentMode: input.deploymentMode ?? "authenticated",
|
||||
exposure: input.exposure ?? "private",
|
||||
host: trimmedHost || LOOPBACK_BIND_HOST,
|
||||
port: input.port,
|
||||
allowedHostnames: input.allowedHostnames,
|
||||
serveUi: input.serveUi,
|
||||
publicBaseUrl: input.publicBaseUrl,
|
||||
});
|
||||
}
|
||||
|
||||
if (trimmedHost) {
|
||||
return buildCustomServerConfig({
|
||||
deploymentMode: input.deploymentMode ?? (isLoopbackHost(trimmedHost) ? "local_trusted" : "authenticated"),
|
||||
exposure: input.exposure ?? "private",
|
||||
host: trimmedHost,
|
||||
port: input.port,
|
||||
allowedHostnames: input.allowedHostnames,
|
||||
serveUi: input.serveUi,
|
||||
publicBaseUrl: input.publicBaseUrl,
|
||||
});
|
||||
}
|
||||
|
||||
if (input.deploymentMode === "authenticated") {
|
||||
if (input.exposure === "public") {
|
||||
return buildCustomServerConfig({
|
||||
deploymentMode: "authenticated",
|
||||
exposure: "public",
|
||||
host: ALL_INTERFACES_BIND_HOST,
|
||||
port: input.port,
|
||||
allowedHostnames: input.allowedHostnames,
|
||||
serveUi: input.serveUi,
|
||||
publicBaseUrl: input.publicBaseUrl,
|
||||
});
|
||||
}
|
||||
|
||||
return buildPresetServerConfig("lan", {
|
||||
port: input.port,
|
||||
allowedHostnames: input.allowedHostnames,
|
||||
serveUi: input.serveUi,
|
||||
});
|
||||
}
|
||||
|
||||
return buildPresetServerConfig("loopback", {
|
||||
port: input.port,
|
||||
allowedHostnames: input.allowedHostnames,
|
||||
serveUi: input.serveUi,
|
||||
});
|
||||
}
|
||||
|
|
@ -50,7 +50,8 @@ program
|
|||
.description("Interactive first-run setup wizard")
|
||||
.option("-c, --config <path>", "Path to config file")
|
||||
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
||||
.option("-y, --yes", "Accept defaults (quickstart + start immediately)", false)
|
||||
.option("--bind <mode>", "Quickstart reachability preset (loopback, lan, tailnet)")
|
||||
.option("-y, --yes", "Accept quickstart defaults (trusted local loopback unless --bind is set) and start immediately", false)
|
||||
.option("--run", "Start Paperclip immediately after saving config", false)
|
||||
.action(onboard);
|
||||
|
||||
|
|
@ -108,6 +109,7 @@ program
|
|||
.option("-c, --config <path>", "Path to config file")
|
||||
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
||||
.option("-i, --instance <id>", "Local instance id (default: default)")
|
||||
.option("--bind <mode>", "On first run, use onboarding reachability preset (loopback, lan, tailnet)")
|
||||
.option("--repair", "Attempt automatic repairs during doctor", true)
|
||||
.option("--no-repair", "Disable automatic repairs during doctor")
|
||||
.action(runCommand);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,17 @@
|
|||
import * as p from "@clack/prompts";
|
||||
import { isLoopbackHost, type BindMode } from "@paperclipai/shared";
|
||||
import type { AuthConfig, ServerConfig } from "../config/schema.js";
|
||||
import { parseHostnameCsv } from "../config/hostnames.js";
|
||||
import {
|
||||
buildCustomServerConfig,
|
||||
buildPresetServerConfig,
|
||||
inferConfiguredBind,
|
||||
} from "../config/server-bind.js";
|
||||
|
||||
function cancelled(): never {
|
||||
p.cancel("Setup cancelled.");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
export async function promptServer(opts?: {
|
||||
currentServer?: Partial<ServerConfig>;
|
||||
|
|
@ -8,69 +19,37 @@ export async function promptServer(opts?: {
|
|||
}): Promise<{ server: ServerConfig; auth: AuthConfig }> {
|
||||
const currentServer = opts?.currentServer;
|
||||
const currentAuth = opts?.currentAuth;
|
||||
const currentBind = inferConfiguredBind(currentServer);
|
||||
|
||||
const deploymentModeSelection = await p.select({
|
||||
message: "Deployment mode",
|
||||
const bindSelection = await p.select({
|
||||
message: "Reachability",
|
||||
options: [
|
||||
{
|
||||
value: "local_trusted",
|
||||
label: "Local trusted",
|
||||
hint: "Easiest for local setup (no login, localhost-only)",
|
||||
value: "loopback" as const,
|
||||
label: "Trusted local",
|
||||
hint: "Recommended for first run: localhost only, no login friction",
|
||||
},
|
||||
{
|
||||
value: "authenticated",
|
||||
label: "Authenticated",
|
||||
hint: "Login required; use for private network or public hosting",
|
||||
value: "lan" as const,
|
||||
label: "Private network",
|
||||
hint: "Broad private bind for LAN, VPN, or legacy --tailscale-auth style access",
|
||||
},
|
||||
{
|
||||
value: "tailnet" as const,
|
||||
label: "Tailnet",
|
||||
hint: "Private authenticated access using the machine's detected Tailscale address",
|
||||
},
|
||||
{
|
||||
value: "custom" as const,
|
||||
label: "Custom",
|
||||
hint: "Choose exact auth mode, exposure, and host manually",
|
||||
},
|
||||
],
|
||||
initialValue: currentServer?.deploymentMode ?? "local_trusted",
|
||||
initialValue: currentBind,
|
||||
});
|
||||
|
||||
if (p.isCancel(deploymentModeSelection)) {
|
||||
p.cancel("Setup cancelled.");
|
||||
process.exit(0);
|
||||
}
|
||||
const deploymentMode = deploymentModeSelection as ServerConfig["deploymentMode"];
|
||||
|
||||
let exposure: ServerConfig["exposure"] = "private";
|
||||
if (deploymentMode === "authenticated") {
|
||||
const exposureSelection = await p.select({
|
||||
message: "Exposure profile",
|
||||
options: [
|
||||
{
|
||||
value: "private",
|
||||
label: "Private network",
|
||||
hint: "Private access (for example Tailscale), lower setup friction",
|
||||
},
|
||||
{
|
||||
value: "public",
|
||||
label: "Public internet",
|
||||
hint: "Internet-facing deployment with stricter requirements",
|
||||
},
|
||||
],
|
||||
initialValue: currentServer?.exposure ?? "private",
|
||||
});
|
||||
if (p.isCancel(exposureSelection)) {
|
||||
p.cancel("Setup cancelled.");
|
||||
process.exit(0);
|
||||
}
|
||||
exposure = exposureSelection as ServerConfig["exposure"];
|
||||
}
|
||||
|
||||
const hostDefault = deploymentMode === "local_trusted" ? "127.0.0.1" : "0.0.0.0";
|
||||
const hostStr = await p.text({
|
||||
message: "Bind host",
|
||||
defaultValue: currentServer?.host ?? hostDefault,
|
||||
placeholder: hostDefault,
|
||||
validate: (val) => {
|
||||
if (!val.trim()) return "Host is required";
|
||||
},
|
||||
});
|
||||
|
||||
if (p.isCancel(hostStr)) {
|
||||
p.cancel("Setup cancelled.");
|
||||
process.exit(0);
|
||||
}
|
||||
if (p.isCancel(bindSelection)) cancelled();
|
||||
const bind = bindSelection as BindMode;
|
||||
|
||||
const portStr = await p.text({
|
||||
message: "Server port",
|
||||
|
|
@ -84,15 +63,109 @@ export async function promptServer(opts?: {
|
|||
},
|
||||
});
|
||||
|
||||
if (p.isCancel(portStr)) {
|
||||
p.cancel("Setup cancelled.");
|
||||
process.exit(0);
|
||||
if (p.isCancel(portStr)) cancelled();
|
||||
const port = Number(portStr) || 3100;
|
||||
const serveUi = currentServer?.serveUi ?? true;
|
||||
|
||||
if (bind === "loopback") {
|
||||
return buildPresetServerConfig("loopback", {
|
||||
port,
|
||||
allowedHostnames: [],
|
||||
serveUi,
|
||||
});
|
||||
}
|
||||
|
||||
if (bind === "lan" || bind === "tailnet") {
|
||||
const allowedHostnamesInput = await p.text({
|
||||
message: "Allowed private hostnames (comma-separated, optional)",
|
||||
defaultValue: (currentServer?.allowedHostnames ?? []).join(", "),
|
||||
placeholder:
|
||||
bind === "tailnet"
|
||||
? "your-machine.tailnet.ts.net"
|
||||
: "dotta-macbook-pro, host.docker.internal",
|
||||
validate: (val) => {
|
||||
try {
|
||||
parseHostnameCsv(val);
|
||||
return;
|
||||
} catch (err) {
|
||||
return err instanceof Error ? err.message : "Invalid hostname list";
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
if (p.isCancel(allowedHostnamesInput)) cancelled();
|
||||
|
||||
return buildPresetServerConfig(bind, {
|
||||
port,
|
||||
allowedHostnames: parseHostnameCsv(allowedHostnamesInput),
|
||||
serveUi,
|
||||
});
|
||||
}
|
||||
|
||||
const deploymentModeSelection = await p.select({
|
||||
message: "Auth mode",
|
||||
options: [
|
||||
{
|
||||
value: "local_trusted",
|
||||
label: "Local trusted",
|
||||
hint: "No login required; only safe with loopback-only or similarly trusted access",
|
||||
},
|
||||
{
|
||||
value: "authenticated",
|
||||
label: "Authenticated",
|
||||
hint: "Login required; supports both private-network and public deployments",
|
||||
},
|
||||
],
|
||||
initialValue: currentServer?.deploymentMode ?? "authenticated",
|
||||
});
|
||||
|
||||
if (p.isCancel(deploymentModeSelection)) cancelled();
|
||||
const deploymentMode = deploymentModeSelection as ServerConfig["deploymentMode"];
|
||||
|
||||
let exposure: ServerConfig["exposure"] = "private";
|
||||
if (deploymentMode === "authenticated") {
|
||||
const exposureSelection = await p.select({
|
||||
message: "Exposure profile",
|
||||
options: [
|
||||
{
|
||||
value: "private",
|
||||
label: "Private network",
|
||||
hint: "Private access only, with automatic URL handling",
|
||||
},
|
||||
{
|
||||
value: "public",
|
||||
label: "Public internet",
|
||||
hint: "Internet-facing deployment with explicit public URL requirements",
|
||||
},
|
||||
],
|
||||
initialValue: currentServer?.exposure ?? "private",
|
||||
});
|
||||
if (p.isCancel(exposureSelection)) cancelled();
|
||||
exposure = exposureSelection as ServerConfig["exposure"];
|
||||
}
|
||||
|
||||
const defaultHost =
|
||||
currentServer?.customBindHost ??
|
||||
currentServer?.host ??
|
||||
(deploymentMode === "local_trusted" ? "127.0.0.1" : "0.0.0.0");
|
||||
const host = await p.text({
|
||||
message: "Bind host",
|
||||
defaultValue: defaultHost,
|
||||
placeholder: defaultHost,
|
||||
validate: (val) => {
|
||||
if (!val.trim()) return "Host is required";
|
||||
if (deploymentMode === "local_trusted" && !isLoopbackHost(val.trim())) {
|
||||
return "Local trusted mode requires a loopback host such as 127.0.0.1";
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
if (p.isCancel(host)) cancelled();
|
||||
|
||||
let allowedHostnames: string[] = [];
|
||||
if (deploymentMode === "authenticated" && exposure === "private") {
|
||||
const allowedHostnamesInput = await p.text({
|
||||
message: "Allowed hostnames (comma-separated, optional)",
|
||||
message: "Allowed private hostnames (comma-separated, optional)",
|
||||
defaultValue: (currentServer?.allowedHostnames ?? []).join(", "),
|
||||
placeholder: "dotta-macbook-pro, your-host.tailnet.ts.net",
|
||||
validate: (val) => {
|
||||
|
|
@ -105,15 +178,11 @@ export async function promptServer(opts?: {
|
|||
},
|
||||
});
|
||||
|
||||
if (p.isCancel(allowedHostnamesInput)) {
|
||||
p.cancel("Setup cancelled.");
|
||||
process.exit(0);
|
||||
}
|
||||
if (p.isCancel(allowedHostnamesInput)) cancelled();
|
||||
allowedHostnames = parseHostnameCsv(allowedHostnamesInput);
|
||||
}
|
||||
|
||||
const port = Number(portStr) || 3100;
|
||||
let auth: AuthConfig = { baseUrlMode: "auto", disableSignUp: false };
|
||||
let publicBaseUrl: string | undefined;
|
||||
if (deploymentMode === "authenticated" && exposure === "public") {
|
||||
const urlInput = await p.text({
|
||||
message: "Public base URL",
|
||||
|
|
@ -133,32 +202,17 @@ export async function promptServer(opts?: {
|
|||
}
|
||||
},
|
||||
});
|
||||
if (p.isCancel(urlInput)) {
|
||||
p.cancel("Setup cancelled.");
|
||||
process.exit(0);
|
||||
}
|
||||
auth = {
|
||||
baseUrlMode: "explicit",
|
||||
disableSignUp: false,
|
||||
publicBaseUrl: urlInput.trim().replace(/\/+$/, ""),
|
||||
};
|
||||
} else if (currentAuth?.baseUrlMode === "explicit" && currentAuth.publicBaseUrl) {
|
||||
auth = {
|
||||
baseUrlMode: "explicit",
|
||||
disableSignUp: false,
|
||||
publicBaseUrl: currentAuth.publicBaseUrl,
|
||||
};
|
||||
if (p.isCancel(urlInput)) cancelled();
|
||||
publicBaseUrl = urlInput.trim().replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
return {
|
||||
server: {
|
||||
deploymentMode,
|
||||
exposure,
|
||||
host: hostStr.trim(),
|
||||
port,
|
||||
allowedHostnames,
|
||||
serveUi: currentServer?.serveUi ?? true,
|
||||
},
|
||||
auth,
|
||||
};
|
||||
return buildCustomServerConfig({
|
||||
deploymentMode,
|
||||
exposure,
|
||||
host: host.trim(),
|
||||
port,
|
||||
allowedHostnames,
|
||||
serveUi,
|
||||
publicBaseUrl,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue