@@ -8,6 +8,7 @@ import * as Digest from "effect/crypto/Digest"; |
8 | 8 | import * as Effect from "effect/Effect"; |
9 | 9 | import * as Hex from "effect/encoding/Hex"; |
10 | 10 | import * as FileSystem from "effect/FileSystem"; |
| 11 | +import * as Option from "effect/Option"; |
11 | 12 | import * as Path from "effect/Path"; |
12 | 13 | import type * as PlatformError from "effect/PlatformError"; |
13 | 14 | import * as Schema from "effect/Schema"; |
@@ -243,23 +244,34 @@ class AntigravitySkillLinkError extends Schema.TaggedError<AntigravitySkillLinkE |
243 | 244 | { link: Schema.String, cause: Schema.Defect() }, |
244 | 245 | ) { |
245 | 246 | override get message(): string { |
246 | | - return `Could not link Antigravity user skills at ${this.link}.`; |
| 247 | + return `Could not link Antigravity user configuration at ${this.link}.`; |
247 | 248 | } |
248 | 249 | } |
249 | 250 |
|
250 | | -/** Private GEMINI_HOME isolates credentials/hooks/MCP; link global skills from the real ~/.gemini. */ |
251 | | -const linkAntigravityUserSkills = Effect.fn("linkAntigravityUserSkills")(function* (input: { |
| 251 | +const antigravityUserRuleFiles = ["AGENTS.md", "GEMINI.md"] as const; |
| 252 | + |
| 253 | +/** Private GEMINI_HOME isolates credentials/hooks/MCP; link global skills and rules from the real ~/.gemini. */ |
| 254 | +const linkAntigravityUserConfig = Effect.fn("linkAntigravityUserConfig")(function* (input: { |
252 | 255 | readonly profileDirectory: string; |
253 | 256 | readonly userHome: string; |
254 | 257 | readonly platform: NodeJS.Platform; |
255 | 258 | }): Effect.fn.Return<void, never, FileSystem.FileSystem | Path.Path> { |
256 | 259 | const fs = yield* FileSystem.FileSystem; |
257 | 260 | const path = yield* Path.Path; |
| 261 | + const userGemini = path.join(input.userHome, ".gemini"); |
258 | 262 | const links = antigravityUserSkillDirectories(path, input.profileDirectory); |
259 | | - const targets = antigravityUserSkillDirectories(path, path.join(input.userHome, ".gemini")); |
260 | | - for (const [link, target] of [ |
261 | | - [links[0], targets[0]], |
262 | | - [links[1], targets[1]], |
| 263 | + const targets = antigravityUserSkillDirectories(path, userGemini); |
| 264 | + const directoryType = input.platform === "win32" ? "junction" : "dir"; |
| 265 | + for (const [link, target, type] of [ |
| 266 | + [links[0], targets[0], directoryType], |
| 267 | + [links[1], targets[1], directoryType], |
| 268 | + // File symlinks need elevation or Developer Mode on Windows, so rules are copied there. |
| 269 | + ...(input.platform === "win32" |
| 270 | + ? [] |
| 271 | + : antigravityUserRuleFiles.map( |
| 272 | + (name) => |
| 273 | + [path.join(input.profileDirectory, name), path.join(userGemini, name), "file"] as const, |
| 274 | + )), |
263 | 275 | ] as const) { |
264 | 276 | yield* Effect.gen(function* () { |
265 | 277 | // The harness creates these folders itself, and mkdir fails on a dangling link. |
@@ -292,19 +304,73 @@ const linkAntigravityUserSkills = Effect.fn("linkAntigravityUserSkills")(functio |
292 | 304 | } |
293 | 305 | yield* fs.makeDirectory(path.dirname(link), { recursive: true }); |
294 | 306 | yield* Effect.tryPromise({ |
295 | | - try: () => NodeFSP.symlink(target, link, input.platform === "win32" ? "junction" : "dir"), |
| 307 | + try: () => NodeFSP.symlink(target, link, type), |
296 | 308 | catch: (cause) => new AntigravitySkillLinkError({ link, cause }), |
297 | 309 | }); |
298 | 310 | }).pipe( |
299 | 311 | Effect.catch((error) => |
300 | | - Effect.logWarning("Antigravity user skills are not linked into the profile.", { |
| 312 | + Effect.logWarning("Antigravity user configuration is not linked into the profile.", { |
| 313 | + link, |
| 314 | + target, |
| 315 | + error, |
| 316 | + }), |
| 317 | + ), |
| 318 | + ); |
| 319 | + } |
| 320 | +}); |
| 321 | + |
| 322 | +const RuleCopiesJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.String)); |
| 323 | +const decodeRuleCopies = Schema.decodeUnknownOption(RuleCopiesJson); |
| 324 | +const encodeRuleCopies = Schema.encodeSync(RuleCopiesJson); |
| 325 | + |
| 326 | +/** Copies refresh each launch; the recorded copy keeps a file the profile owns or edited untouched. */ |
| 327 | +const copyAntigravityUserRuleFiles = Effect.fn("copyAntigravityUserRuleFiles")(function* (input: { |
| 328 | + readonly profileDirectory: string; |
| 329 | + readonly userHome: string; |
| 330 | +}): Effect.fn.Return<void, never, FileSystem.FileSystem | Path.Path> { |
| 331 | + const fs = yield* FileSystem.FileSystem; |
| 332 | + const path = yield* Path.Path; |
| 333 | + const manifestPath = path.join(input.profileDirectory, ".t3-rule-copies.json"); |
| 334 | + const readOptional = (file: string) => |
| 335 | + fs.readFileString(file).pipe(Effect.orElseSucceed((): string | undefined => undefined)); |
| 336 | + const manifestText = yield* readOptional(manifestPath); |
| 337 | + const copies: Record<string, string> = { |
| 338 | + ...Option.getOrElse(decodeRuleCopies(manifestText), () => ({})), |
| 339 | + }; |
| 340 | + for (const name of antigravityUserRuleFiles) { |
| 341 | + const link = path.join(input.profileDirectory, name); |
| 342 | + const target = path.join(input.userHome, ".gemini", name); |
| 343 | + yield* Effect.gen(function* () { |
| 344 | + const current = yield* readOptional(link); |
| 345 | + if (current !== undefined && current !== copies[name]) { |
| 346 | + delete copies[name]; |
| 347 | + return; |
| 348 | + } |
| 349 | + const source = yield* readOptional(target); |
| 350 | + if (source === undefined) { |
| 351 | + if (current !== undefined) yield* fs.remove(link); |
| 352 | + delete copies[name]; |
| 353 | + return; |
| 354 | + } |
| 355 | + yield* fs.writeFileString(link, source); |
| 356 | + copies[name] = source; |
| 357 | + }).pipe( |
| 358 | + Effect.catch((error) => |
| 359 | + Effect.logWarning("Antigravity user rules are not copied into the profile.", { |
301 | 360 | link, |
302 | 361 | target, |
303 | 362 | error, |
304 | 363 | }), |
305 | 364 | ), |
306 | 365 | ); |
307 | 366 | } |
| 367 | + yield* fs |
| 368 | + .writeFileString(manifestPath, encodeRuleCopies(copies)) |
| 369 | + .pipe( |
| 370 | + Effect.catch((error) => |
| 371 | + Effect.logWarning("Antigravity rule copy record could not be written.", { error }), |
| 372 | + ), |
| 373 | + ); |
308 | 374 | }); |
309 | 375 |
|
310 | 376 | export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(function* (input: { |
@@ -453,7 +519,10 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")( |
453 | 519 | authSupportError("The Antigravity profile settings could not be written."), |
454 | 520 | ), |
455 | 521 | ); |
456 | | - yield* linkAntigravityUserSkills({ profileDirectory: geminiHome, userHome, platform }); |
| 522 | + yield* linkAntigravityUserConfig({ profileDirectory: geminiHome, userHome, platform }); |
| 523 | + if (platform === "win32") { |
| 524 | + yield* copyAntigravityUserRuleFiles({ profileDirectory: geminiHome, userHome }); |
| 525 | + } |
457 | 526 | return profile; |
458 | 527 | }); |
459 | 528 |
|
|