Skip to content

fix: skip reading binary files during scans - #6

Open
alloutflo wants to merge 1 commit into
AgentPostmortem:mainfrom
alloutflo:codex/issue-4-skip-binary-read
Open

fix: skip reading binary files during scans#6
alloutflo wants to merge 1 commit into
AgentPostmortem:mainfrom
alloutflo:codex/issue-4-skip-binary-read

Conversation

@alloutflo

Copy link
Copy Markdown

What does this PR do?

Avoid reading file contents when scanRepo already knows from the extension that a file is binary.

  • Extract path-only rules into classifyPath, keeping a single source for every existing category and reason.
  • Bypass fileInfo only for binary path classifications; other files still collect token and sample data.
  • Cover both binary read paths with a small .png and a larger-than-MAX_READ .pdf.
  • Verify that generated markers and larger-than-MAX_READ JSON files still read their contents and retain content-dependent classification.
  • Bump the package version to 0.1.2 and add the required changelog entry.

Binary results keep the existing contract: category: "binary", trim: true, binary: true, tokens: 0, and the exact reason binary asset (skipped by agents, excluded to be safe).

Fixes #4

Verification

The focused regression test fails against the original scan path because the .png reaches readFileSync; it passes with this fast path. The final checks are:

  • npm test — passed, 8/8
  • npx --yes node@18 --test test/ctxtrim.test.js — passed, 6/6
  • npx --yes node@20 --test test/ctxtrim.test.js — passed, 6/6
  • node bin/ctxtrim.js test/fixtures/sample-repo --format json — passed
  • node --check for every JavaScript file — passed
  • npm pack --dry-run --json — passed with the expected nine package files and no bundled dependencies
  • git diff --check — passed

Checklist

  • Tests pass (node --test)
  • Updated docs / README if behavior changed (changelog updated; CLI behavior is unchanged)
  • Added a CHANGELOG.md entry
  • Followed the existing code style

Notes

The regression explicitly observes readFileSync, openSync, and readSync. It also compares .png and .pdf result fields directly with classify, so the fast path cannot drift from the established category/reason contract.

@alloutflo
alloutflo marked this pull request as ready for review August 9, 2026 13:16
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.

Binary files are read from disk only to be classified as binary and given zero tokens

1 participant