qwen-code/packages/core
jinye 637d00cebc
feat(core): render PDF pages to images when text extraction overflows or fails (#6585)
* feat(core): render PDF pages to images when text overflows or fails

Replace the PDF text-only 12000-token dead-end with a bounded page->image
fallback for vision-capable models, mirroring claude-code's approach.

- pdf.ts: add renderPDFPagesToImages / isPdftoppmAvailable (pdftoppm -jpeg
  -scale-to), with timeout, error mapping, and a total-bytes cap.
- fileUtils.ts: text-first, then four ordered fallbacks on overflow/failure:
  (1) render to the vision main model (explicit read, <=20 pages),
  (2) render <=4 pages to the vision bridge (text-only model, scanned @-PDF),
  (3) reference (no-pages @-attach), (4) text too-large guidance / error.
  Widen ProcessedFileReadResult.llmContent to PartListUnion.
- read-file.ts / readManyFiles.ts / pathReader.ts: handle the Part[] payload;
  pathReader now references large @-PDFs, aligning the two @ paths.

WIP: tests not yet migrated.

🤖 Generated with [Qwen Code](https://github.com/QwenLM/qwen-code)

* test(core): cover PDF page rendering and vision-bridge fallbacks

- pdf.test.ts: renderPDFPagesToImages (success/sort, page range, Infinity
  last page, unavailable, password, corrupt, empty output, byte-cap).
- fileUtils.test.ts: mock renderPDFPagesToImages and assert vision-model
  page/whole-doc/scanned rendering, >20-page guidance, truncation notes,
  renderer-unavailable fallback, and text-only bridge rendering (scanned @
  PDF -> <=4 pages, page-count note, text-first reference, no-flag error).

🤖 Generated with [Qwen Code](https://github.com/QwenLM/qwen-code)

* fix(core): never drop PDF pages silently when page count is unknown

Audit follow-up. Both image-render fallbacks could omit pages without a
note when pdfinfo is unavailable (page count null):

- vision no-pages render: when the size heuristic underestimates and the
  render fills the per-read page ceiling, add a note (previously only the
  byte-cap path was flagged).
- vision-bridge render: when the page count is unknown and the render hits
  the image cap, flag it (previously required a known count). Soften the
  note wording to not over-promise a later-range read on the @ path.

Adds regression tests for both unknown-page-count paths.

🤖 Generated with [Qwen Code](https://github.com/QwenLM/qwen-code)
2026-07-09 10:09:44 +00:00
..
scripts Fix: Improve ripgrep binary detection and cross-platform compatibility (#1060) 2025-11-18 19:38:30 +08:00
src feat(core): render PDF pages to images when text extraction overflows or fails (#6585) 2026-07-09 10:09:44 +00:00
vendor feat test tool permissions 2026-03-10 16:30:22 +08:00
index.ts fix: Remove remaining ClearcutLogger export from packages/core/index.ts 2026-02-01 14:52:14 +08:00
package.json chore(release): v0.19.8 (#6549) 2026-07-08 15:51:03 +00:00
test-setup.ts feat(memory): managed auto-memory and auto-dream system (#3087) 2026-04-16 20:05:45 +08:00
tsconfig.json fix: upgrade @lydell/node-pty to 1.2.0-beta.10 to fix PTY FD leak 2026-04-01 07:55:56 +08:00
vitest.config.ts