diff --git a/CHANGELOG.md b/CHANGELOG.md index e68511a6c..86a0ba0ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Docs: https://docs.clawd.bot ||||||| parent of 903e9be49 (feat: surface node core/ui versions in macOS) ### Fixes +- Tools: clamp bash foreground duration using shared helpers. - Auth profiles: keep auto-pinned preference while allowing rotation on failover; user pins stay locked. (#1138) — thanks @cheeeee. - macOS: avoid touching launchd in Remote over SSH so quitting the app no longer disables the remote gateway. (#1105) - Memory: index atomically so failed reindex preserves the previous memory database. (#1151) diff --git a/src/auto-reply/reply/bash-command.ts b/src/auto-reply/reply/bash-command.ts index 74f341910..0e81c22ce 100644 --- a/src/auto-reply/reply/bash-command.ts +++ b/src/auto-reply/reply/bash-command.ts @@ -5,6 +5,7 @@ import { resolveSandboxRuntimeStatus } from "../../agents/sandbox.js"; import { killProcessTree } from "../../agents/shell-utils.js"; import type { ClawdbotConfig } from "../../config/config.js"; import { logVerbose } from "../../globals.js"; +import { clampInt } from "../../utils.js"; import type { MsgContext } from "../templating.js"; import type { ReplyPayload } from "../types.js"; import { stripMentions, stripStructuralPrefixes } from "./mentions.js"; @@ -31,14 +32,10 @@ type ActiveBashJob = let activeJob: ActiveBashJob | null = null; -function clampNumber(value: number, min: number, max: number) { - return Math.min(Math.max(value, min), max); -} - function resolveForegroundMs(cfg: ClawdbotConfig): number { const raw = cfg.commands?.bashForegroundMs; if (typeof raw !== "number" || Number.isNaN(raw)) return DEFAULT_FOREGROUND_MS; - return clampNumber(Math.floor(raw), 0, MAX_FOREGROUND_MS); + return clampInt(raw, 0, MAX_FOREGROUND_MS); } function formatSessionSnippet(sessionId: string) { diff --git a/src/utils.ts b/src/utils.ts index 14cb9880c..a2f048613 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -8,6 +8,14 @@ export async function ensureDir(dir: string) { await fs.promises.mkdir(dir, { recursive: true }); } +export function clampNumber(value: number, min: number, max: number): number { + return Math.max(min, Math.min(max, value)); +} + +export function clampInt(value: number, min: number, max: number): number { + return clampNumber(Math.floor(value), min, max); +} + export type WebChannel = "web"; export function assertWebChannel(input: string): asserts input is WebChannel {