Commit ae5a386
feat(init): add init command for guided Sentry project setup (#283)
## Summary
Adds `sentry init` — an AI-powered wizard that walks users through
adding Sentry to their project. It detects the platform, installs the
SDK, instruments the code, and configures error monitoring, tracing, and
session replay.
## Changes
### Core wizard
- New `init` command backed by a Mastra AI workflow (hosted at
[getsentry/cli-init-api](https://github.com/getsentry/cli-init-api/))
that handles platform detection, SDK installation, and code
instrumentation
- ASCII banner, AI transparency note, and review reminder in the wizard
UX
- Tracing: unique trace IDs per wizard run with flattened span hierarchy
- Python platforms use venv for isolated dependency installation
- Magic values extracted into named constants (`constants.ts`)
- Docs page added to cli.sentry.dev
### Security hardening
- Shell metacharacter blocklist: `()` subshell bypass, `>` `<` `&`
redirection/background, `$` `'` `"` `\` expansion/escaping, `{` `}` `*`
`?` glob/brace expansion, `#` shell comment
- Environment variable injection blocking (`VAR=value cmd` pattern)
- Remote-supplied `cwd` validation against project directory
- Dangerous executable blocklist and path-traversal prevention
- File descriptor cleanup on `readSync` failure
- Cross-platform shell execution (`{ shell: true }` instead of hardcoded
`sh`)
### Performance
- Pre-computed directory listing sent with first API call to skip
initial `list-dir` round-trip
- `_prevPhases` cross-phase caching to reuse results across workflow
steps (#307)
### Testing & CI
- Wizard-runner unit tests (coverage 5.94% → 99.42%)
- Banner extracted to `src/lib/banner.ts` to break circular import
- Mock isolation fixes (`spyOn` instead of `mock.module` where possible)
- Simplified coverage pipeline (removed merge-lcov workaround)
## Eval suite
The eval suite validates that the wizard produces correct, buildable
Sentry instrumentation for each supported platform. It uses a **3-phase
test architecture**:
### Phase 1: Wizard run
Each test scaffolds a fresh project from a platform template, then runs
the full `sentry init` wizard against it. The wizard output (exit code,
stdout/stderr, git diff, new files) is captured for the next phases.
### Phase 2: Hard assertions (deterministic)
Five code-based pass/fail checks that run without any LLM:
1. **exit-code** — wizard exits 0
2. **sdk-installed** — the Sentry SDK package appears in the dependency
file (`package.json` / `requirements.txt`)
3. **init-present** — `Sentry.init` (or `sentry_sdk.init`) appears in
changed or new files
4. **no-placeholder-dsn** — no leftover placeholder DSNs
(`___PUBLIC_DSN___`, `YOUR_DSN_HERE`, etc.)
5. **build-succeeds** — `npm run build` / equivalent passes after the
wizard's changes
### Phase 3: LLM judge (per-feature)
For each feature (errors, tracing, replay, logs, profiling, etc.), an
LLM judge scores correctness:
- Official Sentry docs are fetched as ground truth (URLs mapped in
`feature-docs.json`)
- GPT-4o evaluates the wizard's diff + new files against the docs on 4
criteria: feature-initialized, correct-imports, no-syntax-errors,
follows-docs
- Each criterion is scored pass/fail/unknown; the overall feature score
must be >= 0.5
### Platforms
6 platform templates are covered:
| Platform | Template | SDK |
|----------|----------|-----|
| Express | `express/` | `@sentry/node` |
| Next.js | `nextjs/` | `@sentry/nextjs` |
| SvelteKit | `sveltekit/` | `@sentry/sveltekit` |
| React + Vite | `react-vite/` | `@sentry/react` |
| Flask | `python-flask/` | `sentry-sdk` |
| FastAPI | `python-fastapi/` | `sentry-sdk` |
### Running
```bash
bun run test:init-eval # all platforms
```
Requires `SENTRY_AUTH_TOKEN`, `SENTRY_ORG`, `SENTRY_PROJECT`, and
optionally `OPENAI_API_KEY` (LLM judge is skipped without it).
## Test Plan
- [x] All init unit tests pass (124 tests across 7 files)
- [x] `bun run lint` and `bun run typecheck` pass
- [x] CI passes (unit tests, e2e, lint, typecheck, build)
- CI workflow for eval is tracked separately in #290
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>1 parent 8ce5128 commit ae5a386
79 files changed
Lines changed: 6095 additions & 71 deletions
File tree
- docs/src/content/docs
- commands
- plugins/sentry-cli/skills/sentry-cli
- src
- commands
- project
- lib
- init
- test
- commands
- project
- init-eval
- helpers
- templates
- express-app
- src
- nextjs-app
- src/app
- python-fastapi-app
- python-flask-app
- react-vite-app
- src
- sveltekit-app
- src
- routes
- lib
- formatters
- init
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| |||
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
| 73 | + | |
69 | 74 | | |
70 | 75 | | |
71 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
630 | 630 | | |
631 | 631 | | |
632 | 632 | | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
633 | 647 | | |
634 | 648 | | |
635 | 649 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| 68 | + | |
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | 111 | | |
130 | 112 | | |
131 | 113 | | |
| |||
0 commit comments