DeepTutor icon indicating copy to clipboard operation
DeepTutor copied to clipboard

[Feature Request]:Post-generation book structure editing + AI-assisted content authoring from the page chat

Open zhiyuan8015 opened this issue 3 weeks ago • 3 comments

Do you need to file a feature request?

  • [x] I have searched the existing feature request and this feature request is not already filed.
  • [x] I believe this is a legitimate feature request, not just a question or bug.

Feature Request Description

english: Two related capabilities are missing from the Book module. Both target the same user problem: the book is generated once, but real learning changes what the book needs to contain.

1. Edit the book structure after generation

Once a book has been generated and its spine confirmed, there is currently no way to add, remove, or insert chapters or sections (pages) without discarding the book. In the 1.7.2 data model the hierarchy is Chapter → Page (section) → Block. Today:

  • POST /books/confirm-spine accepts an edited spine, so chapters can only be adjusted before generation.
  • After generation, only block-level operations are available (insert-block, delete-block, move-block, update-block, change-block-type, regenerate-block).
  • POST /books/rebuild preserves the spine but discards and recompiles every page.

What we need is chapter/section mutation after generation, without rebuilding the book and without losing already-compiled content:

  • add a chapter at a chosen position; rename, reorder, delete a chapter;
  • add a section (page) under a chapter; rename, reorder, delete a section;
  • newly added pages compile on demand; existing pages remain untouched.

2. Let the page-level AI chat modify the book it is discussing

The page chat can explain, discuss, and answer questions about the currently open chapter, but it cannot write back to the book. After several turns of discussion, the conclusion often is "this section should exist" or "this page needs an extra block" — yet the chat has no way to apply it.

We would like the page chat to support AI-assisted authoring with explicit user control:

  • the agent can propose an edit (add a section, insert a block, extend a section) based on the conversation;
  • the proposal is shown as a diff/preview and is applied only after the user confirms (or with an explicit "allow edits for this book" toggle);
  • applied edits are revisioned and undoable, scoped to the current book/page.

The two parts complement each other: structure editing gives the user a manual path, and chat-driven authoring gives a natural-language path for the same operations.

Chinese: Book 模块缺少两项相关能力,它们指向同一个问题:书籍只生成一次,但真实的学习过程会改变书籍应当包含的内容。

1. 生成后仍可编辑书籍结构

书籍生成并确认 spine 之后,目前无法在不丢弃整本书的前提下新增、删除或插入章节/小节(page)。1.7.2 的数据模型是 Chapter → Page(小节)→ Block。现状:

  • POST /books/confirm-spine 支持传入编辑后的 spine,因此章节只能在生成前调整;
  • 生成后只支持 block 级操作(insert-block、delete-block、move-block、update-block、change-block-type、regenerate-block);
  • POST /books/rebuild 会保留 spine,但丢弃并重新编译所有页面。

需要的是生成之后的章节/小节增删改,且不重建整本书、不丢失已生成内容:

  • 在指定位置新增章节;重命名、调整顺序、删除章节;
  • 在章节下新增小节(page);重命名、调整顺序、删除小节;
  • 新增页面按需编译,已有页面保持不变。

2. 页面级 AI 聊天可以修改它正在讨论的书籍

当前页面聊天可以解释、讨论、回答当前章节的问题,但无法把结论写回书籍。多轮讨论后,结论经常是"这里应该有一节"或"这一页需要补充一个 block",而聊天没有权限落实它。

希望页面聊天支持有明确用户控制的 AI 辅助创作:

  • 智能体可以基于对话提出编辑方案(新增小节、插入 block、扩写某一节);
  • 方案以 diff/预览形式展示,用户确认后才应用(或通过"允许编辑本书"的显式开关);
  • 所有改动都有版本记录、可撤销,且仅限当前书籍/页面。

两者互补:结构编辑给用户手动路径,聊天驱动创作给同一批操作提供自然语言路径。

Related Module

Notebook

Use Case

english: Scenario A — beginner discovers a gap after studying.

A beginner does not know the subject well enough to judge an auto-generated outline. After studying a few chapters, they realise an important prerequisite topic is missing, or that one chapter needs an extra section for a concept they kept struggling with. Rebuilding the book is not acceptable because it discards the progress, notes, and content already generated. The user wants to insert a chapter or section in place and keep everything else.

Scenario B — knowledge is clarified through multi-turn discussion.

Many deep concepts only become precise after several rounds of dialogue with the agent. Today the chat can explain the concept but cannot persist the conclusion into the book. The user has to manually copy the conclusion into an editor, or rebuild the chapter and lose the discussion context. The user wants the agent to turn the agreed-upon conclusion into a section or block in the current chapter, with a confirmation step.

chinese: 场景 A——初学者学习后才发现内容缺口。

初学者对学科本身不熟悉,无法准确判断自动生成的大纲是否合适。学习几章之后,才发现缺少某个重要的前置主题,或者某一章需要为反复卡住的概念补一节。此时重建整本书是不可接受的,因为会丢弃已有进度、笔记和已生成内容。用户希望就地插入章节或小节,其余内容保持不变。

场景 B——知识在充分讨论后才变得清晰。

很多深刻的概念需要与智能体多轮对话后才能明确。当前聊天可以解释概念,却无法把结论持久化到书籍中。用户只能手动复制,或者重建章节并丢失讨论上下文。用户希望智能体把讨论后的结论变成当前章节中的一节或一个 block,并且在应用前确认。

Additional Context

english: Proposed behavior (for discussion, not prescriptive)

  • New endpoints, mirroring the existing block CRUD style:
    • POST /books/{book_id}/chapters, PATCH/DELETE /books/{book_id}/chapters/{chapter_id}, POST /books/{book_id}/chapters/{chapter_id}/move
    • POST /books/{book_id}/chapters/{chapter_id}/pages, PATCH/DELETE /books/{book_id}/pages/{page_id}, POST /books/{book_id}/pages/{page_id}/move
    • all mutations accept expected_revision (the field already exists on book mutation requests).
  • Page chat gains a scoped write toolset exposed only while the user is in that book, with a confirmation UI before applying changes.
  • New pages start as pending shells and compile on demand; existing pages are not recompiled.
  • Every AI-originated change records its source turn/message id for traceability.

chinese: 建议行为(供讨论,非强制)

  • 新增接口,风格与现有 block CRUD 保持一致:
    • POST /books/{book_id}/chapters、PATCH/DELETE /books/{book_id}/chapters/{chapter_id}、POST /books/{book_id}/chapters/{chapter_id}/move
    • POST /books/{book_id}/chapters/{chapter_id}/pages、PATCH/DELETE /books/{book_id}/pages/{page_id}、POST /books/{book_id}/pages/{page_id}/move
    • 所有变更接受 expected_revision(该字段在现有书籍变更请求中已存在)。
  • 页面聊天获得一个受限的写入工具集,仅在该书籍上下文中可用;应用修改前弹出确认界面。
  • 新增页面以 pending 空壳开始,按需编译;不重新编译已有页面。
  • 所有由 AI 发起的修改记录来源对话轮次/消息 id,便于追溯。

zhiyuan8015 avatar Nov 09 '26 15:11 zhiyuan8015

I'd like to take this on, targeting dev.

The gap matches your description exactly: on current dev, deeptutor/api/routers/book.py exposes only block-level mutations (insert-block / delete-block / move-block / update-block / change-block-type / regenerate-block), plus confirm-spine (pre-generation) and rebuild (discards and recompiles every page). There is no chapter/section mutation after generation.

Since this is a sizable feature, I'd propose to deliver it incrementally so each PR stays reviewable:

Slice 1 — post-generation chapter CRUD. POST /books/{book_id}/chapters, PATCH/DELETE /books/{book_id}/chapters/{chapter_id}, POST /books/{book_id}/chapters/{chapter_id}/move, mirroring the existing block-CRUD handlers and honoring expected_revision for optimistic concurrency. New chapters start as empty shells; existing compiled pages are never recompiled or discarded. Covered by API + engine tests (revision conflict, reorder stability, delete-with-compiled-pages preservation).

Follow-ups: section/page CRUD under a chapter, then the scoped page-chat write toolset with the confirmation UI and per-change source-turn traceability.

This keeps the data model and the expected_revision contract unchanged and reuses the existing mutation patterns rather than adding a new path. If you'd prefer a different sequencing — or want the page-chat authoring first — I'm happy to adjust before starting.

ZQR1101 avatar Nov 11 '26 07:11 ZQR1101

Thank you for your prompt reply! Currently, I have solved this problem by exporting the generated books to the local storage, thereby enabling the AI agent to participate in the subsequent improvement of the data. At present, I'm not in a hurry. You can assess and proceed with the development on your own. I wish you a successful development process. I hope these features can be implemented as soon as possible. Also, just a side note: If you want to add a new chapter and have the AI generate the content, you can consider following the steps of "first asking about the learning objective, then listing the generation plan" (consistent with pre-generated books), with the aim of ensuring that the output content style is consistent with the previous text. Finally, once again, I would like to express my gratitude for your work.

zhiyuan8015 avatar Nov 11 '26 08:11 zhiyuan8015

Fixed on local dev (8ab4ecfee91df1ca347c88eeb66f22664b840651). feat(books): review and undo scoped chapter and section edits. Chapter/section CRUD via preview and explicit apply; new sections compile on demand, existing content preserved including spine reconfirmation. Scoped propose_book_edit never applies changes. Revision fences, source-turn trace, latest unchanged edit undo and rollback journal tested. Focused 451 Python tests and 9 UI tests passed; typecheck, contracts, i18n and ESLint passed.

will be fixed in the next releases!

pancacake avatar Nov 14 '26 17:11 pancacake