fix(openclaw): use sync plugin registration (#498)

Co-authored-by: Niemand Assistant <niemand@kessler.io>
This commit is contained in:
Martin Kessler
2026-04-08 14:13:43 -07:00
committed by GitHub
parent 042ee73239
commit 2c05c43dc8
2 changed files with 8 additions and 39 deletions

View File

@@ -177,17 +177,16 @@ function buildOpenClawConfig(
function generateEntryPoint(commands: OpenClawCommandRegistration[]): string {
const commandRegistrations = commands
.map((cmd) => {
// JSON.stringify produces a fully-escaped string literal safe for JS/TS source embedding
const safeName = JSON.stringify(cmd.name)
const safeDesc = JSON.stringify(cmd.description ?? "")
const safeNotFound = JSON.stringify(`Command ${cmd.name} not found. Check skills directory.`)
const safeBody = JSON.stringify(cmd.body)
return ` api.registerCommand({
name: ${safeName},
description: ${safeDesc},
acceptsArgs: ${cmd.acceptsArgs},
requireAuth: false,
handler: (ctx) => ({
text: skills[${safeName}] ?? ${safeNotFound},
handler: () => ({
text: ${safeBody},
}),
});`
})
@@ -195,39 +194,7 @@ function generateEntryPoint(commands: OpenClawCommandRegistration[]): string {
return `// Auto-generated OpenClaw plugin entry point
// Converted from Claude Code plugin format by compound-plugin CLI
import { promises as fs } from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Pre-load skill bodies for command responses
const skills: Record<string, string> = {};
async function loadSkills() {
const skillsDir = path.join(__dirname, "skills");
try {
const entries = await fs.readdir(skillsDir, { withFileTypes: true });
for (const entry of entries) {
if (!entry.isDirectory()) continue;
const skillPath = path.join(skillsDir, entry.name, "SKILL.md");
try {
const content = await fs.readFile(skillPath, "utf8");
// Strip frontmatter
const body = content.replace(/^---[\\s\\S]*?---\\n*/, "");
skills[entry.name.replace(/^cmd-/, "")] = body.trim();
} catch {
// Skill file not found, skip
}
}
} catch {
// Skills directory not found
}
}
export default async function register(api) {
await loadSkills();
export default function register(api) {
${commandRegistrations}
}
`