mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 11:07:41 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -71,7 +71,9 @@ export class ChatLog extends Container {
|
||||
|
||||
updateToolArgs(toolCallId: string, args: unknown) {
|
||||
const existing = this.toolById.get(toolCallId);
|
||||
if (!existing) return;
|
||||
if (!existing) {
|
||||
return;
|
||||
}
|
||||
existing.setArgs(args);
|
||||
}
|
||||
|
||||
@@ -81,7 +83,9 @@ export class ChatLog extends Container {
|
||||
opts?: { isError?: boolean; partial?: boolean },
|
||||
) {
|
||||
const existing = this.toolById.get(toolCallId);
|
||||
if (!existing) return;
|
||||
if (!existing) {
|
||||
return;
|
||||
}
|
||||
if (opts?.partial) {
|
||||
existing.setPartialResult(result as Record<string, unknown>);
|
||||
return;
|
||||
|
||||
@@ -19,11 +19,15 @@ export function isWordBoundary(text: string, index: number): boolean {
|
||||
* Returns null if no match.
|
||||
*/
|
||||
export function findWordBoundaryIndex(text: string, query: string): number | null {
|
||||
if (!query) return null;
|
||||
if (!query) {
|
||||
return null;
|
||||
}
|
||||
const textLower = text.toLowerCase();
|
||||
const queryLower = query.toLowerCase();
|
||||
const maxIndex = textLower.length - queryLower.length;
|
||||
if (maxIndex < 0) return null;
|
||||
if (maxIndex < 0) {
|
||||
return null;
|
||||
}
|
||||
for (let i = 0; i <= maxIndex; i++) {
|
||||
if (textLower.startsWith(queryLower, i) && isWordBoundary(textLower, i)) {
|
||||
return i;
|
||||
@@ -37,8 +41,12 @@ export function findWordBoundaryIndex(text: string, query: string): number | nul
|
||||
* Returns score (lower = better) or null if no match.
|
||||
*/
|
||||
export function fuzzyMatchLower(queryLower: string, textLower: string): number | null {
|
||||
if (queryLower.length === 0) return 0;
|
||||
if (queryLower.length > textLower.length) return null;
|
||||
if (queryLower.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
if (queryLower.length > textLower.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let queryIndex = 0;
|
||||
let score = 0;
|
||||
@@ -53,9 +61,13 @@ export function fuzzyMatchLower(queryLower: string, textLower: string): number |
|
||||
score -= consecutiveMatches * 5; // Reward consecutive matches
|
||||
} else {
|
||||
consecutiveMatches = 0;
|
||||
if (lastMatchIndex >= 0) score += (i - lastMatchIndex - 1) * 2; // Penalize gaps
|
||||
if (lastMatchIndex >= 0) {
|
||||
score += (i - lastMatchIndex - 1) * 2;
|
||||
} // Penalize gaps
|
||||
}
|
||||
if (isAtWordBoundary) score -= 10; // Reward word boundary matches
|
||||
if (isAtWordBoundary) {
|
||||
score -= 10;
|
||||
} // Reward word boundary matches
|
||||
score += i * 0.1; // Slight penalty for later matches
|
||||
lastMatchIndex = i;
|
||||
queryIndex++;
|
||||
@@ -73,10 +85,14 @@ export function fuzzyFilterLower<T extends { searchTextLower?: string }>(
|
||||
queryLower: string,
|
||||
): T[] {
|
||||
const trimmed = queryLower.trim();
|
||||
if (!trimmed) return items;
|
||||
if (!trimmed) {
|
||||
return items;
|
||||
}
|
||||
|
||||
const tokens = trimmed.split(/\s+/).filter((t) => t.length > 0);
|
||||
if (tokens.length === 0) return items;
|
||||
if (tokens.length === 0) {
|
||||
return items;
|
||||
}
|
||||
|
||||
const results: { item: T; score: number }[] = [];
|
||||
for (const item of items) {
|
||||
@@ -92,7 +108,9 @@ export function fuzzyFilterLower<T extends { searchTextLower?: string }>(
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allMatch) results.push({ item, score: totalScore });
|
||||
if (allMatch) {
|
||||
results.push({ item, score: totalScore });
|
||||
}
|
||||
}
|
||||
results.sort((a, b) => a.score - b.score);
|
||||
return results.map((r) => r.item);
|
||||
@@ -106,9 +124,15 @@ export function prepareSearchItems<
|
||||
>(items: T[]): (T & { searchTextLower: string })[] {
|
||||
return items.map((item) => {
|
||||
const parts: string[] = [];
|
||||
if (item.label) parts.push(item.label);
|
||||
if (item.description) parts.push(item.description);
|
||||
if (item.searchText) parts.push(item.searchText);
|
||||
if (item.label) {
|
||||
parts.push(item.label);
|
||||
}
|
||||
if (item.description) {
|
||||
parts.push(item.description);
|
||||
}
|
||||
if (item.searchText) {
|
||||
parts.push(item.searchText);
|
||||
}
|
||||
return { ...item, searchTextLower: parts.join(" ").toLowerCase() };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -119,8 +119,12 @@ export class SearchableSelectList implements Component {
|
||||
a: { item: SelectItem; tier: number; score: number },
|
||||
b: { item: SelectItem; tier: number; score: number },
|
||||
) => {
|
||||
if (a.tier !== b.tier) return a.tier - b.tier;
|
||||
if (a.score !== b.score) return a.score - b.score;
|
||||
if (a.tier !== b.tier) {
|
||||
return a.tier - b.tier;
|
||||
}
|
||||
if (a.score !== b.score) {
|
||||
return a.score - b.score;
|
||||
}
|
||||
return this.getItemLabel(a.item).localeCompare(this.getItemLabel(b.item));
|
||||
};
|
||||
|
||||
@@ -134,7 +138,9 @@ export class SearchableSelectList implements Component {
|
||||
.split(/\s+/)
|
||||
.map((token) => token.toLowerCase())
|
||||
.filter((token) => token.length > 0);
|
||||
if (tokens.length === 0) return text;
|
||||
if (tokens.length === 0) {
|
||||
return text;
|
||||
}
|
||||
|
||||
const uniqueTokens = Array.from(new Set(tokens)).toSorted((a, b) => b.length - a.length);
|
||||
let result = text;
|
||||
@@ -186,7 +192,9 @@ export class SearchableSelectList implements Component {
|
||||
// Render visible items
|
||||
for (let i = startIndex; i < endIndex; i++) {
|
||||
const item = this.filteredItems[i];
|
||||
if (!item) continue;
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
const isSelected = i === this.selectedIndex;
|
||||
lines.push(this.renderItemLine(item, isSelected, width, query));
|
||||
}
|
||||
@@ -236,7 +244,9 @@ export class SearchableSelectList implements Component {
|
||||
}
|
||||
|
||||
handleInput(keyData: string): void {
|
||||
if (isKeyRelease(keyData)) return;
|
||||
if (isKeyRelease(keyData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const allowVimNav = !this.searchInput.getValue().trim();
|
||||
|
||||
|
||||
@@ -20,8 +20,12 @@ const PREVIEW_LINES = 12;
|
||||
function formatArgs(toolName: string, args: unknown): string {
|
||||
const display = resolveToolDisplay({ name: toolName, args });
|
||||
const detail = formatToolDetail(display);
|
||||
if (detail) return detail;
|
||||
if (!args || typeof args !== "object") return "";
|
||||
if (detail) {
|
||||
return detail;
|
||||
}
|
||||
if (!args || typeof args !== "object") {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return JSON.stringify(args);
|
||||
} catch {
|
||||
@@ -30,7 +34,9 @@ function formatArgs(toolName: string, args: unknown): string {
|
||||
}
|
||||
|
||||
function extractText(result?: ToolResult): string {
|
||||
if (!result?.content) return "";
|
||||
if (!result?.content) {
|
||||
return "";
|
||||
}
|
||||
const lines: string[] = [];
|
||||
for (const entry of result.content) {
|
||||
if (entry.type === "text" && entry.text) {
|
||||
|
||||
Reference in New Issue
Block a user