plugin-sdk: add channel subpaths and migrate bundled plugins

This commit is contained in:
Gustavo Madeira Santana
2026-03-03 22:07:03 -05:00
parent 1c200ca7ae
commit 1278ee9248
75 changed files with 808 additions and 174 deletions

View File

@@ -0,0 +1,50 @@
import fs from "node:fs";
import path from "node:path";
import { discoverOpenClawPlugins } from "../src/plugins/discovery.js";
const ROOT_IMPORT_PATTERNS = [
/\b(?:import|export)\b[\s\S]*?\bfrom\s+["']openclaw\/plugin-sdk["']/,
/\bimport\s+["']openclaw\/plugin-sdk["']/,
/\bimport\s*\(\s*["']openclaw\/plugin-sdk["']\s*\)/,
/\brequire\s*\(\s*["']openclaw\/plugin-sdk["']\s*\)/,
];
function hasMonolithicRootImport(content: string): boolean {
return ROOT_IMPORT_PATTERNS.some((pattern) => pattern.test(content));
}
function main() {
const discovery = discoverOpenClawPlugins({});
const bundledEntryFiles = [
...new Set(discovery.candidates.filter((c) => c.origin === "bundled").map((c) => c.source)),
];
const offenders: string[] = [];
for (const entryFile of bundledEntryFiles) {
let content = "";
try {
content = fs.readFileSync(entryFile, "utf8");
} catch {
continue;
}
if (hasMonolithicRootImport(content)) {
offenders.push(entryFile);
}
}
if (offenders.length > 0) {
console.error("Bundled plugin entrypoints must not import monolithic openclaw/plugin-sdk.");
for (const file of offenders.toSorted()) {
const relative = path.relative(process.cwd(), file) || file;
console.error(`- ${relative}`);
}
console.error("Use openclaw/plugin-sdk/<channel> for channel plugins or /core for others.");
process.exit(1);
}
console.log(
`OK: bundled entrypoints use scoped plugin-sdk subpaths (${bundledEntryFiles.length} checked).`,
);
}
main();