@@ -8,6 +8,7 @@ import * as Digest from "effect/crypto/Digest";
88import * as Effect from "effect/Effect" ;
99import * as Hex from "effect/encoding/Hex" ;
1010import * as FileSystem from "effect/FileSystem" ;
11+ import * as Option from "effect/Option" ;
1112import * as Path from "effect/Path" ;
1213import type * as PlatformError from "effect/PlatformError" ;
1314import * as Schema from "effect/Schema" ;
@@ -243,23 +244,34 @@ class AntigravitySkillLinkError extends Schema.TaggedError<AntigravitySkillLinkE
243244 { link : Schema . String , cause : Schema . Defect ( ) } ,
244245) {
245246 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 } .` ;
247248 }
248249}
249250
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 : {
252255 readonly profileDirectory : string ;
253256 readonly userHome : string ;
254257 readonly platform : NodeJS . Platform ;
255258} ) : Effect . fn . Return < void , never , FileSystem . FileSystem | Path . Path > {
256259 const fs = yield * FileSystem . FileSystem ;
257260 const path = yield * Path . Path ;
261+ const userGemini = path . join ( input . userHome , ".gemini" ) ;
258262 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+ ) ) ,
263275 ] as const ) {
264276 yield * Effect . gen ( function * ( ) {
265277 // The harness creates these folders itself, and mkdir fails on a dangling link.
@@ -292,19 +304,73 @@ const linkAntigravityUserSkills = Effect.fn("linkAntigravityUserSkills")(functio
292304 }
293305 yield * fs . makeDirectory ( path . dirname ( link ) , { recursive : true } ) ;
294306 yield * Effect . tryPromise ( {
295- try : ( ) => NodeFSP . symlink ( target , link , input . platform === "win32" ? "junction" : "dir" ) ,
307+ try : ( ) => NodeFSP . symlink ( target , link , type ) ,
296308 catch : ( cause ) => new AntigravitySkillLinkError ( { link, cause } ) ,
297309 } ) ;
298310 } ) . pipe (
299311 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." , {
301360 link,
302361 target,
303362 error,
304363 } ) ,
305364 ) ,
306365 ) ;
307366 }
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+ ) ;
308374} ) ;
309375
310376export const prepareAntigravityProfile = Effect . fn ( "prepareAntigravityProfile" ) ( function * ( input : {
@@ -453,7 +519,10 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(
453519 authSupportError ( "The Antigravity profile settings could not be written." ) ,
454520 ) ,
455521 ) ;
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+ }
457526 return profile ;
458527} ) ;
459528
0 commit comments