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:
Seb Slight
2026-02-08 10:48:52 -05:00
committed by GitHub
parent 744892de72
commit ad8b839aa7
3 changed files with 114 additions and 1 deletions

View File

@@ -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}`);
}