chore: format models CLI

This commit is contained in:
Peter Steinberger
2026-01-04 18:11:41 +01:00
parent 8e5153ba10
commit ff46f8ce58
14 changed files with 74 additions and 71 deletions

View File

@@ -1,7 +1,4 @@
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 {
ensureFlagCompatibility,
@@ -47,7 +44,7 @@ export async function modelsAliasesAddCommand(
const alias = normalizeAlias(aliasRaw);
const updated = await updateConfig((cfg) => {
const resolved = resolveModelTarget({ raw: modelRaw, cfg });
const nextAliases = { ...(cfg.agent?.modelAliases ?? {}) };
const nextAliases = { ...cfg.agent?.modelAliases };
nextAliases[alias] = `${resolved.provider}/${resolved.model}`;
return {
...cfg,
@@ -68,7 +65,7 @@ export async function modelsAliasesRemoveCommand(
) {
const alias = normalizeAlias(aliasRaw);
const updated = await updateConfig((cfg) => {
const nextAliases = { ...(cfg.agent?.modelAliases ?? {}) };
const nextAliases = { ...cfg.agent?.modelAliases };
if (!nextAliases[alias]) {
throw new Error(`Alias not found: ${alias}`);
}
@@ -83,7 +80,10 @@ export async function modelsAliasesRemoveCommand(
});
runtime.log(`Updated ${CONFIG_PATH_CLAWDBOT}`);
if (!updated.agent?.modelAliases || Object.keys(updated.agent.modelAliases).length === 0) {
if (
!updated.agent?.modelAliases ||
Object.keys(updated.agent.modelAliases).length === 0
) {
runtime.log("No aliases configured.");
}
}

View File

@@ -1,12 +1,9 @@
import {
CONFIG_PATH_CLAWDBOT,
loadConfig,
} from "../../config/config.js";
import type { RuntimeEnv } from "../../runtime.js";
import {
buildModelAliasIndex,
resolveModelRefFromString,
} from "../../agents/model-selection.js";
import { CONFIG_PATH_CLAWDBOT, loadConfig } from "../../config/config.js";
import type { RuntimeEnv } from "../../runtime.js";
import {
DEFAULT_PROVIDER,
ensureFlagCompatibility,
@@ -60,8 +57,8 @@ export async function modelsFallbacksAddCommand(
aliasIndex,
}),
)
.filter(Boolean)
.map((entry) => modelKey(entry!.ref.provider, entry!.ref.model));
.filter((entry): entry is NonNullable<typeof entry> => Boolean(entry))
.map((entry) => modelKey(entry.ref.provider, entry.ref.model));
if (existingKeys.includes(targetKey)) return cfg;

View File

@@ -1,22 +1,22 @@
import chalk from "chalk";
import { type Api, getEnvApiKey, type Model } from "@mariozechner/pi-ai";
import {
discoverAuthStorage,
discoverModels,
} from "@mariozechner/pi-coding-agent";
import { getEnvApiKey, type Api, type Model } from "@mariozechner/pi-ai";
import chalk from "chalk";
import { resolveClawdbotAgentDir } from "../../agents/agent-paths.js";
import { ensureClawdbotModelsJson } from "../../agents/models-config.js";
import {
buildModelAliasIndex,
parseModelRef,
resolveModelRefFromString,
resolveConfiguredModelRef,
resolveModelRefFromString,
} from "../../agents/model-selection.js";
import { ensureClawdbotModelsJson } from "../../agents/models-config.js";
import {
type ClawdbotConfig,
CONFIG_PATH_CLAWDBOT,
loadConfig,
type ClawdbotConfig,
} from "../../config/config.js";
import { info } from "../../globals.js";
import type { RuntimeEnv } from "../../runtime.js";
@@ -35,7 +35,9 @@ const LOCAL_PAD = 5;
const AUTH_PAD = 5;
const isRich = (opts?: { json?: boolean; plain?: boolean }) =>
Boolean(process.stdout.isTTY && chalk.level > 0 && !opts?.json && !opts?.plain);
Boolean(
process.stdout.isTTY && chalk.level > 0 && !opts?.json && !opts?.plain,
);
const pad = (value: string, size: number) => value.padEnd(size);

View File

@@ -3,9 +3,10 @@ import { discoverAuthStorage } from "@mariozechner/pi-coding-agent";
import { resolveClawdbotAgentDir } from "../../agents/agent-paths.js";
import {
scanOpenRouterModels,
type ModelScanResult,
scanOpenRouterModels,
} from "../../agents/model-scan.js";
import { CONFIG_PATH_CLAWDBOT } from "../../config/config.js";
import { warn } from "../../globals.js";
import type { RuntimeEnv } from "../../runtime.js";
import {
@@ -14,7 +15,6 @@ import {
formatTokenK,
updateConfig,
} from "./shared.js";
import { CONFIG_PATH_CLAWDBOT } from "../../config/config.js";
const MODEL_PAD = 42;
const CTX_PAD = 8;
@@ -27,7 +27,6 @@ const truncate = (value: string, max: number) => {
return `${value.slice(0, max - 3)}...`;
};
function sortScanResults(results: ModelScanResult[]): ModelScanResult[] {
return results.slice().sort((a, b) => {
const aImage = a.image.ok ? 1 : 0;
@@ -133,16 +132,20 @@ export async function modelsScanCommand(
runtime: RuntimeEnv,
) {
const minParams = opts.minParams ? Number(opts.minParams) : undefined;
if (minParams !== undefined && (!Number.isFinite(minParams) || minParams < 0)) {
if (
minParams !== undefined &&
(!Number.isFinite(minParams) || minParams < 0)
) {
throw new Error("--min-params must be >= 0");
}
const maxAgeDays = opts.maxAgeDays ? Number(opts.maxAgeDays) : undefined;
if (maxAgeDays !== undefined && (!Number.isFinite(maxAgeDays) || maxAgeDays < 0)) {
if (
maxAgeDays !== undefined &&
(!Number.isFinite(maxAgeDays) || maxAgeDays < 0)
) {
throw new Error("--max-age-days must be >= 0");
}
const maxCandidates = opts.maxCandidates
? Number(opts.maxCandidates)
: 6;
const maxCandidates = opts.maxCandidates ? Number(opts.maxCandidates) : 6;
if (!Number.isFinite(maxCandidates) || maxCandidates <= 0) {
throw new Error("--max-candidates must be > 0");
}
@@ -151,7 +154,10 @@ export async function modelsScanCommand(
throw new Error("--timeout must be > 0");
}
const concurrency = opts.concurrency ? Number(opts.concurrency) : undefined;
if (concurrency !== undefined && (!Number.isFinite(concurrency) || concurrency <= 0)) {
if (
concurrency !== undefined &&
(!Number.isFinite(concurrency) || concurrency <= 0)
) {
throw new Error("--concurrency must be > 0");
}
@@ -226,9 +232,7 @@ export async function modelsScanCommand(
const allowlist = buildAllowlistSet(updated);
const allowlistMissing =
allowlist.size > 0
? selected.filter((entry) => !allowlist.has(entry))
: [];
allowlist.size > 0 ? selected.filter((entry) => !allowlist.has(entry)) : [];
if (opts.json) {
runtime.log(

View File

@@ -1,11 +1,13 @@
import { CONFIG_PATH_CLAWDBOT } from "../../config/config.js";
import type { RuntimeEnv } from "../../runtime.js";
import { buildAllowlistSet, modelKey, resolveModelTarget, updateConfig } from "./shared.js";
import {
buildAllowlistSet,
modelKey,
resolveModelTarget,
updateConfig,
} from "./shared.js";
export async function modelsSetCommand(
modelRaw: string,
runtime: RuntimeEnv,
) {
export async function modelsSetCommand(modelRaw: string, runtime: RuntimeEnv) {
const updated = await updateConfig((cfg) => {
const resolved = resolveModelTarget({ raw: modelRaw, cfg });
const allowlist = buildAllowlistSet(cfg);

View File

@@ -1,7 +1,4 @@
import {
DEFAULT_MODEL,
DEFAULT_PROVIDER,
} from "../../agents/defaults.js";
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../../agents/defaults.js";
import {
buildModelAliasIndex,
modelKey,
@@ -9,9 +6,9 @@ import {
resolveModelRefFromString,
} from "../../agents/model-selection.js";
import {
type ClawdbotConfig,
readConfigFileSnapshot,
writeConfigFile,
type ClawdbotConfig,
} from "../../config/config.js";
export const ensureFlagCompatibility = (opts: {