Skip to content

feat(ssh): add ssh command with output truncation#1043

Open
lgbarn wants to merge 2 commits intortk-ai:developfrom
lgbarn:feat/ssh-command
Open

feat(ssh): add ssh command with output truncation#1043
lgbarn wants to merge 2 commits intortk-ai:developfrom
lgbarn:feat/ssh-command

Conversation

@lgbarn
Copy link
Copy Markdown

@lgbarn lgbarn commented Apr 5, 2026

Summary

  • Add rtk ssh command that passes through to ssh and compacts output
  • Strips blank lines and caps stdout at 80 lines, stderr at 5 lines
  • Add rewrite rule so ssh host cmdrtk ssh host cmd via hook

Closes #783
Closes #333

Motivation

rtk discover showed 326 unhandled ssh commands over 30 days. SSH remote commands frequently produce verbose output (docker logs, journal dumps, systemctl status) that wastes tokens when piped back to an LLM.

Changes

File Change
src/cmds/cloud/ssh_cmd.rs New: passthrough handler with blank-line stripping and 80-line cap
src/discover/rules.rs Add ssh rule (pattern ^ssh\s+\S+, category Infra, 50% est. savings)
src/main.rs Add Ssh command variant, dispatch, and hook registration

Design decisions

  • Passthrough with truncation rather than parsing: SSH output is unpredictable (could be JSON, logs, status tables) so we just cap lines rather than trying to parse structure
  • 80-line stdout cap: matches the typical useful output length for LLM context; anything beyond is noise
  • 5-line stderr cap: connection warnings and auth messages are useful; full error dumps are not

Test plan

  • cargo test ssh — 4 new tests pass (truncation, short output, blank lines, empty)
  • cargo test — 1257 passed, 3 ignored, 0 failed
  • rtk rewrite "ssh pi@rpi docker ps"rtk ssh pi@rpi docker ps

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 5, 2026

CLA assistant check
All committers have signed the CLA.

lgbarn added 2 commits April 15, 2026 21:43
Add first-class `rtk ssh` command that passes through to ssh but
compacts the output: blank lines are stripped and results are capped
at 80 lines. Stderr (connection warnings, errors) is capped at 5
lines.

SSH remote commands frequently produce verbose output (docker logs,
journal dumps, systemctl status) that wastes tokens. `rtk discover`
showed 326 unhandled ssh commands over 30 days.

Closes rtk-ai#783
Closes rtk-ai#333
Add missing tests per project testing rules:
- Token savings verification (≥50% on verbose output)
- Truncated output format validation (line boundaries)
- Stderr isolation (not leaked into filtered output)
@lgbarn lgbarn force-pushed the feat/ssh-command branch from 3ed0bfa to 1bbc86c Compare April 16, 2026 01:45
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.

Feature request: ssh command support Feature Request rtk ssh subcommand — remote command output filtering

2 participants