Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/commands/sandbox/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/commands/sandbox/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/commands/sandbox/agents/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/commands/sandbox/agents/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/commands/sandbox/agents/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/commands/sandbox/agents/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/commands/sandbox/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/commands/sandbox/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/commands/sandbox/sessions/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/commands/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down
6 changes: 6 additions & 0 deletions src/lib/cli/argv-normalizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/cli/argv-normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -15,6 +16,7 @@ export type NormalizedSandboxArgv = {
export type NormalizedArgv =
| NormalizedRootHelpArgv
| NormalizedDumpCommandsArgv
| NormalizedDumpCommandFlagsArgv
| NormalizedGlobalArgv
| NormalizedSandboxArgv;

Expand All @@ -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 };
}
Expand Down
23 changes: 23 additions & 0 deletions src/lib/cli/command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/lib/cli/generate-oclif-metadata-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function main(): Promise<void> {
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);
Expand Down
9 changes: 8 additions & 1 deletion src/lib/cli/oclif-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const GENERATED_METADATA_FILE = "oclif-command-metadata.generated.json";
export type OclifCommandMetadata = {
args?: Record<string, unknown>;
baseFlags?: Record<string, unknown>;
/** Whether the command renders public help outside oclif flag metadata. */
customHelp?: boolean;
description?: string;
deprecationOptions?: unknown;
examples?: string[];
Expand Down Expand Up @@ -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*;`),
);
Expand All @@ -104,9 +109,11 @@ function loadSourceOclifMetadata(commandRoot: string): Record<string, OclifComma
const commandId = commandIdFromSourceFile(relativeFile);
const commandMetadata: OclifCommandMetadata = { id: commandId };
const summary = staticSummary(source);
const customHelp = staticBoolean(source, "customHelp");
const hidden = staticBoolean(source, "hidden");
const strict = staticBoolean(source, "strict");
if (summary !== undefined) commandMetadata.summary = summary;
if (customHelp !== undefined) commandMetadata.customHelp = customHelp;
if (hidden !== undefined) commandMetadata.hidden = hidden;
if (strict !== undefined) commandMetadata.strict = strict;
if (metadata[commandId]) throw new Error(`Duplicate source oclif command ID: ${commandId}`);
Expand Down
8 changes: 8 additions & 0 deletions src/lib/cli/public-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const { CLI_NAME } = require("./branding");
const { help } = require("../actions/root-help");
const { runOclifArgv, runOclifCommandById } = require("./oclif-runner");
const {
canonicalCommandFlagLines,
canonicalUsageList,
globalCommandTokens,
sandboxActionTokensForDispatch,
Expand Down Expand Up @@ -362,6 +363,11 @@ async function dispatchNormalizedArgv(normalized: NormalizedArgv, argv: string[]
return;
}

if (normalized.kind === "dumpCommandFlags") {
canonicalCommandFlagLines().forEach((line: string) => console.log(line));
return;
}

if (normalized.kind === "global") {
await dispatchGlobalArgv(normalized);
return;
Expand Down Expand Up @@ -482,6 +488,8 @@ export async function dispatchCli(argv: string[] = process.argv.slice(2)): Promi
argv.includes("--help") ||
argv.includes("-h") ||
argv.includes("--version") ||
argv[0] === "--dump-commands" ||
argv[0] === "--dump-command-flags" ||
argv[0] === "version" ||
argv[0] === "help" ||
argv[0] === "completion";
Expand Down
Loading
Loading