Skip to content

Commit 20c4e94

Browse files
committed
docs: document cli startup helpers
1 parent 98187f3 commit 20c4e94

10 files changed

Lines changed: 19 additions & 0 deletions

src/cli/run-main-policy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Main CLI startup policy helpers for fast paths, proxy startup, aliases, and missing commands.
12
import {
23
normalizeLowercaseStringOrEmpty,
34
normalizeOptionalLowercaseString,
@@ -82,6 +83,7 @@ function isBareParentDefaultHelpArgv(argv: string[]): boolean {
8283
}
8384

8485
export function rewriteUpdateFlagArgv(argv: string[]): string[] {
86+
// Preserve the old root --update spelling by rewriting before Commander registration.
8587
const index = argv.indexOf("--update");
8688
if (index === -1) {
8789
return argv;

src/cli/run-main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Main CLI entry orchestration: fast paths, env setup, plugin aliases, and Commander dispatch.
12
import { existsSync } from "node:fs";
23
import path from "node:path";
34
import process from "node:process";
@@ -79,6 +80,7 @@ const loadCrestodianModule = async () => await import("../crestodian/crestodian.
7980
const loadProgressModule = async () => await import("./progress.js");
8081

8182
function createGatewayCliMainStartupTrace(argv: string[]) {
83+
// Startup trace is scoped to gateway invocations to avoid routine CLI stderr noise.
8284
const enabled =
8385
isTruthyEnvValue(process.env.OPENCLAW_GATEWAY_STARTUP_TRACE) &&
8486
argv.slice(2).includes("gateway");

src/cli/sandbox-cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Commander registration for sandbox container list, recreate, and explain commands.
12
import type { Command } from "commander";
23
import { formatDocsLink } from "../../packages/terminal-core/src/links.js";
34
import { theme } from "../../packages/terminal-core/src/theme.js";
@@ -44,6 +45,7 @@ const SANDBOX_EXAMPLES = {
4445
function createRunner(
4546
commandFn: (opts: CommandOptions, runtime: typeof defaultRuntime) => Promise<void>,
4647
) {
48+
// Sandbox commands share the default runtime error/exit behavior.
4749
return async (opts: CommandOptions) => {
4850
try {
4951
await commandFn(opts, defaultRuntime);

src/cli/secrets-cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Secrets CLI for reload, audit, configure, and apply workflows.
12
import type { Command } from "commander";
23
import { formatDocsLink } from "../../packages/terminal-core/src/links.js";
34
import { theme } from "../../packages/terminal-core/src/theme.js";
@@ -46,6 +47,7 @@ const secretsApplyLoader = createLazyImportLoader<SecretsApplyModule>(
4647
);
4748

4849
async function readPlanFile(pathname: string): Promise<SecretsApplyPlan> {
50+
// Apply consumes a generated plan shape, not arbitrary JSON.
4951
const [{ readFileSync }, { isSecretsApplyPlan }] = await Promise.all([
5052
fsModuleLoader.load(),
5153
import("../secrets/plan.js"),

src/cli/security-cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Security CLI for local/deep audits and safe remediation.
12
import {
23
normalizeOptionalLowercaseString,
34
normalizeOptionalString,
@@ -43,6 +44,7 @@ function buildAuditGatewayAuthOverride(params: {
4344
token?: string;
4445
password?: string;
4546
}) {
47+
// Explicit runtime auth overrides must include the matching credential.
4648
if (!params.mode) {
4749
return undefined;
4850
}

src/cli/setup-onboard-configure-help-fast-path.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Fast help renderer for setup/onboard/configure without loading full CLI startup.
12
import { Command } from "commander";
23
import { VERSION } from "../version.js";
34
import { resolveCliArgvInvocation } from "./argv-invocation.js";
@@ -66,6 +67,7 @@ async function registerHelpCommand(
6667
}
6768

6869
export async function tryOutputSetupOnboardConfigureHelp(argv: string[]): Promise<boolean> {
70+
// Register only the requested command so help stays quick and avoids config/plugin startup.
6971
const command = resolveSetupOnboardConfigureHelpCommand(argv);
7072
if (!command) {
7173
return false;

src/cli/skills-cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Skills CLI for workspace status, install/update, ClawHub verification, and workshop proposals.
12
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
23
import type { Command } from "commander";
34
import { formatDocsLink } from "../../packages/terminal-core/src/links.js";
@@ -72,6 +73,7 @@ function resolveSkillsWorkspace(options?: ResolveSkillsWorkspaceOptions): {
7273
workspaceDir: string;
7374
agentId: string;
7475
} {
76+
// Prefer explicit --agent, then infer from cwd, then fall back to configured default agent.
7577
const config = getRuntimeConfig();
7678
const explicitAgentId = normalizeOptionalString(options?.agentId);
7779
const inferredAgentId = explicitAgentId

src/cli/startup-metadata.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Reader/cache for generated CLI startup metadata used by help and completion fast paths.
12
import fs from "node:fs";
23
import path from "node:path";
34
import { fileURLToPath } from "node:url";
@@ -14,6 +15,7 @@ function resolveStartupMetadataPathCandidates(moduleUrl: string): string[] {
1415
}
1516

1617
export function readCliStartupMetadata(moduleUrl: string): Record<string, unknown> | null {
18+
// Check both source and bundled layouts; cache misses too so repeated help stays cheap.
1719
for (const metadataPath of resolveStartupMetadataPathCandidates(moduleUrl)) {
1820
const cached = startupMetadataByPath.get(metadataPath);
1921
if (cached !== undefined) {

src/cli/tagline.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// CLI tagline selection helpers, including deterministic random/default/holiday modes.
12
import { parseStrictNonNegativeInteger } from "../infra/parse-finite-number.js";
23

34
const DEFAULT_TAGLINE = "All your chats, one OpenClaw.";

src/cli/test-runtime-capture.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Shared Vitest runtime capture helpers for CLI command output assertions.
12
import { vi } from "vitest";
23
import type { OutputRuntimeEnv } from "../runtime.js";
34
import type { MockFn } from "../test-utils/vitest-mock-fn.js";
@@ -32,6 +33,7 @@ function stringifyRuntimeJson(value: unknown, space = 2): string {
3233
}
3334

3435
export function createCliRuntimeCapture(): CliRuntimeCapture {
36+
// Capture output in arrays while preserving vi mock call inspection.
3537
const runtimeLogs: string[] = [];
3638
const runtimeErrors: string[] = [];
3739
const stringifyArgs = (args: unknown[]) => args.map((value) => String(value)).join(" ");

0 commit comments

Comments
 (0)