Skip to content

Simplified rtk curl Filter - #1310

Merged
aeppling merged 4 commits into
rtk-ai:developfrom
JBF1991:feat/curl-cmd-no-filter
Apr 18, 2026
Merged

aeppling merged 4 commits into
rtk-ai:developfrom
JBF1991:feat/curl-cmd-no-filter

Conversation

@JBF1991

@JBF1991 JBF1991 commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refactored rtk curl to use a simple, predictable truncation strategy with tee hints instead of JSON schema conversion. This eliminates edge cases, reduces code complexity by ~36%, and delivers consistent 73-99% token savings across all response types greater than 500 bytes.

Test plan

I tested against various local and remote endpoints with responses >500 bytess, <500 bytes and both successful and error responses.

  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • Manual testing: rtk <command> output inspected

Savings

Response Type Original Size Savings Behavior
npm registry (express) 801 KB 99.9% 500B truncated + tee hint
GitHub API (releases) 36 KB 98.5% 500B truncated + tee hint
httpbin HTML 3.7 KB 86.0% 500B truncated + tee hint
nginx 404 HTML 2 KB 73.8% 500B truncated + tee hint
httpbin UUID 53 B 0% Below threshold, passed through
httpbin 404 (empty) 0 B 0% Empty body, no output, timer not called

Tiny JSON — passed through (< 500 bytes)

$ rtk curl -s https://httpbin.org/ip
{
  "origin": "75.143.98.179"
}

Large API response — truncated + tee hint

$ rtk curl -s "https://api.github.com/repos/rust-lang/rust/releases?per_page=5"
[
  {
    "url": "https://api.github.com/repos/rust-lang/rust/releases/301852655",
    "assets_url": "https://api.github.com/repos/rust-lang/rust/releases/301852655/assets",
    "upload_url": "https://uploads.github.com/repos/rust-lang/rust/releases/301852655/assets{?name,label}",
    ... (36049 bytes total)
[full output: ~/.local/share/rtk/tee/1776209074_curl.log]

Important: All PRs must target the develop branch (not master).
See CONTRIBUTING.md for details.

@JBF1991

JBF1991 commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

I am working on documentation for this. Apologies.

@aeppling

Copy link
Copy Markdown
Contributor

Hello @JBF1991

RTK rewrite commands transparently, it catch cmd by hooks and then rewrite with rtk. Some implementation use context because hook not available, but in reality, for RTK to be efficient, it should rewrite transparently.

For me this fix is not the correct approach since it require LLM to be aware of RTK and add flag.

You may want to check https://github.com/rtk-ai/rtk/blob/master/CONTRIBUTING.md#design-philosophy this part of contributing guide.

Thanks for the contribution ! If any questions or want to discuss i'm reachable here or on Discord

@aeppling aeppling self-assigned this Apr 14, 2026
@aeppling aeppling added filter-quality Filter produces incorrect/truncated signal invalid This doesn't seem right labels Apr 14, 2026
@JBF1991
JBF1991 force-pushed the feat/curl-cmd-no-filter branch from d73823b to c391f4a Compare April 14, 2026 23:55
@JBF1991 JBF1991 changed the title adding a --no-filter argument to curl_cmd.rs Simplified rtk curl Filter Apr 15, 2026
@aeppling aeppling removed the invalid This doesn't seem right label Apr 15, 2026
@JBF1991
JBF1991 force-pushed the feat/curl-cmd-no-filter branch from c391f4a to 71baf2b Compare April 15, 2026 19:26
@JBF1991

JBF1991 commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

I have updated to using the tee/hint form from other areas of the project as well as re-updated the docs.

@aeppling

aeppling commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor

Hey @JBF1991

Sorry for response time, lot of work beside, here is some issues found to be addressed before merging:

P0: Data loss when tee is unavailable

filter_curl_output truncates at 500 bytes unconditionally, but force_tee_hint can return None in at least 5 scenarios: RTK_TEE=0, tee.enabled = false, broken config TOML, directory creation failure, or disk full. When any of these hit, everything beyond byte 500 is permanently lost with no recovery path. The old code would have passed through the full response.

P1: Magic number 500 decoupled from MIN_TEE_SIZE

tee.rs defines MIN_TEE_SIZE = 500 privately. curl_cmd.rs hardcodes the same 500 separately.

Use already existing constant for consistence with codebase.

Coding practices

Hardcoded threshold: The 500 byte threshold appears inline. Coding practice requires named constants at the top of the file for fixed limits.

Missing edge case comment: The UTF-8 char boundary loop is a non-obvious edge case that needs a comment explaining why it's there.

Fallback pattern: If a filter fails, fall back to raw output. When tee is unavailable, truncation still destroys data with no fallback. Directly related to the P0.

Stale header comment: The file header still says //! Runs curl and auto-compresses JSON responses, JSON compression is removed and should reflect the new behavior.

@aeppling

Copy link
Copy Markdown
Contributor

Hello, rectifying review, for MIN_TEE_SIZE do not reuse from tee you can just define your constant locally it will be better for this purpose; thanks for pointing this out

@aeppling

Copy link
Copy Markdown
Contributor

#1152

@JBF1991

JBF1991 commented Apr 18, 2026

Copy link
Copy Markdown
Contributor Author

Added MAX_RESPONSE_SIZE comment.
Corrected doc comment.
Added comment for utf-8 boundary edge case.
If force_tee_hint returns none, default to trimmed raw.

@aeppling
aeppling merged commit 176ceb4 into rtk-ai:develop Apr 18, 2026
10 checks passed
@aeppling aeppling mentioned this pull request Apr 22, 2026
thehoff pushed a commit to thehoff/contextcrawler that referenced this pull request May 14, 2026
thehoff pushed a commit to thehoff/contextcrawler that referenced this pull request May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

filter-quality Filter produces incorrect/truncated signal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants