CLI: streamline startup paths and env parsing

Add shared parseBooleanValue()/isTruthyEnvValue() and apply across CLI, gateway, memory, and live-test flags for consistent env handling.
Introduce route-first fast paths, lazy subcommand registration, and deferred plugin loading to reduce CLI startup overhead.
Centralize config validation via ensureConfigReady() and add config caching/deferred shell env fallback for fewer IO passes.
Harden logger initialization/imports and add focused tests for argv, boolean parsing, frontmatter, and CLI subcommands.
This commit is contained in:
Gustavo Madeira Santana
2026-01-18 15:56:24 -05:00
committed by Peter Steinberger
parent 97531f174f
commit acb523de86
58 changed files with 1274 additions and 500 deletions

62
src/cli/argv.test.ts Normal file
View File

@@ -0,0 +1,62 @@
import { describe, expect, it } from "vitest";
import {
buildParseArgv,
getCommandPath,
getPrimaryCommand,
hasHelpOrVersion,
} from "./argv.js";
describe("argv helpers", () => {
it("detects help/version flags", () => {
expect(hasHelpOrVersion(["node", "clawdbot", "--help"])).toBe(true);
expect(hasHelpOrVersion(["node", "clawdbot", "-V"])).toBe(true);
expect(hasHelpOrVersion(["node", "clawdbot", "status"])).toBe(false);
});
it("extracts command path ignoring flags and terminator", () => {
expect(getCommandPath(["node", "clawdbot", "status", "--json"], 2)).toEqual([
"status",
]);
expect(getCommandPath(["node", "clawdbot", "agents", "list"], 2)).toEqual([
"agents",
"list",
]);
expect(getCommandPath(["node", "clawdbot", "status", "--", "ignored"], 2)).toEqual([
"status",
]);
});
it("returns primary command", () => {
expect(getPrimaryCommand(["node", "clawdbot", "agents", "list"])).toBe("agents");
expect(getPrimaryCommand(["node", "clawdbot"])).toBeNull();
});
it("builds parse argv from raw args", () => {
const nodeArgv = buildParseArgv({
programName: "clawdbot",
rawArgs: ["node", "clawdbot", "status"],
});
expect(nodeArgv).toEqual(["node", "clawdbot", "status"]);
const directArgv = buildParseArgv({
programName: "clawdbot",
rawArgs: ["clawdbot", "status"],
});
expect(directArgv).toEqual(["node", "clawdbot", "status"]);
const bunArgv = buildParseArgv({
programName: "clawdbot",
rawArgs: ["bun", "src/entry.ts", "status"],
});
expect(bunArgv).toEqual(["bun", "src/entry.ts", "status"]);
});
it("builds parse argv from fallback args", () => {
const fallbackArgv = buildParseArgv({
programName: "clawdbot",
fallbackArgv: ["status"],
});
expect(fallbackArgv).toEqual(["node", "clawdbot", "status"]);
});
});