fix(adapt): sync edits from /editor back into the result panel - #61
Merged
Merged
Conversation
The editor's only download was the schema YAML — useful for the pipeline contract, useless for directors and actors. Adds an end-to-end export path so the author leaves with a file the rest of the team can read. Backend: new story2script.export package with three pure renderers (to_fountain, to_txt, to_markdown), wired to POST /api/v1/export. The endpoint runs the same schema validator the YAML download relies on, so a broken draft surfaces as 422 with field-level errors instead of a half-rendered file. PDF is intentionally NOT a server format — generating CJK-safe PDFs needs either weasyprint+GTK or a 5 MB bundled font; the frontend opens the Markdown variant in a print-friendly window and lets the browser's native Print → Save as PDF do the conversion. Zero new server dependencies. Frontend: the toolbar's 导出 YAML button becomes a 导出剧本 dropdown with five options (Fountain / txt / md / PDF / raw YAML). PDF reuses the markdown response, rewraps it in an inline HTML template with CJK system fonts, and triggers window.print() after load. Error messaging surfaces 422 schema details so the author knows which field to fix in the editor. Tests: 25 new (8 fountain, 4 txt, 7 markdown, 6 endpoint), covering character cue casing, parenthetical split, transition normalization, mode block presence, invalid YAML / invalid screenplay / unknown format error paths. Full suite 314 passing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Returning to /app after editing in /editor showed a stale result — the screenplay_yaml in the React state still reflected the original LLM output even though the editor had patched sessionStorage with every keystroke. Two real consequences: - Exporting via PR #60's new dropdown would have produced the PRE-edit Fountain / Markdown / etc., silently discarding all the author's manual fixes. - Schema validation and quality metrics displayed the LLM's draft state, not what the author was about to ship. Strategy: on mount AND on tab focus / visibility change, diff the editor's draft against the result.screenplay_yaml. When they differ, swap the YAML in and re-run /api/v1/validate so schema_validation reflects current state. Quality metrics intentionally stay frozen since they describe how the LLM produced the draft, not whether the author's hand-edits are still valid. The validate call's failure path falls through to a YAML-only swap so the export button still reflects current edits when the backend is down; the eventual /export call will surface the same errors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
功能描述
修隐藏的数据双源 bug:从 Editor 改完回到 Adapt,之前你看到的 YAML 是旧的——LLM 第一次生成的版本,作者所有的手动修改都不反映。
后果两个:
实现思路
Adapt mount + tab focus / visibilitychange 三个时机各跑一次同步:
```
```
quality_metrics 故意不更新——它描述的是 LLM 怎么生成的草稿(章节数、AI stage 应用情况、置信度均值),跟手动改无关,刷它会误导。
validate 调用失败时回退到只换 YAML,导出按钮还是反映当前 YAML;后续 /export 端点会重新报 schema 错误。
监听 `window.focus` 和 `document.visibilitychange`——React Router 切换路由不会重 mount 已渲染的页面,所以光靠 mount effect 不够;focus 事件覆盖"切 tab 回来",visibilitychange 覆盖"标签页隐藏后切回"。
测试方式
人眼验证:
依赖与复用声明
无新增依赖。复用:
依赖 PR #60(导出剧本)——没那个的话双源 bug 只是显示问题,有了导出就成了真问题。所以两个 PR 同期推。
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com