t1430: Integrate rtk CLI proxy for token-optimized output#4095
t1430: Integrate rtk CLI proxy for token-optimized output#4095alex-solovyev merged 4 commits intomainfrom
Conversation
- Add rtk (rtk-ai/rtk) as optional token-saving layer in setup.sh - Add setup_rtk() function with brew/curl install, telemetry disabled by default - Add token-optimized CLI guidance to build.txt (prefer rtk prefix for git/gh/test) - Add rtk-ai/rtk to upstream-watch.json for release monitoring - Add research brief with full compatibility assessment and recommendation Recommendation: ADAPT — adopt as optional optimization, not mandatory dependency. rtk compresses bash command outputs (git 86%, gh 29-87%, tests 90%+) with <10ms overhead. Does NOT affect MCP tools, helper scripts, or file operations. Closes #4093
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughRegisters Changes
Sequence Diagram(s)sequenceDiagram
participant User as User
participant SetupScript as "setup.sh"
participant Installer as "setup-modules/tool-install.sh"
participant rtkBin as "rtk (binary)"
participant Agent as "Aidevops Agent"
participant LLM as "LLM"
User->>SetupScript: run interactive setup
SetupScript->>User: prompt "Setup rtk?"
User-->>SetupScript: confirm
SetupScript->>Installer: call setup_rtk()
Installer->>rtkBin: check version / install (brew/curl)
Installer->>rtkBin: write config (telemetry off, tee enabled)
rtkBin-->>Installer: installed/ready
Installer-->>SetupScript: return success
Note right of Agent: At runtime
Agent->>rtkBin: invoke CLI tools (git, test runners, etc.)
rtkBin->>Agent: filtered/compressed output
Agent->>LLM: send filtered output for context
LLM-->>Agent: responses
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Tue Mar 10 20:17:00 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
There was a problem hiding this comment.
Code Review
This pull request successfully integrates the rtk CLI proxy as an optional tool to optimize token usage for shell commands. The changes are well-structured, including the setup script, documentation updates in build.txt, and monitoring configuration. My review includes a high-severity comment regarding the security of the installation script and a couple of medium-severity comments about potential date typos in data and documentation files. Addressing the installation script issue is important for ensuring stability and security. Overall, this is a valuable addition for cost optimization.
Note: Security Review did not run due to the size of the PR.
setup-modules/tool-install.sh
Outdated
| if curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh; then | ||
| print_success "rtk installed to ~/.local/bin/rtk" | ||
| else | ||
| print_warning "rtk installation failed (non-critical, optional tool)" | ||
| fi | ||
| fi | ||
| else | ||
| # Linux or macOS without brew — use curl installer | ||
| if curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh; then | ||
| print_success "rtk installed to ~/.local/bin/rtk" | ||
| else | ||
| print_warning "rtk installation failed (non-critical, optional tool)" | ||
| echo " Manual install: https://github.com/rtk-ai/rtk#installation" | ||
| fi |
There was a problem hiding this comment.
The installation script is being piped directly from the master branch of the rtk-ai/rtk repository in two places. This is a security and stability risk, as the master branch is subject to change and could contain unstable or even malicious code. It is best practice to use a URL pointing to a specific, tagged release to ensure you are installing a stable and verified version of the tool.
For example, you could use a URL pointing to a specific tag:
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/v0.28.2/install.sh | shPlease update these URLs to point to a fixed, trusted version.
| "description": "CLI proxy that reduces LLM token consumption by 60-90% via smart output filtering", | ||
| "relevance": "Token cost optimization for agent bash operations (git, gh, test runners). Evaluated in t1430.", | ||
| "default_branch": "master", | ||
| "added_at": "2026-03-10" |
|
|
||
| ## Origin | ||
|
|
||
| - **Created:** 2026-03-10 |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
.agents/prompts/build.txt (1)
88-97: Add safeguards for commands requiring exact or structured output.The RTK research (t1430-brief.md) already assessed "compressed git output breaking agent decisions" as low risk because agents use MCP tools for critical operations. However, the current guidance doesn't explicitly carve out cases where exact output matters:
gh api --json,git status --porcelain, parser pipelines, and diffs where agents need verbatim content. RTK's "structure-only" filtering (keys + types without values) would compress these. Defensively exclude them or add a fallback instruction to rerun without RTK if output looks summarized.Suggested additions
- When `rtk` is installed (`command -v rtk`), prefer `rtk` prefix for token-heavy bash commands: - `rtk git status` instead of `git status` (76-80% reduction) - `rtk git log -n N` instead of `git log -n N` (86% reduction) - `rtk git diff` instead of `git diff` (75% reduction) - `rtk gh pr list` instead of `gh pr list` (29-80% reduction) - `rtk gh pr view N` instead of `gh pr view N` (87% reduction) - Do NOT use rtk for file reading (use MCP Read tool) or content search (use MCP Grep tool) +- Do NOT use rtk when exact or machine-readable output is required: `gh api`, `gh ... --json`, `gh ... --jq`, `git status --porcelain`, parser pipelines, or any diff/log output you need verbatim +- If a command run via rtk looks summarized or filtered, rerun without `rtk` before making decisions from it - Do NOT use rtk in helper scripts — scripts call tools directly, not through the agent - rtk is optional — if not installed, use commands normally. Never block on rtk absence. - Telemetry: disable in headless/worker mode (`RTK_TELEMETRY_DISABLED=1`)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.agents/prompts/build.txt around lines 88 - 97, The prompt needs explicit safeguards for commands that require exact or structured output: update the guidance for `rtk` to explicitly exclude/avoid using it for commands such as `gh api --json`, `git status --porcelain`, parser pipelines, and any verbatim diff/cat outputs (i.e., when using the MCP Read tool or MCP Grep tool is required), and add a fallback rule that if output appears summarized/structure-only (e.g., missing values, only keys/types) the agent must automatically re-run the command without `rtk` (or run the original command directly) and prefer direct tool calls in helper scripts; reference these symbols (`rtk`, `gh api --json`, `git status --porcelain`, MCP Read tool, MCP Grep tool) in the updated text so implementers can locate and apply the exclusion and fallback behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@setup-modules/tool-install.sh`:
- Around line 243-247: The early return in the rtk detection block prevents the
later RTK configuration (telemetry disable / tee setup) from running; remove the
"return 0" in the block that checks command -v rtk so the script continues to
the configuration section, or replace it by setting a flag (e.g.,
rtk_found=true) after printing via print_success and let the later config logic
inspect that flag and run the telemetry/tee setup; ensure you keep the
rtk_version capture and print_success call but do not exit early so the
subsequent RTK config steps execute.
- Around line 260-299: The script currently creates the RTK config regardless of
whether installation succeeded; update the logic so config creation runs only
after confirming the rtk binary is present. Concretely, after both Homebrew and
curl installer branches (where you call run_with_spinner brew install rtk or
curl ... | sh), verify installation with command -v rtk >/dev/null 2>&1 (or
check "$HOME/.local/bin/rtk") and only then create the directory and write
config to rtk_config_dir/config.toml; if the binary is absent, skip creating the
config and emit the existing warning/echo so the step correctly reflects
failure. Ensure the references to rtk_config_dir and the config TOML block
remain unchanged but are guarded by the post-install existence check.
- Around line 265-278: Replace the unsafe "curl ... | sh" usage in the rtk
install branches with the existing verified_install() helper: locate the two
occurrences that pipe curl to sh (the branches that currently print_success "rtk
installed..." and print_warning on failure) and call verified_install with the
installer URL instead, then keep the same success/failure handling
(print_success/print_warning and the manual install echo) based on
verified_install's exit status; ensure you reference verified_install() and
preserve the surrounding messages (print_success, print_warning, and the manual
install echo).
---
Nitpick comments:
In @.agents/prompts/build.txt:
- Around line 88-97: The prompt needs explicit safeguards for commands that
require exact or structured output: update the guidance for `rtk` to explicitly
exclude/avoid using it for commands such as `gh api --json`, `git status
--porcelain`, parser pipelines, and any verbatim diff/cat outputs (i.e., when
using the MCP Read tool or MCP Grep tool is required), and add a fallback rule
that if output appears summarized/structure-only (e.g., missing values, only
keys/types) the agent must automatically re-run the command without `rtk` (or
run the original command directly) and prefer direct tool calls in helper
scripts; reference these symbols (`rtk`, `gh api --json`, `git status
--porcelain`, MCP Read tool, MCP Grep tool) in the updated text so implementers
can locate and apply the exclusion and fallback behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: bbe8e774-a5a0-4fd5-b3be-b8a90b399de9
⛔ Files ignored due to path filters (1)
todo/tasks/t1430-brief.mdis excluded by!todo/tasks/*-brief.md
📒 Files selected for processing (4)
.agents/configs/upstream-watch.json.agents/prompts/build.txtsetup-modules/tool-install.shsetup.sh
…binary check (t1430) Address CodeRabbit CHANGES_REQUESTED on PR #4095: - Remove early return in rtk detection so existing installs get telemetry/tee config - Guard config writing behind command -v rtk check so config is only written when binary is available - Add rtk usage guidance: skip rtk for machine-readable output (gh api, --json, --porcelain)
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Tue Mar 10 23:40:44 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@setup-modules/tool-install.sh`:
- Around line 256-261: The code currently defaults install_rtk="y" causing RTK
to be installed in non-interactive runs; change the flow so RTK remains opt-in:
initialize install_rtk="n" (or empty) and only set it to "y" after an explicit
interactive confirmation (the read prompt) or by calling the existing
confirm_step() helper when INTERACTIVE_MODE is true; ensure no automatic "y"
assignment occurs when INTERACTIVE_MODE is false so headless setups do not
install RTK implicitly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a34b558a-9250-4f38-813b-bd0b205d72f7
📒 Files selected for processing (2)
.agents/prompts/build.txtsetup-modules/tool-install.sh
🚧 Files skipped from review as they are similar to previous changes (1)
- .agents/prompts/build.txt
…430) Address CodeRabbit CHANGES_REQUESTED on PR #4095: 1. tool-install.sh: change install_rtk default from 'y' to 'n' so non-interactive runs skip installation. Prompt hint updated to [y/N] and regex tightened to require explicit 'y'/'Y' (empty input = no). 2. build.txt: expand the 'do not use rtk' guidance with explicit categories — API/JSON, porcelain/parseable, test assertions, parser pipelines, and verbatim diffs — so agents have clear carve-outs for commands requiring exact output.
|
@coderabbitai review Addressed both CHANGES_REQUESTED items:
|
|
Triggering a review to verify the changes in full. 🧠 Learnings used✅ Actions performedReview triggered.
|
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Wed Mar 11 01:42:21 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
|
Dispatching worker to address CodeRabbit review feedback.
|
Address Gemini Code Assist review finding: replace master branch URL with tagged release URL for stability and auditability. The install script is still fetched via verified_install() (download-verify-execute), and the tag should be updated when upstream-watch detects a new release. Gemini date findings (2026-03-10 in upstream-watch.json and brief) are false positives — the dates are yesterday, not future dates.
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Wed Mar 11 01:47:20 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
|



Summary
setup_rtk()tosetup.shwith brew/curl install and telemetry-off default configrtkprefix guidance tobuild.txtfor git/gh/test commandsupstream-watch.jsonfor release monitoringResearch Findings
Recommendation: ADAPT — adopt as optional optimization, not mandatory dependency.
git statusgit log -5gh pr listKey insight: rtk only affects Bash tool calls. MCP tools (Read, Grep, Glob) and helper scripts are completely unaffected — no risk to existing workflows.
Estimated impact: 15-25% total session token reduction (because most file ops use MCP tools, not bash). Material at scale (100+ worker sessions/week).
Full analysis:
todo/tasks/t1430-brief.mdCloses #4093
Summary by CodeRabbit
New Features
Documentation