Open History to see the last commit
1import * as NodeOS from "node:os";
2
3import type { ClaudeSettings } from "@t3tools/contracts";
4import { Effect, Path } from "effect";
5
6import { expandHomePath } from "../../pathExpansion.ts";
7
8export const resolveClaudeHomePath = Effect.fn("resolveClaudeHomePath")(function* (
9 config: Pick<ClaudeSettings, "homePath">,
10): Effect.fn.Return<string, never, Path.Path> {
11 const path = yield* Path.Path;
12 const homePath = config.homePath.trim();
13 return path.resolve(homePath.length > 0 ? expandHomePath(homePath) : NodeOS.homedir());
14});
15
16export const makeClaudeEnvironment = Effect.fn("makeClaudeEnvironment")(function* (
17 config: Pick<ClaudeSettings, "homePath">,
18 baseEnv: NodeJS.ProcessEnv = process.env,
19): Effect.fn.Return<NodeJS.ProcessEnv, never, Path.Path> {
20 const homePath = config.homePath.trim();
21 if (homePath.length === 0) return baseEnv;
22 const resolvedHomePath = yield* resolveClaudeHomePath(config);
23 return {
24 ...baseEnv,
25 HOME: resolvedHomePath,
26 };
27});
28
29export const makeClaudeContinuationGroupKey = Effect.fn("makeClaudeContinuationGroupKey")(
30 function* (config: Pick<ClaudeSettings, "homePath">): Effect.fn.Return<string, never, Path.Path> {
31 const resolvedHomePath = yield* resolveClaudeHomePath(config);
32 return `claude:home:${resolvedHomePath}`;
33 },
34);
35
36export const makeClaudeCapabilitiesCacheKey = Effect.fn("makeClaudeCapabilitiesCacheKey")(
37 function* (
38 config: Pick<ClaudeSettings, "binaryPath" | "homePath">,
39 ): Effect.fn.Return<string, never, Path.Path> {
40 const resolvedHomePath = yield* resolveClaudeHomePath(config);
41 return `${config.binaryPath}\0${resolvedHomePath}`;
42 },
43);