mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 13:54:57 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -32,12 +32,16 @@ function normalizeFailureText(text: string): string {
|
||||
}
|
||||
|
||||
function truncateFailureText(text: string, maxChars: number): string {
|
||||
if (text.length <= maxChars) return text;
|
||||
if (text.length <= maxChars) {
|
||||
return text;
|
||||
}
|
||||
return `${text.slice(0, Math.max(0, maxChars - 3))}...`;
|
||||
}
|
||||
|
||||
function formatToolFailureMeta(details: unknown): string | undefined {
|
||||
if (!details || typeof details !== "object") return undefined;
|
||||
if (!details || typeof details !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
const record = details as Record<string, unknown>;
|
||||
const status = typeof record.status === "string" ? record.status : undefined;
|
||||
const exitCode =
|
||||
@@ -45,16 +49,24 @@ function formatToolFailureMeta(details: unknown): string | undefined {
|
||||
? record.exitCode
|
||||
: undefined;
|
||||
const parts: string[] = [];
|
||||
if (status) parts.push(`status=${status}`);
|
||||
if (exitCode !== undefined) parts.push(`exitCode=${exitCode}`);
|
||||
if (status) {
|
||||
parts.push(`status=${status}`);
|
||||
}
|
||||
if (exitCode !== undefined) {
|
||||
parts.push(`exitCode=${exitCode}`);
|
||||
}
|
||||
return parts.length > 0 ? parts.join(" ") : undefined;
|
||||
}
|
||||
|
||||
function extractToolResultText(content: unknown): string {
|
||||
if (!Array.isArray(content)) return "";
|
||||
if (!Array.isArray(content)) {
|
||||
return "";
|
||||
}
|
||||
const parts: string[] = [];
|
||||
for (const block of content) {
|
||||
if (!block || typeof block !== "object") continue;
|
||||
if (!block || typeof block !== "object") {
|
||||
continue;
|
||||
}
|
||||
const rec = block as { type?: unknown; text?: unknown };
|
||||
if (rec.type === "text" && typeof rec.text === "string") {
|
||||
parts.push(rec.text);
|
||||
@@ -68,9 +80,13 @@ function collectToolFailures(messages: AgentMessage[]): ToolFailure[] {
|
||||
const seen = new Set<string>();
|
||||
|
||||
for (const message of messages) {
|
||||
if (!message || typeof message !== "object") continue;
|
||||
if (!message || typeof message !== "object") {
|
||||
continue;
|
||||
}
|
||||
const role = (message as { role?: unknown }).role;
|
||||
if (role !== "toolResult") continue;
|
||||
if (role !== "toolResult") {
|
||||
continue;
|
||||
}
|
||||
const toolResult = message as {
|
||||
toolCallId?: unknown;
|
||||
toolName?: unknown;
|
||||
@@ -78,9 +94,13 @@ function collectToolFailures(messages: AgentMessage[]): ToolFailure[] {
|
||||
details?: unknown;
|
||||
isError?: unknown;
|
||||
};
|
||||
if (toolResult.isError !== true) continue;
|
||||
if (toolResult.isError !== true) {
|
||||
continue;
|
||||
}
|
||||
const toolCallId = typeof toolResult.toolCallId === "string" ? toolResult.toolCallId : "";
|
||||
if (!toolCallId || seen.has(toolCallId)) continue;
|
||||
if (!toolCallId || seen.has(toolCallId)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(toolCallId);
|
||||
|
||||
const toolName =
|
||||
@@ -101,7 +121,9 @@ function collectToolFailures(messages: AgentMessage[]): ToolFailure[] {
|
||||
}
|
||||
|
||||
function formatToolFailuresSection(failures: ToolFailure[]): string {
|
||||
if (failures.length === 0) return "";
|
||||
if (failures.length === 0) {
|
||||
return "";
|
||||
}
|
||||
const lines = failures.slice(0, MAX_TOOL_FAILURES).map((failure) => {
|
||||
const meta = failure.meta ? ` (${failure.meta})` : "";
|
||||
return `- ${failure.toolName}${meta}: ${failure.summary}`;
|
||||
@@ -130,7 +152,9 @@ function formatFileOperations(readFiles: string[], modifiedFiles: string[]): str
|
||||
if (modifiedFiles.length > 0) {
|
||||
sections.push(`<modified-files>\n${modifiedFiles.join("\n")}\n</modified-files>`);
|
||||
}
|
||||
if (sections.length === 0) return "";
|
||||
if (sections.length === 0) {
|
||||
return "";
|
||||
}
|
||||
return `\n\n${sections.join("\n\n")}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user