anomalyco / anomalyco/opencode

read: paginated binary detection misfires on single control-char-dense lines (ANSI logs)

Open
#45,913 1 comment 0 reactions 1 assignee View on GitHub

@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 same nonPrintable / bytes.length > 0.3 threshold.

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.