The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): preserve quoted URL references in code copy
Denis H23d3eba43020
diff --git a/apps/desktop/src/components/assistant-ui/directive-text.tsx b/apps/desktop/src/components/assistant-ui/directive-text.tsxindex 87ce68841bb..1abbb64f518 100644--- a/apps/desktop/src/components/assistant-ui/directive-text.tsx+++ b/apps/desktop/src/components/assistant-ui/directive-text.tsx@@ -17,7 +17,7 @@ import { useSessionLinkTitle } from '@/lib/session-link-title'import { parseSessionRefValue, sessionRefFallbackLabel } from '@/lib/session-refs'import { cn } from '@/lib/utils'-import { referenceKind, referenceRe, referenceStyle, WIRE_REFERENCE_KINDS } from './reference-kinds'+import { referenceKind, referenceRe, referenceStyle, unwrapReferenceValue, WIRE_REFERENCE_KINDS } from './reference-kinds'const HERMES_REF_TYPES = WIRE_REFERENCE_KINDStype HermesRefType = (typeof HERMES_REF_TYPES)[number]@@ -147,22 +147,6 @@ const SLASH_SKILL_RE = /(?<=^|\s)\/([a-zA-Z][\w-]*)(?![\w-]*\/)/g// qualify: a plain-http/data markdown image is foreign input and stays text.const BLOB_MARKDOWN_IMAGE_RE = /!\[([^\]\n]{0,512})\]\((blob:[^)\s]{1,2048})\)/g-const TRAILING_PUNCTUATION_RE = /[,.;!?]+$/--function unwrapRefValue(raw: string): string {- if (raw.length < 2) {- return raw- }-- const head = raw[0]- const tail = raw[raw.length - 1]-- if ((head === '`' && tail === '`') || (head === '"' && tail === '"') || (head === "'" && tail === "'")) {- return raw.slice(1, -1)- }-- return raw.replace(TRAILING_PUNCTUATION_RE, '')-}function needsQuoting(value: string): boolean {return /[\s()[\]{}<>"'`]/.test(value)@@ -245,7 +229,7 @@ function parseDirectiveText(text: string): Unstable_DirectiveSegment[] {id: match[3] || match[2] || ''})),...Array.from(text.matchAll(HERMES_DIRECTIVE_RE)).map(match => {- const id = unwrapRefValue(match[2] || '')+ const id = unwrapReferenceValue(match[2] || '')return {start: match.index ?? 0,diff --git a/apps/desktop/src/components/assistant-ui/reference-kinds.ts b/apps/desktop/src/components/assistant-ui/reference-kinds.tsindex 3a5113f81de..1986fbcaf6b 100644--- a/apps/desktop/src/components/assistant-ui/reference-kinds.ts+++ b/apps/desktop/src/components/assistant-ui/reference-kinds.ts@@ -194,4 +194,18 @@ export function splitLeadingAttachmentRefs(text: string): { refs: string[]; text}return refs.length ? { refs, text: lines.join('\n').trim() } : { refs, text }+/** Remove optional wire-format quotes and terminal prose punctuation from a reference value. */+export function unwrapReferenceValue(raw: string): string {+ if (raw.length < 2) {+ return raw+ }++ const head = raw[0]+ const tail = raw[raw.length - 1]++ if ((head === '`' && tail === '`') || (head === '"' && tail === '"') || (head === "'" && tail === "'")) {+ return raw.slice(1, -1)+ }++ return raw.replace(/[,.;!?]+$/, '')}diff --git a/apps/desktop/src/components/chat/shiki-highlighter.test.ts b/apps/desktop/src/components/chat/shiki-highlighter.test.tsindex 9839d4ca1d9..5cbcff93470 100644--- a/apps/desktop/src/components/chat/shiki-highlighter.test.ts+++ b/apps/desktop/src/components/chat/shiki-highlighter.test.ts@@ -34,9 +34,19 @@ describe('chunkByLines', () => {describe('copyableCodeText', () => {- it('unwraps URL reference directives before copying a code block', () => {- expect(copyableCodeText('curl @url:https://example.com/image.png -o image.png')).toBe(+ it('unwraps quoted URL reference directives before copying a code block', () => {+ expect(copyableCodeText('curl @url:`https://example.com/image.png` -o image.png')).toBe('curl https://example.com/image.png -o image.png')})++ it('unwraps each supported URL quote style without changing other references', () => {+ expect(copyableCodeText(`first @url:'https://one.example'\nsecond @url:"https://two.example" @file:\`src/app.ts\``)).toBe(+ 'first https://one.example\nsecond https://two.example @file:`src/app.ts`'+ )+ })++ it('leaves text that is not a wire reference unchanged', () => {+ expect(copyableCodeText("const directive = '@url:'")).toBe("const directive = '@url:'")+ })})diff --git a/apps/desktop/src/components/chat/shiki-highlighter.tsx b/apps/desktop/src/components/chat/shiki-highlighter.tsxindex cbdb2ed55c7..28682ba159d 100644--- a/apps/desktop/src/components/chat/shiki-highlighter.tsx+++ b/apps/desktop/src/components/chat/shiki-highlighter.tsx@@ -3,6 +3,7 @@import type { SyntaxHighlighterProps } from '@assistant-ui/react-streamdown'import { type FC, lazy, Suspense, useMemo } from 'react'+import { referenceRe, unwrapReferenceValue } from '@/components/assistant-ui/reference-kinds'import { CodeCard, CodeCardBody } from '@/components/chat/code-card'import { ExpandableBlock } from '@/components/chat/expandable-block'// Theme constants live in shiki-config (dependency-free) so the lazy shiki@@ -125,9 +126,15 @@ const PlainCode: FC<{ code: string }> = ({ code }) => {)}-/** Convert URL references back to the literal URL for code-block clipboard text. */+const URL_REFERENCE_VALUE_RE = /^https?:\/\/\S+$/i++/** Convert URL references back to literal URLs for code-block clipboard text. */export function copyableCodeText(code: string): string {- return code.replaceAll('@url:', '')+ return code.replace(referenceRe(), (directive, kind: string, value: string) => {+ const url = unwrapReferenceValue(value)++ return kind === 'url' && URL_REFERENCE_VALUE_RE.test(url) ? url : directive+ })}export const SyntaxHighlighter: FC<HermesSyntaxHighlighterProps> = ({