feat: add richer color to models output
This commit is contained in:
@@ -31,7 +31,6 @@ import {
|
|||||||
CONFIG_PATH_CLAWDBOT,
|
CONFIG_PATH_CLAWDBOT,
|
||||||
loadConfig,
|
loadConfig,
|
||||||
} from "../../config/config.js";
|
} from "../../config/config.js";
|
||||||
import { info } from "../../globals.js";
|
|
||||||
import {
|
import {
|
||||||
getShellEnvAppliedKeys,
|
getShellEnvAppliedKeys,
|
||||||
shouldEnableShellEnvFallback,
|
shouldEnableShellEnvFallback,
|
||||||
@@ -59,6 +58,24 @@ const isRich = (opts?: { json?: boolean; plain?: boolean }) =>
|
|||||||
|
|
||||||
const pad = (value: string, size: number) => value.padEnd(size);
|
const pad = (value: string, size: number) => value.padEnd(size);
|
||||||
|
|
||||||
|
const colorize = (
|
||||||
|
rich: boolean,
|
||||||
|
color: (value: string) => string,
|
||||||
|
value: string,
|
||||||
|
) => (rich ? color(value) : value);
|
||||||
|
|
||||||
|
const formatTag = (tag: string, rich: boolean) => {
|
||||||
|
if (!rich) return tag;
|
||||||
|
if (tag === "default") return chalk.greenBright(tag);
|
||||||
|
if (tag === "image") return chalk.magentaBright(tag);
|
||||||
|
if (tag === "configured") return chalk.cyan(tag);
|
||||||
|
if (tag === "missing") return chalk.red(tag);
|
||||||
|
if (tag.startsWith("fallback#")) return chalk.yellow(tag);
|
||||||
|
if (tag.startsWith("img-fallback#")) return chalk.yellowBright(tag);
|
||||||
|
if (tag.startsWith("alias:")) return chalk.blue(tag);
|
||||||
|
return chalk.gray(tag);
|
||||||
|
};
|
||||||
|
|
||||||
const truncate = (value: string, max: number) => {
|
const truncate = (value: string, max: number) => {
|
||||||
if (value.length <= max) return value;
|
if (value.length <= max) return value;
|
||||||
if (max <= 3) return value.slice(0, max);
|
if (max <= 3) return value.slice(0, max);
|
||||||
@@ -424,23 +441,45 @@ function printModelTable(
|
|||||||
const keyLabel = pad(truncate(row.key, MODEL_PAD), MODEL_PAD);
|
const keyLabel = pad(truncate(row.key, MODEL_PAD), MODEL_PAD);
|
||||||
const inputLabel = pad(row.input || "-", INPUT_PAD);
|
const inputLabel = pad(row.input || "-", INPUT_PAD);
|
||||||
const ctxLabel = pad(formatTokenK(row.contextWindow), CTX_PAD);
|
const ctxLabel = pad(formatTokenK(row.contextWindow), CTX_PAD);
|
||||||
const localLabel = pad(
|
const localText = row.local === null ? "-" : row.local ? "yes" : "no";
|
||||||
row.local === null ? "-" : row.local ? "yes" : "no",
|
const localLabel = pad(localText, LOCAL_PAD);
|
||||||
LOCAL_PAD,
|
const authText =
|
||||||
|
row.available === null ? "-" : row.available ? "yes" : "no";
|
||||||
|
const authLabel = pad(authText, AUTH_PAD);
|
||||||
|
const tagsLabel =
|
||||||
|
row.tags.length > 0
|
||||||
|
? rich
|
||||||
|
? row.tags.map((tag) => formatTag(tag, rich)).join(",")
|
||||||
|
: row.tags.join(",")
|
||||||
|
: "";
|
||||||
|
|
||||||
|
const coloredInput = colorize(
|
||||||
|
rich,
|
||||||
|
row.input.includes("image") ? chalk.magenta : chalk.white,
|
||||||
|
inputLabel,
|
||||||
);
|
);
|
||||||
const authLabel = pad(
|
const coloredLocal = colorize(
|
||||||
row.available === null ? "-" : row.available ? "yes" : "no",
|
rich,
|
||||||
AUTH_PAD,
|
row.local === null ? chalk.gray : row.local ? chalk.green : chalk.gray,
|
||||||
|
localLabel,
|
||||||
|
);
|
||||||
|
const coloredAuth = colorize(
|
||||||
|
rich,
|
||||||
|
row.available === null
|
||||||
|
? chalk.gray
|
||||||
|
: row.available
|
||||||
|
? chalk.green
|
||||||
|
: chalk.red,
|
||||||
|
authLabel,
|
||||||
);
|
);
|
||||||
const tagsLabel = row.tags.length > 0 ? row.tags.join(",") : "";
|
|
||||||
|
|
||||||
const line = [
|
const line = [
|
||||||
rich ? chalk.cyan(keyLabel) : keyLabel,
|
rich ? chalk.cyan(keyLabel) : keyLabel,
|
||||||
inputLabel,
|
coloredInput,
|
||||||
ctxLabel,
|
ctxLabel,
|
||||||
localLabel,
|
coloredLocal,
|
||||||
authLabel,
|
coloredAuth,
|
||||||
rich ? chalk.gray(tagsLabel) : tagsLabel,
|
tagsLabel,
|
||||||
].join(" ");
|
].join(" ");
|
||||||
runtime.log(line);
|
runtime.log(line);
|
||||||
}
|
}
|
||||||
@@ -701,47 +740,116 @@ export async function modelsStatusCommand(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.log(info(`Config: ${CONFIG_PATH_CLAWDBOT}`));
|
const rich = isRich(opts);
|
||||||
runtime.log(info(`Agent dir: ${shortenHomePath(agentDir)}`));
|
const label = (value: string) => colorize(rich, chalk.cyan, value.padEnd(14));
|
||||||
runtime.log(`Default: ${defaultLabel}`);
|
|
||||||
runtime.log(
|
runtime.log(
|
||||||
`Fallbacks (${fallbacks.length || 0}): ${fallbacks.join(", ") || "-"}`,
|
`${label("Config")}${colorize(rich, chalk.gray, ":")} ${colorize(rich, chalk.white, CONFIG_PATH_CLAWDBOT)}`,
|
||||||
);
|
|
||||||
runtime.log(`Image model: ${imageModel || "-"}`);
|
|
||||||
runtime.log(
|
|
||||||
`Image fallbacks (${imageFallbacks.length || 0}): ${
|
|
||||||
imageFallbacks.length ? imageFallbacks.join(", ") : "-"
|
|
||||||
}`,
|
|
||||||
);
|
);
|
||||||
runtime.log(
|
runtime.log(
|
||||||
`Aliases (${Object.keys(aliases).length || 0}): ${
|
`${label("Agent dir")}${colorize(rich, chalk.gray, ":")} ${colorize(
|
||||||
|
rich,
|
||||||
|
chalk.white,
|
||||||
|
shortenHomePath(agentDir),
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
|
runtime.log(
|
||||||
|
`${label("Default")}${colorize(rich, chalk.gray, ":")} ${colorize(
|
||||||
|
rich,
|
||||||
|
chalk.green,
|
||||||
|
defaultLabel,
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
|
runtime.log(
|
||||||
|
`${label(`Fallbacks (${fallbacks.length || 0})`)}${colorize(
|
||||||
|
rich,
|
||||||
|
chalk.gray,
|
||||||
|
":",
|
||||||
|
)} ${colorize(
|
||||||
|
rich,
|
||||||
|
fallbacks.length ? chalk.yellow : chalk.gray,
|
||||||
|
fallbacks.length ? fallbacks.join(", ") : "-",
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
|
runtime.log(
|
||||||
|
`${label("Image model")}${colorize(rich, chalk.gray, ":")} ${colorize(
|
||||||
|
rich,
|
||||||
|
imageModel ? chalk.magenta : chalk.gray,
|
||||||
|
imageModel || "-",
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
|
runtime.log(
|
||||||
|
`${label(`Image fallbacks (${imageFallbacks.length || 0})`)}${colorize(
|
||||||
|
rich,
|
||||||
|
chalk.gray,
|
||||||
|
":",
|
||||||
|
)} ${colorize(
|
||||||
|
rich,
|
||||||
|
imageFallbacks.length ? chalk.magentaBright : chalk.gray,
|
||||||
|
imageFallbacks.length ? imageFallbacks.join(", ") : "-",
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
|
runtime.log(
|
||||||
|
`${label(`Aliases (${Object.keys(aliases).length || 0})`)}${colorize(
|
||||||
|
rich,
|
||||||
|
chalk.gray,
|
||||||
|
":",
|
||||||
|
)} ${colorize(
|
||||||
|
rich,
|
||||||
|
Object.keys(aliases).length ? chalk.cyan : chalk.gray,
|
||||||
Object.keys(aliases).length
|
Object.keys(aliases).length
|
||||||
? Object.entries(aliases)
|
? Object.entries(aliases)
|
||||||
.map(([alias, target]) => `${alias} -> ${target}`)
|
.map(([alias, target]) =>
|
||||||
|
rich
|
||||||
|
? `${chalk.blue(alias)} ${chalk.gray("->")} ${chalk.white(
|
||||||
|
target,
|
||||||
|
)}`
|
||||||
|
: `${alias} -> ${target}`,
|
||||||
|
)
|
||||||
.join(", ")
|
.join(", ")
|
||||||
: "-"
|
: "-",
|
||||||
}`,
|
)}`,
|
||||||
);
|
);
|
||||||
runtime.log(
|
runtime.log(
|
||||||
`Configured models (${allowed.length || 0}): ${
|
`${label(`Configured models (${allowed.length || 0})`)}${colorize(
|
||||||
allowed.length ? allowed.join(", ") : "all"
|
rich,
|
||||||
}`,
|
chalk.gray,
|
||||||
|
":",
|
||||||
|
)} ${colorize(
|
||||||
|
rich,
|
||||||
|
allowed.length ? chalk.white : chalk.gray,
|
||||||
|
allowed.length ? allowed.join(", ") : "all",
|
||||||
|
)}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
runtime.log("");
|
runtime.log("");
|
||||||
runtime.log(info("Auth overview"));
|
runtime.log(colorize(rich, chalk.bold, "Auth overview"));
|
||||||
runtime.log(
|
runtime.log(
|
||||||
`Auth store: ${shortenHomePath(resolveAuthStorePathForDisplay())}`,
|
`${label("Auth store")}${colorize(rich, chalk.gray, ":")} ${colorize(
|
||||||
|
rich,
|
||||||
|
chalk.white,
|
||||||
|
shortenHomePath(resolveAuthStorePathForDisplay()),
|
||||||
|
)}`,
|
||||||
);
|
);
|
||||||
runtime.log(
|
runtime.log(
|
||||||
`Shell env fallback: ${shellFallbackEnabled ? "on" : "off"}${
|
`${label("Shell env")}${colorize(rich, chalk.gray, ":")} ${colorize(
|
||||||
applied.length ? ` (applied: ${applied.join(", ")})` : ""
|
rich,
|
||||||
|
shellFallbackEnabled ? chalk.green : chalk.gray,
|
||||||
|
shellFallbackEnabled ? "on" : "off",
|
||||||
|
)}${
|
||||||
|
applied.length
|
||||||
|
? colorize(rich, chalk.gray, ` (applied: ${applied.join(", ")})`)
|
||||||
|
: ""
|
||||||
}`,
|
}`,
|
||||||
);
|
);
|
||||||
runtime.log(
|
runtime.log(
|
||||||
`Providers with OAuth (${providersWithOauth.length || 0}): ${
|
`${label(
|
||||||
providersWithOauth.length ? providersWithOauth.join(", ") : "-"
|
`Providers w/ OAuth (${providersWithOauth.length || 0})`,
|
||||||
}`,
|
)}${colorize(rich, chalk.gray, ":")} ${colorize(
|
||||||
|
rich,
|
||||||
|
providersWithOauth.length ? chalk.white : chalk.gray,
|
||||||
|
providersWithOauth.length ? providersWithOauth.join(", ") : "-",
|
||||||
|
)}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const entry of providerAuth) {
|
for (const entry of providerAuth) {
|
||||||
|
|||||||
Reference in New Issue
Block a user