Skip to content

feat(core): cap read_file at 20,000 chars with offset/limit continuation (#211 part 3) - #357

Merged
ajianaz merged 1 commit into
developfrom
feat/read-file-head-cap
Oct 9, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/read-file-head-cap

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What

read_file now returns at most 20,000 characters per call and accepts optional offset / limit (characters, UTF-8 boundary-safe). The result adds truncated, total_chars and next_offset (only when truncated) so the model can continue reading.

Why

read_file was the largest single history body (whole file up to 1 MiB), re-sent on every later step. git/web are already capped at 20,000 chars. Decision 7 of #211. Part of #211 (follow-ups remain open).

Changes

  • crates/tole-core/src/read_file.rs: head cap (pub(crate) MAX_READ_CHARS), offset/limit parsing (non-negative integers, limit >= 1, larger limit silently clamped to 20,000), slicing via char_indices; offset >= total_chars returns empty content, truncated:false and a note (not an error). Result before: {path, content, bytes, hash}; after: same plus truncated, total_chars, next_offset?. bytes and hash still describe the WHOLE file, so edit_file.old_hash anchors are unaffected.
  • Spec/summary(): +109 chars in the summary, +165 chars of schema (offset, limit) = 274 added spec characters.
  • Jail, symlink, directory/FIFO, binary (lossy UTF-8) handling and all existing error strings are untouched. Files over the 1 MiB read bound keep the existing "is N bytes (max M)" error unchanged: they remain unreadable (chunked reading would need a redesign of that bound, out of scope here), so the message does not mention offset/limit.
  • Tests: unit tests in read_file.rs and crates/tole-cli/tests/read_file_chunks_e2e.rs. No existing test needed adapting.
  • Docs: README tool row, threat-model size-cap line, CHANGELOG ### Changed.

Testing

  • Unit: small file, exactly 20,000 chars (not truncated), 20,001 (next_offset == 20000), multibyte (é, 日本語, emoji) reassembly for limits 1/2/3/7/13/1000, offset in chars, offset beyond end, limit clamp, negative/float/string/bool/array offset|limit rejected, CRLF, empty file.
  • E2E (real binary + scripted mock provider, no network): a 50,000-char file is read in 3 chunks (offsets 0, 20000, 40000, taken from next_offset) and the mission concludes.
  • Proven failing without the source change: 8 of the 11 new unit tests plus the e2e test fail when only the execute slicing is reverted.
  • fmt, clippy -D warnings, workspace tests, no-default-features and shell-tools profiles, evals_tier1 (unmodified), cora review --staged: clean.

🤖 Generated with Claude Code

…ion (#211 part 3)

read_file previously returned the whole file (up to 1 MiB), the largest
single history body re-sent on every step. It now returns at most 20,000
characters per call and accepts optional offset/limit (characters,
UTF-8 boundary-safe). The result keeps path/content/bytes/hash and adds
truncated, total_chars and next_offset (only when truncated).

Part of #211.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 3c40948 into develop Oct 9, 2026
17 checks passed
@ajianaz
ajianaz deleted the feat/read-file-head-cap branch October 9, 2026 07:51
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.

1 participant