mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-14 05:38:33 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
@@ -10,6 +10,7 @@ import { fetchWithSsrFGuard } from "../infra/net/fetch-guard.js";
|
||||
import { isWithinDir, resolveSafeBaseDir } from "../infra/path-safety.js";
|
||||
import { runCommandWithTimeout } from "../process/exec.js";
|
||||
import { ensureDir, resolveUserPath } from "../utils.js";
|
||||
import { formatInstallFailureMessage } from "./skills-install-output.js";
|
||||
import { hasBinary } from "./skills.js";
|
||||
import { resolveSkillToolsRootDir } from "./skills/tools-dir.js";
|
||||
|
||||
@@ -17,45 +18,6 @@ function isNodeReadableStream(value: unknown): value is NodeJS.ReadableStream {
|
||||
return Boolean(value && typeof (value as NodeJS.ReadableStream).pipe === "function");
|
||||
}
|
||||
|
||||
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 isWindowsDrivePath(p: string): boolean {
|
||||
return /^[a-zA-Z]:[\\/]/.test(p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user