mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 09:51:22 +00:00
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { loadSkillsFromDir } from "@mariozechner/pi-coding-agent";
|
|
import { createSubsystemLogger } from "../../logging/subsystem.js";
|
|
import { resolveBundledSkillsDir, type BundledSkillsResolveOptions } from "./bundled-dir.js";
|
|
|
|
const skillsLogger = createSubsystemLogger("skills");
|
|
let hasWarnedMissingBundledDir = false;
|
|
let cachedBundledContext: { dir: string; names: Set<string> } | null = null;
|
|
|
|
export type BundledSkillsContext = {
|
|
dir?: string;
|
|
names: Set<string>;
|
|
};
|
|
|
|
export function resolveBundledSkillsContext(
|
|
opts: BundledSkillsResolveOptions = {},
|
|
): BundledSkillsContext {
|
|
const dir = resolveBundledSkillsDir(opts);
|
|
const names = new Set<string>();
|
|
if (!dir) {
|
|
if (!hasWarnedMissingBundledDir) {
|
|
hasWarnedMissingBundledDir = true;
|
|
skillsLogger.warn(
|
|
"Bundled skills directory could not be resolved; built-in skills may be missing.",
|
|
);
|
|
}
|
|
return { dir, names };
|
|
}
|
|
|
|
if (cachedBundledContext?.dir === dir) {
|
|
return { dir, names: new Set(cachedBundledContext.names) };
|
|
}
|
|
const result = loadSkillsFromDir({ dir, source: "openclaw-bundled" });
|
|
for (const skill of result.skills) {
|
|
if (skill.name.trim()) {
|
|
names.add(skill.name);
|
|
}
|
|
}
|
|
cachedBundledContext = { dir, names: new Set(names) };
|
|
return { dir, names };
|
|
}
|