fix: centralize cli command registry

Co-authored-by: gumadeiras <gumadeiras@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-19 05:34:38 +00:00
parent 81d392a2d7
commit 9822a53649
5 changed files with 201 additions and 97 deletions

View File

@@ -1,23 +1,11 @@
import { defaultRuntime } from "../runtime.js";
import { setVerbose } from "../globals.js";
import { healthCommand } from "../commands/health.js";
import { statusCommand } from "../commands/status.js";
import { sessionsCommand } from "../commands/sessions.js";
import { agentsListCommand } from "../commands/agents.js";
import { ensurePluginRegistryLoaded } from "./plugin-registry.js";
import { isTruthyEnvValue } from "../infra/env.js";
import { emitCliBanner } from "./banner.js";
import { VERSION } from "../version.js";
import {
getCommandPath,
getFlagValue,
getPositiveIntFlagValue,
getVerboseFlag,
hasFlag,
hasHelpOrVersion,
} from "./argv.js";
import { getCommandPath, hasHelpOrVersion } from "./argv.js";
import { ensureConfigReady } from "./program/config-guard.js";
import { runMemoryStatus } from "./memory-cli.js";
import { findRoutedCommand } from "./program/command-registry.js";
async function prepareRoutedCommand(params: {
argv: string[];
@@ -36,65 +24,9 @@ export async function tryRouteCli(argv: string[]): Promise<boolean> {
if (hasHelpOrVersion(argv)) return false;
const path = getCommandPath(argv, 2);
const [primary, secondary] = path;
if (!primary) return false;
if (primary === "health") {
await prepareRoutedCommand({ argv, commandPath: path, loadPlugins: true });
const json = hasFlag(argv, "--json");
const verbose = getVerboseFlag(argv, { includeDebug: true });
const timeoutMs = getPositiveIntFlagValue(argv, "--timeout");
if (timeoutMs === null) return false;
setVerbose(verbose);
await healthCommand({ json, timeoutMs, verbose }, defaultRuntime);
return true;
}
if (primary === "status") {
await prepareRoutedCommand({ argv, commandPath: path, loadPlugins: true });
const json = hasFlag(argv, "--json");
const deep = hasFlag(argv, "--deep");
const all = hasFlag(argv, "--all");
const usage = hasFlag(argv, "--usage");
const verbose = getVerboseFlag(argv, { includeDebug: true });
const timeoutMs = getPositiveIntFlagValue(argv, "--timeout");
if (timeoutMs === null) return false;
setVerbose(verbose);
await statusCommand({ json, deep, all, usage, timeoutMs, verbose }, defaultRuntime);
return true;
}
if (primary === "sessions") {
await prepareRoutedCommand({ argv, commandPath: path });
const json = hasFlag(argv, "--json");
const verbose = getVerboseFlag(argv);
const store = getFlagValue(argv, "--store");
if (store === null) return false;
const active = getFlagValue(argv, "--active");
if (active === null) return false;
setVerbose(verbose);
await sessionsCommand({ json, store, active }, defaultRuntime);
return true;
}
if (primary === "agents" && secondary === "list") {
await prepareRoutedCommand({ argv, commandPath: path });
const json = hasFlag(argv, "--json");
const bindings = hasFlag(argv, "--bindings");
await agentsListCommand({ json, bindings }, defaultRuntime);
return true;
}
if (primary === "memory" && secondary === "status") {
await prepareRoutedCommand({ argv, commandPath: path });
const agent = getFlagValue(argv, "--agent");
if (agent === null) return false;
const json = hasFlag(argv, "--json");
const deep = hasFlag(argv, "--deep");
const index = hasFlag(argv, "--index");
const verbose = hasFlag(argv, "--verbose");
await runMemoryStatus({ agent, json, deep, index, verbose });
return true;
}
return false;
if (!path[0]) return false;
const route = findRoutedCommand(path);
if (!route) return false;
await prepareRoutedCommand({ argv, commandPath: path, loadPlugins: route.loadPlugins });
return route.run(argv);
}