mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-17 03:10:38 +09:00
Fix runtime skill injection across adapters
This commit is contained in:
parent
82f253c310
commit
7675fd0856
27 changed files with 506 additions and 222 deletions
|
|
@ -15,8 +15,8 @@ import {
|
|||
ensureCommandResolvable,
|
||||
ensurePaperclipSkillSymlink,
|
||||
ensurePathInEnv,
|
||||
listPaperclipSkillEntries,
|
||||
readPaperclipSkillSyncPreference,
|
||||
readPaperclipRuntimeSkillEntries,
|
||||
resolvePaperclipDesiredSkillNames,
|
||||
removeMaintainerOnlySkillSymlinks,
|
||||
renderTemplate,
|
||||
runChildProcess,
|
||||
|
|
@ -53,18 +53,18 @@ function parseModelId(model: string | null): string | null {
|
|||
|
||||
async function ensurePiSkillsInjected(
|
||||
onLog: AdapterExecutionContext["onLog"],
|
||||
skillsEntries: Array<{ name: string; source: string }>,
|
||||
desiredSkillNames?: string[],
|
||||
) {
|
||||
const allSkillsEntries = await listPaperclipSkillEntries(__moduleDir);
|
||||
const desiredSet = new Set(desiredSkillNames ?? allSkillsEntries.map((entry) => entry.name));
|
||||
const skillsEntries = allSkillsEntries.filter((entry) => desiredSet.has(entry.name));
|
||||
if (skillsEntries.length === 0) return;
|
||||
const desiredSet = new Set(desiredSkillNames ?? skillsEntries.map((entry) => entry.name));
|
||||
const selectedEntries = skillsEntries.filter((entry) => desiredSet.has(entry.name));
|
||||
if (selectedEntries.length === 0) return;
|
||||
|
||||
const piSkillsHome = path.join(os.homedir(), ".pi", "agent", "skills");
|
||||
await fs.mkdir(piSkillsHome, { recursive: true });
|
||||
const removedSkills = await removeMaintainerOnlySkillSymlinks(
|
||||
piSkillsHome,
|
||||
skillsEntries.map((entry) => entry.name),
|
||||
selectedEntries.map((entry) => entry.name),
|
||||
);
|
||||
for (const skillName of removedSkills) {
|
||||
await onLog(
|
||||
|
|
@ -73,7 +73,7 @@ async function ensurePiSkillsInjected(
|
|||
);
|
||||
}
|
||||
|
||||
for (const entry of skillsEntries) {
|
||||
for (const entry of selectedEntries) {
|
||||
const target = path.join(piSkillsHome, entry.name);
|
||||
|
||||
try {
|
||||
|
|
@ -139,12 +139,9 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
|
|||
await ensureSessionsDir();
|
||||
|
||||
// Inject skills
|
||||
const piSkillEntries = await listPaperclipSkillEntries(__moduleDir);
|
||||
const piPreference = readPaperclipSkillSyncPreference(config);
|
||||
const desiredPiSkillNames = piPreference.explicit
|
||||
? piPreference.desiredSkills
|
||||
: piSkillEntries.map((entry) => entry.name);
|
||||
await ensurePiSkillsInjected(onLog, desiredPiSkillNames);
|
||||
const piSkillEntries = await readPaperclipRuntimeSkillEntries(config, __moduleDir);
|
||||
const desiredPiSkillNames = resolvePaperclipDesiredSkillNames(config, piSkillEntries);
|
||||
await ensurePiSkillsInjected(onLog, piSkillEntries, desiredPiSkillNames);
|
||||
|
||||
// Build environment
|
||||
const envConfig = parseObject(config.env);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import type {
|
|||
} from "@paperclipai/adapter-utils";
|
||||
import {
|
||||
ensurePaperclipSkillSymlink,
|
||||
listPaperclipSkillEntries,
|
||||
readPaperclipSkillSyncPreference,
|
||||
readPaperclipRuntimeSkillEntries,
|
||||
resolvePaperclipDesiredSkillNames,
|
||||
} from "@paperclipai/adapter-utils/server-utils";
|
||||
|
||||
const __moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
|
@ -29,11 +29,6 @@ function resolvePiSkillsHome(config: Record<string, unknown>) {
|
|||
return path.join(home, ".pi", "agent", "skills");
|
||||
}
|
||||
|
||||
function resolveDesiredSkillNames(config: Record<string, unknown>, availableSkillNames: string[]) {
|
||||
const preference = readPaperclipSkillSyncPreference(config);
|
||||
return preference.explicit ? preference.desiredSkills : availableSkillNames;
|
||||
}
|
||||
|
||||
async function readInstalledSkillTargets(skillsHome: string) {
|
||||
const entries = await fs.readdir(skillsHome, { withFileTypes: true }).catch(() => []);
|
||||
const out = new Map<string, { targetPath: string | null; kind: "symlink" | "directory" | "file" }>();
|
||||
|
|
@ -57,12 +52,9 @@ async function readInstalledSkillTargets(skillsHome: string) {
|
|||
}
|
||||
|
||||
async function buildPiSkillSnapshot(config: Record<string, unknown>): Promise<AdapterSkillSnapshot> {
|
||||
const availableEntries = await listPaperclipSkillEntries(__moduleDir);
|
||||
const availableEntries = await readPaperclipRuntimeSkillEntries(config, __moduleDir);
|
||||
const availableByName = new Map(availableEntries.map((entry) => [entry.name, entry]));
|
||||
const desiredSkills = resolveDesiredSkillNames(
|
||||
config,
|
||||
availableEntries.map((entry) => entry.name),
|
||||
);
|
||||
const desiredSkills = resolvePaperclipDesiredSkillNames(config, availableEntries);
|
||||
const desiredSet = new Set(desiredSkills);
|
||||
const skillsHome = resolvePiSkillsHome(config);
|
||||
const installed = await readInstalledSkillTargets(skillsHome);
|
||||
|
|
@ -97,6 +89,8 @@ async function buildPiSkillSnapshot(config: Record<string, unknown>): Promise<Ad
|
|||
sourcePath: available.source,
|
||||
targetPath: path.join(skillsHome, available.name),
|
||||
detail,
|
||||
required: Boolean(available.required),
|
||||
requiredReason: available.requiredReason ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -147,8 +141,11 @@ export async function syncPiSkills(
|
|||
ctx: AdapterSkillContext,
|
||||
desiredSkills: string[],
|
||||
): Promise<AdapterSkillSnapshot> {
|
||||
const availableEntries = await listPaperclipSkillEntries(__moduleDir);
|
||||
const desiredSet = new Set(desiredSkills);
|
||||
const availableEntries = await readPaperclipRuntimeSkillEntries(ctx.config, __moduleDir);
|
||||
const desiredSet = new Set([
|
||||
...desiredSkills,
|
||||
...availableEntries.filter((entry) => entry.required).map((entry) => entry.name),
|
||||
]);
|
||||
const skillsHome = resolvePiSkillsHome(ctx.config);
|
||||
await fs.mkdir(skillsHome, { recursive: true });
|
||||
const installed = await readInstalledSkillTargets(skillsHome);
|
||||
|
|
@ -173,7 +170,7 @@ export async function syncPiSkills(
|
|||
|
||||
export function resolvePiDesiredSkillNames(
|
||||
config: Record<string, unknown>,
|
||||
availableSkillNames: string[],
|
||||
availableEntries: Array<{ name: string; required?: boolean }>,
|
||||
) {
|
||||
return resolveDesiredSkillNames(config, availableSkillNames);
|
||||
return resolvePaperclipDesiredSkillNames(config, availableEntries);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue