Skip to content

feat: route ssh/scp (+ timeout wrapper) and add dedup_repeats TOML action#2948

Open
melchior123 wants to merge 2 commits into
rtk-ai:developfrom
melchior123:feat/dedup-repeats-ssh-scp
Open

feat: route ssh/scp (+ timeout wrapper) and add dedup_repeats TOML action#2948
melchior123 wants to merge 2 commits into
rtk-ai:developfrom
melchior123:feat/dedup-repeats-ssh-scp

Conversation

@melchior123

@melchior123 melchior123 commented Jul 11, 2026

Copy link
Copy Markdown

Summary

Makes ssh/scp output flow through RTK, adds a dedup_repeats TOML action for repetitive log output, and strips the timeout wrapper so timeout-wrapped commands still route.

Why: ssh is one of the highest-volume commands in real agent sessions — remote diagnostics like journalctl, docker logs, dmesg, virsh list. A scan of my Claude Code history showed ~2000 ssh invocations in 30 days, none compressed, because ssh was never registered as a rewritable command (an ssh.toml filter existed but nothing routed to it). A further ~140 were wrapped in timeout <N> ssh ..., which bypassed routing entirely because the command starts with timeout. Remote log output is also highly repetitive, which the pipeline had no way to collapse.

Changes

  • core/toml_filter.rs — new dedup_repeats bool action, pipeline stage 4.5 (after strip/keep, before truncate). Collapses runs of consecutive identical lines into a [xN] suffix. Trailing whitespace ignored; blank lines never merged. Non-lossy — the count preserves the information, so no tee fallback triggers.
  • discover/rules.rs — register ^ssh\brtk ssh and ^scp\brtk scp.
  • discover/registry.rsstrip_timeout_prefix(): strips a timeout [OPTS] DURATION wrapper (mandatory duration + optional -s/-k with args, --preserve-status, etc.), routes the inner command, and re-prepends the wrapper verbatim. Can't use BUILTIN_TRANSPARENT_PREFIXES because that path is fixed-word only.
  • filters/ssh.toml — enable dedup_repeats; strip additional connection noise (Last login, X11 forwarding request failed, Shared connection ... closed). New inline test for the dedup path.
  • filters/scp.toml — new filter: strips banners/progress, keeps transfer errors.

Examples

$ rtk ssh host 'journalctl -u docker -n 500'
Mar 10 12:00:01 host dockerd[812]: connection reset by peer [x37]
Mar 10 12:00:42 host systemd[1]: docker.service: restarting

$ timeout 60 ssh host uptime      # rewritten to: timeout 60 rtk ssh host uptime

Testing

  • cargo test --all — 2453 passed, 0 failed
  • cargo clippy --all-targets — clean
  • Built-in filter count assertions updated (63 → 64).
  • 9 new tests for the timeout parser (plain duration, suffix durations, -k/-s with args, scp inner, unknown inner → passthrough, composition with env prefixes).
  • Verified end-to-end against real hosts through the hook path.

Notes / open questions

  • Registering ssh/scp changes default behavior for all users. The filters are conservative — banners and blank lines only, plus dedup — so a successful command's real stdout is preserved. Happy to gate behind config if you'd prefer opt-in.
  • dedup_repeats is generic and could be reused by other log-like filters (journalctl, docker logs) in follow-ups.

Adds a new `dedup_repeats` filter action that collapses consecutive
identical lines into 'line [xN]', and wires up ssh/scp so the Claude
Code / hook layer rewrites them to `rtk ssh` / `rtk scp`.

Motivation: ssh is one of the highest-volume commands in agent
sessions (remote diagnostics: journalctl, docker logs, dmesg), but it
was never registered as a rewritable command, so its output bypassed
RTK entirely. Log-like remote output is also highly repetitive, which
the existing pipeline had no way to compress.

Changes:
- core/toml_filter.rs: new `dedup_repeats` bool action, applied as
  pipeline stage 4.5 (after strip/keep, before truncate). Collapses
  runs of identical lines (trailing whitespace ignored, blank lines
  never merged) into a ' [xN]' suffix. Non-lossy: the count preserves
  the information, so no tee fallback is triggered.
- discover/rules.rs: register ^ssh\b -> rtk ssh and ^scp\b -> rtk scp.
- filters/ssh.toml: enable dedup_repeats; strip additional connection
  noise (Last login, X11 forwarding request failed, shared connection
  closed). New inline test for the dedup path.
- filters/scp.toml: new filter — strips banners/progress, keeps errors.

All 2444 tests pass, clippy clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Jul 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

timeout-wrapped commands ('timeout <N> ssh ...') bypassed all filters
because the command starts with 'timeout', not the inner command. Since
timeout takes a mandatory DURATION arg plus optional flags, it can't use
the fixed-word BUILTIN_TRANSPARENT_PREFIXES path.

Adds strip_timeout_prefix(): consumes 'timeout', option flags (-s/-k with
their separate args, --preserve-status/--foreground/-v), and the DURATION
token, routes the inner command, and re-prepends the wrapper verbatim.
9 new tests. All 2453 tests pass, clippy clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@melchior123 melchior123 changed the title feat: dedup_repeats TOML action + register ssh/scp for hook rewrite feat: route ssh/scp (+ timeout wrapper) and add dedup_repeats TOML action Jul 11, 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.

3 participants