mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:31:23 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -84,16 +84,24 @@ function resolveRuntimeLabel(
|
||||
sessionKey,
|
||||
});
|
||||
const sandboxMode = runtimeStatus.mode ?? "off";
|
||||
if (sandboxMode === "off") return "direct";
|
||||
if (sandboxMode === "off") {
|
||||
return "direct";
|
||||
}
|
||||
const runtime = runtimeStatus.sandboxed ? "docker" : sessionKey ? "direct" : "unknown";
|
||||
return `${runtime}/${sandboxMode}`;
|
||||
}
|
||||
|
||||
const sandboxMode = args.agent?.sandbox?.mode ?? "off";
|
||||
if (sandboxMode === "off") return "direct";
|
||||
if (sandboxMode === "off") {
|
||||
return "direct";
|
||||
}
|
||||
const sandboxed = (() => {
|
||||
if (!sessionKey) return false;
|
||||
if (sandboxMode === "all") return true;
|
||||
if (!sessionKey) {
|
||||
return false;
|
||||
}
|
||||
if (sandboxMode === "all") {
|
||||
return true;
|
||||
}
|
||||
if (args.config) {
|
||||
return resolveSandboxRuntimeStatus({
|
||||
cfg: args.config,
|
||||
@@ -128,32 +136,48 @@ export const formatContextUsageShort = (
|
||||
) => `Context ${formatTokens(total, contextTokens ?? null)}`;
|
||||
|
||||
const formatAge = (ms?: number | null) => {
|
||||
if (!ms || ms < 0) return "unknown";
|
||||
if (!ms || ms < 0) {
|
||||
return "unknown";
|
||||
}
|
||||
const minutes = Math.round(ms / 60_000);
|
||||
if (minutes < 1) return "just now";
|
||||
if (minutes < 60) return `${minutes}m ago`;
|
||||
if (minutes < 1) {
|
||||
return "just now";
|
||||
}
|
||||
if (minutes < 60) {
|
||||
return `${minutes}m ago`;
|
||||
}
|
||||
const hours = Math.round(minutes / 60);
|
||||
if (hours < 48) return `${hours}h ago`;
|
||||
if (hours < 48) {
|
||||
return `${hours}h ago`;
|
||||
}
|
||||
const days = Math.round(hours / 24);
|
||||
return `${days}d ago`;
|
||||
};
|
||||
|
||||
const formatQueueDetails = (queue?: QueueStatus) => {
|
||||
if (!queue) return "";
|
||||
if (!queue) {
|
||||
return "";
|
||||
}
|
||||
const depth = typeof queue.depth === "number" ? `depth ${queue.depth}` : null;
|
||||
if (!queue.showDetails) {
|
||||
return depth ? ` (${depth})` : "";
|
||||
}
|
||||
const detailParts: string[] = [];
|
||||
if (depth) detailParts.push(depth);
|
||||
if (depth) {
|
||||
detailParts.push(depth);
|
||||
}
|
||||
if (typeof queue.debounceMs === "number") {
|
||||
const ms = Math.max(0, Math.round(queue.debounceMs));
|
||||
const label =
|
||||
ms >= 1000 ? `${ms % 1000 === 0 ? ms / 1000 : (ms / 1000).toFixed(1)}s` : `${ms}ms`;
|
||||
detailParts.push(`debounce ${label}`);
|
||||
}
|
||||
if (typeof queue.cap === "number") detailParts.push(`cap ${queue.cap}`);
|
||||
if (queue.dropPolicy) detailParts.push(`drop ${queue.dropPolicy}`);
|
||||
if (typeof queue.cap === "number") {
|
||||
detailParts.push(`cap ${queue.cap}`);
|
||||
}
|
||||
if (queue.dropPolicy) {
|
||||
detailParts.push(`drop ${queue.dropPolicy}`);
|
||||
}
|
||||
return detailParts.length ? ` (${detailParts.join(" · ")})` : "";
|
||||
};
|
||||
|
||||
@@ -170,9 +194,13 @@ const readUsageFromSessionLog = (
|
||||
}
|
||||
| undefined => {
|
||||
// Transcripts are stored at the session file path (fallback: ~/.openclaw/sessions/<SessionId>.jsonl)
|
||||
if (!sessionId) return undefined;
|
||||
if (!sessionId) {
|
||||
return undefined;
|
||||
}
|
||||
const logPath = resolveSessionFilePath(sessionId, sessionEntry);
|
||||
if (!fs.existsSync(logPath)) return undefined;
|
||||
if (!fs.existsSync(logPath)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
const lines = fs.readFileSync(logPath, "utf-8").split(/\n+/);
|
||||
@@ -183,7 +211,9 @@ const readUsageFromSessionLog = (
|
||||
let lastUsage: ReturnType<typeof normalizeUsage> | undefined;
|
||||
|
||||
for (const line of lines) {
|
||||
if (!line.trim()) continue;
|
||||
if (!line.trim()) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(line) as {
|
||||
message?: {
|
||||
@@ -195,19 +225,25 @@ const readUsageFromSessionLog = (
|
||||
};
|
||||
const usageRaw = parsed.message?.usage ?? parsed.usage;
|
||||
const usage = normalizeUsage(usageRaw);
|
||||
if (usage) lastUsage = usage;
|
||||
if (usage) {
|
||||
lastUsage = usage;
|
||||
}
|
||||
model = parsed.message?.model ?? parsed.model ?? model;
|
||||
} catch {
|
||||
// ignore bad lines
|
||||
}
|
||||
}
|
||||
|
||||
if (!lastUsage) return undefined;
|
||||
if (!lastUsage) {
|
||||
return undefined;
|
||||
}
|
||||
input = lastUsage.input ?? 0;
|
||||
output = lastUsage.output ?? 0;
|
||||
promptTokens = derivePromptTokens(lastUsage) ?? lastUsage.total ?? input + output;
|
||||
const total = lastUsage.total ?? promptTokens + output;
|
||||
if (promptTokens === 0 && total === 0) return undefined;
|
||||
if (promptTokens === 0 && total === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return { input, output, promptTokens, total, model };
|
||||
} catch {
|
||||
return undefined;
|
||||
@@ -215,14 +251,18 @@ const readUsageFromSessionLog = (
|
||||
};
|
||||
|
||||
const formatUsagePair = (input?: number | null, output?: number | null) => {
|
||||
if (input == null && output == null) return null;
|
||||
if (input == null && output == null) {
|
||||
return null;
|
||||
}
|
||||
const inputLabel = typeof input === "number" ? formatTokenCount(input) : "?";
|
||||
const outputLabel = typeof output === "number" ? formatTokenCount(output) : "?";
|
||||
return `🧮 Tokens: ${inputLabel} in / ${outputLabel} out`;
|
||||
};
|
||||
|
||||
const formatMediaUnderstandingLine = (decisions?: MediaUnderstandingDecision[]) => {
|
||||
if (!decisions || decisions.length === 0) return null;
|
||||
if (!decisions || decisions.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const parts = decisions
|
||||
.map((decision) => {
|
||||
const count = decision.attachments.length;
|
||||
@@ -253,8 +293,12 @@ const formatMediaUnderstandingLine = (decisions?: MediaUnderstandingDecision[])
|
||||
return null;
|
||||
})
|
||||
.filter((part): part is string => part != null);
|
||||
if (parts.length === 0) return null;
|
||||
if (parts.every((part) => part.endsWith(" none"))) return null;
|
||||
if (parts.length === 0) {
|
||||
return null;
|
||||
}
|
||||
if (parts.every((part) => part.endsWith(" none"))) {
|
||||
return null;
|
||||
}
|
||||
return `📎 Media: ${parts.join(" · ")}`;
|
||||
};
|
||||
|
||||
@@ -262,7 +306,9 @@ const formatVoiceModeLine = (
|
||||
config?: OpenClawConfig,
|
||||
sessionEntry?: SessionEntry,
|
||||
): string | null => {
|
||||
if (!config) return null;
|
||||
if (!config) {
|
||||
return null;
|
||||
}
|
||||
const ttsConfig = resolveTtsConfig(config);
|
||||
const prefsPath = resolveTtsPrefsPath(ttsConfig);
|
||||
const autoMode = resolveTtsAutoMode({
|
||||
@@ -270,7 +316,9 @@ const formatVoiceModeLine = (
|
||||
prefsPath,
|
||||
sessionAuto: sessionEntry?.ttsAuto,
|
||||
});
|
||||
if (autoMode === "off") return null;
|
||||
if (autoMode === "off") {
|
||||
return null;
|
||||
}
|
||||
const provider = getTtsProvider(ttsConfig, prefsPath);
|
||||
const maxLength = getTtsMaxLength(prefsPath);
|
||||
const summarize = isSummarizationEnabled(prefsPath) ? "on" : "off";
|
||||
@@ -310,12 +358,18 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
if (!totalTokens || totalTokens === 0 || candidate > totalTokens) {
|
||||
totalTokens = candidate;
|
||||
}
|
||||
if (!model) model = logUsage.model ?? model;
|
||||
if (!model) {
|
||||
model = logUsage.model ?? model;
|
||||
}
|
||||
if (!contextTokens && logUsage.model) {
|
||||
contextTokens = lookupContextTokens(logUsage.model) ?? contextTokens;
|
||||
}
|
||||
if (!inputTokens || inputTokens === 0) inputTokens = logUsage.input;
|
||||
if (!outputTokens || outputTokens === 0) outputTokens = logUsage.output;
|
||||
if (!inputTokens || inputTokens === 0) {
|
||||
inputTokens = logUsage.input;
|
||||
}
|
||||
if (!outputTokens || outputTokens === 0) {
|
||||
outputTokens = logUsage.output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,8 +530,12 @@ export function buildHelpMessage(cfg?: OpenClawConfig): string {
|
||||
lines.push("");
|
||||
|
||||
const optionParts = ["/think <level>", "/model <id>", "/verbose on|off"];
|
||||
if (cfg?.commands?.config === true) optionParts.push("/config");
|
||||
if (cfg?.commands?.debug === true) optionParts.push("/debug");
|
||||
if (cfg?.commands?.config === true) {
|
||||
optionParts.push("/config");
|
||||
}
|
||||
if (cfg?.commands?.debug === true) {
|
||||
optionParts.push("/debug");
|
||||
}
|
||||
lines.push("Options");
|
||||
lines.push(` ${optionParts.join(" | ")}`);
|
||||
lines.push("");
|
||||
@@ -521,7 +579,9 @@ function formatCommandEntry(command: ChatCommandDefinition): string {
|
||||
.filter((alias) => alias.toLowerCase() !== primary.toLowerCase())
|
||||
.filter((alias) => {
|
||||
const key = alias.toLowerCase();
|
||||
if (seen.has(key)) return false;
|
||||
if (seen.has(key)) {
|
||||
return false;
|
||||
}
|
||||
seen.add(key);
|
||||
return true;
|
||||
});
|
||||
@@ -544,7 +604,9 @@ function buildCommandItems(
|
||||
|
||||
for (const category of CATEGORY_ORDER) {
|
||||
const categoryCommands = grouped.get(category) ?? [];
|
||||
if (categoryCommands.length === 0) continue;
|
||||
if (categoryCommands.length === 0) {
|
||||
continue;
|
||||
}
|
||||
const label = CATEGORY_LABELS[category];
|
||||
for (const command of categoryCommands) {
|
||||
items.push({ label, text: formatCommandEntry(command) });
|
||||
@@ -568,7 +630,9 @@ function formatCommandList(items: CommandsListItem[]): string {
|
||||
|
||||
for (const item of items) {
|
||||
if (item.label !== currentLabel) {
|
||||
if (lines.length > 0) lines.push("");
|
||||
if (lines.length > 0) {
|
||||
lines.push("");
|
||||
}
|
||||
lines.push(item.label);
|
||||
currentLabel = item.label;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user