fix(utils): share clamp helpers
Co-authored-by: Gustavo Madeira Santana <gumadeiras@gmail.com>
This commit is contained in:
committed by
Peter Steinberger
parent
810394f43b
commit
7252938339
@@ -26,6 +26,7 @@ Docs: https://docs.clawd.bot
|
|||||||
||||||| parent of 903e9be49 (feat: surface node core/ui versions in macOS)
|
||||||| parent of 903e9be49 (feat: surface node core/ui versions in macOS)
|
||||||
|
|
||||||
### Fixes
|
### 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.
|
- 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)
|
- 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)
|
- Memory: index atomically so failed reindex preserves the previous memory database. (#1151)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { resolveSandboxRuntimeStatus } from "../../agents/sandbox.js";
|
|||||||
import { killProcessTree } from "../../agents/shell-utils.js";
|
import { killProcessTree } from "../../agents/shell-utils.js";
|
||||||
import type { ClawdbotConfig } from "../../config/config.js";
|
import type { ClawdbotConfig } from "../../config/config.js";
|
||||||
import { logVerbose } from "../../globals.js";
|
import { logVerbose } from "../../globals.js";
|
||||||
|
import { clampInt } from "../../utils.js";
|
||||||
import type { MsgContext } from "../templating.js";
|
import type { MsgContext } from "../templating.js";
|
||||||
import type { ReplyPayload } from "../types.js";
|
import type { ReplyPayload } from "../types.js";
|
||||||
import { stripMentions, stripStructuralPrefixes } from "./mentions.js";
|
import { stripMentions, stripStructuralPrefixes } from "./mentions.js";
|
||||||
@@ -31,14 +32,10 @@ type ActiveBashJob =
|
|||||||
|
|
||||||
let activeJob: ActiveBashJob | null = null;
|
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 {
|
function resolveForegroundMs(cfg: ClawdbotConfig): number {
|
||||||
const raw = cfg.commands?.bashForegroundMs;
|
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 clampNumber(Math.floor(raw), 0, MAX_FOREGROUND_MS);
|
return clampInt(raw, 0, MAX_FOREGROUND_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatSessionSnippet(sessionId: string) {
|
function formatSessionSnippet(sessionId: string) {
|
||||||
|
|||||||
@@ -8,6 +8,14 @@ export async function ensureDir(dir: string) {
|
|||||||
await fs.promises.mkdir(dir, { recursive: true });
|
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 type WebChannel = "web";
|
||||||
|
|
||||||
export function assertWebChannel(input: string): asserts input is WebChannel {
|
export function assertWebChannel(input: string): asserts input is WebChannel {
|
||||||
|
|||||||
Reference in New Issue
Block a user