feat: unify onboarding + config schema
This commit is contained in:
@@ -24,6 +24,7 @@ import { resolveGatewayService } from "../daemon/service.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { resolveUserPath, sleep } from "../utils.js";
|
||||
import { createClackPrompter } from "../wizard/clack-prompter.js";
|
||||
import {
|
||||
isRemoteEnvironment,
|
||||
loginAntigravityVpsAware,
|
||||
@@ -419,6 +420,7 @@ export async function runConfigureWizard(
|
||||
intro(
|
||||
opts.command === "update" ? "Clawdis update wizard" : "Clawdis configure",
|
||||
);
|
||||
const prompter = createClackPrompter();
|
||||
|
||||
const snapshot = await readConfigFileSnapshot();
|
||||
let baseConfig: ClawdisConfig = snapshot.valid ? snapshot.config : {};
|
||||
@@ -490,7 +492,7 @@ export async function runConfigureWizard(
|
||||
) as "local" | "remote";
|
||||
|
||||
if (mode === "remote") {
|
||||
let remoteConfig = await promptRemoteGatewayConfig(baseConfig, runtime);
|
||||
let remoteConfig = await promptRemoteGatewayConfig(baseConfig, prompter);
|
||||
remoteConfig = applyWizardMetadata(remoteConfig, {
|
||||
command: opts.command,
|
||||
mode,
|
||||
@@ -565,7 +567,7 @@ export async function runConfigureWizard(
|
||||
}
|
||||
|
||||
if (selected.includes("providers")) {
|
||||
nextConfig = await setupProviders(nextConfig, runtime, {
|
||||
nextConfig = await setupProviders(nextConfig, runtime, prompter, {
|
||||
allowDisable: true,
|
||||
allowSignalInstall: true,
|
||||
});
|
||||
@@ -573,7 +575,7 @@ export async function runConfigureWizard(
|
||||
|
||||
if (selected.includes("skills")) {
|
||||
const wsDir = resolveUserPath(workspaceDir);
|
||||
nextConfig = await setupSkills(nextConfig, wsDir, runtime);
|
||||
nextConfig = await setupSkills(nextConfig, wsDir, runtime, prompter);
|
||||
}
|
||||
|
||||
nextConfig = applyWizardMetadata(nextConfig, {
|
||||
|
||||
@@ -1,594 +1,22 @@
|
||||
import path from "node:path";
|
||||
|
||||
import {
|
||||
confirm,
|
||||
intro,
|
||||
note,
|
||||
outro,
|
||||
select,
|
||||
spinner,
|
||||
text,
|
||||
} from "@clack/prompts";
|
||||
import { loginAnthropic, type OAuthCredentials } from "@mariozechner/pi-ai";
|
||||
import type { ClawdisConfig } from "../config/config.js";
|
||||
import {
|
||||
CONFIG_PATH_CLAWDIS,
|
||||
readConfigFileSnapshot,
|
||||
resolveGatewayPort,
|
||||
writeConfigFile,
|
||||
} from "../config/config.js";
|
||||
import { GATEWAY_LAUNCH_AGENT_LABEL } from "../daemon/constants.js";
|
||||
import { resolveGatewayProgramArguments } from "../daemon/program-args.js";
|
||||
import { resolveGatewayService } from "../daemon/service.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { resolveUserPath, sleep } from "../utils.js";
|
||||
import {
|
||||
isRemoteEnvironment,
|
||||
loginAntigravityVpsAware,
|
||||
} from "./antigravity-oauth.js";
|
||||
import { healthCommand } from "./health.js";
|
||||
import {
|
||||
applyMinimaxConfig,
|
||||
setAnthropicApiKey,
|
||||
writeOAuthCredentials,
|
||||
} from "./onboard-auth.js";
|
||||
import {
|
||||
applyWizardMetadata,
|
||||
DEFAULT_WORKSPACE,
|
||||
ensureWorkspaceAndSessions,
|
||||
guardCancel,
|
||||
handleReset,
|
||||
openUrl,
|
||||
printWizardHeader,
|
||||
probeGatewayReachable,
|
||||
randomToken,
|
||||
resolveControlUiLinks,
|
||||
summarizeExistingConfig,
|
||||
} from "./onboard-helpers.js";
|
||||
import { setupProviders } from "./onboard-providers.js";
|
||||
import { promptRemoteGatewayConfig } from "./onboard-remote.js";
|
||||
import { setupSkills } from "./onboard-skills.js";
|
||||
import type {
|
||||
AuthChoice,
|
||||
GatewayAuthChoice,
|
||||
OnboardMode,
|
||||
OnboardOptions,
|
||||
ResetScope,
|
||||
} from "./onboard-types.js";
|
||||
import { createClackPrompter } from "../wizard/clack-prompter.js";
|
||||
import { runOnboardingWizard } from "../wizard/onboarding.js";
|
||||
import { WizardCancelledError } from "../wizard/prompts.js";
|
||||
import type { OnboardOptions } from "./onboard-types.js";
|
||||
|
||||
export async function runInteractiveOnboarding(
|
||||
opts: OnboardOptions,
|
||||
runtime: RuntimeEnv = defaultRuntime,
|
||||
) {
|
||||
printWizardHeader(runtime);
|
||||
intro("Clawdis onboarding");
|
||||
|
||||
const snapshot = await readConfigFileSnapshot();
|
||||
let baseConfig: ClawdisConfig = snapshot.valid ? snapshot.config : {};
|
||||
|
||||
if (snapshot.exists) {
|
||||
const title = snapshot.valid
|
||||
? "Existing config detected"
|
||||
: "Invalid config";
|
||||
note(summarizeExistingConfig(baseConfig), title);
|
||||
if (!snapshot.valid && snapshot.issues.length > 0) {
|
||||
note(
|
||||
snapshot.issues
|
||||
.map((iss) => `- ${iss.path}: ${iss.message}`)
|
||||
.join("\n"),
|
||||
"Config issues",
|
||||
);
|
||||
}
|
||||
|
||||
const action = guardCancel(
|
||||
await select({
|
||||
message: "Config handling",
|
||||
options: [
|
||||
{ value: "keep", label: "Use existing values" },
|
||||
{ value: "modify", label: "Update values" },
|
||||
{ value: "reset", label: "Reset" },
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
|
||||
if (action === "reset") {
|
||||
const workspaceDefault = baseConfig.agent?.workspace ?? DEFAULT_WORKSPACE;
|
||||
const resetScope = guardCancel(
|
||||
await select({
|
||||
message: "Reset scope",
|
||||
options: [
|
||||
{ value: "config", label: "Config only" },
|
||||
{
|
||||
value: "config+creds+sessions",
|
||||
label: "Config + creds + sessions",
|
||||
},
|
||||
{
|
||||
value: "full",
|
||||
label: "Full reset (config + creds + sessions + workspace)",
|
||||
},
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
) as ResetScope;
|
||||
await handleReset(resetScope, resolveUserPath(workspaceDefault), runtime);
|
||||
baseConfig = {};
|
||||
} else if (action === "keep" && !snapshot.valid) {
|
||||
baseConfig = {};
|
||||
}
|
||||
}
|
||||
|
||||
const localPort = resolveGatewayPort(baseConfig);
|
||||
const localUrl = `ws://127.0.0.1:${localPort}`;
|
||||
const localProbe = await probeGatewayReachable({
|
||||
url: localUrl,
|
||||
token: process.env.CLAWDIS_GATEWAY_TOKEN,
|
||||
password:
|
||||
baseConfig.gateway?.auth?.password ??
|
||||
process.env.CLAWDIS_GATEWAY_PASSWORD,
|
||||
});
|
||||
const remoteUrl = baseConfig.gateway?.remote?.url?.trim() ?? "";
|
||||
const remoteProbe = remoteUrl
|
||||
? await probeGatewayReachable({
|
||||
url: remoteUrl,
|
||||
token: baseConfig.gateway?.remote?.token,
|
||||
})
|
||||
: null;
|
||||
|
||||
const mode =
|
||||
opts.mode ??
|
||||
(guardCancel(
|
||||
await select({
|
||||
message: "Where will the Gateway run?",
|
||||
options: [
|
||||
{
|
||||
value: "local",
|
||||
label: "Local (this machine)",
|
||||
hint: localProbe.ok
|
||||
? `Gateway reachable (${localUrl})`
|
||||
: `No gateway detected (${localUrl})`,
|
||||
},
|
||||
{
|
||||
value: "remote",
|
||||
label: "Remote (info-only)",
|
||||
hint: !remoteUrl
|
||||
? "No remote URL configured yet"
|
||||
: remoteProbe?.ok
|
||||
? `Gateway reachable (${remoteUrl})`
|
||||
: `Configured but unreachable (${remoteUrl})`,
|
||||
},
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
) as OnboardMode);
|
||||
|
||||
if (mode === "remote") {
|
||||
let nextConfig = await promptRemoteGatewayConfig(baseConfig, runtime);
|
||||
nextConfig = applyWizardMetadata(nextConfig, { command: "onboard", mode });
|
||||
await writeConfigFile(nextConfig);
|
||||
runtime.log(`Updated ${CONFIG_PATH_CLAWDIS}`);
|
||||
outro("Remote gateway configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
const workspaceInput =
|
||||
opts.workspace ??
|
||||
(guardCancel(
|
||||
await text({
|
||||
message: "Workspace directory",
|
||||
initialValue: baseConfig.agent?.workspace ?? DEFAULT_WORKSPACE,
|
||||
}),
|
||||
runtime,
|
||||
) as string);
|
||||
|
||||
const workspaceDir = resolveUserPath(
|
||||
workspaceInput.trim() || DEFAULT_WORKSPACE,
|
||||
);
|
||||
|
||||
let nextConfig: ClawdisConfig = {
|
||||
...baseConfig,
|
||||
agent: {
|
||||
...baseConfig.agent,
|
||||
workspace: workspaceDir,
|
||||
},
|
||||
gateway: {
|
||||
...baseConfig.gateway,
|
||||
mode: "local",
|
||||
},
|
||||
};
|
||||
|
||||
const authChoice = guardCancel(
|
||||
await select({
|
||||
message: "Model/auth choice",
|
||||
options: [
|
||||
{ value: "oauth", label: "Anthropic OAuth (Claude Pro/Max)" },
|
||||
{
|
||||
value: "antigravity",
|
||||
label: "Google Antigravity (Claude Opus 4.5, Gemini 3, etc.)",
|
||||
},
|
||||
{ value: "apiKey", label: "Anthropic API key" },
|
||||
{ value: "minimax", label: "Minimax M2.1 (LM Studio)" },
|
||||
{ value: "skip", label: "Skip for now" },
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
) as AuthChoice;
|
||||
|
||||
if (authChoice === "oauth") {
|
||||
note(
|
||||
"Browser will open. Paste the code shown after login (code#state).",
|
||||
"Anthropic OAuth",
|
||||
);
|
||||
const spin = spinner();
|
||||
spin.start("Waiting for authorization…");
|
||||
let oauthCreds: OAuthCredentials | null = null;
|
||||
try {
|
||||
oauthCreds = await loginAnthropic(
|
||||
async (url) => {
|
||||
await openUrl(url);
|
||||
runtime.log(`Open: ${url}`);
|
||||
},
|
||||
async () => {
|
||||
const code = guardCancel(
|
||||
await text({
|
||||
message: "Paste authorization code (code#state)",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
return String(code);
|
||||
},
|
||||
);
|
||||
spin.stop("OAuth complete");
|
||||
if (oauthCreds) {
|
||||
await writeOAuthCredentials("anthropic", oauthCreds);
|
||||
}
|
||||
} catch (err) {
|
||||
spin.stop("OAuth failed");
|
||||
runtime.error(String(err));
|
||||
}
|
||||
} else if (authChoice === "antigravity") {
|
||||
const isRemote = isRemoteEnvironment();
|
||||
note(
|
||||
isRemote
|
||||
? [
|
||||
"You are running in a remote/VPS environment.",
|
||||
"A URL will be shown for you to open in your LOCAL browser.",
|
||||
"After signing in, copy the redirect URL and paste it back here.",
|
||||
].join("\n")
|
||||
: [
|
||||
"Browser will open for Google authentication.",
|
||||
"Sign in with your Google account that has Antigravity access.",
|
||||
"The callback will be captured automatically on localhost:51121.",
|
||||
].join("\n"),
|
||||
"Google Antigravity OAuth",
|
||||
);
|
||||
const spin = spinner();
|
||||
spin.start("Starting OAuth flow…");
|
||||
let oauthCreds: OAuthCredentials | null = null;
|
||||
try {
|
||||
oauthCreds = await loginAntigravityVpsAware(
|
||||
async (url) => {
|
||||
if (isRemote) {
|
||||
spin.stop("OAuth URL ready");
|
||||
runtime.log(`\nOpen this URL in your LOCAL browser:\n\n${url}\n`);
|
||||
} else {
|
||||
spin.message("Complete sign-in in browser…");
|
||||
await openUrl(url);
|
||||
runtime.log(`Open: ${url}`);
|
||||
}
|
||||
},
|
||||
(msg) => spin.message(msg),
|
||||
);
|
||||
spin.stop("Antigravity OAuth complete");
|
||||
if (oauthCreds) {
|
||||
await writeOAuthCredentials("google-antigravity", oauthCreds);
|
||||
// Set default model to Claude Opus 4.5 via Antigravity
|
||||
nextConfig = {
|
||||
...nextConfig,
|
||||
agent: {
|
||||
...nextConfig.agent,
|
||||
model: "google-antigravity/claude-opus-4-5-thinking",
|
||||
},
|
||||
};
|
||||
note(
|
||||
"Default model set to google-antigravity/claude-opus-4-5-thinking",
|
||||
"Model configured",
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
spin.stop("Antigravity OAuth failed");
|
||||
runtime.error(String(err));
|
||||
}
|
||||
} else if (authChoice === "apiKey") {
|
||||
const key = guardCancel(
|
||||
await text({
|
||||
message: "Enter Anthropic API key",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
await setAnthropicApiKey(String(key).trim());
|
||||
} else if (authChoice === "minimax") {
|
||||
nextConfig = applyMinimaxConfig(nextConfig);
|
||||
}
|
||||
|
||||
const portRaw = guardCancel(
|
||||
await text({
|
||||
message: "Gateway port",
|
||||
initialValue: String(localPort),
|
||||
validate: (value) =>
|
||||
Number.isFinite(Number(value)) ? undefined : "Invalid port",
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const port = Number.parseInt(String(portRaw), 10);
|
||||
|
||||
let bind = guardCancel(
|
||||
await select({
|
||||
message: "Gateway bind",
|
||||
options: [
|
||||
{ value: "loopback", label: "Loopback (127.0.0.1)" },
|
||||
{ value: "lan", label: "LAN" },
|
||||
{ value: "tailnet", label: "Tailnet" },
|
||||
{ value: "auto", label: "Auto" },
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
) as "loopback" | "lan" | "tailnet" | "auto";
|
||||
|
||||
let authMode = guardCancel(
|
||||
await select({
|
||||
message: "Gateway auth",
|
||||
options: [
|
||||
{
|
||||
value: "off",
|
||||
label: "Off (loopback only)",
|
||||
hint: "Recommended for single-machine setups",
|
||||
},
|
||||
{
|
||||
value: "token",
|
||||
label: "Token",
|
||||
hint: "Use for multi-machine access or non-loopback binds",
|
||||
},
|
||||
{ value: "password", label: "Password" },
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
) as GatewayAuthChoice;
|
||||
|
||||
const tailscaleMode = guardCancel(
|
||||
await select({
|
||||
message: "Tailscale exposure",
|
||||
options: [
|
||||
{ value: "off", label: "Off", hint: "No Tailscale exposure" },
|
||||
{
|
||||
value: "serve",
|
||||
label: "Serve",
|
||||
hint: "Private HTTPS for your tailnet (devices on Tailscale)",
|
||||
},
|
||||
{
|
||||
value: "funnel",
|
||||
label: "Funnel",
|
||||
hint: "Public HTTPS via Tailscale Funnel (internet)",
|
||||
},
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
) as "off" | "serve" | "funnel";
|
||||
|
||||
let tailscaleResetOnExit = false;
|
||||
if (tailscaleMode !== "off") {
|
||||
tailscaleResetOnExit = Boolean(
|
||||
guardCancel(
|
||||
await confirm({
|
||||
message: "Reset Tailscale serve/funnel on exit?",
|
||||
initialValue: false,
|
||||
}),
|
||||
runtime,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (tailscaleMode !== "off" && bind !== "loopback") {
|
||||
note(
|
||||
"Tailscale requires bind=loopback. Adjusting bind to loopback.",
|
||||
"Note",
|
||||
);
|
||||
bind = "loopback";
|
||||
}
|
||||
|
||||
if (authMode === "off" && bind !== "loopback") {
|
||||
note("Non-loopback bind requires auth. Switching to token auth.", "Note");
|
||||
authMode = "token";
|
||||
}
|
||||
|
||||
if (tailscaleMode === "funnel" && authMode !== "password") {
|
||||
note("Tailscale funnel requires password auth.", "Note");
|
||||
authMode = "password";
|
||||
}
|
||||
|
||||
let gatewayToken: string | undefined;
|
||||
if (authMode === "token") {
|
||||
const tokenInput = guardCancel(
|
||||
await text({
|
||||
message: "Gateway token (blank to generate)",
|
||||
placeholder: "Needed for multi-machine or non-loopback access",
|
||||
initialValue: randomToken(),
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
gatewayToken = String(tokenInput).trim() || randomToken();
|
||||
}
|
||||
|
||||
if (authMode === "password") {
|
||||
const password = guardCancel(
|
||||
await text({
|
||||
message: "Gateway password",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
nextConfig = {
|
||||
...nextConfig,
|
||||
gateway: {
|
||||
...nextConfig.gateway,
|
||||
auth: {
|
||||
...nextConfig.gateway?.auth,
|
||||
mode: "password",
|
||||
password: String(password).trim(),
|
||||
},
|
||||
},
|
||||
};
|
||||
} else if (authMode === "token") {
|
||||
nextConfig = {
|
||||
...nextConfig,
|
||||
gateway: {
|
||||
...nextConfig.gateway,
|
||||
auth: {
|
||||
...nextConfig.gateway?.auth,
|
||||
mode: "token",
|
||||
token: gatewayToken,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
nextConfig = {
|
||||
...nextConfig,
|
||||
gateway: {
|
||||
...nextConfig.gateway,
|
||||
port,
|
||||
bind,
|
||||
tailscale: {
|
||||
...nextConfig.gateway?.tailscale,
|
||||
mode: tailscaleMode,
|
||||
resetOnExit: tailscaleResetOnExit,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
nextConfig = await setupProviders(nextConfig, runtime, {
|
||||
allowSignalInstall: true,
|
||||
});
|
||||
|
||||
await writeConfigFile(nextConfig);
|
||||
runtime.log(`Updated ${CONFIG_PATH_CLAWDIS}`);
|
||||
await ensureWorkspaceAndSessions(workspaceDir, runtime);
|
||||
|
||||
nextConfig = await setupSkills(nextConfig, workspaceDir, runtime);
|
||||
nextConfig = applyWizardMetadata(nextConfig, { command: "onboard", mode });
|
||||
await writeConfigFile(nextConfig);
|
||||
|
||||
const installDaemon = guardCancel(
|
||||
await confirm({
|
||||
message: "Install Gateway daemon (recommended)",
|
||||
initialValue: true,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
|
||||
if (installDaemon) {
|
||||
const service = resolveGatewayService();
|
||||
const loaded = await service.isLoaded({ env: process.env });
|
||||
if (loaded) {
|
||||
const action = guardCancel(
|
||||
await select({
|
||||
message: "Gateway service already installed",
|
||||
options: [
|
||||
{ value: "restart", label: "Restart" },
|
||||
{ value: "reinstall", label: "Reinstall" },
|
||||
{ value: "skip", label: "Skip" },
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
if (action === "restart") {
|
||||
await service.restart({ stdout: process.stdout });
|
||||
} else if (action === "reinstall") {
|
||||
await service.uninstall({ env: process.env, stdout: process.stdout });
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!loaded ||
|
||||
(loaded && (await service.isLoaded({ env: process.env })) === false)
|
||||
) {
|
||||
const devMode =
|
||||
process.argv[1]?.includes(`${path.sep}src${path.sep}`) &&
|
||||
process.argv[1]?.endsWith(".ts");
|
||||
const { programArguments, workingDirectory } =
|
||||
await resolveGatewayProgramArguments({ port, dev: devMode });
|
||||
const environment: Record<string, string | undefined> = {
|
||||
PATH: process.env.PATH,
|
||||
CLAWDIS_GATEWAY_TOKEN: gatewayToken,
|
||||
CLAWDIS_LAUNCHD_LABEL:
|
||||
process.platform === "darwin"
|
||||
? GATEWAY_LAUNCH_AGENT_LABEL
|
||||
: undefined,
|
||||
};
|
||||
await service.install({
|
||||
env: process.env,
|
||||
stdout: process.stdout,
|
||||
programArguments,
|
||||
workingDirectory,
|
||||
environment,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await sleep(1500);
|
||||
const prompter = createClackPrompter();
|
||||
try {
|
||||
await healthCommand({ json: false, timeoutMs: 10_000 }, runtime);
|
||||
await runOnboardingWizard(opts, runtime, prompter);
|
||||
} catch (err) {
|
||||
runtime.error(`Health check failed: ${String(err)}`);
|
||||
if (err instanceof WizardCancelledError) {
|
||||
runtime.exit(0);
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
note(
|
||||
[
|
||||
"Add nodes for extra features:",
|
||||
"- macOS app (system + notifications)",
|
||||
"- iOS app (camera/canvas)",
|
||||
"- Android app (camera/canvas)",
|
||||
].join("\n"),
|
||||
"Optional apps",
|
||||
);
|
||||
|
||||
note(
|
||||
(() => {
|
||||
const links = resolveControlUiLinks({ bind, port });
|
||||
const tokenParam =
|
||||
authMode === "token" && gatewayToken
|
||||
? `?token=${encodeURIComponent(gatewayToken)}`
|
||||
: "";
|
||||
const authedUrl = `${links.httpUrl}${tokenParam}`;
|
||||
return [
|
||||
`Web UI: ${links.httpUrl}`,
|
||||
tokenParam ? `Web UI (with token): ${authedUrl}` : undefined,
|
||||
`Gateway WS: ${links.wsUrl}`,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n");
|
||||
})(),
|
||||
"Control UI",
|
||||
);
|
||||
|
||||
const wantsOpen = guardCancel(
|
||||
await confirm({
|
||||
message: "Open Control UI now?",
|
||||
initialValue: true,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
if (wantsOpen) {
|
||||
const links = resolveControlUiLinks({ bind, port });
|
||||
const tokenParam =
|
||||
authMode === "token" && gatewayToken
|
||||
? `?token=${encodeURIComponent(gatewayToken)}`
|
||||
: "";
|
||||
await openUrl(`${links.httpUrl}${tokenParam}`);
|
||||
}
|
||||
|
||||
outro("Onboarding complete.");
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { confirm, multiselect, note, select, text } from "@clack/prompts";
|
||||
import chalk from "chalk";
|
||||
|
||||
import type { ClawdisConfig } from "../config/config.js";
|
||||
import { loginWeb } from "../provider-web.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { normalizeE164 } from "../utils.js";
|
||||
import { resolveWebAuthDir } from "../web/session.js";
|
||||
import { detectBinary, guardCancel } from "./onboard-helpers.js";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import { detectBinary } from "./onboard-helpers.js";
|
||||
import type { ProviderChoice } from "./onboard-types.js";
|
||||
import { installSignalCli } from "./signal-install.js";
|
||||
|
||||
@@ -27,8 +24,8 @@ async function detectWhatsAppLinked(): Promise<boolean> {
|
||||
return await pathExists(credsPath);
|
||||
}
|
||||
|
||||
function noteProviderPrimer(): void {
|
||||
note(
|
||||
async function noteProviderPrimer(prompter: WizardPrompter): Promise<void> {
|
||||
await prompter.note(
|
||||
[
|
||||
"WhatsApp: links via WhatsApp Web (scan QR), stores creds for future sends.",
|
||||
"Telegram: Bot API (token from @BotFather), replies via your bot.",
|
||||
@@ -40,8 +37,8 @@ function noteProviderPrimer(): void {
|
||||
);
|
||||
}
|
||||
|
||||
function noteTelegramTokenHelp(): void {
|
||||
note(
|
||||
async function noteTelegramTokenHelp(prompter: WizardPrompter): Promise<void> {
|
||||
await prompter.note(
|
||||
[
|
||||
"1) Open Telegram and chat with @BotFather",
|
||||
"2) Run /newbot (or /mybots)",
|
||||
@@ -52,8 +49,8 @@ function noteTelegramTokenHelp(): void {
|
||||
);
|
||||
}
|
||||
|
||||
function noteDiscordTokenHelp(): void {
|
||||
note(
|
||||
async function noteDiscordTokenHelp(prompter: WizardPrompter): Promise<void> {
|
||||
await prompter.note(
|
||||
[
|
||||
"1) Discord Developer Portal → Applications → New Application",
|
||||
"2) Bot → Add Bot → Reset Token → copy token",
|
||||
@@ -76,13 +73,14 @@ function setWhatsAppAllowFrom(cfg: ClawdisConfig, allowFrom?: string[]) {
|
||||
|
||||
async function promptWhatsAppAllowFrom(
|
||||
cfg: ClawdisConfig,
|
||||
runtime: RuntimeEnv,
|
||||
_runtime: RuntimeEnv,
|
||||
prompter: WizardPrompter,
|
||||
): Promise<ClawdisConfig> {
|
||||
const existingAllowFrom = cfg.whatsapp?.allowFrom ?? [];
|
||||
const existingLabel =
|
||||
existingAllowFrom.length > 0 ? existingAllowFrom.join(", ") : "unset";
|
||||
|
||||
note(
|
||||
await prompter.note(
|
||||
[
|
||||
"WhatsApp direct chats are gated by `whatsapp.allowFrom`.",
|
||||
'Default (unset) = self-chat only; use "*" to allow anyone.',
|
||||
@@ -105,40 +103,34 @@ async function promptWhatsAppAllowFrom(
|
||||
{ value: "any", label: "Anyone (*)" },
|
||||
] as const);
|
||||
|
||||
const mode = guardCancel(
|
||||
await select({
|
||||
message: "Who can trigger the bot via WhatsApp?",
|
||||
options: options.map((opt) => ({ value: opt.value, label: opt.label })),
|
||||
}),
|
||||
runtime,
|
||||
) as (typeof options)[number]["value"];
|
||||
const mode = (await prompter.select({
|
||||
message: "Who can trigger the bot via WhatsApp?",
|
||||
options: options.map((opt) => ({ value: opt.value, label: opt.label })),
|
||||
})) as (typeof options)[number]["value"];
|
||||
|
||||
if (mode === "keep") return cfg;
|
||||
if (mode === "self") return setWhatsAppAllowFrom(cfg, undefined);
|
||||
if (mode === "any") return setWhatsAppAllowFrom(cfg, ["*"]);
|
||||
|
||||
const allowRaw = guardCancel(
|
||||
await text({
|
||||
message: "Allowed sender numbers (comma-separated, E.164)",
|
||||
placeholder: "+15555550123, +447700900123",
|
||||
validate: (value) => {
|
||||
const raw = String(value ?? "").trim();
|
||||
if (!raw) return "Required";
|
||||
const parts = raw
|
||||
.split(/[\n,;]+/g)
|
||||
.map((p) => p.trim())
|
||||
.filter(Boolean);
|
||||
if (parts.length === 0) return "Required";
|
||||
for (const part of parts) {
|
||||
if (part === "*") continue;
|
||||
const normalized = normalizeE164(part);
|
||||
if (!normalized) return `Invalid number: ${part}`;
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const allowRaw = await prompter.text({
|
||||
message: "Allowed sender numbers (comma-separated, E.164)",
|
||||
placeholder: "+15555550123, +447700900123",
|
||||
validate: (value) => {
|
||||
const raw = String(value ?? "").trim();
|
||||
if (!raw) return "Required";
|
||||
const parts = raw
|
||||
.split(/[\n,;]+/g)
|
||||
.map((p) => p.trim())
|
||||
.filter(Boolean);
|
||||
if (parts.length === 0) return "Required";
|
||||
for (const part of parts) {
|
||||
if (part === "*") continue;
|
||||
const normalized = normalizeE164(part);
|
||||
if (!normalized) return `Invalid number: ${part}`;
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
});
|
||||
|
||||
const parts = String(allowRaw)
|
||||
.split(/[\n,;]+/g)
|
||||
@@ -154,6 +146,7 @@ async function promptWhatsAppAllowFrom(
|
||||
export async function setupProviders(
|
||||
cfg: ClawdisConfig,
|
||||
runtime: RuntimeEnv,
|
||||
prompter: WizardPrompter,
|
||||
options?: { allowDisable?: boolean; allowSignalInstall?: boolean },
|
||||
): Promise<ClawdisConfig> {
|
||||
const whatsappLinked = await detectWhatsAppLinked();
|
||||
@@ -174,91 +167,63 @@ export async function setupProviders(
|
||||
const imessageCliPath = cfg.imessage?.cliPath ?? "imsg";
|
||||
const imessageCliDetected = await detectBinary(imessageCliPath);
|
||||
|
||||
note(
|
||||
await prompter.note(
|
||||
[
|
||||
`WhatsApp: ${
|
||||
whatsappLinked ? chalk.green("linked") : chalk.red("not linked")
|
||||
}`,
|
||||
`Telegram: ${
|
||||
telegramConfigured
|
||||
? chalk.green("configured")
|
||||
: chalk.yellow("needs token")
|
||||
}`,
|
||||
`Discord: ${
|
||||
discordConfigured
|
||||
? chalk.green("configured")
|
||||
: chalk.yellow("needs token")
|
||||
}`,
|
||||
`Signal: ${
|
||||
signalConfigured
|
||||
? chalk.green("configured")
|
||||
: chalk.yellow("needs setup")
|
||||
}`,
|
||||
`iMessage: ${
|
||||
imessageConfigured
|
||||
? chalk.green("configured")
|
||||
: chalk.yellow("needs setup")
|
||||
}`,
|
||||
`signal-cli: ${
|
||||
signalCliDetected ? chalk.green("found") : chalk.red("missing")
|
||||
} (${signalCliPath})`,
|
||||
`imsg: ${
|
||||
imessageCliDetected ? chalk.green("found") : chalk.red("missing")
|
||||
} (${imessageCliPath})`,
|
||||
`WhatsApp: ${whatsappLinked ? "linked" : "not linked"}`,
|
||||
`Telegram: ${telegramConfigured ? "configured" : "needs token"}`,
|
||||
`Discord: ${discordConfigured ? "configured" : "needs token"}`,
|
||||
`Signal: ${signalConfigured ? "configured" : "needs setup"}`,
|
||||
`iMessage: ${imessageConfigured ? "configured" : "needs setup"}`,
|
||||
`signal-cli: ${signalCliDetected ? "found" : "missing"} (${signalCliPath})`,
|
||||
`imsg: ${imessageCliDetected ? "found" : "missing"} (${imessageCliPath})`,
|
||||
].join("\n"),
|
||||
"Provider status",
|
||||
);
|
||||
|
||||
const shouldConfigure = guardCancel(
|
||||
await confirm({
|
||||
message: "Configure chat providers now?",
|
||||
initialValue: true,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const shouldConfigure = await prompter.confirm({
|
||||
message: "Configure chat providers now?",
|
||||
initialValue: true,
|
||||
});
|
||||
if (!shouldConfigure) return cfg;
|
||||
|
||||
noteProviderPrimer();
|
||||
await noteProviderPrimer(prompter);
|
||||
|
||||
const selection = guardCancel(
|
||||
await multiselect({
|
||||
message: "Select providers",
|
||||
options: [
|
||||
{
|
||||
value: "whatsapp",
|
||||
label: "WhatsApp (QR link)",
|
||||
hint: whatsappLinked ? "linked" : "not linked",
|
||||
},
|
||||
{
|
||||
value: "telegram",
|
||||
label: "Telegram (Bot API)",
|
||||
hint: telegramConfigured ? "configured" : "needs token",
|
||||
},
|
||||
{
|
||||
value: "discord",
|
||||
label: "Discord (Bot API)",
|
||||
hint: discordConfigured ? "configured" : "needs token",
|
||||
},
|
||||
{
|
||||
value: "signal",
|
||||
label: "Signal (signal-cli)",
|
||||
hint: signalCliDetected ? "signal-cli found" : "signal-cli missing",
|
||||
},
|
||||
{
|
||||
value: "imessage",
|
||||
label: "iMessage (imsg)",
|
||||
hint: imessageCliDetected ? "imsg found" : "imsg missing",
|
||||
},
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
) as ProviderChoice[];
|
||||
const selection = (await prompter.multiselect({
|
||||
message: "Select providers",
|
||||
options: [
|
||||
{
|
||||
value: "whatsapp",
|
||||
label: "WhatsApp (QR link)",
|
||||
hint: whatsappLinked ? "linked" : "not linked",
|
||||
},
|
||||
{
|
||||
value: "telegram",
|
||||
label: "Telegram (Bot API)",
|
||||
hint: telegramConfigured ? "configured" : "needs token",
|
||||
},
|
||||
{
|
||||
value: "discord",
|
||||
label: "Discord (Bot API)",
|
||||
hint: discordConfigured ? "configured" : "needs token",
|
||||
},
|
||||
{
|
||||
value: "signal",
|
||||
label: "Signal (signal-cli)",
|
||||
hint: signalCliDetected ? "signal-cli found" : "signal-cli missing",
|
||||
},
|
||||
{
|
||||
value: "imessage",
|
||||
label: "iMessage (imsg)",
|
||||
hint: imessageCliDetected ? "imsg found" : "imsg missing",
|
||||
},
|
||||
],
|
||||
})) as ProviderChoice[];
|
||||
|
||||
let next = cfg;
|
||||
|
||||
if (selection.includes("whatsapp")) {
|
||||
if (!whatsappLinked) {
|
||||
note(
|
||||
await prompter.note(
|
||||
[
|
||||
"Scan the QR with WhatsApp on your phone.",
|
||||
"Credentials are stored under ~/.clawdis/credentials/ for future runs.",
|
||||
@@ -266,15 +231,12 @@ export async function setupProviders(
|
||||
"WhatsApp linking",
|
||||
);
|
||||
}
|
||||
const wantsLink = guardCancel(
|
||||
await confirm({
|
||||
message: whatsappLinked
|
||||
? "WhatsApp already linked. Re-link now?"
|
||||
: "Link WhatsApp now (QR)?",
|
||||
initialValue: !whatsappLinked,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const wantsLink = await prompter.confirm({
|
||||
message: whatsappLinked
|
||||
? "WhatsApp already linked. Re-link now?"
|
||||
: "Link WhatsApp now (QR)?",
|
||||
initialValue: !whatsappLinked,
|
||||
});
|
||||
if (wantsLink) {
|
||||
try {
|
||||
await loginWeb(false, "web");
|
||||
@@ -282,25 +244,25 @@ export async function setupProviders(
|
||||
runtime.error(`WhatsApp login failed: ${String(err)}`);
|
||||
}
|
||||
} else if (!whatsappLinked) {
|
||||
note("Run `clawdis login` later to link WhatsApp.", "WhatsApp");
|
||||
await prompter.note(
|
||||
"Run `clawdis login` later to link WhatsApp.",
|
||||
"WhatsApp",
|
||||
);
|
||||
}
|
||||
|
||||
next = await promptWhatsAppAllowFrom(next, runtime);
|
||||
next = await promptWhatsAppAllowFrom(next, runtime, prompter);
|
||||
}
|
||||
|
||||
if (selection.includes("telegram")) {
|
||||
let token: string | null = null;
|
||||
if (!telegramConfigured) {
|
||||
noteTelegramTokenHelp();
|
||||
await noteTelegramTokenHelp(prompter);
|
||||
}
|
||||
if (telegramEnv && !cfg.telegram?.botToken) {
|
||||
const keepEnv = guardCancel(
|
||||
await confirm({
|
||||
message: "TELEGRAM_BOT_TOKEN detected. Use env var?",
|
||||
initialValue: true,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const keepEnv = await prompter.confirm({
|
||||
message: "TELEGRAM_BOT_TOKEN detected. Use env var?",
|
||||
initialValue: true,
|
||||
});
|
||||
if (keepEnv) {
|
||||
next = {
|
||||
...next,
|
||||
@@ -311,43 +273,31 @@ export async function setupProviders(
|
||||
};
|
||||
} else {
|
||||
token = String(
|
||||
guardCancel(
|
||||
await text({
|
||||
message: "Enter Telegram bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
),
|
||||
await prompter.text({
|
||||
message: "Enter Telegram bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
).trim();
|
||||
}
|
||||
} else if (cfg.telegram?.botToken) {
|
||||
const keep = guardCancel(
|
||||
await confirm({
|
||||
message: "Telegram token already configured. Keep it?",
|
||||
initialValue: true,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const keep = await prompter.confirm({
|
||||
message: "Telegram token already configured. Keep it?",
|
||||
initialValue: true,
|
||||
});
|
||||
if (!keep) {
|
||||
token = String(
|
||||
guardCancel(
|
||||
await text({
|
||||
message: "Enter Telegram bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
),
|
||||
await prompter.text({
|
||||
message: "Enter Telegram bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
).trim();
|
||||
}
|
||||
} else {
|
||||
token = String(
|
||||
guardCancel(
|
||||
await text({
|
||||
message: "Enter Telegram bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
),
|
||||
await prompter.text({
|
||||
message: "Enter Telegram bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
).trim();
|
||||
}
|
||||
|
||||
@@ -366,16 +316,13 @@ export async function setupProviders(
|
||||
if (selection.includes("discord")) {
|
||||
let token: string | null = null;
|
||||
if (!discordConfigured) {
|
||||
noteDiscordTokenHelp();
|
||||
await noteDiscordTokenHelp(prompter);
|
||||
}
|
||||
if (discordEnv && !cfg.discord?.token) {
|
||||
const keepEnv = guardCancel(
|
||||
await confirm({
|
||||
message: "DISCORD_BOT_TOKEN detected. Use env var?",
|
||||
initialValue: true,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const keepEnv = await prompter.confirm({
|
||||
message: "DISCORD_BOT_TOKEN detected. Use env var?",
|
||||
initialValue: true,
|
||||
});
|
||||
if (keepEnv) {
|
||||
next = {
|
||||
...next,
|
||||
@@ -386,43 +333,31 @@ export async function setupProviders(
|
||||
};
|
||||
} else {
|
||||
token = String(
|
||||
guardCancel(
|
||||
await text({
|
||||
message: "Enter Discord bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
),
|
||||
await prompter.text({
|
||||
message: "Enter Discord bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
).trim();
|
||||
}
|
||||
} else if (cfg.discord?.token) {
|
||||
const keep = guardCancel(
|
||||
await confirm({
|
||||
message: "Discord token already configured. Keep it?",
|
||||
initialValue: true,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const keep = await prompter.confirm({
|
||||
message: "Discord token already configured. Keep it?",
|
||||
initialValue: true,
|
||||
});
|
||||
if (!keep) {
|
||||
token = String(
|
||||
guardCancel(
|
||||
await text({
|
||||
message: "Enter Discord bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
),
|
||||
await prompter.text({
|
||||
message: "Enter Discord bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
).trim();
|
||||
}
|
||||
} else {
|
||||
token = String(
|
||||
guardCancel(
|
||||
await text({
|
||||
message: "Enter Discord bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
),
|
||||
await prompter.text({
|
||||
message: "Enter Discord bot token",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
).trim();
|
||||
}
|
||||
|
||||
@@ -442,33 +377,39 @@ export async function setupProviders(
|
||||
let resolvedCliPath = signalCliPath;
|
||||
let cliDetected = signalCliDetected;
|
||||
if (options?.allowSignalInstall) {
|
||||
const wantsInstall = guardCancel(
|
||||
await confirm({
|
||||
message: cliDetected
|
||||
? "signal-cli detected. Reinstall/update now?"
|
||||
: "signal-cli not found. Install now?",
|
||||
initialValue: !cliDetected,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const wantsInstall = await prompter.confirm({
|
||||
message: cliDetected
|
||||
? "signal-cli detected. Reinstall/update now?"
|
||||
: "signal-cli not found. Install now?",
|
||||
initialValue: !cliDetected,
|
||||
});
|
||||
if (wantsInstall) {
|
||||
try {
|
||||
const result = await installSignalCli(runtime);
|
||||
if (result.ok && result.cliPath) {
|
||||
cliDetected = true;
|
||||
resolvedCliPath = result.cliPath;
|
||||
note(`Installed signal-cli at ${result.cliPath}`, "Signal");
|
||||
await prompter.note(
|
||||
`Installed signal-cli at ${result.cliPath}`,
|
||||
"Signal",
|
||||
);
|
||||
} else if (!result.ok) {
|
||||
note(result.error ?? "signal-cli install failed.", "Signal");
|
||||
await prompter.note(
|
||||
result.error ?? "signal-cli install failed.",
|
||||
"Signal",
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
note(`signal-cli install failed: ${String(err)}`, "Signal");
|
||||
await prompter.note(
|
||||
`signal-cli install failed: ${String(err)}`,
|
||||
"Signal",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!cliDetected) {
|
||||
note(
|
||||
await prompter.note(
|
||||
"signal-cli not found. Install it, then rerun this step or set signal.cliPath.",
|
||||
"Signal",
|
||||
);
|
||||
@@ -476,25 +417,19 @@ export async function setupProviders(
|
||||
|
||||
let account = cfg.signal?.account ?? "";
|
||||
if (account) {
|
||||
const keep = guardCancel(
|
||||
await confirm({
|
||||
message: `Signal account set (${account}). Keep it?`,
|
||||
initialValue: true,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const keep = await prompter.confirm({
|
||||
message: `Signal account set (${account}). Keep it?`,
|
||||
initialValue: true,
|
||||
});
|
||||
if (!keep) account = "";
|
||||
}
|
||||
|
||||
if (!account) {
|
||||
account = String(
|
||||
guardCancel(
|
||||
await text({
|
||||
message: "Signal bot number (E.164)",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
),
|
||||
await prompter.text({
|
||||
message: "Signal bot number (E.164)",
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
).trim();
|
||||
}
|
||||
|
||||
@@ -510,7 +445,7 @@ export async function setupProviders(
|
||||
};
|
||||
}
|
||||
|
||||
note(
|
||||
await prompter.note(
|
||||
[
|
||||
'Link device with: signal-cli link -n "Clawdis"',
|
||||
"Scan QR in Signal → Linked Devices",
|
||||
@@ -523,17 +458,17 @@ export async function setupProviders(
|
||||
if (selection.includes("imessage")) {
|
||||
let resolvedCliPath = imessageCliPath;
|
||||
if (!imessageCliDetected) {
|
||||
const entered = guardCancel(
|
||||
await text({
|
||||
message: "imsg CLI path",
|
||||
initialValue: resolvedCliPath,
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const entered = await prompter.text({
|
||||
message: "imsg CLI path",
|
||||
initialValue: resolvedCliPath,
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
});
|
||||
resolvedCliPath = String(entered).trim();
|
||||
if (!resolvedCliPath) {
|
||||
note("imsg CLI path required to enable iMessage.", "iMessage");
|
||||
await prompter.note(
|
||||
"imsg CLI path required to enable iMessage.",
|
||||
"iMessage",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,7 +483,7 @@ export async function setupProviders(
|
||||
};
|
||||
}
|
||||
|
||||
note(
|
||||
await prompter.note(
|
||||
[
|
||||
"Ensure Clawdis has Full Disk Access to Messages DB.",
|
||||
"Grant Automation permission for Messages when prompted.",
|
||||
@@ -560,13 +495,10 @@ export async function setupProviders(
|
||||
|
||||
if (options?.allowDisable) {
|
||||
if (!selection.includes("telegram") && telegramConfigured) {
|
||||
const disable = guardCancel(
|
||||
await confirm({
|
||||
message: "Disable Telegram provider?",
|
||||
initialValue: false,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const disable = await prompter.confirm({
|
||||
message: "Disable Telegram provider?",
|
||||
initialValue: false,
|
||||
});
|
||||
if (disable) {
|
||||
next = {
|
||||
...next,
|
||||
@@ -576,13 +508,10 @@ export async function setupProviders(
|
||||
}
|
||||
|
||||
if (!selection.includes("discord") && discordConfigured) {
|
||||
const disable = guardCancel(
|
||||
await confirm({
|
||||
message: "Disable Discord provider?",
|
||||
initialValue: false,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const disable = await prompter.confirm({
|
||||
message: "Disable Discord provider?",
|
||||
initialValue: false,
|
||||
});
|
||||
if (disable) {
|
||||
next = {
|
||||
...next,
|
||||
@@ -592,13 +521,10 @@ export async function setupProviders(
|
||||
}
|
||||
|
||||
if (!selection.includes("signal") && signalConfigured) {
|
||||
const disable = guardCancel(
|
||||
await confirm({
|
||||
message: "Disable Signal provider?",
|
||||
initialValue: false,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const disable = await prompter.confirm({
|
||||
message: "Disable Signal provider?",
|
||||
initialValue: false,
|
||||
});
|
||||
if (disable) {
|
||||
next = {
|
||||
...next,
|
||||
@@ -608,13 +534,10 @@ export async function setupProviders(
|
||||
}
|
||||
|
||||
if (!selection.includes("imessage") && imessageConfigured) {
|
||||
const disable = guardCancel(
|
||||
await confirm({
|
||||
message: "Disable iMessage provider?",
|
||||
initialValue: false,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const disable = await prompter.confirm({
|
||||
message: "Disable iMessage provider?",
|
||||
initialValue: false,
|
||||
});
|
||||
if (disable) {
|
||||
next = {
|
||||
...next,
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { confirm, note, select, spinner, text } from "@clack/prompts";
|
||||
|
||||
import type { ClawdisConfig } from "../config/config.js";
|
||||
import type { GatewayBonjourBeacon } from "../infra/bonjour-discovery.js";
|
||||
import { discoverGatewayBeacons } from "../infra/bonjour-discovery.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { detectBinary, guardCancel } from "./onboard-helpers.js";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import { detectBinary } from "./onboard-helpers.js";
|
||||
|
||||
const DEFAULT_GATEWAY_URL = "ws://127.0.0.1:18789";
|
||||
|
||||
@@ -28,7 +26,7 @@ function ensureWsUrl(value: string): string {
|
||||
|
||||
export async function promptRemoteGatewayConfig(
|
||||
cfg: ClawdisConfig,
|
||||
runtime: RuntimeEnv,
|
||||
prompter: WizardPrompter,
|
||||
): Promise<ClawdisConfig> {
|
||||
let selectedBeacon: GatewayBonjourBeacon | null = null;
|
||||
let suggestedUrl = cfg.gateway?.remote?.url ?? DEFAULT_GATEWAY_URL;
|
||||
@@ -36,25 +34,21 @@ export async function promptRemoteGatewayConfig(
|
||||
const hasBonjourTool =
|
||||
(await detectBinary("dns-sd")) || (await detectBinary("avahi-browse"));
|
||||
const wantsDiscover = hasBonjourTool
|
||||
? guardCancel(
|
||||
await confirm({
|
||||
message: "Discover gateway on LAN (Bonjour)?",
|
||||
initialValue: true,
|
||||
}),
|
||||
runtime,
|
||||
)
|
||||
? await prompter.confirm({
|
||||
message: "Discover gateway on LAN (Bonjour)?",
|
||||
initialValue: true,
|
||||
})
|
||||
: false;
|
||||
|
||||
if (!hasBonjourTool) {
|
||||
note(
|
||||
await prompter.note(
|
||||
"Bonjour discovery requires dns-sd (macOS) or avahi-browse (Linux).",
|
||||
"Discovery",
|
||||
);
|
||||
}
|
||||
|
||||
if (wantsDiscover) {
|
||||
const spin = spinner();
|
||||
spin.start("Searching for gateways…");
|
||||
const spin = prompter.progress("Searching for gateways…");
|
||||
const beacons = await discoverGatewayBeacons({ timeoutMs: 2000 });
|
||||
spin.stop(
|
||||
beacons.length > 0
|
||||
@@ -63,19 +57,16 @@ export async function promptRemoteGatewayConfig(
|
||||
);
|
||||
|
||||
if (beacons.length > 0) {
|
||||
const selection = guardCancel(
|
||||
await select({
|
||||
message: "Select gateway",
|
||||
options: [
|
||||
...beacons.map((beacon, index) => ({
|
||||
value: String(index),
|
||||
label: buildLabel(beacon),
|
||||
})),
|
||||
{ value: "manual", label: "Enter URL manually" },
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const selection = await prompter.select({
|
||||
message: "Select gateway",
|
||||
options: [
|
||||
...beacons.map((beacon, index) => ({
|
||||
value: String(index),
|
||||
label: buildLabel(beacon),
|
||||
})),
|
||||
{ value: "manual", label: "Enter URL manually" },
|
||||
],
|
||||
});
|
||||
if (selection !== "manual") {
|
||||
const idx = Number.parseInt(String(selection), 10);
|
||||
selectedBeacon = Number.isFinite(idx) ? (beacons[idx] ?? null) : null;
|
||||
@@ -87,24 +78,21 @@ export async function promptRemoteGatewayConfig(
|
||||
const host = pickHost(selectedBeacon);
|
||||
const port = selectedBeacon.gatewayPort ?? 18789;
|
||||
if (host) {
|
||||
const mode = guardCancel(
|
||||
await select({
|
||||
message: "Connection method",
|
||||
options: [
|
||||
{
|
||||
value: "direct",
|
||||
label: `Direct gateway WS (${host}:${port})`,
|
||||
},
|
||||
{ value: "ssh", label: "SSH tunnel (loopback)" },
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const mode = await prompter.select({
|
||||
message: "Connection method",
|
||||
options: [
|
||||
{
|
||||
value: "direct",
|
||||
label: `Direct gateway WS (${host}:${port})`,
|
||||
},
|
||||
{ value: "ssh", label: "SSH tunnel (loopback)" },
|
||||
],
|
||||
});
|
||||
if (mode === "direct") {
|
||||
suggestedUrl = `ws://${host}:${port}`;
|
||||
} else {
|
||||
suggestedUrl = DEFAULT_GATEWAY_URL;
|
||||
note(
|
||||
await prompter.note(
|
||||
[
|
||||
"Start a tunnel before using the CLI:",
|
||||
`ssh -N -L 18789:127.0.0.1:18789 <user>@${host}${
|
||||
@@ -117,42 +105,33 @@ export async function promptRemoteGatewayConfig(
|
||||
}
|
||||
}
|
||||
|
||||
const urlInput = guardCancel(
|
||||
await text({
|
||||
message: "Gateway WebSocket URL",
|
||||
initialValue: suggestedUrl,
|
||||
validate: (value) =>
|
||||
String(value).trim().startsWith("ws://") ||
|
||||
String(value).trim().startsWith("wss://")
|
||||
? undefined
|
||||
: "URL must start with ws:// or wss://",
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const urlInput = await prompter.text({
|
||||
message: "Gateway WebSocket URL",
|
||||
initialValue: suggestedUrl,
|
||||
validate: (value) =>
|
||||
String(value).trim().startsWith("ws://") ||
|
||||
String(value).trim().startsWith("wss://")
|
||||
? undefined
|
||||
: "URL must start with ws:// or wss://",
|
||||
});
|
||||
const url = ensureWsUrl(String(urlInput));
|
||||
|
||||
const authChoice = guardCancel(
|
||||
await select({
|
||||
message: "Gateway auth",
|
||||
options: [
|
||||
{ value: "token", label: "Token (recommended)" },
|
||||
{ value: "off", label: "No auth" },
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
) as "token" | "off";
|
||||
const authChoice = (await prompter.select({
|
||||
message: "Gateway auth",
|
||||
options: [
|
||||
{ value: "token", label: "Token (recommended)" },
|
||||
{ value: "off", label: "No auth" },
|
||||
],
|
||||
})) as "token" | "off";
|
||||
|
||||
let token = cfg.gateway?.remote?.token ?? "";
|
||||
if (authChoice === "token") {
|
||||
token = String(
|
||||
guardCancel(
|
||||
await text({
|
||||
message: "Gateway token",
|
||||
initialValue: token,
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
),
|
||||
await prompter.text({
|
||||
message: "Gateway token",
|
||||
initialValue: token,
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
).trim();
|
||||
} else {
|
||||
token = "";
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import {
|
||||
confirm,
|
||||
multiselect,
|
||||
note,
|
||||
select,
|
||||
spinner,
|
||||
text,
|
||||
} from "@clack/prompts";
|
||||
|
||||
import { installSkill } from "../agents/skills-install.js";
|
||||
import { buildWorkspaceSkillStatus } from "../agents/skills-status.js";
|
||||
import type { ClawdisConfig } from "../config/config.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { guardCancel, resolveNodeManagerOptions } from "./onboard-helpers.js";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import { resolveNodeManagerOptions } from "./onboard-helpers.js";
|
||||
|
||||
function summarizeInstallFailure(message: string): string | undefined {
|
||||
const cleaned = message
|
||||
@@ -58,6 +50,7 @@ export async function setupSkills(
|
||||
cfg: ClawdisConfig,
|
||||
workspaceDir: string,
|
||||
runtime: RuntimeEnv,
|
||||
prompter: WizardPrompter,
|
||||
): Promise<ClawdisConfig> {
|
||||
const report = buildWorkspaceSkillStatus(workspaceDir, { config: cfg });
|
||||
const eligible = report.skills.filter((s) => s.eligible);
|
||||
@@ -66,7 +59,7 @@ export async function setupSkills(
|
||||
);
|
||||
const blocked = report.skills.filter((s) => s.blockedByAllowlist);
|
||||
|
||||
note(
|
||||
await prompter.note(
|
||||
[
|
||||
`Eligible: ${eligible.length}`,
|
||||
`Missing requirements: ${missing.length}`,
|
||||
@@ -75,22 +68,16 @@ export async function setupSkills(
|
||||
"Skills status",
|
||||
);
|
||||
|
||||
const shouldConfigure = guardCancel(
|
||||
await confirm({
|
||||
message: "Configure skills now? (recommended)",
|
||||
initialValue: true,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const shouldConfigure = await prompter.confirm({
|
||||
message: "Configure skills now? (recommended)",
|
||||
initialValue: true,
|
||||
});
|
||||
if (!shouldConfigure) return cfg;
|
||||
|
||||
const nodeManager = guardCancel(
|
||||
await select({
|
||||
message: "Preferred node manager for skill installs",
|
||||
options: resolveNodeManagerOptions(),
|
||||
}),
|
||||
runtime,
|
||||
) as "npm" | "pnpm" | "bun";
|
||||
const nodeManager = (await prompter.select({
|
||||
message: "Preferred node manager for skill installs",
|
||||
options: resolveNodeManagerOptions(),
|
||||
})) as "npm" | "pnpm" | "bun";
|
||||
|
||||
let next: ClawdisConfig = {
|
||||
...cfg,
|
||||
@@ -107,24 +94,21 @@ export async function setupSkills(
|
||||
(skill) => skill.install.length > 0 && skill.missing.bins.length > 0,
|
||||
);
|
||||
if (installable.length > 0) {
|
||||
const toInstall = guardCancel(
|
||||
await multiselect({
|
||||
message: "Install missing skill dependencies",
|
||||
options: [
|
||||
{
|
||||
value: "__skip__",
|
||||
label: "Skip for now",
|
||||
hint: "Continue without installing dependencies",
|
||||
},
|
||||
...installable.map((skill) => ({
|
||||
value: skill.name,
|
||||
label: `${skill.emoji ?? "🧩"} ${skill.name}`,
|
||||
hint: formatSkillHint(skill),
|
||||
})),
|
||||
],
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const toInstall = await prompter.multiselect({
|
||||
message: "Install missing skill dependencies",
|
||||
options: [
|
||||
{
|
||||
value: "__skip__",
|
||||
label: "Skip for now",
|
||||
hint: "Continue without installing dependencies",
|
||||
},
|
||||
...installable.map((skill) => ({
|
||||
value: skill.name,
|
||||
label: `${skill.emoji ?? "🧩"} ${skill.name}`,
|
||||
hint: formatSkillHint(skill),
|
||||
})),
|
||||
],
|
||||
});
|
||||
|
||||
const selected = (toInstall as string[]).filter(
|
||||
(name) => name !== "__skip__",
|
||||
@@ -134,8 +118,7 @@ export async function setupSkills(
|
||||
if (!target || target.install.length === 0) continue;
|
||||
const installId = target.install[0]?.id;
|
||||
if (!installId) continue;
|
||||
const spin = spinner();
|
||||
spin.start(`Installing ${name}…`);
|
||||
const spin = prompter.progress(`Installing ${name}…`);
|
||||
const result = await installSkill({
|
||||
workspaceDir,
|
||||
skillName: target.name,
|
||||
@@ -161,22 +144,16 @@ export async function setupSkills(
|
||||
|
||||
for (const skill of missing) {
|
||||
if (!skill.primaryEnv || skill.missing.env.length === 0) continue;
|
||||
const wantsKey = guardCancel(
|
||||
await confirm({
|
||||
message: `Set ${skill.primaryEnv} for ${skill.name}?`,
|
||||
initialValue: false,
|
||||
}),
|
||||
runtime,
|
||||
);
|
||||
const wantsKey = await prompter.confirm({
|
||||
message: `Set ${skill.primaryEnv} for ${skill.name}?`,
|
||||
initialValue: false,
|
||||
});
|
||||
if (!wantsKey) continue;
|
||||
const apiKey = String(
|
||||
guardCancel(
|
||||
await text({
|
||||
message: `Enter ${skill.primaryEnv}`,
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
runtime,
|
||||
),
|
||||
await prompter.text({
|
||||
message: `Enter ${skill.primaryEnv}`,
|
||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
);
|
||||
next = upsertSkillEntry(next, skill.skillKey, { apiKey: apiKey.trim() });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user