Skip to content

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

Closed
riba2534 wants to merge 1 commit into
mainfrom
fix/cli-statusline-windows-home-abbreviation-2c49
Closed

riba2534 wants to merge 1 commit into
mainfrom
fix/cli-statusline-windows-home-abbreviation-2c49

Conversation

@riba2534

Copy link
Copy Markdown
Owner

Fork-only staging PR (riba2534/makariba2534/maka). Not for upstream submission from here.

Summary

shortenCwd in packages/cli/src/pi-transcript.ts decided home-containment with cwd.startsWith(home + '/'). On win32 os.homedir() reports C:\Users\<name> and process.cwd() uses backslashes, so that test was false for every subdirectory of the profile: the TUI statusline printed the full absolute path where it should have shown ~\Videos\clip. Exact-home still matched, which is why the feature from apache#1064 / apache#1066 looked partly alive rather than broken.

Containment is now decided on separator-normalized copies of both paths, and the emitted tail is sliced out of the original cwd so it keeps whichever separators the platform actually produced (~\Videos\clip on Windows, ~/workspace/project on POSIX). Mixed separators within one Windows path match too.

Two deliberate choices worth a reviewer's attention:

  • path.relative is not used. It follows the host platform, so C:\Users\alice would be misread on a POSIX runner — the same platform coupling that caused the bug, just inverted. A separator-normalized prefix test plus an explicit .. rejection is the OS-independent equivalent, and it is what lets the regression test cover Windows without a Windows runner.
  • No case folding was introduced. No path helper in the tree case-folds (isPathWithin in packages/storage/src/project-catalog.ts, the ..${sep} containment checks in session-bundle-policy.ts and runtime-host-cli-installation.ts are all case-sensitive), so inventing a Windows-only policy here would be a new and unreviewed rule.

A .. segment now falls back to the unabbreviated path instead of emitting a ~/.. form that no longer names the same directory. Statusline layout, every other segment, and the renderer are untouched; the change is confined to shortenCwd and its tests.

Fixes apache#3825

Verification

shortenCwd is exported so the regression table can inject home and cwd as plain strings — the Windows expectations hold on a Linux runner. A second test drives renderMakaPiStatusLine with join(homedir(), 'workspace', 'project') and asserts against the platform's own sep, covering the production wiring on any OS.

RED — with the original home + '/' body (test kept as-is):

not ok 8 - abbreviates a home-relative cwd on every platform (#3825)
  error: |-
    C:\Users\alice\Videos\clip under C:\Users\alice
    + actual - expected

    + 'C:\\Users\\alice\\Videos\\clip'
    - '~\\Videos\\clip'
# tests 480
# pass 479
# fail 1

GREENnpm --workspace maka-agent test (clean + build + node --test dist/**/*.test.js):

# tests 480
# pass 480
# fail 0

Also run, all clean: npm --workspace maka-agent run typecheck, npm run lint, npm run format:check, and npx biome check on both touched files.

Not run: the root npm test across every workspace and the Windows CI jobs. Nothing outside packages/cli imports pi-transcript, and the abbreviation is pure string logic, so the CLI suite is the relevant blast radius. The Windows behavior is asserted from injected strings rather than a Windows runner by design.

AI use

Select exactly one:

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

Tool(s) and scope: Cursor Cloud Agent (Claude Opus 5) investigated the report, wrote the shortenCwd replacement and the regression tests, and ran the checks above. Human contributor of record: riba2534. Commits carry a Generated-by: Cursor Cloud Agent trailer.

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 — described under Summary above
  • No
Open in Web Open in Cursor 

`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>
@riba2534

Copy link
Copy Markdown
Owner Author

Opened against upstream: apache#3867

@riba2534 riba2534 closed this Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants