Skip to content

feat(cli): crash reports with a cli_ reference for the CLI and MCP server, proxied through the API (repo#705) - #1908

Draft
nc9 wants to merge 1 commit into
mainfrom
boat/cli-crash-reporting-705
Draft

nc9 wants to merge 1 commit into
mainfrom
boat/cli-crash-reporting-705

Conversation

@nc9

@nc9 nc9 commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 3 of squirrelscan/repo#705, the public (CLI and MCP) half. The API half (forwarding crash events to Sentry server-side) is private and filed as a follow-up, so this PR does not close the epic.

  • apps/cli/src/self/crash-reporter.ts (new): process-wide uncaughtException and unhandledRejection handlers, installed first thing in run() (light path included). A crash prints a friendly stderr message with a cli_<12 hex> reference, sends one report, waits for it (at most 2 s) and exits 1. Node built-ins only; telemetry is imported lazily on crash, so the light startup path (feat(rules): rendered reflow, text spacing and text resize checks (repo#3091) #2023) is unchanged.
  • run-cli.ts: an unexpected error thrown by a command goes through the same path (it used to console.error the raw error).
  • mcp/server.ts: every registered tool handler is wrapped. A throw becomes an isError tool result carrying a reference, one stderr line (never stdout), and a report. SDK ProtocolErrors pass through untouched.
  • telemetry.ts: sendCrashReport posts an error event on the existing /v1/traces path with reference, error_type (class name), command (subcommand name only), platform, source, and stack. The API's zod schema strips unknown fields today, so this is backward compatible until the API side lands.
  • Privacy: the stack keeps only code locations (function, file name, line:col). The message line, directories, URLs and email addresses are removed, it is capped at 8 KB (the API's anonymous body cap is 16 KB). The error message is never sent. All opt-outs (NO_TELEMETRY, DO_NOT_TRACK, user and project telemetry=false) and --offline send nothing. The telemetry notice gains one sentence and its version goes 2 to 3 so existing installs see it once more; stack frames are only sent once v3 has been seen (the session token still needs v2).
  • No Sentry SDK or DSN in the binary; a test guards it.
  • Docs: docs/cli/self.mdx (new "Crash reports" subsection), docs/faq.mdx, README telemetry paragraph, CHANGELOG.

Acceptance criteria (repo#705, Phase 3 item)

  • Uncaught exception: friendly message with reference, exit 1, reported. process crash handlers > an uncaught exception prints a reference, exits 1 and reports it (real subprocess, local stand-in API).
  • Unhandled rejection: same. ... > an unhandled rejection prints a reference, exits 1 and reports it.
  • Command that throws: same via runCli. ... > a command that throws prints a reference, exits 1 and reports it.
  • MCP server: tool failure returns a referenced tool error and reports; protocol errors pass through. sendCrashReport > an MCP tool that throws ..., ... > an MCP protocol error passes through unreported. Process-level MCP crashes use the same global handlers (stderr only).
  • Telemetry off or --offline: reference still printed, exit 1, nothing sent. ... > with telemetry off ..., ... > with --offline ..., sendCrashReport > every opt-out sends nothing.
  • No Sentry DSN in the shipped binary. no third-party DSN in the binary > the CLI has no Sentry SDK dependency and no DSN in its source.
  • Appears in Sentry via the API: needs the private API change (follow-up in squirrelscan/repo).

Gates

  • apps/cli: bun run format:check pass, bun run lint pass, bun run typecheck pass.
  • bun test tests/self/crash-reporter.test.ts tests/cli/run-cli.test.ts tests/self/first-run-telemetry.test.ts tests/mcp/server.test.ts tests/cli/startup.test.ts: 87 pass, 0 fail.
  • bun test tests/self/telemetry.test.ts tests/squirrel-home-guard.test.ts tests/mcp/protocol.test.ts tests/cli/setup-telemetry.test.ts tests/cli/banner.test.ts: 32 pass, 0 fail.
  • docs/: make validate all checks passed.

Agent skill

The squirrelscan agent skill does not need a change. It could later mention quoting the cli_ reference when reporting a crash, but nothing it says is now wrong.

@nc9
nc9 force-pushed the boat/cli-crash-reporting-705 branch from 841f6a6 to ed4acb4 Compare November 16, 2026 04:33
…rver, proxied through the API (repo#705)

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the boat/cli-crash-reporting-705 branch from ed4acb4 to 7cf3cb3 Compare November 17, 2026 01:43

This branch has not been deployed

No deployments
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