Skip to content

Add opt-in RTK output filtering for execute_command#488

Open
aj47 wants to merge 2 commits into
mainfrom
claude/great-franklin-OKnVP
Open

Add opt-in RTK output filtering for execute_command#488
aj47 wants to merge 2 commits into
mainfrom
claude/great-franklin-OKnVP

Conversation

@aj47

@aj47 aj47 commented May 25, 2026

Copy link
Copy Markdown
Owner

Closes #475.

Summary

  • Adds apps/desktop/src/main/rtk.ts, a small helper that decides whether to wrap a shell command with RTK (Rust Token Killer) so the agent sees a compact, token-light summary instead of raw stdout/stderr.
  • Wires the wrapper into the execute_command runtime tool in apps/desktop/src/main/runtime-tools.ts just before execAsync. When wrapping is applied the result payload includes "rtkWrapped": true.
  • Documents the integration and config in docs/rtk-integration.md.

Behaviour

Wrapping only happens when all of these hold:

  • DOTAGENTS_RTK=1 (also accepts true/yes/on).
  • The rtk binary (or DOTAGENTS_RTK_BINARY) resolves on PATH. Probe result is cached.
  • The command is a single invocation — no |, &&, ||, ;, redirects, subshells, or leading FOO=bar env assignments.
  • The first token is not destructive/interactive (rm, mv, sudo, docker, ssh, vim, cd, …) and is not already rtk.
  • For git, the subcommand is not push, reset, or clean.

If any condition fails, the original command runs unchanged. Default behaviour with no env var set is a no-op, so existing sessions are unaffected.

Issue acceptance criteria

The issue asked for a recommendation and, if positive, a concrete integration plan. This PR is the concrete plan made code: opt-in via env, single integration point in the runtime tool runner, no schema changes, easy to revert. Subagents using the same execute_command path inherit the behaviour automatically.

Test plan

  • pnpm exec vitest run src/main/rtk.test.ts — 6 new unit tests cover env parsing, the metacharacter/destructive-command blocklist, the binary-not-on-PATH path, and the success wrap.
  • pnpm exec vitest run src/main/runtime-tools.execute-command.test.ts — existing tests still pass.
  • pnpm --filter @dotagents/desktop typecheck:node — clean.
  • Manual smoke: set DOTAGENTS_RTK=1 in a dev session with rtk installed and confirm git status output appears summarised.

https://claude.ai/code/session_01UEBJw7jDKFSWzAoXayXYcB


Generated by Claude Code

RTK (https://www.rtk-ai.app) is a CLI proxy that filters noisy command
output before it reaches the LLM. When DOTAGENTS_RTK is set, safe shell
invocations issued via the execute_command runtime tool are transparently
rewritten as `rtk <command>`, cutting tokens for tools like git, pnpm,
cargo, and test runners. Wrapping is skipped silently when the rtk
binary is not on PATH, for destructive or interactive commands, and for
any command using shell metacharacters/pipelines.

https://claude.ai/code/session_01UEBJw7jDKFSWzAoXayXYcB

@augment-app-staging augment-app-staging Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread apps/desktop/src/main/rtk.ts Outdated

export function getRtkBinary(): string {
const configured = process.env[RTK_BINARY_ENV]
return configured && configured.trim().length > 0 ? configured : "rtk"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRtkBinary() returns the untrimmed DOTAGENTS_RTK_BINARY value, so a value with trailing whitespace can unexpectedly break the PATH probe or the wrapped command.

Severity: low

🤖 Was this useful? React with 👍 or 👎


function probeRtkBinary(binary: string): Promise<boolean> {
return new Promise((resolve) => {
const probe = process.platform === "win32" ? `where ${binary}` : `command -v ${binary}`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probeRtkBinary() interpolates binary directly into a shell command string; if DOTAGENTS_RTK_BINARY contains spaces or shell metacharacters it can cause false negatives or execute unintended shell fragments during probing.

Severity: medium

🤖 Was this useful? React with 👍 or 👎

Build rtk from source in the predev/build-rs hooks via
`cargo install --git https://github.com/rtk-ai/rtk`, stage it in
resources/bin/, and ship it through the same electron-builder
extraResources + mac.binaries channels as dotagents-rs. Resolve the
bundled path at runtime so users get RTK filtering without installing
anything, and flip the wrap default to on (opt out with DOTAGENTS_RTK=0).
The build step degrades gracefully when cargo is unavailable so dev
iteration is unaffected.

https://claude.ai/code/session_01UEBJw7jDKFSWzAoXayXYcB
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.

Investigate integrating RTK for command output token reduction

2 participants