Decouple agent host skill bridging into dedicated module src/core/agent-hosts/: - antigravity.ts: manage ~/.gemini/config/skills.json - symlink-hosts.ts: detect and bridge ~/.workbuddy, ~/.claude, and ~/.qoder - types.ts: explicit types for host results and statuses - agent-hosts.test.ts: isolated unit tests for host discovery and symlinks Respect existing parent symlinks, replace legacy real directories safely, prevent dotfile pollution by only acting when host roots exist, and expose unified hosts array in seal-use skill install & status.
128 lines
3.5 KiB
TypeScript
128 lines
3.5 KiB
TypeScript
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { homedir } from "node:os";
|
|
import { dirname, join } from "node:path";
|
|
import type { AntigravitySkillsStatus, AntigravitySkillsSyncResult } from "./types.js";
|
|
|
|
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
|
|
};
|
|
}
|