The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): trim wrapper parens from raw URL autolinks
harjoth826e40c1b37c
diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.test.ts b/apps/desktop/src/components/assistant-ui/markdown-text.test.tsindex c2f1c6223c6..5914bb7a095 100644--- a/apps/desktop/src/components/assistant-ui/markdown-text.test.ts+++ b/apps/desktop/src/components/assistant-ui/markdown-text.test.ts@@ -94,6 +94,60 @@ describe('preprocessMarkdown', () => {expect(output).toContain('<https://www.getyourguide.com/culebra-island-l145468/from-fajardo-tour-t19894/>')})+ it('does not include wrapper closing parens in raw-url autolinks', () => {+ const output = preprocessMarkdown('Check (https://example.com/page)')++ expect(output).toContain('(<https://example.com/page>)')+ expect(output).not.toContain('<https://example.com/page)>')+ })++ it('strips wrapper closing parens from bare raw-url autolinks', () => {+ const output = preprocessMarkdown('(https://example.com/page)')++ expect(output).toBe('(<https://example.com/page>)')+ expect(output).not.toContain('<https://example.com/page)>')+ })++ it('strips multiple wrapper closing parens from raw-url autolinks', () => {+ const output = preprocessMarkdown('((https://example.com/page))')++ expect(output).toBe('((<https://example.com/page>))')+ expect(output).not.toContain('<https://example.com/page)>')+ expect(output).not.toContain('<https://example.com/page))>')+ })++ it('leaves raw URLs inside inline code spans unchanged', () => {+ const input = 'Keep `https://example.com/page)` literal.'+ const output = preprocessMarkdown(input)++ expect(output).toBe(input)+ })++ it('keeps trailing punctuation outside wrapper-paren raw-url autolinks', () => {+ expect(preprocessMarkdown('(https://example.com/page).')).toBe('(<https://example.com/page>).')+ expect(preprocessMarkdown('(https://example.com/page),')).toBe('(<https://example.com/page>),')+ })++ it('preserves balanced parens inside raw-url autolinks', () => {+ const output = preprocessMarkdown('See https://example.com/wiki/Foo_(bar)')++ expect(output).toContain('<https://example.com/wiki/Foo_(bar)>')+ })++ it('strips only the wrapper closing paren around balanced-paren URLs', () => {+ const output = preprocessMarkdown('(https://example.com/wiki/Foo_(bar))')++ expect(output).toBe('(<https://example.com/wiki/Foo_(bar)>)')+ expect(output).not.toContain('<https://example.com/wiki/Foo_(bar))>')+ })++ it('does not autolink canonical markdown links', () => {+ const input = '[link](https://github.com/NousResearch/hermes-agent/issues)'+ const output = preprocessMarkdown(input)++ expect(output).toBe(input)+ })+it('strips orphan numeric citation markers outside code spans', () => {const output = preprocessMarkdown('This is the source[0], but keep `items[0]` untouched.')diff --git a/apps/desktop/src/lib/markdown-preprocess.ts b/apps/desktop/src/lib/markdown-preprocess.tsindex 4d873f31388..3881446b1b5 100644--- a/apps/desktop/src/lib/markdown-preprocess.ts+++ b/apps/desktop/src/lib/markdown-preprocess.ts@@ -208,6 +208,31 @@ function isUrlOnlyBlock(lines: string[]): boolean {return nonEmpty.length > 0 && nonEmpty.every(line => URL_ONLY_LINE_RE.test(line))}+function trimUnbalancedTrailingParens(url: string): string {+ let result = url++ while (result.endsWith(')')) {+ let opens = 0+ let closes = 0++ for (const char of result) {+ if (char === '(') {+ opens += 1+ } else if (char === ')') {+ closes += 1+ }+ }++ if (closes <= opens) {+ break+ }++ result = result.slice(0, -1)+ }++ return result+}+function autoLinkRawUrls(text: string): string {return text.replace(RAW_URL_RE, (url: string, index: number) => {const previous = text[index - 1] || ''@@ -217,7 +242,9 @@ function autoLinkRawUrls(text: string): string {return url}- return `<${url}>`+ const trimmed = trimUnbalancedTrailingParens(url)++ return `<${trimmed}>${url.slice(trimmed.length)}`})}