Skip to content

Comments

feat: add AWS CLI and psql modules#216

Open
itai-sagi wants to merge 3 commits intortk-ai:masterfrom
itai-sagi:feat/aws-psql-support
Open

feat: add AWS CLI and psql modules#216
itai-sagi wants to merge 3 commits intortk-ai:masterfrom
itai-sagi:feat/aws-psql-support

Conversation

@itai-sagi
Copy link

Summary

  • rtk aws: Specialized filters for 8 high-frequency AWS CLI commands (STS identity, S3 ls, EC2 describe-instances, ECS list/describe-services, RDS describe-db-instances, CloudFormation list/describe-stacks). Generic fallback forces --output json and compresses via json_cmd::filter_json_string() at depth 4. Achieves 60%+ token savings on verbose AWS table/text output.
  • rtk psql: Detects psql table format (strips ----+---- borders, (N rows) footer, column padding → tab-separated) and expanded format (-[ RECORD N ]- blocks → [N] key=val one-liners). Passthrough for COPY/SET/notices. Overflow limits: 30 table rows, 20 expanded records.
  • Hook rewrite patterns added for both aws and psql in distributable and dev hooks.

Test plan

  • 32 new inline tests (16 aws_cmd + 16 psql_cmd) all passing
  • Full test suite: 428 tests pass, 0 failures
  • cargo fmt --all clean
  • cargo clippy --all-targets — no new warnings
  • Manual test with real AWS CLI (if configured): rtk aws sts get-caller-identity
  • Manual test with real psql (if available): rtk psql -c "SELECT 1" mydb

🤖 Generated with Claude Code

@pszymkowiak
Copy link
Collaborator

Thanks for adding AWS CLI and psql support — great additions to RTK's ecosystem! Tests pass (428/428), build is clean, and existing commands are unaffected. Here are some items to address
before merge:

Critical

  1. Revert commit polluting the PR: There's a revert commit that adds noise to the diff. Please clean up the git history (interactive rebase) so only AWS/psql changes are included.
  2. run_generic --output injection: The --output json flag is injected into all AWS commands via run_generic, but not all AWS subcommands support --output. This could break commands like
    aws s3 cp or aws s3 sync. Consider only injecting --output json for commands that support structured output (describe, list, get, etc.), or catch the error and fallback to raw execution.
  3. psql tracking on failed commands: Token savings are recorded even when the psql command fails (non-zero exit code). Tracking should only happen on successful executions to avoid
    skewing metrics.

Improvements

  1. Duplicate lazy_static! blocks: Several identical regex patterns are defined in multiple lazy_static! blocks across both modules. Factor them into shared constants or a single block.
  2. Test fixtures should use real command output: Per project guidelines (see CLAUDE.md > Testing Strategy), tests should use include_str!("../tests/fixtures/...") with real command
    output, not synthetic/hardcoded strings. This ensures filters work against actual CLI output formats.
  3. Token savings threshold too low: Tests assert ≥30% savings, but RTK's project standard is ≥60%. Please raise the threshold or justify why these specific filters have lower savings
    expectations.

Minor

  • Consider adding snapshot tests (assert_snapshot!) for output format validation
  • AWS module is +845 lines — could some shared patterns (JSON flattening, table formatting) be extracted to utils.rs?

Overall solid work, looking forward to the next iteration! 🔧

Add two new command modules that compress verbose AWS CLI and PostgreSQL
client output for significant token savings when used with LLMs.

## aws_cmd (AWS CLI)
- Specialized filters for 8 high-frequency commands:
  - `sts get-caller-identity` → single-line `AWS: <account> <arn>`
  - `s3 ls` → compact listing, 30-item overflow counter
  - `ec2 describe-instances` → one line per instance with name tag
  - `ecs list-services` → short names extracted from ARNs
  - `ecs describe-services` → `name status running/desired (launch)`
  - `rds describe-db-instances` → `name engine version class status`
  - `cloudformation list-stacks` → `name STATUS date`
  - `cloudformation describe-stacks` → same + outputs section
- Generic fallback: compress JSON at depth 4 via json_cmd schema
  - Only injects `--output json` for structured ops (describe-/list-/get-),
    not for mutating/transfer ops (s3 cp, s3 sync, cloudformation deploy…)
- All filters use serde_json::Value for resilience (no typed structs)
- Max 20 items shown per command, overflow counter for rest

## psql_cmd (PostgreSQL)
- Detects table format (`----+----` separators) and expanded format
  (`-[ RECORD N ]-` markers); passthrough for COPY, notices, etc.
- Table filter: strips borders, `(N rows)` footer, converts to tab-separated
  (30-row limit with overflow counter)
- Expanded filter: converts verbose field-per-line format to compact
  `[N] key=val key=val` one-liners (20-record limit)
- Tracking recorded only on success (exit code 0)
- Module-level lazy_static! regex patterns (compile once, reuse)

## Hook integration
- Both hook files updated to rewrite `aws ...` → `rtk aws ...`
  and `psql ...` → `rtk psql ...`

## Tests
- 17 unit tests for aws_cmd, 17 for psql_cmd (429 total, all passing)
- Token savings tests use include_str! with real-format fixtures:
  tests/fixtures/aws_ec2_describe.json  — 2-instance multi-field response
  tests/fixtures/aws_sts_identity.json  — STS response
  tests/fixtures/psql_table.txt         — 20-row 7-column padded table
  tests/fixtures/psql_expanded.txt      — 5-record expanded display
- EC2 and STS filters verified ≥60% savings; expanded psql ≥60%;
  table psql ~40% (mathematical limit of tab-conversion: |→tab saves
  at most ~47% regardless of column count, documented in test)
@itai-sagi itai-sagi force-pushed the feat/aws-psql-support branch from 940d2df to e50ef8b Compare February 21, 2026 20:07
itai-sagi and others added 2 commits February 22, 2026 09:24
- Extract join_with_overflow() to utils.rs (replaces 5 repeated overflow
  patterns in aws_cmd)
- Extract truncate_iso_date() to utils.rs (replaces 2 repeated date-
  truncation patterns in aws_cmd)
- Add output format tests to aws_cmd and psql_cmd using real fixture files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@itai-sagi itai-sagi force-pushed the feat/aws-psql-support branch from 1071ae8 to 9ec3583 Compare February 22, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants