Skip to content

fix: curl JSON size guard (#297) + exclude_commands config (#243) - #342

Merged
pszymkowiak merged 3 commits into
masterfrom
fix/hook-rewrite-guard-and-exclude
Mar 5, 2026
Merged

pszymkowiak merged 3 commits into
masterfrom
fix/hook-rewrite-guard-and-exclude

Conversation

@FlorianBruniaux

Copy link
Copy Markdown
Contributor

Summary

Fixes two related issues with the auto-rewrite hook behavior.

Bug #297 — rtk curl inflates small JSON responses

Problem: rtk curl was replacing all JSON responses with a type schema, even when the schema was larger than the original payload:

# Original: {"r2Ready":true,"status":"ok"}
# RTK output (inflated):
{
  r2Ready: bool,
  status: string
}

Fix: Size guard in filter_curl_output() — schema is only returned when schema.len() <= original.len(). Small JSON payloads now pass through unchanged.

Inspired by PR #324 (@rursache).

Feature #243 — exclude_commands config

Problem: The auto-rewrite hook intercepted all supported commands unconditionally. No way to opt out of specific rewrites without manually editing the hook (which gets overwritten by rtk init -g).

Fix: New [hooks] section in config.toml:

[hooks]
exclude_commands = ["curl", "playwright"]

Excluded commands pass through the hook unchanged. Survives rtk init -g re-runs.

Changes

  • src/curl_cmd.rs — size guard + updated test fixture
  • src/config.rs — new HooksConfig struct with exclude_commands
  • src/rewrite_cmd.rs — load config, pass excludes to registry
  • src/discover/registry.rs — thread excluded through rewrite chain + new tests

Test plan

  • 617 unit tests pass (cargo test)
  • 89 smoke tests pass (bash scripts/test-all.sh)
  • Doc validation passes (bash scripts/validate-docs.sh)
  • Manual: small JSON {"status":"ok"} returns raw, not schema
  • Manual: exclude_commands = ["curl"] → rtk rewrite "curl ..." exits 1
  • Manual: excluded curl + non-excluded git in compound command rewrites only git

🤖 Generated with Claude Code

FlorianBruniaux and others added 3 commits March 5, 2026 20:28
**#297 — curl JSON inflation guard**
- `rtk curl` no longer replaces small JSON responses with a type schema
  that is larger than the original payload
- Size guard in `filter_curl_output()`: only return schema when
  `schema.len() <= original.len()`
- Inspired by PR #324 (@rursache)

**#243 — exclude_commands config**
- Add `[hooks] exclude_commands = ["curl"]` in config.toml to prevent
  the auto-rewrite hook from rewriting specific commands
- Survives `rtk init -g` re-runs (config.toml is user-owned)
- Implemented in `rewrite_cmd::run()` via `HooksConfig` struct
- Threaded through `rewrite_command()` → `rewrite_compound()` → `rewrite_segment()`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 5, 2026 19:38
@pszymkowiak
pszymkowiak merged commit a8d6106 into master Mar 5, 2026
3 checks passed
dragonGR pushed a commit to dragonGR/rtk that referenced this pull request Mar 5, 2026
…-ai#243) (rtk-ai#342)

* fix: curl size guard (rtk-ai#297) + exclude_commands config (rtk-ai#243)

**rtk-ai#297 — curl JSON inflation guard**
- `rtk curl` no longer replaces small JSON responses with a type schema
  that is larger than the original payload
- Size guard in `filter_curl_output()`: only return schema when
  `schema.len() <= original.len()`
- Inspired by PR rtk-ai#324 (@rursache)

**rtk-ai#243 — exclude_commands config**
- Add `[hooks] exclude_commands = ["curl"]` in config.toml to prevent
  the auto-rewrite hook from rewriting specific commands
- Survives `rtk init -g` re-runs (config.toml is user-owned)
- Implemented in `rewrite_cmd::run()` via `HooksConfig` struct
- Threaded through `rewrite_command()` → `rewrite_compound()` → `rewrite_segment()`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs: add rtk-ai#297 and rtk-ai#243 to CHANGELOG + exclude_commands in README

* docs: fix version references 0.24.0 → 0.25.0 across all docs

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@FlorianBruniaux
FlorianBruniaux removed the request for review from Copilot March 23, 2026 23:39
thehoff pushed a commit to thehoff/contextcrawler that referenced this pull request May 14, 2026
…-ai#243) (rtk-ai#342)

* fix: curl size guard (rtk-ai#297) + exclude_commands config (rtk-ai#243)

**rtk-ai#297 — curl JSON inflation guard**
- `rtk curl` no longer replaces small JSON responses with a type schema
  that is larger than the original payload
- Size guard in `filter_curl_output()`: only return schema when
  `schema.len() <= original.len()`
- Inspired by PR rtk-ai#324 (@rursache)

**rtk-ai#243 — exclude_commands config**
- Add `[hooks] exclude_commands = ["curl"]` in config.toml to prevent
  the auto-rewrite hook from rewriting specific commands
- Survives `rtk init -g` re-runs (config.toml is user-owned)
- Implemented in `rewrite_cmd::run()` via `HooksConfig` struct
- Threaded through `rewrite_command()` → `rewrite_compound()` → `rewrite_segment()`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs: add rtk-ai#297 and rtk-ai#243 to CHANGELOG + exclude_commands in README

* docs: fix version references 0.24.0 → 0.25.0 across all docs

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@aeppling
aeppling deleted the fix/hook-rewrite-guard-and-exclude branch June 30, 2026 20:09
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