Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(skills): enhance metadata and config system for OpenClaw compatibility

Jiang Bohan00915d7fb90e
diff --git a/src/agent/skills/eligibility.ts b/src/agent/skills/eligibility.ts
index dab295dd39..f86bec3bd9 100644
--- a/src/agent/skills/eligibility.ts
+++ b/src/agent/skills/eligibility.ts
@@ -1,11 +1,26 @@
/**
* Skill Eligibility Checker
*
- * Filter skills based on platform, binaries, and environment requirements
+ * Filter skills based on platform, binaries, environment, and configuration
+ * Compatible with OpenClaw eligibility rules
*/
import { execSync } from "node:child_process";
-import type { Skill, EligibilityResult } from "./types.js";
+import type {
+ Skill,
+ SkillsConfig,
+ EligibilityResult,
+} from "./types.js";
+import {
+ getSkillKey,
+ getSkillConfig,
+ normalizeRequirements,
+ normalizePlatforms,
+} from "./types.js";
+
+// ============================================================================
+// Binary and Environment Checks
+// ============================================================================
/**
* Check if a binary exists in PATH
@@ -13,7 +28,7 @@ import type { Skill, EligibilityResult } from "./types.js";
* @param binary - Binary name to check
* @returns True if binary exists
*/
-function binaryExists(binary: string): boolean {
+export function binaryExists(binary: string): boolean {
try {
// Use 'which' on Unix, 'where' on Windows
const cmd = process.platform === "win32" ? `where ${binary}` : `which ${binary}`;
@@ -34,48 +49,201 @@ function envExists(envVar: string): boolean {
return envVar in process.env;
}
+// ============================================================================
+// Config Path Resolution
+// ============================================================================
+
+/**
+ * Resolve a dot-separated config path
+ *
+ * @param config - Config object
+ * @param pathStr - Dot-separated path (e.g., "browser.enabled")
+ * @returns The value at the path, or undefined
+ */
+export function resolveConfigPath(
+ config: Record<string, unknown> | undefined,
+ pathStr: string,
+): unknown {
+ if (!config) return undefined;
+
+ const parts = pathStr.split(".").filter(Boolean);
+ let current: unknown = config;
+
+ for (const part of parts) {
+ if (typeof current !== "object" || current === null) {
+ return undefined;
+ }
+ current = (current as Record<string, unknown>)[part];
+ }
+
+ return current;
+}
+
+/**
+ * Check if a config path is truthy
+ *
+ * @param config - Config object
+ * @param pathStr - Dot-separated path
+ * @returns True if the value at path is truthy
+ */
+export function isConfigPathTruthy(
+ config: Record<string, unknown> | undefined,
+ pathStr: string,
+): boolean {
+ const value = resolveConfigPath(config, pathStr);
+ if (value === undefined || value === null) return false;
+ if (typeof value === "boolean") return value;
+ if (typeof value === "number") return value !== 0;
+ if (typeof value === "string") return value.trim().length > 0;
+ return true;
+}
+
+// ============================================================================
+// Bundled Skills Allowlist
+// ============================================================================
+
+const BUNDLED_SOURCES = new Set(["bundled"]);
+
+/**
+ * Check if a skill is from bundled source
+ */
+function isBundledSkill(skill: Skill): boolean {
+ return BUNDLED_SOURCES.has(skill.source);
+}
+
/**
- * Check if a skill is eligible based on its requirements
+ * Check if a bundled skill is allowed by the allowlist
*
* @param skill - Skill to check
- * @param platform - Platform to check against (defaults to current)
+ * @param allowlist - List of allowed skill keys (undefined = allow all)
+ * @returns True if allowed
+ */
+function isBundledSkillAllowed(skill: Skill, allowlist?: string[]): boolean {
+ // No allowlist = allow all
+ if (!allowlist || allowlist.length === 0) return true;
+ // Non-bundled skills are always allowed
+ if (!isBundledSkill(skill)) return true;
+ // Check if skill key or id is in allowlist
+ const key = getSkillKey(skill);
+ return allowlist.includes(key) || allowlist.includes(skill.id);
+}
+
+// ============================================================================
+// Main Eligibility Check
+// ============================================================================
+
+export interface EligibilityContext {
+ /** Skills configuration */
+ config?: SkillsConfig | undefined;
+ /** Platform to check against (defaults to current) */
+ platform?: NodeJS.Platform | undefined;
+ /** Custom config object for config path checks */
+ customConfig?: Record<string, unknown> | undefined;
+}
+
+/**
+ * Check if a skill is eligible based on its requirements and configuration
+ *
+ * Eligibility rules (in order):
+ * 1. If explicitly disabled in config → not eligible
+ * 2. If bundled and not in allowlist → not eligible
+ * 3. If platform not supported → not eligible
+ * 4. If metadata.always is true → eligible (skip remaining checks)
+ * 5. All required binaries must exist
+ * 6. At least one of anyBins must exist (if specified)
+ * 7. All required env vars must be set (or provided via config)
+ * 8. All required config paths must be truthy
+ *
+ * @param skill - Skill to check
+ * @param context - Eligibility context
* @returns Eligibility result with reasons if ineligible
*/
export function checkEligibility(
skill: Skill,
- platform: NodeJS.Platform = process.platform,
+ context: EligibilityContext = {},
): EligibilityResult {
+ const { config, platform = process.platform, customConfig } = context;
const reasons: string[] = [];
const metadata = skill.frontmatter.metadata;
+ const skillConfig = getSkillConfig(skill, config);
+
+ // 1. Check if explicitly disabled in config
+ if (skillConfig?.enabled === false) {
+ return {
+ eligible: false,
+ reasons: [`Skill disabled in configuration`],
+ };
+ }
+
+ // 2. Check bundled allowlist
+ if (!isBundledSkillAllowed(skill, config?.allowBundled)) {
+ return {
+ eligible: false,
+ reasons: [`Bundled skill not in allowlist`],
+ };
+ }
- // No metadata means no requirements
- if (!metadata) {
+ // 3. Platform check
+ const platforms = normalizePlatforms(metadata);
+ if (platforms.length > 0 && !platforms.includes(platform)) {
+ reasons.push(
+ `Platform '${platform}' not supported (requires: ${platforms.join(", ")})`,
+ );
+ }
+
+ // Early return if platform check failed
+ if (reasons.length > 0) {
+ return { eligible: false, reasons };
+ }
+
+ // 4. Always flag - skip remaining checks
+ if (metadata?.always === true) {
return { eligible: true };
}
- // Platform check
- if (metadata.platforms && metadata.platforms.length > 0) {
- if (!metadata.platforms.includes(platform)) {
+ // Get normalized requirements
+ const requirements = normalizeRequirements(metadata);
+
+ // 5. Required binaries check (all must exist)
+ if (requirements.bins && requirements.bins.length > 0) {
+ for (const bin of requirements.bins) {
+ if (!binaryExists(bin)) {
+ reasons.push(`Required binary not found: ${bin}`);
+ }
+ }
+ }
+
+ // 6. Any binaries check (at least one must exist)
+ if (requirements.anyBins && requirements.anyBins.length > 0) {
+ const anyFound = requirements.anyBins.some((bin) => binaryExists(bin));
+ if (!anyFound) {
reasons.push(
- `Platform '${platform}' not supported (requires: ${metadata.platforms.join(", ")})`,
+ `None of required binaries found: ${requirements.anyBins.join(", ")}`,
);
}
}
- // Binary requirements check
- if (metadata.requiresBinaries && metadata.requiresBinaries.length > 0) {
- for (const binary of metadata.requiresBinaries) {
- if (!binaryExists(binary)) {
- reasons.push(`Required binary not found: ${binary}`);
- }
+ // 7. Environment variable check
+ if (requirements.env && requirements.env.length > 0) {
+ for (const envVar of requirements.env) {
+ // Check if env var exists
+ if (envExists(envVar)) continue;
+
+ // Check if provided via skill config env
+ if (skillConfig?.env?.[envVar]) continue;
+
+ // Check if provided via apiKey + primaryEnv match
+ if (skillConfig?.apiKey && metadata?.primaryEnv === envVar) continue;
+
+ reasons.push(`Required environment variable not set: ${envVar}`);
}
}
- // Environment variable check
- if (metadata.requiresEnv && metadata.requiresEnv.length > 0) {
- for (const envVar of metadata.requiresEnv) {
- if (!envExists(envVar)) {
- reasons.push(`Required environment variable not set: ${envVar}`);
+ // 8. Config path check
+ if (requirements.config && requirements.config.length > 0) {
+ for (const configPath of requirements.config) {
+ if (!isConfigPathTruthy(customConfig, configPath)) {
+ reasons.push(`Required config path not truthy: ${configPath}`);
}
}
}
@@ -90,17 +258,17 @@ export function checkEligibility(
* Filter skills by eligibility
*
* @param skills - Map of skills to filter
- * @param platform - Platform to check against
+ * @param context - Eligibility context
* @returns Map containing only eligible skills
*/
export function filterEligibleSkills(
skills: Map<string, Skill>,
- platform?: NodeJS.Platform,
+ context: EligibilityContext = {},
): Map<string, Skill> {
const eligible = new Map<string, Skill>();
for (const [id, skill] of skills) {
- const result = checkEligibility(skill, platform);
+ const result = checkEligibility(skill, context);
if (result.eligible) {
eligible.set(id, skill);
}
@@ -108,3 +276,17 @@ export function filterEligibleSkills(
return eligible;
}
+
+// ============================================================================
+// Legacy Compatibility
+// ============================================================================
+
+/**
+ * @deprecated Use checkEligibility with context instead
+ */
+export function checkEligibilityLegacy(
+ skill: Skill,
+ platform: NodeJS.Platform = process.platform,
+): EligibilityResult {
+ return checkEligibility(skill, { platform });
+}
diff --git a/src/agent/skills/index.ts b/src/agent/skills/index.ts
index 776d983c28..22b01330e3 100644
--- a/src/agent/skills/index.ts
+++ b/src/agent/skills/index.ts
@@ -2,11 +2,16 @@
* Skills Module
*
* Manages skill loading, eligibility filtering, and system prompt generation
+ * Compatible with OpenClaw/AgentSkills specification
*/
-import type { Skill, SkillManagerOptions } from "./types.js";
+import type { Skill, SkillManagerOptions, SkillsConfig } from "./types.js";
import { loadAllSkills, getBundledSkillsDir, getProfileSkillsDir } from "./loader.js";
-import { filterEligibleSkills, checkEligibility } from "./eligibility.js";
+import {
+ filterEligibleSkills,
+ checkEligibility,
+ type EligibilityContext,
+} from "./eligibility.js";
// Re-export types and utilities
export type {
@@ -15,11 +20,33 @@ export type {
SkillMetadata,
SkillSource,
SkillManagerOptions,
+ SkillsConfig,
+ SkillConfig,
+ SkillsLoadConfig,
+ SkillsInstallConfig,
+ SkillInstallSpec,
+ SkillRequirements,
EligibilityResult,
} from "./types.js";
-export { SKILL_FILE, SKILL_SOURCE_PRECEDENCE } from "./types.js";
-export { checkEligibility, filterEligibleSkills } from "./eligibility.js";
+export {
+ SKILL_FILE,
+ SKILL_SOURCE_PRECEDENCE,
+ getSkillKey,
+ getSkillConfig,
+ normalizeRequirements,
+ normalizePlatforms,
+} from "./types.js";
+
+export {
+ checkEligibility,
+ filterEligibleSkills,
+ binaryExists,
+ resolveConfigPath,
+ isConfigPathTruthy,
+ type EligibilityContext,
+} from "./eligibility.js";
+
export { parseFrontmatter, parseSkillFile } from "./parser.js";
export { loadAllSkills, getBundledSkillsDir, getProfileSkillsDir } from "./loader.js";
@@ -27,7 +54,7 @@ export { loadAllSkills, getBundledSkillsDir, getProfileSkillsDir } from "./loade
* SkillManager - Loads and manages skills
*
* Provides access to skills from multiple sources with precedence handling
- * and eligibility filtering.
+ * and eligibility filtering based on configuration.
*/
export class SkillManager {
private readonly options: SkillManagerOptions;
@@ -38,13 +65,26 @@ export class SkillManager {
this.options = options;
}
+ /**
+ * Get the eligibility context for filtering
+ */
+ private getEligibilityContext(): EligibilityContext {
+ return {
+ config: this.options.config,
+ platform: this.options.platform,
+ };
+ }
+
/**
* Ensure skills are loaded (lazy loading)
*/
private ensureLoaded(): void {
if (this.skills) return;
this.skills = loadAllSkills(this.options);
- this.eligibleSkills = filterEligibleSkills(this.skills, this.options.platform);
+ this.eligibleSkills = filterEligibleSkills(
+ this.skills,
+ this.getEligibilityContext(),
+ );
}
/**
@@ -85,6 +125,18 @@ export class SkillManager {
return this.skills!.get(skillId);
}
+ /**
+ * Check eligibility for a specific skill
+ *
+ * @param skillId - Skill identifier
+ * @returns Eligibility result or undefined if skill not found
+ */
+ checkSkillEligibility(skillId: string): { eligible: boolean; reasons?: string[] | undefined } | undefined {
+ const skill = this.getSkillFromAll(skillId);
+ if (!skill) return undefined;
+ return checkEligibility(skill, this.getEligibilityContext());
+ }
+
/**
* Reload skills from disk
* Clears cache and reloads on next access
@@ -94,6 +146,23 @@ export class SkillManager {
this.eligibleSkills = undefined;
}
+ /**
+ * Update configuration and reload
+ *
+ * @param config - New skills configuration
+ */
+ updateConfig(config: SkillsConfig): void {
+ (this.options as { config?: SkillsConfig }).config = config;
+ this.reload();
+ }
+
+ /**
+ * Get the current configuration
+ */
+ getConfig(): SkillsConfig | undefined {
+ return this.options.config;
+ }
+
/**
* Build skills section for system prompt
*
@@ -147,10 +216,22 @@ export class SkillManager {
*
* @returns Array of skill info for display
*/
- listSkills(): Array<{ id: string; name: string; emoji: string; description: string }> {
+ listSkills(): Array<{
+ id: string;
+ name: string;
+ emoji: string;
+ description: string;
+ source: string;
+ }> {
this.ensureLoaded();
- const result: Array<{ id: string; name: string; emoji: string; description: string }> = [];
+ const result: Array<{
+ id: string;
+ name: string;
+ emoji: string;
+ description: string;
+ source: string;
+ }> = [];
for (const [id, skill] of this.eligibleSkills!) {
result.push({
@@ -158,6 +239,49 @@ export class SkillManager {
name: skill.frontmatter.name,
emoji: skill.frontmatter.metadata?.emoji ?? "🔧",
description: skill.frontmatter.description ?? "No description",
+ source: skill.source,
+ });
+ }
+
+ return result;
+ }
+
+ /**
+ * List all skills with eligibility status
+ *
+ * @returns Array of skill info with eligibility status
+ */
+ listAllSkillsWithStatus(): Array<{
+ id: string;
+ name: string;
+ emoji: string;
+ description: string;
+ source: string;
+ eligible: boolean;
+ reasons?: string[] | undefined;
+ }> {
+ this.ensureLoaded();
+
+ const result: Array<{
+ id: string;
+ name: string;
+ emoji: string;
+ description: string;
+ source: string;
+ eligible: boolean;
+ reasons?: string[] | undefined;
+ }> = [];
+
+ for (const [id, skill] of this.skills!) {
+ const eligibility = checkEligibility(skill, this.getEligibilityContext());
+ result.push({
+ id,
+ name: skill.frontmatter.name,
+ emoji: skill.frontmatter.metadata?.emoji ?? "🔧",
+ description: skill.frontmatter.description ?? "No description",
+ source: skill.source,
+ eligible: eligibility.eligible,
+ reasons: eligibility.reasons,
});
}
diff --git a/src/agent/skills/types.ts b/src/agent/skills/types.ts
index 787e9eafb9..256ce282e0 100644
--- a/src/agent/skills/types.ts
+++ b/src/agent/skills/types.ts
@@ -2,22 +2,92 @@
* Skills Module Types
*
* Type definitions for the skills system
+ * Compatible with OpenClaw/AgentSkills specification
*/
+// ============================================================================
+// Install Specification Types
+// ============================================================================
+
+/**
+ * Skill install specification
+ * Defines how to install dependencies for a skill
+ */
+export interface SkillInstallSpec {
+ /** Unique identifier for this install option */
+ id?: string | undefined;
+ /** Install method type */
+ kind: "brew" | "node" | "go" | "uv" | "download";
+ /** Human-readable label for UI */
+ label?: string | undefined;
+ /** Binaries that will be installed */
+ bins?: string[] | undefined;
+ /** Platforms this install option supports */
+ os?: string[] | undefined;
+ /** Homebrew formula name (for kind: "brew") */
+ formula?: string | undefined;
+ /** Package name (for kind: "node" or "uv") */
+ package?: string | undefined;
+ /** Go module path (for kind: "go") */
+ module?: string | undefined;
+ /** Download URL (for kind: "download") */
+ url?: string | undefined;
+ /** Archive type: "tar.gz" | "tar.bz2" | "zip" (for kind: "download") */
+ archive?: string | undefined;
+ /** Whether to extract the archive (for kind: "download") */
+ extract?: boolean | undefined;
+ /** Strip N leading path components when extracting (for kind: "download") */
+ stripComponents?: number | undefined;
+ /** Target directory for download (defaults to ~/.super-multica/tools/<skillKey>) */
+ targetDir?: string | undefined;
+}
+
+/**
+ * Skill requirements specification
+ * Defines what must be present for a skill to be eligible
+ */
+export interface SkillRequirements {
+ /** All listed binaries must exist in PATH */
+ bins?: string[] | undefined;
+ /** At least one of listed binaries must exist in PATH */
+ anyBins?: string[] | undefined;
+ /** All listed environment variables must be set (or provided via config) */
+ env?: string[] | undefined;
+ /** All listed config paths must be truthy */
+ config?: string[] | undefined;
+}
+
/**
* Skill metadata for eligibility and display
+ * Compatible with OpenClaw spec (metadata.openclaw or metadata.multica)
*/
export interface SkillMetadata {
+ /** Always include this skill (skip eligibility checks except explicit disable) */
+ always?: boolean | undefined;
+ /** Custom key for config lookup (defaults to skill id) */
+ skillKey?: string | undefined;
+ /** Primary environment variable for API key injection */
+ primaryEnv?: string | undefined;
/** Emoji for display (e.g., "📝") */
emoji?: string | undefined;
- /** Required environment variables */
- requiresEnv?: string[] | undefined;
- /** Required binaries in PATH */
- requiresBinaries?: string[] | undefined;
+ /** Homepage URL for documentation */
+ homepage?: string | undefined;
/** Supported platforms (darwin, linux, win32) */
- platforms?: string[] | undefined;
+ os?: string[] | undefined;
+ /** Skill requirements */
+ requires?: SkillRequirements | undefined;
+ /** Install specifications */
+ install?: SkillInstallSpec[] | undefined;
/** Skill tags for categorization */
tags?: string[] | undefined;
+
+ // Legacy fields (for backward compatibility with existing skills)
+ /** @deprecated Use requires.env instead */
+ requiresEnv?: string[] | undefined;
+ /** @deprecated Use requires.bins instead */
+ requiresBinaries?: string[] | undefined;
+ /** @deprecated Use os instead */
+ platforms?: string[] | undefined;
}
/**
@@ -67,6 +137,65 @@ export interface Skill {
filePath: string;
}
+// ============================================================================
+// Configuration Types
+// ============================================================================
+
+/**
+ * Per-skill configuration
+ * Applied via skills.entries.<skillKey>
+ */
+export interface SkillConfig {
+ /** Explicitly enable/disable this skill */
+ enabled?: boolean | undefined;
+ /** API key for skills with primaryEnv set */
+ apiKey?: string | undefined;
+ /** Environment variables to inject */
+ env?: Record<string, string> | undefined;
+ /** Custom per-skill configuration */
+ config?: Record<string, unknown> | undefined;
+}
+
+/**
+ * Skills loading configuration
+ */
+export interface SkillsLoadConfig {
+ /** Additional directories to search for skills */
+ extraDirs?: string[] | undefined;
+ /** Enable file watching for hot reload (default: true) */
+ watch?: boolean | undefined;
+ /** Watch debounce delay in ms (default: 250) */
+ watchDebounceMs?: number | undefined;
+}
+
+/**
+ * Skills install preferences
+ */
+export interface SkillsInstallConfig {
+ /** Prefer brew over other installers when available */
+ preferBrew?: boolean | undefined;
+ /** Node package manager to use */
+ nodeManager?: "npm" | "pnpm" | "yarn" | "bun" | undefined;
+}
+
+/**
+ * Complete skills configuration
+ */
+export interface SkillsConfig {
+ /** Allowlist for bundled skills (if set, only these bundled skills are eligible) */
+ allowBundled?: string[] | undefined;
+ /** Loading configuration */
+ load?: SkillsLoadConfig | undefined;
+ /** Install preferences */
+ install?: SkillsInstallConfig | undefined;
+ /** Per-skill configuration entries */
+ entries?: Record<string, SkillConfig> | undefined;
+}
+
+// ============================================================================
+// Manager Types
+// ============================================================================
+
/**
* Skill Manager options
*/
@@ -79,6 +208,8 @@ export interface SkillManagerOptions {
extraDirs?: string[] | undefined;
/** Platform override (for testing) */
platform?: NodeJS.Platform | undefined;
+ /** Skills configuration */
+ config?: SkillsConfig | undefined;
}
/**
@@ -95,3 +226,49 @@ export interface EligibilityResult {
* Filename constant for skill definition file
*/
export const SKILL_FILE = "SKILL.md";
+
+// ============================================================================
+// Utility Functions
+// ============================================================================
+
+/**
+ * Get the config key for a skill
+ * Uses metadata.skillKey if defined, otherwise falls back to skill id
+ */
+export function getSkillKey(skill: Skill): string {
+ return skill.frontmatter.metadata?.skillKey ?? skill.id;
+}
+
+/**
+ * Get the skill config for a specific skill
+ */
+export function getSkillConfig(
+ skill: Skill,
+ config?: SkillsConfig,
+): SkillConfig | undefined {
+ if (!config?.entries) return undefined;
+ const key = getSkillKey(skill);
+ return config.entries[key];
+}
+
+/**
+ * Normalize requirements from both new and legacy metadata formats
+ */
+export function normalizeRequirements(metadata?: SkillMetadata): SkillRequirements {
+ if (!metadata) return {};
+
+ return {
+ bins: metadata.requires?.bins ?? metadata.requiresBinaries ?? [],
+ anyBins: metadata.requires?.anyBins ?? [],
+ env: metadata.requires?.env ?? metadata.requiresEnv ?? [],
+ config: metadata.requires?.config ?? [],
+ };
+}
+
+/**
+ * Normalize platforms from both new and legacy metadata formats
+ */
+export function normalizePlatforms(metadata?: SkillMetadata): string[] {
+ if (!metadata) return [];
+ return metadata.os ?? metadata.platforms ?? [];
+}