mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 19:04:31 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
@@ -6,6 +6,7 @@ import { runCommandWithTimeout, type CommandOptions } from "../process/exec.js";
|
||||
import { scanDirectoryWithSummary } from "../security/skill-scanner.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
import { installDownloadSpec } from "./skills-install-download.js";
|
||||
import { formatInstallFailureMessage } from "./skills-install-output.js";
|
||||
import {
|
||||
hasBinary,
|
||||
loadWorkspaceSkillEntries,
|
||||
@@ -32,45 +33,6 @@ export type SkillInstallResult = {
|
||||
warnings?: string[];
|
||||
};
|
||||
|
||||
function summarizeInstallOutput(text: string): string | undefined {
|
||||
const raw = text.trim();
|
||||
if (!raw) {
|
||||
return undefined;
|
||||
}
|
||||
const lines = raw
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean);
|
||||
if (lines.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const preferred =
|
||||
lines.find((line) => /^error\b/i.test(line)) ??
|
||||
lines.find((line) => /\b(err!|error:|failed)\b/i.test(line)) ??
|
||||
lines.at(-1);
|
||||
|
||||
if (!preferred) {
|
||||
return undefined;
|
||||
}
|
||||
const normalized = preferred.replace(/\s+/g, " ").trim();
|
||||
const maxLen = 200;
|
||||
return normalized.length > maxLen ? `${normalized.slice(0, maxLen - 1)}…` : normalized;
|
||||
}
|
||||
|
||||
function formatInstallFailureMessage(result: {
|
||||
code: number | null;
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
}): string {
|
||||
const code = typeof result.code === "number" ? `exit ${result.code}` : "unknown exit";
|
||||
const summary = summarizeInstallOutput(result.stderr) ?? summarizeInstallOutput(result.stdout);
|
||||
if (!summary) {
|
||||
return `Install failed (${code})`;
|
||||
}
|
||||
return `Install failed (${code}): ${summary}`;
|
||||
}
|
||||
|
||||
function withWarnings(result: SkillInstallResult, warnings: string[]): SkillInstallResult {
|
||||
if (warnings.length === 0) {
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user