: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): keep file references in copied chat text (#96274)
Charles Vien5f6f41d2b7fd
diff --git a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsx b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsxindex 5f74b8c62ed0..3d15ad83c251 100644--- a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsx+++ b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsx@@ -53,19 +53,27 @@ export const GithubRefChipLink = forwardRef<}{...buttonProps}className={cn(- "cli-file-mention focus-visible:-outline-offset-1 mx-0.5 max-w-full cursor-pointer! whitespace-nowrap pl-1.5 align-baseline no-underline",+ "cli-file-mention focus-visible:-outline-offset-1 mx-0.5 inline-block max-w-full cursor-pointer! select-text whitespace-nowrap pl-1.5 align-baseline leading-[1.375rem] no-underline",buttonProps.className,)}><RefIconsize={12}weight="bold"- className={cn("shrink-0", toneClass)}+ className={cn("mr-1 inline-block align-[-0.125em]", toneClass)}aria-label={iconLabel}aria-hidden={iconLabel ? undefined : true}role={iconLabel ? "img" : undefined}/>- <span className={cn("min-w-0 max-w-64 truncate", toneClass)}>+ <span+ // 1rem is the icon and its margin, which share the chip's content box+ // with the label. Without that subtraction the label paints past the+ // chip edge in a narrow panel instead of truncating.+ className={cn(+ "inline-block max-w-[min(16rem,calc(100%-1rem))] truncate align-top",+ toneClass,+ )}+ >{children}</span></Button>diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsxindex 224947a36a45..f738497274eb 100644--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsx@@ -59,6 +59,11 @@ vi.mock("@posthog/ui/features/pr-review/usePrChecks", () => ({usePrChecks: () => ({ data: [], isLoading: false }),}));+vi.mock("@posthog/ui/features/sidebar/useCwd", () => ({+ useCwd: () => "/repo",+}));++import { SessionTaskIdProvider } from "@posthog/ui/features/sessions/useSessionTaskId";import { ChatMarkdown, ChatStreamingMarkdown } from "./ChatMarkdown";const MERMAID_FENCE = "```mermaid\ngraph TD; A-->B\n```";@@ -191,3 +196,16 @@ describe("ChatStreamingMarkdown", () => {expect(html).toContain("the report");});});++describe("ChatMarkdown file links", () => {+ it("shows the filename but carries the whole path in its text", () => {+ render(+ <SessionTaskIdProvider taskId="task-1">+ <ChatMarkdown content="See `src/utils/helpers.ts:12` for the fix." />+ </SessionTaskIdProvider>,+ );++ const link = screen.getByText("helpers.ts:12");+ expect(link).toHaveTextContent("src/utils/helpers.ts:12");+ });+});diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/fileLinkChips.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/fileLinkChips.tsxindex f390ab61286d..71e517700c20 100644--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/fileLinkChips.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/fileLinkChips.tsx@@ -42,6 +42,7 @@ export function InlineFileLink({const { filePath: rawPath, lineSuffix } = parseFilePath(text);const filePath = resolvedPath ?? rawPath;const filename = rawPath.split("/").pop() ?? rawPath;+ const directory = rawPath.slice(0, rawPath.length - filename.length);const taskId = useSessionTaskId();const repoPath = useCwd(taskId ?? "");const openFileInSplit = usePanelLayoutStore((s) => s.openFileInSplit);@@ -73,6 +74,7 @@ export function InlineFileLink({disabled={!taskId}className={`m-0 inline border-0 bg-transparent p-0 font-[inherit] text-[length:inherit] text-foreground ${taskId ? "cursor-pointer underline underline-offset-2" : ""}`}>+ {directory && <span className="sr-only">{directory}</span>}{filename}{lineSuffix ? `:${lineSuffix}` : ""}</button>diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/parseFileMentions.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/parseFileMentions.test.tsxnew file mode 100644index 000000000000..01b59d805942--- /dev/null+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/parseFileMentions.test.tsx@@ -0,0 +1,29 @@+import { render } from "@testing-library/react";+import { describe, expect, it } from "vitest";+import { parseFileMentions } from "./parseFileMentions";++describe("parseFileMentions", () => {+ it.each([+ [+ "between words",+ 'Look at <file path="src/a.ts" /> now',+ "Look at src/a.ts now",+ ],+ ["at the start", '<file path="src/a.ts" /> is wrong', "src/a.ts is wrong"],+ ["at the end", 'Open <file path="src/a.ts" />', "Open src/a.ts"],+ ["without spaces", 'See (<file path="src/a.ts" />)', "See (src/a.ts)"],+ [+ "between two mentions",+ '<file path="src/a.ts" /> <file path="src/b.ts" />',+ "src/a.ts src/b.ts",+ ],+ [+ "after a slash command",+ '/review <file path="src/a.ts" /> please',+ "/review src/a.ts please",+ ],+ ])("keeps the spacing around a mention %s", (_case, content, text) => {+ const { container } = render(<div>{parseFileMentions(content)}</div>);+ expect(container.textContent).toBe(text);+ });+});diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/parseFileMentions.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/parseFileMentions.tsxindex a32c82b70696..4704b80985a1 100644--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/parseFileMentions.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/parseFileMentions.tsx@@ -49,7 +49,7 @@ function hasMentionTags(content: string): boolean {export const hasFileMentions = hasMentionTags;const chipClass =- "inline-flex min-w-0 max-w-full items-center gap-1 rounded-[var(--radius-1)] bg-[var(--accent-a3)] px-1 py-px align-middle font-medium text-[var(--accent-11)]";+ "inline-block max-w-full truncate rounded-[var(--radius-1)] bg-[var(--accent-a3)] px-1 py-px align-middle font-medium text-[var(--accent-11)]";export function MentionChip({icon,@@ -66,8 +66,10 @@ export function MentionChip({const content = (<>- {icon}- <span className="truncate">{label}</span>+ {icon && (+ <span className="mr-1 inline-block align-[-0.125em]">{icon}</span>+ )}+ {label}</>);@@ -105,6 +107,16 @@ function parseMentionTags(content: string): ReactNode[] {const parts: ReactNode[] = [];let lastIndex = 0;+ const pushText = (text: string, chipFollows: boolean): void => {+ if (!text.trim()) {+ if (parts.length > 0) parts.push(" ");+ return;+ }+ if (parts.length > 0 && /^\s/.test(text)) parts.push(" ");+ parts.push(<InlineMarkdown key={`text-${lastIndex}`} content={text} />);+ if (chipFollows && /\s$/.test(text)) parts.push(" ");+ };+const slashMatch = content.match(SLASH_COMMAND_START);if (slashMatch) {parts.push(@@ -118,12 +130,7 @@ function parseMentionTags(content: string): ReactNode[] {if (matchIndex < lastIndex) continue;if (matchIndex > lastIndex) {- parts.push(- <InlineMarkdown- key={`text-${lastIndex}`}- content={content.slice(lastIndex, matchIndex)}- />,- );+ pushText(content.slice(lastIndex, matchIndex), true);}if (match[1]) {@@ -181,12 +188,7 @@ function parseMentionTags(content: string): ReactNode[] {}if (lastIndex < content.length) {- parts.push(- <InlineMarkdown- key={`text-${lastIndex}`}- content={content.slice(lastIndex)}- />,- );+ pushText(content.slice(lastIndex), false);}return parts;diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/parseFileMentions.test.ts b/products/desktop/packages/ui/src/features/sessions/components/session-update/piSkillInvocation.test.tssimilarity index 100%rename from products/desktop/packages/ui/src/features/sessions/components/session-update/parseFileMentions.test.tsrename to products/desktop/packages/ui/src/features/sessions/components/session-update/piSkillInvocation.test.tsdiff --git a/products/desktop/packages/ui/src/primitives/ArtifactChip.tsx b/products/desktop/packages/ui/src/primitives/ArtifactChip.tsxindex 6637cdec4d2d..64689a750b11 100644--- a/products/desktop/packages/ui/src/primitives/ArtifactChip.tsx+++ b/products/desktop/packages/ui/src/primitives/ArtifactChip.tsx@@ -41,23 +41,27 @@ export function ArtifactChip({data-orientation="horizontal"className={cn(buttonGroupVariants(),- "mx-0.5 inline-flex max-w-full align-middle",+ "mx-0.5 inline-block max-w-full whitespace-nowrap align-middle",)}><ButtononClick={onOpen}disabled={disabled || !onOpen}aria-label={name ? `Open ${name}` : undefined}- // Quill's base button is `shrink-0`; restore shrinking so a long name- // truncates inside a narrow message or activity row instead of pushing- // the download half out of reach.- className="min-w-0 shrink"+ className={cn(+ "inline-block select-text truncate align-top leading-[1.375rem]",+ onDownload ? "max-w-[calc(100%-1.5rem)]" : "max-w-full",+ )}variant="outline"size="sm">- {typeof name === "string" && <FileIcon filename={name} size={12} />}- <span className="min-w-0 truncate">{label}</span>- {meta && <span className="shrink-0 text-muted-foreground">{meta}</span>}+ {typeof name === "string" && (+ <span className="mr-1 inline-block align-[-0.125em]">+ <FileIcon filename={name} size={12} />+ </span>+ )}+ {label}+ {meta && <span className="text-muted-foreground"> {meta}</span>}</Button>{onDownload && (<Tooltip content={downloading ? "Downloading…" : "Download"}>@@ -67,6 +71,7 @@ export function ArtifactChip({onClick={onDownload}disabled={downloading}aria-label={name ? `Download ${name}` : "Download"}+ className="align-top"><DownloadSimpleIcon size={12} /></Button>