diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts index 02c77021a6a..a81aacd9d8e 100644 --- a/packages/opencode/src/index.ts +++ b/packages/opencode/src/index.ts @@ -54,7 +54,7 @@ import { Auth } from "./auth" import { DbCommand } from "./cli/cmd/db" import path from "path" import { Global } from "./global" -import { HelpCommand } from "./kilocode/help-command" // kilocode_change +import { createHelpCommand } from "./kilocode/help-command" // kilocode_change import { JsonMigration } from "./storage/json-migration" import { Database } from "./storage/db" @@ -197,9 +197,12 @@ let cli = yargs(hideBin(process.argv)) .command(SessionCommand) .command(RemoteCommand) // kilocode_change .command(DbCommand) - .command(HelpCommand) // kilocode_change .command(ConfigCLICommand) // kilocode_change +// kilocode_change start - registered after initial chain to avoid self-referential type error +cli = cli.command(createHelpCommand(() => cli)) +// kilocode_change end + if (Installation.isLocal()) { cli = cli.command(WorkspaceServeCommand) } diff --git a/packages/opencode/src/kilocode/help-command.ts b/packages/opencode/src/kilocode/help-command.ts index c33caa54039..ecb5f90f14d 100644 --- a/packages/opencode/src/kilocode/help-command.ts +++ b/packages/opencode/src/kilocode/help-command.ts @@ -1,37 +1,45 @@ import { cmd } from "../cli/cmd/cmd" import { generateHelp } from "./help" +import type { Argv } from "yargs" -export const HelpCommand = cmd({ - command: "help [command]", - describe: "show full CLI reference", - builder: (yargs) => - yargs - .positional("command", { - describe: "command to show help for", - type: "string", +export function createHelpCommand(root?: () => Argv) { + return cmd({ + command: "help [command]", + describe: "show full CLI reference", + builder: (yargs) => + yargs + .positional("command", { + describe: "command to show help for", + type: "string", + }) + .option("all", { + describe: "show help for all commands", + type: "boolean", + default: false, + }) + .option("format", { + describe: "output format", + type: "string", + choices: ["md", "text"] as const, + default: "md" as const, + }), + async handler(args) { + if (!args.command && !args.all) { + if (root) { + const help = await root().getHelp() + process.stdout.write(help + "\n") + } + return + } + const output = await generateHelp({ + command: args.command, + all: args.all, + format: args.format as "md" | "text", }) - .option("all", { - describe: "show help for all commands", - type: "boolean", - default: false, - }) - .option("format", { - describe: "output format", - type: "string", - choices: ["md", "text"] as const, - default: "md" as const, - }), - async handler(args) { - if (!args.command && !args.all) { - process.stdout.write("Usage: kilo help --all Show full CLI reference\n") - process.stdout.write(" kilo help Show help for a specific command\n") - return - } - const output = await generateHelp({ - command: args.command, - all: args.all, - format: args.format as "md" | "text", - }) - process.stdout.write(output + "\n") - }, -}) + process.stdout.write(output + "\n") + }, + }) +} + +// Static instance for introspection by commands.ts / help.ts (handler not invoked) +export const HelpCommand = createHelpCommand()