Register MANIFEST paths.localSkills alongside pack _skills.

Parse packaging-generated paths and load each local_skills/*/SKILL.md with the same hasSkills toggles and provider as shared packs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-09-15 08:23:05 +08:00
parent 6dee69be31
commit 53c47fbc6a
18 changed files with 662 additions and 156 deletions

View file

@ -240,7 +240,8 @@ function skillBody(snapshot) {
"Environment mirrors: KB_ROOT, KB_OPERATOR, KB_COUNTRY, KB_VERSION, KB_CONTENT, KB_STATUS.",
"",
"Business playbooks (kb-troubleshoot, kb-retrieve, …) register from",
`${snapshot.realRoot}/_skills/ when hasSkills is true — use those skills for KB triage;`,
`${snapshot.realRoot}/_skills/ (or MANIFEST paths.skills) when hasSkills is true,`,
"plus paths.localSkills when present — use those skills for KB triage;",
"keep netx-ops for live netx evidence only."
].join(`
`)
@ -282,24 +283,29 @@ import { join as join2 } from "node:path";
function kbPackSkillsEnabled(snapshot) {
return snapshot.status === "configured" && snapshot.content.hasSkills === true;
}
async function registerKbPackSkills(ctx, snapshot, options) {
if (!options.enabled || !kbPackSkillsEnabled(snapshot)) {
return () => {};
}
const skillsApi = ctx.skills;
if (!skillsApi || typeof skillsApi.register !== "function") {
return () => {};
}
const root = join2(snapshot.realRoot, "_skills");
function resolveKbSkillsRoot(snapshot) {
const rel = snapshot.paths.skills?.trim() || "_skills";
return join2(snapshot.realRoot, rel);
}
function resolveKbLocalSkillsRoot(snapshot) {
const rel = snapshot.paths.localSkills?.trim();
if (!rel)
return null;
return join2(snapshot.realRoot, rel);
}
async function registerSkillsUnderRoot(ctx, skillsApi, root, provider, options) {
let entries;
try {
entries = await readdir2(root);
} catch {
ctx.logger.info("netxops: kb pack skills dir missing at %s — skip", root);
return () => {};
if (options.logMissing) {
ctx.logger.info("netxops: kb %s dir missing at %s — skip", options.label, root);
}
return [];
}
if (entries.length === 0)
return [];
const disposers = [];
const provider = options.providerLabel ?? "netxops-kb-pack";
for (const entry of entries) {
const full = join2(root, entry);
let isDir = false;
@ -314,11 +320,11 @@ async function registerKbPackSkills(ctx, snapshot, options) {
try {
skill = await loadSkillBundle(full);
} catch (error) {
ctx.logger.warn("netxops: kb pack skill load failed at %s: %s", full, error instanceof Error ? error.message : String(error));
ctx.logger.warn("netxops: kb %s skill load failed at %s: %s", options.label, full, error instanceof Error ? error.message : String(error));
continue;
}
if (!skill) {
ctx.logger.warn("netxops: kb pack skill skipped (invalid SKILL.md): %s", full);
ctx.logger.warn("netxops: kb %s skill skipped (invalid SKILL.md): %s", options.label, full);
continue;
}
disposers.push(skillsApi.register({
@ -331,8 +337,32 @@ async function registerKbPackSkills(ctx, snapshot, options) {
source: "custom"
}));
}
return disposers;
}
async function registerKbPackSkills(ctx, snapshot, options) {
if (!options.enabled || !kbPackSkillsEnabled(snapshot)) {
return () => {};
}
const skillsApi = ctx.skills;
if (!skillsApi || typeof skillsApi.register !== "function") {
return () => {};
}
const provider = options.providerLabel ?? "netxops-kb-pack";
const disposers = [];
const skillsRoot = resolveKbSkillsRoot(snapshot);
disposers.push(...await registerSkillsUnderRoot(ctx, skillsApi, skillsRoot, provider, {
logMissing: true,
label: "pack"
}));
const localRoot = resolveKbLocalSkillsRoot(snapshot);
if (localRoot) {
disposers.push(...await registerSkillsUnderRoot(ctx, skillsApi, localRoot, provider, {
logMissing: false,
label: "local"
}));
}
if (disposers.length > 0) {
ctx.logger.info("netxops: kb pack skills registered count=%s root=%s provider=%s", disposers.length, root, provider);
ctx.logger.info("netxops: kb pack skills registered count=%s skillsRoot=%s localSkills=%s provider=%s", disposers.length, skillsRoot, localRoot ?? "(none)", provider);
}
return () => {
for (const dispose of disposers)
@ -356,6 +386,7 @@ function unconfiguredKbSnapshot() {
country: "",
version: "",
content: { ...EMPTY_CONTENT },
paths: {},
errorMessage: ""
};
}
@ -372,7 +403,12 @@ function store() {
return current;
}
function getKbContext() {
return { ...store().snapshot, content: { ...store().snapshot.content } };
const snap = store().snapshot;
return {
...snap,
content: { ...snap.content },
paths: { ...snap.paths }
};
}
function watchKbContext(listener) {
const state = store();