mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 18:34:57 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
40
src/agents/skills-install-output.ts
Normal file
40
src/agents/skills-install-output.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
export type InstallCommandResult = {
|
||||
code: number | null;
|
||||
stdout: string;
|
||||
stderr: 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;
|
||||
}
|
||||
|
||||
export function formatInstallFailureMessage(result: InstallCommandResult): 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}`;
|
||||
}
|
||||
Reference in New Issue
Block a user