Repository navigation
feat(cli): Add sentry games snake - #1432
Conversation
betegon
left a comment
There was a problem hiding this comment.
Before merging:
- Stabilize the pane sizing in
ink-app.tsx/ink-snake.tsx. At 80×20, pressinggthen ↑ changes the measured board width and pauses the game before its first tick, without a terminal resize. Keep the score/help visible and add a regression covering narrow and wide terminals. - Respect
NO_COLORin the renderer while keeping the cell types distinguishable. - Add the required JSDoc for the new engine exports and type fields.
The engine/UI split and shared shortcuts fit the repo. Property/model-based tests would suit the engine invariants, but that preference is not a separate merge blocker.
|
@betegon Thanks for the review. Fixed in 0ea3fc8:
|
Adds `sentry games snake`, so the Snake game from the `sentry init` waiting screen can be played on its own. Stacked on #1432. - The command runs full-screen in the alternate screen. esc, q or ctrl+c quits and restores the terminal. - It errors when there is no TTY or when an AI agent runs the CLI. `SENTRY_INIT_GAME` does not apply here. - `loadInkSidecar()` is extracted from `createInkUI` with no behavior change, so the init wizard and the game load the sidecar the same way. - Generated docs and skill references include the new `games` route. Breaking Changes: None --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: betegon <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Adds `sentry games snake`, so the Snake game from the `sentry init` waiting screen can be played on its own. Stacked on #1432. - The command runs full-screen in the alternate screen. esc, q or ctrl+c quits and restores the terminal. - It errors when there is no TTY or when an AI agent runs the CLI. `SENTRY_INIT_GAME` does not apply here. - `loadInkSidecar()` is extracted from `createInkUI` with no behavior change, so the init wizard and the game load the sidecar the same way. - Generated docs and skill references include the new `games` route. Breaking Changes: None --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: betegon <[email protected]>
ba78133 to
2e16786
Compare
32293fa to
d1efe47
Compare
| /** Routes that stay in `sentry help` but not in the skill, because agents cannot use them. */ | ||
| const HUMAN_ONLY_ROUTES = new Set(["games"]); |
There was a problem hiding this comment.
Shall we make this an easter egg, hidden from the help too?
There was a problem hiding this comment.
Done in bec0f47. games is now a hidden route, so help, help --json, completions, the docs site, and the skill leave it out. The skill filter is gone.
870f494 to
159de2b
Compare
|
This PR now sits on #1945, which sets a CI budget for the JavaScript each command reads. Size cost of games (#1432 and #1437 together), against that baseline:
The games code loads only for |
Please no, not yet. |
Play Snake full-screen in the terminal with `sentry games snake`. The game is standalone: it no longer runs inside the `sentry init` waiting screen and does not load Ink or the init sidecar. A small runner (`src/lib/games/snake-terminal.ts`) draws straight to the terminal with the alternate screen and raw-mode keys, on top of the pure engine in `src/lib/games/snake-game.ts`. The command imports the runner with `import()`, so other commands and the full route tree load only the route stub. `completions.property.test.ts` now accepts a command without visible flags: the completion targets leave `flagNames` out for those, and `games snake` is the first one. Co-authored-by: Claude <[email protected]>
Agents cannot play, so the skill does not list the games route. It stays in sentry help. Co-authored-by: Claude <[email protected]>
Co-authored-by: Claude <[email protected]>
A terminal can deliver one arrow key over two reads, and Alt plus a key arrives as escape and the key. Both quit the game. Keep an unfinished sequence until the next read, drop Alt plus a key, and read a lone escape as Esc only when nothing follows within 100 ms. Co-authored-by: Claude <[email protected]>
A lone Esc waits for the rest of a split key sequence. When the next read did not continue it, the Esc and the next key were dropped as Alt+key, and leftover bytes of an arrow key could turn the snake. Now the pending Esc quits and the next read is parsed on its own. An Esc followed by another escape in one read is also the Esc key. Co-authored-by: Claude <[email protected]>
Make `sentry games` an easter egg. The route is now hidden, so help, help --json, completions, the docs site, and the agent skill leave it out, and the skill no longer needs its own filter for it. Co-authored-by: Claude <[email protected]>
159de2b to
bec0f47
Compare
|
Unstacked: this PR is on |
Adds `sentry games leaderboard`, which shows the top 10 Snake scores from the last 30 days. Stacked on #1432. The leaderboard is a working example of Sentry application metrics: the CLI emits a metric and the Worker reads it back, with no database. `apps/games-api/README.md` describes the full data flow and lists which file to edit for each kind of change. **Scores (CLI)** - A finished game sends one `snake.score` metric to the CLI telemetry project. Its only custom attribute is a random handle such as `brave-otter-4242`, stored in the local `metadata` table. - The metric goes out in a new trace with the user cleared on both scopes. `beforeSendMetric` keeps only `handle`, `sentry.release`, `sentry.environment` and `sentry.sdk.*` for this metric. - The handle format, metric name and score limit live in `@sentry/toolkit-core/games`, which the CLI and the Worker both import. - Nothing is sent when telemetry is off (`SENTRY_CLI_NO_TELEMETRY`, `DO_NOT_TRACK`, or the stored preference). - The score is flushed as soon as it is recorded. Metrics otherwise wait up to 5 seconds in the SDK buffer, and on macOS the CLI force-exits about 100 ms after a command ends. **Endpoint (new `apps/games-api` Worker)** - A standalone Hono Worker, `sentry-games-api`, on `https://games.sentry.new`. The MCP server is not changed: the read token never shares a Worker with its OAuth secrets. - `GET /v1/snake/leaderboard` queries the `tracemetrics` dataset for `max(value)` per handle, with `value:<=10000`. - It rate-limits by hashed IP (30/min). The limiter fails open, like `checkRateLimit` in mcp-cloudflare. It caches the result with the Workers Cache API for 5 minutes. - It checks the upstream rows against the handle format and the score bounds. Every failure returns a generic error. The token, URL and upstream text never reach the response or Sentry. - `Sentry.withSentry` reports upstream and missing-token failures to `sentry-developer-experience/games-api`. The SDK does not collect the client IP, headers, cookies, bodies or query strings. A test checks the emitted envelope through the production wrapper. - The CLI validates each row again and drops rows that fail, so server text cannot write control sequences to the terminal. Network and HTTP failures exit with the API exit code (30). `--json` entries carry a `you` flag. **Impact on other commands:** +600 bytes on the startup path of every command (the metric scrubber in `telemetry.ts` and the `SENTRY_GAMES_API_URL` registry entry). The rest loads only for `sentry games`. **Deployment.** The Worker runs on the Sentry Internal Cloudflare account. The `Deploy Games API` workflow deploys it after a successful `Test` push run on `main`, the same gate as `Deploy Docs MCP`. Only the credential check and `wrangler deploy` steps receive the Cloudflare credentials. The MCP Workers use a different account, so the workflow has its own secrets. All of them are set: 1. `production` environment: `GAMES_API_CLOUDFLARE_API_TOKEN` (Workers Scripts: Edit on Sentry Internal; Workers Routes: Edit and Zone: Read on `sentry.new`) and `GAMES_API_CLOUDFLARE_ACCOUNT_ID`. The token is a personal token for now; replace it with an account-owned token when a Sentry Internal Super Administrator can create one. 2. On the Worker: `SENTRY_GAMES_READ_TOKEN` (a bot token with `org:read` only, on a user that is a member only of the CLI team) and `SENTRY_DSN`. **Known limit:** the DSN is public, so anyone can submit a score. The handle format and the 10,000 cap block only impossible values. Breaking Changes: None Created with Claude Code --------- Co-authored-by: Claude <[email protected]>
| const SENTRY_HOST = "https://us.sentry.io"; | ||
| const SENTRY_ORG_SLUG = "sentry"; | ||
| const SNAKE_PROJECT_ID = "4510776311808000"; | ||
| const SCORE_FIELD = `max(value,${SNAKE_SCORE_METRIC},distribution,-)`; |
There was a problem hiding this comment.
Leaderboard aggregate uses a unit that does not match emitted scores
Snake scores are emitted without a unit, whose documented tracemetrics unit is none, but the leaderboard requests distribution,-. The query therefore does not read the emitted score series, leaving the leaderboard empty or unavailable.
Evidence
reportSnakeScore()emitssnake.scorewithout a unit; the Explore/dashboard docs say an unspecified metric unit isnoneand that the query unit must match SDK emission.buildUpstreamUrl()usesdistribution,-for both the score field and sort, andfetchLeaderboard()reads scores using that same field key.- The leaderboard test fabricates upstream rows keyed with
-and checks the generated URL, so it does not verify compatibility with emitted metrics; the deploy smoke test checks only HTTP 200.
Identified by Warden · code-review · EK9-T42
There was a problem hiding this comment.
No change needed. In a trace metric aggregate, - means "any unit" and adds no unit filter. It is not a different unit:
extract_trace_metric_aggregate_argumentsinsrc/sentry/search/eap/columns.pyturns a-unit argument intometric_unit=None.TraceMetric.get_filterinsrc/sentry/search/eap/trace_metrics/types.pyadds a unit filter only when the unit is notNoneand notANY_UNIT("-").
So max(value,snake.score,distribution,-) matches the scores that the CLI sends without a unit. none would also match them, but - keeps the query correct if the CLI adds a unit later.
When the terminal is smaller than the smallest board, show a short message instead of the board and ignore keys other than quit. Clip the score line to the board width so it does not wrap. Co-authored-by: Claude <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a8a7ca5. Configure here.
| fits() | ||
| ? renderSnakeFrame(state, best, color) | ||
| : `\x1b[H${TOO_SMALL_MESSAGE.slice(0, columns())}\x1b[K\x1b[J`, | ||
| ); |
There was a problem hiding this comment.
Game runs while terminal is too small
Low Severity
Shrinking below the smallest frame does not stop a playing run when snakeBoardSize still returns the clamped 10×6 board. resizeSnake then leaves status as playing, so schedule keeps stepping while draw hides the board and keys are ignored. The snake can hit a wall and fire onGameOver off-screen.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit a8a7ca5. Configure here.


Summary
Adds
sentry games snake, a full-screen Snake game in the terminal. It is a standalone command. It has no link tosentry init, which will be deprecated.src/lib/games/snake-game.tsis the pure engine: state transitions and a half-block renderer.src/lib/games/snake-terminal.tsdrives the terminal directly: alternate screen, raw-mode keys, and one redraw per state change. It loads no React, Ink, or Yoga.wasd, orhjklsteer.por space pauses,rrestarts, andesc,q, orctrl+cquits. A resize pauses the run and keeps it.gamesis an easter egg: a hidden route, so help,help --json, completions, the docs site, and the agent skill leave it out.gamesis a lazy route in the command manifest, so other commands do not load the game.This PR replaces the earlier version that put the game on the
sentry initwaiting screen. Rebased onmain.Impact on other commands
Measured on the npm bundle, as bytes of the chunks each command compiles, against
main, before the route was hidden. Hiding it can only make these numbers smaller:--version,help,issue list,org listhelp --jsonBreaking Changes
Created with Claude Code