diff --git a/desktop/src/components/chat/AssistantMessage.linkrouting.test.tsx b/desktop/src/components/chat/AssistantMessage.linkrouting.test.tsx index 93d2c808..a192775f 100644 --- a/desktop/src/components/chat/AssistantMessage.linkrouting.test.tsx +++ b/desktop/src/components/chat/AssistantMessage.linkrouting.test.tsx @@ -80,6 +80,24 @@ describe('AssistantMessage output-target cards', () => { expect(screen.getByText('assistantOutputs.kind.localhost')).toBeInTheDocument() }) + it('does NOT render a localhost card for URLs shown inside a log code block', () => { + render( + , + ) + + expect(screen.queryByText('assistantOutputs.kind.localhost')).toBeNull() + }) + it('renders a card for a markdown link with its Markdown badge', () => { render( { ]) }) + it('ignores localhost URLs printed inside fenced log output', () => { + const targets = extractAssistantOutputTargets( + [ + '日志前 50 行:', + '```log', + '[08:29:36][INFO] 代理服务已启动: 127.0.0.1:15721', + '[08:29:36][INFO] Claude Live 配置已接管,代理地址: http://127.0.0.1:15721', + '```', + ].join('\n'), + { workDir }, + ) + + expect(targets).toEqual([]) + }) + + it('ignores markdown links printed inside fenced code blocks', () => { + const targets = extractAssistantOutputTargets( + ['```md', '调试输出: [preview](http://localhost:5173/) [page](index.html)', '```'].join('\n'), + { workDir }, + ) + + expect(targets).toEqual([]) + }) + it('keeps markdown localhost links as markdown-link targets with authored labels', () => { const targets = extractAssistantOutputTargets( '[Preview](http://localhost:4173) then http://localhost:4173', diff --git a/desktop/src/lib/assistantOutputTargets.ts b/desktop/src/lib/assistantOutputTargets.ts index 30fd4754..7ac3d578 100644 --- a/desktop/src/lib/assistantOutputTargets.ts +++ b/desktop/src/lib/assistantOutputTargets.ts @@ -105,6 +105,10 @@ export function extractAssistantOutputTargets( const localhostTarget = toLocalhostTarget(href) const fileTarget = toWorkspaceFileTarget(href, workDir) + if (isInCodeBlock(match.start, codeBlocks)) { + continue + } + if (!title) { continue } @@ -144,6 +148,10 @@ export function extractAssistantOutputTargets( continue } + if (isInCodeBlock(position, codeBlocks)) { + continue + } + const href = trimTrailingPunctuation(match[0] ?? '') if (!href) {