Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

feat: add sentry conversation command group for inspecting AI agent transcripts - #1020

Merged
jared-outpost[bot] merged 5 commits into
mainfrom
feat/ai-conversations-command
Aug 3, 2026
Merged

jared-outpost[bot] merged 5 commits into
mainfrom
feat/ai-conversations-command

Conversation

@sergical

@sergical sergical commented May 24, 2026 •

Copy link
Copy Markdown
Member

Goal

Give Sentry users a first-class, terminal-native way to inspect AI agent
conversations
— the same LLM/tool-call transcripts you can see in the Sentry
UI's AI monitoring views — without leaving the shell or hand-rolling API calls.
This is aimed squarely at the CLI's agent-friendly audience: people debugging
agents want to pull a conversation's full transcript (and a scannable list of
recent ones) into their own tooling.

Two commands:

  • sentry conversation list — recent AI conversations for an org
  • sentry conversation view [<org>/]<conversation-id> — the full transcript
    (user/assistant turns, tool calls, tokens, errors)

Principles

  • Consistency over novelty. Everything reuses the existing CLI machinery —
    buildListCommand/buildCommand, the shared bidirectional pagination
    cursor-stack, resolveOrg auto-detection, the markdown/plain rendering
    pipeline, and --json/--fields output. Nothing about conversations gets a
    bespoke code path where a shared one exists, so it behaves exactly like
    issue, trace, and span for flags, pagination, and JSON envelopes.

  • Match gh-style ergonomics. view takes a single
    [<org>/]<conversation-id> positional (org is parsed off the prefix or
    auto-detected), mirroring how the other view commands accept a target. The
    list table sheds low-priority columns on narrow terminals instead of
    truncating the useful ones.

  • Lean on @sentry/api, deviate only where forced. Response pagination goes
    through the SDK's canonical Link-header parser. The /ai-conversations/
    endpoints themselves are not yet modeled by @sentry/api (0.253.0, the
    latest release) — they're a new AI-monitoring feature that hasn't landed in
    getsentry/sentry-api-schema — so, exactly as logs.ts/traces.ts do for
    their experimental endpoints, they're called directly via apiRequestToRegion
    with local Zod schemas and an explanatory comment. When the SDK ships these
    endpoints, the local schemas should be swapped for the generated types.

  • Faithful transcripts. Transcript reconstruction from raw gen_ai.* span
    attributes is ported from sentry-mcp's get-ai-conversation-details so the
    CLI, MCP, and UI tell the same story about a conversation.

  • Agent-friendly output. Every command emits a structured --json envelope
    so coding agents can consume conversations directly, per the CLI's core goals.

Test plan

  • sentry conversation list shows recent conversations
  • sentry conversation list my-org with explicit org
  • sentry conversation list --json outputs the JSON envelope
  • sentry conversation list -c next / -c prev paginate
  • sentry conversation view my-org/conv-123 shows the transcript
  • sentry conversation view conv-123 with auto-detected org
  • sentry conversation view my-org/conv-123 --json outputs structured JSON
  • narrow terminals drop low-priority list columns instead of truncating

@github-actions

github-actions Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1020/

Built to branch gh-pages at 2026-08-03 18:58 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@sergical

Copy link
Copy Markdown
Member Author

Addressed both Warden findings in 3021223:

GGA-VPD (absolute date ranges silently ignored): listConversations now accepts start/end params, and the list command spreads ...timeParams to forward all time range fields.

5RV-D34 (Infinity timestamps on empty spans): buildTranscriptResult returns 0 instead of Infinity/-Infinity when spans array is empty.

Also consolidated the duplicate view formatter into formatTranscriptResult in the formatters module.

AI-generated, verified against tsc and updated code.

Comment thread src/lib/api/ai-conversations.ts Resolved
@github-actions

github-actions Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 92.18%. Project has 4301 uncovered lines.

Files with missing lines (2)
File Patch % Lines
src/lib/formatters/conversation.ts 88.51% ⚠️ 17 Missing and 16 partials
src/commands/conversation/list.ts 94.29% ⚠️ 2 Missing and 1 partials

Generated by Codecov Action

Comment thread src/lib/formatters/ai-conversations.ts Resolved
@sergical
sergical marked this pull request as ready for review May 24, 2026 13:21
Comment thread src/lib/api/ai-conversations.ts Resolved
Comment thread src/lib/formatters/conversation.ts Resolved
Comment thread src/commands/ai-conversations/view.ts Resolved
Comment thread src/lib/formatters/ai-conversations.ts Resolved
@sergical sergical changed the title feat: add sentry ai-conversations command group feat: add sentry conversation command group May 24, 2026
Comment thread src/lib/formatters/conversation.ts Resolved
Comment thread src/lib/formatters/ai-conversations.ts Resolved
@BYK BYK added the jared Trigger the Jared agent to work on stuff label Aug 3, 2026
@BYK

BYK commented Aug 3, 2026

Copy link
Copy Markdown
Member

Jared, get this PR into a mergeable state

Adds `sentry conversation list` (paginated AI conversation listing) and
`sentry conversation view [org] <conversation-id>` (full transcript with
turns, messages, and tool calls), following existing CLI patterns
(buildListCommand/buildCommand, bidirectional pagination, resolveOrg,
domain formatter).

Rebuilt on top of current main after the pnpm-workspace restructure moved
the CLI under packages/cli/; the original feat/ai-conversations-command
branch predated that migration and could no longer merge cleanly.

New files:
- src/commands/conversation/ (route map, list, view)
- src/lib/api/conversations.ts (list + detail endpoints)
- src/lib/formatters/conversation.ts (table + transcript parser)
- src/types/conversation.ts (Zod schemas)

Wired into app routes, api-client barrel, types barrel, and completions.
Generated docs/skill files regenerated.
@jared-outpost
jared-outpost Bot force-pushed the feat/ai-conversations-command branch from eb249d0 to c7c9ff9 Compare August 3, 2026 17:28
@jared-outpost

jared-outpost Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Got #1020 into a mergeable state. The branch was 254 commits behind main and predated the pnpm-workspace restructure (everything moved under packages/cli/), so the old branch couldn't merge and a plain rebase would've fought the layout migration through 17 commits.

Rebuilt the feature cleanly on top of current main:

  • ported the conversation command group, API module, formatter, and Zod types to packages/cli/ paths
  • wired it into app.ts routes, the api-client and types barrels, and completions (ORG_ONLY_COMMANDS)
  • regenerated docs/skill files

Locally green: tsc --noEmit, biome check, check:deps, check:fragments, and all 103 conversation/completions tests. Squashed into a single commit; CI is running now. Merge conflict is resolved — PR now shows MERGEABLE.

@BYK

BYK commented Aug 3, 2026

Copy link
Copy Markdown
Member

Jared, address all bot comments, review this PR in terms of our command standards for naming, help, documentation, output format consistency etc. and make any fixes you see necessary. Than ask me to review before merging.

@BYK

BYK commented Aug 3, 2026

Copy link
Copy Markdown
Member

Jared, .lore.md at project root will be your north star for standards along with the already in lint rules

- Fix token double-count in buildTranscriptResult: sum tokens per turn
  (ai_client spans) instead of every span, so parent invoke_agent spans
  that aggregate child usage don't inflate the header total (Cursor Bugbot).
- Route human output through the markdown pipeline: formatConversationTable
  uses formatTable/Column; formatTranscriptResult/formatTurnHuman use
  mdKvTable, markdown headings, escapeMarkdownCell/Inline, safeCodeSpan and
  renderMarkdown instead of hand-rolled padStart columns + raw sanitize().
- Use typed ContextError for missing org (list) and missing conversation-id
  (view) instead of bare throw new Error.
- Add module-level JSDoc to src/types/conversation.ts.
- Update tests for markdown-rendered output and typed errors.
@jared-outpost

jared-outpost Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@BYK ready for your review. Pushed 11e3f456 addressing everything:

Bot comments

  • Cursor Bugbot (token double-count): buildTranscriptResult now sums tokens per turn (ai_client spans) instead of every span, so parent invoke_agent aggregate spans don't inflate the header total. Thread resolved.

Command-standards pass (against .lore.md + lint rules, benchmarked vs replay/trace):

  • Output now goes through the markdown pipeline like every other command — formatConversationTable uses formatTable/Column; the transcript view uses mdKvTable, markdown headings, escapeMarkdownCell/escapeMarkdownInline/safeCodeSpan and renderMarkdown. Dropped the hand-rolled padStart columns and the sanitize() (which is the local serve tail helper, not the escaping used by the renderer).
  • Errors: missing org (list) and missing conversation-id (view) now throw typed ContextError instead of bare Error, matching the ContextError/ResolutionError/ValidationError convention.
  • Added the missing module-level JSDoc to types/conversation.ts.
  • Pagination, flag/alias sets, positionals, and help/fragments already matched the sibling conventions.

Green locally: tsc --noEmit, biome check, check:deps, check:fragments, and 104 conversation/formatter/completions tests. CI is re-running on the new commit.

Two things I deliberately left as-is (flag me if you want them changed):

  1. view keeps two positionals ([<org>] <conversation-id>) rather than a single slash-separated org/conversation-id arg — the disambiguation logic already handles the org-optional case and conversation IDs aren't org/project-scoped like trace/replay IDs.
  2. The list table has 7 columns, so on an 80-col terminal it truncates aggressively (same shrink behavior as other wide tables via formatTable).

Not auto-merging — it's risk: high and sizable. Over to you.

Comment thread packages/cli/src/app.ts Resolved
@BYK

BYK commented Aug 3, 2026

Copy link
Copy Markdown
Member

view keeps two positionals ([] ) rather than a single slash-separated org/conversation-id arg — the disambiguation logic already handles the org-optional case and conversation IDs aren't org/project-scoped like trace/replay IDs.

Use sentry trace as your blueprint for this

The list table has 7 columns, so on an 80-col terminal it truncates aggressively (same shrink behavior as other wide tables via formatTable).

See what sentry issue list does for this: less columns on narrow widths.

- Register a hidden `conversations` route alias + PLURAL_TO_SINGULAR entry
  so `sentry conversations` runs `conversation list` and the singular is
  suggested, matching issues/replays/events (Cursor Bugbot).
- collectMessages: fall back to `parts` (in addition to content/text) so
  `conversation view` renders text for spans that store message parts under
  a `parts` array instead of dropping them as empty turns (Cursor Bugbot).
- conversation view: take a single `[<org>/]<conversation-id>` positional
  instead of two positionals; conversation IDs are org-scoped and never
  contain a slash, so org is parsed off the prefix and otherwise auto-detected.
- conversation list: drop the Tools/Errs/User columns on terminals narrower
  than 100 cols so the core columns don't truncate aggressively, mirroring
  `issue list`'s TREND-column behavior.
- Regenerate committed skill docs for the new alias.
@jared-outpost

jared-outpost Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Done in 52e7e59. Both Bugbot issues + your two follow-ups:

  • view arg: now a single [<org>/]<conversation-id> positional (sentry conversation view my-org/conv-123), org optional and auto-detected. Conversation IDs are org-scoped and never contain /, so it's a plain first-slash split rather than the org/project/id form trace uses.
  • narrow list: drops the Tools/Errs/User columns below 100 cols (keeps ID/Started/Tokens/First Input), same width-gated approach as issue list's TREND column.

Updated the view/formatter tests and regenerated the skill docs. Typecheck + conversation tests green locally.

@jared-outpost
jared-outpost Bot requested a review from BYK August 3, 2026 18:32

@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 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 52e7e59. Configure here.

Comment thread packages/cli/src/app.ts Resolved
The `conversations` alias added in the previous commit was registered in
the route map but missing from `hideRoute`, so — unlike every other plural
alias — it surfaced in help output, the generated project tree (as a
phantom `conversations.ts`), and the skill docs. Add it to `hideRoute`
and regenerate the committed skill docs (Cursor Bugbot).
@BYK

BYK commented Aug 3, 2026

Copy link
Copy Markdown
Member

Jared, final requests:

  1. Update the PR title and description to reflect our latest state. Explain the principles and goals, not the changes that can be read directly from the PR contents
  2. Make sure we use @sentry/api to its fullest for these new endpoints and we are not inventing new types or custom endpoint calls where we could have use existing ones from the canonical @sentry/api package. Bump its version if needed.

@BYK

BYK commented Aug 3, 2026

Copy link
Copy Markdown
Member

After those and if you don't have any more bot comments, you can merge Jared

…ntry/api

The /organizations/{org}/ai-conversations/ endpoints are not modeled by
@sentry/api 0.253.0 (the latest release) — they're a new AI-monitoring
feature not yet published to getsentry/sentry-api-schema, so no generated
SDK function or response type exists. Document that here, matching the
convention used for the experimental endpoints in logs.ts/traces.ts, so
the direct apiRequestToRegion calls read as a deliberate choice rather
than a missed reuse of the SDK (BYK review).
@jared-outpost jared-outpost Bot changed the title feat: add sentry conversation command group feat: add sentry conversation command group for inspecting AI agent transcripts Aug 3, 2026
@jared-outpost
jared-outpost Bot enabled auto-merge (squash) August 3, 2026 18:58
@jared-outpost
jared-outpost Bot merged commit 7cf6483 into main Aug 3, 2026
32 checks passed
@jared-outpost
jared-outpost Bot deleted the feat/ai-conversations-command branch August 3, 2026 19:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

jared Trigger the Jared agent to work on stuff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants