refactor: polish CLI theme + progress helpers
This commit is contained in:
@@ -23,6 +23,12 @@ export type ProgressReporter = {
|
|||||||
done: () => void;
|
done: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ProgressTotalsUpdate = {
|
||||||
|
completed: number;
|
||||||
|
total: number;
|
||||||
|
label?: string;
|
||||||
|
};
|
||||||
|
|
||||||
const noopReporter: ProgressReporter = {
|
const noopReporter: ProgressReporter = {
|
||||||
setLabel: () => {},
|
setLabel: () => {},
|
||||||
setPercent: () => {},
|
setPercent: () => {},
|
||||||
@@ -133,3 +139,20 @@ export async function withProgress<T>(
|
|||||||
progress.done();
|
progress.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function withProgressTotals<T>(
|
||||||
|
options: ProgressOptions,
|
||||||
|
work: (
|
||||||
|
update: (update: ProgressTotalsUpdate) => void,
|
||||||
|
progress: ProgressReporter,
|
||||||
|
) => Promise<T>,
|
||||||
|
): Promise<T> {
|
||||||
|
return await withProgress(options, async (progress) => {
|
||||||
|
const update = ({ completed, total, label }: ProgressTotalsUpdate) => {
|
||||||
|
if (label) progress.setLabel(label);
|
||||||
|
if (!Number.isFinite(total) || total <= 0) return;
|
||||||
|
progress.setPercent((completed / total) * 100);
|
||||||
|
};
|
||||||
|
return await work(update, progress);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
const DEFAULT_TAGLINE =
|
const DEFAULT_TAGLINE = "All your chats, one ClawdBot.";
|
||||||
"Send, receive, and auto-reply on WhatsApp (web) and Telegram (bot).";
|
|
||||||
|
|
||||||
const TAGLINES: string[] = [];
|
const TAGLINES: string[] = [];
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
type ModelScanResult,
|
type ModelScanResult,
|
||||||
scanOpenRouterModels,
|
scanOpenRouterModels,
|
||||||
} from "../../agents/model-scan.js";
|
} from "../../agents/model-scan.js";
|
||||||
import { withProgress } from "../../cli/progress.js";
|
import { withProgressTotals } from "../../cli/progress.js";
|
||||||
import { CONFIG_PATH_CLAWDBOT, loadConfig } from "../../config/config.js";
|
import { CONFIG_PATH_CLAWDBOT, loadConfig } from "../../config/config.js";
|
||||||
import type { RuntimeEnv } from "../../runtime.js";
|
import type { RuntimeEnv } from "../../runtime.js";
|
||||||
import { formatMs, formatTokenK, updateConfig } from "./shared.js";
|
import { formatMs, formatTokenK, updateConfig } from "./shared.js";
|
||||||
@@ -189,13 +189,13 @@ export async function modelsScanCommand(
|
|||||||
storedKey = undefined;
|
storedKey = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const results = await withProgress(
|
const results = await withProgressTotals(
|
||||||
{
|
{
|
||||||
label: "Scanning OpenRouter models...",
|
label: "Scanning OpenRouter models...",
|
||||||
indeterminate: false,
|
indeterminate: false,
|
||||||
enabled: opts.json !== true,
|
enabled: opts.json !== true,
|
||||||
},
|
},
|
||||||
async (progress) =>
|
async (update) =>
|
||||||
await scanOpenRouterModels({
|
await scanOpenRouterModels({
|
||||||
apiKey: storedKey ?? undefined,
|
apiKey: storedKey ?? undefined,
|
||||||
minParamB: minParams,
|
minParamB: minParams,
|
||||||
@@ -206,10 +206,12 @@ export async function modelsScanCommand(
|
|||||||
probe,
|
probe,
|
||||||
onProgress: ({ phase, completed, total }) => {
|
onProgress: ({ phase, completed, total }) => {
|
||||||
if (phase !== "probe") return;
|
if (phase !== "probe") return;
|
||||||
if (total <= 0) return;
|
|
||||||
const labelBase = probe ? "Probing models" : "Scanning models";
|
const labelBase = probe ? "Probing models" : "Scanning models";
|
||||||
progress.setLabel(`${labelBase} (${completed}/${total})`);
|
update({
|
||||||
progress.setPercent((completed / total) * 100);
|
completed,
|
||||||
|
total,
|
||||||
|
label: `${labelBase} (${completed}/${total})`,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import chalk from "chalk";
|
|
||||||
import { type ClawdbotConfig, loadConfig } from "../config/config.js";
|
import { type ClawdbotConfig, loadConfig } from "../config/config.js";
|
||||||
import { resolveTelegramToken } from "../telegram/token.js";
|
import { resolveTelegramToken } from "../telegram/token.js";
|
||||||
|
import { theme } from "../terminal/theme.js";
|
||||||
import { normalizeE164 } from "../utils.js";
|
import { normalizeE164 } from "../utils.js";
|
||||||
import {
|
import {
|
||||||
getWebAuthAgeMs,
|
getWebAuthAgeMs,
|
||||||
@@ -30,7 +30,7 @@ export async function buildProviderSummary(
|
|||||||
|
|
||||||
const webEnabled = effective.web?.enabled !== false;
|
const webEnabled = effective.web?.enabled !== false;
|
||||||
if (!webEnabled) {
|
if (!webEnabled) {
|
||||||
lines.push(tint("WhatsApp: disabled", chalk.cyan));
|
lines.push(tint("WhatsApp: disabled", theme.muted));
|
||||||
} else {
|
} else {
|
||||||
const webLinked = await webAuthExists();
|
const webLinked = await webAuthExists();
|
||||||
const authAgeMs = getWebAuthAgeMs();
|
const authAgeMs = getWebAuthAgeMs();
|
||||||
@@ -40,28 +40,28 @@ export async function buildProviderSummary(
|
|||||||
webLinked
|
webLinked
|
||||||
? tint(
|
? tint(
|
||||||
`WhatsApp: linked${e164 ? ` ${e164}` : ""}${authAge}`,
|
`WhatsApp: linked${e164 ? ` ${e164}` : ""}${authAge}`,
|
||||||
chalk.green,
|
theme.success,
|
||||||
)
|
)
|
||||||
: tint("WhatsApp: not linked", chalk.red),
|
: tint("WhatsApp: not linked", theme.error),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const telegramEnabled = effective.telegram?.enabled !== false;
|
const telegramEnabled = effective.telegram?.enabled !== false;
|
||||||
if (!telegramEnabled) {
|
if (!telegramEnabled) {
|
||||||
lines.push(tint("Telegram: disabled", chalk.cyan));
|
lines.push(tint("Telegram: disabled", theme.muted));
|
||||||
} else {
|
} else {
|
||||||
const { token: telegramToken } = resolveTelegramToken(effective);
|
const { token: telegramToken } = resolveTelegramToken(effective);
|
||||||
const telegramConfigured = Boolean(telegramToken?.trim());
|
const telegramConfigured = Boolean(telegramToken?.trim());
|
||||||
lines.push(
|
lines.push(
|
||||||
telegramConfigured
|
telegramConfigured
|
||||||
? tint("Telegram: configured", chalk.green)
|
? tint("Telegram: configured", theme.success)
|
||||||
: tint("Telegram: not configured", chalk.cyan),
|
: tint("Telegram: not configured", theme.muted),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const signalEnabled = effective.signal?.enabled !== false;
|
const signalEnabled = effective.signal?.enabled !== false;
|
||||||
if (!signalEnabled) {
|
if (!signalEnabled) {
|
||||||
lines.push(tint("Signal: disabled", chalk.cyan));
|
lines.push(tint("Signal: disabled", theme.muted));
|
||||||
} else {
|
} else {
|
||||||
const signalConfigured =
|
const signalConfigured =
|
||||||
Boolean(effective.signal) &&
|
Boolean(effective.signal) &&
|
||||||
@@ -75,20 +75,20 @@ export async function buildProviderSummary(
|
|||||||
);
|
);
|
||||||
lines.push(
|
lines.push(
|
||||||
signalConfigured
|
signalConfigured
|
||||||
? tint("Signal: configured", chalk.green)
|
? tint("Signal: configured", theme.success)
|
||||||
: tint("Signal: not configured", chalk.cyan),
|
: tint("Signal: not configured", theme.muted),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const imessageEnabled = effective.imessage?.enabled !== false;
|
const imessageEnabled = effective.imessage?.enabled !== false;
|
||||||
if (!imessageEnabled) {
|
if (!imessageEnabled) {
|
||||||
lines.push(tint("iMessage: disabled", chalk.cyan));
|
lines.push(tint("iMessage: disabled", theme.muted));
|
||||||
} else {
|
} else {
|
||||||
const imessageConfigured = Boolean(effective.imessage);
|
const imessageConfigured = Boolean(effective.imessage);
|
||||||
lines.push(
|
lines.push(
|
||||||
imessageConfigured
|
imessageConfigured
|
||||||
? tint("iMessage: configured", chalk.green)
|
? tint("iMessage: configured", theme.success)
|
||||||
: tint("iMessage: not configured", chalk.cyan),
|
: tint("iMessage: not configured", theme.muted),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ export async function buildProviderSummary(
|
|||||||
? effective.whatsapp.allowFrom.map(normalizeE164).filter(Boolean)
|
? effective.whatsapp.allowFrom.map(normalizeE164).filter(Boolean)
|
||||||
: [];
|
: [];
|
||||||
if (allowFrom.length) {
|
if (allowFrom.length) {
|
||||||
lines.push(tint(`AllowFrom: ${allowFrom.join(", ")}`, chalk.cyan));
|
lines.push(tint(`AllowFrom: ${allowFrom.join(", ")}`, theme.muted));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { existsSync } from "node:fs";
|
import { existsSync } from "node:fs";
|
||||||
import chalk from "chalk";
|
|
||||||
import { promptYesNo } from "../cli/prompt.js";
|
import { promptYesNo } from "../cli/prompt.js";
|
||||||
import {
|
import {
|
||||||
danger,
|
danger,
|
||||||
@@ -8,6 +7,7 @@ import {
|
|||||||
shouldLogVerbose,
|
shouldLogVerbose,
|
||||||
warn,
|
warn,
|
||||||
} from "../globals.js";
|
} from "../globals.js";
|
||||||
|
import { colorize, isRich, theme } from "../terminal/theme.js";
|
||||||
import { runExec } from "../process/exec.js";
|
import { runExec } from "../process/exec.js";
|
||||||
import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
|
import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
|
||||||
import { ensureBinary } from "./binaries.js";
|
import { ensureBinary } from "./binaries.js";
|
||||||
@@ -180,8 +180,17 @@ export async function ensureFunnel(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (shouldLogVerbose()) {
|
if (shouldLogVerbose()) {
|
||||||
if (stdout.trim()) runtime.error(chalk.gray(`stdout: ${stdout.trim()}`));
|
const rich = isRich();
|
||||||
if (stderr.trim()) runtime.error(chalk.gray(`stderr: ${stderr.trim()}`));
|
if (stdout.trim()) {
|
||||||
|
runtime.error(
|
||||||
|
colorize(rich, theme.muted, `stdout: ${stdout.trim()}`),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (stderr.trim()) {
|
||||||
|
runtime.error(
|
||||||
|
colorize(rich, theme.muted, `stderr: ${stderr.trim()}`),
|
||||||
|
);
|
||||||
|
}
|
||||||
runtime.error(err as Error);
|
runtime.error(err as Error);
|
||||||
}
|
}
|
||||||
runtime.exit(1);
|
runtime.exit(1);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
|
||||||
|
// Semantic palette for CLI output. Keep in sync with docs/cli/index.md.
|
||||||
export const LOBSTER_PALETTE = {
|
export const LOBSTER_PALETTE = {
|
||||||
accent: "#FF5A2D",
|
accent: "#FF5A2D",
|
||||||
accentBright: "#FF7A3D",
|
accentBright: "#FF7A3D",
|
||||||
|
|||||||
Reference in New Issue
Block a user