70 Commits

Author SHA1 Message Date
Bingxi Zhao (Frank)
8ecf2da95f fix(parsing): validate uploads against available parser formats
Fixes #2338
2026-11-15 01:20:52 +08:00
Bingxi Zhao (Frank)
ea517d2c59 fix(import): use locale hints for ambiguous legacy text encodings
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.
2026-11-15 00:50:30 +08:00
Bingxi Zhao (Frank)
92a26ae3cc fix(storage): isolate attachment writes and settle document parsing
Local dev repairs for #2244, #2245, #2255, #2426, #2453. Regression checks cover reported symptoms and compatibility boundaries.
2026-11-15 00:44:09 +08:00
Bingxi Zhao (Frank)
3ef9ee8886 Merge PR #2513: fix: pick the JSON fence when a code snippet fence comes first
Prefer explicit JSON fences over unlabeled examples, ignore other language fences, and cover both precedence and embedded JSON preservation.
2026-11-14 23:07:03 +08:00
Bingxi Zhao (Frank)
21e9878b59 Merge PR #2556: fix: sync and index MDX documentation in knowledge bases 2026-11-14 22:57:42 +08:00
yunyv
2e1014df88 test(utils): cover BibTeX fragment whitespace 2026-11-13 13:00:56 -07:00
markxu
fdae1dfdf0 fix: sync and index MDX documentation in knowledge bases
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
2026-11-09 14:09:57 +00:00
Mohammad Hijjawi
e27aa512df fix: pick the JSON fence when a code snippet fence comes first
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.
2026-11-07 10:41:08 +00:00
Bingxi Zhao (Frank)
b49cdbc38e Merge #2311 from rudycelekli 2026-11-06 01:56:22 +08:00
Rudy Celekli
f930c5ece8 fix(ingestion): separate EPUB table cells during text extraction
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>
2026-11-01 09:35:37 -05:00
RRFZ
4ffda7aa2e fix(archive): skip zip members that differ only in case on Windows and macOS
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.
2026-10-31 20:37:51 -04:00
Bingxi Zhao (Frank)
32e992b139 Merge commit '92f0b68db074f013d3aab4482c1ed5bd8dec8a83' into codex/validate-reviewed-integration 2026-10-31 18:53:15 +08:00
Bingxi Zhao (Frank)
64ad8598de Merge commit 'cc9a60237bcc7e4213f574081824c49c92569ed8' into codex/validate-reviewed-integration 2026-10-31 18:53:15 +08:00
Bingxi Zhao (Frank)
862fa3cb97 Merge commit '0fb3d74495eb4063177df3286bd4de0aab2e76bf' into codex/validate-reviewed-integration 2026-10-31 18:52:54 +08:00
Bingxi Zhao (Frank)
92f0b68db0 Merge dev while preserving both BibTeX parser regressions 2026-10-31 18:26:27 +08:00
Bingxi Zhao
f756f371e7 Merge pull request #2157 from jayhemnani9910/bibtex-author-names
fix: format BibTeX names with Jr parts and braced "and"
2026-10-31 18:08:07 +08:00
Bingxi Zhao (Frank)
cc9a60237b Merge remote-tracking branch 'origin/dev' into codex/land-2163
# Conflicts:
#	deeptutor/utils/document_extractor.py
2026-10-31 17:25:30 +08:00
Bingxi Zhao (Frank)
92488f5a63 fix(docx): retain grouping for sums of delimited math terms 2026-10-31 17:18:09 +08:00
Bingxi Zhao (Frank)
0fb3d74495 fix(archive): close partial files before cleanup on every failure 2026-10-31 17:17:26 +08:00
Bingxi Zhao
10dace6fdb Merge pull request #2236 from rudycelekli/fix/pptx-presentation-slide-order-20261031
fix(documents): follow PPTX presentation slide order in fallbacks
2026-10-31 17:02:04 +08:00
Bingxi Zhao
3f3cff69c6 Merge pull request #2199 from rudycelekli/codex/fix-pptx-fallback-pictures-20261030
fix(documents): retain picture shapes in PPTX fallback
2026-10-31 16:49:39 +08:00
Bingxi Zhao
662c94b903 Merge pull request #2237 from rudycelekli/fix/xlsx-sparse-cell-columns-20261031
fix(documents): preserve sparse XLSX cell columns in fallback
2026-10-31 16:49:11 +08:00
Bingxi Zhao
5d7049869f Merge pull request #2227 from rudycelekli/fix/bibtex-delimiter-scope-20261030
fix(utils): keep interval punctuation inside BibTeX values
2026-10-31 16:47:15 +08:00
Bingxi Zhao (Frank)
9cbdb75e6d fix(docx): preserve nested scripts and empty math delimiters 2026-10-31 16:45:03 +08:00
Bingxi Zhao (Frank)
77addee410 fix(archive): preserve pre-existing files on extraction failure 2026-10-31 16:40:20 +08:00
Rudy Celekli
eea3b870aa fix(documents): preserve sparse XLSX cell columns in fallback
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.
2026-10-31 01:43:08 -04:00
Rudy Celekli
75776a7bbc fix(documents): respect empty PPTX presentation metadata
Keep valid empty presentation lists empty even if orphan slide parts remain. Only missing or unreadable metadata permits filename fallback; external relationships stay excluded.
2026-10-31 01:41:09 -04:00
Rudy Celekli
0628c03240 fix(documents): follow PPTX presentation slide order in fallbacks
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.
2026-10-31 01:39:12 -04:00
Rudy Celekli
d7e621ad5f fix(utils): finish UTF-8 characters at text probe boundaries
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.
2026-10-30 23:30:41 -04:00
Rudy Celekli
4a1163b71f fix(utils): keep interval punctuation inside BibTeX values
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.
2026-10-30 23:19:23 -04:00
RRFZ
5a344d3133 fix(knowledge): remove extracted members when a zip upload is rejected
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.
2026-10-30 16:10:42 -04:00
Rudy Celekli
e0ad3bba56 fix(documents): retain picture shapes in PPTX fallback 2026-10-30 07:55:43 -04:00
朱鸿儒
47e39c40ca fix(docx): preserve OMML across fallback paths 2026-10-30 10:50:12 +08:00
朱鸿儒
e51c25f726 fix(docx): preserve native OMML equation structure 2026-10-30 10:41:28 +08:00
Jay Hemnani
aee4ac8dd3 fix: keep BibTeX quoted values that contain a braced quote
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.
2026-10-29 13:44:32 +05:30
Jay Hemnani
9a2f1dd074 fix: format BibTeX names with Jr parts and braced "and"
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".
2026-10-29 13:44:32 +05:30
Fancie-Personal
e7c909ec94 perf(documents): bound an inlined raster's long edge before admission
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.
2026-10-18 23:36:28 +08:00
Mohammad Hijjawi
d16481a77c fix: decode escaped emoji in ask_user cards as real characters (#1780)
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.
2026-10-07 20:21:09 +08:00
Mohammad Hijjawi
ec79b40996 fix: keep BibTeX entries with accented author names
_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.
2026-09-28 13:53:27 +01:00
Bingxi Zhao (Frank)
8880529c65 Merge PR batch with local follow-up fixes
Preserve precise learner KB route guards, combine UI and response language domains, carry normalized EPUB extraction, and regenerate frontend contracts.

Update locale fallback coverage for the completed Ukrainian translation bundle.
2026-09-23 12:01:14 +08:00
Bingxi Zhao (Frank)
705e9bf9d5 Merge branch 'codex/reading-learning-prs-20260923' into codex/pr-batch-root
# Conflicts:
#	deeptutor/reading/extract.py
#	deeptutor/reading/store.py
#	web/components/notebook/NotebookRecordRow.tsx
#	web/locales/en/app.json
#	web/locales/zh/app.json
2026-09-23 10:58:38 +08:00
Bingxi Zhao (Frank)
064034a283 Merge branch 'codex/evan-backend-prs-20260923' into codex/pr-batch-root
# Conflicts:
#	deeptutor/api/routers/settings.py
#	tests/api/test_settings_router.py
#	web/components/notebook/NotebookRecordRow.tsx
#	web/components/settings/SettingsOverview.tsx
#	web/context/app-shell-storage.ts
#	web/features/knowledge/api/sources.ts
#	web/features/settings/store/SettingsStore.tsx
2026-09-23 10:56:37 +08:00
Bingxi Zhao (Frank)
1829ae23f0 Fix PDF image mapping, caption refresh, and Grok detection 2026-09-23 10:48:36 +08:00
Bingxi Zhao (Frank)
4defba8b99 Merge commit 'refs/pr/1371' into codex/evan-backend-prs-20260923 2026-09-23 10:27:59 +08:00
flower-moon
8999c0d3e4 feat(reading): extract PDF figures so the reader can send them to the model
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).
2026-09-17 18:46:28 +08:00
flower-moon
e1b4954a23 feat(documents): Office/PDF 嵌入图片全链路支持 — 提取、显示、喂视觉模型
- 新增 utils/document_images.py:docx(OOXML单遍扫描)/pptx(python-pptx+OOXML兜底)/pdf(pymupdf, xref去重)
  嵌入图片提取,统一 [图片 N: name] 正文标记 + ImageBudget 预算(单文档12张/12MB,单回合16张/12MB)
- 聊天附件:extract_documents_from_records 产出嵌入图片 image 记录(embedded 标记),
  turn_runtime 托管附件库后经现有多模态注入管道发给视觉模型,UI 零改动渲染图片附件
- 阅读区:Extraction.media + 标记→locator 映射,入库 media/ + media.json,
  新增 GET /materials/{id}/media(/{name}) API,TextUnitView 图片条(article 外侧,不动逐字锚定),
  immersive_reading 回合注入当前页图片(≤4张),read_material 结果附图片清单
- docx 富提取顺带补齐 python-docx 一直丢掉的表格文本;EMF/WMF 矢量图计数尾注不静默丢弃
- MaterialManifest 新增 media_count(向后兼容);media_path 索引校验防路径穿越
- tests: test_document_images.py 8 用例;utils 51 + 阅读区全套 + session 209 通过

详细文档: docs/文档图片支持_提取显示与视觉模型_2026-09-07.md (gitignored)
2026-09-17 18:46:28 +08:00
XZH
28aa40ff45 fix(reading): normalize packaged EPUB archives 2026-09-15 02:11:01 -07:00
Bingxi Zhao (Frank)
752fba35d4 fix(reading): read an EPUB that macOS re-zipped as the book it is
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>
2026-09-13 20:42:23 +08:00
XZH
785f13cca7 feat(knowledge): add Zotero BibTeX search
Refs #1303.
2026-09-10 09:49:20 -07:00
Bingxi Zhao (Frank)
02ba56793e chore: checkpoint backend stabilization workspace 2026-09-01 21:28:15 +08:00