From fbadf6f85855498229f853f64bcc5e4a9a29aef9 Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Fri, 20 Nov 2026 09:18:04 +0800 Subject: [PATCH] fix: keep loaded tool output when the tail page only has its shell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List responses ask the server to elide large tool output (`x-openchamber-part-shells: v1`): the part comes back as an empty text plus an `openchamberContentShell` marker, and the full text is fetched when a step is expanded. Every tail refresh (a turn starting, the app returning) then replaced the loaded message with that shell again, so an expanded step fell back to "无输出" — the more the session was used, the more it looked like shell steps never had output. reloadTail now keeps an already-loaded tool part when the server's copy of that part is a shell (matched by position and call id), and the pending state reads "输出较大,正在载入…" instead of claiming there was no output. Version 0.3.7 (code 307). --- PLAN.md | 12 ++++++++++ README.md | 2 +- lib/screens/chat_screen.dart | 10 +++++++- lib/state.dart | 46 +++++++++++++++++++++++++++++++++++- pubspec.yaml | 2 +- 5 files changed, 68 insertions(+), 4 deletions(-) diff --git a/PLAN.md b/PLAN.md index fbdfe5d..98e95dd 100644 --- a/PLAN.md +++ b/PLAN.md @@ -27,6 +27,18 @@ --- +## 0.3.7 工具输出被“壳”覆盖(分支 `flutter`) + +| 项 | 结果 | +| --- | --- | +| 现象 | 会话列表接口带 `x-openchamber-part-shells: v1` 时,大一点的工具输出只给一个空壳:`content:[{type:'text',text:''}]` + `metadata.openchamberContentShell`。展开步骤时客户端会单条拉完整消息(`/message/:id`,不带壳),输出就出来了 | +| 根因 | 每次 `reloadTail()`(每轮 `execution.started`、回到前台等)都用**带壳**的列表覆盖本地消息,把刚加载出来的输出又盖回空壳,于是展开着的那一步变回「无输出」——看起来就像“始终无输出” | +| 修复 | `reloadTail` 合并消息时,如果服务端给的是壳、本地这一条已经加载过完整内容,就保留本地那条(按 part 顺序与 call id 对齐),不再降级;真没有输出的命令仍然显示「无输出」 | +| 提示 | 壳还没加载完时不再显示「无输出」,而是「输出较大,正在载入…」 | +| 版本 | **0.3.7(code 307)** | + +--- + ## 0.3.6 斜杠指令与错误显示(分支 `flutter`) | 项 | 结果 | diff --git a/README.md b/README.md index 7c8811c..4674e88 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Android first. This branch (`flutter`) is a framework evaluation: the same feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in Flutter to compare mobile UI maturity. -Status: 0.3.6 — servers (passwordless / password login, HTTP/HTTPS and +Status: 0.3.7 — servers (passwordless / password login, HTTP/HTTPS and SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live events, chat with streaming Markdown and full history paging, tool steps grouped per turn (icon, one-line summary, foldable run) with image previews, a diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index 3e7a717..0e34da2 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -770,6 +770,10 @@ class _ChatScreenState extends State { final shell = _isShell(p); final command = shell ? '${input['command'] ?? ''}'.trim() : ''; final output = toolOutput(p); + // A big output arrives as an empty shell until the message is fetched; + // that is not the same as a command that printed nothing. + final shelled = shell && + (p.state?.metadata?.containsKey('openchamberContentShell') ?? false); const mono = TextStyle(fontSize: 12, height: 1.45, fontFamily: 'monospace'); return Padding( padding: const EdgeInsets.fromLTRB(10, 2, 10, 8), @@ -796,7 +800,11 @@ class _ChatScreenState extends State { ), if (extras.isNotEmpty) const SizedBox(height: 4), SelectableText( - output.isEmpty ? (shell ? '无输出' : '无内容') : output, + output.isNotEmpty + ? output + : shelled + ? '输出较大,正在载入…' + : (shell ? '无输出' : '无内容'), style: mono.copyWith( color: p.state?.error != null ? theme.colorScheme.error diff --git a/lib/state.dart b/lib/state.dart index 10e8010..9185397 100644 --- a/lib/state.dart +++ b/lib/state.dart @@ -602,6 +602,46 @@ class ChatState extends ChangeNotifier { return null; } + /// A page keeps large tool outputs out (`x-openchamber-part-shells`); the + /// message itself still carries them. Such a part reads as an empty text. + static bool _shelledPart(ContentPart p) => + p.type == 'tool' && + (p.state?.metadata?.containsKey('openchamberContentShell') ?? false); + + /// The server's copy of a message, except that a tool output already loaded + /// in full is kept: taking the shell back would turn the step's output into + /// "无输出" again on the next tail refresh. + static Message _keepLoadedOutput(Message local, Message server) { + if (!server.content.any(_shelledPart)) return server; + final parts = []; + for (var i = 0; i < server.content.length; i++) { + final s = server.content[i]; + final l = i < local.content.length ? local.content[i] : null; + final loaded = l != null && + l.type == 'tool' && + l.id == s.id && + (l.state?.content.any((c) => c.text.isNotEmpty) ?? false); + parts.add(_shelledPart(s) && loaded ? l : s); + } + return Message( + id: server.id, + type: server.type, + created: server.created, + completed: server.completed, + agent: server.agent, + model: server.model, + content: parts, + text: server.text, + files: server.files, + finish: server.finish, + cost: server.cost, + tokens: server.tokens, + error: server.error, + status: server.status, + reason: server.reason, + ); + } + /// Refreshes the newest page without dropping the older pages that were /// already loaded; the server's copy wins for messages it returns. Future reloadTail() async { @@ -612,7 +652,11 @@ class ChatState extends ChangeNotifier { } else { final fresh = {for (final m in page.data) m.id: m}; final merged = [ - for (final m in msgs) fresh.remove(m.id) ?? m, + for (final m in msgs) + switch (fresh.remove(m.id)) { + final Message s => _keepLoadedOutput(m, s), + null => m, + }, for (final m in page.data) if (fresh.containsKey(m.id)) m, ]; diff --git a/pubspec.yaml b/pubspec.yaml index 1189161..27da456 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: openchamber description: "A lightweight OpenChamber client for phones." publish_to: 'none' -version: 0.3.6+306 +version: 0.3.7+307 environment: sdk: ^3.14.0