Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(inbox): Move report code diff into a Files changed tab (#68257)

Michael Matloka96bdebff4d10
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 9b54a90f4655..e5f0bcf09fa4 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -5823,17 +5823,17 @@ snapshots:
scenes-app-inbox-cards--skeleton--light:
hash: v1.k794b7964.24c19ab5df1e4ccb843b1ad726752e3a98aeadaa08595e66cb4b41aff1a9e9a1.Y3z44tkU4jsAYUyXxfl72fTuZ0MKA6_S6TTNCKt5jSg
scenes-app-inbox-detail--pull-request--dark:
- hash: v1.k794b7964.386115011be31707aaf9d16697612459ad1c566f71c8e6cec065ac047d0770de.r_CQ_s1jAIwMXL6qVCyT63AvZK5T2vixwTD3_1J2DW4
+ hash: v1.k794b7964.afc834899dd290dd373afd5b9ef0f9481d5d5c895e92dcab5b656d278602035a.X5nW1dvAD5zn3RFeytk9dFvvjHj8FWVMlQW9h1XGMAo
scenes-app-inbox-detail--pull-request--light:
- hash: v1.k794b7964.2c6998881cc1012f7074e095d51d84f8c74f3d8f04a019a3e7e16c70b544e8f6.H7U2xewUqXIanKxXfMUGkTKQg5IX2JNrIYYs3gbnBew
+ hash: v1.k794b7964.c2624da48e0b123f86b2cbceb9d11bc9935abf24d1aece6d2f1259f182439d4e.-fYiL53nvwVzWAf5fGKa9Ze0Qvze-VdG4uLVJ9gVUCU
scenes-app-inbox-detail--report--dark:
- hash: v1.k794b7964.af9919d42abe14c590a989816603f2973e8e6a5e272260cf5fe3eedd00b162bc.fEhmjESZwg_Qft3lrg346I9iD4GnPEYT9i2rBum_feE
+ hash: v1.k794b7964.1d75ec9c3bc54647bc0275b183ba1c3b0e4a50ae546c2796d2ccc8e7213c2eb7.s8cctju78p2KKN4rBtcwW-0B7rZvfH2S4awE_z4bJBk
scenes-app-inbox-detail--report--light:
- hash: v1.k794b7964.56c75cded955fb2f08c09decfaf23c8ee9d3d14aaaeeffe6e0414454630b1e0c.PNDzFwFf1Dw9QDkkQtSetmZkAAqPkqv4GxnYeL5LV_M
+ hash: v1.k794b7964.a7ef412ce67a64dc50a6f39bcdcbae819ae469f834fe0c4774e8057e98f8da9e.SlB-3-uMV0Nx_dw1BEyd0myjI8K9SRjGi0xZbHwkB1I
scenes-app-inbox-detail--report-minimal--dark:
- hash: v1.k794b7964.bcc48fa880c9368e1b2f9f544b20cb26ed3b7c703acfd48ee60044651dbc71c0.ttJCHwEflRemFjMlI0TU6rXpUePyI4RC8XRhj8P3TaU
+ hash: v1.k794b7964.8cfc9e62bfd17e114ad92c87b90b0001f50e8bfc4eec52d651482d85b3f81e4a.1i2hZbDqM13hR1tjXuQmBHNUyyiM_MW52wiMhXO2Mdo
scenes-app-inbox-detail--report-minimal--light:
- hash: v1.k794b7964.71a9fc9ab6e75a29954d860103da9b45a1848ea31b0eda5669e97f343d8db986.S8rycB_MQK2wCPMi0gELuVE6Gc62h0Kbmp0g3fuE7i0
+ hash: v1.k794b7964.36bed308e7377b8b36a43b015d95d91cc4a1156f4c7dde7bd5d60bf9b29cdae4.kBXbfs9cEV7FwkIf_dNSHSW4UTLLDXA_ATLSA3LUe9c
scenes-app-inbox-detail--run-failed--dark:
hash: v1.k794b7964.6694c0a4ba6adc4c39564eba480983fef70204296e62367e4d4967d0af76e544.SBnSmqIC6wqOb4FbDhPcxHOecFjXvW6mtg6ucQmh9hs
scenes-app-inbox-detail--run-failed--light:
diff --git a/frontend/src/lib/lemon-ui/LemonTabs/LemonTabs.scss b/frontend/src/lib/lemon-ui/LemonTabs/LemonTabs.scss
index c9b23e790c69..ff513eb1d391 100644
--- a/frontend/src/lib/lemon-ui/LemonTabs/LemonTabs.scss
+++ b/frontend/src/lib/lemon-ui/LemonTabs/LemonTabs.scss
@@ -86,6 +86,10 @@
color: var(--color-text-primary);
}
+ &:not(:hover) .LemonTag {
+ color: var(--color-text-tertiary);
+ }
+
&.LemonTabs__tab--disabled {
color: var(--color-text-tertiary);
opacity: 0.5;
diff --git a/frontend/src/scenes/inbox/InboxScene.tsx b/frontend/src/scenes/inbox/InboxScene.tsx
index c3388311516b..e3a1882323d2 100644
--- a/frontend/src/scenes/inbox/InboxScene.tsx
+++ b/frontend/src/scenes/inbox/InboxScene.tsx
@@ -134,7 +134,8 @@ function InboxDetailView({ report }: { report: SignalReport }): JSX.Element {
return (
<div className="flex flex-col min-h-0 flex-1 overflow-auto">
- <ReportDetail report={report} tab={activeTab} />
+ {/* Key on the report so per-report detail state (e.g. the active diff tab) resets on navigation. */}
+ <ReportDetail key={report.id} report={report} tab={activeTab} />
</div>
)
}
diff --git a/frontend/src/scenes/inbox/components/detail/PullRequestDiffPanel.tsx b/frontend/src/scenes/inbox/components/detail/PullRequestDiffPanel.tsx
index f794ace3f461..9d04dd77ade6 100644
--- a/frontend/src/scenes/inbox/components/detail/PullRequestDiffPanel.tsx
+++ b/frontend/src/scenes/inbox/components/detail/PullRequestDiffPanel.tsx
@@ -1,14 +1,13 @@
import { useValues } from 'kea'
-import { useState } from 'react'
+import { useMemo, useState } from 'react'
-import { IconCode, IconGitBranch } from '@posthog/icons'
+import { IconGitBranch } from '@posthog/icons'
import { LemonSegmentedButton, LemonSkeleton, LemonTag, Tooltip } from '@posthog/lemon-ui'
import { inboxReportDetailLogic } from '../../logics/inboxReportDetailLogic'
import { SignalReport } from '../../types'
import { CommitContent } from './artefactTypes'
-import { DetailSection } from './DetailSection'
-import { PullRequestDiffView } from './PullRequestDiffView'
+import { PullRequestDiffView, summarizeDiff } from './PullRequestDiffView'
const DIFF_STYLE_OPTIONS = [
{ value: 'unified' as const, label: 'Unified' },
@@ -16,53 +15,98 @@ const DIFF_STYLE_OPTIONS = [
]
/**
- * Full-width "Files changed" section: the report's branch diff against the repository default branch,
- * rendered GitHub-style and read-only. The diff itself is loaded by `inboxReportDetailLogic` (keyed to
- * the report, cascading off the artefact load) — this component just renders the current state. The
- * diff reflects the latest `commit` artefact's branch tip, so it tracks the work as the branch moves.
+ * The report's branch as a git-branch tag. Rendered in the "Files changed" tab label (so the tab
+ * signals there's code behind it, GitHub-style) — inside the LemonTabs active tab it picks up the
+ * accent color for free.
+ */
+export function PullRequestBranchTag({ commit }: { commit: CommitContent }): JSX.Element {
+ return (
+ <Tooltip title={`Comparing ${commit.repository}@${commit.branch} against the default branch`}>
+ <LemonTag type="muted" className="font-mono min-w-0">
+ <IconGitBranch className="shrink-0" />
+ <span className="truncate">{commit.branch}</span>
+ </LemonTag>
+ </Tooltip>
+ )
+}
+
+/**
+ * "Files changed" tab body: the report's branch diff against the repository default branch, rendered
+ * GitHub-style and read-only. The tab carries the branch tag; this toolbar balances diff stats on the
+ * left with the unified/split toggle on the right. The diff itself is loaded by `inboxReportDetailLogic`
+ * (keyed to the report, cascading off the artefact load) — this component just renders the current
+ * state, tracking the branch tip as the work moves.
*/
export function PullRequestDiffPanel({ report, commit }: { report: SignalReport; commit: CommitContent }): JSX.Element {
const { reportDiff, reportDiffError } = useValues(inboxReportDetailLogic({ reportId: report.id, report }))
const [diffStyle, setDiffStyle] = useState<'unified' | 'split'>('unified')
+ const diffSummary = useMemo(
+ () => (reportDiff ? summarizeDiff(reportDiff.diff, commit.commit_sha) : null),
+ [reportDiff, commit.commit_sha]
+ )
return (
- <DetailSection
- icon={<IconCode />}
- title="Files changed"
- afterTitle={
- <Tooltip title={`Comparing ${commit.repository}@${commit.branch} against the default branch`}>
- <LemonTag type="muted" className="font-mono">
- <IconGitBranch className="shrink-0" />
- <span className="truncate">{commit.branch}</span>
- </LemonTag>
- </Tooltip>
- }
- rightSlot={
+ <div className="flex flex-col gap-3">
+ <div className="flex items-center justify-between gap-3 min-w-0">
+ <DiffToolbarSummary commit={commit} diffSummary={diffSummary} />
<LemonSegmentedButton
size="small"
value={diffStyle}
onChange={setDiffStyle}
options={DIFF_STYLE_OPTIONS}
+ className="shrink-0"
/>
- }
- >
- <div className="flex flex-col gap-3">
- {reportDiffError ? (
- <p className="m-0 py-4 text-sm text-danger">{reportDiffError}</p>
- ) : reportDiff ? (
- <PullRequestDiffView
- diff={reportDiff.diff}
- truncated={reportDiff.truncated}
- cacheKey={commit.commit_sha}
- diffStyle={diffStyle}
- />
- ) : (
- <div className="flex flex-col gap-2">
- <LemonSkeleton className="h-8 w-full" />
- <LemonSkeleton className="h-24 w-full" />
- </div>
+ </div>
+ {reportDiffError ? (
+ <p className="m-0 py-4 text-sm text-danger">{reportDiffError}</p>
+ ) : reportDiff ? (
+ <PullRequestDiffView
+ diff={reportDiff.diff}
+ truncated={reportDiff.truncated}
+ cacheKey={commit.commit_sha}
+ diffStyle={diffStyle}
+ />
+ ) : (
+ <div className="flex flex-col gap-2">
+ <LemonSkeleton className="h-8 w-full" />
+ <LemonSkeleton className="h-24 w-full" />
+ </div>
+ )}
+ </div>
+ )
+}
+
+/** Left side of the diff toolbar — repo context while loading, GitHub-style stats once the patch lands. */
+function DiffToolbarSummary({
+ commit,
+ diffSummary,
+}: {
+ commit: CommitContent
+ diffSummary: ReturnType<typeof summarizeDiff>
+}): JSX.Element {
+ if (diffSummary) {
+ const fileLabel = diffSummary.fileCount === 1 ? '1 file changed' : `${diffSummary.fileCount} files changed`
+
+ return (
+ <div className="flex min-w-0 items-center gap-2 text-sm">
+ <span className="truncate text-secondary">{fileLabel}</span>
+ {(diffSummary.additions > 0 || diffSummary.deletions > 0) && (
+ <span className="flex shrink-0 items-center gap-2 font-mono text-xs tabular-nums">
+ {diffSummary.deletions > 0 && <span className="text-danger">-{diffSummary.deletions}</span>}
+ {diffSummary.additions > 0 && <span className="text-success">+{diffSummary.additions}</span>}
+ </span>
)}
</div>
- </DetailSection>
+ )
+ }
+
+ return (
+ <span
+ className="min-w-0 truncate font-mono text-xs text-tertiary"
+ title={`Comparing ${commit.repository}@${commit.branch} against the default branch`}
+ >
+ {commit.repository}
+ <span className="opacity-70"> · vs default branch</span>
+ </span>
)
}
diff --git a/frontend/src/scenes/inbox/components/detail/PullRequestDiffView.tsx b/frontend/src/scenes/inbox/components/detail/PullRequestDiffView.tsx
index 37bbce84b840..655fad4beaf1 100644
--- a/frontend/src/scenes/inbox/components/detail/PullRequestDiffView.tsx
+++ b/frontend/src/scenes/inbox/components/detail/PullRequestDiffView.tsx
@@ -22,6 +22,33 @@ const CHANGE_META: Record<ChangeTypes, { label: string; icon: ReactNode; classNa
'rename-changed': { label: 'Renamed', icon: <IconArrowRight />, className: 'text-secondary' },
}
+export interface DiffSummary {
+ fileCount: number
+ additions: number
+ deletions: number
+}
+
+/** Aggregate file/line counts from a unified diff patch — shared by the diff toolbar and file headers. */
+export function summarizeDiff(diff: string, cacheKey?: string): DiffSummary | null {
+ if (!diff.trim()) {
+ return { fileCount: 0, additions: 0, deletions: 0 }
+ }
+ try {
+ const files = parsePatchFiles(diff, cacheKey).flatMap((patch) => patch.files)
+ let additions = 0
+ let deletions = 0
+ for (const file of files) {
+ for (const hunk of file.hunks) {
+ additions += hunk.additionLines
+ deletions += hunk.deletionLines
+ }
+ }
+ return { fileCount: files.length, additions, deletions }
+ } catch {
+ return null
+ }
+}
+
/** Our own file header (rendered into Pierre's light-DOM header slot): status icon + monospace path + counts. */
function FileDiffHeader({ file }: { file: FileDiffMetadata }): JSX.Element {
const meta = CHANGE_META[file.type] ?? { label: 'Changed', icon: <IconPencil />, className: 'text-secondary' }
diff --git a/frontend/src/scenes/inbox/components/detail/ReportDetail.tsx b/frontend/src/scenes/inbox/components/detail/ReportDetail.tsx
index 9d483b12b96f..21d371527f63 100644
--- a/frontend/src/scenes/inbox/components/detail/ReportDetail.tsx
+++ b/frontend/src/scenes/inbox/components/detail/ReportDetail.tsx
@@ -1,8 +1,8 @@
import { useValues } from 'kea'
-import { ReactNode } from 'react'
+import { ReactNode, useState } from 'react'
import { IconArrowLeft, IconDocument, IconEllipsis, IconExternal, IconPullRequest, IconSearch } from '@posthog/icons'
-import { LemonButton, Tooltip } from '@posthog/lemon-ui'
+import { LemonButton, LemonTabs, Tooltip } from '@posthog/lemon-ui'
import { TZLabel } from 'lib/components/TZLabel'
import { IconLink } from 'lib/lemon-ui/icons'
@@ -35,7 +35,7 @@ import {
import { ConventionalCommitScopeTag } from '../cards/ReportCard'
import { CommitContent } from './artefactTypes'
import { DetailSection } from './DetailSection'
-import { PullRequestDiffPanel } from './PullRequestDiffPanel'
+import { PullRequestBranchTag, PullRequestDiffPanel } from './PullRequestDiffPanel'
import { ReportActivitySection } from './ReportActivitySection'
import { ReportDetailAction, useReportDetailActions } from './ReportDetailActions'
import { ReportTasksSection } from './ReportTasksSection'
@@ -242,8 +242,10 @@ interface InboxDetailFrameProps {
summary: { icon: ReactNode; title: string }
/** Extra primary action(s) rendered after the shared report actions. */
primaryAction?: ReactNode
- /** Full-width section rendered below the two-column overview (the Graphite-style diff). */
+ /** Diff body. When present, the overview and this render behind two tabs (GitHub-style PR view). */
diffSection?: ReactNode
+ /** Branch tag shown in the "Files changed" tab label, so the tab signals there's code behind it. */
+ diffBranchTag?: ReactNode
/** Extra sections (Tasks, Reviewers) – defaults applied by callers. */
children?: ReactNode
}
@@ -260,11 +262,15 @@ export function InboxDetailFrame({
summary,
primaryAction,
diffSection,
+ diffBranchTag,
children,
}: InboxDetailFrameProps): JSX.Element {
const { reportSignals, reportSignalsLoading, priorityExplanation, actionabilityExplanation } = useValues(
inboxReportDetailLogic({ reportId: report.id, report })
)
+ // GitHub-style PR view: when a diff is present, the overview and the diff live behind two tabs.
+ const [activeDetailTab, setActiveDetailTab] = useState<'overview' | 'files'>('overview')
+ const hasDiff = !!diffSection
const signals = reportSignals ?? []
const evidenceCount = reportSignals !== null ? signals.length : report.signal_count
const hasEvidence = evidenceCount > 0
@@ -354,7 +360,8 @@ export function InboxDetailFrame({
return (
<div className="@container w-full max-w-[calc(160ch+5rem)] mx-auto px-6 py-5 text-sm">
- <div className="flex flex-col gap-3.5 mb-6 pb-5 border-b border-primary">
+ {/* With a diff present the tab bar owns the full-width divider, so the heading drops its own. */}
+ <div className={`flex flex-col gap-3.5 ${hasDiff ? 'mb-4' : 'mb-6 pb-5 border-b border-primary'}`}>
<LemonButton
type="tertiary"
size="small"
@@ -424,11 +431,27 @@ export function InboxDetailFrame({
</div>
</div>
- <div className="flex flex-col gap-8">
- {overviewBody}
- {/* Full-width diff below the overview, Graphite-style — always visible, not tabbed away. */}
- {diffSection}
- </div>
+ {hasDiff ? (
+ <LemonTabs
+ activeKey={activeDetailTab}
+ onChange={setActiveDetailTab}
+ tabs={[
+ { key: 'overview', label: 'Overview', content: overviewBody },
+ {
+ key: 'files',
+ label: (
+ <span className="flex items-center gap-1.5">
+ <span>Files changed</span>
+ {diffBranchTag}
+ </span>
+ ),
+ content: <>{diffSection}</>,
+ },
+ ]}
+ />
+ ) : (
+ overviewBody
+ )}
</div>
)
}
@@ -441,8 +464,8 @@ function prFilesUrl(prUrl: string): string {
/**
* Unified report detail for Pull requests / Reports / Not actionable. The "Open in GitHub" action
* surfaces only when the report has a shipped implementation PR; otherwise it reads as a plain
- * report. When the report has a "Commit pushed" artefact, a full-width "Files changed" section at the
- * bottom renders the branch's diff against the default branch. Runs keep their own `AgentRunDetail`.
+ * report. When the report has a "Commit pushed" artefact, a GitHub-style "Files changed" tab renders
+ * the branch's diff against the default branch alongside the overview. Runs keep their own `AgentRunDetail`.
*/
export function ReportDetail({ report, tab }: { report: SignalReport; tab: InboxTabKey }): JSX.Element {
const { latestCommitArtefact } = useValues(inboxReportDetailLogic({ reportId: report.id, report }))
@@ -480,6 +503,9 @@ export function ReportDetail({ report, tab }: { report: SignalReport; tab: Inbox
<PullRequestDiffPanel report={report} commit={commit} />
) : undefined
}
+ diffBranchTag={
+ canDiff && commit && latestCommitArtefact ? <PullRequestBranchTag commit={commit} /> : undefined
+ }
/>
)
}