From aafb55a309f8b2b693b560765e77dcb0012331f0 Mon Sep 17 00:00:00 2001 From: Willie Date: Mon, 28 Sep 2026 16:05:21 +0800 Subject: [PATCH] fix(ui): name the instructions tab by file name on Windows The tab split the path on / only, so on Windows it showed the whole C:\...\CLAUDE.md path. fileName splits on both separators. Refs #299 --- ui/src/lib/__tests__/paths.test.ts | 11 ++++++++++- ui/src/lib/paths.ts | 5 +++++ ui/src/pages/TargetDetailPage.tsx | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ui/src/lib/__tests__/paths.test.ts b/ui/src/lib/__tests__/paths.test.ts index 315346b84..a1f40ab76 100644 --- a/ui/src/lib/__tests__/paths.test.ts +++ b/ui/src/lib/__tests__/paths.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { shortenPath } from '../paths'; +import { fileName, shortenPath } from '../paths'; describe('shortenPath', () => { it('keeps both ends of a long local path', () => { @@ -9,3 +9,12 @@ describe('shortenPath', () => { for (const source of ['~/plugins/demo', 'runkids/docs-helper', 'https://github.com/runkids/docs-helper/tree/main/plugins/demo']) expect(shortenPath(source)).toBe(source); }); }); + +describe('fileName', () => { + it('takes the last segment of a Windows path', () => { + expect(fileName('C:\\Users\\Public\\sstest\\.claude\\CLAUDE.md')).toBe('CLAUDE.md'); + }); + it('takes the last segment of a POSIX path', () => { + expect(fileName('/home/me/.codex/AGENTS.md')).toBe('AGENTS.md'); + }); +}); diff --git a/ui/src/lib/paths.ts b/ui/src/lib/paths.ts index 45342646b..48c940112 100644 --- a/ui/src/lib/paths.ts +++ b/ui/src/lib/paths.ts @@ -17,3 +17,8 @@ export function shortenPath(path: string): string { if (!/^[~/]/.test(short) || parts.length <= 5) return short; return [...parts.slice(0, 2), '…', ...parts.slice(-2)].join('/'); } + +/** Last segment of a local path, splitting on / and on Windows \ alike. */ +export function fileName(path: string): string { + return path.split(/[\\/]/).pop() || path; +} diff --git a/ui/src/pages/TargetDetailPage.tsx b/ui/src/pages/TargetDetailPage.tsx index 57319f8f8..3efe31e3e 100644 --- a/ui/src/pages/TargetDetailPage.tsx +++ b/ui/src/pages/TargetDetailPage.tsx @@ -19,7 +19,7 @@ import TargetInstructions from '../components/instructions/TargetInstructions'; import { mcpClient, serverCount } from '../components/mcp/mcpView'; import { refreshTargets } from '../components/targets/targetView'; import { queryKeys, staleTimes } from '../lib/queryKeys'; -import { shortenHome } from '../lib/paths'; +import { fileName, shortenHome } from '../lib/paths'; import { useT } from '../i18n'; type Kind = 'skill' | 'agent'; @@ -127,7 +127,7 @@ function TargetEditor({ target }: { target: Target }) { : k === 'instructions' ? instructions.data?.read_order.filter((e) => e.read).length : entriesOf(k).length) || null; // Name the tab after the file this target actually reads (CLAUDE.md, GEMINI.md, …). - const instructionsTab = instructions.data?.supported && instructions.data.path ? instructions.data.path.split('/').pop() : 'AGENTS.md'; + const instructionsTab = instructions.data?.supported && instructions.data.path ? fileName(instructions.data.path) : 'AGENTS.md'; // The instructions tab shows its file path in the panel, for whichever tool is picked. const subtitle = tab === 'mcp' ? mcpPath ?? '' : tab === 'instructions' ? '' : agent ? target.agentPath ?? '' : target.path; return (