Skip to content

fix(cli): abbreviate home-relative Windows paths in the status line - #4481

Merged
jackwener merged 3 commits into
apache:mainfrom
ggbdpq:fix/statusline-shorten-cwd-windows
Sep 1, 2026
Merged

jackwener merged 3 commits into
apache:mainfrom
ggbdpq:fix/statusline-shorten-cwd-windows

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

The TUI status line never shortened home-relative paths on Windows: shortenCwd compared cwd against home + '/', which can never match a Windows profile path (C:\Users\<name>\Videos\...). Only the exact home directory shortened; every subdirectory rendered as a full absolute path.

This change compares through path.relative instead, which handles drive letters and case-only differences via the platform module, rejects native parent-traversal and absolute results (siblings, parent traversal, and other drives keep their absolute form), and emits ~/<rest> with the remainder's native separators. A review follow-up keeps POSIX directory names whose first segment literally contains a backslash eligible for shortening.

shortenCwd is exported so the contract has focused coverage.

Fixes #3825

Verification

Check Command Result
Target suite node --test dist/__tests__/pi-transcript.test.js in packages/cli 110 pass, 0 fail, 2 skip on Windows — the three #3825 Windows cases pass; the two POSIX-only cases skip there and run on POSIX hosts
Full CLI suite after review fix npm --workspace maka-agent test 667 pass, 0 fail, 3 Windows-only skip on macOS
Format npm run format:check Checked 1780 files, no fixes applied
Changed-file format npx biome check packages/cli/src/pi-transcript.ts packages/cli/src/__tests__/pi-transcript.test.ts 2 files clean after the review fix
Windows skip inventory npm run windows:inventory Current at 72 declarations after recording the two POSIX-only path contracts on current main
ASF headers npm run check:asf-headers 3146 files audited, every source file carries the ASF header

Note: the full @maka/cli suite on the original Windows checkout reports one failure unrelated to this change — runtime-host-update-reconciliation.test.js hits EPERM: operation not permitted, fsync on a directory, the Windows directory-sync gap tracked by #3898. The failing module does not import pi-transcript. The check:asf-source release-legal script tests also fail on that checkout for spawn-environment reasons; the header audit that governs source files passes.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: GLM-5.3-Flash via ZCode traced the root cause, implemented the original fix and tests, and ran the original verification table. OpenAI Codex corrected the cross-platform parent-separator guard, added the POSIX ..\notes regression, and refreshed the repository's Windows skip inventory during review. All affected commits carry Generated-by trailers.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — the Windows status line now renders ~/-relative paths instead of full absolute paths; macOS/Linux behavior is unchanged

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

@github-actions github-actions Bot added the effort/S Under 100 readable lines label Sep 1, 2026

@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.

Re-reviewed at 2cce995 — nice catch and a clean fix.

I verified this independently:

  • Root cause matches #3825 exactly: startsWith(home + '/') can never match a Windows profile path, so only the exact home directory shortened.
  • Walked all six Windows assertions against node:path/win32 semantics — case-only differences, sibling rejection (..\\), and cross-drive absolute fallback all behave as the tests claim; POSIX behavior is unchanged (confirmed by running the packages/cli suite: 667 pass / 0 fail on macOS, including the existing statusline-abbreviation tests).
  • The rewrite replaces the old logic outright — no parallel path, minimal surface.

One non-blocking observation: if CI has no Windows runner, the three win32 cases will always skip there, so the Windows branch is currently covered by local verification only. Existing infra gap, not something this PR needs to solve.

Approving — nice work. 🚀

ggbdpq and others added 3 commits September 2, 2026 00:32
shortenCwd matched the home directory by a POSIX-separator prefix, so
on Windows only the exact home path shortened and every profile
subdirectory rendered as a full absolute path. Compare through
path.relative instead - it handles drive letters and case-only
differences - and reject ..-prefixed or absolute results before
emitting the ~/ form, keeping the remainder's native separators.

The helper is exported so the contract has focused coverage: POSIX
shortening and fallbacks, plus Windows profile, case-insensitive,
sibling, and cross-drive cases (the Windows cases run on win32 hosts).

Fixes apache#3825

Generated-by: GLM-5.3-Flash (ZCode)
Generated-by: OpenAI Codex
@jackwener
jackwener force-pushed the fix/statusline-shorten-cwd-windows branch from 3cff059 to d115e27 Compare September 1, 2026 16:33

@jackwener jackwener left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The status line now derives home-relative paths through the native path module, so Windows profile descendants shorten correctly while siblings, parent traversal, and other drives remain absolute. The review follow-up also keeps legal POSIX child names such as ..\notes eligible for shortening by checking only the native separator.

The exact rebased head built successfully and its full CLI suite passed 728 tests with three Windows-only skips. The focused Win32 path cases cover case-only profile differences, siblings, and cross-drive fallbacks, and the Windows skip inventory is current. The exact-head hosted check and the clean current-main merge both pass.

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

@jackwener
jackwener merged commit 5013f90 into apache:main Sep 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/S Under 100 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