Commit Graph

39 Commits

Author SHA1 Message Date
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
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
Bingxi Zhao (Frank)
04040a2c06 release: v1.6.5
Ship a content workspace you choose, one exec tool for every language,
Mastery Path modes that gate its tools, and Settings that grades
readiness instead of listing faults.

Release notes: assets/releases/ver1-6-5.md
2026-09-06 13:46:29 +08:00
Bingxi Zhao (Frank)
93df3d48b7 release: v1.6.4
Ship lighter isolated runtimes, richer Books and Mastery flows,
Reading/session polish, and explicit model API capabilities.

Release notes: assets/releases/ver1-6-4.md
2026-09-03 01:38:54 +08:00
Bingxi Zhao (Frank)
02ba56793e chore: checkpoint backend stabilization workspace 2026-09-01 21:28:15 +08:00
Bingxi Zhao (Frank)
0b0a5f93dc Merge origin/main into dev
Back-merge PR #1041 (Anthropic SDK 1.x temperature via extra_body) and
PR #741 (owner-only permissions for auth secret/token files), which were
merged directly into main and never flowed back to dev. Required so the
release cut can fast-forward main from dev.
2026-08-30 12:49:49 +08:00
Bingxi Zhao
3f6e82405e Merge pull request #741 from lukiod/fix/secret-file-permissions 2026-08-29 11:27:40 +08:00
ZQR1101
81e5ff8e3d fix(tools): decode unicode escapes in ask_user payloads
Models sometimes emit literal \\uXXXX runs in ask_user and mastery_quiz tool args. Decode dense non-ASCII runs when building learner-facing payloads so cards do not leak escapes (#973).
2026-08-28 13:21:08 +08:00
XZH
d3b19f3a2e feat(reading): add source-faithful EPUB contract 2026-08-23 04:38:24 -07:00
zhouraym
0f22353806 feat: add EPUB support for knowledge base (#843)
* feat: add EPUB support for knowledge base

* fix: bound and tolerate EPUB extraction

---------

Co-authored-by: zhouruim <zhouruim@digitalchina.com>
Co-authored-by: Bingxi Zhao (Frank) <13051345080@163.com>
2026-08-16 19:24:04 +08:00
Bingxi Zhao (Frank)
c96440d6ac fix: harden Responses stream parsing (#825) 2026-08-12 16:11:21 +08:00
Bingxi Zhao (Frank)
ef5ce9f952 fix: RAM issues 2026-08-02 13:07:32 +08:00
lukiod
255e00b19c fix: create auth secret and token files with owner only permissions
Three sites wrote secrets with Path.write_text and narrowed them with chmod
afterwards. write_text creates using 0o666 & ~umask, so the contents were
readable by other local users until the chmod landed, and permanently whenever
it raised, since the error was discarded.

Affected: the auth secret in multi_user/identity.py, minted with
secrets.token_hex(32) and written world readable at creation, the same file on
the legacy migration path, and the skill hub tokens in
services/skill/credentials.py.

write_secret_text passes the mode to os.open so it applies at creation. The
parent directory is created 0700, and a leftover from an interrupted run is
replaced rather than truncated.

Measured on Linux under the default umask: 0644 holding the secret before being
narrowed to 0600.
2026-07-27 22:08:26 +05:30
Bingxi Zhao (Frank)
34ca1cb27c fix(utils): return the longest decodable JSON value, not the first (#692)
The raw_decode scan added for trailing brace-prose returned the first
decodable value in the response. DeepSeek-style reasoning preludes often
embed a small schema example (e.g. {"chapters": []}) before the real
payload, so the example shadowed the actual object and BookEngine's
SpineAgent fell back to a single Overview chapter. Scan every top-level
candidate and keep the longest decode instead.
2026-07-24 17:39:00 +08:00
Cyriellewu
b020686ced fix(json_parser): strip <think> reasoning tags before parsing (#675)
Reasoning models (Qwen, DeepSeek, etc.) emit chain-of-thought inside
<think>...</think> blocks before the JSON payload. parse_json_response()
did not account for this: a brace inside the reasoning was picked up by
the raw_decode scan and returned instead of the real object, silently
yielding wrong or empty data (e.g. empty BookEngine proposal fields).

Strip <think> blocks only on the direct-parse failure path, so a valid
JSON payload whose string values legitimately contain the substring
'<think>' is preserved exactly. Also drop an unclosed leading <think>
prelude up to the first JSON opener, and return the fallback when the
response is reasoning-only with no payload.

Fixes #673

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-24 16:04:42 +08:00
santhreal
19789f19be style(utils): one-line comment on trailing-prose JSON decode 2026-07-22 22:52:15 -07:00
santhreal
5c3e5bf560 fix(utils): decode trailing-prose JSON before repair
json-repair wrapped a valid object plus trailing brace-prose into an array,
corrupting book/question callers that expect a single object. Prefer
raw_decode of the first JSON value before repair.
2026-07-22 22:49:04 -07:00
Bingxi Zhao (Frank)
b728354863 release: v1.5.2
Configurable chat attachment limits, PageIndex retrieval by reasoning
over your documents, broader Anthropic/OpenAI model support, and a
sweep of Book / Knowledge Base / chat-UI reliability fixes. Drop-in —
no migrations.

- attachments: size caps + extraction budgets editable in Settings →
  Chat → Attachments (admin), stored in system.json with CHAT_ATTACHMENT_*
  env overrides; the WebSocket frame ceiling is now derived from the
  total cap, fixing large uploads silently dropping the connection.
- pageindex: chat retrieves via an internal MCP server (agentic tool
  calls over the document tree); search() returns the outline; ingestion
  accepts PDF/Office/Markdown/text/CSV.
- llm: newer Anthropic/OpenAI models via official SDKs incl. Codex native
  tools; effort-based Claude → adaptive thinking; corrected temperature-
  rejection set; streamed usage counted once per completion.
- book/knowledge: rescue stuck GENERATING/PLANNING pages + reset on
  failure; KB status updates on upload/sync; atomic manager writes.
- web/channels: full-width chat + single scrollbar, aligned composer,
  Enter sends edited message, malformed-markdown crash fix; WeCom aligned
  with SDK 1.0.8; Mastery recency weighting restored (#618).
- release notes ver1-5-2.md (v1.5.0/v1.5.1 archived to past_releases/),
  __version__ bump to 1.5.2, README Releases row + one-week fold.
- README Settings/config prose + all 10 translations synced; docs
  settings/knowledge/chat pages updated separately in site/.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 17:15:36 +08:00
Bingxi Zhao (Frank)
c0037dfb58 fix chat attatchments 2026-07-19 16:56:34 +08:00
Bingxi Zhao (Frank)
9983c0a3d1 fix: partners & multi-user 2026-06-27 18:27:16 +08:00
Bingxi Zhao (Frank)
b2ce70db69 Merge pull request #500: Guided Learning (mastery-based tutoring subsystem)
New self-contained deeptutor/learning/ subsystem (models, storage, service,
scheduler, grading) + 12-stage guided_learning capability, REST router, and
web learning pages, with 164 tests.

Conflict resolutions:
- services/llm/factory.py: kept dev's stream runner (allow_image_fallback
  multimodal path); dropped the PR's incidental 300s asyncio.wait_for wrapper
  and its now-orphaned TimeoutError handler / unused logger — the blanket
  timeout is unrelated to guided learning, dev already has consumer-side
  timeouts, and 300s would truncate long legitimate streams (book/research).
- web/components/sidebar/WorkspaceSidebar.tsx: kept dev's structure, added a
  useCallback handleNewChat that cancels any in-flight streaming turn before
  newSession() (mirrors handleDeleteSession) and wired it to onNewChat.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-29 13:44:05 +08:00
Bingxi Zhao (Frank)
6c024857b7 release: v1.4.1 — security & stability patch
Security: lock down the TutorBot tool sandbox (shell exec is opt-in, all
filesystem/shell access confined to the bot workspace) and isolate per-user
resources, closing #518, #517, #516, #515, #514 and #506 (first hardened in
#507).

Bug fixes: chat input disabled after the first turn (#520), KB embedding
failure on long documents (#521 / #509), profile creation under Docker
(#512 / #513), Qwen reasoning models failing native tool calling (#527 / #528),
the GPT-5 init-wizard token parameter (#508), and oversized session-event
truncation (#524).

Features: HTTP/SSE API for multi-turn chat with a specific TutorBot (#511),
multimodal image fallback for vision-capable providers without a capability
entry, safe ZIP knowledge upload, and a /settings/network page with model
fetching (community PRs #522 and #523 reimplemented locally).

Also bumps __version__ to 1.4.1, adds the v1.4.1 release notes, updates the
README Releases section, and ships the Astro + Starlight docs site under site/.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 23:16:00 +08:00
unknown
77b24725c5 merge: upstream/dev into feature/guided-learning
Resolved 8 conflicts:
- agentic_pipeline.py: keep `import asyncio` (ours)
- deep_question.py: accept upstream's removal of answer_now fast-path
  (refactored into agentic engine in upstream 23ca302); drop dead
  helpers _parse_answer_now_json, _collect_cost_summary, and the
  legacy _run_mimic_mode overload
- pocketbase_store.py, WorkspaceSidebar.tsx, en/zh app.json: keep ours
- playground/page.tsx: keep ours (apiFetch + RESEARCH_SOURCE_OPTIONS),
  also remove pre-existing duplicate top-of-file block left over from
  the earlier a8801f9 merge; add `type ResearchSource` import
- reporting_agent.py: accept upstream's deletion
2026-05-21 23:26:53 +08:00
Bingxi Zhao (Frank)
90a2c14c81 chore: backend + frontend follow-ons for v1.4.0-beta
Wires the new memory / capability / settings / quiz subsystems into
existing surfaces and finishes the chat-pipeline follow-on work.

Backend:
- Session services pick up the cumulative source inventory + new tool
  tags (turn_runtime, sqlite_store, pocketbase_store, protocol,
  base_session_manager).
- LlamaIndex RAG pipeline config / document_loader / retrievers
  tightened; rag/service.py routed to match.
- Sessions / unified_ws / settings / notebook routers updated for
  delete-chat-turn, multi-user, and the new tool surface.
- TutorBot manager + Zulip channel + openai_compat_provider follow-on
  fixes layered on top of the v1.3.10 SSL/Zulip sweeps.
- runtime/{banner, launcher, orchestrator}, services/setup/init,
  prompt/manager, json_parser refined for the runtime-settings
  rewrite.

Frontend:
- Co-Learn pages and session-surfaces removed (folded into chat).
- Chat composer / messages / trace / session panels, sidebars,
  common modals, markdown renderers, and i18n updated for the new
  ask_user / write_note / source-inventory flow.
- Admin, agents, co-writer, playground, book pages picked up the
  shared updates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 18:08:22 +08:00
whf
a8801f929a merge: guided-learning-v2 into feature/guided-learning (target dev)
Resolved 10 conflicts:
- api/main.py: kept dev CORS config
- unified_ws.py: kept dev auth flow (ws_require_auth)
- builtin_capabilities.py: added guided_learning + auto capabilities
- pocketbase_store.py: merged both additions
- ChatMessages, WorkspaceSidebar, chat/playground pages: merged both additions
- en/zh app.json: added comma, validated JSON
2026-05-21 13:18:41 +08:00
unknown
6934db4a91 perf: unified LLM/RAG timeout, per-stage degradation, and code cleanup
- Add stage_failure_counts/stage_failure_notes to LearningProgress for persistent failure tracking
- Wrap RAG retrieval with 10s independent timeout in _call_llm_impl
- Add _call_llm_with_timeout (default 60s) and _call_llm_with_degradation (bounded retry + skip)
- Apply degradation to all 12 stage handlers with stage-specific fallback paths
- Extract _run_interactive_quiz_loop shared helper for practice/practice_quiz
- Extract StructuredStageContent component from page.tsx
- Add TypeError to JSON parse except clauses across 7 files
- Simplify _record_attempt_and_update_mastery to single save exit
- Move import logging to module top in service.py
2026-05-21 00:07:31 +08:00
Bingxi Zhao (Frank)
85779c846b refactor env settings and installation 2026-05-11 12:59:56 +08:00
Bingxi Zhao (Frank)
144c90f3f7 prepare v1.3.4 release
Made-with: Cursor
2026-05-01 13:51:45 +08:00
Bingxi Zhao (Frank)
824bf778df fix: lint & logging system 2026-05-01 01:39:08 +08:00
Bingxi Zhao (Frank)
7fce54d98a chore: prepare v1.3.0 release
Made-with: Cursor
2026-04-27 21:09:25 +08:00
Bingxi Zhao (Frank)
6428458049 chore: prepare v1.2.5 release 2026-04-25 22:08:44 +08:00
Bingxi Zhao (Frank)
c89a3df8a5 chore: prepare v1.2.4 release 2026-04-25 15:10:55 +08:00
Bingxi Zhao (Frank)
4b7d24d33e release: v1.2.3 — document attachments, thinking blocks, provider core refactor
- Chat document attachments (PDF/DOCX/XLSX/PPTX) with text extraction
- Reasoning model <think> block display as collapsible cards
- Tri-state send_dimensions toggle for embeddings (#368)
- LLM provider_core module refactor + context_window detection
- Soul template editor (PR #373), Co-Writer save-to-notebook
- Knowledge Base drag-and-drop upload, delete resilience (#370),
  progress persistence, supported-file-types endpoint
- Question generation language fidelity via shared prompt directives
- Settings tour redesign, CLI notebook add-md/replace-md
- Bug fixes: CJK bot name slug, I18nProvider init, Skills default off,
  Moonshot base URL, version badge
- Provider registry: custom_anthropic, thinking_style, alias expansion
- +1900 test lines across 15 new/expanded test files

Made-with: Cursor
2026-04-24 22:36:32 +08:00
Bingxi Zhao (Frank)
77f29cbcc7 fix lint 2026-04-23 19:29:16 +08:00
Cocoon-Break
cd33a527c1 fix: use lowercased filename in mimetypes.guess_type for consistent MIME validation 2026-04-10 00:30:06 +08:00
Bingxi Zhao (Frank)
a4d9bd4860 fix: use sentinel for parse_json_response fallback so None is honored
The original implementation converted `fallback=None` to `{}`,
making `if data is None:` checks dead code in data_structures,
note_agent and reporting_agent. Use a `_UNSET` sentinel so callers
can explicitly request `None` as the failure value.

Also simplify control flow in data_structures and reporting_agent
to avoid raising ValueError inside bare try/except that wouldn't
catch it.

Made-with: Cursor
2026-04-08 12:11:19 +08:00
Bingxi Zhao (Frank)
f3779138ae fix: remove lightrag and unify llm & search config 2026-03-13 23:48:49 +08:00
Bingxi Zhao (Frank)
9c18bf0705 codebase cleanup and decoupled, introduce cli operation 2026-03-13 20:42:16 +08:00