Repository navigation
fix(tee): quote recovery hint paths with spaces - #2325
Conversation
pszymkowiak
left a comment
There was a problem hiding this comment.
Approved after review + real-binary verification (built origin/develop + this PR, exercised the compiled release binary on macOS).
Correctness — the fix is at the right layer. Both hint formatters (format_hint → [full output: …] and force_tee_tail_hint → [see remaining: tail …]) route through the new display_shell_path. I grepped every hint emitter in the tree (go, uv, cargo, dotnet, ruff, eslint/pylint, pnpm, aws, glab, docker/kubectl, git, gh, grep, curl, rubocop) plus the TOML engine's tee_payload/tail_offset consumer in main.rs — all of them go through these two functions, so patching the choke point covers 100% of cases. Uses "$HOME/…" rather than a quoted ~ (correct — ~ doesn't expand inside quotes), and escapes `\ " $ `` — the right set for a double-quoted context.
Verified end-to-end on the compiled binary (this was the actual bug):
- Before:
[see remaining: tail -n +26 ~/Library/Application Support/rtk/tee/…]→ pasted literally,tail: …/Application: No such file. - After:
[see remaining: tail -n +26 "$HOME/Library/Application Support/rtk/tee/…"]→ literal copy-paste recovers the omitted lines. - Confirmed on a non-uv path too (
rtk ruff checkwith 320 violations → 270 lines recovered) and on a failure-path[full output: …]hint (100/100 pre-crash stdout lines recovered). So the quoting is universal, not uv-specific.
No regressions: merges cleanly on current develop; full suite 2559 passed, 0 failed; clippy --all-targets clean; the 4 added unit tests cover simple-path-unchanged, absolute-with-space, home→$HOME, and the no-backslash-escaping assertion.
Minor (non-blocking): [full output: "$HOME/…"] is more informational than a runnable command, so an agent that opens the path directly (not via a shell) now has to strip the quotes and expand $HOME. The shell copy-paste case (the subject of #1858) dominates, so this is the right trade-off.
Small, correct, well-tested fix that makes recovery hints actually usable on macOS. LGTM.
Retrait de l'approbation à la demande de l'auteur.
pszymkowiak
left a comment
There was a problem hiding this comment.
Re-approving after a deeper adversarial pass (built origin/develop + this PR, exercised the compiled binary on macOS).
Security — command injection neutralized (verified, not just by inspection). With a booby-trapped tee dir /tmp/a $(touch /tmp/RTK_PWN) b, the emitted hint escapes the substitution:
[see remaining: tail -n +26 "/tmp/a \$(touch /tmp/RTK_PWN) b/…log"]. Pasting it literally recovers the file (65 lines) and does not execute the injected command. The `\ " $ `` escape set does its job under attack.
Coverage — the fix is at the single choke point. Both hint formatters (format_hint, force_tee_tail_hint) route through display_shell_path; a full grep of every hint emitter (go, uv, cargo, dotnet, ruff, eslint/pylint, pnpm, aws, glab, docker/kubectl, git, gh, grep, curl, rubocop) plus the TOML engine's consumer in main.rs confirms 100% go through these two. No code parses the hint back, so changing ~/path → "$HOME/path" is integration-safe.
Realistic case works end-to-end. Default macOS dir (~/Library/Application Support, has a space) → "$HOME/…", literal copy-paste recovers the omitted lines. Verified on a non-uv path too (rtk ruff check, 270 lines recovered) and on a failure-path [full output: …] hint (100/100 pre-crash lines).
No regressions: merges clean on current develop; full suite 2559 passed / 0 failed; clippy clean.
One non-blocking suggestion: the $/"/backtick escaping (the security-relevant part) has no direct unit test — escape_double_quoted_path is only covered indirectly. A small test feeding a path with $(…)/\"/backtick would lock in the property. Nice-to-have, not a blocker.
Investigated a suspected 'long path suppresses the hint' issue and it turned out to be a non-bug — that's just never_worse correctly showing full raw when truncation isn't a net token win (no data loss; large outputs keep the hint regardless of path length).
Correct, secure, well-scoped. LGTM.
TaKO8Ki
left a comment
There was a problem hiding this comment.
Thank you. I left a comment.
TaKO8Ki
left a comment
There was a problem hiding this comment.
The CI failed on Windows. Could you check it?
|
Checked and fixed in |
Summary
Fixes #1858. RTK recovery hints can point at macOS tee files under
~/Library/Application Support/.... When that path is copied into a shell command, agents tend to use backslash-escaped whitespace (Application\ Support), which makes Claude Code ask for permission again.This keeps simple hint paths unchanged, but renders paths that need shell quoting as copy-paste-safe double-quoted paths. For home-relative paths with spaces, it uses
"$HOME/..."instead of quoting~, because~does not expand inside quotes.Related to #2187, but this keeps the compact
~/...display for simple paths and directly quotes paths with spaces instead of only rendering an absolute path.Validation
cargo fmt --checkcargo test core::tee::testscargo clippy --all-targets -- -D warningscargo test