Commit 8e23278c7 for llama.cpp
commit 8e23278c7c36f4429fb237467d50e2935a91e655
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date: Fri Nov 27 20:28:53 2026 +0100
ui: show only the mention label in generated conversation titles (#33205)
An `@`-mention is sent to the model as a `[name](file:///abs/path)` link, so
a title derived from the first user message inherited the whole link and the
path crowded out the words. Collapse every mention to the text inside its
square brackets when the title comes from the message itself, which covers
both the non-LLM setting and the fallback used when LLM output is unusable.
The LLM prompt still sees the full link, so the model keeps the path.
diff --git a/ui/apps/chat/src/lib/stores/chat/index.svelte.ts b/ui/apps/chat/src/lib/stores/chat/index.svelte.ts
index 0f30d75b9..dfbdadd06 100644
--- a/ui/apps/chat/src/lib/stores/chat/index.svelte.ts
+++ b/ui/apps/chat/src/lib/stores/chat/index.svelte.ts
@@ -55,6 +55,7 @@ import {
filterByLeafNodeId,
findMessageById,
formatCwdMessage,
+ generateConversationTitle,
getConversationModel,
isAbortError,
normalizeModelName,
@@ -1484,9 +1485,10 @@ class ChatStore implements ChatStreamHost, ChatFlowsHost {
.trim();
if (!cleanTitle || cleanTitle.length < TITLE_GENERATION.MIN_LENGTH) {
- const firstLine = userContent.split('\n').find((l) => l.trim().length > 0);
+ // the fallback title is the user's own text, so `@`-mentions collapse there too
+ const firstLine = generateConversationTitle(userContent, true);
- cleanTitle = firstLine ? firstLine.trim() : TITLE_GENERATION.FALLBACK;
+ cleanTitle = firstLine || TITLE_GENERATION.FALLBACK;
}
if (cleanTitle && cleanTitle.length >= TITLE_GENERATION.MIN_LENGTH) {
diff --git a/ui/apps/chat/src/lib/utils/index.ts b/ui/apps/chat/src/lib/utils/index.ts
index 2229262d3..f4e17836d 100644
--- a/ui/apps/chat/src/lib/utils/index.ts
+++ b/ui/apps/chat/src/lib/utils/index.ts
@@ -295,6 +295,7 @@ export {
getMentionBadgeIconPaths,
getMentionBadgeLabel,
splitMentionSegments,
+ stripMentionLinks,
buildMentionInsertion
} from './mention-badge';
diff --git a/ui/apps/chat/src/lib/utils/mention-badge.ts b/ui/apps/chat/src/lib/utils/mention-badge.ts
index ee72bf1a9..4a7d913ec 100644
--- a/ui/apps/chat/src/lib/utils/mention-badge.ts
+++ b/ui/apps/chat/src/lib/utils/mention-badge.ts
@@ -85,6 +85,15 @@ export function splitMentionSegments(value: string): MentionTextSegment[] {
return segments;
}
+/**
+ * Collapse every `[name](file://path)` mention to its `name`, dropping the
+ * path. Used where a mention must read as plain text (a conversation title)
+ * rather than render as a badge.
+ */
+export function stripMentionLinks(value: string): string {
+ return value.replace(fileMentionLinkRe(MENTION_LINK_SCAN_FLAGS), (_match, name: string) => name);
+}
+
export function getMentionBadgeIconPaths(path: string): readonly string[] {
return path.endsWith(DIRECTORY_PATH_SUFFIX)
? MENTION_BADGE_FOLDER_ICON_PATHS
diff --git a/ui/apps/chat/src/lib/utils/text.ts b/ui/apps/chat/src/lib/utils/text.ts
index 2b7c7723f..f6523266b 100644
--- a/ui/apps/chat/src/lib/utils/text.ts
+++ b/ui/apps/chat/src/lib/utils/text.ts
@@ -1,3 +1,4 @@
+import { stripMentionLinks } from './mention-badge';
import { NEWLINE } from '#lib/constants/index.ts';
/**
@@ -11,13 +12,18 @@ export function getPreviewText(content: string, max = 150): string {
/**
* Generates a single-line title from a potentially multi-line prompt.
* Uses the first non-empty line if `useFirstLine` is true.
+ *
+ * `@`-mentions travel as `[name](file://path)` links, which would otherwise
+ * dominate a short title, so each one collapses to its `name`.
*/
export function generateConversationTitle(content: string, useFirstLine: boolean = false): string {
+ const stripped = stripMentionLinks(content);
+
if (useFirstLine) {
- const firstLine = content.split(NEWLINE).find((line) => line.trim().length > 0);
+ const firstLine = stripped.split(NEWLINE).find((line) => line.trim().length > 0);
- return firstLine ? firstLine.trim() : content.trim();
+ return firstLine ? firstLine.trim() : stripped.trim();
}
- return content.trim();
+ return stripped.trim();
}
diff --git a/ui/apps/chat/tests/unit/conversation-title.test.ts b/ui/apps/chat/tests/unit/conversation-title.test.ts
new file mode 100644
index 000000000..3c9ffa83f
--- /dev/null
+++ b/ui/apps/chat/tests/unit/conversation-title.test.ts
@@ -0,0 +1,69 @@
+import { generateConversationTitle, stripMentionLinks } from '#lib/utils/index.ts';
+import { describe, expect, it } from 'vitest';
+
+describe('stripMentionLinks', () => {
+ it('replaces a mention with its label', () => {
+ expect(stripMentionLinks('refactor [src/lib](file:///repo/src/lib/) please')).toBe(
+ 'refactor src/lib please'
+ );
+ });
+
+ it('replaces every mention in the value', () => {
+ expect(stripMentionLinks('diff [a.m](file:///repo/a.m) with [b.m](file:///repo/b.m)')).toBe(
+ 'diff a.m with b.m'
+ );
+ });
+
+ it('keeps a directory label and drops its whole path, trailing slash included', () => {
+ expect(stripMentionLinks('[apps](file:///repo/ui/apps/chat/) has a bug')).toBe(
+ 'apps has a bug'
+ );
+ });
+
+ it('never leaks a percent-encoded path into the label', () => {
+ expect(stripMentionLinks('[Shot (1).png](file:///tmp/Shot%20(1).png) is blurry')).toBe(
+ 'Shot (1).png is blurry'
+ );
+ });
+
+ it('leaves an ordinary markdown link alone', () => {
+ expect(stripMentionLinks('see [docs](https://example.com/guide)')).toBe(
+ 'see [docs](https://example.com/guide)'
+ );
+ });
+
+ it('leaves a bare at-sign alone', () => {
+ expect(stripMentionLinks('mail me at foo@example.com')).toBe('mail me at foo@example.com');
+ });
+});
+
+describe('generateConversationTitle', () => {
+ it('trims plain content', () => {
+ expect(generateConversationTitle(' why is my build slow \n')).toBe('why is my build slow');
+ });
+
+ it('drops the file url from a leading mention', () => {
+ expect(
+ generateConversationTitle(
+ '[llama.cpp](file:///Users/me/git/llama.cpp/) how do I build for metal?'
+ )
+ ).toBe('llama.cpp how do I build for metal?');
+ });
+
+ it('collapses mentions on the picked line when useFirstLine is set', () => {
+ const content =
+ 'compare [main.c](file:///repo/src/main.c) with [main.cpp](file:///repo/src/main.cpp)\n\nmore detail here';
+
+ expect(generateConversationTitle(content, true)).toBe('compare main.c with main.cpp');
+ });
+
+ it('collapses before picking the first line, so a mention-only line still yields text', () => {
+ expect(generateConversationTitle('\n[notes.md](file:///tmp/notes.md)\nrest', true)).toBe(
+ 'notes.md'
+ );
+ });
+
+ it('returns an empty title for content that is nothing but whitespace', () => {
+ expect(generateConversationTitle(' \n\t \n', true)).toBe('');
+ });
+});