Add Antigravity global skills config sync to skill commands
Sync ~/.gemini/config/skills.json to include the user's absolute global agents skills directory (~/.agents/skills) upon global skill install, and expose Antigravity status in skill status. - Prepend the absolute path to entries if not already present - Migrate legacy tilde path to absolute path to ensure discovery - Avoid modifying config if target path is already registered - Provide unit tests covering creation, deduplication, and prepend
This commit is contained in:
1 parent
eb77ca1aef
commit
ee4cb332d9
3 files changed
+258
-5
No files matched your search
@@ -104,3 +104,142 @@ export function syncGlobalSkillIfPresent(): { synced: boolean; targetDir?: strin
|
||||
|
||||
return { synced: false };
|
||||
}
|
||||
|
||||
export type AntigravitySkillsSyncResult = {
|
||||
detected: boolean;
|
||||
configured: boolean;
|
||||
configPath: string;
|
||||
targetDir: string;
|
||||
action: "created" | "prepended" | "already_present" | "updated_tilde";
|
||||
};
|
||||
|
||||
export type AntigravitySkillsStatus = {
|
||||
detected: boolean;
|
||||
configured: boolean;
|
||||
configPath: string;
|
||||
targetDir: string;
|
||||
};
|
||||
|
||||
export function getGlobalAgentsSkillsDir(): string {
|
||||
return join(homedir(), ".agents", "skills");
|
||||
}
|
||||
|
||||
export function getAntigravitySkillsConfigFile(): string {
|
||||
return join(homedir(), ".gemini", "config", "skills.json");
|
||||
}
|
||||
|
||||
export function isAntigravityDetected(): boolean {
|
||||
const home = homedir();
|
||||
return (
|
||||
existsSync(join(home, ".gemini", "antigravity")) ||
|
||||
existsSync(join(home, ".gemini", "antigravity-cli")) ||
|
||||
existsSync(join(home, ".local", "bin", "agy"))
|
||||
);
|
||||
}
|
||||
|
||||
export function syncAntigravitySkillsConfig(options?: {
|
||||
configFile?: string;
|
||||
targetSkillsDir?: string;
|
||||
}): AntigravitySkillsSyncResult {
|
||||
const targetDir = options?.targetSkillsDir ?? getGlobalAgentsSkillsDir();
|
||||
const configPath = options?.configFile ?? getAntigravitySkillsConfigFile();
|
||||
const detected = isAntigravityDetected();
|
||||
|
||||
if (!existsSync(configPath)) {
|
||||
mkdirSync(dirname(configPath), { recursive: true });
|
||||
const initialConfig = {
|
||||
entries: [{ path: targetDir }]
|
||||
};
|
||||
writeFileSync(configPath, JSON.stringify(initialConfig, null, 2) + "\n", "utf8");
|
||||
return {
|
||||
detected,
|
||||
configured: true,
|
||||
configPath,
|
||||
targetDir,
|
||||
action: "created"
|
||||
};
|
||||
}
|
||||
|
||||
let parsed: { entries?: Array<{ path?: string; [key: string]: unknown }>; [key: string]: unknown } = {};
|
||||
try {
|
||||
parsed = JSON.parse(readFileSync(configPath, "utf8"));
|
||||
} catch {
|
||||
parsed = { entries: [] };
|
||||
}
|
||||
|
||||
if (!Array.isArray(parsed.entries)) {
|
||||
parsed.entries = [];
|
||||
}
|
||||
|
||||
const exactIndex = parsed.entries.findIndex(
|
||||
(entry) => entry && typeof entry.path === "string" && entry.path === targetDir
|
||||
);
|
||||
if (exactIndex !== -1) {
|
||||
return {
|
||||
detected,
|
||||
configured: true,
|
||||
configPath,
|
||||
targetDir,
|
||||
action: "already_present"
|
||||
};
|
||||
}
|
||||
|
||||
const tildeIndex = parsed.entries.findIndex(
|
||||
(entry) =>
|
||||
entry &&
|
||||
typeof entry.path === "string" &&
|
||||
(entry.path === "~/.agents/skills" || entry.path === "~/.agents/skills/")
|
||||
);
|
||||
if (tildeIndex !== -1) {
|
||||
parsed.entries[tildeIndex] = { ...parsed.entries[tildeIndex], path: targetDir };
|
||||
writeFileSync(configPath, JSON.stringify(parsed, null, 2) + "\n", "utf8");
|
||||
return {
|
||||
detected,
|
||||
configured: true,
|
||||
configPath,
|
||||
targetDir,
|
||||
action: "updated_tilde"
|
||||
};
|
||||
}
|
||||
|
||||
parsed.entries.unshift({ path: targetDir });
|
||||
writeFileSync(configPath, JSON.stringify(parsed, null, 2) + "\n", "utf8");
|
||||
return {
|
||||
detected,
|
||||
configured: true,
|
||||
configPath,
|
||||
targetDir,
|
||||
action: "prepended"
|
||||
};
|
||||
}
|
||||
|
||||
export function getAntigravitySkillsStatus(options?: {
|
||||
configFile?: string;
|
||||
targetSkillsDir?: string;
|
||||
}): AntigravitySkillsStatus {
|
||||
const targetDir = options?.targetSkillsDir ?? getGlobalAgentsSkillsDir();
|
||||
const configPath = options?.configFile ?? getAntigravitySkillsConfigFile();
|
||||
const detected = isAntigravityDetected();
|
||||
let configured = false;
|
||||
|
||||
if (existsSync(configPath)) {
|
||||
try {
|
||||
const parsed = JSON.parse(readFileSync(configPath, "utf8"));
|
||||
if (Array.isArray(parsed?.entries)) {
|
||||
configured = parsed.entries.some(
|
||||
(e: { path?: string }) => e?.path === targetDir
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
detected,
|
||||
configured,
|
||||
configPath,
|
||||
targetDir
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user