Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(web): keep the final segment of directory paths with a trailing separator (#5460)

jorvareaf915320914d1
diff --git a/apps/web/src/markdown-links.test.ts b/apps/web/src/markdown-links.test.ts
index 9fc296138..f7c507c17 100644
--- a/apps/web/src/markdown-links.test.ts
+++ b/apps/web/src/markdown-links.test.ts
@@ -273,3 +273,28 @@ describe("resolveInlineCodeFileLinkMeta", () => {
expect(resolveInlineCodeFileLinkMeta(".plans/worktree-management-v1.md")).toBeNull();
});
});
+
+describe("directory paths with a trailing separator", () => {
+ it("keeps the final segment for a POSIX directory path", () => {
+ expect(resolveMarkdownFileLinkMeta("/tmp/favicons/", "/repo/project")).toMatchObject({
+ basename: "favicons",
+ });
+ });
+
+ it("keeps the final segment for a Windows directory path", () => {
+ expect(
+ resolveMarkdownFileLinkMeta("C:\\Users\\kelchm\\.claude\\", "/repo/project"),
+ ).toMatchObject({ basename: ".claude" });
+ });
+
+ it("matches the label of the same path without a trailing separator", () => {
+ const withSlash = resolveMarkdownFileLinkMeta("/tmp/favicons/", "/repo/project");
+ const withoutSlash = resolveMarkdownFileLinkMeta("/tmp/favicons", "/repo/project");
+ expect(withSlash?.basename).toBe(withoutSlash?.basename);
+ });
+
+ it("does not produce an empty label for the filesystem root", () => {
+ const meta = resolveMarkdownFileLinkMeta("/tmp/", "/repo/project");
+ expect(meta?.basename).not.toBe("");
+ });
+});
diff --git a/apps/web/src/markdown-links.ts b/apps/web/src/markdown-links.ts
index a6dba941b..e74bd1701 100644
--- a/apps/web/src/markdown-links.ts
+++ b/apps/web/src/markdown-links.ts
@@ -359,8 +359,12 @@ export function resolveInlineCodeFileLinkMeta(
}
function basenameOfPath(path: string): string {
- const separatorIndex = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
- return separatorIndex >= 0 ? path.slice(separatorIndex + 1) : path;
+ // A trailing separator is a valid way to write a directory, so trim it before
+ // taking the final segment. Without this the segment reads as empty and the
+ // chip renders with no label at all.
+ const trimmed = path.replace(/[/\\]+$/, "") || path;
+ const separatorIndex = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
+ return separatorIndex >= 0 ? trimmed.slice(separatorIndex + 1) : trimmed;
}
function workspaceRelativePath(path: string, workspaceRoot: string | undefined): string | null {