Files
seal-use/src/core/embedded-skill.ts
T

88 lines
3.6 KiB
TypeScript

import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import skillMain from "../../skills/seal-use/SKILL.md" with { type: "text" };
import agentOpenAi from "../../skills/seal-use/agents/openai.yaml" with { type: "text" };
import refRuleLightweight from "../../skills/seal-use/references/rule-lightweight.md" with { type: "text" };
import refApprovalBadCases from "../../skills/seal-use/references/approval-bad-cases.md" with { type: "text" };
import refCli from "../../skills/seal-use/references/cli.md" with { type: "text" };
import refApprovalRunLightweight from "../../skills/seal-use/references/approval-run-lightweight.md" with { type: "text" };
import refApprovalAttachmentTrace from "../../skills/seal-use/references/approval-attachment-trace.md" with { type: "text" };
import refCustomerFeedbackRuleRemediation from "../../skills/seal-use/references/customer-feedback-rule-remediation.md" with { type: "text" };
import refEnterpriseOnboarding from "../../skills/seal-use/references/enterprise-onboarding.md" with { type: "text" };
import refHoseEnterpriseAuth from "../../skills/seal-use/references/hose-enterprise-auth.md" with { type: "text" };
import refHoseEnterpriseInit from "../../skills/seal-use/references/hose-enterprise-init.md" with { type: "text" };
export const EMBEDDED_SKILL_FILES: Record<string, string> = {
"SKILL.md": skillMain,
"agents/openai.yaml": agentOpenAi,
"references/rule-lightweight.md": refRuleLightweight,
"references/approval-bad-cases.md": refApprovalBadCases,
"references/cli.md": refCli,
"references/approval-run-lightweight.md": refApprovalRunLightweight,
"references/approval-attachment-trace.md": refApprovalAttachmentTrace,
"references/customer-feedback-rule-remediation.md": refCustomerFeedbackRuleRemediation,
"references/enterprise-onboarding.md": refEnterpriseOnboarding,
"references/hose-enterprise-auth.md": refHoseEnterpriseAuth,
"references/hose-enterprise-init.md": refHoseEnterpriseInit
};
export function getSkillContent(): string {
return EMBEDDED_SKILL_FILES["SKILL.md"] || "";
}
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);
}
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 };
}