mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:38:27 +00:00
Exec approvals: render forwarded commands in monospace (#11937)
* fix(exec-approvals): format forwarded commands as code * fix(exec-approvals): place fenced command blocks on new line (#11937) (thanks @sebslight)
This commit is contained in:
@@ -115,9 +115,27 @@ function buildTargetKey(target: ExecApprovalForwardTarget): string {
|
||||
return [channel, target.to, accountId, threadId].join(":");
|
||||
}
|
||||
|
||||
function formatApprovalCommand(command: string): { inline: boolean; text: string } {
|
||||
if (!command.includes("\n") && !command.includes("`")) {
|
||||
return { inline: true, text: `\`${command}\`` };
|
||||
}
|
||||
|
||||
let fence = "```";
|
||||
while (command.includes(fence)) {
|
||||
fence += "`";
|
||||
}
|
||||
return { inline: false, text: `${fence}\n${command}\n${fence}` };
|
||||
}
|
||||
|
||||
function buildRequestMessage(request: ExecApprovalRequest, nowMs: number) {
|
||||
const lines: string[] = ["🔒 Exec approval required", `ID: ${request.id}`];
|
||||
lines.push(`Command: ${request.request.command}`);
|
||||
const command = formatApprovalCommand(request.request.command);
|
||||
if (command.inline) {
|
||||
lines.push(`Command: ${command.text}`);
|
||||
} else {
|
||||
lines.push("Command:");
|
||||
lines.push(command.text);
|
||||
}
|
||||
if (request.request.cwd) {
|
||||
lines.push(`CWD: ${request.request.cwd}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user