anomalyco / anomalyco/opencode
read: paginated binary detection misfires on single control-char-dense lines (ANSI logs)
Open
@neriousy is already working on this.
Since Aug 28, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- Avg merge
- 7h 2m
- Merged PRs (30d)
- 384
Description
Describe the bug
packages/core/src/tool/read-filesystem.ts detects binary files differently depending on the read path:
- Whole-file read checks the first 64 KB as one buffer (
binary(resource, first)). - Paginated read (offset/limit, or large files) calls
binary(resource, segment)per line, with the samenonPrintable / bytes.length > 0.3threshold.
A single line dense in control characters (ANSI escape sequences in colored logs, backspace progress bars) can exceed 30% on that one line and fail the entire read with BinaryFileError — while reading the same file without offset succeeds. So page 2 of a log can suddenly report "binary".
Suggested fix
Apply the non-printable heuristic over a larger window in the paginated path too, rather than per single line.
Environment
- opencode version: latest dev
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.