TypeScript
fix(shared): shortened agent paths like /tmp/... no longer become broken file chips (#30762)
Alex Southwell47a89f2ee7b7
diff --git a/packages/shared/src/markdownLinks.test.ts b/packages/shared/src/markdownLinks.test.tsindex 318f2e1c333..68aa6950135 100644--- a/packages/shared/src/markdownLinks.test.ts+++ b/packages/shared/src/markdownLinks.test.ts@@ -29,6 +29,12 @@ describe("inlineCodeFilePathCandidate", () => {["share/man/ls.1", "share/man/ls.1"],["src/main.ts/", null],["./patches/", "./patches/"],+ // regression: #30757 an agent's shortened path is not a file+ ["/tmp/claude-1000/...", null],+ ["/tmp/claude-1000/...:12", null],+ ["/tmp/.../scratchpad/notes.md", null],+ ["~/projects/…/notes.md", null],+ ["src/.../main.ts", null],])("distinguishes file paths from code and hostnames in %s", (source, candidate) => {expect(inlineCodeFilePathCandidate(source)).toBe(candidate);});diff --git a/packages/shared/src/markdownLinks.ts b/packages/shared/src/markdownLinks.tsindex 6b76b61475a..f8b0e8434e9 100644--- a/packages/shared/src/markdownLinks.ts+++ b/packages/shared/src/markdownLinks.ts@@ -33,6 +33,8 @@ const POSITION_ONLY_PATTERN = /^\d+(?::\d+)?$/;const INLINE_CODE_DISQUALIFIER_PATTERN = /[\s`]/;const PATH_SEPARATOR_PATTERN = /[\\/]/;+// Agents shorten long paths with a `...` or `…` segment, which no file chip can open.+const ELIDED_PATH_SEGMENT_PATTERN = /(?:^|[\\/])(?:\.{3,}|…)(?:[\\/]|$)/;const FILE_EXTENSION_PATTERN = /\.[A-Za-z0-9_-]+$/;const VERSION_SUFFIX_PATTERN = /\d\.\d[^.]*$/;@@ -178,6 +180,7 @@ export function inlineCodeFilePathCandidate(codeText: string): string | null {const candidate = isWindowsAbsolutePath(trimmed) ? trimmed : trimmed.replaceAll("\\", "/");const hasPosition = POSITION_SUFFIX_PATTERN.test(candidate);if (!hasPosition && !PATH_SEPARATOR_PATTERN.test(candidate)) return null;+ if (ELIDED_PATH_SEGMENT_PATTERN.test(candidate.replace(POSITION_SUFFIX_PATTERN, ""))) return null;const hasExplicitPathShape =RELATIVE_PATH_PREFIX_PATTERN.test(candidate) ||