Skip to content

fix(tee): quote recovery hint paths with spaces - #2325

Merged
TaKO8Ki merged 3 commits into
rtk-ai:developfrom
fengjikui:fix/escaped-space-tee-path
Jul 28, 2026
Merged

TaKO8Ki merged 3 commits into
rtk-ai:developfrom
fengjikui:fix/escaped-space-tee-path

Conversation

@fengjikui

Copy link
Copy Markdown
Contributor

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 --check
  • cargo test core::tee::tests
  • cargo clippy --all-targets -- -D warnings
  • cargo test

pszymkowiak
pszymkowiak previously approved these changes Jul 24, 2026

@pszymkowiak pszymkowiak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 check with 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.

@pszymkowiak
pszymkowiak dismissed their stale review July 24, 2026 10:51

Retrait de l'approbation à la demande de l'auteur.

@pszymkowiak pszymkowiak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pszymkowiak
pszymkowiak requested a review from TaKO8Ki July 24, 2026 11:22

@TaKO8Ki TaKO8Ki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I left a comment.

Comment thread src/core/tee.rs Resolved
TaKO8Ki
TaKO8Ki previously approved these changes Jul 27, 2026
@TaKO8Ki
TaKO8Ki dismissed their stale review July 27, 2026 11:56

CI failure

@TaKO8Ki TaKO8Ki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI failed on Windows. Could you check it?

@fengjikui

Copy link
Copy Markdown
Contributor Author

Checked and fixed in 5de188b. The two failing tests used home-relative paths built with PathBuf::join; on Windows, display() emitted \\ separators, so the quoted $HOME/... hints escaped them as literal backslashes. The home-relative shell branch now normalizes the platform separator to / before quoting, while non-home paths and literal backslashes keep their existing escaping behavior. Local validation: tee tests (25 passed), full suite (2077 passed, 7 ignored), clippy with -D warnings, and fmt all pass. The pushed CI run will provide the Windows-target confirmation.

@TaKO8Ki TaKO8Ki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@TaKO8Ki
TaKO8Ki merged commit 8a24ce2 into rtk-ai:develop Jul 28, 2026
11 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClaudeCode keeps asking for permissions to read rtk logs in ~/Library/Application Support/ because of backslash in path

3 participants