From 6c69ea2c9151659ea1cd3d2aaed62e7b897d2153 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 21 Jan 2026 09:07:21 +0000 Subject: [PATCH] refactor: centralize sandbox runtime label --- src/auto-reply/status.test.ts | 19 +++++++++ src/auto-reply/status.ts | 72 ++++++++++++++++++----------------- 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/auto-reply/status.test.ts b/src/auto-reply/status.test.ts index ea7a96726..31b6b92ec 100644 --- a/src/auto-reply/status.test.ts +++ b/src/auto-reply/status.test.ts @@ -74,6 +74,25 @@ describe("buildStatusMessage", () => { expect(normalized).toContain("Queue: collect"); }); + it("uses per-agent sandbox config when config and session key are provided", () => { + const text = buildStatusMessage({ + config: { + agents: { + list: [ + { id: "main", default: true }, + { id: "discord", sandbox: { mode: "all" } }, + ], + }, + } as ClawdbotConfig, + agent: {}, + sessionKey: "agent:discord:discord:channel:1456350065223270435", + sessionScope: "per-sender", + queue: { mode: "collect", depth: 0 }, + }); + + expect(normalizeTestText(text)).toContain("Runtime: docker/all"); + }); + it("shows verbose/elevated labels only when enabled", () => { const text = buildStatusMessage({ agent: { model: "anthropic/claude-opus-4-5" }, diff --git a/src/auto-reply/status.ts b/src/auto-reply/status.ts index 2742492eb..2184c5f9a 100644 --- a/src/auto-reply/status.ts +++ b/src/auto-reply/status.ts @@ -59,6 +59,42 @@ type StatusArgs = { now?: number; }; +function resolveRuntimeLabel( + args: Pick, +): string { + const sessionKey = args.sessionKey?.trim(); + if (args.config && sessionKey) { + const runtimeStatus = resolveSandboxRuntimeStatus({ + cfg: args.config, + sessionKey, + }); + const sandboxMode = runtimeStatus.mode ?? "off"; + 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"; + const sandboxed = (() => { + if (!sessionKey) return false; + if (sandboxMode === "all") return true; + if (args.config) { + return resolveSandboxRuntimeStatus({ + cfg: args.config, + sessionKey, + }).sandboxed; + } + const sessionScope = args.sessionScope ?? "per-sender"; + const mainKey = resolveMainSessionKey({ + session: { scope: sessionScope }, + }); + return sessionKey !== mainKey.trim(); + })(); + const runtime = sandboxed ? "docker" : sessionKey ? "direct" : "unknown"; + return `${runtime}/${sandboxMode}`; +} + const formatTokens = (total: number | null | undefined, contextTokens: number | null) => { const ctx = contextTokens ?? null; if (total == null) { @@ -258,41 +294,7 @@ export function buildStatusMessage(args: StatusArgs): string { args.agent?.elevatedDefault ?? "on"; - const runtime = (() => { - const sessionKey = args.sessionKey?.trim(); - if (args.config && sessionKey) { - const runtimeStatus = resolveSandboxRuntimeStatus({ - cfg: args.config, - sessionKey, - }); - const sandboxMode = runtimeStatus.mode ?? "off"; - if (sandboxMode === "off") return { label: "direct" }; - const runtime = runtimeStatus.sandboxed ? "docker" : sessionKey ? "direct" : "unknown"; - return { label: `${runtime}/${sandboxMode}` }; - } - - const sandboxMode = args.agent?.sandbox?.mode ?? "off"; - if (sandboxMode === "off") return { label: "direct" }; - const sandboxed = (() => { - if (!sessionKey) return false; - if (sandboxMode === "all") return true; - if (args.config) { - return resolveSandboxRuntimeStatus({ - cfg: args.config, - sessionKey, - }).sandboxed; - } - const sessionScope = args.sessionScope ?? "per-sender"; - const mainKey = resolveMainSessionKey({ - session: { scope: sessionScope }, - }); - return sessionKey !== mainKey.trim(); - })(); - const runtime = sandboxed ? "docker" : sessionKey ? "direct" : "unknown"; - return { - label: `${runtime}/${sandboxMode}`, - }; - })(); + const runtime = { label: resolveRuntimeLabel(args) }; const updatedAt = entry?.updatedAt; const sessionLine = [