The best way to control Claude Code, Codex and more from any computer or phone

main
ts 37 lines 1.44 KB
Raw
1 // @effect-diagnostics nodeBuiltinImport:off -- lstat proves no managed component is a link.
2 import type * as NodeFS from "node:fs";
3 import * as NodeFSP from "node:fs/promises";
4 import * as NodePath from "node:path";
5
6 /**
7 * Proves a native runtime entry is at its literal path below the canonical profile: every
8 * component exists with the expected type and none is a link. A link could point at another
9 * child's transcript or another session's database under the same profile.
10 */
11 export async function antigravityManagedPath(
12 profileRoot: string,
13 segments: ReadonlyArray<string>,
14 kind: "file" | "directory",
15 ): Promise<{ readonly path: string; readonly info: NodeFS.Stats } | undefined> {
16 let current = profileRoot;
17 let info: NodeFS.Stats | undefined;
18 for (const [index, segment] of segments.entries()) {
19 current = NodePath.join(current, segment);
20 info = await NodeFSP.lstat(current).catch(() => undefined);
21 const expectFile = kind === "file" && index === segments.length - 1;
22 if (
23 info === undefined ||
24 info.isSymbolicLink() ||
25 (expectFile ? !info.isFile() : !info.isDirectory())
26 ) {
27 return undefined;
28 }
29 }
30 if (info === undefined) return undefined;
31 return (await NodeFSP.realpath(current).catch(() => undefined)) === current
32 ? { path: current, info }
33 : undefined;
34 }
35
36 export const antigravityProfileRoot = (profileDirectory: string) =>
37 NodeFSP.realpath(profileDirectory).catch(() => undefined);