feat: tool steps as foldable runs with icon, label and summary

The old rows ("已思考 ▸", "✓ shell ▸") said nothing about what a step did
and could only be expanded one at a time.

- A turn is one or more assistant messages (the server writes a message
  per step), so grouping per message produced a header for every step.
  Rows are now grouped per turn: one "已完成 · N 次工具调用" header, split
  where the reply has text. Header shows running/complete/failed, and the
  whole run folds away.
- Every step shows a rounded icon for its kind (thought, shell, read,
  write, edit, patch, search, fetch, task, skill), its label and a
  one-line summary: the command, the file path, the pattern, the URL, the
  skill id, and so on.
- A step opens to its reasoning text or the tool's input and output;
  image references stay listed and clickable.
- A lone thought needs no header; a reasoning-only run reads "思考过程".
- Version 0.3.3 (code 303).
This commit is contained in:
blumia committed 2026-11-19 14:58:18 +08:00
1 parent 61977d2b14
commit 2baa0a2730
4 files changed
+424 -106

No files matched your search

+14
View File
@@ -27,6 +27,20 @@
--- ---
## 0.3.3 工具调用展示(分支 `flutter`)
| 项 | 结果 |
| --- | --- |
| 为什么要改 | 旧版每个 reasoning/tool part 只显示一行「已思考 ▸ / ✓ shell ▸」,既没有概要也不能整组收起,长回合里几乎不可读 |
| 分组依据 | 服务端每个 step 各写一条 assistant 消息,所以按**消息**分组会得到「5 组」;现在按**回合**(连续的 assistant 消息)分组,`text` 分隔出新的组。与 dsh-Go 一致:一组一个「已完成 · N 次工具调用」表头 |
| 表头 | 左侧状态图标(进行中转圈 / 完成对勾 / 失败警告),「已完成 · N 次工具调用」/「执行中 · …」/「有步骤失败 · …」;只有一个思考步骤时不显示表头,直接显示「思考」行;纯思考的组显示「思考过程」 |
| 每行 | 26px 圆角图标 + 名称 + 「· 概要」+ 展开箭头;图标按工具类型(思考=psychology、运行=terminal、读取=description、写入/编辑/补丁、搜索、抓取、任务、技能…),未知工具用工具名 |
| 概要 | bash=命令、read/write/edit=文件路径、grep/glob=模式、webfetch=URL、task=描述、skill=id,其余取 description/path/command/query/url/pattern/name/id,再退化为紧凑 JSON |
| 展开 | 单行展开后显示推理全文或工具的 input/输出(等宽、可选中);图片引用仍以 🖼 行列出,点击预览 |
| 版本 | **0.3.3(code 303)** |
---
## 0.3.2 修复(分支 `flutter`) ## 0.3.2 修复(分支 `flutter`)
| 项 | 结果 | | 项 | 结果 |
+7 -6
View File
@@ -5,13 +5,14 @@ Android first. This branch (`flutter`) is a framework evaluation: the same
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
Flutter to compare mobile UI maturity. Flutter to compare mobile UI maturity.
Status: 0.3.2 — servers (passwordless / password login, HTTP/HTTPS and Status: 0.3.3 — servers (passwordless / password login, HTTP/HTTPS and
SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live
events, chat with streaming Markdown and full history paging, tool rows with events, chat with streaming Markdown and full history paging, tool steps
image previews, a context usage ring with a detail sheet, model/agent grouped per turn (icon, one-line summary, foldable run) with image previews, a
switching (Build/Plan only, current one checked), copy / fork / revert, context usage ring with a detail sheet, model/agent switching (Build/Plan only,
attachments (photos/files), permissions. Android 7.0 (API 24)+, plus a Linux current one checked), copy / fork / revert, attachments (photos/files),
desktop target used for local testing. permissions. Android 7.0 (API 24)+, plus a Linux desktop target used for local
testing.
## What is here ## What is here
+402 -99
View File
@@ -34,6 +34,10 @@ class _ChatScreenState extends State<ChatScreen> {
List<_Attach> _attachments = []; List<_Attach> _attachments = [];
bool _attaching = false; bool _attaching = false;
/// Assistant turns show their reasoning/tool parts as a run of steps; the
/// header of each run folds it away (key: message id and start part).
final Set<String> _collapsedSteps = {};
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@@ -173,19 +177,15 @@ class _ChatScreenState extends State<ChatScreen> {
out.add(_Row('useractions', m.id, -1)); out.add(_Row('useractions', m.id, -1));
break; break;
case 'assistant': case 'assistant':
if (m.content.isEmpty && m.completed == 0) { // A turn is one or more assistant messages: the server writes a
out.add(_Row('thinking', m.id, -1)); // message per step, so the whole turn is shown as one run.
continue; var end = mi;
} while (end + 1 < chat.msgs.length &&
for (var i = 0; i < m.content.length; i++) { chat.msgs[end + 1].type == 'assistant') {
final t = m.content[i].type; end++;
if (t == 'text' || t == 'reasoning' || t == 'tool') {
out.add(_Row(t, m.id, i));
}
}
if (m.completed > 0 && _turnEndsAt(mi)) {
out.add(_Row('footer', m.id, -1));
} }
_turnRows(out, mi, end);
mi = end;
break; break;
case 'shell': case 'shell':
out.add(_Row('shell', m.id, -1)); out.add(_Row('shell', m.id, -1));
@@ -198,6 +198,77 @@ class _ChatScreenState extends State<ChatScreen> {
return out; return out;
} }
void _turnRows(List<_Row> out, int from, int to) {
final pending = <_Step>[];
void flush() {
if (pending.isEmpty) return;
final first = pending.first;
// A lone thought needs no foldable header above it.
if (pending.length == 1 && first.part.type == 'reasoning') {
out.add(_Row('step', first.msgId, first.index));
pending.clear();
return;
}
out.add(_Row('steps', first.msgId, first.index));
if (!_groupCollapsed(first.msgId, first.index)) {
for (final step in pending) {
out.add(_Row('step', step.msgId, step.index));
}
}
pending.clear();
}
for (var i = from; i <= to; i++) {
final m = chat.msgs[i];
if (m.content.isEmpty && m.completed == 0) {
flush();
out.add(_Row('thinking', m.id, -1));
continue;
}
for (var p = 0; p < m.content.length; p++) {
final part = m.content[p];
if (part.type == 'reasoning' || part.type == 'tool') {
pending.add(_Step(m.id, p, part));
} else if (part.type == 'text') {
flush();
out.add(_Row('text', m.id, p));
}
}
}
flush();
if (chat.msgs[to].completed > 0 && _turnEndsAt(to)) {
out.add(_Row('footer', chat.msgs[to].id, -1));
}
}
bool _groupCollapsed(String id, int start) =>
_collapsedSteps.contains('$id/$start');
/// The steps of the run that begins at [msgId]/[index]: consecutive
/// reasoning/tool parts, continuing into the following assistant messages.
List<_Step> _collectGroup(String msgId, int index) {
final out = <_Step>[];
var i = chat.msgs.indexWhere((m) => m.id == msgId);
var p = index;
while (i >= 0 && i < chat.msgs.length) {
final m = chat.msgs[i];
if (p >= m.content.length) {
if (i + 1 < chat.msgs.length &&
chat.msgs[i + 1].type == 'assistant') {
i++;
p = 0;
continue;
}
break;
}
final part = m.content[p];
if (part.type != 'reasoning' && part.type != 'tool') break;
out.add(_Step(m.id, p, part));
p++;
}
return out;
}
bool _turnEndsAt(int i) { bool _turnEndsAt(int i) {
for (var j = i + 1; j < chat.msgs.length; j++) { for (var j = i + 1; j < chat.msgs.length; j++) {
if (chat.msgs[j].type == 'assistant') return false; if (chat.msgs[j].type == 'assistant') return false;
@@ -219,10 +290,10 @@ class _ChatScreenState extends State<ChatScreen> {
); );
case 'text': case 'text':
return _textRow(r.msgId, r.part); return _textRow(r.msgId, r.part);
case 'reasoning': case 'steps':
return _reasoningRow(r.msgId, r.part); return _stepsHeader(r.msgId, r.part);
case 'tool': case 'step':
return _toolRow(r.msgId, r.part); return _stepRow(r.msgId, r.part);
case 'footer': case 'footer':
return _footerRow(r.msgId); return _footerRow(r.msgId);
case 'shell': case 'shell':
@@ -341,109 +412,332 @@ class _ChatScreenState extends State<ChatScreen> {
); );
} }
Widget _reasoningRow(String id, int part) { /// "已完成 · 3 次工具调用", with a chevron that folds the whole run.
final m = chat.byId[id]!; Widget _stepsHeader(String id, int start) {
final key = 'reasoning/$id/$part'; final theme = Theme.of(context);
final open = chat.expanded.contains(key); final steps = _collectGroup(id, start);
final text = part < m.content.length ? m.content[part].text : ''; final tools = steps.where((s) => s.part.type == 'tool').length;
return Column( final collapsed = _groupCollapsed(id, start);
crossAxisAlignment: CrossAxisAlignment.start, final failed = steps.any((s) => s.part.state?.status == 'error');
children: [ final running = steps.any((s) {
InkWell( final m = chat.byId[s.msgId];
onTap: () => setState(() { final st = s.part.state?.status ?? '';
open ? chat.expanded.remove(key) : chat.expanded.add(key); return (m != null && m.completed == 0) ||
}), st == 'running' ||
child: Padding( st == 'streaming' ||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2), st == 'pending';
child: Text('已思考 ${open ? '▾' : '▸'}', });
style: const TextStyle(color: Colors.grey, fontSize: 13)), final label = tools == 0
), ? (running ? '思考中…' : '思考过程')
: failed
? '有步骤失败 · $tools 次工具调用'
: running
? '执行中 · $tools 次工具调用'
: '已完成 · $tools 次工具调用';
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => setState(() {
final key = '$id/$start';
collapsed ? _collapsedSteps.remove(key) : _collapsedSteps.add(key);
}),
child: Padding(
padding: const EdgeInsets.fromLTRB(14, 10, 12, 2),
child: Row(
children: [
if (running)
const SizedBox(
width: 15,
height: 15,
child: CircularProgressIndicator(strokeWidth: 1.6))
else
Icon(failed ? Icons.error_outline : Icons.check_circle_outline,
size: 16,
color: failed ? theme.colorScheme.error : theme.hintColor),
const SizedBox(width: 8),
Expanded(
child: Text(label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 13, color: theme.hintColor)),
),
Icon(collapsed ? Icons.expand_more : Icons.expand_less,
size: 18, color: theme.hintColor),
],
), ),
if (open && text.isNotEmpty) ),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
child: Text(text,
style: const TextStyle(color: Colors.grey, fontSize: 13, height: 1.4)),
),
],
); );
} }
Widget _toolRow(String id, int part) { /// One step: a rounded icon, a label, the one-line summary, and details
/// when opened.
Widget _stepRow(String id, int part) {
final m = chat.byId[id]!; final m = chat.byId[id]!;
if (part < 0 || part >= m.content.length) return const SizedBox.shrink(); if (part < 0 || part >= m.content.length) return const SizedBox.shrink();
final p = m.content[part]; final p = m.content[part];
final key = 'tool/$id/$part'; final theme = Theme.of(context);
final open = chat.expanded.contains(key); final reasoning = p.type == 'reasoning';
final status = p.state?.status ?? ''; final status = p.state?.status ?? '';
final icon = status == 'completed' ? '✓' final busy = status == 'running' || status == 'streaming' || status == 'pending';
: status == 'error' ? '✕' final key = 'step/$id/$part';
: status == 'running' || status == 'streaming' ? '◌' : '●'; final open = chat.expanded.contains(key);
final refs = toolImages(p, chat.dir); final label = _stepLabel(p);
return Column( final summary = _stepSummary(p);
crossAxisAlignment: CrossAxisAlignment.start, final refs = reasoning ? const <_ImageRef>[] : toolImages(p, chat.dir);
children: [ return Container(
InkWell( margin: const EdgeInsets.only(left: 22),
onTap: () { decoration: BoxDecoration(
setState(() { border: Border(left: BorderSide(color: theme.dividerColor, width: 1)),
open ? chat.expanded.remove(key) : chat.expanded.add(key); ),
}); child: Column(
if (!open) chat.ensureToolLoaded(id); crossAxisAlignment: CrossAxisAlignment.start,
}, children: [
child: Padding( InkWell(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2), onTap: () {
child: Text('$icon ${p.name ?? ''} ${open ? '▾' : '▸'}', setState(() {
maxLines: 1, open ? chat.expanded.remove(key) : chat.expanded.add(key);
overflow: TextOverflow.ellipsis, });
style: const TextStyle(color: Colors.grey, fontSize: 13)), if (!open && !reasoning) chat.ensureToolLoaded(id);
), },
), child: Padding(
for (final ref in refs) padding: const EdgeInsets.fromLTRB(10, 3, 10, 3),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 1),
child: InkWell(
onTap: () => _openPreview(ref),
child: Row( child: Row(
children: [ children: [
const Text('🖼', style: TextStyle(fontSize: 12)), Container(
const SizedBox(width: 6), width: 26,
Flexible( height: 26,
child: Text(ref.label, decoration: BoxDecoration(
maxLines: 1, color: status == 'error'
overflow: TextOverflow.ellipsis, ? theme.colorScheme.errorContainer
style: TextStyle(fontSize: 12, color: Theme.of(context).colorScheme.primary)), : theme.colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(7),
),
child: busy
? const Padding(
padding: EdgeInsets.all(6),
child: CircularProgressIndicator(strokeWidth: 1.6),
)
: Icon(_stepIcon(p),
size: 15,
color: status == 'error'
? theme.colorScheme.onErrorContainer
: theme.colorScheme.onSurfaceVariant),
), ),
const SizedBox(width: 10),
Text(label,
style: TextStyle(
fontSize: 13.5, color: theme.colorScheme.onSurface)),
if (summary.isEmpty)
const Spacer()
else ...[
const SizedBox(width: 6),
Text('·', style: TextStyle(fontSize: 13, color: theme.hintColor)),
const SizedBox(width: 6),
Expanded(
child: Text(summary,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 13, color: theme.hintColor)),
),
],
Icon(open ? Icons.expand_less : Icons.expand_more,
size: 16, color: theme.hintColor),
], ],
), ),
), ),
), ),
if (open) for (final ref in refs)
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2), padding: const EdgeInsets.fromLTRB(10, 0, 10, 2),
child: Container( child: InkWell(
width: double.infinity, onTap: () => _openPreview(ref),
padding: const EdgeInsets.all(8), child: Row(
decoration: BoxDecoration( children: [
color: Theme.of(context).colorScheme.surfaceContainerHighest, const Text('🖼', style: TextStyle(fontSize: 12)),
borderRadius: BorderRadius.circular(8), const SizedBox(width: 6),
), Flexible(
child: Column( child: Text(ref.label,
crossAxisAlignment: CrossAxisAlignment.start, maxLines: 1,
children: [ overflow: TextOverflow.ellipsis,
if (p.state != null && (p.state!.input).isNotEmpty) style: TextStyle(
Text(const JsonEncoder.withIndent(' ').convert(p.state!.input), fontSize: 12, color: theme.colorScheme.primary)),
style: const TextStyle(fontSize: 12, color: Colors.grey)), ),
if (toolOutput(p).isNotEmpty) ],
Text(toolOutput(p), ),
style: const TextStyle(fontSize: 12, color: Colors.grey, height: 1.4)),
],
), ),
), ),
), if (open) _stepDetails(p, reasoning),
], ],
),
); );
} }
Widget _stepDetails(ContentPart p, bool reasoning) {
final theme = Theme.of(context);
if (reasoning) {
if (p.text.isEmpty) return const SizedBox.shrink();
return Padding(
padding: const EdgeInsets.fromLTRB(10, 2, 10, 8),
child: SelectableText(p.text,
style: TextStyle(
fontSize: 12.5, height: 1.45, color: theme.hintColor)),
);
}
final input = p.state?.input ?? const <String, dynamic>{};
final output = toolOutput(p);
return Padding(
padding: const EdgeInsets.fromLTRB(10, 2, 10, 8),
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (input.isNotEmpty)
SelectableText(const JsonEncoder.withIndent(' ').convert(input),
style: const TextStyle(
fontSize: 12,
fontFamily: 'monospace',
height: 1.4)),
if (input.isNotEmpty && output.isNotEmpty)
const SizedBox(height: 6),
if (output.isNotEmpty)
SelectableText(output,
style: TextStyle(
fontSize: 12,
height: 1.4,
color: p.state?.error != null
? theme.colorScheme.error
: theme.colorScheme.onSurfaceVariant)),
],
),
),
);
}
static IconData _stepIcon(ContentPart p) {
if (p.type == 'reasoning') return Icons.psychology_outlined;
switch (p.name ?? '') {
case 'bash':
case 'shell':
case 'execute':
return Icons.terminal;
case 'read':
return Icons.description_outlined;
case 'write':
return Icons.note_add_outlined;
case 'edit':
return Icons.edit_outlined;
case 'patch':
case 'apply_patch':
return Icons.difference_outlined;
case 'grep':
return Icons.search;
case 'glob':
case 'find':
return Icons.travel_explore;
case 'list':
return Icons.format_list_bulleted;
case 'webfetch':
case 'web_fetch':
return Icons.language;
case 'todowrite':
return Icons.checklist_rtl;
case 'task':
return Icons.smart_toy_outlined;
case 'skill':
return Icons.extension_outlined;
default:
return Icons.handyman_outlined;
}
}
static String _stepLabel(ContentPart p) {
if (p.type == 'reasoning') return '思考';
switch (p.name ?? '') {
case 'bash':
case 'shell':
case 'execute':
return '运行';
case 'read':
return '读取';
case 'write':
return '写入';
case 'edit':
return '编辑';
case 'patch':
case 'apply_patch':
return '补丁';
case 'grep':
case 'glob':
case 'find':
return '搜索';
case 'list':
return '列出';
case 'webfetch':
case 'web_fetch':
return '抓取';
case 'todowrite':
return '任务';
case 'task':
return '子任务';
case 'skill':
return '技能';
default:
return p.name == null || p.name!.isEmpty ? '工具' : p.name!;
}
}
/// One line that says what the step is about, so a folded run stays useful.
static String _stepSummary(ContentPart p) {
if (p.type == 'reasoning') return _firstLine(p.text);
final input = p.state?.input ?? const <String, dynamic>{};
String one(Object? v) =>
(v ?? '').toString().replaceAll(RegExp(r'\s+'), ' ').trim();
switch (p.name ?? '') {
case 'bash':
case 'shell':
case 'execute':
return one(input['command']);
case 'read':
case 'write':
case 'edit':
return one(input['filePath'] ?? input['path'] ?? input['file']);
case 'grep':
case 'glob':
case 'find':
return one(input['pattern']);
case 'webfetch':
case 'web_fetch':
return one(input['url']);
case 'task':
return one(input['description'] ?? input['prompt']);
case 'skill':
return one(input['id'] ?? input['name']);
default:
for (final k in const [
'description', 'filePath', 'path', 'command', 'query', 'url',
'pattern', 'name', 'id',
]) {
final v = one(input[k]);
if (v.isNotEmpty) return v;
}
if (input.isEmpty) return '';
return one(const JsonEncoder().convert(input));
}
}
static String _firstLine(String text) {
for (final line in const LineSplitter().convert(text)) {
final t = line.replaceAll(RegExp(r'^[\s#>*\-]+'), '').trim();
if (t.isNotEmpty) return t;
}
return '';
}
Widget _footerRow(String id) { Widget _footerRow(String id) {
final m = chat.byId[id]!; final m = chat.byId[id]!;
final parts = <String>[]; final parts = <String>[];
@@ -1055,6 +1349,15 @@ class _Row {
_Row(this.kind, this.msgId, this.part); _Row(this.kind, this.msgId, this.part);
} }
/// One reasoning or tool part, addressed across the assistant messages of a
/// turn.
class _Step {
final String msgId;
final int index;
final ContentPart part;
const _Step(this.msgId, this.index, this.part);
}
class _Attach { class _Attach {
final String name; final String name;
final String mime; final String mime;
+1 -1
View File
@@ -2,7 +2,7 @@ name: openchamber
description: "A lightweight OpenChamber client for phones." description: "A lightweight OpenChamber client for phones."
publish_to: 'none' publish_to: 'none'
version: 0.3.2+302 version: 0.3.3+303
environment: environment:
sdk: ^3.14.0 sdk: ^3.14.0