diff --git a/src/commands/sandbox/agent.ts b/src/commands/sandbox/agent.ts index b258f488003..ffac1b5d6de 100644 --- a/src/commands/sandbox/agent.ts +++ b/src/commands/sandbox/agent.ts @@ -7,6 +7,7 @@ import { NemoClawCommand } from "../../lib/cli/nemoclaw-oclif-command"; export default class SandboxAgentCommand extends NemoClawCommand { static id = "sandbox:agent"; + static customHelp = true; static strict = false; static summary = "Run one agent turn non-interactively in a sandbox"; static description = diff --git a/src/commands/sandbox/agents.ts b/src/commands/sandbox/agents.ts index ced6311ad74..daae1d885d3 100644 --- a/src/commands/sandbox/agents.ts +++ b/src/commands/sandbox/agents.ts @@ -6,6 +6,7 @@ import { NemoClawCommand } from "../../lib/cli/nemoclaw-oclif-command"; export default class SandboxAgentsCommand extends NemoClawCommand { static id = "sandbox:agents"; + static customHelp = true; static strict = false; static summary = "Manage OpenClaw agents inside a sandbox"; static description = diff --git a/src/commands/sandbox/agents/add.ts b/src/commands/sandbox/agents/add.ts index c84a9c723f6..de331de5c40 100644 --- a/src/commands/sandbox/agents/add.ts +++ b/src/commands/sandbox/agents/add.ts @@ -10,6 +10,7 @@ import { NemoClawCommand } from "../../../lib/cli/nemoclaw-oclif-command"; export default class SandboxAgentsAddCommand extends NemoClawCommand { static id = "sandbox:agents:add"; + static customHelp = true; static strict = false; static summary = "Add an OpenClaw agent inside a sandbox"; static description = diff --git a/src/commands/sandbox/agents/apply.ts b/src/commands/sandbox/agents/apply.ts index ac7ec05efc8..0db75130f16 100644 --- a/src/commands/sandbox/agents/apply.ts +++ b/src/commands/sandbox/agents/apply.ts @@ -37,6 +37,7 @@ function printApplyHelp(): void { export default class SandboxAgentsApplyCommand extends NemoClawCommand { static id = "sandbox:agents:apply"; + static customHelp = true; static strict = false; static summary = "Reconcile a sandbox's OpenClaw agents against a declarative manifest"; static description = diff --git a/src/commands/sandbox/agents/delete.ts b/src/commands/sandbox/agents/delete.ts index d5613803c34..009a7ea186e 100644 --- a/src/commands/sandbox/agents/delete.ts +++ b/src/commands/sandbox/agents/delete.ts @@ -10,6 +10,7 @@ import { NemoClawCommand } from "../../../lib/cli/nemoclaw-oclif-command"; export default class SandboxAgentsDeleteCommand extends NemoClawCommand { static id = "sandbox:agents:delete"; + static customHelp = true; static strict = false; static summary = "Delete an OpenClaw agent inside a sandbox"; static description = diff --git a/src/commands/sandbox/agents/list.ts b/src/commands/sandbox/agents/list.ts index c5d2027cc72..d92686d1183 100644 --- a/src/commands/sandbox/agents/list.ts +++ b/src/commands/sandbox/agents/list.ts @@ -10,6 +10,7 @@ import { NemoClawCommand } from "../../../lib/cli/nemoclaw-oclif-command"; export default class SandboxAgentsListCommand extends NemoClawCommand { static id = "sandbox:agents:list"; + static customHelp = true; static strict = false; static summary = "List OpenClaw agents configured in a sandbox"; static description = diff --git a/src/commands/sandbox/mcp.ts b/src/commands/sandbox/mcp.ts index c531cae658b..12a6782d330 100644 --- a/src/commands/sandbox/mcp.ts +++ b/src/commands/sandbox/mcp.ts @@ -5,6 +5,7 @@ import { NemoClawCommand } from "../../lib/cli/nemoclaw-oclif-command"; export default class SandboxMcpCommand extends NemoClawCommand { static id = "sandbox:mcp"; + static customHelp = true; static strict = false; static summary = "Manage MCP servers for a sandbox"; static description = diff --git a/src/commands/sandbox/sessions.ts b/src/commands/sandbox/sessions.ts index a1928029ba6..49cacb183b9 100644 --- a/src/commands/sandbox/sessions.ts +++ b/src/commands/sandbox/sessions.ts @@ -10,6 +10,7 @@ import { NemoClawCommand } from "../../lib/cli/nemoclaw-oclif-command"; export default class SandboxSessionsCommand extends NemoClawCommand { static id = "sandbox:sessions"; + static customHelp = true; static strict = false; static summary = "List conversation sessions in a sandbox"; static description = diff --git a/src/commands/sandbox/sessions/list.ts b/src/commands/sandbox/sessions/list.ts index 9bcbe8b7d34..7e89c4018ec 100644 --- a/src/commands/sandbox/sessions/list.ts +++ b/src/commands/sandbox/sessions/list.ts @@ -10,6 +10,7 @@ import { NemoClawCommand } from "../../../lib/cli/nemoclaw-oclif-command"; export default class SandboxSessionsListCommand extends NemoClawCommand { static id = "sandbox:sessions:list"; + static customHelp = true; static strict = false; static summary = "List conversation sessions in a sandbox"; static description = diff --git a/src/commands/uninstall.ts b/src/commands/uninstall.ts index e7fafb0b93c..526e82fdc51 100644 --- a/src/commands/uninstall.ts +++ b/src/commands/uninstall.ts @@ -10,6 +10,7 @@ import { buildVersionedUninstallUrl, runUninstallCommand } from "../lib/uninstal export default class UninstallCliCommand extends NemoClawCommand { static id = "uninstall"; + static customHelp = true; static strict = false; static summary = "Run uninstall.sh"; static description = "Run the local uninstall.sh script; remote fallback is disabled."; diff --git a/src/lib/cli/argv-normalizer.test.ts b/src/lib/cli/argv-normalizer.test.ts index 07bc742be3d..850bda285a1 100644 --- a/src/lib/cli/argv-normalizer.test.ts +++ b/src/lib/cli/argv-normalizer.test.ts @@ -24,6 +24,12 @@ describe("normalizeArgv", () => { expect( normalizeArgv(["--dump-commands"], { globalCommands, isSandboxConnectFlag: isConnectFlag }), ).toEqual({ kind: "dumpCommands" }); + expect( + normalizeArgv(["--dump-command-flags"], { + globalCommands, + isSandboxConnectFlag: isConnectFlag, + }), + ).toEqual({ kind: "dumpCommandFlags" }); }); it("normalizes global commands", () => { diff --git a/src/lib/cli/argv-normalizer.ts b/src/lib/cli/argv-normalizer.ts index ee9e73c9116..cca96b9cedc 100644 --- a/src/lib/cli/argv-normalizer.ts +++ b/src/lib/cli/argv-normalizer.ts @@ -3,6 +3,7 @@ export type NormalizedRootHelpArgv = { kind: "rootHelp" }; export type NormalizedDumpCommandsArgv = { kind: "dumpCommands" }; +export type NormalizedDumpCommandFlagsArgv = { kind: "dumpCommandFlags" }; export type NormalizedGlobalArgv = { kind: "global"; command: string; args: string[] }; export type NormalizedSandboxArgv = { kind: "sandbox"; @@ -15,6 +16,7 @@ export type NormalizedSandboxArgv = { export type NormalizedArgv = | NormalizedRootHelpArgv | NormalizedDumpCommandsArgv + | NormalizedDumpCommandFlagsArgv | NormalizedGlobalArgv | NormalizedSandboxArgv; @@ -34,6 +36,10 @@ export function normalizeArgv(argv: readonly string[], opts: NormalizeArgvOption return { kind: "dumpCommands" }; } + if (cmd === "--dump-command-flags") { + return { kind: "dumpCommandFlags" }; + } + if (opts.globalCommands.has(cmd)) { return { kind: "global", command: cmd, args }; } diff --git a/src/lib/cli/command-registry.ts b/src/lib/cli/command-registry.ts index e400dbedf73..8f87b5f03ee 100644 --- a/src/lib/cli/command-registry.ts +++ b/src/lib/cli/command-registry.ts @@ -121,6 +121,29 @@ export function canonicalUsageList(): string[] { .sort(); } +type PublicFlagMetadata = { + allowNo?: boolean; + hidden?: boolean; +}; + +/** Sorted public long flags and their help source keyed by canonical usage. */ +export function canonicalCommandFlagLines(): string[] { + const metadata = getRegisteredOclifCommandsMetadata(); + return visibleCommands() + .map((command) => { + const flags = Object.entries(metadata[command.commandId]?.flags ?? {}) + .flatMap(([name, value]) => { + const flag = value as PublicFlagMetadata; + if (flag.hidden) return []; + return flag.allowNo ? [`--${name}`, `--no-${name}`] : [`--${name}`]; + }) + .sort(); + const helpSource = metadata[command.commandId]?.customHelp === true ? "rendered" : "metadata"; + return `${command.usage}\t${helpSource}\t${flags.join(" ")}`; + }) + .sort(); +} + /** * First token(s) after "nemoclaw" for each global command. * diff --git a/src/lib/cli/generate-oclif-metadata-manifest.ts b/src/lib/cli/generate-oclif-metadata-manifest.ts index 1ad991885c8..95418f59b8e 100644 --- a/src/lib/cli/generate-oclif-metadata-manifest.ts +++ b/src/lib/cli/generate-oclif-metadata-manifest.ts @@ -32,6 +32,7 @@ async function main(): Promise { for (const command of [...config.commands].sort((a, b) => a.id.localeCompare(b.id))) { const entry: SerializableCommandMetadata = {}; setIfDefined(entry, "args", command.args); + setIfDefined(entry, "customHelp", (command as { customHelp?: unknown }).customHelp); setIfDefined(entry, "description", command.description); setIfDefined(entry, "deprecationOptions", command.deprecationOptions); setIfDefined(entry, "examples", command.examples); diff --git a/src/lib/cli/oclif-metadata.ts b/src/lib/cli/oclif-metadata.ts index 8b2060a6627..ff7efcd5084 100644 --- a/src/lib/cli/oclif-metadata.ts +++ b/src/lib/cli/oclif-metadata.ts @@ -12,6 +12,8 @@ const GENERATED_METADATA_FILE = "oclif-command-metadata.generated.json"; export type OclifCommandMetadata = { args?: Record; baseFlags?: Record; + /** Whether the command renders public help outside oclif flag metadata. */ + customHelp?: boolean; description?: string; deprecationOptions?: unknown; examples?: string[]; @@ -83,7 +85,10 @@ function staticSummary(source: string): string | undefined { return `${brandedTemplate[1]}${CLI_DISPLAY_NAME}${brandedTemplate[2]}`; } -function staticBoolean(source: string, property: "hidden" | "strict"): boolean | undefined { +function staticBoolean( + source: string, + property: "customHelp" | "hidden" | "strict", +): boolean | undefined { const match = source.match( new RegExp(`\\bstatic\\s+(?:readonly\\s+)?${property}\\s*=\\s*(true|false)\\s*;`), ); @@ -104,9 +109,11 @@ function loadSourceOclifMetadata(commandRoot: string): Record