Skip to content

feat(az): add Azure CLI filter support (pipelines, devops, account)#1209

Open
lucachitayat wants to merge 2 commits intortk-ai:developfrom
lucachitayat:feat/az-cli-support
Open

feat(az): add Azure CLI filter support (pipelines, devops, account)#1209
lucachitayat wants to merge 2 commits intortk-ai:developfrom
lucachitayat:feat/az-cli-support

Conversation

@lucachitayat
Copy link
Copy Markdown

@lucachitayat lucachitayat commented Apr 11, 2026

Scope

Add token-optimized output filters for Azure CLI (az) commands. RTK supports aws but had no Azure equivalent — this adds the same pattern for az.

Closes #1208

Implementation

Follows the exact architecture of aws_cmd.rs: CLI enum registration, rewrite rule in rules.rs, and a new az_cmd.rs handler in src/cmds/cloud/.

Specialized filters (5 handlers):

  • az pipelines build list — compact one-liner per build with id, buildNumber, pipeline, result, branch, reason, date
  • az pipelines build show — multi-line build card with branch, commit SHA, reason, requester, chrono-computed duration
  • az devops invoke --resource timeline — all tasks with durations; failed tasks show errorCount, warningCount, and first issue message
  • az devops invoke --resource logs — strips timestamps, tails last 50 lines
  • az account get-access-tokenmasks JWT (10-char prefix only), shows subscription/tenant/expiry metadata

Generic fallback — forces --output json and applies json_cmd::filter_json_string() for any unhandled az subcommand.

Hardening Pass (post-review)

5 bugs fixed, 1 security issue resolved, 3 filters enriched, 14 tests added:

Fix What
--output= detection Equals syntax (--output=table) was not detected, causing duplicate flag injection
Double stderr run_az_json and callers both printed stderr on error — now prints once
Exit code propagation Success path always returned 0 — now propagates real exit code
JWT masking Full access token was sent to LLM context — now shows Bearer [eyJ0eXAiOi...] prefix only
Text runner tee run_az_text_filtered wasn't combining stdout+stderr for tee recovery
lazy_static placement TIMESTAMP_RE moved from function body to module level per convention

Real-world test results (production Azure DevOps)

Command Raw Filtered Savings
az pipelines build list --top 5 35,394 chars 554 chars 98.5%
az pipelines build show --id 295493 6,741 chars 194 chars 97.2%
az devops invoke --resource timeline (57 tasks) 81,861 chars 2,449 chars 97.1%
az account get-access-token 2,534 chars 133 chars 94.8%

Example filtered output — build show:

FAIL build 295493 | myapp-yaml #2026.0410.23-pr-1509-5-4-mini
  branch: 8347/merge | commit: 1efef02
  reason: pullRequest | by: GitHub
  started: 2026-04-11 | finished: 2026-04-11 (18m)

Example filtered output — timeline (truncated):

FAIL timeline: 5 failed of 57 tasks
  ok Build Tools (Stage) 3m42s
  FAIL Run Integration Tests (Task) logId:107 2err 1warn 2m13s
    > Free disk space on / is lower than 5%; Currently used: 98.01%
  FAIL Build (Linux) (Job) logId:117 16m40s

Notable Changes

  • src/cmds/cloud/az_cmd.rs — 1,501 lines. Core filter logic + 25 unit tests (5 token savings, 9 edge cases, 11 functional).
  • src/main.rsAz variant added to Commands enum + dispatch.
  • src/discover/rules.rs — Rewrite rule for ^az\s+ with per-subcommand savings estimates.

Add token-optimized output for Azure CLI commands:
- az pipelines build list/show — compact build summary table
- az devops invoke --resource timeline — failed tasks only with logIds
- az devops invoke --resource logs — timestamp stripping, tail last N
- az account get-access-token — token value extraction
- Generic JSON compression fallback for all other az subcommands

Measured savings in a .NET monorepo:
- az pipelines build list: 99.1% reduction (7KB → 70B per build)
- az devops invoke timeline: 99.7% reduction (81KB → 250B)
- az account get-access-token: ~90% reduction

Includes rewrite rule, 11 unit tests, and CLI enum registration.

Closes rtk-ai#1208
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 11, 2026

CLA assistant check
All committers have signed the CLA.

… tests

- Fix --output= equals syntax detection (was injecting duplicate flags)
- Remove double stderr on error (run_az_json + caller both printed)
- Propagate exit codes on success path (was always returning 0)
- Mask JWT in filter_access_token (credential leak to LLM context)
- Enrich filter_build_show with branch, commit, reason, requester, duration
- Enrich filter_build_list with buildNumber and reason per line
- Enrich filter_timeline with all tasks, error counts, issue messages, durations
- Move TIMESTAMP_RE to module-level lazy_static
- Combine stdout+stderr in run_az_text_filtered tee path
- Add 14 new tests: token savings assertions + edge cases (25 total)
@lucachitayat
Copy link
Copy Markdown
Author

Hey @aeppling — the CI workflow is stuck at action_required (awaiting first-run approval from a maintainer before any jobs execute). Could you approve the CI run when you get a chance?

👉 https://github.com/rtk-ai/rtk/actions/runs/24272093000

Thanks!

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.

2 participants