Skip to content

fix(cli): abbreviate home-relative cwd on Windows statusline - #3867

Closed
riba2534 wants to merge 2 commits into
apache:mainfrom
riba2534:fix/cli-statusline-windows-home-abbreviation-2c49
Closed

riba2534 wants to merge 2 commits into
apache:mainfrom
riba2534:fix/cli-statusline-windows-home-abbreviation-2c49

Conversation

@riba2534

Copy link
Copy Markdown
Contributor

Fixes #3825. shortenCwd used home + slash, which never matches Windows subdirectories. Separator-normalized containment; tests in packages/cli/src/tests/pi-transcript.test.ts.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this head and found blocking issues.

[P2] Windows caseness still wrong

pi-transcript.ts:1537-1541 uses case-sensitive compare; C:\Users\Alice vs c:\users\ALICE\work should match on Windows (path.win32.relative === 'work') but returns full path. Tests don't cover this.

Also Standards 4 hard (template, AI disclosure, checks, before/after missing) and 2×P3 (POSIX backslash, HOME root).

Hosted test currently has no checks on this head — needs CI.

简体中文Windows 路径大小写与模板缺失。

Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@riba2534 riba2534 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed 1aed8f08 addressing the Windows caseness note:

  • Win32/UNC/drive-letter paths now compare case-insensitively after separator normalization; POSIX stays case-sensitive.
  • c:\users\ALICE\work under C:\Users\Alice now yields ~\work.
  • POSIX backslash in a name is no longer treated as a separator (/Users/alice\evil stays unchanged).
  • Empty/root HOME already returned the full path; added regression rows only.

CI on this fork still needs first-time workflow approval.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this head and found no new blocking code issues beyond process.

Fixes for 4f95 Windows caseness and POSIX backslash now closed (verified). Remaining:

  • [P3] HOME=/ exact-home regressionshortenCwd('/', '/') now returns / instead of ~ (trim makes home empty). Fix: handle root case before trim.
  • Standards 4 hard — PR body still empty (template, AI disclosure, Verification, before/after missing).
  • Hosted test still has no checks on this head — needs CI green.
简体中文主要问题已修,剩余为小边界与流程材料。

Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this head and found no blocking issues.

Windows home-relative shortening now case-insensitive with normalized separators while POSIX keeps backslash as filename char; coverage includes equal-length, UNC, drive mismatch, and traversal cases.

No P0-P3 on code; hosted checks currently have no runs on this head — needs CI green.

简体中文该头无阻断,待 CI。

Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@jackwener
jackwener force-pushed the fix/cli-statusline-windows-home-abbreviation-2c49 branch from 1aed8f0 to 6a3f0e6 Compare August 26, 2026 08:28
cursoragent and others added 2 commits August 26, 2026 17:57
`shortenCwd` tested containment with `cwd.startsWith(home + '/')`. On win32
`os.homedir()` reports `C:\Users\<name>` and `process.cwd()` uses backslashes,
so the test was false for every subdirectory of the profile and the statusline
printed the full absolute path instead of `~\Videos\clip`. Exact-home still
matched, which is why the feature looked partly alive.

Decide containment on separator-normalized copies of both paths, and slice the
tail out of the original `cwd` so it keeps the separators the platform actually
produced. `path.relative` is avoided on purpose: it follows the host platform,
so a Windows path would be misread on a POSIX runner. A `..` segment now falls
back to the full path rather than emitting a `~/..` form that no longer names
the same directory. Comparison stays case-sensitive, like the other path
helpers in the tree.

The helper is exported so the regression table can inject home and cwd as
plain strings and assert the Windows cases without a Windows runner; a second
test drives `renderMakaPiStatusLine` through the real `os.homedir()` to cover
the wiring. Statusline layout and every other segment are untouched.

Closes apache#3825

Generated-by: Cursor Cloud Agent

Co-authored-by: riba2534 <riba2534@qq.com>
Review follow-up on apache#3825. Separator normalization alone was not enough:
`shortenCwd` still compared case-sensitively, so `c:\users\ALICE\work` did not
abbreviate under `C:\Users\Alice` even though Windows treats them as the same
directory. Normalizing separators unconditionally was also wrong in the other
direction — `\` is a legal POSIX filename character, so a sibling entry named
`alice\evil` was read as `alice/evil` and `/Users/alice\evil` was abbreviated
to `~\evil`, a path it never was.

Split the two rulesets. A win32 path — `process.platform`, a `C:` drive root,
or a `\\` UNC root — treats `\` and `/` as interchangeable and compares folded;
a POSIX path compares exactly and leaves `\` alone. `path.relative` still isn't
used: it follows the host platform, so the Windows cases would need a Windows
runner to mean anything. The tail is still sliced out of the original `cwd`, so
it keeps the separators and casing the platform produced, and the emitted form
agrees with `path.win32.relative` on the win32 rows.

Containment is now a fixed-offset prefix comparison rather than
`startsWith(home + '/')`. Folding is applied only to the two equal-length
slices being compared, never to the string the tail is cut from: `toLowerCase`
can change a string's length, which would otherwise shift the cut. Inputs where
folding does change the length (`İstanbul` under `Istanbul`) therefore fall back
to the full path instead of producing a garbled one.

The platform is injectable, following renderMakaPiPendingQueue, so every row in
the regression table pins its own platform and asserts the same result on a
POSIX and a Windows runner. Added coverage for win32 case folding, POSIX case
sensitivity, backslash-in-a-name on POSIX, and empty, `/` and `\` homes, which
must not collapse every absolute path to `~`.

Refs apache#3825

Generated-by: Cursor Cloud Agent

Co-authored-by: riba2534 <riba2534@qq.com>
@M4n5ter
M4n5ter force-pushed the fix/cli-statusline-windows-home-abbreviation-2c49 branch from 6a3f0e6 to eb79662 Compare August 26, 2026 09:57
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Aug 27, 2026
@Astro-Han

Copy link
Copy Markdown
Contributor

Closing this one — #4481 landed a fix for #3825 earlier today, so the Windows home-relative path is already abbreviated on main. Three PRs ended up aimed at the same issue and #4481 got there first; that's on our triage, not on you.

Sorry for the wasted effort, and thanks for taking it on. If you pull main and still see a path that isn't abbreviated, please do reopen or file a follow-up — a case #4481 missed would be worth having.

@Astro-Han Astro-Han closed this Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): statusline never abbreviates home-relative paths on Windows

3 participants