From 2363fab6434e548cc67efc742228b260e60e669b Mon Sep 17 00:00:00 2001 From: evgenyponomarev <712802+evgenyponomarev@users.noreply.github.com> Date: Mon, 31 Aug 2026 04:21:50 +0300 Subject: [PATCH] Apply reviewed change --- .../cli/src/__tests__/pi-transcript.test.ts | 17 +++++++++++++++++ packages/cli/src/pi-transcript.ts | 10 +++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/__tests__/pi-transcript.test.ts b/packages/cli/src/__tests__/pi-transcript.test.ts index b74ed7bdd2..53b936faad 100644 --- a/packages/cli/src/__tests__/pi-transcript.test.ts +++ b/packages/cli/src/__tests__/pi-transcript.test.ts @@ -42,6 +42,7 @@ import { makaPiToolPresentationStatus, retireCancelledTransientMessages, replaceTranscriptWithStoredMessages, + shortenCwd, submitCompactToTranscript, toggleAllThinkingExpansion, toggleAllToolExpansion, @@ -383,6 +384,22 @@ describe('Maka Pi TUI transcript', () => { assert.doesNotMatch(line, /·\s*$/); }); + test('shortens cwd under home with either path separator', () => { + assert.equal( + shortenCwd('/Users/alice/workspace/project', '/Users/alice'), + '~/workspace/project', + ); + assert.equal( + shortenCwd('C:\\Users\\alice\\Videos\\project', 'C:\\Users\\alice'), + '~\\Videos\\project', + ); + assert.equal(shortenCwd('C:\\Users\\alice', 'C:\\Users\\alice'), '~'); + assert.equal( + shortenCwd('C:\\Users\\alice2\\project', 'C:\\Users\\alice'), + 'C:\\Users\\alice2\\project', + ); + }); + test('status line never drops mode, model, goal, or ctx at narrow widths (#3421)', () => { const line = stripAnsi( renderMakaPiStatusLine( diff --git a/packages/cli/src/pi-transcript.ts b/packages/cli/src/pi-transcript.ts index bbbec37545..196a95bf7a 100644 --- a/packages/cli/src/pi-transcript.ts +++ b/packages/cli/src/pi-transcript.ts @@ -1922,10 +1922,14 @@ function firstLinePreview(text: string): string { * `/Users/alice/workspace/project` → `~/workspace/project`. * Falls back to the original path if it is not under the home directory. */ -function shortenCwd(cwd: string, homeDir?: string): string { +export function shortenCwd(cwd: string, homeDir?: string): string { const home = homeDir ?? homedir(); - if (home && cwd.startsWith(home + '/')) return `~${cwd.slice(home.length)}`; - if (home && cwd === home) return '~'; + const normalizedHome = home.replace(/\\/g, '/'); + const normalizedCwd = cwd.replace(/\\/g, '/'); + if (home && normalizedCwd.startsWith(normalizedHome + '/')) { + return `~${cwd.slice(home.length)}`; + } + if (home && normalizedCwd === normalizedHome) return '~'; return cwd; }