docs: document cli startup helpers · openclaw/openclaw@20c4e94
steipete
·
2026-06-04
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Main CLI startup policy helpers for fast paths, proxy startup, aliases, and missing commands. |
1 | 2 | import { |
2 | 3 | normalizeLowercaseStringOrEmpty, |
3 | 4 | normalizeOptionalLowercaseString, |
@@ -82,6 +83,7 @@ function isBareParentDefaultHelpArgv(argv: string[]): boolean {
|
82 | 83 | } |
83 | 84 | |
84 | 85 | export function rewriteUpdateFlagArgv(argv: string[]): string[] { |
| 86 | +// Preserve the old root --update spelling by rewriting before Commander registration. |
85 | 87 | const index = argv.indexOf("--update"); |
86 | 88 | if (index === -1) { |
87 | 89 | return argv; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Main CLI entry orchestration: fast paths, env setup, plugin aliases, and Commander dispatch. |
1 | 2 | import { existsSync } from "node:fs"; |
2 | 3 | import path from "node:path"; |
3 | 4 | import process from "node:process"; |
@@ -79,6 +80,7 @@ const loadCrestodianModule = async () => await import("../crestodian/crestodian.
|
79 | 80 | const loadProgressModule = async () => await import("./progress.js"); |
80 | 81 | |
81 | 82 | function createGatewayCliMainStartupTrace(argv: string[]) { |
| 83 | +// Startup trace is scoped to gateway invocations to avoid routine CLI stderr noise. |
82 | 84 | const enabled = |
83 | 85 | isTruthyEnvValue(process.env.OPENCLAW_GATEWAY_STARTUP_TRACE) && |
84 | 86 | argv.slice(2).includes("gateway"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Commander registration for sandbox container list, recreate, and explain commands. |
1 | 2 | import type { Command } from "commander"; |
2 | 3 | import { formatDocsLink } from "../../packages/terminal-core/src/links.js"; |
3 | 4 | import { theme } from "../../packages/terminal-core/src/theme.js"; |
@@ -44,6 +45,7 @@ const SANDBOX_EXAMPLES = {
|
44 | 45 | function createRunner( |
45 | 46 | commandFn: (opts: CommandOptions, runtime: typeof defaultRuntime) => Promise<void>, |
46 | 47 | ) { |
| 48 | +// Sandbox commands share the default runtime error/exit behavior. |
47 | 49 | return async (opts: CommandOptions) => { |
48 | 50 | try { |
49 | 51 | await commandFn(opts, defaultRuntime); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Secrets CLI for reload, audit, configure, and apply workflows. |
1 | 2 | import type { Command } from "commander"; |
2 | 3 | import { formatDocsLink } from "../../packages/terminal-core/src/links.js"; |
3 | 4 | import { theme } from "../../packages/terminal-core/src/theme.js"; |
@@ -46,6 +47,7 @@ const secretsApplyLoader = createLazyImportLoader<SecretsApplyModule>(
|
46 | 47 | ); |
47 | 48 | |
48 | 49 | async function readPlanFile(pathname: string): Promise<SecretsApplyPlan> { |
| 50 | +// Apply consumes a generated plan shape, not arbitrary JSON. |
49 | 51 | const [{ readFileSync }, { isSecretsApplyPlan }] = await Promise.all([ |
50 | 52 | fsModuleLoader.load(), |
51 | 53 | import("../secrets/plan.js"), |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Security CLI for local/deep audits and safe remediation. |
1 | 2 | import { |
2 | 3 | normalizeOptionalLowercaseString, |
3 | 4 | normalizeOptionalString, |
@@ -43,6 +44,7 @@ function buildAuditGatewayAuthOverride(params: {
|
43 | 44 | token?: string; |
44 | 45 | password?: string; |
45 | 46 | }) { |
| 47 | +// Explicit runtime auth overrides must include the matching credential. |
46 | 48 | if (!params.mode) { |
47 | 49 | return undefined; |
48 | 50 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Fast help renderer for setup/onboard/configure without loading full CLI startup. |
1 | 2 | import { Command } from "commander"; |
2 | 3 | import { VERSION } from "../version.js"; |
3 | 4 | import { resolveCliArgvInvocation } from "./argv-invocation.js"; |
@@ -66,6 +67,7 @@ async function registerHelpCommand(
|
66 | 67 | } |
67 | 68 | |
68 | 69 | export async function tryOutputSetupOnboardConfigureHelp(argv: string[]): Promise<boolean> { |
| 70 | +// Register only the requested command so help stays quick and avoids config/plugin startup. |
69 | 71 | const command = resolveSetupOnboardConfigureHelpCommand(argv); |
70 | 72 | if (!command) { |
71 | 73 | return false; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Skills CLI for workspace status, install/update, ClawHub verification, and workshop proposals. |
1 | 2 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
2 | 3 | import type { Command } from "commander"; |
3 | 4 | import { formatDocsLink } from "../../packages/terminal-core/src/links.js"; |
@@ -72,6 +73,7 @@ function resolveSkillsWorkspace(options?: ResolveSkillsWorkspaceOptions): {
|
72 | 73 | workspaceDir: string; |
73 | 74 | agentId: string; |
74 | 75 | } { |
| 76 | +// Prefer explicit --agent, then infer from cwd, then fall back to configured default agent. |
75 | 77 | const config = getRuntimeConfig(); |
76 | 78 | const explicitAgentId = normalizeOptionalString(options?.agentId); |
77 | 79 | const inferredAgentId = explicitAgentId |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Reader/cache for generated CLI startup metadata used by help and completion fast paths. |
1 | 2 | import fs from "node:fs"; |
2 | 3 | import path from "node:path"; |
3 | 4 | import { fileURLToPath } from "node:url"; |
@@ -14,6 +15,7 @@ function resolveStartupMetadataPathCandidates(moduleUrl: string): string[] {
|
14 | 15 | } |
15 | 16 | |
16 | 17 | export function readCliStartupMetadata(moduleUrl: string): Record<string, unknown> | null { |
| 18 | +// Check both source and bundled layouts; cache misses too so repeated help stays cheap. |
17 | 19 | for (const metadataPath of resolveStartupMetadataPathCandidates(moduleUrl)) { |
18 | 20 | const cached = startupMetadataByPath.get(metadataPath); |
19 | 21 | if (cached !== undefined) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// CLI tagline selection helpers, including deterministic random/default/holiday modes. |
1 | 2 | import { parseStrictNonNegativeInteger } from "../infra/parse-finite-number.js"; |
2 | 3 | |
3 | 4 | const DEFAULT_TAGLINE = "All your chats, one OpenClaw."; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Shared Vitest runtime capture helpers for CLI command output assertions. |
1 | 2 | import { vi } from "vitest"; |
2 | 3 | import type { OutputRuntimeEnv } from "../runtime.js"; |
3 | 4 | import type { MockFn } from "../test-utils/vitest-mock-fn.js"; |
@@ -32,6 +33,7 @@ function stringifyRuntimeJson(value: unknown, space = 2): string {
|
32 | 33 | } |
33 | 34 | |
34 | 35 | export function createCliRuntimeCapture(): CliRuntimeCapture { |
| 36 | +// Capture output in arrays while preserving vi mock call inspection. |
35 | 37 | const runtimeLogs: string[] = []; |
36 | 38 | const runtimeErrors: string[] = []; |
37 | 39 | const stringifyArgs = (args: unknown[]) => args.map((value) => String(value)).join(" "); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。