Skip to content

feat: add rtk cdk diff/synth/deploy filters#402

Open
ThomasHoussin wants to merge 2 commits intortk-ai:developfrom
ThomasHoussin:feat/cdk-cmd
Open

feat: add rtk cdk diff/synth/deploy filters#402
ThomasHoussin wants to merge 2 commits intortk-ai:developfrom
ThomasHoussin:feat/cdk-cmd

Conversation

@ThomasHoussin
Copy link

Context

AWS CDK is an Infrastructure-as-Code framework. Its CLI commands (cdk diff, cdk synth, cdk deploy) produce extremely verbose output: asset bundling logs (esbuild, Docker, pip), CloudFormation progress lines, NOTICES sections, and full YAML templates. A typical cdk diff on a project with 13 lambdas generates ~870 tokens of which only ~240 are meaningful.

What this PR does

Adds rtk cdk with 3 specialized filters:

  • rtk cdk diff — Keeps only stack headers, resource diff markers ([+]/[-]/[~]), IAM change tables, and a summary count. Strips all bundling noise, build logs, and NOTICES.
  • rtk cdk synth — Two modes: when no stack is specified, shows the synthesized path + stack list. When a full YAML template is output, extracts a resource type summary (e.g. "Lambda::Function x7, IAM::Role x10").
  • rtk cdk deploy — Strips per-resource CloudFormation progress lines, keeps success/failure status, outputs section, and timing. Handles both standard and stack-prefixed progress formats.

Design: whitelist approach — only keep lines matching known meaningful patterns. Everything else is dropped. This is future-proof: any new bundler or tool CDK adds will be automatically filtered without code changes.

Handles Windows/PowerShell mojibake (box-drawing characters rendered as Ôö£ÔöÇ instead of ├──).

Token savings

Fixture Raw Filtered Savings
cdk diff (5 stacks, esbuild bundling) 870 tok 240 tok 72.4%
cdk diff (Docker pull + pip install) 1049 tok 133 tok 87.3%
cdk synth (no-template, stack list) 483 tok 10 tok 97.9%
cdk synth (full 62KB YAML template) 2446 tok 23 tok 99.1%
cdk deploy (stack-prefixed progress) 396 tok 13 tok 96.7%

Depends on

Based on #398 (fix/windows-cmd-compat) — cdk_cmd.rs uses script_cmd() required for Windows where cdk is a .ps1 wrapper. Will rebase onto master once #398 is merged.

Test plan

  • 32 unit tests including 6 insta snapshot tests
  • 6 real-world anonymized fixtures (2 projects x 3 commands)
  • Token savings verified >= 60% on all fixtures
  • cargo fmt && cargo clippy --all-targets && cargo test --all — 745 tests pass

🤖 Generated with Claude Code

ThomasHoussin added a commit to ThomasHoussin/rtk that referenced this pull request Mar 7, 2026
Merge fork/feat/yarn-cmd-v2 (PR rtk-ai#317) into local branch based on
feat/cdk-cmd (PR rtk-ai#402). Resolved 3 conflicts:
- registry.rs: kept both gh and yarn rewrite tests, added CDK rewrite tests
- tsc_cmd.rs: kept has_program() from windows-compat branch
- utils.rs: kept has_program() + script_cmd with concise doc

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ThomasHoussin and others added 2 commits March 7, 2026 19:18
Add `script_cmd()` and `has_program()` helpers to utils.rs, then
migrate all bare `Command::new` calls for Node.js CLI tools to use
`.cmd` wrappers on Windows, and replace all `Command::new("which")`
probes with a cross-platform `where.exe`/`which` helper.

- Add `script_cmd(program)`: appends `.cmd` on Windows (compile-time cfg)
- Add `has_program(program)`: uses `where.exe` on Windows, `which` on Unix
- Fix `package_manager_exec()` to use both helpers
- Migrate 8 Node.js modules: npm, pnpm, tsc, next, prisma, playwright,
  ccusage, main.rs prisma passthrough
- Remove 3 duplicate local `which_command()` fns from pip, mypy, pytest
- Fix `tree.rs` inline `which` probe
- Add platform-specific tests for both helpers

13 files changed, 167 insertions(+), 108 deletions(-)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implement rtk cdk command with 3 specialized filters:
- diff: whitelist keeps only stack headers, diff markers, IAM tables
- synth: dual-path (no-template: stack list, template: resource types)
- deploy: progress counting, success/error detection, outputs

Whitelist approach auto-filters any new bundler noise (Docker, pip,
esbuild, NOTICES) without enumeration. Handles both proper Unicode
and Windows/PowerShell mojibake box-drawing characters.

32 tests, 6 snapshot tests, token savings 72-99% on real fixtures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ThomasHoussin ThomasHoussin changed the base branch from master to develop March 7, 2026 18:20
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.

1 participant