Repository navigation
feat(chat): 流式配速 + 就地编辑重发 + 单入口回退(0.4.14–0.4.16) - #12
Merged
CjiW merged 3 commits intoNov 3, 2026
Merged
Conversation
流式输出时文字一阵一阵地蹦,是「到达节奏」直接决定的;调小合批窗口只会让块更小更频繁。 这里的做法参考 Paseo 移动端(agent-stream/text-reveal.ts): - ui/TextReveal.kt: 到达只更新目标长度,显示速率由积压反推 (每帧 backlog*elapsed/150ms,至少 1 字);首次整段、结束 snap; 切点按字素簇回退,emoji/组合字符不闪半字形; 按稳定块边界切 head+tail,每帧只重解析短 tail - chat/EventBatcher.kt: SSE 事件 leading + 60ms trailing 合批, 一批事件在一个 _state.update 里 fold 完,不再每 token 重组 - ChatScreen: 内容增长时按 layout deficit 粘底(配速时最后一行不被压住) - 单测:TextRevealTest 17 + EventBatcherTest 7,全量 108 个通过 - docs/agent/streaming.md 记录整条链路与「不要做的事」
旧流程是「先回退(等接口 + 重载历史)→ 再把草稿塞回输入框 → 才能打字」,中间那段空白 用户只能干等。改成先输入、确认后才回退: - 每条用户消息下方新增「编辑」按钮(canRewindTurn 判定:有历史 id、正文非空、 没有回合在跑、不在回退中) - EditMessageDialog:预填原文、自动聚焦;点「确定并重新发送」才发起 rewind - ChatViewModel.rewindAndResend(): rewind → 等历史整体重载落地 → 再 send, 避免新消息挂在旧列表上、SSE 回声多出一条 - ChatUiState.rewinding:回退期间禁用所有编辑入口 - 新增 ui/RewindRules.kt(纯函数)+ RewindRulesTest 5 个用例;全量 113 个测试通过 - docs/agent/chat.md 补「两条入口 + 顺序为什么不能换」
… (0.4.16) - 删掉顶栏「回退」对话框(RewindDialog.kt / rewindMessage / History 按钮):入口只保留 用户消息下方的「编辑」,两个入口只会让文案和状态各说一套话 - 编辑对话框新增「仅回退」:只截断历史、不重新发送,编辑后的文字回填到输入框 - rewindAndResend → rewindTo(historyId, text, resend):resend=false 时把文字放进 ChatUiState.draft,UI 回填输入框后 consumeDraft() 清空 - docs/agent/chat.md 更新为单入口 + 两个动作
CjiW
deleted the
agent/peer/reveal-batch/paced-text-reveal-plus-sse-eve
branch
November 3, 2026 02:30
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.
概述
三个面向"手感"的改动:
1. 配速显示 + 事件合批(0.4.14)
借鉴 getpaseo/paseo 移动端:
agent-stream/text-reveal.ts、docs/agent-stream-performance.md、timeline/session-stream-reducers.ts。ui/TextReveal.ktcomputeRevealStep(backlog, elapsedMs)每帧推进backlog * elapsed / 150ms(向上取整、至少 1 字)。revealed初值text.length,streaming = false立刻显示全文 —— 历史消息、重挂载无需特判。stableBlockBoundary,避开未闭合 ``` 围栏):head 只在整块写完时变,命中MarkdownText内部的 `remember(text)`;每帧只重解析短 tail。chat/EventBatcher.ktFlow<T>.batchByWindow(windowMs = 60, maxBatch = 64):leading + trailing。窗口里第一条立刻发(否则每回合首字多等一个窗口),随后最多再攒 60ms;ChatViewModel把一批事件在一个_state.update里fold完。配套:内容增长时粘底(
ChatScreen)配速让正文每帧长一点,靠"尾部指纹变化"触发贴底会滞后一个合批窗口。新增盯
layoutInfo的 effect:跟随状态下按deficit单次scrollBy;isScrollInProgress为真(用户手势)立即停手。2. 就地编辑重发(0.4.15)
旧流程:顶栏「回退」→ 选消息 → 等 rewind + 历史重载 → 草稿回到输入框 → 才能改 → 发送。中间那段空白用户只能干等。
canRewindTurn():持久化历史 id、正文非空、无回合在跑、不在回退中)。EditMessageDialog:预填原文、自动聚焦;改完点「确定并重新发送」才发起回退。ChatViewModel.rewindTo(...):rewindHistory→ 等历史整体重载落地 → 再决定发不发。先发再重载会让新消息挂在旧列表上、SSE 回声多出一条;不重载直接发则看起来像"消息发丢了"。
ChatUiState.rewinding置位,禁用所有编辑入口,避免连锁回退。3. 单入口 + 仅回退(0.4.16)
RewindDialog、rewindMessage、History 按钮):两个入口只会让文案和状态各说一套话。ChatUiState.draft回填输入框(UI 消费后consumeDraft()),用户再决定发不发。提交清单
77ad9bc2ea36d37b6dc98验证
TextRevealTest17 个:步长(积压/时长/上限/horizon=0)、字素安全切点(代理对/组合音标/ZWJ 家庭 emoji)、稳定块边界(空行、围栏内外)EventBatcherTest7 个:leading 立即发、突发合成 trailing 批、跨窗口拆分、maxBatch 切分、顺序与零丢失、批次数收敛RewindRulesTest5 个:历史 id / 空正文 / 回合运行中 / 回退中:app:lintVitalRelease、:app:assembleRelease通过说明
ChatReducer)仍存全文,配速只作用于渲染切片 —— 复制、选中、滚动几何和屏幕一致。BottomAnchorController(请求枚举 + post-layout 校验)、加 Compose UI 回归用例(Maestro)。关联
docs/agent/streaming.md(链路 + 「不要做的事」)、更新docs/agent/chat.md(单入口 + 两个动作)