@devries-cameron20 / t3code Mirror · read-only / commits / 6de7da548d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 19:30 UTC

fix(shared): recognize relative folder links with trailing slash (#22188)

Co-authored-by: macodev00 <macodev00@users.noreply.github.com>

maco committed Oct 22, 2026 at 00:12 UTC 6de7da548d15d86e86f7550a9f1b402e924249dd
2 files changed +21 -2
packages/shared/src/markdownLinks.test.ts
+15 -1
@@ -26,6 +26,8 @@ describe("inlineCodeFilePathCandidate", () => {
26 ["origin/main", null],
27 ["z-ai/glm-5.3", null],
28 ["share/man/ls.1", "share/man/ls.1"],
29 + ["src/main.ts/", null],
30 + ["./patches/", "./patches/"],
31 ])("distinguishes file paths from code and hostnames in %s", (source, candidate) => {
32 expect(inlineCodeFilePathCandidate(source)).toBe(candidate);
33 });
@@ -40,13 +42,18 @@ describe("parseMarkdownFileLink", () => {
42 expect(parseMarkdownFileLink(href)?.path).toBe(path);
43 });
44
43 - it.each(["https://example.com/docs", "/chat/settings#L3", "TODO:12"])(
45 + it.each(["https://example.com/docs", "/chat/settings#L3", "TODO:12", "patches"])(
46 "does not treat %s as a file",
47 (href) => {
48 expect(parseMarkdownFileLink(href)).toBeNull();
49 },
50 );
51
52 + it("recognizes a relative folder that ends in a slash", () => {
53 + expect(parseMarkdownFileLink("patches/")).toEqual({ path: "patches/" });
54 + expect(parseMarkdownFileLink("docs/My%20Folder/")?.path).toBe("docs/My Folder/");
55 + });
56 +
57 it("accepts conventional extensionless names with or without a position", () => {
58 expect(parseMarkdownFileLink("Makefile")).toEqual({ path: "Makefile" });
59 expect(parseMarkdownFileLink("Dockerfile:8")).toEqual({ path: "Dockerfile", line: 8 });
@@ -89,6 +96,13 @@ describe("extractMarkdownLinkHrefs", () => {
96 });
97
98 describe("resolveMarkdownFileLinkTarget", () => {
99 + it("resolves a relative folder with a trailing slash against cwd", () => {
100 + expect(resolveMarkdownFileLinkTarget("patches/", "/repo/project")).toBe(
101 + "/repo/project/patches/",
102 + );
103 + expect(resolveMarkdownFileLinkTarget("patches", "/repo/project")).toBeNull();
104 + });
105 +
106 it("does not treat filename line references as external schemes", () => {
107 expect(resolveMarkdownFileLinkTarget("script.ts:10", "/Users/julius/project")).toBe(
108 "/Users/julius/project/script.ts:10",
packages/shared/src/markdownLinks.ts
+6 -1
@@ -9,8 +9,10 @@ import {
9
10 const RELATIVE_PATH_PREFIX_PATTERN = /^(~\/|\.{1,2}\/)/;
11
12 +// The final segment is optional so an explicit folder link may end in `/`
13 +// (`patches/`, `docs/My Folder/`). A bare name with no slash still fails.
14 const RELATIVE_FILE_PATH_PATTERN =
13 - /^(?:[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*\/)+[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*(?::\d+){0,2}$/;
15 + /^(?:[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*\/)+(?:[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*(?::\d+){0,2})?$/;
16
17 const RELATIVE_FILE_NAME_PATTERN =
18 /^[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*\.[A-Za-z0-9_-]+(?::\d+){0,2}$/;
@@ -176,6 +178,9 @@ export function inlineCodeFilePathCandidate(codeText: string): string | null {
178 isWindowsAbsolutePath(candidate);
179 if (!hasExplicitPathShape) {
180 const withoutPosition = candidate.replace(POSITION_SUFFIX_PATTERN, "");
181 + // Markdown destinations accept `patches/`. Inline code still needs a
182 + // file-shaped final segment, so a trailing slash stays plain code.
183 + if (withoutPosition.endsWith("/")) return null;
184 const firstSegment = withoutPosition.split("/")[0] ?? withoutPosition;
185 if (looksLikeHostname(firstSegment, hasPosition)) return null;
186 const basename =