mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 18:04:32 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -10,15 +10,21 @@ function extractBetween(
|
||||
endMarker: string,
|
||||
): { text: string; found: boolean } {
|
||||
const start = input.indexOf(startMarker);
|
||||
if (start === -1) return { text: "", found: false };
|
||||
if (start === -1) {
|
||||
return { text: "", found: false };
|
||||
}
|
||||
const end = input.indexOf(endMarker, start + startMarker.length);
|
||||
if (end === -1) return { text: input.slice(start), found: true };
|
||||
if (end === -1) {
|
||||
return { text: input.slice(start), found: true };
|
||||
}
|
||||
return { text: input.slice(start, end), found: true };
|
||||
}
|
||||
|
||||
function parseSkillBlocks(skillsPrompt: string): Array<{ name: string; blockChars: number }> {
|
||||
const prompt = skillsPrompt.trim();
|
||||
if (!prompt) return [];
|
||||
if (!prompt) {
|
||||
return [];
|
||||
}
|
||||
const blocks = Array.from(prompt.matchAll(/<skill>[\s\S]*?<\/skill>/gi)).map(
|
||||
(match) => match[0] ?? "",
|
||||
);
|
||||
@@ -58,7 +64,9 @@ function buildToolsEntries(tools: AgentTool[]): SessionSystemPromptReport["tools
|
||||
const summary = tool.description?.trim() || tool.label?.trim() || "";
|
||||
const summaryChars = summary.length;
|
||||
const schemaChars = (() => {
|
||||
if (!tool.parameters || typeof tool.parameters !== "object") return 0;
|
||||
if (!tool.parameters || typeof tool.parameters !== "object") {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return JSON.stringify(tool.parameters).length;
|
||||
} catch {
|
||||
@@ -71,7 +79,9 @@ function buildToolsEntries(tools: AgentTool[]): SessionSystemPromptReport["tools
|
||||
? (tool.parameters as Record<string, unknown>)
|
||||
: null;
|
||||
const props = schema && typeof schema.properties === "object" ? schema.properties : null;
|
||||
if (!props || typeof props !== "object") return null;
|
||||
if (!props || typeof props !== "object") {
|
||||
return null;
|
||||
}
|
||||
return Object.keys(props as Record<string, unknown>).length;
|
||||
})();
|
||||
return { name, summaryChars, schemaChars, propertiesCount };
|
||||
@@ -83,7 +93,9 @@ function extractToolListText(systemPrompt: string): string {
|
||||
const markerB =
|
||||
"\nTOOLS.md does not control tool availability; it is user guidance for how to use external tools.";
|
||||
const extracted = extractBetween(systemPrompt, markerA, markerB);
|
||||
if (!extracted.found) return "";
|
||||
if (!extracted.found) {
|
||||
return "";
|
||||
}
|
||||
return extracted.text.replace(markerA, "").trim();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user