Add opt-in RTK output filtering for execute_command#488
Open
aj47 wants to merge 2 commits into
Open
Conversation
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
|
|
||
| export function getRtkBinary(): string { | ||
| const configured = process.env[RTK_BINARY_ENV] | ||
| return configured && configured.trim().length > 0 ? configured : "rtk" |
Contributor
There was a problem hiding this comment.
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}` |
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #475.
Summary
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.execute_commandruntime tool inapps/desktop/src/main/runtime-tools.tsjust beforeexecAsync. When wrapping is applied the result payload includes"rtkWrapped": true.docs/rtk-integration.md.Behaviour
Wrapping only happens when all of these hold:
DOTAGENTS_RTK=1(also acceptstrue/yes/on).rtkbinary (orDOTAGENTS_RTK_BINARY) resolves onPATH. Probe result is cached.|,&&,||,;, redirects, subshells, or leadingFOO=barenv assignments.rm,mv,sudo,docker,ssh,vim,cd, …) and is not alreadyrtk.git, the subcommand is notpush,reset, orclean.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_commandpath 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.DOTAGENTS_RTK=1in a dev session withrtkinstalled and confirmgit statusoutput appears summarised.https://claude.ai/code/session_01UEBJw7jDKFSWzAoXayXYcB
Generated by Claude Code