Skip to content

fix: skip reading binary files during scans - #6

Merged
royalpinto007 merged 1 commit into
AgentPostmortem:mainfrom
alloutflo:codex/issue-4-skip-binary-read
Aug 11, 2026
Merged

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

Conversation

@alloutflo

Copy link
Copy Markdown
Contributor

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
@alloutflo

Copy link
Copy Markdown
Contributor Author

@royalpinto007 Maintainer handoff: this PR is ready for review, mergeable, up to date with main, and has no review comments or open threads. Upstream CI is green. The regression proves both small and larger-than-MAX_READ binary files bypass all read paths while generated and large structured text files still receive content-based classification; Node 18 and 20 runs also pass. Could you review the Issue #4 fast path when convenient?

@royalpinto007
royalpinto007 merged commit 87c6877 into AgentPostmortem:main Aug 11, 2026
1 check 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.

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

2 participants