Files
seal-use/src/core/embedded-skill.ts
T
gitea fb673f754e Add multi-host skill bridge for WorkBuddy, Claude, and Qoder
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.
2026-09-18 22:20:18 +08:00

110 lines
3.5 KiB
TypeScript

import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import {
EMBEDDED_SKILL_ASSET_DATA,
EMBEDDED_SKILL_TEXT_FILES
} from "./embedded-skill.generated.js";
export { EMBEDDED_SKILL_ALL_PATHS } from "./embedded-skill.generated.js";
export const EMBEDDED_SKILL_FILES = EMBEDDED_SKILL_TEXT_FILES;
export const EMBEDDED_SKILL_ASSETS: Record<string, Uint8Array> = Object.fromEntries(
Object.entries(EMBEDDED_SKILL_ASSET_DATA).map(([relPath, base64]) => [relPath, Buffer.from(base64, "base64")])
);
export function getSkillContent(): string {
return EMBEDDED_SKILL_FILES["SKILL.md"] || "";
}
/**
* Reads the `version:` field out of a SKILL.md front matter block.
*
* The skill is versioned separately from the code that reads it, and that separation is exactly
* how `seal-use update` shipped a stale skill across several releases: writing the file reported
* success either way, so the version is the only signal that says *which generation* of the
* document actually landed on disk.
*/
export function parseSkillVersion(markdown: string): string | undefined {
return markdown.match(/^\s*version:\s*(\S+)\s*$/m)?.[1];
}
/** Reads the version of an installed SKILL.md, or `undefined` when it is missing or unreadable. */
export function readInstalledSkillVersion(
skillFile: string = join(getDefaultGlobalSkillDir(), "SKILL.md")
): string | undefined {
try {
return parseSkillVersion(readFileSync(skillFile, "utf8"));
} catch {
return undefined;
}
}
/** The version of the skill compiled into this build, used to assert what an install wrote. */
export const EMBEDDED_SKILL_VERSION = parseSkillVersion(getSkillContent());
export function getDefaultGlobalSkillDir(): string {
return join(homedir(), ".agents", "skills", "seal-use");
}
function getLegacyGlobalSkillDir(): string {
return join(homedir(), ".agents", "skills", "seal-home");
}
function cleanLegacySkillDir(): boolean {
const legacyDir = getLegacyGlobalSkillDir();
if (existsSync(legacyDir)) {
try {
rmSync(legacyDir, { recursive: true, force: true });
return true;
} catch {
return false;
}
}
return false;
}
export function installSkillFiles(targetDir: string = getDefaultGlobalSkillDir()): { targetDir: string; files: string[] } {
cleanLegacySkillDir();
mkdirSync(targetDir, { recursive: true });
const installed: string[] = [];
for (const [relPath, content] of Object.entries(EMBEDDED_SKILL_FILES)) {
const fullPath = join(targetDir, relPath);
mkdirSync(dirname(fullPath), { recursive: true });
writeFileSync(fullPath, content, "utf8");
installed.push(relPath);
}
for (const [relPath, content] of Object.entries(EMBEDDED_SKILL_ASSETS)) {
const fullPath = join(targetDir, relPath);
mkdirSync(dirname(fullPath), { recursive: true });
writeFileSync(fullPath, content);
installed.push(relPath);
}
return {
targetDir,
files: installed
};
}
export function syncGlobalSkillIfPresent(): { synced: boolean; targetDir?: string } {
const legacyDir = getLegacyGlobalSkillDir();
const globalDir = getDefaultGlobalSkillDir();
const hadLegacy = existsSync(legacyDir);
const hadCurrent = existsSync(globalDir);
if (hadLegacy || hadCurrent) {
cleanLegacySkillDir();
installSkillFiles(globalDir);
return { synced: true, targetDir: globalDir };
}
return { synced: false };
}
// Re-export agent host skill bridging capabilities
export * from "./agent-hosts/index.js";