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
This commit is contained in:
Willie
2026-09-28 16:05:21 +08:00
parent 8063a6f424
commit aafb55a309
3 changed files with 17 additions and 3 deletions
+10 -1
View File
@@ -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');
});
});
+5
View File
@@ -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;
}
+2 -2
View File
@@ -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 (