|
1 | | -import * as NodeCrypto from "node:crypto"; |
2 | 1 | // @effect-diagnostics-next-line nodeBuiltinImport:off - Effect's symlink has no type argument, and Windows needs a junction to link without elevation. |
3 | 2 | import * as NodeFSP from "node:fs/promises"; |
4 | | -// @effect-diagnostics-next-line nodeBuiltinImport:off - resolveAntigravityProfileDirectory is a pure sync helper, so it cannot use the Path service. |
5 | | -import * as NodePath from "node:path"; |
6 | 3 |
|
7 | 4 | import type { AntigravityAuthMethod, ProviderInstanceId } from "@t3tools/contracts"; |
8 | 5 | import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; |
9 | 6 | import { resolveNodeExecutable, nodeRuntimeUnavailableMessage } from "@t3tools/shared/nodeRuntime"; |
| 7 | +import * as Crypto from "effect/Crypto"; |
10 | 8 | import * as Effect from "effect/Effect"; |
| 9 | +import * as Encoding from "effect/Encoding"; |
11 | 10 | import * as FileSystem from "effect/FileSystem"; |
12 | 11 | import * as Path from "effect/Path"; |
13 | 12 | import type * as PlatformError from "effect/PlatformError"; |
@@ -185,19 +184,32 @@ export function isAntigravitySignInRequiredError(error: unknown): boolean { |
185 | 184 | ); |
186 | 185 | } |
187 | 186 |
|
188 | | -/** Keeps case-sensitive instance IDs separate on case-insensitive filesystems. */ |
189 | | -export function resolveAntigravityProfileDirectory( |
190 | | - stateDir: string, |
191 | | - instanceId: ProviderInstanceId, |
192 | | -): string { |
193 | | - const directoryName = NodeCrypto.createHash("sha256").update(instanceId).digest("hex"); |
194 | | - return NodePath.join(stateDir, "providers", "antigravity", directoryName); |
| 187 | +export interface AntigravityInstanceDirectories { |
| 188 | + /** GEMINI_HOME for the agent. Holds the instance's Google sign-in. */ |
| 189 | + readonly profile: string; |
| 190 | + /** |
| 191 | + * Parent of the per-process directories the agent unpacks into. It sits |
| 192 | + * beside the profile, not inside it: the agent unpacks members up to 120 |
| 193 | + * characters deep, and the profile's longer name would push them past |
| 194 | + * Windows' 260-character path limit. |
| 195 | + */ |
| 196 | + readonly runtimeTemp: string; |
195 | 197 | } |
196 | 198 |
|
197 | | -/** Parent of the per-process runtime temp directories inside a profile. */ |
198 | | -export function resolveAntigravityRuntimeTempDirectory(profileDirectory: string): string { |
199 | | - return NodePath.join(profileDirectory, "antigravity-acp", "tmp"); |
200 | | -} |
| 199 | +/** Hashes the instance ID so case-only differences stay separate on case-insensitive filesystems. */ |
| 200 | +export const resolveAntigravityInstanceDirectories = Effect.fn( |
| 201 | + "resolveAntigravityInstanceDirectories", |
| 202 | +)(function* (stateDir: string, instanceId: ProviderInstanceId) { |
| 203 | + const crypto = yield* Crypto.Crypto; |
| 204 | + const path = yield* Path.Path; |
| 205 | + const key = Encoding.encodeHex( |
| 206 | + yield* crypto.digest("SHA-256", new TextEncoder().encode(instanceId)), |
| 207 | + ); |
| 208 | + return { |
| 209 | + profile: path.join(stateDir, "providers", "antigravity", key), |
| 210 | + runtimeTemp: path.join(stateDir, "antigravity-tmp", key.slice(0, 12)), |
| 211 | + } satisfies AntigravityInstanceDirectories; |
| 212 | +}); |
201 | 213 |
|
202 | 214 | function quoteBrowserArgument(value: string): string { |
203 | 215 | return `'${value.replaceAll("'", `'"'"'`)}'`; |
@@ -300,6 +312,8 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")( |
300 | 312 | readonly auth?: AntigravityAuthConfig; |
301 | 313 | /** Home the agent expands `~` against. Defaults to the launch environment's. */ |
302 | 314 | readonly userHome?: string; |
| 315 | + /** Parent of per-process temp directories. Defaults to one inside the profile. */ |
| 316 | + readonly tempDirectory?: string; |
303 | 317 | }) { |
304 | 318 | const auth = input.auth ?? ANTIGRAVITY_PERSONAL_AUTH; |
305 | 319 | const fs = yield* FileSystem.FileSystem; |
@@ -337,7 +351,7 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")( |
337 | 351 |
|
338 | 352 | const geminiHome = path.resolve(input.profileDirectory); |
339 | 353 | const acpDirectory = path.join(geminiHome, "antigravity-acp"); |
340 | | - const tempDirectory = resolveAntigravityRuntimeTempDirectory(geminiHome); |
| 354 | + const tempDirectory = input.tempDirectory ?? path.join(acpDirectory, "tmp"); |
341 | 355 | const profile: AntigravityProfile = { |
342 | 356 | platform, |
343 | 357 | geminiHome, |
|
0 commit comments