mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 20:08:26 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -28,19 +28,31 @@ const NESTED_LOG_PREFIX = "[agent:nested]";
|
||||
function formatNestedLogPrefix(opts: AgentCommandOpts): string {
|
||||
const parts = [NESTED_LOG_PREFIX];
|
||||
const session = opts.sessionKey ?? opts.sessionId;
|
||||
if (session) parts.push(`session=${session}`);
|
||||
if (opts.runId) parts.push(`run=${opts.runId}`);
|
||||
if (session) {
|
||||
parts.push(`session=${session}`);
|
||||
}
|
||||
if (opts.runId) {
|
||||
parts.push(`run=${opts.runId}`);
|
||||
}
|
||||
const channel = opts.messageChannel ?? opts.channel;
|
||||
if (channel) parts.push(`channel=${channel}`);
|
||||
if (opts.to) parts.push(`to=${opts.to}`);
|
||||
if (opts.accountId) parts.push(`account=${opts.accountId}`);
|
||||
if (channel) {
|
||||
parts.push(`channel=${channel}`);
|
||||
}
|
||||
if (opts.to) {
|
||||
parts.push(`to=${opts.to}`);
|
||||
}
|
||||
if (opts.accountId) {
|
||||
parts.push(`account=${opts.accountId}`);
|
||||
}
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
function logNestedOutput(runtime: RuntimeEnv, opts: AgentCommandOpts, output: string) {
|
||||
const prefix = formatNestedLogPrefix(opts);
|
||||
for (const line of output.split(/\r?\n/)) {
|
||||
if (!line) continue;
|
||||
if (!line) {
|
||||
continue;
|
||||
}
|
||||
runtime.log(`${prefix} ${line}`);
|
||||
}
|
||||
}
|
||||
@@ -102,16 +114,22 @@ export async function deliverAgentCommandResult(params: {
|
||||
const logDeliveryError = (err: unknown) => {
|
||||
const message = `Delivery failed (${deliveryChannel}${deliveryTarget ? ` to ${deliveryTarget}` : ""}): ${String(err)}`;
|
||||
runtime.error?.(message);
|
||||
if (!runtime.error) runtime.log(message);
|
||||
if (!runtime.error) {
|
||||
runtime.log(message);
|
||||
}
|
||||
};
|
||||
|
||||
if (deliver) {
|
||||
if (!isDeliveryChannelKnown) {
|
||||
const err = new Error(`Unknown channel: ${deliveryChannel}`);
|
||||
if (!bestEffortDeliver) throw err;
|
||||
if (!bestEffortDeliver) {
|
||||
throw err;
|
||||
}
|
||||
logDeliveryError(err);
|
||||
} else if (resolvedTarget && !resolvedTarget.ok) {
|
||||
if (!bestEffortDeliver) throw resolvedTarget.error;
|
||||
if (!bestEffortDeliver) {
|
||||
throw resolvedTarget.error;
|
||||
}
|
||||
logDeliveryError(resolvedTarget.error);
|
||||
}
|
||||
}
|
||||
@@ -128,7 +146,9 @@ export async function deliverAgentCommandResult(params: {
|
||||
2,
|
||||
),
|
||||
);
|
||||
if (!deliver) return { payloads: normalizedPayloads, meta: result.meta };
|
||||
if (!deliver) {
|
||||
return { payloads: normalizedPayloads, meta: result.meta };
|
||||
}
|
||||
}
|
||||
|
||||
if (!payloads || payloads.length === 0) {
|
||||
@@ -138,9 +158,13 @@ export async function deliverAgentCommandResult(params: {
|
||||
|
||||
const deliveryPayloads = normalizeOutboundPayloads(payloads);
|
||||
const logPayload = (payload: NormalizedOutboundPayload) => {
|
||||
if (opts.json) return;
|
||||
if (opts.json) {
|
||||
return;
|
||||
}
|
||||
const output = formatOutboundPayloadLog(payload);
|
||||
if (!output) return;
|
||||
if (!output) {
|
||||
return;
|
||||
}
|
||||
if (opts.lane === AGENT_LANE_NESTED) {
|
||||
logNestedOutput(runtime, opts, output);
|
||||
return;
|
||||
@@ -148,7 +172,9 @@ export async function deliverAgentCommandResult(params: {
|
||||
runtime.log(output);
|
||||
};
|
||||
if (!deliver) {
|
||||
for (const payload of deliveryPayloads) logPayload(payload);
|
||||
for (const payload of deliveryPayloads) {
|
||||
logPayload(payload);
|
||||
}
|
||||
}
|
||||
if (deliver && deliveryChannel && !isInternalMessageChannel(deliveryChannel)) {
|
||||
if (deliveryTarget) {
|
||||
|
||||
@@ -9,19 +9,29 @@ export function resolveAgentRunContext(opts: AgentCommandOpts): AgentRunContext
|
||||
merged.messageChannel ?? opts.messageChannel,
|
||||
opts.replyChannel ?? opts.channel,
|
||||
);
|
||||
if (normalizedChannel) merged.messageChannel = normalizedChannel;
|
||||
if (normalizedChannel) {
|
||||
merged.messageChannel = normalizedChannel;
|
||||
}
|
||||
|
||||
const normalizedAccountId = normalizeAccountId(merged.accountId ?? opts.accountId);
|
||||
if (normalizedAccountId) merged.accountId = normalizedAccountId;
|
||||
if (normalizedAccountId) {
|
||||
merged.accountId = normalizedAccountId;
|
||||
}
|
||||
|
||||
const groupId = (merged.groupId ?? opts.groupId)?.toString().trim();
|
||||
if (groupId) merged.groupId = groupId;
|
||||
if (groupId) {
|
||||
merged.groupId = groupId;
|
||||
}
|
||||
|
||||
const groupChannel = (merged.groupChannel ?? opts.groupChannel)?.toString().trim();
|
||||
if (groupChannel) merged.groupChannel = groupChannel;
|
||||
if (groupChannel) {
|
||||
merged.groupChannel = groupChannel;
|
||||
}
|
||||
|
||||
const groupSpace = (merged.groupSpace ?? opts.groupSpace)?.toString().trim();
|
||||
if (groupSpace) merged.groupSpace = groupSpace;
|
||||
if (groupSpace) {
|
||||
merged.groupSpace = groupSpace;
|
||||
}
|
||||
|
||||
if (
|
||||
merged.currentThreadTs == null &&
|
||||
|
||||
@@ -56,7 +56,9 @@ export async function updateSessionStoreAfterAgentRun(params: {
|
||||
};
|
||||
if (isCliProvider(providerUsed, cfg)) {
|
||||
const cliSessionId = result.meta.agentMeta?.sessionId?.trim();
|
||||
if (cliSessionId) setCliSessionId(next, providerUsed, cliSessionId);
|
||||
if (cliSessionId) {
|
||||
setCliSessionId(next, providerUsed, cliSessionId);
|
||||
}
|
||||
}
|
||||
next.abortedLastRun = result.meta.aborted ?? false;
|
||||
if (hasNonzeroUsage(usage)) {
|
||||
|
||||
@@ -74,7 +74,9 @@ export function resolveSessionKeyForRequest(opts: {
|
||||
const foundKey = Object.keys(sessionStore).find(
|
||||
(key) => sessionStore[key]?.sessionId === opts.sessionId,
|
||||
);
|
||||
if (foundKey) sessionKey = foundKey;
|
||||
if (foundKey) {
|
||||
sessionKey = foundKey;
|
||||
}
|
||||
}
|
||||
|
||||
return { sessionKey, sessionStore, storePath };
|
||||
|
||||
Reference in New Issue
Block a user