diff --git a/PLAN.md b/PLAN.md index 69c9a28..a4e3d79 100644 --- a/PLAN.md +++ b/PLAN.md @@ -5,6 +5,17 @@ --- +## 0.3.19 输入框环居中、运行状态条、侧栏项目层级与 Windows 路径(分支 `flutter`) + +| 项 | 结果 | +| --- | --- | +| 上下文环 | 单行输入框用 `CrossAxisAlignment.end`,16px 的环贴着底部而按键是 36px;给环加 10px 底边距,与按键同一中轴(有焦点时的两行布局本来就是居中,未改) | +| 运行中的尾部 | 运行中不再显示上一轮的 footer(模型 · 模式 · 用时,以及“复制回答 / 从这里分叉”菜单):`_turnRows` 在 `chat.running` 为真时不加 footer。改为在输入框上方显示 dsh-Go 风格的活动条:「思考中 / 正在回复 / 正在读取 · …」加当前步骤摘要和秒表,每秒刷新 | +| 侧栏项目 | 项目分组头改成带底色的圆角条,最小高度 56,加文件夹图标;标题 13.5 粗体、路径作副标题,与会话行的层级更清楚 | +| Windows 路径 | 项目名只取路径最后一段,`/` 与 `\` 都识别;同一项目的比较统一分隔符(盘符路径忽略大小写),分组键也统一分隔符,避免一个项目被拆成两组 | +| 版本 | **0.3.19(code 319)** | +--- + ## 0.3.18 需要密码的服务器无法输入密码(分支 `flutter`) | 项 | 结果 | diff --git a/README.md b/README.md index 1f3bb90..0aaec0a 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.18 — servers (passwordless / password login, HTTP/HTTPS and +Status: 0.3.19 — 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 @@ -22,7 +22,9 @@ composer folds to one line when unfocused (or when the keyboard is dismissed) and opens into two rows on focus, as in dsh-Go: the model and its thinking level form one pill, the Build/Plan mode a separate chip (picked from a sheet). A message sent while a turn runs can steer it or queue for its end, and waits as a -pending bubble that can be withdrawn. The picker groups providers, favourites, +pending bubble that can be withdrawn; while a turn runs, an activity strip above +the input names the current step and its clock instead of the finished turn's +footer. The picker groups providers, favourites, recents and context size. The sidebar footer names the connected server (tap to switch) beside a settings key; settings holds appearance (theme mode and seed colour, device-local), the server's follow-up behavior (steer or queue on a send diff --git a/lib/api/models.dart b/lib/api/models.dart index 59fef38..39726e2 100644 --- a/lib/api/models.dart +++ b/lib/api/models.dart @@ -167,13 +167,34 @@ class ProjectInfo { String get label { if (name.trim().isNotEmpty) return name.trim(); - final trimmed = - canonical.replaceAll(RegExp(r'/+$'), ''); - final index = trimmed.lastIndexOf('/'); - return index >= 0 ? trimmed.substring(index + 1) : trimmed; + return pathLeaf(canonical); } } +/// The last segment of a path, treating `\` and `/` alike: a Windows server +/// sends `C:\...` and a project has to read as its folder name, not the path. +String pathLeaf(String path) { + final trimmed = path.replaceAll(RegExp(r'[/\\]+$'), ''); + final index = trimmed.lastIndexOf(RegExp(r'[/\\]')); + return index >= 0 ? trimmed.substring(index + 1) : trimmed; +} + +/// A path with `\` written as `/` and no trailing slash, for comparing and +/// grouping directory names from a Windows or a POSIX server. +String slashPath(String path) => + path.replaceAll('\\', '/').replaceAll(RegExp(r'/+$'), ''); + +/// Whether two directory paths name the same place. Separators are unified; +/// a drive-letter path compares case-insensitively, as Windows does. +bool samePath(String a, String b) { + final x = slashPath(a); + final y = slashPath(b); + if (x == y) return true; + final windows = RegExp(r'^[A-Za-z]:').hasMatch(x) || + RegExp(r'^[A-Za-z]:').hasMatch(y); + return windows && x.toLowerCase() == y.toLowerCase(); +} + class ContentPart { final String type; final String text; diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index d6bdfb7..495a051 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -64,11 +64,15 @@ class _ChatScreenState extends State { final Set _collapsedSteps = {}; final Set _expandedSteps = {}; + /// Ticks the activity strip's clock while a turn runs. + Timer? _runClock; + @override void initState() { super.initState(); chat.addListener(_onChat); _inputFocus.addListener(_onFocusChanged); + if (chat.running) _startClock(); // The list is reversed: offset 0 is the newest message (the bottom), and // older pages grow above without moving what is on screen. _scroll.addListener(() { @@ -87,6 +91,11 @@ class _ChatScreenState extends State { void _onChat() { if (mounted) setState(() {}); + if (chat.running) { + _startClock(); + } else { + _stopClock(); + } if (_stick) { WidgetsBinding.instance.addPostFrameCallback((_) { if (_scroll.hasClients) _scroll.jumpTo(0); @@ -94,6 +103,17 @@ class _ChatScreenState extends State { } } + void _startClock() { + _runClock ??= Timer.periodic(const Duration(seconds: 1), (_) { + if (mounted && chat.running) setState(() {}); + }); + } + + void _stopClock() { + _runClock?.cancel(); + _runClock = null; + } + void _onFocusChanged() { if (mounted) setState(() {}); } @@ -102,6 +122,7 @@ class _ChatScreenState extends State { void dispose() { chat.removeListener(_onChat); _inputFocus.removeListener(_onFocusChanged); + _stopClock(); _draftCtrl.dispose(); _inputFocus.dispose(); _scroll.dispose(); @@ -148,6 +169,7 @@ class _ChatScreenState extends State { Expanded(child: _messageList()), _permissions(), _forms(), + if (chat.running) _activityStrip(), _composer(widget.keyboardInset), ], ), @@ -291,7 +313,9 @@ class _ChatScreenState extends State { if (last.error != null && !last.error!.isEmpty) { out.add(_Row('error', last.id, -1)); } - if (last.completed > 0 && _turnEndsAt(to)) { + // A running turn has no "done" strip (nor its copy/fork menu): the + // activity strip above the composer speaks for it instead. + if (last.completed > 0 && _turnEndsAt(to) && !chat.running) { out.add(_Row('footer', last.id, -1)); } } @@ -1317,6 +1341,100 @@ class _ChatScreenState extends State { ); } + /// What the agent is doing right now, for the strip above the composer. + ({String title, String detail}) _activity() { + for (var i = chat.msgs.length - 1; i >= 0; i--) { + final m = chat.msgs[i]; + if (m.type != 'assistant') continue; + for (var p = m.content.length - 1; p >= 0; p--) { + final part = m.content[p]; + final st = part.state?.status ?? ''; + if (part.type == 'tool' && + (st == 'running' || st == 'streaming' || st == 'pending')) { + return (title: '正在${_stepLabel(part)}', detail: _stepSummary(part)); + } + } + if (m.completed == 0) { + // No tool running yet: say which part of the reply is being written. + final text = + m.content.any((p) => p.type == 'text' && p.text.trim().isNotEmpty); + final reasoning = m.content + .any((p) => p.type == 'reasoning' && p.text.trim().isNotEmpty); + if (text) return (title: '正在回复', detail: ''); + if (reasoning) return (title: '思考中', detail: ''); + } + break; + } + return (title: '思考中', detail: ''); + } + + /// The running turn started with the newest user message. + int _runningStart() { + for (var i = chat.msgs.length - 1; i >= 0; i--) { + if (chat.msgs[i].type == 'user') return chat.msgs[i].created; + } + return 0; + } + + String _elapsedSince(int start) { + if (start <= 0) return ''; + final secs = + ((DateTime.now().millisecondsSinceEpoch - start) / 1000).round(); + if (secs <= 0) return ''; + if (secs < 60) return '$secs 秒'; + return '${secs ~/ 60}:${(secs % 60).toString().padLeft(2, '0')}'; + } + + /// dsh-Go's activity strip: the current step and its clock, above the input. + Widget _activityStrip() { + final theme = Theme.of(context); + final scheme = theme.colorScheme; + final act = _activity(); + final elapsed = _elapsedSince(_runningStart()); + return Padding( + padding: const EdgeInsets.fromLTRB(14, 2, 14, 2), + child: Row( + children: [ + SizedBox( + width: 13, + height: 13, + child: CircularProgressIndicator( + strokeWidth: 1.7, + color: scheme.primary, + ), + ), + const SizedBox(width: 8), + Expanded( + child: Text.rich( + TextSpan(children: [ + TextSpan( + text: act.title, + style: TextStyle( + fontSize: 12.5, + fontWeight: FontWeight.w600, + color: scheme.onSurface, + ), + ), + if (act.detail.isNotEmpty) + TextSpan( + text: ' · ${act.detail}', + style: TextStyle(fontSize: 12, color: theme.hintColor), + ), + if (elapsed.isNotEmpty) + TextSpan( + text: ' · $elapsed', + style: TextStyle(fontSize: 12, color: theme.hintColor), + ), + ]), + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ), + ], + ), + ); + } + String _turnDuration(Message m) { var start = 0; final idx = chat.msgs.indexWhere((x) => x.id == m.id); diff --git a/lib/screens/sessions_screen.dart b/lib/screens/sessions_screen.dart index 47dfc3a..c9d49f8 100644 --- a/lib/screens/sessions_screen.dart +++ b/lib/screens/sessions_screen.dart @@ -257,17 +257,20 @@ class _SessionListPaneState extends State { List<_SessionGroup> _groups(List sessions) { final map = >{}; for (final session in sessions) { + // Group on a separator-normalised key so a Windows server's mix of + // `\` and `/` does not split one project into two. final key = _isChatDirectory(session.directory) ? '\u0000chats' - : session.directory; + : slashPath(session.directory); map.putIfAbsent(key, () => []).add(session); } final groups = [ for (final entry in map.entries) _SessionGroup( key: entry.key, - label: _groupLabel(entry.key), - path: entry.key == '\u0000chats' ? '' : entry.key, + label: _groupLabel(entry.value.first.directory), + // The first session's own path: the server knows that spelling. + path: entry.key == '\u0000chats' ? '' : entry.value.first.directory, sessions: entry.value ..sort((a, b) => b.updated.compareTo(a.updated)), ), @@ -294,50 +297,74 @@ class _SessionListPaneState extends State { Widget _groupHeader(_SessionGroup group, {required bool collapsed}) { final theme = Theme.of(context); - return InkWell( - onTap: () => setState(() { - if (collapsed) { - _collapsed.remove(group.key); - } else { - _collapsed.add(group.key); - } - }), - child: Padding( - padding: const EdgeInsets.fromLTRB(14, 10, 4, 4), - child: Row( - children: [ - Icon(collapsed ? Icons.chevron_right : Icons.expand_more, - size: 16, color: theme.hintColor), - const SizedBox(width: 2), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + final scheme = theme.colorScheme; + final radius = BorderRadius.circular(10); + // A tinted band, at least a session row's height: a project reads as a + // section, not as another row. + return Padding( + padding: const EdgeInsets.fromLTRB(8, 10, 8, 2), + child: Material( + color: scheme.surfaceContainerHighest.withValues(alpha: 0.5), + borderRadius: radius, + clipBehavior: Clip.antiAlias, + child: InkWell( + onTap: () => setState(() { + if (collapsed) { + _collapsed.remove(group.key); + } else { + _collapsed.add(group.key); + } + }), + child: ConstrainedBox( + constraints: const BoxConstraints(minHeight: 56), + child: Padding( + padding: const EdgeInsets.fromLTRB(10, 10, 4, 10), + child: Row( children: [ - Text( - group.label.isEmpty ? '未命名项目' : group.label, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: const TextStyle( - fontSize: 12.5, fontWeight: FontWeight.w700), - ), - if (group.path.isNotEmpty) - Text( - group.path, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: - TextStyle(fontSize: 10.5, color: theme.hintColor), + Icon(collapsed ? Icons.chevron_right : Icons.expand_more, + size: 18, color: scheme.onSurfaceVariant), + const SizedBox(width: 6), + Icon(Icons.folder_outlined, + size: 16, color: scheme.primary), + const SizedBox(width: 6), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + group.label.isEmpty ? '未命名项目' : group.label, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 13.5, + fontWeight: FontWeight.w700, + color: scheme.onSurface), + ), + if (group.path.isNotEmpty) + Padding( + padding: const EdgeInsets.only(top: 2), + child: Text( + group.path, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 11, color: theme.hintColor), + ), + ), + ], ), + ), + IconButton( + icon: const Icon(Icons.add, size: 18), + tooltip: '在此项目新会话', + visualDensity: VisualDensity.compact, + onPressed: () => _newSession(directory: group.path), + ), ], ), ), - IconButton( - icon: const Icon(Icons.add, size: 18), - tooltip: '在此项目新会话', - visualDensity: VisualDensity.compact, - onPressed: () => _newSession(directory: group.path), - ), - ], + ), ), ), ); diff --git a/lib/state.dart b/lib/state.dart index 71efa1f..1ec445f 100644 --- a/lib/state.dart +++ b/lib/state.dart @@ -474,16 +474,14 @@ class AppState extends ChangeNotifier { String projectLabelFor(String directory) { if (directory.isEmpty) return ''; for (final project in projects) { - if (project.canonical == directory) return project.label; + if (samePath(project.canonical, directory)) return project.label; } - final trimmed = directory.replaceAll(RegExp(r'/+$'), ''); - final index = trimmed.lastIndexOf('/'); - return index >= 0 ? trimmed.substring(index + 1) : trimmed; + return pathLeaf(directory); } ProjectInfo? projectFor(String directory) { for (final project in projects) { - if (project.canonical == directory) return project; + if (samePath(project.canonical, directory)) return project; } return null; } diff --git a/lib/widgets/composer_box.dart b/lib/widgets/composer_box.dart index 1c380a1..acf6c05 100644 --- a/lib/widgets/composer_box.dart +++ b/lib/widgets/composer_box.dart @@ -187,7 +187,13 @@ class _ComposerBoxState extends State { Expanded(child: _field()), const SizedBox(width: 4), if (accessory != null) ...[ - accessory, + // The keys are 36 high and the row aligns to its bottom: + // lift the smaller accessory by half the difference so it + // sits on the keys' centre line, not below it. + Padding( + padding: const EdgeInsets.only(bottom: 10), + child: accessory, + ), const SizedBox(width: 2), ], widget.trailing, diff --git a/pubspec.yaml b/pubspec.yaml index 89e5e1e..73bda42 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.18+318 +version: 0.3.19+319 environment: sdk: ^3.14.0 diff --git a/test/paths_test.dart b/test/paths_test.dart new file mode 100644 index 0000000..e838881 --- /dev/null +++ b/test/paths_test.dart @@ -0,0 +1,33 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:openchamber/api/models.dart'; + +void main() { + test('a Windows project path reads as its folder name', () { + expect(pathLeaf(r'C:\msys64\home\Gary\Sources\pineapple-notepad'), + 'pineapple-notepad'); + expect(pathLeaf('/home/blumia/Sources/telegram/'), 'telegram'); + expect(pathLeaf('relative'), 'relative'); + + expect( + ProjectInfo(id: 'p', canonical: r'C:\work\pineapple-notepad').label, + 'pineapple-notepad', + ); + expect( + ProjectInfo(id: 'p', canonical: '/w/x', name: '显式名称').label, + '显式名称', + ); + }); + + test('the same place compares across separators and Windows case', () { + expect(samePath(r'C:\x\y', 'C:/x/y'), isTrue); + expect(samePath(r'C:\X\y', r'c:\x\Y'), isTrue); + expect(samePath('/a/b/', '/a/b'), isTrue); + expect(samePath('/a/b', '/a/c'), isFalse); + // A POSIX path stays case-sensitive. + expect(samePath('/a/B', '/a/b'), isFalse); + }); + + test('slashPath only unifies separators', () { + expect(slashPath(r'C:\a\b\'), 'C:/a/b'); + }); +}