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: trueadds the--confirm <hash>line to the per-command help.hidden: truekeeps the command out ofCOMMANDS, the help and the snippet.plugin initis hidden.helpOptionsadds extra lines underCommon options:in the per-command help. Thehelpadapter uses it for-a, --alland-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 incommandHelp().- The
helpentry is a regular row. Its syntax ishelp [-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 inUSAGE. - Syntax is padded to 22 columns. Longer syntax moves the description to the next line, indented to the description column.
test/snippet.test.mjscompares 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 getororg list) is matched first; otherwise the first word is used. hook,discover,helpandplugin initarerunEarlyadapters.run()hands them the raw arguments before the shared parser, so their own argument handling applies.helpusescommandUsageinside itsrunEarly.- An unknown command with
--helpexits 2. The messageUnknown 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:
- Create
src/cli/<name>.mjswith aCliCommandexport. Give itname,args,summaryand anagentTipin": "form (see agents-snippet.md). SettargetOrg: falseif it takes no org,json: falseif it has no JSON output, andconfirm: trueif policy approval applies. Setdocsif it needs ansfd helpmanual. - Add a
request(daemon-backed) or arun/runEarly(local) handler. SetdefaultWaitMinutesfor a longer client timeout. Sethealth: trueonly for lifecycle commands that check daemon health. - Register it in
cliCommandsinsrc/cli/index.mjs. Registry order is help order. - Add its name to
helpOrderintest/cli-registry.test.mjs. That test hard-codes the order and fails until the list matches. - Declare each parser option in the adapter’s
options. Reuse the definitions insrc/cli/shared-options.mjswhere one exists (sharedOptions). Each option must deep-equal the mergedSHARED_OPTIONSentry of the same name, whichtest/cli-registry.test.mjschecks. - A new lifecycle command also needs its summary in
commandHelp()updated. The row name follows the registry automatically. - Update the README command table and the “Using sfd with coding agents” section.
- Run
npm testbefore 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.