Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import {
proposedPlanTitle,
resolvePlanFollowUpSubmission,
} from "../proposedPlan";
import { truncateTitle } from "../truncateTitle";
import { buildThreadTitle } from "../threadTitle";
import {
DEFAULT_INTERACTION_MODE,
DEFAULT_RUNTIME_MODE,
Expand Down Expand Up @@ -2341,7 +2341,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
titleSeed = "New thread";
}
}
const title = truncateTitle(titleSeed);
const title = buildThreadTitle(titleSeed);
let threadCreateModel: ModelSlug =
selectedModel || (activeProject.model as ModelSlug) || DEFAULT_MODEL_BY_PROVIDER.codex;

Expand Down Expand Up @@ -2768,7 +2768,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
const nextThreadId = newThreadId();
const planMarkdown = activeProposedPlan.planMarkdown;
const implementationPrompt = buildPlanImplementationPrompt(planMarkdown);
const nextThreadTitle = truncateTitle(buildPlanImplementationThreadTitle(planMarkdown));
const nextThreadTitle = buildThreadTitle(buildPlanImplementationThreadTitle(planMarkdown));
const nextThreadModel: ModelSlug =
selectedModel ||
(activeThread.model as ModelSlug) ||
Expand Down
53 changes: 53 additions & 0 deletions apps/web/src/threadTitle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe, expect, it } from "vitest";

import { buildThreadTitle } from "./threadTitle";

describe("buildThreadTitle", () => {
it("trims surrounding whitespace", () => {
expect(buildThreadTitle(" hello world ")).toBe("hello world");
});

it("returns trimmed text when within max length", () => {
expect(buildThreadTitle("alpha", 10)).toBe("alpha");
});

it("appends ellipsis when text exceeds max length", () => {
expect(buildThreadTitle("abcdefghij", 5)).toBe("abcde...");
});

it("shortens a single file mention to its basename while keeping the marker", () => {
expect(buildThreadTitle("Inspect @apps/web/src/components/ChatView.tsx please")).toBe(
"Inspect @ChatView.tsx please",
);
});

it("shortens multiple file mentions independently", () => {
expect(buildThreadTitle("Compare @apps/web/src/a.ts with @packages/shared/src/b.ts now")).toBe(
"Compare @a.ts with @b.ts now",
);
});

it("shortens mentions before truncating the title", () => {
const title = buildThreadTitle(
"@apps/web/src/components/ChatView.tsx investigate header layout",
20,
);

expect(title).toBe("@ChatView.tsx invest...");
expect(title).not.toContain("apps/web/src/components");
});

it("leaves incomplete trailing mentions unchanged", () => {
expect(buildThreadTitle("Inspect @apps/web/src/components/ChatView.tsx")).toBe(
"Inspect @apps/web/src/components/ChatView.tsx",
);
});

it("preserves punctuation and whitespace around mention segments", () => {
expect(
buildThreadTitle(
"Review @apps/web/src/components/ChatView.tsx ; then ping @README.md please",
),
).toBe("Review @ChatView.tsx ; then ping @README.md please");
});
});
17 changes: 17 additions & 0 deletions apps/web/src/threadTitle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { splitPromptIntoComposerSegments } from "./composer-editor-mentions";
import { basenameOfPath } from "./vscode-icons";

export function buildThreadTitle(text: string, maxLength = 50): string {
const normalized = splitPromptIntoComposerSegments(text)
.map((segment) =>
segment.type === "mention" ? `@${basenameOfPath(segment.path)}` : segment.text,
)
.join("")
.trim();

if (normalized.length <= maxLength) {
return normalized;
}

return `${normalized.slice(0, maxLength)}...`;
}
17 changes: 0 additions & 17 deletions apps/web/src/truncateTitle.test.ts

This file was deleted.

7 changes: 0 additions & 7 deletions apps/web/src/truncateTitle.ts

This file was deleted.

Loading