Repository navigation
feat(composer): compact input row and show the context budget - #8
Merged
Merged
Conversation
The input row was ~72dp tall on its own: Material3's OutlinedTextField pins its decoration box to TextFieldDefaults.MinHeight (56dp), and the icons kept their 48dp touch size. Every pixel there is a pixel the transcript loses. Render the field with BasicTextField plus our own rounded background so the row is ~36dp, and shrink the icon buttons to 36dp with 20dp glyphs. The freed space pays for a context-budget indicator: a 14dp arc plus the percentage, sitting left of the send button and turning amber at 60% and red at 85%, with a tap-through dialog showing prompt tokens, the context cap and the model. The data comes from POST /api/session/status, which the client never called: TokenUsage now carries available/max_context_tokens/usage_percent/model, and ChatReducer.withContextBudget keeps the server's percentage authoritative while hiding the indicator entirely until the server has real token counts (available=false on a fresh session, so no misleading 0%). Progress events only carry prompt_tokens, so withLiveTokenUsage estimates against the cap from the last status call and leaves the value alone when the cap is unknown.
Two traps worth not rediscovering: Material3's OutlinedTextField pins a 56dp minimum inside its decoration box so height has to come from BasicTextField, and the only real context-budget source is /api/session/status (progress events carry prompt tokens but no cap).
versionCode 17 is above the 0.3.3 (16) build that is already installed on the test device, so the composer work can be sideloaded and picked up by the in-app updater. The 0.3.4 entry also covers the indicator's data contract: no percentage until the server has real token counts.
A ring plus a percentage inside the input row cost ~45dp of horizontal space and still made the reader do the division. Print the ratio instead, right-aligned on its own line above the field: 85K/200K. It only exists when the server has real token counts, so an empty session keeps the composer at its compact height. versionCode 18: the 17 build of 0.3.4 is already on the test device, and Android refuses a downgrade.
Right-aligning it put the number in the corner furthest from the text being typed; centred it reads as a caption for the whole input row. versionCode 19: 18 is already on the test device.
The server already sends work_dir on every chat and cwd in session status, but neither reached the UI, so two chats on the same server looked identical until you opened them. Session rows put the path on the time line (weight 1f + ellipsis, so the card never grows); the chat screen prints it next to the context budget above the composer. Both use PathText, which keeps the tail of the path installed of the head: right-truncation would cut the leaf directory that actually identifies the workspace. ChatUiState.cwd is fed from session status (blank keeps the previous value) and from progress events, which can carry a new cwd mid-turn. versionCode 20.
The server's protocol.HistoryRewindResult declares both flags as bool, but RewindResponse typed them as Int. kotlinx.serialization therefore threw "Unexpected symbol 't' in numeric literal at path: $.data.files_rewound" on a rewind that had already succeeded server-side -- the user saw a JSON parse error and no rewind dialog feedback at all. Type them as Boolean and report the two outcomes separately: history not truncated is a real failure, while files_rewound=false with a non-blank checkpoint_error means the history moved but the file snapshot did not. The full "已回退" message used to hide that difference. Adds RewindResponseTest with the exact payload captured on device, plus a failed-rewind case. A sweep of every bool json tag in protocol/ against the client models found no other bool-as-Int mismatches. versionCode 21.
reload() merged the newest page into the existing turns whenever the chat already had history, and mergeLatestHistory only ever adds: turns the server no longer returns survive. After a rewind the truncated messages therefore stayed on screen until the chat was reopened, because open() resets the state and takes the replacing path. Add reload(replaceTurns): the rewind success handler and the server's history_rewound session event now ask for a replacing reload, while ordinary reloads (reconnect, resync) keep merging so pages loaded by scrolling up are preserved. The flag travels through ChatUiState.reloadReplacesHistory because needsReload alone is also used by resync_required, which must merge. Tests pin both behaviours: withHistory drops the removed turn, mergeLatestHistory keeps it (the old bug), and the session event sets both flags. versionCode 22, plus docs/agent/chat.md on the two history paths.
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.
目标
输入区占的高度全是从对话正文里抢来的;腾出来的空间放在输入框上方,用一行居中的小字显示工作目录与上下文占用(如
📁 ~/xbot-android · 85K/200K)。输入区压缩:约 72dp → 约 48dp
OutlinedTextField(装饰盒内固定 56dp 最小高度)BasicTextField+ 自绘圆角背景/边框/占位符,单行 ≈36dph 10dp v 8dp、spacedBy 4dph 8dp v 6dp、spacedBy 2dpM3 的
OutlinedTextField把TextFieldDefaults.MinHeight(56dp)写在装饰盒内部,外面套Modifier.height()/defaultMinSize()只会裁掉内容 —— 想真正压低必须换BasicTextField。上下文预算:输入框上方居中一行文字
居中显示
已用输入/上下文上限(formatTokens压成 K/M,上限未知时右半是—),点击弹出明细(已用输入 / 上下文上限 / 当前占用 / 模型)。<60%常规次要文字色,60%~85%琥珀,>=85%error。POST /api/session/status(客户端此前从未调用)→token_usage.max_context_tokens / usage_percent。available == false(新会话,服务端还没有真实 API token 数)→ 这一行整个不存在;usage_percent→ 以它为准;prompt_tokens、没有上限 → 用上次 status 的上限估算,弹窗标注「回合进行中估算」;上限未知时保持不动。reload()成功后、SSE 中busy由 true 转 false 时。工作目录
服务端本来就给了
work_dir(会话列表)和cwd(session status / progress),但客户端从没显示过 —— 同一台服务器上的多个会话看起来一模一样。weight(1f, fill = false)+ 省略号,卡片高度不变。ui/components/PathText.kt:Icons.Outlined.Folder+shortenPath(),^/(home|Users|root)/<user>/→~/,段数过多时只留最后两段并加…/—— 路径尾巴才是有信息量的部分,Compose 默认的右截断会把目录名切掉。ChatUiState.cwd由 session status(空值保留旧值)与 progress 事件(回合中可变)共同维护。顺带修复:Rewind 一直失败
真机上报
Unexpected symbol 't' in numeric literal at path: $.data.files_rewound。服务端
protocol.HistoryRewindResult里history_rewound/files_rewound是 bool,客户端模型声明成了Int—— 回退在服务端已经成功,客户端却在反序列化阶段抛异常,用户既看不到成功也看不到文件结果。
Boolean;history_rewound=false是「没生效」,files_rewound=false+checkpoint_error非空是「历史回退了但文件快照没恢复」,不再用一句「已回退」盖掉;RewindResponseTest(真机原始 payload + 失败场景);顺手用脚本比对了protocol/里 31 个 bool json tag,没有其他同类错配。第二轮(真机反馈):回退后消息不消失。 服务端已删除的 turn 之所以还留在屏幕上,是因为
reload()在会话已加载时无条件走合并分支,而
mergeLatestHistory只增不减;open()会重置 state 才「看起来好了」。reload(replaceTurns)增加替换语义;Rewind 成功回调与 SSEsession.action == "history_rewound"都走替换,普通重载(重连 / resync)继续合并,保住上滑加载的旧页;
ChatUiState.reloadReplacesHistory传递 —— 不能复用needsReload,resync_required也用它且必须合并;docs/agent/chat.md说明两条历史路径;单测同时钉住「替换会丢」与「合并会留」两种行为。验证
./gradlew :app:testDebugUnitTest✅ —ChatReducerTest23 个用例 +RewindResponseTest2 个用例 + 3 个「历史装载」用例(上下文预算 6、cwd 3、rewind 2、reload 语义 3)./gradlew :app:lintDebug✅./gradlew :app:assembleRelease✅(签名CN=xbot)https://minio.cjiw.site/uploads/share/android/xbot-android-22.apk(versionCode 22 / 0.3.4,sha256
6e613d46…,公网回拉校验一致)版本号
本 PR 顺带把版本推到 0.3.4(versionCode 20)。同一版本的 trial 包 17/18/19 已在测试机上迭代过,
Android 不允许降级,所以每次都要往上加。如果不想让功能 PR 带版本号,可以摘掉
14de4ca这个 commit,发版时再统一改。文档
docs/agent/ui-composer.md:OutlinedTextField的 56dp 陷阱、上下文预算的数据来源与三种口径、cwd 的来源与显示位置。