Skip to content

fix(tracking): store commands so they read back as the same words - #4403

Merged
KuSh merged 1 commit into
developfrom
fix/tracked-command-quoting
Oct 6, 2026
Merged

KuSh merged 1 commit into
developfrom
fix/tracked-command-quoting

Conversation

@KuSh

@KuSh KuSh commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

rtk gain --history and rtk discover read back the command each handler records. Handlers built that string by joining argv with spaces, which loses word boundaries: grep -n 'a b' f and grep -n a b f were stored the same, and grep 'foo()' f was stored as shell syntax.

  • One helper in core/shell.rs (with_args, on top of display_args) quotes only the words that need it, as shlex.quote does. Plain commands look the same as before.
  • Every handler that records a command goes through it. A test scans src/ for a tracked label built by joining words with a space, so a new one fails CI.
  • A passthrough run is recorded as rtk:passthrough <command> instead of <command> (passthrough).
  • Stored rows are read back with the project's lexer. A row that is not spelled the way the helper writes it, such as one recorded before this change, is split on whitespace instead.

Nothing changes in what rtk executes; only what it records.

Test plan

  • cargo fmt --all --check && cargo clippy --all-targets -- -D warnings && cargo test --all green on the rebased commit
  • wincheck.sh (cfg(windows) type-check) clean
  • Unit tests for the quoting helper (plain words, blanks, each special-byte class, inner ', the empty word, non-ASCII) and for the stored labels of find, passthrough runs and old rows

🤖 Generated with Claude Code

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added area:cli bug Something isn't working tracking labels Oct 2, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes command tracking so stored commands preserve word boundaries by quoting only words that need it (like shlex.quote), instead of naively joining argv with spaces. Adds a shared display_args/with_args helper in core/shell.rs used across all tracking call sites, changes passthrough labeling to rtk:passthrough <command>, and ensures old unquoted rows still parse correctly via whitespace splitting.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

@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.

After resolving the conflicts, it looks good to me.

@KuSh
KuSh force-pushed the fix/tracked-command-quoting branch 2 times, most recently from b4bea1c to 421510e Compare October 6, 2026 21:52
Tracked commands quote each argv word the way shlex.quote does, so
`grep -n 'a b' f` and `grep -n a b f` stay distinct and `foo()` is not
stored as shell syntax. A word starting with `=` is quoted too, and so is
a program word a shell would not run as a program (`NAME=value`, or a
reserved word such as `time`). A passthrough run is recorded as
`rtk:passthrough <command>`. Words made only of safe characters are
written as they are, so plain commands look the same in
`rtk gain --history`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@KuSh
KuSh force-pushed the fix/tracked-command-quoting branch from 421510e to 87d1b18 Compare October 6, 2026 22:02
@KuSh
KuSh merged commit dd9edb5 into develop Oct 6, 2026
17 checks passed
@KuSh
KuSh deleted the fix/tracked-command-quoting branch October 6, 2026 22:17
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli bug Something isn't working tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants