Skip to content

Command-Line Interface ​

GodeX ships as a single godex binary with a focused set of commands for bootstrapping configuration, validating settings, and running the API gateway. The CLI is the primary operational surface for operators and CI pipelines, so it prioritises clear error messages, sensible defaults, and an interactive wizard that generates a working godex.yaml in under a minute. Understanding the CLI structure is the first step to deploying and operating GodeX effectively.

At a Glance ​

AspectDetail
FrameworkCommander.js (commander package)
Entry pointrunCli() at src/cli/cli.ts:5-24
Interactive prompts@clack/prompts
Default commandserve
Config filegodex.yaml (YAML with env interpolation)

Command Overview ​

CommandPurposeSource
godex initInteractive config wizardsrc/cli/commands/init.ts
godex serveStart the API gatewaysrc/cli/commands/serve.ts
godex config checkValidate config without startingsrc/cli/commands/config.ts
godex config printPrint resolved config (secrets redacted)src/cli/commands/config.ts

CLI Execution Flow ​

runCli at src/cli/cli.ts:5-24 wraps Commander's parseAsync with error handling that distinguishes Commander exit codes (help, version) from unexpected errors. The program is constructed in createProgram at src/cli/program.ts:10-30, which sets the name, description, version, and registers all three command groups.

init Command ​

The init command at src/cli/commands/init.ts:4-12 delegates to runInit at src/cli/init/run.ts:8-22, which drives the interactive wizard.

Supported Providers ​

The wizard offers four built-in providers defined in src/cli/init/providers.ts:36-65:

ProviderLabelDefault ModelAPI Key Placeholder
deepseekDeepSeekdeepseek-v4-pro${DEEPSEEK_API_KEY}
zhipuZhipu (智谱)glm-5.2${ZHIPU_API_KEY}
minimaxMiniMaxMiniMax-M3${MINIMAX_API_KEY}
xiaomiXiaomi (小米)mimo-v2.5-pro${MIMO_API_KEY}

Prompt Sequence ​

The wizard at src/cli/init/prompts.ts:15-59 collects:

  1. Provider selection -- multi-select from built-in list (required)
  2. Provider configuration -- API key + base URL per provider
  3. Default provider -- single select (skipped if only one)
  4. Server port -- text input, default 5678
  5. Session backend -- sqlite or memory
  6. Log level -- debug, info, or warn

The resulting config is serialized via buildConfigYaml at src/cli/init/config-yaml.ts:6-53 using js-yaml and written with permissions 0600.

serve Command ​

The serve command at src/cli/serve.ts:12-62 executes the following steps:

  1. Load config via loadRuntimeConfig at src/cli/runtime-config/load.ts:17-39
  2. Validate provider registrations
  3. Create ApplicationContext
  4. Start the Bun HTTP server
  5. Print the startup banner
  6. Register SIGINT/SIGTERM shutdown handlers

Startup Banner ​

formatStartupBanner at src/cli/banner.ts:14-25 outputs:

GodeX v1.0.0

  address:   http://0.0.0.0:5678
  env:       prod
  config:    /etc/godex/godex.yaml
  providers: deepseek, zhipu
  session:   sqlite (/data/sessions.db)

Shutdown Handling ​

registerShutdownHandlers at src/cli/serve.ts:64-106 gracefully stops the server, closes the ApplicationContext, and exits with code 0. A shuttingDown guard prevents double-shutdown on rapid signal repeats.

config Command ​

The config command group at src/cli/commands/config.ts:16-47 provides two subcommands:

SubcommandDescription
godex config checkValidates config + provider registration, exits on failure
godex config printPrints fully resolved config as JSON with secrets redacted

Both accept the same --config, --port, --host, and --log-level options as serve.

Common CLI Options ​

Defined in CliOptions at src/cli/runtime-config/options.ts:3-8:

OptionApplies ToDescription
--config <path>serve, configPath to godex.yaml
--port <number>serve, configOverride server port (1-65535)
--host <address>serve, configOverride bind address
--log-level <level>serve, configOverride log level

Cross-References ​

References ​