Skip to content

perf(cli): Skip loading every command for --version, leading global flags, and top-level help - #1826

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
perf/cli-version-skip-routes
Open

sentry-junior[bot] wants to merge 2 commits into
mainfrom
perf/cli-version-skip-routes

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #1814. That PR made a run load only the top-level route it names. But it still loaded every command when the first token was a flag, or when the run printed the top-level help, which lists every command. This PR covers those cases.

Commit 1: --version and leading global flags. selectApp() now reads the tokens before the route name the same way the route scanner does. It skips global flags and their values, so sentry --verbose issue list loads only issue. A bare sentry --version loads only help, since Stricli prints the version before it runs any command.

Commit 2: top-level help. sentry, sentry help, and sentry --help now print a copy rendered at build time. script/generate-root-help.ts writes src/generated/root-help.json as part of generate:docs. The file is gitignored and listed in ensure-generated.mjs. It holds:

  • the command summaries that the branded help lists (name, brief, subcommands, placeholder)
  • Stricli's root --help text, plain and with colors

For these runs, the CLI loads only the help route and registers the copy through setRootHelp(). The Stricli patch now passes ansiColor to the renderHelp hook, so plain --help can pick the plain or colored copy. The graphics banner registration moved to src/graphics-banner.ts, so both paths register it.

These still load the full application:

  • JSON help (--json, --fields, SENTRY_OUTPUT_FORMAT=json)
  • help <command>
  • --help before a route name, and any flag the scanner doesn't accept there
  • unknown names (they need every route for suggestions)
  • schema and cli

Verification

  • test/lib/app-for-args.test.ts:
    • checks root-help.json against the full tree with buildRootHelp(app, routes), so stale generated data fails the test
    • checks that printCustomHelp (overview and full) and --help (plain and colored) print the same text with only help loaded as with the full app
    • covers how selectApp picks routes for each argument case
  • Compared the npm bundle output against main for 46 argument cases with piped and TTY output: no args, help, -h/--help, help --help, --helpAll, JSON help, --version combinations, global flags, help issue, issue --help, and an unknown route. Output and exit codes matched for every case. They also matched under NO_COLOR, STRICLI_NO_COLOR, FORCE_AGENT_MODE, SENTRY_OUTPUT_FORMAT=json, narrow and wide terminals, and with an auth token set.
  • tsc, pnpm run lint, and ci:policy (including check:patches) pass. The CLI unit suite has 13,091 passing tests. 6 fail in this sandbox; all of them are chmod/EACCES permission tests (completions, db readonly, code-scanner, file-changes, upgrade lock), unrelated to this change.

Startup time (npm bundle, median of 15 runs, noisy sandbox)

command main this PR
sentry 466 ms 375 ms
sentry help 484 ms 376 ms
sentry --help 465 ms 370 ms
sentry --version 461 ms 374 ms
sentry --verbose --version 461 ms 363 ms
sentry issue list --help 372 ms 372 ms (unchanged, as expected)

main here already includes the @sentry/api bump from #1820. The generated help text adds about 20 KB to index.cjs.

via @BYK.

--

View Session in Sentry

sentry-junior Bot and others added 2 commits November 3, 2026 00:02
routesForArgs fell back to the full application whenever the first token
was a flag, so `sentry --version` and `sentry --verbose issue list`
loaded every command. Read the leading tokens like the route scanner
does: skip global flags (and their values), and for a bare `--version`
load only the help route, since Stricli prints the version before it
runs any command. Other leading flags, like `--help`, still get the
full application.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
`sentry`, `sentry help`, and `sentry --help` list every top-level
command, so they loaded app.ts and with it every command module.

Render that help from the full route tree at build time instead
(`script/generate-root-help.ts` writes `src/generated/root-help.json`
as part of `generate:docs`): the command summaries the branded help
lists, and Stricli's `--help` text with and without colors. For the
text top-level help, `selectApp()` loads only the `help` route and
registers the precomputed copy with `setRootHelp()`. The Stricli
patch now passes `ansiColor` to the `renderHelp` hook so plain
`--help` can pick the matching copy.

JSON help (`--json`, `--fields`, SENTRY_OUTPUT_FORMAT=json), `help
<command>`, and `--help` before a route name still load the full
application. A test checks the generated file against the full tree,
and that both paths print the same text.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentry-local Ready Ready Preview Nov 3, 2026 12:05am UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 3adf5551 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant