mirror of
https://github.com/vercel/vercel-plugin.git
synced 2026-09-14 15:39:47 +08:00
8d4fda5a60
Align the shipped architecture around engine-native rules and the zero-bundle runtime so orchestration, documentation, and maintenance all reflect the same source of truth. Remove the pre-engine build and template pipeline to eliminate dead paths that were masking drift and making test failures harder to reason about. Make session-start installation honor registry-backed skills accurately, including per-registry grouping and alias slugs, so first-session cache warming can produce a usable zero-bundle cache instead of leaving mapped skills unresolved. Update doctor coverage and supporting tests so the orchestrator branch catches hook-registration regressions and cache-resolution mistakes before release. Ploop-Iter: 1
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
// hooks/src/registry-skill-metadata.mts
|
|
import { existsSync, readFileSync } from "fs";
|
|
import { join } from "path";
|
|
import { pluginRoot as resolvePluginRoot } from "./hook-env.mjs";
|
|
function loadRegistrySkillMetadata(rootDir = resolvePluginRoot()) {
|
|
const metadata = /* @__PURE__ */ new Map();
|
|
const manifestPaths = [
|
|
join(rootDir, "generated", "skill-rules.json"),
|
|
join(rootDir, "..", "generated", "skill-rules.json")
|
|
];
|
|
const manifestPath = manifestPaths.find((candidate) => existsSync(candidate));
|
|
if (!manifestPath) {
|
|
return metadata;
|
|
}
|
|
try {
|
|
const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
for (const [skill, raw] of Object.entries(manifest.skills ?? {})) {
|
|
if (typeof raw.registry !== "string" || raw.registry.trim() === "") continue;
|
|
metadata.set(skill, {
|
|
registry: raw.registry,
|
|
registrySlug: typeof raw.registrySlug === "string" && raw.registrySlug.trim() !== "" ? raw.registrySlug : skill
|
|
});
|
|
}
|
|
} catch {
|
|
return metadata;
|
|
}
|
|
return metadata;
|
|
}
|
|
function buildRegistryAliasMap(rootDir = resolvePluginRoot()) {
|
|
const aliases = /* @__PURE__ */ new Map();
|
|
for (const [skill, metadata] of loadRegistrySkillMetadata(rootDir)) {
|
|
if (metadata.registrySlug !== skill) {
|
|
aliases.set(metadata.registrySlug, skill);
|
|
}
|
|
}
|
|
return aliases;
|
|
}
|
|
function canonicalizeInstalledSkillNames(skillNames, rootDir = resolvePluginRoot()) {
|
|
const aliases = buildRegistryAliasMap(rootDir);
|
|
return [...new Set(skillNames.map((skill) => aliases.get(skill) ?? skill))].sort();
|
|
}
|
|
export {
|
|
buildRegistryAliasMap,
|
|
canonicalizeInstalledSkillNames,
|
|
loadRegistrySkillMetadata
|
|
};
|