Skip to content

Let Codex look at the typeset PDF - #10

Merged
cu1ch3n merged 5 commits into
mainfrom
codex-view-pdf
Oct 31, 2026
Merged

cu1ch3n merged 5 commits into
mainfrom
codex-view-pdf

Conversation

@cu1ch3n

@cu1ch3n cu1ch3n commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

What

New Codex tasks get a view_pdf tool, so the agent can see the typeset pages instead of editing LaTeX blind. Codex decides when to use it; the instructions ask for it when the look of the pages matters (line breaks, spacing, figures, tables, displayed formulas) and not for wording alone.

  • Codex asks for the pages where source lines are typeset (main/chapters/intro.tex:42) or for printed page numbers when the PDF supplies page-label metadata, in its worktree or in the accepted text (accepted: true), up to 4 pages per call.
  • The review engine's new POST /api/tasks/:name/view snapshots the worktree, compiles it like a review round (partial builds when the paper allows them, so the review after the turn reuses the build), finds pages with synctex view, and draws them as PNG files under the engine's state folder. Compiler errors go back to the agent as the tool result.
  • Without page-label metadata, printed-number requests explain the limitation and ask for source locations. Pages found through SyncTeX still work and are identified by their physical PDF position, without inventing a printed number.
  • The tool returns file paths, and Codex opens the pages with its own view_image. Returning images directly made Codex's code mode print the base64 as text (about 25k tokens for one page in testing); by path, one page costs about 1.5k tokens.
  • Papilot answers the call itself, without asking the author. The conversation shows each look as Viewed the PDF (查看了 PDF), and folded tool groups count it separately.

Things to review

  • This uses the app-server's experimental API: Codex is now initialized with capabilities.experimentalApi, and dynamicTools is passed on thread/start only. If Codex rejects the tool, the thread starts without it and later threads skip it.
  • Only Codex gets the tool. Tasks started before this change don't get it, because tools can't be added to an existing thread; resumed threads keep theirs (task.viewPdf).
  • Viewed pages stay in views/<task> in the engine state for 6 hours, then the next view of that task removes them.
  • Pending tool replies are discarded if the agent disconnects, reconnects, finishes its turn or shuts down. Transport errors are caught without trying to send another reply, so a Codex exit during compilation cannot crash Papilot.
  • Each call may compile: about 13 s for the example paper; on a 300-page thesis, about 17–37 s for one chapter and about 140 s for a full build.

Testing

  • Papilot build and typecheck; review engine typecheck. The application suite passes (323 passed, 1 skipped).
  • 96 workspace tests and 7 engine view/server tests pass.
  • Real TeX regression: a paper with roman front matter and reset arabic numbering, with and without PDF page-label metadata. Missing metadata never returns the front matter as printed page 1; source locations still reach the correct page.
  • Tool-response coverage distinguishes physical page positions from known printed labels.

New Codex tasks get a view_pdf tool. Codex asks for the pages where
source lines are typeset, or for printed page numbers, in its worktree
or in the accepted text. The review engine compiles them like a review
round and draws the pages as PNG files, which Codex opens with its own
view_image tool. The tool returns file paths rather than images: in
testing, Codex's code mode printed returned images as base64 text,
about 25k tokens for one page, against about 1.5k for a page opened by
path.

The engine compiles only the chapters that the edits and the asked-for
places need when the paper allows partial builds, so the review after
the turn reuses the build, and it reports compiler errors to the agent
when the worktree does not compile. Papilot answers the call itself,
without asking the author, and the conversation shows each look as
"Viewed the PDF". The instructions ask Codex to use the tool when the
look of the pages matters and not for wording alone.

The tool is a dynamic tool of the app-server's experimental API, so
Papilot now initializes Codex with experimentalApi. A Codex that refuses
the tool starts its threads without it. Resumed threads keep the tool;
tasks started before this change do not get it.
@cu1ch3n
cu1ch3n merged commit da0e738 into main Oct 31, 2026
4 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.

1 participant