Local dev repairs for #2132, #2133.
Turkish UI prefers Windows-1254 after UTF-8; strict explicit encoding is available for mixed legacy collections. Tested both upload bytes and file reads, short Turkish strings, GBK, GB18030 and Windows-1252. Encoding and memory suite: 398 passed.
GitHub source sync kept only .md and .markdown, so a docs glob of *.mdx
reported success with zero files and left raw/ empty. Re-index then failed
because no supported source files were present. Treat .mdx as text next to
Markdown in the sync filter, the knowledge-base file router, and the chat
attachment list that mirrors it.
Fixes#2552
parse_json_response extracted only the first fenced block, so a reply
that shows a code snippet (for example a ```python block) before the
fenced JSON payload lost the payload: it returned a list literal from the
snippet or the fallback. Prefer the first fenced block that holds a JSON
object or array, and keep the first block otherwise.
td/th were missing from _EPUB_BLOCK_TAGS, and nothing else emits a
separator between table cells. Both EPUB text renderers (_epub_render_text
and the _EpubHTMLTextParser fallback) only break on block tags, so they
relied on source whitespace between cells. Commercially produced EPUBs
often ship minified, whitespace-free XHTML, where a row like
<tr><td>Revenue</td><td>100</td><td>Q1</td></tr> extracts as the single
glued token "Revenue100Q1" — unreadable data fed to the model.
Add td and th to _EPUB_BLOCK_TAGS so each cell is separated, the same way
li/dd/dt already are. One constant fixes both renderers.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
On a case-insensitive filesystem, week2/readme.md flattens onto the
README.md that week1/README.md already wrote in the same call. Since
members are created with "xb", that raised FileExistsError and the
upload router rejected the whole archive with a 400 naming the server
path. Before "xb", the later member silently replaced the earlier one.
Treat it like any other flattening collision: when the destination is
the same file as a member this call already wrote, skip it as a
duplicate. A pre-existing file with a case-only name match is still
refused, and case-sensitive filesystems keep both names as before.
Use worksheet cell coordinates to retain missing leading and interior cells. Bound padding to Excel columns A through XFD and keep sequential fallback for missing or malformed references.
AI-assisted: implemented and validated with OpenAI Codex; real saved openpyxl workbooks provide independent row oracles.
Keep valid empty presentation lists empty even if orphan slide parts remain. Only missing or unreadable metadata permits filename fallback; external relationships stay excluded.
Resolve presentation slide IDs through their relationships instead of sorting part filenames. Share ordering across both OOXML extraction paths and preserve metadata-free extraction.
AI-assisted: implemented and validated with OpenAI Codex; actual generated decks checked against python-pptx.
Use an incremental UTF-8 decoder to complete only a code point split by the 8192-byte sample while still rejecting invalid bytes and incomplete input at EOF.
AI-assisted: implementation and regression tests prepared and validated with OpenAI Codex. Maintainer review is pending.
Count parentheses as outer entry delimiters only for parenthesized entries and outside braced field values, so half-open intervals do not discard valid references.
AI-assisted: implementation and regression tests prepared and validated with OpenAI Codex. Maintainer review is pending.
safe_extract_zip writes members one by one into the KB raw/ directory.
When a later member tripped a zip-bomb guard or failed its CRC check, the
upload was rejected with HTTP 400 but every member written before it, and
for a CRC failure the corrupt member itself, stayed on disk.
Delete the files this call wrote before the error propagates, and drop a
member's partial output when it fails mid-read.
In a quoted BibTeX value a double quote is written inside braces, as in
title = "The {"}Quoted{"} Paper". The converter ended the value at the
first quote, so the title became "The" and the entry lost its remaining
fields. Only end a quoted value at a quote outside braces.
Authors were split on every " and " after braces were removed, so a
braced corporate name such as {Food and Agriculture Organization} became
two people, and "King, Jr., Martin Luther" came out as "Jr., Martin Luther
King". Split names and name parts only outside braces, and order the
three-part "Last, Jr, First" form as "First Last Jr".
Chat attachments base64-inline every harvested image into one provider
request, and the byte budgets did not bound what a *page-sized* raster costs
there: a scanned A4 page arrives at ~2900x4032 (~600 KB), so a seven-page scan
rode along as ~4.2 MB of body / ~5.6 MB encoded even though the model is served
a raster scaled toward ~1.5k on the long edge anyway.
Fit a candidate to MAX_INLINE_IMAGE_EDGE (1600) before the byte budgets weigh
it, so the budgets measure what will actually ship. An image already within the
bound keeps its bytes and its format; re-encoding is reserved for rasters past
it, at the same jpg_quality (82) the reading viewport's whole-page render
already uses. Every failure path returns the original bytes, and a pixel count
past MAX_INLINE_FIT_PIXELS is refused before Pillow allocates for it.
The reading-area ingest keeps source resolution (max_inline_edge=0) because
those images are written to disk for the reader pane. The PPTX and DOCX
ingests were still on the chat-attachment budget by default, so they now pass
the reading budget like the PDF ingest already did.
decode_escaped_unicode_for_display repairs double-encoded \uXXXX runs
(#973) with the unicode_escape codec, which turns a surrogate-pair escape
for an emoji into two lone surrogates instead of one emoji. The
result cannot be encoded as UTF-8, so an ask_user card or mastery question
whose escaped text contains an emoji fails when the event is persisted to
SQLite or sent over the WebSocket.
Decode each run as a JSON string instead, matching the web decoder's
JSON.parse, and leave runs with an unpaired surrogate escaped.
_scan_entry treated every double quote as the start of a quoted value,
even inside a braced one. An accent such as {\"u} in
author = {M{\"u}ller, Hans} therefore opened a "quoted" run that swallowed
the entry's closing brace, and the whole entry was silently dropped from
the converted bibliography. Only treat a double quote as a delimiter at
the entry's top level, as BibTeX does.
The reading chain only pulled embedded images out of Office files; the PDF
branch produced text alone, so a slide deck uploaded as PDF reported
media_count 0 and no [图片 N] markers at all. The chat-attachment path already
had the missing half (extract_pdf_images + per-page markers), so the reader
now reuses it: each page's figures are pinned to that page's locator and the
marker lines are appended at the END of the page text, leaving every existing
character offset — and therefore every saved annotation anchor — untouched.
Budgets differ by path. Chat attachments inflate images into one request, so
they keep the 12-image/12MB document cap; the reader stores bytes on disk and
only ever sends the open page, so reading_image_budget() allows 120 images /
60MB per document while capping each page at 4 — the same ceiling the viewport
injection applies per turn, which keeps one dense figure page from eating the
document budget. extract_pdf_images/extract_docx_rich/extract_pptx_rich now
accept an explicit ImageBudget, defaulting to the previous behaviour.
Measured on the physics decks: day03_GaussLaw.pdf goes from 0 to 63 media rows
across 23 of its 42 pages (66 candidates, 3 dropped by the per-page cap).
Finder's "Compress" does two things to an EPUB: it nests the whole book
under one folder, and it writes a parallel `__MACOSX/` tree of AppleDouble
resource forks that carry the content files' names and extensions.
The package lookup only ever looked for `META-INF/container.xml` at the
archive root, so a wrapped book found no container, no OPF and no spine,
and fell back to matching file extensions over the whole archive. That
fallback then read `__MACOSX/OEBPS/._index_split_000.xhtml` — 60 bytes of
binary resource fork — as a chapter. Hence the phantom `._…` sections in
the sidebar and "Could not load this section" on opening them (#1447).
Both halves of the same rule, in one place. Packaging residue (`__MACOSX`,
dotfiles) is not book content and never reaches either reader; the other
archive readers in this codebase already drop it. And a single wrapper
directory is resolved from wherever the container actually sits, so spine
order survives it.
The container/OPF chain was written out twice — once for the spine, once
for the navigation — so a wrapped book silently lost its whole outline
too, by a `return []` in the half nobody was looking at. One resolver now
answers "where is this book's package document" for both.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>