Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/server/src/checkpointing/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Encoding } from "effect";
import { CheckpointRef, ProjectId, type ThreadId } from "@t3tools/contracts";
import { expandTilde } from "../os-jank.js";

export const CHECKPOINT_REFS_PREFIX = "refs/t3/checkpoints";

Expand All @@ -24,5 +25,7 @@ export function resolveThreadWorkspaceCwd(input: {
return worktreeCwd;
}

return input.projects.find((project) => project.id === input.thread.projectId)?.workspaceRoot;
const raw = input.projects.find((project) => project.id === input.thread.projectId)
?.workspaceRoot;
return raw ? expandTilde(raw) : undefined;
}
31 changes: 31 additions & 0 deletions apps/server/src/os-jank.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as OS from "node:os";
import { describe, expect, it } from "vitest";
import { expandTilde } from "./os-jank.js";

describe("expandTilde", () => {
const home = OS.homedir();

it("expands bare ~", () => {
expect(expandTilde("~")).toBe(home);
});

it("expands ~/ prefix", () => {
expect(expandTilde("~/projects/foo")).toBe(`${home}/projects/foo`);
});

it("expands ~\\ prefix (Windows)", () => {
expect(expandTilde("~\\projects\\foo")).toBe(`${home}\\projects\\foo`);
});

it("does not expand ~ in the middle of a path", () => {
expect(expandTilde("/home/~user/foo")).toBe("/home/~user/foo");
});

it("returns absolute paths unchanged", () => {
expect(expandTilde("/usr/local/bin")).toBe("/usr/local/bin");
});

it("returns empty string unchanged", () => {
expect(expandTilde("")).toBe("");
});
});
15 changes: 4 additions & 11 deletions apps/server/src/os-jank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@ export function fixPath(): void {
}
}

export const expandHomePath = Effect.fn(function* (input: string) {
const { join } = yield* Path.Path;
if (input === "~") {
return OS.homedir();
}
if (input.startsWith("~/") || input.startsWith("~\\")) {
return join(OS.homedir(), input.slice(2));
}
return input;
});
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.

return pathStr.replace(/^~(?=$|[\\/])/, OS.homedir());
}

export const resolveStateDir = Effect.fn(function* (raw: string | undefined) {
const { join, resolve } = yield* Path.Path;
if (!raw || raw.trim().length === 0) {
return join(OS.homedir(), ".t3", "userdata");
}
return resolve(yield* expandHomePath(raw.trim()));
return resolve(expandTilde(raw.trim()));
});
2 changes: 1 addition & 1 deletion apps/server/src/wsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
readonly command: ClientOrchestrationCommand;
}) {
const normalizeProjectWorkspaceRoot = Effect.fnUntraced(function* (workspaceRoot: string) {
const normalizedWorkspaceRoot = path.resolve(yield* expandHomePath(workspaceRoot.trim()));
const normalizedWorkspaceRoot = path.resolve(expandTilde(workspaceRoot.trim()));
const workspaceStat = yield* fileSystem
.stat(normalizedWorkspaceRoot)
.pipe(Effect.catch(() => Effect.succeed(null)));
Expand Down
Loading