Skip to content

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

Closed
wyattjoh wants to merge 6 commits into
wyattjoh/effect-upgrade-4-1-7from
wyattjoh/effect-cli-native
Closed

wyattjoh wants to merge 6 commits into
wyattjoh/effect-upgrade-4-1-7from
wyattjoh/effect-cli-native

Conversation

@wyattjoh

@wyattjoh wyattjoh commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Stacked on #662 (base 7c8ccda).

Summary

Commands are now plain effect/cli values, and effect/cli owns parsing, help and completion. The Commander-shaped layer between them is gone.

 packages/cli-core/src/
 ├── cli.ts                   # Effect-free --version fast path, else runProgram
 ├── cli-program.ts           # Command.make("clerk") + runWith, usage_error envelope
 ├── lib/
+│   ├── command.ts           # global flags, flag helpers, action(path, run)
-│   └── command-parser.ts
 ├── startup/
-│   ├── command-spec.ts
-│   ├── help-format.ts
-│   └── argv.ts
 ├── commands/<group>/index.ts  # Command.make / Flag / Argument / withSubcommands
 ├── commands/completion/
-│   ├── __complete.ts
-│   └── shells/*.ts          # replaced by Completions.generate
 └── test/surface/            # Commander fixture + argv corpus → tree, help and completion snapshots
const list = Command.make(
  "list",
  { json: switchFlag("json", "Output as JSON") },
  action("apps list", async (input) => (await import("./list.ts")).list(input)),
).pipe(Command.withDescription("List your Clerk applications"));

action keeps the startup contract: telemetry, --verbose, --mode, the environment banner and the update notice. Shims remain only where agent mode or scripts depend on them: --input-json expansion, --mode on usage errors, the usage_error envelope with exit 2, a bare group exiting 1, and the Effect-free --version.

Evidence

  • Before: 315 test files, 9234 tests. Parsing is pinned by a Commander surface fixture and an argv corpus.
    After: 308 test files, 8952 tests, all passing. Parsing is pinned by a snapshot of the command tree, a help snapshot per command, a completion script per shell, and a parse-error table:
clerk --mode agent users list --limit 5 --limit 6
  → exit 2 {"error":{"code":"usage_error","message":"Invalid value for flag --limit: \"2 occurrences\". Expected: at most 1 value\nRun `clerk users list --help` for usage."}}
clerk --mode agent deploy run
  → exit 2 {"error":{"code":"usage_error","message":"Unknown subcommand \"run\" for \"clerk deploy\"\nRun `clerk deploy --help` for usage."}}
  • format:check, lint, typecheck, test, the e2e list, check:patches and build all exit 0. The full E2E suite has not run yet on this branch.
  • build(deps): upgrade Effect to 4.1.7 #662's parser fixes were rechecked against the native parser. Its cases are now surface tests: each still holds, or is a usage error listed below.
  • Startup (compiled binary, median of 10, on a heavily loaded host): --version is the same or faster, since it never loads Effect; --help is slower, since it loads Effect and the command tree; a parsed command is about the same.

Merge Danger

Door: two-way

Reverting restores the old parser. Users who regenerated their shell completion would need to regenerate it again.

Blast Radius: CLI-wide

Every command line goes through the new parser. Breaking changes:

  • Help uses effect/cli's layout (DESCRIPTION / USAGE / FLAGS / GLOBAL FLAGS / SUBCOMMANDS / EXAMPLES), in declaration order. clerk help <command> is gone: use --help.
  • Completion is a static script. Regenerate it after upgrading. __complete and values computed at completion time (mcp install --client, migrate --source) are gone, and clerk completion needs a shell.
  • One alias per command: auth login keeps signin (signup and sign-in are gone), and auth logout keeps signout (sign-out is gone).
  • A non-repeatable flag given twice is a usage error. The last value no longer wins. This includes --help --help, -h -h and --version=true --version=true; a bare clerk --version --version still prints the version.
  • --=<value> is read as an argument: a usage error where none is taken, the endpoint in clerk api --=users.
  • A short flag's value is its own word (-X POST, not -XPOST), and a value starting with - needs --flag=-x.
  • A group's flags are shared by its subcommands, and a flag a subcommand doesn't take is a usage error. impersonate revoke --open is rejected, deploy status --domain reports an unknown flag, and deploy --domain x status ignores the flag.
  • deploy run is gone: run clerk deploy, which usage telemetry still records as deploy run.
  • mcp run no longer passes flags through, so a flag after it is a usage error.
  • A switch that defaults on is listed as --x and also accepts that positive form (--skills, --with-identities).
  • An invalid --mode value is a parse error raised before any command starts, so it sends no usage telemetry event.
  • An explicit flag next to --input-json replaces the JSON key of the same name.

Commands, groups and flags are now effect/cli Command, Flag and Argument
values, and handlers are lazily imported Effect programs. Help and shell
completion come from effect/cli (HelpDoc and Completions), replacing the
command spec, the hand-written parser, the help formatter, the argv shims
and the runtime __complete engine. cli.ts keeps an Effect-free --version
fast path; everything else loads the command tree.
Record the command tree, every listed command's help, each shell's
completion script and the parse-error envelopes, and keep oxfmt off the
recorded files.
…eploy as deploy run

A boolean flag took a following true/false/yes/no word as its value, so
--json true ran the command; every boolean flag now goes through
booleanFlag (Flag.withOptionalValue), as the spec parser did, and help
still lists it as a plain switch. Bare clerk deploy is recorded as
deploy run again in usage telemetry and feedback, the path the
warehouse's deploy contract reads. The surface tests cover the parse
cases the old argv shims handled.
@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 added this pull request to stack #663 December 1, 2026 09:34
@wyattjoh

wyattjoh commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Folded into #661, which now moves the CLI from Commander to native effect/cli in one PR, including the effect 4.1.7 upgrade. Closing this layer.

@wyattjoh wyattjoh closed this Dec 1, 2026
@wyattjoh
wyattjoh removed this pull request from stack #663 December 1, 2026 11:04
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