Skip to content

feat(cli): add the wizard's shared AST and URL helpers - #2520

Merged
BYK merged 7 commits into
feat/cli-wizard-scaffoldfrom
feat/cli-wizard-shared-ast-helpers
Nov 27, 2026
Merged

BYK merged 7 commits into
feat/cli-wizard-scaffoldfrom
feat/cli-wizard-shared-ast-helpers

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2519. Tracking issue: #2511.

Nine of the remaining sentry-wizard flows (SvelteKit, Remix, React Router, Angular, Nuxt, source maps, Cloudflare, React Native, Android) use the same two helpers. Landing them here, once, lets those platform PRs stack on this one in parallel without each one re-adding the same files.

  • src/lib/wizard/utils/ast-utils.ts: finds and edits nodes in recast ASTs and reads and writes JSON-C. It's ported from sentry-wizard with strict types (unknown in place of any), and invalid JSON-C now goes to the wizard's debug log instead of being dropped.
  • src/lib/wizard/utils/url.ts: builds the issue stream URL the wizards print once setup finishes.
  • Its tests are ported to test/lib/wizard/utils/ast-utils.test.ts.

recast and ast-types become direct dev dependencies. Both already came in through magicast, so nothing new is bundled. They stay until the wizard's config edits move to the shared init/wizard flow in #2510.

via @BYK.

--

View Session [Sentry]

Port `ast-utils` and `url` from getsentry/sentry-wizard into
`src/lib/wizard/utils/`. The SvelteKit, Remix, React Router, Angular,
Nuxt, source maps, Cloudflare, React Native and Android wizards all use
them, so they land once here and the platform PRs that follow build on
them in parallel.

`ast-utils` edits recast ASTs, so recast and ast-types become direct
dev dependencies; both already came in through magicast.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@sentry-junior
sentry-junior Bot added this pull request to stack #2521 November 26, 2026 11:52
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
cli Ready Ready Preview Nov 26, 2026 10:42pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 26, 2026 10:42pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📊 MCP Server Token Cost Report

Summary

  • Total Tokens: 67760 tokens
  • Tool Count: 76 tools
  • Average: 892 tokens/tool

Per-Tool Breakdown

Tool Tokens % of Total
get_issue_details 3967 5.9%
get_alert_rule 2245 3.3%
find_releases 1805 2.7%
get_issue_activity 1759 2.6%
update_alert_rule 1653 2.4%
get_replay_details 1602 2.4%
create_alert_rule 1506 2.2%
get_monitor_details 1501 2.2%
update_metric_monitor 1479 2.2%
create_metric_monitor 1458 2.2%
get_event_stacktrace 1381 2%
update_issue 1380 2%
render_sentry_chart 1362 2%
get_snapshot 1308 1.9%
get_profile 1291 1.9%
get_agent_conversation_details 1278 1.9%
find_monitors 1261 1.9%
search_logs 1248 1.8%
search_traces 1246 1.8%
get_alert_options 1236 1.8%
search_profiles 1228 1.8%
search_metrics 1216 1.8%
search_errors 1214 1.8%
get_profile_details 1200 1.8%
find_related_issues 1171 1.7%
get_uptime_monitor_details 1163 1.7%
create_monitor 1135 1.7%
onboarding_status_update 1109 1.6%
search_issue_events 1103 1.6%
search_replays 1095 1.6%
render_issue_chart 1061 1.6%
get_release_details 1056 1.6%
get_dashboard_details 1052 1.6%
search_issues 977 1.4%
search_docs 973 1.4%
find_alert_rules 908 1.3%
update_uptime_monitor 873 1.3%
create_uptime_monitor 871 1.3%
search_agent_conversations 830 1.2%
find_dropped_events 819 1.2%
get_metric_monitor_details 797 1.2%
create_project 793 1.2%
update_dsn 765 1.1%
get_issue_user_reports 630 0.9%
get_latest_base_snapshot 623 0.9%
find_dashboards 553 0.8%
link_issue 545 0.8%
find_uptime_monitors 537 0.8%
get_issue_breadcrumbs 492 0.7%
unlink_issue 476 0.7%
find_metric_monitors 471 0.7%
get_issue_tag_values 469 0.7%
update_project 441 0.7%
get_sentry_resource 429 0.6%
submit_feedback_to_sentry_team 426 0.6%
add_issue_note 404 0.6%
delete_monitor_environment 363 0.5%
find_teams 351 0.5%
find_projects 346 0.5%
delete_alert_rule 345 0.5%
delete_uptime_monitor 333 0.5%
delete_metric_monitor 331 0.5%
create_dsn 326 0.5%
add_team_to_project 324 0.5%
remove_team_from_project 320 0.5%
find_dsns 319 0.5%
find_organizations 311 0.5%
get_snapshot_image 302 0.4%
analyze_issue_with_seer 300 0.4%
get_event_attachment 299 0.4%
get_trace_details 282 0.4%
create_team 266 0.4%
get_span_details 263 0.4%
whoami 261 0.4%
get_sentry_mcp_info 142 0.2%
get_doc 102 0.2%

Note: This measures the static overhead of tool definitions sent to LLM clients with every request. Lower is better.

MCP Apps views

Each ui:// view as a host receives it from resources/read.

View MIME type Raw Gzip Brotli Budget % of budget
ui://sentry/chart/v6.html text/html;profile=mcp-app 19,249 B 7,913 B 7,014 B 24,576 B 78.3%

The budget applies to raw bytes, and the view's generator fails over it.

…st-helpers

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

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
*/
export function getLastRequireIndex(program: t.Program): number {
let lastRequireIdex = -1;
program.body.forEach((s, i) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using for .. of, isn't this enforced by a lint rule already?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No lint rule was enforcing it. 2c987511 enables unicorn/no-array-for-each repo-wide in .oxlintrc.json and converts all 34 .forEach sites to for…of, getLastRequireIndex included. The other 33 are in cli, mcp-core, mcp-cloudflare, apps/local and apps/games-api. A return inside a callback became continue.

* Checks if a file where we don't know its concrete file type yet exists
* and returns the full path to the file with the correct file type.
*/
export function findFile(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have this functionality already in the CLI under DSN discovery code or something like that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DSN code has no extension-probing helper, but lib/dsn/fs-utils.ts has isRegularFile. 2c987511 moves findFile there and builds it on isRegularFile, so a directory or FIFO with a matching name is skipped. It's async now, and it has tests. The platform PRs will update their call sites when they next pick up this base.

*
* Example: https://org-slug.sentry.io/issues/?project=1234567
*/
export function getIssueStreamUrl({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should already have a URL builder somewhere in the codebase?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was one. 2c987511 adds buildProjectIssuesUrl(orgSlug, projectId) to lib/sentry-urls.ts, built on getOrgBaseUrl like buildEventSearchUrl, with SaaS and self-hosted tests. It also deletes wizard/utils/url.ts.

Address review feedback on the shared wizard helpers:

- Enable unicorn/no-array-for-each repo-wide and convert every
  .forEach call site to for...of, including getLastRequireIndex.
- Add buildProjectIssuesUrl to lib/sentry-urls.ts, built on
  getOrgBaseUrl like buildEventSearchUrl, and delete the
  wizard-specific wizard/utils/url.ts.
- Move findFile into lib/dsn/fs-utils.ts and build it on
  isRegularFile, so a directory or FIFO with a matching name is
  skipped. It is async now.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@BYK
BYK marked this pull request as ready for review November 26, 2026 19:07
@BYK
BYK requested a review from a team as a code owner November 26, 2026 19:07
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 26, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2c98751. Configure here.

Comment thread packages/cli/src/lib/sentry-urls.ts Resolved
Re-export buildProjectIssuesUrl from lib/sentry-web-urls.ts through
withSentryBaseUrl(getApiBaseUrl()), like the other user-facing link
builders, so self-hosted and regional logins get links on the host they
are authenticated against.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
sentry-junior Bot and others added 2 commits November 26, 2026 22:40
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…eat/cli-wizard-shared-ast-helpers

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel
vercel Bot temporarily deployed to Preview – sentry-local November 26, 2026 22:42 Inactive
sentry-junior Bot added a commit that referenced this pull request Nov 27, 2026
…izard base

Merges origin/feat/cli-wizard-shared-ast-helpers at f0a48de (#2520, the
chart-app fix and #2519's positional rework) and fixes what it breaks:

- `runWizard` no longer takes `debug`, so the redirect to another wizard
  drops it.
- `wizard/utils/url.ts` is gone. The source maps outro links to the
  project's issues with `buildProjectIssuesUrl` from `lib/sentry-web-urls`.
- `findFile` now comes from `lib/dsn/fs-utils` and is async, so the tsc,
  Vite and webpack tools await it.
- The new `no-array-for-each` lint rule: two `forEach` loops become
  `for...of`.
- The wizard docs fragment keeps the base's flag table and the source maps
  paragraph from this branch.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@BYK
BYK merged commit 504d4f9 into main Nov 27, 2026
48 checks passed
@BYK
BYK deleted the feat/cli-wizard-shared-ast-helpers branch November 27, 2026 14:04
BYK added a commit that referenced this pull request Nov 27, 2026
Before v4.0.0, the setup wizards of getsentry/sentry-wizard move into
the CLI as `sentry wizard`, so there is one tool, one login and one
telemetry client, and the wizards call v4 `sentry` commands instead of
sentry-cli v2. Tracking issue: #2511 (part of
#1965). This is the first PR in that stack: the
command, its login, and the Next.js flow.

## Changes

- **`sentry wizard [<org>/<project>] [<integration>]`**: the target
comes first, like other commands, and both are optional. The integration
takes the `@sentry/wizard -i` ids, one at a time; without it the picker
runs. The target uses the CLI's org/project syntax and resolves after
login like other commands' targets; without it the org and project
pickers run, with no detection. A bare integration id is never read as a
target and a single bare word is always read as an integration, so a
project spelled like one is written `my-org/nextjs`. `-f/--force` is the
only flag: it changes a project with uncommitted changes without asking
and force-installs the SDK. Everything else comes from the CLI: the
instance from `SENTRY_URL` or the stored login, Spotlight mode from
`SENTRY_SPOTLIGHT`, telemetry from the CLI's settings, and debug output
from `--verbose`/`--log-level`. No other `@sentry/wizard` flag or
`SENTRY_WIZARD_*` variable is accepted, hidden or not; a test pins the
flags and `ci:policy` rejects `SENTRY_WIZARD_` under `packages/cli/src`.
- **Sign-up flags are removed.** `-s/--signup`, `--promo-code` and
`--coming-from` fail as unknown flags, because the CLI's login has no
sign-up or partner step. `promoCode`/`comingFrom` are gone from the
wizard options, the welcome banner and the CI step.
- **The Next.js flow** is ported as-is in `src/lib/wizard/nextjs/`, with
its tests. Each flow loads lazily. The picker lists only ported flows,
and naming an unported integration says it isn't available in this
version yet. Cordova and Electron are dropped along with sentry-wizard's
`lib/`.
- **Shared helpers** are in `src/lib/wizard/utils/`. A small pnpm
catalog reader replaces js-yaml.
- **Login uses the CLI's own login** instead of the
`account/settings/wizard/<hash>` browser flow: the stored `sentry auth
login` session, an agent handoff from `SENTRY_HANDOFF`, or the device
flow with `org:ci` and `org:tokens`. The wizard then picks the org,
picks or creates the project for the flow's platform, reads its DSN, and
creates an org auth token for source map uploads. If it can't create a
token, for example when there's no TTY to add scopes, it writes the
placeholder token and says so.
- **No `sentry-cli` binary needed.** The wizard runs inside the CLI, so
it never installs or checks for `sentry-cli`; the old `get-cli` +
`sentry-cli --version` check isn't ported.
- **Telemetry** goes through the CLI's Sentry client and follows the
CLI's telemetry settings (`SENTRY_CLI_NO_TELEMETRY`, `DO_NOT_TRACK`,
`sentry cli defaults`).
- `sentry init` still prints the agent setup guide. Its help points to
`sentry wizard`, and the wizard's help points back to `init`. Merging
the two is #2510, after v4.

This adds one dependency: `magicast@0.2.11`, which brings recast. They
stay until the config edits move to the shared flow in
#2510.

**Breaking for `@sentry/wizard` users:** the command line changes to
`sentry wizard [<org>/<project>] [<integration>]` with only
`-f/--force`. Every other `@sentry/wizard` flag, including `--signup`,
`--promo-code` and `--coming-from`, now fails as an unknown flag,
`SENTRY_WIZARD_*` variables are ignored, and the Cordova and Electron
wizards are gone.

## Rest of the stack

1. This PR: scaffold, auth, Next.js
2. #2520: shared AST and URL helpers
3. JS frameworks: SvelteKit, Remix, React Router, Nuxt, Angular
4. Source maps and Cloudflare, with sentry-cli v2 calls moved to v4
`sentry` commands
5. Mobile: iOS and Apple Snapshots, React Native, Android, Flutter
6. Wizard e2e tests in toolkit CI

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A23ba814e02fcece5f64e00f096d03341 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A23ba814e02fcece5f64e00f096d03341)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A23ba814e02fcece5f64e00f096d03341/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
sentry-junior Bot added a commit that referenced this pull request Nov 27, 2026
#2519 and #2520 were squash-merged into main, so this
branch's base is now main. The add/add conflicts came from the squashed
wizard files. main's copies of run.ts and test/commands/wizard.test.ts
equal f0a48de, which this branch already merged, so this branch's
Android and Flutter additions are kept. project-data.ts and its test take
main's copy, which has the #2559 fix for the origin trust check.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
sentry-junior Bot added a commit that referenced this pull request Nov 27, 2026
#2519 and #2520 were squash-merged, so this PR's base
is now main. Resolved the add/add conflicts: run.ts keeps this branch's
runner registrations (main's copy equals the old base), and
project-data.ts and its test take main's copy, with the #2559
context-scoped origin trust fix (this branch didn't change them).

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

This branch was successfully deployed

2 active and 1 inactive deployments
Preview – cli — f0a48dee Deployed Nov 26, 2026 by vercel[bot]
Actions — f0a48dee Deployed Nov 26, 2026 by sentry-junior[bot] via eval #2089
Preview – sentry-local — f0a48dee Deployed Nov 26, 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