mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 08:11:38 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -35,19 +35,25 @@ let activeJob: ActiveBashJob | null = null;
|
||||
|
||||
function resolveForegroundMs(cfg: OpenClawConfig): number {
|
||||
const raw = cfg.commands?.bashForegroundMs;
|
||||
if (typeof raw !== "number" || Number.isNaN(raw)) return DEFAULT_FOREGROUND_MS;
|
||||
if (typeof raw !== "number" || Number.isNaN(raw)) {
|
||||
return DEFAULT_FOREGROUND_MS;
|
||||
}
|
||||
return clampInt(raw, 0, MAX_FOREGROUND_MS);
|
||||
}
|
||||
|
||||
function formatSessionSnippet(sessionId: string) {
|
||||
const trimmed = sessionId.trim();
|
||||
if (trimmed.length <= 12) return trimmed;
|
||||
if (trimmed.length <= 12) {
|
||||
return trimmed;
|
||||
}
|
||||
return `${trimmed.slice(0, 8)}…`;
|
||||
}
|
||||
|
||||
function formatOutputBlock(text: string) {
|
||||
const trimmed = text.trim();
|
||||
if (!trimmed) return "(no output)";
|
||||
if (!trimmed) {
|
||||
return "(no output)";
|
||||
}
|
||||
return `\`\`\`txt\n${trimmed}\n\`\`\``;
|
||||
}
|
||||
|
||||
@@ -56,7 +62,9 @@ function parseBashRequest(raw: string): BashRequest | null {
|
||||
let restSource = "";
|
||||
if (trimmed.toLowerCase().startsWith("/bash")) {
|
||||
const match = trimmed.match(/^\/bash(?:\s*:\s*|\s+|$)([\s\S]*)$/i);
|
||||
if (!match) return null;
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
restSource = match[1] ?? "";
|
||||
} else if (trimmed.startsWith("!")) {
|
||||
restSource = trimmed.slice(1);
|
||||
@@ -68,7 +76,9 @@ function parseBashRequest(raw: string): BashRequest | null {
|
||||
}
|
||||
|
||||
const rest = restSource.trimStart();
|
||||
if (!rest) return { action: "help" };
|
||||
if (!rest) {
|
||||
return { action: "help" };
|
||||
}
|
||||
const tokenMatch = rest.match(/^(\S+)(?:\s+([\s\S]+))?$/);
|
||||
const token = tokenMatch?.[1]?.trim() ?? "";
|
||||
const remainder = tokenMatch?.[2]?.trim() ?? "";
|
||||
@@ -100,17 +110,27 @@ function resolveRawCommandBody(params: {
|
||||
|
||||
function getScopedSession(sessionId: string) {
|
||||
const running = getSession(sessionId);
|
||||
if (running && running.scopeKey === CHAT_BASH_SCOPE_KEY) return { running };
|
||||
if (running && running.scopeKey === CHAT_BASH_SCOPE_KEY) {
|
||||
return { running };
|
||||
}
|
||||
const finished = getFinishedSession(sessionId);
|
||||
if (finished && finished.scopeKey === CHAT_BASH_SCOPE_KEY) return { finished };
|
||||
if (finished && finished.scopeKey === CHAT_BASH_SCOPE_KEY) {
|
||||
return { finished };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
function ensureActiveJobState() {
|
||||
if (!activeJob) return null;
|
||||
if (activeJob.state === "starting") return activeJob;
|
||||
if (!activeJob) {
|
||||
return null;
|
||||
}
|
||||
if (activeJob.state === "starting") {
|
||||
return activeJob;
|
||||
}
|
||||
const { running, finished } = getScopedSession(activeJob.sessionId);
|
||||
if (running) return activeJob;
|
||||
if (running) {
|
||||
return activeJob;
|
||||
}
|
||||
if (finished) {
|
||||
activeJob = null;
|
||||
return null;
|
||||
@@ -120,12 +140,20 @@ function ensureActiveJobState() {
|
||||
}
|
||||
|
||||
function attachActiveWatcher(sessionId: string) {
|
||||
if (!activeJob || activeJob.state !== "running") return;
|
||||
if (activeJob.sessionId !== sessionId) return;
|
||||
if (activeJob.watcherAttached) return;
|
||||
if (!activeJob || activeJob.state !== "running") {
|
||||
return;
|
||||
}
|
||||
if (activeJob.sessionId !== sessionId) {
|
||||
return;
|
||||
}
|
||||
if (activeJob.watcherAttached) {
|
||||
return;
|
||||
}
|
||||
const { running } = getScopedSession(sessionId);
|
||||
const child = running?.child;
|
||||
if (!child) return;
|
||||
if (!child) {
|
||||
return;
|
||||
}
|
||||
activeJob.watcherAttached = true;
|
||||
child.once("close", () => {
|
||||
if (activeJob?.state === "running" && activeJob.sessionId === sessionId) {
|
||||
@@ -317,7 +345,9 @@ export async function handleBashChatCommand(params: {
|
||||
}
|
||||
|
||||
const commandText = request.command.trim();
|
||||
if (!commandText) return buildUsageReply();
|
||||
if (!commandText) {
|
||||
return buildUsageReply();
|
||||
}
|
||||
|
||||
activeJob = {
|
||||
state: "starting",
|
||||
|
||||
Reference in New Issue
Block a user