mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 17:00:21 +00:00
perf: generate bundled plugin metadata for cold startup
This commit is contained in:
@@ -3,9 +3,14 @@ import path from "node:path";
|
||||
import { openBoundaryFileSync } from "../infra/boundary-file-read.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
import { detectBundleManifestFormat, loadBundleManifest } from "./bundle-manifest.js";
|
||||
import {
|
||||
BUNDLED_PLUGIN_METADATA,
|
||||
resolveBundledPluginGeneratedPath,
|
||||
} from "./bundled-plugin-metadata.js";
|
||||
import {
|
||||
DEFAULT_PLUGIN_ENTRY_CANDIDATES,
|
||||
getPackageManifestMetadata,
|
||||
type PluginManifest,
|
||||
resolvePackageExtensionEntries,
|
||||
type OpenClawPackageManifest,
|
||||
type PackageManifest,
|
||||
@@ -38,6 +43,8 @@ export type PluginCandidate = {
|
||||
packageDescription?: string;
|
||||
packageDir?: string;
|
||||
packageManifest?: OpenClawPackageManifest;
|
||||
bundledManifest?: PluginManifest;
|
||||
bundledManifestPath?: string;
|
||||
};
|
||||
|
||||
export type PluginDiscoveryResult = {
|
||||
@@ -372,6 +379,8 @@ function addCandidate(params: {
|
||||
workspaceDir?: string;
|
||||
manifest?: PackageManifest | null;
|
||||
packageDir?: string;
|
||||
bundledManifest?: PluginManifest;
|
||||
bundledManifestPath?: string;
|
||||
}) {
|
||||
const resolved = path.resolve(params.source);
|
||||
if (params.seen.has(resolved)) {
|
||||
@@ -405,6 +414,8 @@ function addCandidate(params: {
|
||||
packageDescription: manifest?.description?.trim() || undefined,
|
||||
packageDir: params.packageDir,
|
||||
packageManifest: getPackageManifestMetadata(manifest ?? undefined),
|
||||
bundledManifest: params.bundledManifest,
|
||||
bundledManifestPath: params.bundledManifestPath,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -485,6 +496,7 @@ function discoverInDirectory(params: {
|
||||
candidates: PluginCandidate[];
|
||||
diagnostics: PluginDiagnostic[];
|
||||
seen: Set<string>;
|
||||
skipDirectories?: Set<string>;
|
||||
}) {
|
||||
if (!fs.existsSync(params.dir)) {
|
||||
return;
|
||||
@@ -522,6 +534,9 @@ function discoverInDirectory(params: {
|
||||
if (!entry.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
if (params.skipDirectories?.has(entry.name)) {
|
||||
continue;
|
||||
}
|
||||
if (shouldIgnoreScannedDirectory(entry.name)) {
|
||||
continue;
|
||||
}
|
||||
@@ -754,6 +769,54 @@ function discoverFromPath(params: {
|
||||
}
|
||||
}
|
||||
|
||||
function discoverBundledMetadataInDirectory(params: {
|
||||
dir: string;
|
||||
ownershipUid?: number | null;
|
||||
candidates: PluginCandidate[];
|
||||
diagnostics: PluginDiagnostic[];
|
||||
seen: Set<string>;
|
||||
}) {
|
||||
if (!fs.existsSync(params.dir)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const coveredDirectories = new Set<string>();
|
||||
for (const entry of BUNDLED_PLUGIN_METADATA) {
|
||||
const rootDir = path.join(params.dir, entry.dirName);
|
||||
if (!fs.existsSync(rootDir)) {
|
||||
continue;
|
||||
}
|
||||
coveredDirectories.add(entry.dirName);
|
||||
const source = resolveBundledPluginGeneratedPath(rootDir, entry.source);
|
||||
if (!source) {
|
||||
continue;
|
||||
}
|
||||
const setupSource = resolveBundledPluginGeneratedPath(rootDir, entry.setupSource);
|
||||
addCandidate({
|
||||
candidates: params.candidates,
|
||||
diagnostics: params.diagnostics,
|
||||
seen: params.seen,
|
||||
idHint: entry.idHint,
|
||||
source,
|
||||
...(setupSource ? { setupSource } : {}),
|
||||
rootDir,
|
||||
origin: "bundled",
|
||||
ownershipUid: params.ownershipUid,
|
||||
manifest: {
|
||||
...(entry.packageName ? { name: entry.packageName } : {}),
|
||||
...(entry.packageVersion ? { version: entry.packageVersion } : {}),
|
||||
...(entry.packageDescription ? { description: entry.packageDescription } : {}),
|
||||
...(entry.packageManifest ? { openclaw: entry.packageManifest } : {}),
|
||||
},
|
||||
packageDir: rootDir,
|
||||
bundledManifest: entry.manifest,
|
||||
bundledManifestPath: path.join(rootDir, "openclaw.plugin.json"),
|
||||
});
|
||||
}
|
||||
|
||||
return coveredDirectories;
|
||||
}
|
||||
|
||||
export function discoverOpenClawPlugins(params: {
|
||||
workspaceDir?: string;
|
||||
extraPaths?: string[];
|
||||
@@ -816,6 +879,13 @@ export function discoverOpenClawPlugins(params: {
|
||||
}
|
||||
|
||||
if (roots.stock) {
|
||||
const coveredBundledDirectories = discoverBundledMetadataInDirectory({
|
||||
dir: roots.stock,
|
||||
ownershipUid: params.ownershipUid,
|
||||
candidates,
|
||||
diagnostics,
|
||||
seen,
|
||||
});
|
||||
discoverInDirectory({
|
||||
dir: roots.stock,
|
||||
origin: "bundled",
|
||||
@@ -823,6 +893,7 @@ export function discoverOpenClawPlugins(params: {
|
||||
candidates,
|
||||
diagnostics,
|
||||
seen,
|
||||
...(coveredBundledDirectories ? { skipDirectories: coveredBundledDirectories } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user