diff --git a/PLAN.md b/PLAN.md index 08c2643..69ce302 100644 --- a/PLAN.md +++ b/PLAN.md @@ -5,6 +5,21 @@ --- +## 0.4.15 后台任务条细节:外观一致、停止移到弹层、宠物站位(分支 `flutter`) + +| 项 | 结果 | +| --- | --- | +| 外观一致 | 后台任务条改为与运行状态胶囊同一套形状:8 边距、14 水平内边距、36 最小高度、Stadium 圆角、相同的文字大小与基线,两条叠在一起时读作一组;多条任务在同一条胶囊里逐行排列 | +| 停止 | 按反馈去掉任务条上的「停止」按钮:它会把右侧对齐从计时挤开,与上方运行条的右端对不齐。现在点任意一行打开弹层,停止与复制都在弹层里(确认框「停止这个任务?」不变) | +| 弹层状态行 | 不再写「运行中」(弹层开着就是在跑,计时已经说明),也没有会让人误以为「点我刷新」的 `sync` 图标:左边只有计时;「停止」改成带方块停止图标的按钮;命令结束后才显示「已结束」 | +| 弹层关闭 | 去掉右侧的 x:拖动把手下滑和点遮罩都能关,x 是多余的 | +| 宠物 | 宠物站在最上方那条胶囊的边沿:有运行条或后台任务条时按它的 4px 上边距收脚,都不在时按输入框的 6px;之前会陷进胶囊顶边 2px | +| 测试 | `test/shell_jobs_test.dart`:任务条不再有「停止」、点行回调打开弹层、计时仍在;80 项全过 | +| 验证 | 模拟器:运行中 + 一条后台任务,两条胶囊等高同圆角;点任务行打开弹层:计时、带图标的「停止」与「复制」、实时输出与跟随,没有「运行中」字样与 x;首次读取时显示「读取输出…」转圈,不会误报「等待输出」;弹层内停止 → 确认 → shell 消失,弹层转为「已结束」并保留最后输出;从弹层头部下滑确实能关闭(x 去掉的前提);宠物在只有运行条、只有任务条、两者都有时都踩在胶囊上沿 | +| 版本 | **0.4.15(code 415)** | + +--- + ## 0.4.14 后台任务:状态条、实时输出与停止(分支 `flutter`) | 项 | 结果 | @@ -17,7 +32,7 @@ | 结束后 | 命令结束后,工具行与弹层不再轮询,改用会话里 synthetic `` 的最终输出(shell 被删除后仍能看);如果是用户在 App 里停的,显示「用户停止了这条命令。」而不是 Shell.NotFoundError | | 刷新 | 打开会话立即刷新,之后 3 秒一次;会话消息变化时也刷新(新任务立刻出现);服务端无该接口时停止轮询 | | 测试 | 新增 `test/shell_jobs_test.dart`:后台标记识别(前台命令不算)、转录/任务/外壳列表解析、输出页、完成说明与停止标记、计时格式、停止说明,以及状态条 1 条/2 条/多条折叠的布局;80 项全过 | -| 验证 | 模拟器(真实任务):`sleep 900` 单条任务条 → 第二条命令变为「正在执行 2 条命令」+ 两条行;弹层实时输出(每秒 tick);弹层内「停止」→ 确认 → 任务与 shell 消失、模型收到 synthetic 停止说明;工具行「后台」标签 + 展开后的最终输出/「用户停止了这条命令。」 | +| 验证 | 模拟器(真实任务):`sleep 900` 单条任务条 → 第二条命令变为「正在执行 2 条命令」+ 两条行;弹层实时输出(每秒 tick);弹层内「停止」→ 确认 → 任务与 shell 消失、模型收到 synthetic 停止说明;工具行「后台」标签 + 展开后的最终输出/「用户停止了这条命令。」。后台进程可用前台命令超时后「移到后台」的方式启动(`timeout` 5 秒、不加 background),这样不会像 `background: true` 那样在超时点被 SIGKILL,任务会一直跑到手动停止 | | 版本 | **0.4.14(code 414)** | --- diff --git a/README.md b/README.md index c7b0701..9d9f4cb 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.4.14 — servers (passwordless / password login, HTTP/HTTPS and +Status: 0.4.15 — servers (passwordless / password login, HTTP/HTTPS and SOCKS5/socks5h proxy, self-signed certificates and pinning, or a pairing link over the OpenChamber private relay with end-to-end encryption; the pairing link is pasted or scanned with the camera), session list with search and live diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index cee3fb7..55c85f7 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -342,7 +342,11 @@ class _ChatScreenState extends State { Positioned.fill(child: _messageList()), // Over the messages, not in the column: the list keeps its // full height and shows through around the pet. - Positioned.fill(child: PetLayer(state: _petState())), + Positioned.fill( + child: PetLayer( + state: _petState(), + footOffset: _petFootOffset, + )), ], ), ), @@ -1714,6 +1718,15 @@ class _ChatScreenState extends State { ); } + /// Where the pet's feet rest: on the composer's capsule, or on the status + /// capsule when one is the last thing above the composer. That strip keeps + /// a 4px top margin of its own, so the feet stop on its edge instead of + /// sinking into it. + double get _petFootOffset { + final strip = chat.running || (_shells?.tasks.isNotEmpty ?? false); + return strip ? 4 : 6; + } + /// The mood the pet draws: the same activity the strip shows, then a failed /// last turn, then idle. String _petState() { @@ -1780,10 +1793,6 @@ class _ChatScreenState extends State { tasks: tasks, sessionId: chat.session.id, onOpen: _openShellSheet, - onStop: (task) async { - final ok = await confirmStopShell(context, task.command); - if (ok == true) await _stopShell(task); - }, ); } diff --git a/lib/widgets/pet_sprite.dart b/lib/widgets/pet_sprite.dart index 908ac4c..7a5d200 100644 --- a/lib/widgets/pet_sprite.dart +++ b/lib/widgets/pet_sprite.dart @@ -16,7 +16,12 @@ import '../pets/pet_pack.dart'; /// cap's while a turn runs). Dragging it sideways moves it along that edge. class PetLayer extends StatefulWidget { final String state; - const PetLayer({super.key, required this.state}); + + /// How far below the layer's bottom edge the feet stand: the composer's + /// top padding, or the status capsule's edge when one sits above it. + final double footOffset; + + const PetLayer({super.key, required this.state, this.footOffset = 6}); @override State createState() => _PetLayerState(); @@ -62,8 +67,9 @@ class _PetLayerState extends State { // little below the anchor, and the composer keeps a few px of top // padding above its capsule, so step past both; that overflow is // fine, the layer does not clip. - final bottom = - -((pack.canvas.height - pack.anchor.dy) * scale + 6) + _lift; + final bottom = -((pack.canvas.height - pack.anchor.dy) * scale + + widget.footOffset) + + _lift; return Stack( clipBehavior: Clip.none, diff --git a/lib/widgets/shell_jobs.dart b/lib/widgets/shell_jobs.dart index 3981b91..5f06b75 100644 --- a/lib/widgets/shell_jobs.dart +++ b/lib/widgets/shell_jobs.dart @@ -15,15 +15,15 @@ class ShellTaskBar extends StatefulWidget { /// The chat's own session: a task from a child session is marked. final String sessionId; + + /// Tapping a row opens its output; the stop lives in that sheet. final void Function(ShellTask task) onOpen; - final void Function(ShellTask task) onStop; const ShellTaskBar({ super.key, required this.tasks, required this.sessionId, required this.onOpen, - required this.onStop, }); @override @@ -42,27 +42,35 @@ class _ShellTaskBarState extends State { if (tasks.isEmpty) return const SizedBox.shrink(); final theme = Theme.of(context); final single = tasks.length == 1; + // The same capsule as the activity strip above it: one row of text in the + // same stadium, with the same margins, so the two read as one stack. return Padding( - padding: const EdgeInsets.fromLTRB(8, 2, 8, 6), + padding: const EdgeInsets.fromLTRB(8, 4, 8, 4), child: Material( color: theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.7), - borderRadius: BorderRadius.circular(14), + shape: const StadiumBorder(), clipBehavior: Clip.antiAlias, - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - if (!single) _header(theme, tasks.length), - if (single || _open) - for (final task in tasks) - _ShellTaskRow( - key: ValueKey(task.id), - task: task, - subagent: task.sessionId.isNotEmpty && - task.sessionId != widget.sessionId, - onTap: () => widget.onOpen(task), - onStop: () => widget.onStop(task), - ), - ], + child: ConstrainedBox( + constraints: const BoxConstraints(minHeight: 36), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (!single) _header(theme, tasks.length), + if (single || _open) + for (final task in tasks) + _ShellTaskRow( + key: ValueKey(task.id), + task: task, + subagent: task.sessionId.isNotEmpty && + task.sessionId != widget.sessionId, + onTap: () => widget.onOpen(task), + ), + ], + ), + ), ), ), ); @@ -71,8 +79,8 @@ class _ShellTaskBarState extends State { Widget _header(ThemeData theme, int count) { return InkWell( onTap: () => setState(() => _expanded = !_open), - child: Padding( - padding: const EdgeInsets.fromLTRB(12, 8, 8, 8), + child: SizedBox( + height: 24, child: Row( children: [ Icon(Icons.terminal, size: 15, color: theme.hintColor), @@ -84,7 +92,8 @@ class _ShellTaskBarState extends State { overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 13, - color: theme.colorScheme.onSurfaceVariant, + fontWeight: FontWeight.w600, + color: theme.colorScheme.onSurface, ), ), ), @@ -101,14 +110,12 @@ class _ShellTaskRow extends StatelessWidget { final ShellTask task; final bool subagent; final VoidCallback onTap; - final VoidCallback onStop; const _ShellTaskRow({ super.key, required this.task, required this.subagent, required this.onTap, - required this.onStop, }); @override @@ -116,8 +123,8 @@ class _ShellTaskRow extends StatelessWidget { final theme = Theme.of(context); return InkWell( onTap: onTap, - child: Padding( - padding: const EdgeInsets.fromLTRB(12, 2, 4, 2), + child: SizedBox( + height: 24, child: Row( children: [ Icon(Icons.terminal, size: 15, color: theme.hintColor), @@ -128,26 +135,22 @@ class _ShellTaskRow extends StatelessWidget { maxLines: 1, overflow: TextOverflow.ellipsis, style: const TextStyle( - fontSize: 12, fontFamily: 'monospace', height: 1.35), + fontSize: 12.5, fontFamily: 'monospace', height: 1.3), ), ), if (subagent) ...[ const SizedBox(width: 6), Text('子代理', - style: TextStyle(fontSize: 11, color: theme.hintColor)), + style: TextStyle( + fontSize: 12, + color: theme.colorScheme.onSurfaceVariant, + )), ], const SizedBox(width: 8), + // The clock ends on the capsule's inner edge, the same line the + // activity strip's clock ends on above it; stopping is a tap away + // in the sheet, so no button here to break that line. ShellElapsed(startedAt: task.startedAt), - TextButton( - onPressed: onStop, - style: TextButton.styleFrom( - minimumSize: const Size(0, 34), - padding: const EdgeInsets.symmetric(horizontal: 10), - foregroundColor: theme.colorScheme.error, - textStyle: const TextStyle(fontSize: 12.5), - ), - child: const Text('停止'), - ), ], ), ), @@ -324,8 +327,10 @@ class _ShellOutputSheetState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ + // The drag handle above and a tap on the scrim close the sheet; + // a close button would only repeat them. Padding( - padding: const EdgeInsets.fromLTRB(20, 0, 8, 0), + padding: const EdgeInsets.fromLTRB(20, 0, 20, 0), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -340,11 +345,6 @@ class _ShellOutputSheetState extends State { fontSize: 13, fontFamily: 'monospace', height: 1.4), ), ), - IconButton( - icon: const Icon(Icons.close, size: 20), - tooltip: '关闭', - onPressed: () => Navigator.pop(context), - ), ], ), ), @@ -352,33 +352,30 @@ class _ShellOutputSheetState extends State { padding: const EdgeInsets.fromLTRB(20, 0, 20, 8), child: Row( children: [ - Icon( - running ? Icons.sync : Icons.check_circle_outline, - size: 15, - color: running ? theme.colorScheme.primary : theme.hintColor, - ), - const SizedBox(width: 6), - Text( - running ? '运行中' : '已结束', - style: TextStyle( - fontSize: 12, - color: running - ? theme.colorScheme.primary - : theme.hintColor), - ), - const SizedBox(width: 10), - ShellElapsed( - startedAt: widget.task.startedAt, running: running), + // No "运行中" label: a live sheet is running by definition, + // and the clock says since when. Only the end is worth saying. + if (running) + ShellElapsed( + startedAt: widget.task.startedAt, running: true) + else ...[ + Icon(Icons.check_circle_outline, + size: 15, color: theme.hintColor), + const SizedBox(width: 6), + Text('已结束', + style: + TextStyle(fontSize: 12, color: theme.hintColor)), + ], const Spacer(), if (running) - TextButton( + TextButton.icon( onPressed: _stopping ? null : _stop, + icon: const Icon(Icons.stop_rounded, size: 17), + label: Text(_stopping ? '停止中…' : '停止'), style: TextButton.styleFrom( foregroundColor: theme.colorScheme.error, minimumSize: const Size(0, 32), padding: const EdgeInsets.symmetric(horizontal: 10), ), - child: Text(_stopping ? '停止中…' : '停止'), ), TextButton.icon( onPressed: _text.isEmpty ? null : _copy, @@ -399,10 +396,29 @@ class _ShellOutputSheetState extends State { Positioned.fill( child: _text.isEmpty ? Center( - child: Text( - _feed.error ?? (running ? '等待输出…' : '没有输出'), - style: TextStyle( - fontSize: 13, color: theme.hintColor), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + if (_feed.error == null && !_feed.loaded) ...[ + const SizedBox( + width: 16, + height: 16, + child: + CircularProgressIndicator(strokeWidth: 1.8), + ), + const SizedBox(height: 10), + ], + Text( + _feed.error ?? + (!_feed.loaded + ? '读取输出…' + : running + ? '等待输出…' + : '没有输出'), + style: TextStyle( + fontSize: 13, color: theme.hintColor), + ), + ], ), ) : Scrollbar( @@ -636,6 +652,10 @@ class ShellOutputFeed { final String directory; String text = ''; + + /// The first page has been read: before that, an empty [text] means the + /// read is still under way, not that the command has printed nothing. + bool loaded = false; bool ended = false; String? error; @@ -675,6 +695,7 @@ class ShellOutputFeed { _cursor = page.cursor; } error = null; + loaded = true; } else if (!ended) { final page = await client.shellOutput(task.id, cursor: _cursor, directory: directory); @@ -701,6 +722,7 @@ class ShellOutputFeed { } on ApiError catch (e) { if (e.status == 404) { ended = true; + loaded = true; error = null; _timer?.cancel(); _timer = null; diff --git a/pubspec.yaml b/pubspec.yaml index 7e9e000..9bb1a49 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.4.14+414 +version: 0.4.15+415 environment: sdk: ^3.14.0 diff --git a/test/shell_jobs_test.dart b/test/shell_jobs_test.dart index 14e3151..4c11ae6 100644 --- a/test/shell_jobs_test.dart +++ b/test/shell_jobs_test.dart @@ -250,7 +250,8 @@ void main() { startedAt: DateTime.now().millisecondsSinceEpoch - 65000, ); - Future pump(WidgetTester tester, List tasks) async { + Future pump(WidgetTester tester, List tasks, + {void Function(ShellTask)? onOpen}) async { await tester.pumpWidget(MaterialApp( home: Scaffold( body: Column( @@ -258,8 +259,7 @@ void main() { ShellTaskBar( tasks: tasks, sessionId: 'ses_a', - onOpen: (_) {}, - onStop: (_) {}, + onOpen: onOpen ?? (_) {}, ), ], ), @@ -267,13 +267,17 @@ void main() { )); } - testWidgets('one command is its own row, with stop and clock', - (tester) async { - await pump(tester, [task('sh_1', command: 'pnpm dev')]); + testWidgets('one command is its own row, with its clock', (tester) async { + ShellTask? opened; + await pump(tester, [task('sh_1', command: 'pnpm dev')], + onOpen: (t) => opened = t); expect(find.text('pnpm dev'), findsOneWidget); - expect(find.text('停止'), findsOneWidget); expect(find.text('1分05秒'), findsOneWidget); expect(find.textContaining('正在执行'), findsNothing); + // Stopping is in the sheet the row opens, not a button on the bar. + expect(find.text('停止'), findsNothing); + await tester.tap(find.text('pnpm dev')); + expect(opened?.id, 'sh_1'); }); testWidgets('two commands share a count header and both show', @@ -286,7 +290,7 @@ void main() { expect(find.text('pnpm dev'), findsOneWidget); expect(find.text('pnpm test'), findsOneWidget); expect(find.text('子代理'), findsOneWidget); - expect(find.text('停止'), findsNWidgets(2)); + expect(find.text('停止'), findsNothing); }); testWidgets('a long list folds until asked', (tester) async {