Skip to content

feat: per-op byte cap for around:/grep_around: (#241)#262

Merged
fdaviddpt merged 2 commits into
masterfrom
feat/around-byte-cap-241
May 29, 2026
Merged

feat: per-op byte cap for around:/grep_around: (#241)#262
fdaviddpt merged 2 commits into
masterfrom
feat/around-byte-cap-241

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #241.

Problem

around: / grep_around: with a large :N context on a file of long (e.g. minified) lines can over-fetch — a single op produced ~340KB, blowing the caller's context budget.

Fix

New _cap_context_window helper caps output at 16KB, truncating at a line boundary and appending a footer that points at the narrower tools:
… truncated (~N more bytes) — narrow context (:N) or use between: for the whole symbol

Applied at three render points: around: single-file, around: dir-aggregate, and the op_grep context branch (serves grep_around: and grep:-with-context).

Configurable: builtin-ops.around.max_bytes / builtin-ops.grep_around.max_bytes in .supertool.json (env: SUPERTOOL_AROUND_MAX_BYTES / SUPERTOOL_GREP_AROUND_MAX_BYTES), default 16000.

Tests

6 TDD tests (tests/test_around_byte_cap_241.py) — caps, line-boundary truncation, small-file pass-through, grep_around path, plain-grep untouched, env override. RED proven by neutralizing the cap. Full suite green.

Docs

docs/configuration.md (builtin-ops table), docs/operations/search.md (Output cap section), .supertool.json + .supertool.example.json (descriptions + max_bytes keys).

fdaviddpt added 2 commits May 29, 2026 16:00
A large :N context on a file of long (minified) lines could dump hundreds
of KB in one op, blowing the caller's context budget (~340KB observed).

Add _cap_context_window: cap output at 16KB (configurable via
builtin-ops.<op>.max_bytes / SUPERTOOL_<OP>_MAX_BYTES), truncate at a line
boundary, append a footer pointing at the narrower tools (smaller :N,
between:). Applied to around: (single-file + dir-aggregate) and the
op_grep context branch (grep_around: and grep:-with-context).

6 TDD tests (red proven by neutralizing the cap). Docs: configuration.md
table, operations/search.md cap section, .supertool[.example].json entries.

Co-Authored-By: Max <noreply>
…docs

- Remove the per-file cap from _around_one_file; cap only at op_around's
  single-file and dir-aggregate returns. Fixes double-capping (per-file +
  aggregate both 16KB) and interleaved truncation footers in dir fan-out.
- _cap_context_window: nl >= 0 (was > 0) so a newline at offset 0 still
  trims; consistent byte-accounting for the dropped count.
- Tests: +dir-aggregate cap (single footer), +single-giant-line no-newline.
- Docs: note grep:PATTERN:PATH:LIMIT:CONTEXT shares the grep_around cap;
  align .supertool.json descriptions.

Co-Authored-By: Max <noreply>
@fdaviddpt fdaviddpt force-pushed the feat/around-byte-cap-241 branch from 213f1d9 to 3faa3d2 Compare May 29, 2026 14:14
@fdaviddpt fdaviddpt merged commit dced977 into master May 29, 2026
12 checks passed
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.

around:/grep_around: large context can over-fetch — add per-op byte cap

1 participant