From e401e2584d985a720bbea6def0e43516e7a5f124 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 14 Feb 2026 14:49:26 +0000 Subject: [PATCH] refactor(auto-reply): share elevated unavailable message --- src/auto-reply/reply/bash-command.ts | 31 +------------------- src/auto-reply/reply/elevated-unavailable.ts | 30 +++++++++++++++++++ src/auto-reply/reply/reply-elevated.ts | 31 +------------------- 3 files changed, 32 insertions(+), 60 deletions(-) create mode 100644 src/auto-reply/reply/elevated-unavailable.ts diff --git a/src/auto-reply/reply/bash-command.ts b/src/auto-reply/reply/bash-command.ts index 9d0449de8..b52f84ccc 100644 --- a/src/auto-reply/reply/bash-command.ts +++ b/src/auto-reply/reply/bash-command.ts @@ -6,9 +6,9 @@ import { getFinishedSession, getSession, markExited } from "../../agents/bash-pr import { createExecTool } from "../../agents/bash-tools.js"; import { resolveSandboxRuntimeStatus } from "../../agents/sandbox.js"; import { killProcessTree } from "../../agents/shell-utils.js"; -import { formatCliCommand } from "../../cli/command-format.js"; import { logVerbose } from "../../globals.js"; import { clampInt } from "../../utils.js"; +import { formatElevatedUnavailableMessage } from "./elevated-unavailable.js"; import { stripMentions, stripStructuralPrefixes } from "./mentions.js"; const CHAT_BASH_SCOPE_KEY = "chat:bash"; @@ -174,35 +174,6 @@ function buildUsageReply(): ReplyPayload { }; } -function formatElevatedUnavailableMessage(params: { - runtimeSandboxed: boolean; - failures: Array<{ gate: string; key: string }>; - sessionKey?: string; -}): string { - const lines: string[] = []; - lines.push( - `elevated is not available right now (runtime=${params.runtimeSandboxed ? "sandboxed" : "direct"}).`, - ); - if (params.failures.length > 0) { - lines.push(`Failing gates: ${params.failures.map((f) => `${f.gate} (${f.key})`).join(", ")}`); - } else { - lines.push( - "Failing gates: enabled (tools.elevated.enabled / agents.list[].tools.elevated.enabled), allowFrom (tools.elevated.allowFrom.).", - ); - } - lines.push("Fix-it keys:"); - lines.push("- tools.elevated.enabled"); - lines.push("- tools.elevated.allowFrom."); - lines.push("- agents.list[].tools.elevated.enabled"); - lines.push("- agents.list[].tools.elevated.allowFrom."); - if (params.sessionKey) { - lines.push( - `See: ${formatCliCommand(`openclaw sandbox explain --session ${params.sessionKey}`)}`, - ); - } - return lines.join("\n"); -} - export async function handleBashChatCommand(params: { ctx: MsgContext; cfg: OpenClawConfig; diff --git a/src/auto-reply/reply/elevated-unavailable.ts b/src/auto-reply/reply/elevated-unavailable.ts new file mode 100644 index 000000000..ed30fa563 --- /dev/null +++ b/src/auto-reply/reply/elevated-unavailable.ts @@ -0,0 +1,30 @@ +import { formatCliCommand } from "../../cli/command-format.js"; + +export function formatElevatedUnavailableMessage(params: { + runtimeSandboxed: boolean; + failures: Array<{ gate: string; key: string }>; + sessionKey?: string; +}): string { + const lines: string[] = []; + lines.push( + `elevated is not available right now (runtime=${params.runtimeSandboxed ? "sandboxed" : "direct"}).`, + ); + if (params.failures.length > 0) { + lines.push(`Failing gates: ${params.failures.map((f) => `${f.gate} (${f.key})`).join(", ")}`); + } else { + lines.push( + "Failing gates: enabled (tools.elevated.enabled / agents.list[].tools.elevated.enabled), allowFrom (tools.elevated.allowFrom.).", + ); + } + lines.push("Fix-it keys:"); + lines.push("- tools.elevated.enabled"); + lines.push("- tools.elevated.allowFrom."); + lines.push("- agents.list[].tools.elevated.enabled"); + lines.push("- agents.list[].tools.elevated.allowFrom."); + if (params.sessionKey) { + lines.push( + `See: ${formatCliCommand(`openclaw sandbox explain --session ${params.sessionKey}`)}`, + ); + } + return lines.join("\n"); +} diff --git a/src/auto-reply/reply/reply-elevated.ts b/src/auto-reply/reply/reply-elevated.ts index 4b66fc63a..8b5166190 100644 --- a/src/auto-reply/reply/reply-elevated.ts +++ b/src/auto-reply/reply/reply-elevated.ts @@ -4,8 +4,8 @@ import { resolveAgentConfig } from "../../agents/agent-scope.js"; import { getChannelDock } from "../../channels/dock.js"; import { normalizeChannelId } from "../../channels/plugins/index.js"; import { CHAT_CHANNEL_ORDER } from "../../channels/registry.js"; -import { formatCliCommand } from "../../cli/command-format.js"; import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js"; +export { formatElevatedUnavailableMessage } from "./elevated-unavailable.js"; function normalizeAllowToken(value?: string) { if (!value) { @@ -202,32 +202,3 @@ export function resolveElevatedPermissions(params: { } return { enabled, allowed: globalAllowed && agentAllowed, failures }; } - -export function formatElevatedUnavailableMessage(params: { - runtimeSandboxed: boolean; - failures: Array<{ gate: string; key: string }>; - sessionKey?: string; -}): string { - const lines: string[] = []; - lines.push( - `elevated is not available right now (runtime=${params.runtimeSandboxed ? "sandboxed" : "direct"}).`, - ); - if (params.failures.length > 0) { - lines.push(`Failing gates: ${params.failures.map((f) => `${f.gate} (${f.key})`).join(", ")}`); - } else { - lines.push( - "Failing gates: enabled (tools.elevated.enabled / agents.list[].tools.elevated.enabled), allowFrom (tools.elevated.allowFrom.).", - ); - } - lines.push("Fix-it keys:"); - lines.push("- tools.elevated.enabled"); - lines.push("- tools.elevated.allowFrom."); - lines.push("- agents.list[].tools.elevated.enabled"); - lines.push("- agents.list[].tools.elevated.allowFrom."); - if (params.sessionKey) { - lines.push( - `See: ${formatCliCommand(`openclaw sandbox explain --session ${params.sessionKey}`)}`, - ); - } - return lines.join("\n"); -}