4777 Commits

Author SHA1 Message Date
whf
95f4498942 Block 22: display module name on /learning cards instead of raw book_id
Backend: list_progress() derives display name from first module name,
falling back to book_id for empty-module books.
Frontend: ProgressSummary gains 'name' field, card heading uses
card.name || card.book_id instead of raw book_id.
Tests: 2 new negative tests (name from module, empty-module fallback).

92/92 passing.
2026-05-18 20:40:47 +08:00
Sam
6c2615df39 fix(visualize): unblock Gemini 2.5+, harden Visualize pipeline
Six bugs that combined to break the Visualize capability on Gemini 2.5
Flash (and similar thinking-by-default models). Each is independently
useful, but the user-visible symptom — Visualize "kind of works but
output is randomly truncated at ~370 chars" — needs all of them.

1. Gemini 2.5/3.x reasoning-tokens default (root cause)

   Gemini 2.5+ models burn most of `max_tokens` on internal "thinking"
   tokens by default. With `max_tokens=4096`, ~3900 went to reasoning
   and only ~160 came out as actual content, causing finish_reason=length
   on every multi-step pipeline (Visualize codegen + review, Deep Solve,
   anything that asks for a structured output beyond a sentence).

   Default `reasoning_effort="none"` for Gemini 2.5/3.x models when the
   caller doesn't specify, in all three execution paths:
   - provider_core/openai_compat_provider.py:_build_kwargs (live path)
   - executors.py:sdk_complete / sdk_stream (legacy SDK path)
   - cloud_provider.py:_openai_complete / _openai_stream (aiohttp fallback)

2. visualize capability had no agents.yaml entry

   `get_agent_params("visualize")` silently fell through to the 4096
   default because there was no section_map entry and no
   DEFAULT_AGENTS_SETTINGS entry. Added both, with a 16384-token budget
   appropriate for full HTML pages.

3. Review stage crashed hard on JSON parse failure

   `ReviewAgent.process` does `ReviewResult.model_validate(extract_json_object(response))`.
   When the model returned prose instead of JSON (common with large SVGs
   that the model can't escape into a JSON string), the parse raised and
   killed the entire turn. Wrapped pipeline.run_review() in try/except
   so review failure falls back to the unreviewed draft and the user
   still gets a rendered result.

4. Codegen output not trimmed to the root tag

   Models often wrap SVG/HTML in prose ("Here you go: <svg>…</svg>
   Enjoy!") or emit a closing code fence on the same line as `</html>`,
   which `extract_code_block`'s regex (requiring a leading \n before
   the fence) doesn't strip. Added defensive root-tag trimming for
   render_type=="svg" and render_type=="html".

Verified end-to-end on Gemini 2.5 Flash via the CLI and headless
Playwright: full 22 KB long-division HTML page, no truncation, all
interactive elements present, multi-step walkthrough completes
correctly (7852 ÷ 6 → 1308 R 4).
2026-05-17 16:36:05 +09:00
whf
d086a06b90 Fix 3 P2 bugs from Codex global review: manual module id collision, stale chapters on book switch, stage not reset on module switch 2026-05-17 12:56:24 +08:00
whf
97496d6511 Block 9: backend endpoint tests (21 new + 3 list_all), fix stale local HTTPException imports 2026-05-17 02:42:09 +08:00
whf
7b273d8db8 Block 8 refinement: remove KB placeholder tab, use bookApi.list, LLM parsing type safety, toast on import failure 2026-05-17 02:22:36 +08:00
unknown
64989bd3e7 Block 7+8: Book integration + Create Module dialog (4 tabs)
Block 7: "Start learning" button on BookLibrary cards, import-from-book
endpoint, handleLearn with duplicate progress check, i18n keys.

Block 8: CreateModuleDialog with manual/book/KB/notebook tabs,
generate-from-notebook backend endpoint with LLM extraction,
listBooks/generateModulesFromNotebook API functions, 30+ i18n keys.
2026-05-17 00:05:16 +08:00
whf
cdc1b73ed8 Block 7: /book integration — Start Learning button in BookLibrary 2026-05-16 23:52:15 +08:00
whf
fb7787b089 Block 5+6: DELETE/redo endpoints, change_module WS, LLM progress hints 2026-05-16 23:33:56 +08:00
whf
1e37128eca Block 4: ModuleTree interactive — click to switch learning module 2026-05-16 22:46:13 +08:00
whf
4aaef7cc41 Block 3: frontend API client + multi-book page redesign with tab panel, delete/redo 2026-05-16 22:32:17 +08:00
whf
3fd2d8e809 Block 2: backend list_all + list_progress + GET /progress endpoint 2026-05-16 21:53:22 +08:00
whf
2d2121cdb7 Block 1: sidebar /learning entry + i18n 2026-05-16 21:37:48 +08:00
unknown
91dbafbe75 Block 7.5: i18n completion, WS reconnect with backoff, error retry button
- Add 16 i18n keys for guided learning (en/zh): input placeholder, submit button, no modules text, 13 stage labels
- Replace hardcoded STAGE_LABELS with t() calls using dynamic i18n keys
- Replace hardcoded "No modules loaded" in ModuleTree with i18n
- Add WebSocket auto-reconnect with exponential backoff (1s/2s/4s/8s, max 5 attempts)
- Add "Reconnect" button on error state for manual retry
- Add intentional disconnect on unmount to prevent ghost reconnects
2026-05-16 11:36:50 +08:00
unknown
80ccbe9dfb Block 7.5: Practice quiz phase, auto-advance fix, cancel streaming safety
- Add PRACTICE_QUIZ stage between Feynman Check and Error Diagnosis
- Generate 5-10 practice questions per module, record attempts but don't gate mastery
- Fix auto-advance race: move stagesRef updates outside React setState callbacks
- Fix stale handleStreamEvent closure via ref pattern
- Fix PLAN stage permanent deadlock when modules not initialized
- Clear error state unconditionally on new stage_start
- Add cancelStreamingTurn to sidebar and chat page for proper cleanup
- Fix cancelStreamingTurn to handle missing turnId gracefully
- Keep empty page_ids refs for whole-book resolution in guided learning
2026-05-16 11:33:45 +08:00
whf
6f3070f8d3 Block 21: Auto-mastery calculation, mock module cleanup, quiz_attempts tracking, global review passed 2026-05-15 00:58:34 +08:00
iwedo
69bf9f62dd fix(zulip): 增加内容检测fallback解决Generic bot收不到mention flag问题 2026-05-15 00:38:47 +08:00
Bingxi Zhao
cade7897f4 Merge pull request #480 from wedone/fix/zulip-upload-and-send
fix(zulip): 修复 Zulip 通道附件上传与消息发送的 BUG,支持 Bot 自动订阅频道
2026-05-15 00:12:08 +08:00
Bingxi Zhao
3a2f169063 Merge pull request #478 from mtsui-cmyk/fix/quiz-textarea-vertical-resize
fix: allow quiz answer textarea vertical resize
2026-05-15 00:11:44 +08:00
whf
1ef5e2db01 Block 20: Interactive Feynman check + practice — user input, server-side grading, error_type tracking 2026-05-14 23:54:03 +08:00
whf
5451aa60b4 Block 19: Interactive diagnostic phases — wait_for_input, server-side grading, answer stripping, correct_count, CLI timeout 2026-05-14 23:15:47 +08:00
whf
315b5d0da0 Block 18: StreamBus wait_for_input bidirectional mechanism with bus registry 2026-05-14 22:28:10 +08:00
whf
526bc1c550 Block 17: Server-side question answer persistence, eliminate client-supplied expected_answer 2026-05-14 21:05:52 +08:00
whf
22336e648e Block 16: Server-side answer grading, remove client-supplied is_correct/mastery_estimate 2026-05-14 20:29:34 +08:00
WeDone
e8f14054b5 fix(zulip): 优化已订阅频道时的日志级别避免误导性WARNING
问题:Bot已订阅所有频道时,add_subscriptions仍返回
      non-success结果,原代码记录WARNING级别日志造成误导。

修改:
- 根据already_subscribed计算实际订阅情况
- 有新增订阅时记录INFO,无新增时记录INFO提示已订阅
- 非success但全部已订阅时降级为DEBUG日志
- 真正失败时才保持WARNING级别
2026-05-14 16:25:16 +08:00
WeDone
ac06a05e22 fix(zulip): 支持所有mention flags类型修复频道@mention无响应问题
问题:在Zulip频道中@机器人没有反应,私聊正常。
根因:_is_mentioned方法只检查mentioned flag,遗漏了
      wildcard_mentioned、stream_wildcard_mentioned、
      topic_wildcard_mentioned等通配符mention标志。

修改:
- _is_mentioned支持所有四种mention flags
- 增强日志输出便于排查问题
- 补充边界测试用例(flags缺失、非字符串元素等)
2026-05-14 11:37:06 +08:00
whf
e82b5374cf Block 15: Phase 3 — enum values English + _missing_() backward compat, __init__.py docstring, i18n keys, 66/66 tests 2026-05-14 11:01:49 +08:00
iwedo
9f6ebe91ba feat(zulip): 支持Bot自动订阅频道以接收话题中的@mention消息
问题:在Zulip话题中@机器人没有反应,deeptutor容器无日志。
根因:Bot未订阅频道,Zulip服务器不会推送频道消息事件给未订阅的Bot。

主要修改:
- ZulipConfig新增subscribe_streams配置项,支持指定频道名或通配符'*'
- start()中新增_subscribe_to_streams()自动订阅频道
- _subscribe_to_streams()支持异常保护,订阅失败不阻断Bot启动
- 通配符'*'与显式频道名混合使用时合并处理
- _on_message()添加调试日志便于排查
- _bot_full_name属性用于后续@mention内容匹配

测试修复:
- TestDownloadAttachments添加get_media_dir mock解决yaml导入错误
- TestUploadAndSend改用call_args_list筛选上传调用修复KeyError
- 新增TestSubscribeStreams测试类(7个用例)
- 将test_stop_cancels_typing_tasks移至TestStop类
2026-05-14 10:29:44 +08:00
WeDone
33aeab41a3 test(zulip): 添加附件上传与发送修复的单元测试
修复现有 test_upload_uses_call_endpoint 测试(使用临时文件替代不存在的路径),新增测试覆盖:- _resolve_media_path: 本地路径直返、Zulip 路径缓存查找、Zulip 路径下载、完整 URL 解析、无效路径返回 None- _upload_and_send: 传递文件对象而非字符串、无法解析路径时跳过- send 元数据补全: 从 _recipient_map 补全缺失路由信息、已有元数据不被覆盖- send _tool_hint 过滤: tool_hint 消息被跳过、普通 progress 消息正常发送
2026-05-14 10:29:44 +08:00
WeDone
b46bdebe1b fix(zulip): 过滤 _tool_hint 进度消息避免重复发送
LLM 调用 message 工具时,agent loop 会先发送一条 _tool_hint 进度消息,然后 MessageTool 才发送真正的消息。配置中 send_tool_hints 默认为 False,但 _outbound_router 未检查该标志,导致 Zulip 通道将工具提示当作普通消息发送,产生重复且格式错误的文本。修复:在 send() 入口处过滤 _tool_hint 消息,直接返回不发送。
2026-05-14 10:29:44 +08:00
WeDone
4bab3a3483 fix(zulip): 用 _recipient_map 补全缺失的路由元数据,修复附件发送报错 Message must have recipients
MessageTool 创建的 OutboundMessage 只包含 message_id,缺少 msg_type/stream/topic/recipient_user_id 等 Zulip 路由字段,导致 _build_send_request 生成空收件人列表。

_recipient_map 在收到消息时已存储了完整的路由元数据,但从未被用于补全发送消息的元数据。

修复:在 send() 中,当 metadata 缺少 msg_type 时,从 _recipient_map 查找对应 chat_id 的路由信息并合并,确保发送消息时始终有正确的收件人。
2026-05-14 10:29:44 +08:00
WeDone
679ba6f36a fix(zulip): 修复附件重发时 Zulip 上传路径被当作本地文件路径
LLM 回复时可能使用消息内容中的 Zulip 上传路径(如 /user_uploads/...)
作为 media 参数,而非本地已下载的文件路径,导致 open() 报错 No such file or directory。

添加 _resolve_media_path 方法,在上传前将 Zulip 路径解析为本地文件:
- 本地路径直接存在则原样返回
- Zulip 上传路径(/user_uploads/...)或完整 URL 先查找已下载的本地副本
- 若本地不存在则从 Zulip 服务器重新下载
- 无法解析时记录错误并跳过
2026-05-14 10:29:44 +08:00
WeDone
6a4398f48e fix(zulip): 修复附件上传报错 'str' object has no attribute 'name'
Zulip Python 客户端的 call_endpoint 方法期望 files 参数接收文件对象列表(有 .name 属性),但代码错误地传入了文件路径字符串列表,导致附件上传时触发 AttributeError。

修复方案:在调用 call_endpoint 前使用 open() 打开文件,传递文件对象给 Zulip 客户端,确保 with 语句在使用完毕后正确关闭文件。

Closes #附件上传失败问题
2026-05-14 10:29:43 +08:00
whf
6195c22e86 Fix P1: Auto-advance learning stages on stage_end with retry logic, error handling, stale closure fixes 2026-05-14 10:18:48 +08:00
whf
a960c27761 Block 13: Remove guided_learning from chat CAPABILITIES selector and badge label 2026-05-14 05:33:55 +08:00
whf
14a7d07438 Block 12: i18n strings (en/zh) + error toast for learning pages 2026-05-14 05:31:34 +08:00
whf
92ae45e361 Block 10+11: Module list page with progress cards + learning-api client 2026-05-14 05:12:01 +08:00
whf
2620bf01b4 Block 9: ModuleTree nav component with mastery indicators, fetch progress from API 2026-05-14 04:20:33 +08:00
whf
c69a24e3de Block 8: WS client + StreamBus stage progress UI with stale closure fix (useRef) and XSS fix (remove dangerouslySetInnerHTML) 2026-05-14 03:10:54 +08:00
whf
2772cf647c Block 7: /learning route skeleton (page.tsx + [bookId]/page.tsx), Next.js build verified 2026-05-14 02:30:56 +08:00
whf
43973c7bc0 Block A: Fix _call_llm fail-open → fail-closed, raise on error, stage retries on failure 2026-05-14 00:39:04 +08:00
whf
1e02874ce2 fix: P1 move prompt imports to module scope, P2 format prompt templates with actual kp/module names 2026-05-13 22:04:24 +08:00
Bingxi Zhao (Frank)
1596807242 refactor chat capability & RAG pipeline(llamaindex) 2026-05-13 21:36:07 +08:00
whf
a8e154fc18 Block 5+6: 12 integration tests for LLM+RAG, 64/64 full regression, moved complete import to module level 2026-05-13 21:24:37 +08:00
whf
f761c34d29 Block 4: RAG retrieval via RAGService injected into system prompt before LLM call 2026-05-13 21:06:31 +08:00
whf
e65893feca Block 3: Structured prompt templates in deeptutor/learning/prompts.py, 11 stages with format() placeholders 2026-05-13 20:59:13 +08:00
whf
99fec2e51e Block 2: Replace _mock_llm() with real await complete() via DeepTutor LLM factory 2026-05-13 20:47:30 +08:00
whf
99798ade00 Block 1: LLM Factory API probe - module-level async complete()/stream() 2026-05-13 20:31:26 +08:00
unknown
ed9654a8b5 fix: address 7 confirmed security/code-quality audit findings (C2,C3,H1-H5) 2026-05-13 00:40:49 +08:00
whf
7193006cbd fix: 5 minor code quality improvements in guided_learning router
- Fix 1: Chinese comment → English
- Fix 2: Move late imports (PydanticValidationError, KnowledgePoint, LearningModule, HTTPException) to top-level
- Fix 3: Remove duplicate HTTPException imports in except blocks
- Fix 4: Document init_modules reset behavior for incremental module addition
- Fix 5: Add book_id validation to all 4 endpoints (+ colon per Codex review)

Codex-reviewed, 52/52 tests pass.
2026-05-12 23:35:53 +08:00
whf
7225eeb378 fix: restore guided_learning frontend UI integration lost in upstream merge 2026-05-12 22:27:04 +08:00