Skip to content

CLI help and version

sfd --help, sfd <command> --help and sfd --version are generated from the command registry (src/cli/index.mjs) through src/commands.mjs. None of them contacts or starts the daemon. sfd help (command manuals and concept guides) is a separate feature, documented in help-topics.md.

Source: src/cli/index.mjs (the registry order, matchBuiltin), the adapters in src/cli/<name>.mjs (their types are in src/cli/types.d.ts), src/commands.mjs (COMMANDS, SHARED_OPTIONS, commandHelp(), commandUsage()), the USAGE string and the --help/--version checks in bin/sfd.mjs, and src/version.mjs. Tests: test/cli.test.mjs (per-command help, --version), test/snippet.test.mjs (the top-level list) and test/cli-registry.test.mjs (registry order and options).

Registry fields

Each built-in command is one CliCommand adapter. src/commands.mjs turns the non-hidden adapters into COMMANDS, which carries these fields:

Field Used by Notes
name help, snippet Subcommand words. May contain spaces (logs get, org list).
args help, snippet fallback Usage placeholder, such as <soql>. Empty is allowed. discover uses DISCOVER_ARGS from src/cli/constants.mjs.
summary help, snippet fallback Help text. Newlines are allowed: they become continuation lines in help and spaces in the snippet.
flags derived The keys of the adapter’s options. Only names listed here are accepted by the command, in addition to the common flags.
agentTip snippet Optional. Format <usage>: <description>. See agents-snippet.md.
agentGroup snippet Optional. Consecutive entries with the same group share one bullet, joined by ; .
targetOrg per-command help Optional. false omits the -o, --target-org line from sfd <name> --help. Set it on commands that take no org (org list, agents-snippet, start, stop, status, reload). Absent means the line is shown.
json per-command help Optional. false omits the common --json line. Use it for commands without JSON output or commands that list the flag in args, such as discover.
docs sfd help <command> Optional. Guide files that make up the command’s manual. See help-topics.md.

Adapter-only fields that help does not show directly:

  • confirm: true adds the --confirm <hash> line to the per-command help.
  • hidden: true keeps the command out of COMMANDS, the help and the snippet. plugin init is hidden.
  • helpOptions adds extra lines under Common options: in the per-command help. The help adapter uses it for -a, --all and -g, --guides.

The four lifecycle commands (start, stop, status, reload) each have their own adapter, so each has specific help. They share agentGroup: "lifecycle", so the agent snippet joins them into one bullet.

Top-level help

sfd --help prints the USAGE string in bin/sfd.mjs with commandHelp() inserted under Commands:.

  • commandHelp() lists every non-lifecycle entry in registry order, then appends one row for the lifecycle group. The row’s name (start | stop | status | reload) is built from the lifecycle entries. Its summary is hard-coded in commandHelp().
  • The help entry is a regular row. Its syntax is help [-a | -g] [<command|guide>].
  • Below the list, the top-level help ends with Run 'sfd help <command|guide>' for full documentation. and then the exit codes (including 4 for approval required or policy denied). The common-options block and the exit-code footer are literal text in USAGE.
  • Syntax is padded to 22 columns. Longer syntax moves the description to the next line, indented to the description column.
  • test/snippet.test.mjs compares the top-level list against a snapshot. Update the snapshot when the text changes on purpose.

Per-command help

sfd <command> --help prints commandUsage(name) from src/commands.mjs:

Usage: sfd <name> <args> [options]
<summary, line breaks kept>
Common options:
-o, --target-org <alias> Select the target org
--json Print the raw JSON response
-h, --help Show this help
Run 'sfd help <command|guide>' for full documentation.

The -o line is omitted when the entry sets targetOrg: false, and the --json line is omitted when it sets json: false. The --confirm <hash> line appears when it sets confirm: true. The --help line is shown for every entry. Any helpOptions lines follow the common options. The footer line is appended to every usage block.

Command resolution is in src/cli/index.mjs (matchBuiltin):

  • A two-word name (such as logs get or org list) is matched first; otherwise the first word is used.
  • hook, discover, help and plugin init are runEarly adapters. run() hands them the raw arguments before the shared parser, so their own argument handling applies. help uses commandUsage inside its runEarly.
  • An unknown command with --help exits 2. The message Unknown command: <name>. Run sfd --help. goes to stderr, and stdout is empty. It does not fall back to the top-level help.

Version

sfd --version and sfd <command> --version both print sfd <VERSION> and exit 0. The check runs first in run() in bin/sfd.mjs, before any dispatch, so it wins over commands, --sf-json, and the runEarly adapters.

VERSION is read from package.json in src/version.mjs. The same module exports PROTOCOL (the version plus the newest source mtime). PROTOCOL is the daemon handshake value, not the printed version.

Keeping it in sync

To add a command:

  1. Create src/cli/<name>.mjs with a CliCommand export. Give it name, args, summary and an agentTip in ": " form (see agents-snippet.md). Set targetOrg: false if it takes no org, json: false if it has no JSON output, and confirm: true if policy approval applies. Set docs if it needs an sfd help manual.
  2. Add a request (daemon-backed) or a run/runEarly (local) handler. Set defaultWaitMinutes for a longer client timeout. Set health: true only for lifecycle commands that check daemon health.
  3. Register it in cliCommands in src/cli/index.mjs. Registry order is help order.
  4. Add its name to helpOrder in test/cli-registry.test.mjs. That test hard-codes the order and fails until the list matches.
  5. Declare each parser option in the adapter’s options. Reuse the definitions in src/cli/shared-options.mjs where one exists (sharedOptions). Each option must deep-equal the merged SHARED_OPTIONS entry of the same name, which test/cli-registry.test.mjs checks.
  6. A new lifecycle command also needs its summary in commandHelp() updated. The row name follows the registry automatically.
  7. Update the README command table and the “Using sfd with coding agents” section.
  8. Run npm test before committing.

If the command calls a new daemon operation, also add its descriptor in src/ops/<name>.mjs with JSDoc parameter types and an *Args interface in src/types.d.ts, because npm run typecheck checks src/ under noImplicitAny.

Write command help includes --confirm <hash> for commands with confirm: true; the confirmation and policy flow is described in Safety policy.