Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,37 @@ describe('toolFormatting', () => {
).toBe('README.md');
});

it.each([
'packages/web-shell/client/messageTypes.ts (lines 161-200)',
'packages/.../MessageList.dom.test.tsx (lines 277-298)',
'./src/index.ts',
'../src/index.ts',
'~/project/src/index.ts',
'Writing to src/index.ts',
"'TODO' in path 'src/components' (filter: '**/*.ts')",
'https://example.com/docs/index.html',
])('preserves separators in title description %s', (description) => {
const call = tool({ title: `ReadFile: ${description}` });
expect(getToolDescription(call, '/workspace/project')).toBe(description);
expect(getToolSummaryDescription(call, '/workspace/project')).toBe(
description,
);
});

it.each([
["'/workspace/project/src/index.ts'", "'src/index.ts'"],
['"/workspace/project/src/index.ts"', '"src/index.ts"'],
['(/workspace/project/src/index.ts)', '(src/index.ts)'],
['C:/workspace/project/src/index.ts', 'index.ts'],
])('normalizes an embedded absolute path %s', (path, expected) => {
expect(
getToolDescription(
tool({ title: `Writing to ${path}` }),
'/workspace/project',
),
).toBe(`Writing to ${expected}`);
});

it('falls back to a workspace-relative file path', () => {
expect(
getToolDescription(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,10 @@ function formatDescriptionPaths(
return pathForDisplay(trimmed, workspaceCwd);
}

return trimmed.replace(/(?:[A-Za-z]:)?\/[^\s'")]+/g, (match) =>
pathForDisplay(match, workspaceCwd),
return trimmed.replace(
/(^|[\s'"(])((?:[A-Za-z]:)?\/[^\s'")]+)/g,
(_match, prefix: string, filePath: string) =>
prefix + pathForDisplay(filePath, workspaceCwd),
);
}

Expand Down
Loading