fix(approval): always render the full command in approval prompts#3
Merged
Conversation
Both the Telegram and terminal approval surfaces could show the command-to-approve incompletely, undermining the user's ability to make an informed decision. Telegram (internal/telegram/approver.go): - When the model supplied a description, the command was hidden entirely and only the description was shown — the user approved a command they could not see. The full command is now always rendered in a fenced code block, with the description shown as a separate "Why:" line. - The command was byte-sliced to 200 chars (UTF-8 unsafe, silent). It is now only truncated when the whole message would exceed Telegram's hard 4096-char limit, on a rune boundary, with an explicit "[truncated]" marker. - Command content inside the code fence was unescaped, so a backtick or backslash could close the fence early and corrupt rendering. Added escapeCodeBlock() to escape ` and \ for MarkdownV2 code blocks. Terminal (internal/narrate/narrate.go): - extractShell scanned for the first quote pair, so any command with an embedded quote (git commit -m "msg", python -c "code") was cut at the first inner quote. It now decodes the JSON args properly, with the old scan kept only as a malformed-input fallback. - The shell narration was byte-truncated at 50 chars; truncate() is now rune-safe and the shell budget is raised to 120. Adds tests covering full-command rendering, code-block escaping, hard-limit truncation, embedded-quote extraction, and rune-safe cuts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On both Telegram and the terminal, the command shown at approval time could be rendered incompletely. Approving a command you can't fully see defeats the purpose of the approval gate.
Root causes
Telegram —
internal/telegram/approver.godescription, the actual command was never rendered, so the user approved a command they could not see.desc[:200] + "..."— a byte slice (UTF-8 unsafe) that silently dropped the rest.```block unescaped, so a backtick or backslash could close the fence early and corrupt the whole message.Terminal —
internal/narrate/narrate.goextractShellbroke on embedded quotes. It scanned for the first"pair, sogit commit -m "msg"orpython -c "code"was cut at the first inner quote.Changes
Why:line; escape`and\for MarkdownV2 code blocks (escapeCodeBlock); only truncate when the message would exceed Telegram's hard 4096-char limit, on a rune boundary, with an explicit[truncated]marker.extractShellnow decodes the JSON args properly (old scan kept as a malformed-input fallback);truncateis rune-safe; shell narration budget raised 50 → 120.Tests
Added coverage for: full-command-always-shown (with description), code-block escaping, hard-limit truncation, embedded-quote extraction, and rune-safe truncation. All
internal/telegramandinternal/narratetests pass;go vetandgofmtclean.🤖 Generated with Claude Code