Files
openclaw/src/plugins/bundled-runtime-staging.ts
Peter Steinberger 250376f885 fix: simplify bundled runtime dependency repair (#75183)
Summary:
- Merged fix: simplify bundled runtime dependency repair after ClawSweeper review.

ClawSweeper fixups:
- Included follow-up commit: fix: verify cached bundled runtime roots
- Included follow-up commit: refactor: simplify plugin runtime startup paths
- Included follow-up commit: refactor: trim plugin startup policy helpers
- Included follow-up commit: refactor: trust package manager runtime deps materialization
- Included follow-up commit: fix: narrow channel runtime deps skip policy
- Included follow-up commit: refactor: defer startup plugin runtime deps
- Ran the ClawSweeper repair loop before final review.

Validation:
- ClawSweeper review passed for head 04dc566534.
- Required merge gates passed before the squash merge.

Prepared head SHA: 04dc566534
Review: https://github.com/openclaw/openclaw/pull/75183#issuecomment-4358383786

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: Shakker <shakkerdroid@gmail.com>
Co-authored-by: clawsweeper-repair <clawsweeper-repair@users.noreply.github.com>
2026-05-01 07:49:02 +00:00

93 lines
3.6 KiB
TypeScript

import type { OpenClawConfig } from "../config/types.openclaw.js";
import { measureDiagnosticsTimelineSpanSync } from "../infra/diagnostics-timeline.js";
import {
installBundledRuntimeDeps,
type BundledRuntimeDepsInstallParams,
} from "./bundled-runtime-deps-install.js";
import { registerBundledRuntimeDependencyJitiAliases } from "./bundled-runtime-deps-jiti-aliases.js";
import {
prepareBundledPluginRuntimeLoadRoot,
type PreparedBundledPluginRuntimeLoadRoot,
} from "./bundled-runtime-root.js";
import type { PluginLogger } from "./types.js";
export function prepareBundledRuntimeLoadRootForPlugin(params: {
pluginId: string;
pluginRoot: string;
modulePath: string;
setupModulePath?: string;
env: NodeJS.ProcessEnv;
config: OpenClawConfig;
installMissingDeps: boolean;
previousRepairError?: unknown;
shouldLog: boolean;
logger: PluginLogger;
installer?: (params: BundledRuntimeDepsInstallParams) => void;
}): PreparedBundledPluginRuntimeLoadRoot {
let installStartedAt: number | null = null;
let installSpecs: string[] = [];
try {
return prepareBundledPluginRuntimeLoadRoot({
pluginId: params.pluginId,
pluginRoot: params.pluginRoot,
modulePath: params.modulePath,
...(params.setupModulePath ? { setupModulePath: params.setupModulePath } : {}),
env: params.env,
config: params.config,
installMissingDeps: params.installMissingDeps,
previousRepairError: params.previousRepairError,
memoizePreparedRoot: true,
registerRuntimeAliasRoot: registerBundledRuntimeDependencyJitiAliases,
installDeps: (installParams) => {
installSpecs = installParams.installSpecs ?? installParams.missingSpecs;
installStartedAt = Date.now();
if (params.shouldLog) {
params.logger.info(
`[plugins] ${params.pluginId} staging bundled runtime deps (${installSpecs.length} specs): ${installSpecs.join(", ")}`,
);
}
const installer =
params.installer ??
((runtimeDepsInstallParams: BundledRuntimeDepsInstallParams) =>
installBundledRuntimeDeps({
installRoot: runtimeDepsInstallParams.installRoot,
...(runtimeDepsInstallParams.installExecutionRoot
? { installExecutionRoot: runtimeDepsInstallParams.installExecutionRoot }
: {}),
missingSpecs:
runtimeDepsInstallParams.installSpecs ?? runtimeDepsInstallParams.missingSpecs,
installSpecs: runtimeDepsInstallParams.installSpecs,
env: params.env,
force: true,
warn: (message) => params.logger.warn(`[plugins] ${params.pluginId}: ${message}`),
}));
measureDiagnosticsTimelineSpanSync("runtimeDeps.stage", () => installer(installParams), {
phase: "startup",
config: params.config,
env: params.env,
attributes: {
pluginId: params.pluginId,
dependencyCount: installSpecs.length,
},
});
},
logInstalled: (installedSpecs) => {
if (!params.shouldLog) {
return;
}
const elapsed = installStartedAt === null ? "" : ` in ${Date.now() - installStartedAt}ms`;
params.logger.info(
`[plugins] ${params.pluginId} installed bundled runtime deps${elapsed}: ${installedSpecs.join(", ")}`,
);
},
});
} catch (error) {
if (params.shouldLog && installStartedAt !== null) {
params.logger.error(
`[plugins] ${params.pluginId} failed to stage bundled runtime deps after ${Date.now() - installStartedAt}ms: ${installSpecs.join(", ")}`,
);
}
throw error;
}
}