Skip to content

refactor(cli-core)!: define every command natively with effect/cli - #661

Draft
wyattjoh wants to merge 13 commits into
wyattjoh/effect-rewrite-testsfrom
wyattjoh/effect-rewrite-cli
Draft

wyattjoh wants to merge 13 commits into
wyattjoh/effect-rewrite-testsfrom
wyattjoh/effect-rewrite-cli

Conversation

@wyattjoh

@wyattjoh wyattjoh commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #660.

Summary

Commander and @clack/prompts are gone. Every command is an effect/cli Command, and effect/cli parses the command line, renders help and prompts, and generates the completion scripts. Effect moves to 4.1.7 for the flag and terminal APIs this needs.

A few shims remain where effect/cli has no equivalent that agent mode, scripts or telemetry can rely on: the --version fast path, exit 1 for a bare group, the usage_error envelope (which keeps the CLI's own value-parser messages unwrapped, and reads --mode off the line when parsing fails), --input-json expansion, the scan of the command line that tells telemetry which flags were set, two patches to the help formatter, and the completion script header.

 packages/cli-core/src/
 ├── cli.ts                  # answers --version before Effect loads
 ├── cli-program.ts          # root command + runProgram
 ├── commands/<name>/index.ts
-│                           # Commander program.command(...)
+│                           # Command.make / Flag / Argument / Command.withSubcommands
 ├── commands/completion/
-│   ├── __complete.ts       # runtime completion engine
-│   └── shells/*.ts
+│   └── completion.ts       # prints Completions.generate for the command tree
 ├── lib/
+│   ├── command.ts          # global flags + action wrapper (telemetry, --mode, banner, update notice)
+│   ├── prompt-render.ts    # prompts on effect/cli's Prompt
+│   └── terminal.ts
 └── startup/
-    ├── prompts.ts          # @clack/prompts
-    └── listage.ts
+    └── frame.ts
 packages/extras/src/index.ts
-  registerExtras(program: Command)
+  extras: readonly Extra[]   # plain data, no parser dependency

Commits: effect 4.1.7 bump → native commands → tests and surface snapshots → docs and rules → changeset → follow-up fixes from review.

Evidence

  • Before: clerk whoami --bogus printed Commander's plain-text error and exited 1; help used Usage: / Options: / Commands:.
    After:
    $ clerk whoami --bogus          # exit 2
    {"error":{"code":"usage_error","message":"Unrecognized flag: --bogus in command clerk whoami\nRun `clerk whoami --help` for usage."}}
    
    $ clerk config pull --output --help   # exit 0, help wins where a value was expected
    DESCRIPTION
      Pull instance configuration from Clerk
    USAGE
      clerk config pull [flags]
    FLAGS
      ...
    
  • The surface snapshots under packages/cli-core/src/test/surface/__snapshots__/ record every command's help, the command tree and every shell's completion script, so any later surface change is a reviewable diff.
  • format, lint, typecheck, unit tests, check:patches, build and the e2e listing all pass locally.

Merge Danger

Door: two-way

Reverting restores Commander; nothing persistent (config, credentials, telemetry schema) changes shape. Users who regenerated completion scripts would need to regenerate them again after a revert.

Blast Radius: wide

Every command's parsing and help change, and this ships as a major release. Scripts and agents that depend on exit codes, flag spellings or help text can break:

  • A malformed command line (unknown flag or subcommand, missing value, value outside the allowed choices) now exits 2 with a usage error, printed as the usage_error JSON envelope in agent mode, instead of exiting 1 with plain text. The error messages are worded differently.
  • Help has a new layout: DESCRIPTION, USAGE, FLAGS, GLOBAL FLAGS, SUBCOMMANDS and EXAMPLES sections replace Usage:, Options: and Commands:. Flags are listed in declaration order, and a switch that defaults on is shown as --x with its --no-x form implied.
  • clerk help <command> and the help subcommand of command groups (clerk migrate help) are gone: use clerk <command> --help.
  • -h or --help anywhere before -- prints help for the most specific command named, even after --version or where a flag's value was expected. clerk -hv prints help.
  • Shell completion is a static script generated from the command tree. Regenerate it (clerk completion <shell>) after upgrading. The hidden clerk __complete command is gone, and values that came from the CLI at completion time (mcp install --client, migrate --source and similar hints) are no longer completed. clerk completion with no shell is a usage error.
  • A command has at most one alias: clerk auth login keeps signin (signup and sign-in are gone) and clerk auth logout keeps signout (sign-out is gone).
  • --keys (clerk config pull, clerk config schema), --for (clerk enable billing, clerk disable billing) and --android-fingerprint (clerk init, clerk doctor) take one value per flag: repeat the flag or separate values with commas. --keys a b no longer works.
  • Any other flag given twice is a usage error; the last value no longer wins. This includes --help and -h (clerk --help --help) and --version written with a value (--version=true --version=true); a bare clerk --version --version still prints the version (with any other word on the line, such as --mode agent, it is a usage error).
  • --help and --version answer whatever form they are written in: --no-help, --help=false, --no-version and --version=false print help or the version and exit 0, instead of failing as unknown options.
  • clerk open help no longer prints help: help is read as a dashboard subpath. Use clerk open --help.
  • A clerk feedback --outcome outside the allowed values (an empty or space-padded one included) is rejected while parsing: the usage error is worded differently, carries no examples, and sends no usage telemetry event.
  • A short flag's value is its own word: -X POST, not -XPOST. A value that starts with - must be attached with = (--attempted=-v printed nothing); as the next word it is read as a flag, except a negative number (--limit -5). An --input-json value always reaches its flag, whatever it looks like.
  • A group's flags go after the group name and before or after the subcommand (clerk users --app app_1 list and clerk users list --app app_1 both work), but a flag a subcommand does not take is a usage error. The duplicate copies of a parent's flag on its children are gone: clerk impersonate revoke --open is now a usage error.
  • clerk deploy run is gone: run clerk deploy, which usage telemetry still records as deploy run. clerk deploy status --domain reports an unknown flag.
  • --=<value> (a flag with no name) is read as an argument: a usage error where the command takes none, and the endpoint where one is expected (clerk api --=users).
  • clerk mcp run no longer passes its flags through: it still prints the removed-command error, but a flag after it is now a usage error.
  • An invalid --mode value is a usage error raised before the command starts, so it sends no usage telemetry event.
  • An explicit flag next to --input-json replaces the JSON key of the same name instead of being appended after it.
  • Prompts look and respond differently: confirm takes y or n, multi-select adds select-all and invert rows, and an invalid answer is corrected in place.
  • Pressing Ctrl-C while a spinner is running now exits 130 instead of 0, so scripts see the interruption.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@wyattjoh wyattjoh changed the title Stacks on the vitest PR, which is itself stacked on https://github.com/clerk/cli/pull/656. refactor(cli-core)!: move the CLI from commander and clack to effect/cli Dec 1, 2026
@changeset-bot

changeset-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cccd999

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
clerk Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@wyattjoh
wyattjoh added this pull request to stack #663 December 1, 2026 08:38
@wyattjoh
wyattjoh force-pushed the wyattjoh/effect-rewrite-cli branch from de52f1d to 33a8de6 Compare December 1, 2026 09:43
@wyattjoh wyattjoh changed the title refactor(cli-core)!: move the CLI from commander and clack to effect/cli refactor(cli-core)!: define every command natively with effect/cli Dec 1, 2026
@wyattjoh
wyattjoh removed this pull request from stack #663 December 1, 2026 11:04
@wyattjoh
wyattjoh added this pull request to stack #666 December 1, 2026 11:04
@wyattjoh
wyattjoh force-pushed the wyattjoh/effect-rewrite-cli branch from c7f7b89 to e01bbf4 Compare December 1, 2026 14:53
@wyattjoh
wyattjoh force-pushed the wyattjoh/effect-rewrite-cli branch from e01bbf4 to 29cd236 Compare December 1, 2026 15:36
…4.1.7

The native effect/cli commands rely on Flag.withOptionalValue and the
terminal and spawn types that arrived in effect 4.1.
Each command group is now an effect/cli Command built with Command.make,
Flag and Argument, and effect/cli parses the command line, renders help
and generates the shell completion scripts. Prompts render through
effect/cli's prompt module, so commander, @commander-js/extra-typings and
@clack/prompts are gone, along with the hidden __complete command.

lib/command.ts holds the global flags and the action wrapper that runs
the startup work (telemetry, --verbose, --mode, the environment banner and
the update notice) around every handler. cli.ts still answers --version
before Effect loads. The extras package exports plain command data so
cli-core can add it to the tree without a parser dependency.

BREAKING CHANGE: usage errors exit 2 with a usage_error envelope, help has
a new layout, completion is a static script, and several flag spellings
and aliases change; the changeset lists each one.
The surface snapshots record every command's help text, the command tree
and the generated completion scripts, so a change to a flag, alias or
description shows up as a reviewable diff. oxfmt skips the snapshot
directory so the recorded text stays byte-for-byte.

The unit and integration tests move from Commander's program to the
effect/cli root command, and the prompt tests drive the effect/cli
renderer through a shared terminal fixture.
AGENTS.md, the rules and the command READMEs now describe commands defined
with effect/cli, the action wrapper in lib/command.ts, the static
completion scripts and the new help and flag conventions.
One major changeset covers the whole move from Commander and
@clack/prompts to effect/cli, including the effect 4.1.7 upgrade.
@wyattjoh
wyattjoh force-pushed the wyattjoh/effect-rewrite-cli branch from 29cd236 to cccd999 Compare December 1, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant