mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 16:06:16 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
@@ -73,6 +73,46 @@ async function ensureOpenClawExtensions(manifest: PackageManifest) {
|
||||
return list;
|
||||
}
|
||||
|
||||
function resolvePluginInstallModeOptions(params: {
|
||||
logger?: PluginInstallLogger;
|
||||
mode?: "install" | "update";
|
||||
dryRun?: boolean;
|
||||
}): { logger: PluginInstallLogger; mode: "install" | "update"; dryRun: boolean } {
|
||||
return {
|
||||
logger: params.logger ?? defaultLogger,
|
||||
mode: params.mode ?? "install",
|
||||
dryRun: params.dryRun ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
function resolveTimedPluginInstallModeOptions(params: {
|
||||
logger?: PluginInstallLogger;
|
||||
timeoutMs?: number;
|
||||
mode?: "install" | "update";
|
||||
dryRun?: boolean;
|
||||
}): {
|
||||
logger: PluginInstallLogger;
|
||||
timeoutMs: number;
|
||||
mode: "install" | "update";
|
||||
dryRun: boolean;
|
||||
} {
|
||||
return {
|
||||
...resolvePluginInstallModeOptions(params),
|
||||
timeoutMs: params.timeoutMs ?? 120_000,
|
||||
};
|
||||
}
|
||||
|
||||
function buildFileInstallResult(pluginId: string, targetFile: string): InstallPluginResult {
|
||||
return {
|
||||
ok: true,
|
||||
pluginId,
|
||||
targetDir: targetFile,
|
||||
manifestName: undefined,
|
||||
version: undefined,
|
||||
extensions: [path.basename(targetFile)],
|
||||
};
|
||||
}
|
||||
|
||||
export function resolvePluginInstallDir(pluginId: string, extensionsDir?: string): string {
|
||||
const extensionsBase = extensionsDir
|
||||
? resolveUserPath(extensionsDir)
|
||||
@@ -101,10 +141,7 @@ async function installPluginFromPackageDir(params: {
|
||||
dryRun?: boolean;
|
||||
expectedPluginId?: string;
|
||||
}): Promise<InstallPluginResult> {
|
||||
const logger = params.logger ?? defaultLogger;
|
||||
const timeoutMs = params.timeoutMs ?? 120_000;
|
||||
const mode = params.mode ?? "install";
|
||||
const dryRun = params.dryRun ?? false;
|
||||
const { logger, timeoutMs, mode, dryRun } = resolveTimedPluginInstallModeOptions(params);
|
||||
|
||||
const manifestPath = path.join(params.packageDir, "package.json");
|
||||
if (!(await fileExists(manifestPath))) {
|
||||
@@ -345,9 +382,7 @@ export async function installPluginFromFile(params: {
|
||||
mode?: "install" | "update";
|
||||
dryRun?: boolean;
|
||||
}): Promise<InstallPluginResult> {
|
||||
const logger = params.logger ?? defaultLogger;
|
||||
const mode = params.mode ?? "install";
|
||||
const dryRun = params.dryRun ?? false;
|
||||
const { logger, mode, dryRun } = resolvePluginInstallModeOptions(params);
|
||||
|
||||
const filePath = resolveUserPath(params.filePath);
|
||||
if (!(await fileExists(filePath))) {
|
||||
@@ -372,27 +407,13 @@ export async function installPluginFromFile(params: {
|
||||
}
|
||||
|
||||
if (dryRun) {
|
||||
return {
|
||||
ok: true,
|
||||
pluginId,
|
||||
targetDir: targetFile,
|
||||
manifestName: undefined,
|
||||
version: undefined,
|
||||
extensions: [path.basename(targetFile)],
|
||||
};
|
||||
return buildFileInstallResult(pluginId, targetFile);
|
||||
}
|
||||
|
||||
logger.info?.(`Installing to ${targetFile}…`);
|
||||
await fs.copyFile(filePath, targetFile);
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
pluginId,
|
||||
targetDir: targetFile,
|
||||
manifestName: undefined,
|
||||
version: undefined,
|
||||
extensions: [path.basename(targetFile)],
|
||||
};
|
||||
return buildFileInstallResult(pluginId, targetFile);
|
||||
}
|
||||
|
||||
export async function installPluginFromNpmSpec(params: {
|
||||
@@ -404,10 +425,7 @@ export async function installPluginFromNpmSpec(params: {
|
||||
dryRun?: boolean;
|
||||
expectedPluginId?: string;
|
||||
}): Promise<InstallPluginResult> {
|
||||
const logger = params.logger ?? defaultLogger;
|
||||
const timeoutMs = params.timeoutMs ?? 120_000;
|
||||
const mode = params.mode ?? "install";
|
||||
const dryRun = params.dryRun ?? false;
|
||||
const { logger, timeoutMs, mode, dryRun } = resolveTimedPluginInstallModeOptions(params);
|
||||
const expectedPluginId = params.expectedPluginId;
|
||||
const spec = params.spec.trim();
|
||||
const specError = validateRegistryNpmSpec(spec);
|
||||
|
||||
Reference in New Issue
Block a user