Skip to content

feat(harness): read built-in tool - #45

Merged
sanchitrk merged 7 commits into
canaryfrom
feature/read-tool
Oct 10, 2026
Merged

sanchitrk merged 7 commits into
canaryfrom
feature/read-tool

Conversation

@prem315

@prem315 prem315 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Rewrites the built-in read tool to match Pi's, and adds the contract pieces it needs.

read

  • Pi's parameters (path, offset, limit), description, prompt snippet/guideline and continuation notices, verbatim.
  • Text is read through scanLines: only the shown window leaves the sandbox. Output is capped at 2000 lines / 50KB, and the cap also holds after invalid UTF-8 is decoded.
  • Images (jpg, png, gif, webp, bmp) are detected by magic bytes, not by extension. Animated PNGs are excluded, and a text file starting with GIF stays text. BMP is converted to PNG, EXIF orientation is applied, and images are resized to fit within 2000×2000 and 4.5MB using Photon on a worker thread (falling back to the current thread if no worker can start).
  • A NUL byte in the first 8000 bytes means the file is binary: Unsupported read <path>: binary file.
  • macOS path spellings are resolved: narrow no-break space before AM/PM, NFD, curly apostrophe. Unicode spaces and a leading @ are normalised.
  • Filesystem errors (ENOENT, EACCES, EISDIR) reach the model as tool errors.

Contract changes

  • SandboxFileSystem.readBytes(path, offset, length): bounded byte reads. Remote backends use a base64 shell script. Implemented in the local VFS, Daytona, Vercel and the extras Vercel driver.
  • ToolDef.encodeDetails: optional; picks which details are stored, so an image carried in the content is not stored a second time.

Tests

  • tools.read.test.ts: E2E through the harness with one parallel tool turn covering 30 cases, snapshotted to __artifacts__/tools.read.json.
  • tools.read.differential.test.ts: ported from Pi. 400 random files × 4 offset/limit trials, compared against a whole-file reference read.
  • Conformance specs for readBytes, verified on real Daytona and Vercel sandboxes.

Arguments are sampled strictly (json_schema, prefer), as in Pi, now that aikit converts strict schemas (#61).

🤖 Generated with Claude Code

Base automatically changed from canary to dev October 8, 2026 05:59
Base automatically changed from dev to main October 8, 2026 06:00
@sanchitrk
sanchitrk changed the base branch from main to canary October 8, 2026 06:13
@sanchitrk sanchitrk changed the title Feature/read tool feat(harness): read built-in tool Oct 10, 2026
Rewrite `read` to match Pi's read tool: Pi's parameters, description,
prompt snippet and continuation notices; text read through `scanLines`
so only the shown window leaves the sandbox; images detected by magic
bytes (animated PNGs excluded), converted and resized with Photon on a
worker thread with EXIF orientation applied; binary files reported as
unsupported; macOS path spellings resolved.

Add `readBytes` to the sandbox filesystem contract, with a base64 shell
form for remote backends, and an optional `encodeDetails` on tool
definitions so a payload carried in content is not stored twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sanchitrk
sanchitrk merged commit 001b942 into canary Oct 10, 2026
@sanchitrk
sanchitrk deleted the feature/read-tool branch October 10, 2026 04:54
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