feat(adapt): ship sample novel and auto-run it on first visit - #59
Merged
Merged
Conversation
Switching scenes via the bottom prev/next links reset scrollTop to the cached value the browser happened to have — often partway down the previous scene's content, occasionally at 0 if the new content was shorter. Going back to an earlier scene lost any in-progress position; if the author was reading scene 3, jumped to scene 5 to fix a beat, and came back, scene 3 reappeared at the top. A Map<sceneId, scrollTop> on a ref captures the offset on every scroll tick (passive listener, no re-render). When activeSceneId changes, a second effect reads the saved value and sets scrollTop — or 0 if this is the scene's first visit. The browser clamps an oversized saved value automatically when the new scene's content height is smaller. The map lives on a ref scoped to the route instance; a new upload remounts the route, so positions reset without manual cleanup. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Existing layout put 修改指令 directly under the 原文 preview, then let the AI suggestion diff push the input button off-screen on small viewports. After a 5-beat conversation with the model, the author had to scroll back up to type the next instruction — exactly the opposite of the chat-app affordance the input was trying to be. Panel now has three regions: [Header — fixed top] [Scrollable context — 原文 + AI 建议结果] [Pinned input — 指令+chips OR speaker+textarea+save] The AI suggestion result moves into the scrollable region so the diff can grow as long as it needs without pushing the input down; the input stays anchored at the bottom in both AI and manual modes so the hands-to-keyboard distance is constant regardless of how the panel content has grown. Error banner sits in a thin strip between context and input — same rule of thumb as the Vercel/Linear input affordances: error stays adjacent to the action that produced it, not buried in scrollback. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Graders landing on /app got an excerpt of 朝花夕拾 in the textarea and an empty result panel — they had to click 生成草稿 to see the pipeline produce anything. That's a soft demo: the first impression is "yet another form" instead of "look at this draft screenplay we just adapted from a novel". Replaces the dropped-in Lu Xun excerpt with a self-contained five-chapter short story (《离镇》, 张三 + 李四) explicitly written to exercise the pipeline: - multiple characters with clear back-and-forth dialogue - explicit scene transitions (location + time jumps) - enough material per chapter for sliding-window chapter split - screenplay-friendly beats (action + parentheticals + slug lines) The full text lives in examples/sample_novel.md (canonical, human-readable) and is mirrored as a TS string in web/src/data/sample-novel.ts. The duplication is intentional: Vite's bundler root is web/, so importing across that boundary needs either a build step or a server.fs.allow workaround; an inline 15 KB string costs nothing and keeps the bundler config untouched. On first visit (localStorage flag SAMPLE_AUTORUN_KEY missing AND no saved draft) the route fires one adaptation against the sample so the result panel populates immediately. The flag is set after the run regardless of success, so a failed first attempt doesn't burn LLM quota on every reload. A new 加载示例 button next to 生成草稿 lets users explicitly replay the demo any time. 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.
功能描述
第一次访问 `/app` 落地体验从 "又一个表单" → "直接看到一份草稿剧本"。
旧行为:textarea 里塞了一段《朝花夕拾》节选,结果面板空着,用户必须自己点 `生成草稿` 才看到管道在干嘛。这对评委毫无演示力度。
实现思路
自带示例小说《离镇》:5 章短篇,张三 + 李四对话戏,刻意为管道五个 stage 量身打造:
文本 canonical 版放 `examples/sample_novel.md`(README 友好),同时镜像成 `web/src/data/sample-novel.ts` 的导出常量给前端 import。故意不走 `?raw` 跨包导入,避免改 Vite `server.fs.allow` 配置——15 KB 字符串成本可忽略。
首访自动改编:
显式重放:表单底部新增 `加载示例` 按钮,把状态重置成示例 + 立刻改编,用户随时可看演示。
测试方式
依赖与复用声明
无新增第三方依赖。复用:
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com