feat: add --json flag to help command for agent introspection#432
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Init
Issue List
Other
Bug Fixes 🐛Dsn
Init
Other
Documentation 📚
Internal Changes 🔧Init
Tests
Other
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 111 passed | Total: 111 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1100 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 95.02% 95.05% +0.03%
==========================================
Files 163 164 +1
Lines 22103 22244 +141
Branches 0 0 —
==========================================
+ Hits 21002 21144 +142
- Misses 1101 1100 -1
- Partials 0 0 —Generated by Codecov Action |
Addressing review commentsRe: circular import — Moved the introspection logic into The only remaining dynamic import in Re: using standard yield-based output — The command now uses
|
Round 2 review fixesAll three review comments addressed:
|
Round 3 review fixesHuman output no longer emits JSON. Implemented a proper
Example human output for No more |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Add structured JSON output to the help command so AI agents can discover CLI commands at runtime without relying on static docs. New features: - `sentry help --json` — emit full command tree as JSON - `sentry help --json <group>` — emit route group metadata - `sentry help --json <group> <cmd>` — emit specific command metadata - Framework-injected flags (help, helpAll, log-level, verbose) are stripped from JSON output Architecture: - Extract shared route-tree introspection into src/lib/introspect.ts - Consolidate duplicated type guards from help.ts and generate-skill.ts - generate-skill.ts now imports from introspect.ts (no functional change) Tests: 33 unit + 12 property-based + 10 integration tests
Phase 1 of #346: Add structured JSON output to the `help` command so AI agents can discover CLI commands at runtime. ## What Three modes of `sentry help --json`: - **Full tree**: `sentry help --json` → all routes, commands, flags, positional params as JSON - **Route group**: `sentry help --json issue` → group metadata with subcommands - **Specific command**: `sentry help --json issue list` → single command's full metadata Framework-injected flags (`help`, `helpAll`, `log-level`, `verbose`) are stripped from JSON output so agents see only user-facing flags. ## Architecture - **`src/lib/introspect.ts`** (new) — shared route-tree introspection module with types, type guards, extraction functions, and JSON cleaning utilities. Used at runtime by `help --json` and at build time by `generate-skill.ts`. - **`src/commands/help.ts`** — adds `output: "json"` and `--json` flag. Dynamic imports for the route tree and introspect module to avoid circular deps. - **`src/lib/help.ts`** — consolidated to import shared types from `introspect.ts` instead of duplicating them. - **`script/generate-skill.ts`** — imports shared types and functions from `introspect.ts`, removing ~100 lines of duplication. No functional change to output. ## Tests - 33 unit tests for introspection functions - 12 property-based tests (fast-check) for invariants - 10 integration tests for `help --json` end-to-end

Phase 1 of #346: Add structured JSON output to the
helpcommand so AI agents can discover CLI commands at runtime.What
Three modes of
sentry help --json:sentry help --json→ all routes, commands, flags, positional params as JSONsentry help --json issue→ group metadata with subcommandssentry help --json issue list→ single command's full metadataFramework-injected flags (
help,helpAll,log-level,verbose) are stripped from JSON output so agents see only user-facing flags.Architecture
src/lib/introspect.ts(new) — shared route-tree introspection module with types, type guards, extraction functions, and JSON cleaning utilities. Used at runtime byhelp --jsonand at build time bygenerate-skill.ts.src/commands/help.ts— addsoutput: "json"and--jsonflag. Dynamic imports for the route tree and introspect module to avoid circular deps.src/lib/help.ts— consolidated to import shared types fromintrospect.tsinstead of duplicating them.script/generate-skill.ts— imports shared types and functions fromintrospect.ts, removing ~100 lines of duplication. No functional change to output.Tests
help --jsonend-to-end