The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a pasted PR-comment deep link lands as text like every other URL
DavidMetcalfe774b38651849
diff --git a/apps/desktop/src/app/chat/composer/attachments.tsx b/apps/desktop/src/app/chat/composer/attachments.tsxindex b87e69068ff..8cb08ba7b58 100644--- a/apps/desktop/src/app/chat/composer/attachments.tsx+++ b/apps/desktop/src/app/chat/composer/attachments.tsx@@ -8,7 +8,7 @@ import { Tip } from '@/components/ui/tooltip'import { useImageDownload } from '@/hooks/use-image-download'import { useI18n } from '@/i18n'import { readDesktopFileDataUrlLocalFirst } from '@/lib/desktop-fs'-import { AlertCircle, FileText, FolderOpen, ImageIcon, Link, Loader2, MessageCode, Terminal } from '@/lib/icons'+import { AlertCircle, FileText, FolderOpen, ImageIcon, Link, Loader2, Terminal } from '@/lib/icons'import { normalizeOrLocalPreviewTarget } from '@/lib/local-preview'import { cn } from '@/lib/utils'import type { ComposerAttachment } from '@/store/composer'@@ -43,7 +43,6 @@ function AttachmentPill({ attachment, onRemove }: { attachment: ComposerAttachmefile: FileText,folder: FolderOpen,image: ImageIcon,- review: MessageCode,terminal: Terminal,url: Link}[attachment.kind]@@ -54,15 +53,10 @@ function AttachmentPill({ attachment, onRemove }: { attachment: ComposerAttachmeconst isUploading = attachment.uploadState === 'uploading'const hasUploadError = attachment.uploadState === 'error'- // A review card's detail is its resolved-comment JSON, not a previewable- // path — clicking it should do nothing rather than toast a bogus failure.- const canPreview =- attachment.kind !== 'folder' && attachment.kind !== 'terminal' && attachment.kind !== 'review' && !isUploading+ const canPreview = attachment.kind !== 'folder' && attachment.kind !== 'terminal' && !isUploadingconst detail =- attachment.kind !== 'review' && attachment.detail && attachment.detail !== attachment.label- ? attachment.detail- : undefined+ attachment.detail && attachment.detail !== attachment.label ? attachment.detail : undefined// Keep full image bytes out of composer state. New chips read their path only// when clicked; previewUrl remains a compatibility fallback for older drafts.diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsxindex b5fd4776f36..e8ac092d6a5 100644--- a/apps/desktop/src/app/chat/composer/index.tsx+++ b/apps/desktop/src/app/chat/composer/index.tsx@@ -12,7 +12,6 @@ import { Button } from '@/components/ui/button'import { Slot as ContribSlot } from '@/contrib/react/slot'import { useI18n } from '@/i18n'import { chatMessageText } from '@/lib/chat-messages'-import { PR_COMMENT_URL_RE } from '@/lib/chat-runtime'import { sanitizeComposerInput } from '@/lib/composer-input-sanitize'import { DATA_IMAGE_URL_RE } from '@/lib/embedded-images'import { triggerHaptic } from '@/lib/haptics'@@ -113,7 +112,6 @@ export function ChatBar({onAddUrl,onAttachDroppedItems,onAttachImageBlob,- onAttachPrCommentUrl,onAttachPastedText,onPasteClipboardImage,onPickFiles,@@ -567,17 +565,6 @@ export function ChatBar({return}- // A pasted GitHub PR-comment deep link resolves to a structured review- // attachment (author, body, file:line anchor, diff hunk) instead of a bare- // `@url:` chip. Optimistic card first, resolve via gh in the background —- // if gh can't answer (offline, unauthenticated, foreign repo) the card- // swaps back to the plain URL ref so nothing is lost.- if (PR_COMMENT_URL_RE.test(pastedText) && onAttachPrCommentUrl?.(pastedText)) {- event.preventDefault()-- return- }-event.preventDefault()// Pasting exactly one link while composer text is selected turns that textdiff --git a/apps/desktop/src/app/chat/composer/paste-url-is-text.test.tsx b/apps/desktop/src/app/chat/composer/paste-url-is-text.test.tsxnew file mode 100644index 00000000000..e4afd31f940--- /dev/null+++ b/apps/desktop/src/app/chat/composer/paste-url-is-text.test.tsx@@ -0,0 +1,149 @@+// @vitest-environment jsdom+import { AssistantRuntimeProvider, useExternalStoreRuntime } from '@assistant-ui/react'+import type { ThreadMessageLike } from '@assistant-ui/react'+import { act, cleanup, fireEvent, render } from '@testing-library/react'+import { MemoryRouter } from 'react-router'+import { afterEach, describe, expect, it, vi } from 'vitest'++import { I18nProvider } from '@/i18n'+import { mainComposerScope } from '@/store/composer'++import { composerPlainText, RICH_INPUT_SLOT } from './rich-editor'+import type { ChatBarState } from './types'++import { ChatBar } from './index'++afterEach(cleanup)++// THE INVARIANT: a pasted URL is never swallowed.+//+// A GitHub PR-comment deep link (`…/pull/1#issuecomment-2`) used to be+// special-cased inside ChatBar's paste handler: it called+// `onAttachPrCommentUrl`, ran `event.preventDefault()`, and returned — so the+// clipboard payload never reached the editor (proven: with this harness the+// editor ends up EMPTY and the hook is called once) and the user saw only an+// attachment pill above the composer. Removing that interception is what makes+// the two URLs behave identically again.+//+// The handler is driven through the REAL ChatBar with a real paste event on the+// contentEditable, focused first (an unfocused ⌘V routes through paste-to-focus,+// which shares this insertion path). jsdom has no clipboard, so the event+// carries the fake DataTransfer shape the sibling paste-to-focus tests use.+//+// `onAttachPrCommentUrl` is spread in under a cast deliberately: the prop was+// deleted along with the interception, and passing it anyway is what proves the+// handler no longer consults it. On the pre-fix tree it is called once and the+// payload is dropped; here it must never be called and the URL must survive.+//+// Scope note: this asserts the URL lands as TEXT, not the `@url:` chip form.+// A lone pasted URL currently lands un-chipped because of a separate, older bug+// in `url-refs.ts` — `resolveExactLinkPaste` leaves the shared `URL_RE.lastIndex`+// past the first match, so the `linkifyUrls` call later in the same handler+// starts scanning after the URL and finds nothing (visible in prose pastes too:+// of two links, only the second chips). That defect is tracked separately; it is+// not this change's to fix, and asserting the chip here would fail for a reason+// that has nothing to do with the interception.+const PR_COMMENT_URL = 'https://github.com/o/r/pull/1#issuecomment-2'++const state: ChatBarState = {+ model: { canSwitch: false, model: '', provider: '' },+ tools: { enabled: false, label: '' },+ voice: { enabled: false, active: false }+}++function Harness({ onAttachPrCommentUrl }: { onAttachPrCommentUrl: (url: string) => boolean }) {+ // The adapter's message generic infers to `never` from an empty array, so the+ // empty store is typed explicitly. The runtime itself is only here to satisfy+ // ChatBar's provider; nothing in this test reads it.+ const runtime = useExternalStoreRuntime({+ convertMessage: (message: ThreadMessageLike) => message,+ isRunning: false,+ messages: [] as ThreadMessageLike[],+ onNew: async () => {}+ })++ return (+ <AssistantRuntimeProvider runtime={runtime}>+ <MemoryRouter>+ <I18nProvider configClient={null} initialLocale="en">+ <ChatBar+ busy={false}+ disabled={false}+ gateway={null}+ onCancel={vi.fn()}+ onSubmit={vi.fn(async () => true)}+ state={state}+ {...({ onAttachPrCommentUrl } as Record<string, unknown>)}+ />+ </I18nProvider>+ </MemoryRouter>+ </AssistantRuntimeProvider>+ )+}++/** Focus `editor` and fire the paste event a ⌘V into the composer produces. */+function pasteInto(editor: HTMLElement, text: string) {+ // jsdom does not implement isContentEditable, so the app's window-level paste+ // router would treat this target as page chrome and insert through the+ // composer bus instead of the editor's own handler. Pin it.+ Object.defineProperty(editor, 'isContentEditable', { configurable: true, value: true })+ editor.focus()++ const event = new Event('paste', { bubbles: true, cancelable: true }) as ClipboardEvent++ Object.defineProperty(event, 'clipboardData', {+ value: {+ getData: (type: string) => (type === 'text' || type === 'text/plain' ? text : ''),+ files: [],+ items: []+ }+ })++ act(() => {+ fireEvent(editor, event)+ })++ return event+}++describe('a pasted URL survives the paste', () => {+ afterEach(() => {+ mainComposerScope.clear()+ })++ it('keeps a GitHub PR-comment deep link in the composer and attaches nothing', () => {+ const onAttachPrCommentUrl = vi.fn(() => true)++ const { container } = render(<Harness onAttachPrCommentUrl={onAttachPrCommentUrl} />)++ const editor = container.querySelector<HTMLElement>(`[data-slot="${RICH_INPUT_SLOT}"]`)!++ const event = pasteInto(editor, PR_COMMENT_URL)++ // The payload reached the editor instead of being consumed by the handler…+ expect(composerPlainText(editor)).toContain(PR_COMMENT_URL)+ // …nothing was attached above the composer…+ expect(mainComposerScope.$attachments.get()).toEqual([])+ // …and the interception hook was never consulted.+ expect(onAttachPrCommentUrl).not.toHaveBeenCalled()+ expect(event.defaultPrevented).toBe(true)+ })++ it('treats it exactly like a plain URL paste — same insertion, no attachment', () => {+ const onAttachPrCommentUrl = vi.fn(() => true)+ const plain = render(<Harness onAttachPrCommentUrl={onAttachPrCommentUrl} />)+ const deep = render(<Harness onAttachPrCommentUrl={onAttachPrCommentUrl} />)++ const plainEditor = plain.container.querySelector<HTMLElement>(`[data-slot="${RICH_INPUT_SLOT}"]`)!+ const deepEditor = deep.container.querySelector<HTMLElement>(`[data-slot="${RICH_INPUT_SLOT}"]`)!++ pasteInto(plainEditor, 'https://github.com/o/r/pull/1')+ pasteInto(deepEditor, PR_COMMENT_URL)++ // Same shape of result for both URLs: the text is present, nothing is attached.+ expect(composerPlainText(plainEditor)).toContain('https://github.com/o/r/pull/1')+ expect(composerPlainText(deepEditor)).toContain(PR_COMMENT_URL)+ expect(mainComposerScope.$attachments.get()).toEqual([])+ expect(onAttachPrCommentUrl).not.toHaveBeenCalled()+ })+})diff --git a/apps/desktop/src/app/chat/composer/types.ts b/apps/desktop/src/app/chat/composer/types.tsindex c43c6b460bf..00cb67d91c9 100644--- a/apps/desktop/src/app/chat/composer/types.ts+++ b/apps/desktop/src/app/chat/composer/types.ts@@ -51,9 +51,6 @@ export interface ChatBarProps {onAddUrl?: (url: string) => voidonAttachImageBlob?: (blob: Blob, isCurrent?: () => boolean) => Promise<boolean | void> | boolean | voidonAttachDroppedItems?: (candidates: DroppedFile[]) => Promise<boolean | void> | boolean | void- /** Pasted GitHub PR-comment deep link → structured review attachment.- * Returns true when the paste was consumed as an attachment. */- onAttachPrCommentUrl?: (url: string) => booleanonAttachPastedText?: (text: string) => Promise<boolean> | booleanonPasteClipboardImage?: (opts?: { silent?: boolean }) => Promise<boolean> | voidonPickFiles?: () => voiddiff --git a/apps/desktop/src/app/chat/hooks/use-composer-actions.ts b/apps/desktop/src/app/chat/hooks/use-composer-actions.tsindex fb5ac54263c..7706a47b545 100644--- a/apps/desktop/src/app/chat/hooks/use-composer-actions.ts+++ b/apps/desktop/src/app/chat/hooks/use-composer-actions.ts@@ -7,7 +7,6 @@ import { formatRefValue } from '@/components/assistant-ui/directive-text'import { useI18n } from '@/i18n'import { attachmentId, contextPath, pathLabel } from '@/lib/chat-runtime'import { readDesktopFileDataUrlLocalFirst, selectDesktopPaths } from '@/lib/desktop-fs'-import { desktopGit } from '@/lib/desktop-git'import { downscaleDataUrlForPreview } from '@/lib/image-resize'import { normalize } from '@/lib/text'import {@@ -395,51 +394,6 @@ export function useComposerActions({[attachToMain])- // A pasted GitHub PR-comment deep link → structured `review` attachment.- // Optimistic: the card lands immediately with the URL as its ref, then the- // background gh resolve fills in author/anchor (label + detail). If gh can't- // answer — offline, unauthenticated, foreign repo, remote gateway — the card- // downgrades to a plain `url` attachment so the paste is never lost.- const attachPrCommentUrl = useCallback(- (url: string): boolean => {- const id = attachmentId('review', url)- const refText = `@url:${formatRefValue(url)}`-- attachToMain({- id,- kind: 'review',- label: url.replace(/^https:\/\/github\.com\//, '').replace(/#.*$/, ''),- refText,- uploadState: 'uploading'- })-- void (async () => {- const comment = currentCwd- ? await (desktopGit()- ?.review.fetchPrComment(currentCwd, url)- .catch(() => null) ?? null)- : null-- if (comment) {- scope.update({- id,- kind: 'review',- label: comment.path- ? `${pathLabel(comment.path)}${comment.line ? `:${comment.line}` : ''} — @${comment.author}`- : `PR #${comment.prNumber} — @${comment.author}`,- detail: JSON.stringify(comment),- refText- })- } else {- scope.update({ id, kind: 'url', label: pathLabel(url), refText })- }- })()-- return true- },- [attachToMain, currentCwd, scope]- )-const pickContextPaths = useCallback(async (kind: 'file' | 'folder') => {const paths = await selectDesktopPaths({@@ -825,7 +779,6 @@ export function useComposerActions({attachDroppedItems,attachImageBlob,attachImagePath,- attachPrCommentUrl,attachPastedText,insertContextPathInlineRef,pasteClipboardImage,diff --git a/apps/desktop/src/app/chat/index.tsx b/apps/desktop/src/app/chat/index.tsxindex 768537b82e1..d65bc27c861 100644--- a/apps/desktop/src/app/chat/index.tsx+++ b/apps/desktop/src/app/chat/index.tsx@@ -98,7 +98,6 @@ interface ChatViewProps extends Omit<React.ComponentProps<'div'>, 'onSubmit'> {maxVoiceRecordingSeconds?: numberonAttachImageBlob: (blob: Blob, isCurrent?: () => boolean) => Promise<boolean | void> | boolean | voidonAttachDroppedItems: (candidates: DroppedFile[]) => Promise<boolean | void> | boolean | void- onAttachPrCommentUrl?: (url: string) => booleanonAttachPastedText?: (text: string) => Promise<boolean> | booleanonPasteClipboardImage: (opts?: { silent?: boolean }) => Promise<boolean> | voidonPickFiles: () => void@@ -432,7 +431,6 @@ const ChatViewContent = memo(function ChatViewContent({onAddUrl,onAttachImageBlob,onAttachDroppedItems,- onAttachPrCommentUrl,onAttachPastedText,onBranchInNewChat,maxVoiceRecordingSeconds,@@ -826,7 +824,6 @@ const ChatViewContent = memo(function ChatViewContent({onAttachDroppedItems={onAttachDroppedItems}onAttachImageBlob={onAttachImageBlob}onAttachPastedText={onAttachPastedText}- onAttachPrCommentUrl={onAttachPrCommentUrl}onCancel={onCancel}onPasteClipboardImage={onPasteClipboardImage}onPickFiles={onPickFiles}diff --git a/apps/desktop/src/app/chat/session-tile.tsx b/apps/desktop/src/app/chat/session-tile.tsxindex 7a7822d64eb..c1b7836b348 100644--- a/apps/desktop/src/app/chat/session-tile.tsx+++ b/apps/desktop/src/app/chat/session-tile.tsx@@ -330,7 +330,6 @@ function TileChat({onAttachDroppedItems={composer.attachDroppedItems}onAttachImageBlob={composer.attachImageBlob}onAttachPastedText={composer.attachPastedText}- onAttachPrCommentUrl={composer.attachPrCommentUrl}onCancel={actions.cancelRun}onDeleteSelectedSession={noop}onDismissError={actions.dismissError}diff --git a/apps/desktop/src/app/contrib/latest-actions.test.ts b/apps/desktop/src/app/contrib/latest-actions.test.tsindex 57756bce20c..d3f020c2689 100644--- a/apps/desktop/src/app/contrib/latest-actions.test.ts+++ b/apps/desktop/src/app/contrib/latest-actions.test.ts@@ -12,7 +12,6 @@ function makeChatActions(): ChatActions {onAttachDroppedItems: vi.fn(),onAttachImageBlob: vi.fn(),onAttachPastedText: vi.fn(),- onAttachPrCommentUrl: vi.fn(),onBranchInNewChat: vi.fn(),onCancel: vi.fn(),onDeleteSelectedSession: vi.fn(),diff --git a/apps/desktop/src/app/contrib/latest-actions.ts b/apps/desktop/src/app/contrib/latest-actions.tsindex 433c6411d36..4648ea28afb 100644--- a/apps/desktop/src/app/contrib/latest-actions.ts+++ b/apps/desktop/src/app/contrib/latest-actions.ts@@ -35,7 +35,6 @@ export function latestChatActions(actions: ChatActions): ChatActions {onAttachDroppedItems: (...args) => actions.onAttachDroppedItems(...args),onAttachImageBlob: (...args) => actions.onAttachImageBlob(...args),onAttachPastedText: latestOptional(() => actions.onAttachPastedText),- onAttachPrCommentUrl: latestOptional(() => actions.onAttachPrCommentUrl),onBranchInNewChat: latestOptional(() => actions.onBranchInNewChat),onCancel: (...args) => actions.onCancel(...args),onDeleteSelectedSession: (...args) => actions.onDeleteSelectedSession(...args),diff --git a/apps/desktop/src/app/contrib/types.ts b/apps/desktop/src/app/contrib/types.tsindex ddf66a4c429..46fab0c7c1b 100644--- a/apps/desktop/src/app/contrib/types.ts+++ b/apps/desktop/src/app/contrib/types.ts@@ -31,7 +31,6 @@ export type ChatActions = Pick<| 'onAddUrl'| 'onAttachDroppedItems'| 'onAttachImageBlob'- | 'onAttachPrCommentUrl'| 'onAttachPastedText'| 'onBranchInNewChat'| 'onCancel'diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsxindex dd315eddf65..f576b0368f0 100644--- a/apps/desktop/src/app/contrib/wiring.tsx+++ b/apps/desktop/src/app/contrib/wiring.tsx@@ -1122,7 +1122,6 @@ export function ContribWiring({ children }: { children: ReactNode }) {onArchiveSession: sessionId => void archiveSession(sessionId),onAttachDroppedItems: composer.attachDroppedItems,onAttachImageBlob: composer.attachImageBlob,- onAttachPrCommentUrl: composer.attachPrCommentUrl,onAttachPastedText: composer.attachPastedText,onBranchInNewChat: messageId => void branchInNewChat(messageId),onBranchSession: sessionId => void branchStoredSession(sessionId),diff --git a/apps/desktop/src/lib/chat-runtime.test.ts b/apps/desktop/src/lib/chat-runtime.test.tsindex 2a8c9bc7962..50dc9ffc7d0 100644--- a/apps/desktop/src/lib/chat-runtime.test.ts+++ b/apps/desktop/src/lib/chat-runtime.test.ts@@ -82,34 +82,6 @@ describe('attachmentDisplayText', () => {it('still resolves a normal file ref', () => {expect(attachmentDisplayText(attachment({ kind: 'file', refText: '@file:src/a.ts' }))).toBe('@file:src/a.ts')})-- it('expands a review attachment into an anchored fenced block', () => {- const detail = JSON.stringify({- author: 'teknium1',- body: 'this cap looks wrong',- diffHunk: '@@ -1,2 +1,2 @@\n-const CAP = 5\n+const CAP = 50',- kind: 'review',- line: 12,- path: 'src/limits.ts',- prNumber: 123,- startLine: null,- url: 'https://github.com/o/r/pull/123#discussion_r1'- })-- const block = attachmentDisplayText(attachment({ kind: 'review', detail, refText: '@url:`https://x`' }))-- // The contract: anchor (file:line), author, body, and the hunk all ride.- expect(block).toContain('review-comment src/limits.ts:12')- expect(block).toContain('@teknium1')- expect(block).toContain('this cap looks wrong')- expect(block).toContain('const CAP = 50')- })-- it('falls back to the url ref when a review detail is malformed', () => {- expect(attachmentDisplayText(attachment({ kind: 'review', detail: 'not json', refText: '@url:`https://x`' }))).toBe(- '@url:`https://x`'- )- })})describe('coerceThinkingText', () => {diff --git a/apps/desktop/src/lib/chat-runtime.ts b/apps/desktop/src/lib/chat-runtime.tsindex 350af6eceb2..50e00fa2a18 100644--- a/apps/desktop/src/lib/chat-runtime.ts+++ b/apps/desktop/src/lib/chat-runtime.ts@@ -173,31 +173,6 @@ export function attachmentId(kind: ComposerAttachment['kind'], value: string): sreturn `${kind}:${normalizeAttachmentValue(kind, value)}`}-/** A GitHub PR review-thread (`#discussion_r<id>`) or conversation- * (`#issuecomment-<id>`) deep link — the one paste shape that can resolve to- * a structured review attachment instead of a plain `@url:` chip. */-export const PR_COMMENT_URL_RE =- /^https:\/\/github\.com\/[^/\s]+\/[^/\s]+\/pull\/\d+(?:\/[^#\s]*)?#(?:discussion_r|issuecomment-)\d+$/--/** The send-time expansion of a `review` attachment. `detail` holds the- * resolved comment as JSON (HermesPrComment shape); a malformed payload falls- * back to the attachment's URL ref so the send never throws. */-export function reviewCommentBlock(detail: string): null | string {- try {- const c = JSON.parse(detail)-- const anchor = c.path- ? `${c.path}${c.line ? `:${c.startLine && c.startLine !== c.line ? `${c.startLine}-` : ''}${c.line}` : ''}`- : `PR #${c.prNumber}`-- const hunk = c.diffHunk ? `\n--- diff hunk ---\n${String(c.diffHunk).trim()}` : ''-- return `\`\`\`review-comment ${anchor}\n@${c.author} on ${c.url}\n\n${String(c.body).trim()}${hunk}\n\`\`\``- } catch {- return null- }-}-export function pathLabel(path: string): string {return path.split(/[\\/]/).filter(Boolean).pop() || path}@@ -214,18 +189,6 @@ export function attachmentDisplayText(attachment: ComposerAttachment): string |return `\`\`\`terminal\n${attachment.detail.trim()}\n\`\`\``}- // A resolved PR review comment: expand to a fenced block carrying the- // anchor (file:line), author, body, and — when present — the diff hunk the- // comment sits on, so "address this" needs no re-explaining what "this" is.- // A malformed payload falls through to the refText (the pasted URL).- if (attachment.kind === 'review' && attachment.detail) {- const block = reviewCommentBlock(attachment.detail)-- if (block) {- return block- }- }-if (attachment.refText) {return attachment.refText}diff --git a/apps/desktop/src/store/composer.ts b/apps/desktop/src/store/composer.tsindex 81cb6e51293..40519d4a562 100644--- a/apps/desktop/src/store/composer.ts+++ b/apps/desktop/src/store/composer.ts@@ -9,7 +9,7 @@ export interface ComposerAttachment {* which is content/path-derived, this survives draft cloning but changes* when the user removes and re-adds the same attachment. */occurrenceId?: string- kind: 'file' | 'folder' | 'image' | 'review' | 'terminal' | 'url'+ kind: 'file' | 'folder' | 'image' | 'terminal' | 'url'label: stringdetail?: stringrefText?: string