Skip to content

fix: expand tilde in project path input#851

Open
ranvier2d2 wants to merge 2 commits intopingdotgg:mainfrom
ranvier2d2:fix/tilde-expansion
Open

fix: expand tilde in project path input#851
ranvier2d2 wants to merge 2 commits intopingdotgg:mainfrom
ranvier2d2:fix/tilde-expansion

Conversation

@ranvier2d2
Copy link
Contributor

@ranvier2d2 ranvier2d2 commented Mar 10, 2026

Summary

Changes

  • Added a plain expandTilde() helper in apps/server/src/os-jank.ts (regex-based, per review feedback from @binbandit)
  • Applied it in resolveThreadWorkspaceCwd() in apps/server/src/checkpointing/Utils.ts, which is the choke point used by CheckpointReactor, CheckpointDiffQuery, ProviderCommandReactor, and ProviderRuntimeIngestion
  • Added 6 unit tests in apps/server/src/os-jank.test.ts

Context

PR #320 already added tilde expansion at project-creation time via normalizeProjectWorkspaceRoot in wsServer.ts. This PR complements that by adding read-time expansion in resolveThreadWorkspaceCwd, so any legacy database entries stored before #320 also resolve correctly.

Test plan

  • Verify bun run test passes for os-jank.test.ts (6 tests)
  • Verify existing projects with absolute paths continue to work
  • Verify checkpoint, git, and provider operations work with tilde-expanded paths

Note

Expand tilde in project path inputs across workspace resolution

  • Replaces the Effect-based expandHomePath with a pure expandTilde function in os-jank.ts that uses a regex and OS.homedir() to expand a leading ~.
  • Applies expandTilde in resolveThreadWorkspaceCwd (Utils.ts) and normalizeProjectWorkspaceRoot (wsServer.ts) so ~-prefixed paths resolve correctly at runtime.
  • Adds a Vitest suite in os-jank.test.ts covering bare ~, ~/, ~\, non-leading ~, absolute paths, and empty strings.
  • Behavioral Change: expandHomePath is no longer exported; callers must use expandTilde instead.

Macroscope summarized 5a79f28.

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5d11dc4a-1507-43d5-9d88-f47798291b5e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting to disable sequence diagrams in the walkthrough.

@github-actions github-actions bot added the vouch:unvouched PR author is not yet trusted in the VOUCHED list. label Mar 10, 2026
Comment on lines +34 to +37
function expandTilde(p: string): string {
if (p === "~") return OS.homedir();
if (p.startsWith("~/") || p.startsWith("~\\")) return path.join(OS.homedir(), p.slice(2));
return p;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice change!

I would ask that we move to something like this instead though:

Suggested change
function expandTilde(p: string): string {
if (p === "~") return OS.homedir();
if (p.startsWith("~/") || p.startsWith("~\\")) return path.join(OS.homedir(), p.slice(2));
return p;
function expandTilde(pathStr: string): string {
return pathStr.replace(/^~(?=$|[\\/])/, OS.homedir());
  1. Using a full parameter name makes it easier for people to understand what to pass via lsp if there are no jsDocs for the function.
  2. We are doing less comparisons, so there will be added performance
  3. We only have one return point over 3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just read this! WIll review. THanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice change!

I would ask that we move to something like this instead though:

  1. Using a full parameter name makes it easier for people to understand what to pass via lsp if there are no jsDocs for the function.
  2. We are doing less comparisons, so there will be added performance
  3. We only have one return point over 3

Applied. Much cleaner with the regex. Also renamed the param to pathStr per your suggestion. Thanks for the review!

@ranvier2d2 ranvier2d2 force-pushed the fix/tilde-expansion branch 2 times, most recently from 8d256fa to 4011e6c Compare March 10, 2026 21:51
}

/** Plain synchronous tilde expansion (no Effect dependency). */
export function expandTilde(pathStr: string): string {
Copy link
Member

Choose a reason for hiding this comment

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

can we replace the old expandHomePath with this? don't like having 2 doing the same thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced expandHomePath with expandTilde and updated the two call sites (resolveStateDir in os-jank.ts and normalizeProjectWorkspaceRoot in wsServer.ts). Single function now handles all tilde expansion.

Replace the Effect-based expandHomePath with a plain synchronous
expandTilde using regex replacement. Apply it in resolveThreadWorkspaceCwd
(read-path for legacy data), resolveStateDir, and
normalizeProjectWorkspaceRoot (write-path, previously using expandHomePath).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ranvier2d2 ranvier2d2 force-pushed the fix/tilde-expansion branch from 4011e6c to 842d5aa Compare March 10, 2026 22:12
@github-actions github-actions bot added the size:M 30-99 changed lines (additions + deletions). label Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

~ expansion for project path not working

3 participants