Skip to content

PDF attachments reach every provider: extracted text for models that cannot read PDFs (#466) - #1679

Merged
currentbits merged 5 commits into
mainfrom
coder/pdf-and-document-attachments-not-just-im-9c6a24
Oct 19, 2026
Merged

currentbits merged 5 commits into
mainfrom
coder/pdf-and-document-attachments-not-just-im-9c6a24

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #466.

Attaching a spec PDF now works with every provider. Claude (its Read tool renders PDFs) and OpenCode (run -f) still get the path. Codex, Kimi, Grok, Cursor and Muse used to get a path to a file they could not read; now Solenta extracts the text locally and points the agent at a .txt copy.

How it works

  • electron/pdf-text.js runs pdfjs in a child process (ELECTRON_RUN_AS_NODE), so parsing never blocks the main process. A 30 s timeout kills it.
  • Caps: 100 pages and 100 MB input. Text lands in userData/attachments/<threadId>/, which the existing image-store pruning already covers.
  • Extraction runs inside the run's busy window, after the thread is marked active, so a slow PDF cannot let a second send start a parallel run. Steering a live turn with a PDF goes through the same path.
  • The prompt gets a short section: PDF -> extracted .txt, a "first 100 pages only" note when capped, or "no text could be extracted" for scanned/protected files.

UI

  • PDF chips in the composer and the queued strip say text only when the selected provider cannot read PDFs.
  • The sent message keeps a pdfText flag, so the transcript chip shows the note only when extraction actually happened, even after a provider switch.

Packaging

  • New dependency pdfjs-dist 6.4.299 (exact pin). package-app.sh and package-cross.sh ship only pdf.min.mjs and pdf.worker.min.mjs (1.8 MB of 35 MB). The optional @napi-rs/canvas is not shipped; text extraction does not need it.
  • verify-package.sh checks both files, because its require() scan cannot see import(). package-deps.test.js now also scans require.resolve(), so dropping pdfjs-dist from either list fails CI.

Testing

  • Full test:electron in a CI-like environment (stripped PATH, no inherited CODER_*) after merging main: 4894 pass, 0 fail.
  • Renderer composer/threadView/queued tests: 308 pass. typecheck and vite build are clean.
  • New tests:
    • extraction with a fake extractor (native skip, page cap, scanned file, non-PDFs untouched, thread-id escape)
    • a real pdfjs child run on a hand-built PDF
    • a runner test that the note and the pdfText flag land on a generic-provider run
    • composer and transcript chip tests
  • The trimmed bundle tree was run under the real Electron binary. package-cross.sh was not run end to end.

Out of scope, per the issue: office documents (.docx etc.).

🤖 Generated with Claude Code

Solenta and others added 3 commits October 18, 2026 21:44
Solenta-Message-Id: 49b07a62-7eba-4e78-af35-6933cd700199
Solenta-Message-Id: 021d9716-d51c-483f-86bb-4f6344245277
…t-attachments-not-just-im-9c6a24

# Conflicts:
#	scripts/package-app.sh
#	scripts/package-cross.sh
#	src/components/Composer.tsx
#	src/components/composer/AttachmentChip.tsx
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T21:31:39.494289Z b43da3b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b43da3bf21

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread electron/pdf-text.js
pdfjs.GlobalWorkerOptions.workerSrc = pathToFileURL(
require.resolve("pdfjs-dist/legacy/build/pdf.worker.min.mjs"),
).href;
const task = pdfjs.getDocument({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ship and configure PDF.js character maps

For PDFs that reference a predefined, non-embedded CMap—common in CJK documents—PDF.js needs cMapUrl/cMapPacked to decode the font character codes. This call supplies neither, while both packaging scripts delete the bundled pdfjs-dist/cmaps directory, so affected packaged-app extractions produce missing text or fail and are silently reported as unextractable. Retain the CMap assets and point getDocument at them.

Useful? React with 👍 / 👎.

Willem and others added 2 commits October 18, 2026 23:47
# Conflicts:
#	src/components/Composer.module.css
#	src/components/composer/AttachmentChip.tsx
@currentbits
currentbits merged commit 5f7ba30 into main Oct 19, 2026
6 checks 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.

PDF and document attachments, not just images

1 participant