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 21, 14:45 UTC
fix(shared): open relative Codex citations with filename punctuation (#36758)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 14, 2026 at 16:23 UTC
60e4be49cfb41ec1910c5f4444c76c0c3fa82c78
7 files changed
+76
-10
packages/shared/src/codexFileCitations.test.ts
+2
-2
@@ -51,7 +51,7 @@ describe("resolveCodexFileCitationLink", () => {
51
}),
52
).toEqual({
53
path: "reports/100% #1? draft.md",
54
- href: "reports/100%25 %231%3F draft.md#L7",
54
+ href: "./reports/100%25 %231%3F draft.md#L7",
55
label: "100% #1? draft.md",
56
lineRangeStart: 7,
57
});
@@ -64,7 +64,7 @@ describe("codexFileCitationMarkdown", () => {
64
path: "reports/*draft*_[copy]`<&.txt",
65
});
66
expect(citation && codexFileCitationMarkdown(citation)).toBe(
67
- "[\\*draft\\*\\_\\[copy\\]\\`\\<\\&.txt](<reports/*draft*_[copy]`%3C%26.txt>)",
67
+ "[\\*draft\\*\\_\\[copy\\]\\`\\<\\&.txt](<./reports/*draft*_[copy]`%3C%26.txt>)",
68
);
69
});
70
});
packages/shared/src/codexFileCitations.ts
+7
-1
@@ -1,3 +1,5 @@
1
+import { parseMarkdownFileLink } from "./markdownLinks.ts";
2
+
3
export interface CodexFileCitationLink {
4
readonly path: string;
5
readonly href: string;
@@ -19,7 +21,11 @@ function citationLabel(path: string): string {
21
}
22
23
function markdownDestinationPath(path: string): string {
22
- return path.replaceAll("%", "%25").replaceAll("#", "%23").replaceAll("?", "%3F");
24
+ const destination = path.replaceAll("%", "%25").replaceAll("#", "%23").replaceAll("?", "%3F");
25
+ // Only disambiguate rejected relative paths; recognized links keep workspace lookup behavior.
26
+ return parseMarkdownFileLink(destination) || /^(?:[a-z][a-z\d+.-]*:|[\\/])/i.test(path)
27
+ ? destination
28
+ : `./${destination}`;
29
}
30
31
export function resolveCodexFileCitationLink(
packages/shared/src/codexMarkdownDirectives.test.ts
+8
-5
@@ -96,15 +96,18 @@ describe.each([
96
])("$name file citation round trips", ({ render }) => {
97
// regression: #12243 copied Codex citations keep their backslashes
98
it.each([
99
- "C:\\Users\\test\\[draft]\\report.md",
100
- "\\\\server\\share\\report.md",
101
- "/tmp/report%5C.md",
102
- ])("preserves the literal path and line: %s", (path) => {
99
+ ["C:\\Users\\test\\[draft]\\report.md", "C:\\Users\\test\\[draft]\\report.md"],
100
+ ["\\\\server\\share\\report.md", "\\\\server\\share\\report.md"],
101
+ ["/tmp/report%5C.md", "/tmp/report%5C.md"],
102
+ ["~\\reports\\draft.md", "~/reports/draft.md"],
103
+ ["reports/100% #1? draft.md", "./reports/100% #1? draft.md"],
104
+ ["./reports/draft.md", "./reports/draft.md"],
105
+ ])("preserves the literal path and line: %s", (path, linkPath) => {
106
const markdown = render(`:codex-file-citation{path="${path}" line_range_start="7"}`);
107
const link = parseOrdinaryMarkdown(markdown).children?.[0]?.children?.[0];
108
109
expect(link?.type).toBe("link");
107
- expect(parseMarkdownFileLink(link?.url ?? "")).toEqual({ path, line: 7 });
110
+ expect(parseMarkdownFileLink(link?.url ?? "")).toEqual({ path: linkPath, line: 7 });
111
});
112
113
it("keeps an entity-like ampersand in the path literal", () => {
packages/shared/src/fileLinks.test.ts
+1
@@ -144,6 +144,7 @@ describe("resolvePathLinkTarget", () => {
144
String.raw`\\server\share\project\.\src\index.ts:12`,
145
],
146
["src/index.ts:12", "/home/jane/project", "/home/jane/project/src/index.ts:12"],
147
+ ["./reports/draft.md:2", "/home/jane/project", "/home/jane/project/reports/draft.md:2"],
148
])("resolves %s using the connected environment cwd %s", (path, cwd, expected) => {
149
expect(resolvePathLinkTarget(path, cwd)).toBe(expected);
150
});
packages/shared/src/fileLinks.ts
+1
-1
@@ -105,7 +105,7 @@ export function resolvePathLinkTarget(rawPath: string, cwd: string): string {
105
}
106
} else if (!isAbsolutePath(path)) {
107
const separator: "/" | "\\" = isWindowsPathStyle(cwd) ? "\\" : "/";
108
- resolvedPath = joinPath(cwd, path, separator);
108
+ resolvedPath = joinPath(cwd, path.replace(/^(?:\.\/)+/, ""), separator);
109
}
110
111
return formatFilePathPosition({ ...position, path: resolvedPath });
packages/shared/src/markdownLinks.test.ts
+1
-1
@@ -198,7 +198,7 @@ describe("resolveMarkdownFileLinkTarget", () => {
198
});
199
200
it("keeps a backslash in a relative link that already names a file", () => {
201
- expect(resolveMarkdownFileLinkTarget("./foo%5Cbar.ts", "/repo")).toBe("/repo/./foo\\bar.ts");
201
+ expect(resolveMarkdownFileLinkTarget("./foo%5Cbar.ts", "/repo")).toBe("/repo/foo\\bar.ts");
202
});
203
204
it("does not treat filename line references as external schemes", () => {
scripts/scenarios/relative-citation-opens-punctuated-file.e2e.ts
new
+56
@@ -0,0 +1,56 @@
1
+/// <reference lib="dom" />
2
+// The DOM lib types the function this scenario runs in the page.
3
+import { expect } from "e2e";
4
+
5
+import { test, WEB } from "./t3.ts";
6
+
7
+const FILE = "reports/100% #1? draft.md";
8
+
9
+test(
10
+ "A relative Codex citation whose name has % # ? opens its file",
11
+ WEB,
12
+ async ({ t3, app, browser, screen }) => {
13
+ // The editor renders in a shadow root that locators do not reach.
14
+ const editorText = () =>
15
+ browser.evaluate(() => {
16
+ for (const host of document.querySelectorAll("*")) {
17
+ const content = host.shadowRoot?.querySelector("[data-content]");
18
+ if (content) return content.textContent ?? "";
19
+ }
20
+ return null;
21
+ });
22
+
23
+ const project = await t3.project("demo", { [FILE]: "Title\nQuarterly draft body\n" });
24
+ // User messages render Codex directives through the same Markdown pipeline as replies.
25
+ const thread = await t3.thread({
26
+ project,
27
+ title: "Citation",
28
+ messages: [`See :codex-file-citation{path="${FILE}" line_range_start="2"}`],
29
+ });
30
+ await t3.open(thread);
31
+ // A message sent through the CLI shows collapsed under its sender.
32
+ await screen.getByRole("button", /^Agent See/).tap();
33
+
34
+ const citation = screen.getByRole("link", /^100% #1\? draft\.md/);
35
+ await expect(citation).toBeVisible();
36
+ await citation.tap();
37
+ await expect.poll(editorText).toContain("Quarterly draft body");
38
+ // The file opens at its workspace path, so the tree selects it and no `.` crumb appears.
39
+ await expect
40
+ .poll(() =>
41
+ browser.evaluate((path) => {
42
+ for (const host of document.querySelectorAll("*")) {
43
+ const row = host.shadowRoot?.querySelector(`[data-item-path="${path}"]`);
44
+ if (row) return row.getAttribute("aria-selected");
45
+ }
46
+ return null;
47
+ }, FILE),
48
+ )
49
+ .toBe("true");
50
+ const crumbs = await browser.evaluate(() =>
51
+ [...document.querySelectorAll("[data-file-crumb]")].map((crumb) => crumb.textContent?.trim()),
52
+ );
53
+ expect(crumbs).not.toContain(".");
54
+ await app.screenshot("citation-opened");
55
+ },
56
+);