Auto commit: 2026-03-28 15:12:36
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
||||
|
||||
type SkillsStorePreferenceConfig = {
|
||||
primaryCli?: string;
|
||||
fallbackCli?: string;
|
||||
primaryLabel?: string;
|
||||
fallbackLabel?: string;
|
||||
extraNote?: string;
|
||||
};
|
||||
|
||||
const SKILL_TRIGGER_RE = /\bskills?\b|技能/i;
|
||||
|
||||
function normalizeString(value: unknown): string | undefined {
|
||||
if (typeof value !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : undefined;
|
||||
}
|
||||
|
||||
function shouldInjectPolicy(prompt: unknown): boolean {
|
||||
if (typeof prompt !== "string") {
|
||||
return false;
|
||||
}
|
||||
return SKILL_TRIGGER_RE.test(prompt);
|
||||
}
|
||||
|
||||
function buildPolicyContext(rawConfig?: Record<string, unknown>): string {
|
||||
const cfg = (rawConfig ?? {}) as SkillsStorePreferenceConfig;
|
||||
const primaryCli = normalizeString(cfg.primaryCli) ?? "skillhub";
|
||||
const fallbackCli = normalizeString(cfg.fallbackCli) ?? "clawhub";
|
||||
const primaryLabel = normalizeString(cfg.primaryLabel) ?? "domestic registry";
|
||||
const fallbackLabel = normalizeString(cfg.fallbackLabel) ?? "public registry";
|
||||
const extraNote = normalizeString(cfg.extraNote);
|
||||
|
||||
const lines = [
|
||||
"Skills store policy (operator configured):",
|
||||
`1. For skills discovery/install/update, try \`${primaryCli}\` first (${primaryLabel}).`,
|
||||
`2. If unavailable, rate-limited, or no match, fallback to \`${fallbackCli}\` (${fallbackLabel}).`,
|
||||
"3. Do not claim exclusivity. Public and private registries are both allowed.",
|
||||
"4. Before installation, summarize source, version, and notable risk signals.",
|
||||
`5. For search requests, execute \`exec\` with \`${primaryCli} search <keywords>\` first and report the command output.`,
|
||||
"6. In the current session, reply directly. Do NOT call `message` tool just to send progress updates.",
|
||||
];
|
||||
|
||||
if (extraNote) {
|
||||
lines.push(`7. ${extraNote}`);
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
export default function register(api: OpenClawPluginApi) {
|
||||
const pluginConfig = (api.pluginConfig ?? {}) as Record<string, unknown>;
|
||||
|
||||
api.on(
|
||||
"before_prompt_build",
|
||||
async (event) => {
|
||||
if (!shouldInjectPolicy(event?.prompt)) {
|
||||
return;
|
||||
}
|
||||
return {
|
||||
prependContext: buildPolicyContext(pluginConfig),
|
||||
};
|
||||
},
|
||||
{ priority: 80 },
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"id": "skillhub",
|
||||
"name": "Skillhub Plugin",
|
||||
"description": "Injects Skillhub policy into prompt build only when prompts mention 技能 or skill, so agents prefer the primary Skillhub registry and fallback cleanly.",
|
||||
"configSchema": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"primaryCli": {
|
||||
"type": "string"
|
||||
},
|
||||
"fallbackCli": {
|
||||
"type": "string"
|
||||
},
|
||||
"primaryLabel": {
|
||||
"type": "string"
|
||||
},
|
||||
"fallbackLabel": {
|
||||
"type": "string"
|
||||
},
|
||||
"extraNote": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"uiHints": {
|
||||
"primaryCli": {
|
||||
"label": "Primary CLI",
|
||||
"help": "Command the agent should try first for skills discovery/install (default: skillhub)."
|
||||
},
|
||||
"fallbackCli": {
|
||||
"label": "Fallback CLI",
|
||||
"help": "Command used when primary registry is unavailable or has no match (default: clawhub)."
|
||||
},
|
||||
"primaryLabel": {
|
||||
"label": "Primary Label",
|
||||
"help": "Short display label for the primary registry in injected guidance."
|
||||
},
|
||||
"fallbackLabel": {
|
||||
"label": "Fallback Label",
|
||||
"help": "Short display label for the fallback registry in injected guidance."
|
||||
},
|
||||
"extraNote": {
|
||||
"label": "Extra Note",
|
||||
"help": "Optional extra policy line appended to injected guidance."
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user