Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions lib/chat/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:math' as math;

import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:bao_editor/textmate/textmate_syntax.dart' show TextMateSyntax;
import 'package:flutter/gestures.dart' show kDoubleTapTimeout;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -336,10 +335,10 @@ class _ChatScreenState extends State<ChatScreen>
late final ChatSession _session = widget.session ?? ChatSession();
final GlobalKey<ChatComposerState> _composerKey = GlobalKey();

/// The suggested reply just put in the composer: its bar stays a double
/// click's time more, for a second click to send it.
String? _pickedReply;
Timer? _pickedReplyFor;
/// The suggested replies put in the composer, as put in, each on a line:
/// their bar stays while it holds just them, for more to be put in beside
/// them, or a second click to send one.
List<String> _pickedReplies = const [];
final GlobalKey _historyKey = GlobalKey();
bool _contextPanelOpen = false;
bool _renaming = false;
Expand Down Expand Up @@ -527,7 +526,6 @@ class _ChatScreenState extends State<ChatScreen>

@override
void dispose() {
_pickedReplyFor?.cancel();
_backMinimapRoom.dispose();
_session.removeListener(_checkStarting);
_session.removeListener(_followPlan);
Expand Down Expand Up @@ -817,35 +815,49 @@ class _ChatScreenState extends State<ChatScreen>
);
}

/// What the agent suggests the user send next, while nothing is typed:
/// one picked is put in the composer, to be edited and sent.
/// What the agent suggests the user send next, while nothing is typed
/// but those picked: each picked is put in the composer, on a line of its
/// own, to be edited and sent with the others.
Widget? _buildReplySuggestions() {
final suggestions = _session.replySuggestions;
if (suggestions.isEmpty) return null;
final draft = _session.draft;
final picked = _pickedReply != null && draft.content == _pickedReply;
if (!picked &&
final picked =
_pickedReplies.isNotEmpty &&
draft.images.isEmpty &&
draft.content == _pickedReplies.join('\n')
? _pickedReplies
: const <String>[];
if (picked.isEmpty &&
((draft.content?.trim().isNotEmpty ?? false) ||
draft.images.isNotEmpty)) {
return null;
}
// In place of what the composer holds: only those picked, or nothing.
void putIn(List<String> replies) {
_composerKey.currentState?.clear();
if (replies.isNotEmpty) draft.restore(replies.join('\n'), const []);
setState(() => _pickedReplies = replies);
}

return ReplySuggestionBar(
suggestions: suggestions,
picked: picked,
playKey:
'${identityHashCode(_session)}\u0000${suggestions.join('\u0000')}',
onPick: (said) {
draft.restore(said, const []);
_pickedReplyFor?.cancel();
setState(() => _pickedReply = said);
_pickedReplyFor = Timer(kDoubleTapTimeout, () {
if (mounted) setState(() => _pickedReply = null);
});
},
onPick: (said) => putIn([said]),
onToggle: (said) => putIn(
picked.contains(said)
? [
for (final other in picked)
if (other != said) other,
]
: [...picked, said],
),
onSend: (said) {
_pickedReplyFor?.cancel();
// Put in at the first click: sent now, not left there too.
if (_pickedReply == said) _composerKey.currentState?.clear();
_pickedReply = null;
if (picked.isNotEmpty) _composerKey.currentState?.clear();
setState(() => _pickedReplies = const []);
_session.send(
ComposerMessage(text: said),
editor: widget.openEditor,
Expand Down
68 changes: 55 additions & 13 deletions lib/chat/panels/reply_suggestion_bar.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import 'package:flutter/gestures.dart' show kDoubleTapTimeout;
import 'package:flutter/material.dart';

import '../../ide/ide_commands.dart' show ideUsesMacKeys;
import '../../ide/ide_hover.dart';
import '../../l10n/l10n.dart';
import '../../platform/held_keys.dart';
import '../../theme/app_theme.dart';
import '../../theme/workbench_theme.dart' show themeColors;
import '../widgets/hover_builder.dart';

/// What the agent suggests the user send next (see ReplySuggestions), on
/// top of what is over the empty composer: each a pill, put in the
/// composer at a click ([onPick]) to be edited and sent, sent as it is at a
/// second click soon after ([onSend]; the bar is kept that long); each
/// says so on hover. They flow as words do, but
/// composer at a click ([onPick]) to be edited and sent, in place of those
/// put in before; put in beside them, or taken out, at a click with ⌘ or
/// Ctrl held ([onToggle]), as files are picked; sent as it is at a second
/// click soon after ([onSend]). Each says so on hover; those in the
/// composer ([picked]) stand out. They flow as words do, but
/// piled on the composer: on to the line above when the row is full;
/// one wider than the row, its text on more lines.
///
Expand All @@ -23,14 +28,20 @@ class ReplySuggestionBar extends StatefulWidget {
super.key,
required this.suggestions,
required this.onPick,
required this.onToggle,
required this.onSend,
this.picked = const [],
this.playKey,
});

final List<String> suggestions;
final ValueChanged<String> onPick;
final ValueChanged<String> onToggle;
final ValueChanged<String> onSend;

/// Those in the composer, as put in.
final List<String> picked;

/// What they are shown for (a conversation's, and these suggestions):
/// played in once for each; null, each time.
final String? playKey;
Expand Down Expand Up @@ -113,7 +124,9 @@ class _ReplySuggestionBarState extends State<ReplySuggestionBar>
still: still,
child: _Pill(
text: said,
picked: widget.picked.contains(said),
onTap: () => widget.onPick(said),
onToggle: () => widget.onToggle(said),
onDoubleTap: () => widget.onSend(said),
),
),
Expand Down Expand Up @@ -160,12 +173,16 @@ class _Entering extends AnimatedWidget {
class _Pill extends StatefulWidget {
const _Pill({
required this.text,
required this.picked,
required this.onTap,
required this.onToggle,
required this.onDoubleTap,
});

final String text;
final bool picked;
final VoidCallback onTap;
final VoidCallback onToggle;
final VoidCallback onDoubleTap;

@override
Expand All @@ -177,8 +194,18 @@ class _PillState extends State<_Pill> {
/// it is sent. A click is taken at once, not once no second one came.
Duration? _clickedAt;

void _click() {
Future<void> _click() async {
final at = _clock.elapsed;
// ⌘ or Ctrl held, on any platform: put in beside the others, or taken
// out; clicked twice so, back as it was, not sent. Held as the system
// has it, not only the app: the app's may have missed its key going up.
if (await HeldKeys.commandOrControl()) {
if (!mounted) return;
_clickedAt = null;
widget.onToggle();
return;
}
if (!mounted) return;
final before = _clickedAt;
if (before != null && at - before <= kDoubleTapTimeout) {
_clickedAt = null;
Expand All @@ -192,8 +219,19 @@ class _PillState extends State<_Pill> {
@override
Widget build(BuildContext context) {
final line = widget.text.replaceAll(RegExp(r'\s+'), ' ').trim();
// In the composer: as a picked option in the panels, a list's
// selection in it, the focus border around it. Hovered, its selection
// deeper, not greyed by the hover's tint.
final colors = themeColors;
final selection = colors['list.activeSelectionBackground'];
final fill = widget.picked
? Color.alphaBlend(selection, AppColors.bubbleFill)
: AppColors.bubbleFill;
final hoveredFill = widget.picked
? Color.alphaBlend(selection, fill)
: Color.alphaBlend(AppColors.bubbleHover, fill);
return IdeHover(
message: context.l10n.replySuggestionHint,
message: context.l10n.replySuggestionHint(ideUsesMacKeys ? '⌘' : 'Ctrl'),
position: IdeHoverPosition.above,
child: HoverBuilder(
builder: (context, hovered) => GestureDetector(
Expand All @@ -209,19 +247,23 @@ class _PillState extends State<_Pill> {
// Hovered, the hover's tint over the fill, not in its
// place: the tint is faint, and on its way to it the
// fill would turn see-through, the page dark through it.
color: hovered
? Color.alphaBlend(
AppColors.bubbleHover,
AppColors.bubbleFill,
)
: AppColors.bubbleFill,
color: hovered ? hoveredFill : fill,
// A pill on one line; on more, its corners as round.
borderRadius: BorderRadius.circular(13),
border: Border.all(color: AppColors.bubbleBorder()),
border: Border.all(
color: widget.picked
? colors['focusBorder']
: AppColors.bubbleBorder(),
),
),
child: Text(
line,
style: TextStyle(color: AppColors.text, fontSize: 12.5),
style: TextStyle(
color: widget.picked
? colors['list.activeSelectionForeground']
: AppColors.text,
fontSize: 12.5,
),
),
),
),
Expand Down
14 changes: 7 additions & 7 deletions lib/chat/reply_suggestions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract final class ReplySuggestions {
static const tag = 'reply_suggestion';

/// The most shown.
static const max = 3;
static const max = 4;

/// The longest shown, in characters: a line to send, not a message.
static const maxLength = 80;
Expand All @@ -20,12 +20,12 @@ abstract final class ReplySuggestions {
static const on =
'<system-reminder>Reply suggestions are on: the user turned them on '
'in BaoCode. When you finish your turn and hand back to them, end your '
'last message with two or three things they might send you next: in '
'last message with two to four things they might send you next: in '
'their voice and their language, short (about 20 Chinese characters, '
'or 10 words, at most), each a different way on (go ahead, change '
'course, ask). They pick one to edit and send. The app shows them apart '
'from your message: do not speak of them. None while you are still '
'working.\n'
'or 10 words, at most), different ways on (go ahead, change course, '
'ask); some may go well together. They pick what to send, edit it and '
'send it. The app shows them apart from your message: do not speak of '
'them. None while you are still working.\n'
'\n'
'Write them as plain text in your reply, not as a tool call: each on a '
'line of its own, between exactly <$tag> and </$tag>, with nothing '
Expand All @@ -47,7 +47,7 @@ abstract final class ReplySuggestions {
/// With each message after, a word.
static const stillOn =
'<system-reminder>Reply suggestions still on: end your turn with two '
'or three short ones, as plain text, each on its own line: '
'to four short ones, as plain text, each on its own line: '
'<$tag>…</$tag>.</system-reminder>';

/// Once, when they turn them off.
Expand Down
11 changes: 8 additions & 3 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2200,9 +2200,14 @@
"queuedEdit": "Take back to edit",
"queuedSendNow": "Stop the agent and send this now",
"queuedRemove": "Remove from the queue",
"replySuggestionHint": "Click to put it in the input, double-click to send it",
"replySuggestionHint": "Click to put it in the input, double-click to send it, {key}-click to pick more than one",
"@replySuggestionHint": {
"description": "Hover of a reply the agent suggests, over the composer."
"description": "Hover of a reply the agent suggests, over the composer. {key} is ⌘ on macOS, Ctrl elsewhere.",
"placeholders": {
"key": {
"type": "String"
}
}
},
"stopConfirmMessage": "Stop the agent?",
"stopConfirmDetail": "{count, plural, =1{The task running in the background will stop too.} other{The {count} tasks running in the background will stop too.}}",
Expand Down Expand Up @@ -2592,7 +2597,7 @@
"@generalSettingsPromptSuggestions": {
"description": "Settings → General switch: whether the agent suggests, at the end of each turn, what the user might send next, shown over the composer."
},
"generalSettingsPromptSuggestionsDescription": "After each turn, two or three things you might send next, over the composer: click one to put it in the input and edit it, double-click to send it as it is; Tab in an empty input takes the first. The agent writes them at the end of its reply, with no extra request. Applies from the next message.",
"generalSettingsPromptSuggestionsDescription": "After each turn, two to four things you might send next, over the composer: click one to put it in the input and edit it, double-click to send it as it is; click with ⌘ or Ctrl held to put in more than one, each on its own line; Tab in an empty input takes the first. The agent writes them at the end of its reply, with no extra request. Applies from the next message.",
"generalSettingsCommitAttributionLabel": "Commit Attribution: {name}",
"@generalSettingsCommitAttributionLabel": {
"description": "The commit attribution dropdown, as read out: its setting and the choice in effect.",
Expand Down
8 changes: 4 additions & 4 deletions lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5708,11 +5708,11 @@ abstract class AppLocalizations {
/// **'Remove from the queue'**
String get queuedRemove;

/// Hover of a reply the agent suggests, over the composer.
/// Hover of a reply the agent suggests, over the composer. {key} is ⌘ on macOS, Ctrl elsewhere.
///
/// In en, this message translates to:
/// **'Click to put it in the input, double-click to send it'**
String get replySuggestionHint;
/// **'Click to put it in the input, double-click to send it, {key}-click to pick more than one'**
String replySuggestionHint(String key);

/// No description provided for @stopConfirmMessage.
///
Expand Down Expand Up @@ -6413,7 +6413,7 @@ abstract class AppLocalizations {
/// No description provided for @generalSettingsPromptSuggestionsDescription.
///
/// In en, this message translates to:
/// **'After each turn, two or three things you might send next, over the composer: click one to put it in the input and edit it, double-click to send it as it is; Tab in an empty input takes the first. The agent writes them at the end of its reply, with no extra request. Applies from the next message.'**
/// **'After each turn, two to four things you might send next, over the composer: click one to put it in the input and edit it, double-click to send it as it is; click with ⌘ or Ctrl held to put in more than one, each on its own line; Tab in an empty input takes the first. The agent writes them at the end of its reply, with no extra request. Applies from the next message.'**
String get generalSettingsPromptSuggestionsDescription;

/// The commit attribution dropdown, as read out: its setting and the choice in effect.
Expand Down
7 changes: 4 additions & 3 deletions lib/l10n/app_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3375,8 +3375,9 @@ class AppLocalizationsEn extends AppLocalizations {
String get queuedRemove => 'Remove from the queue';

@override
String get replySuggestionHint =>
'Click to put it in the input, double-click to send it';
String replySuggestionHint(String key) {
return 'Click to put it in the input, double-click to send it, $key-click to pick more than one';
}

@override
String get stopConfirmMessage => 'Stop the agent?';
Expand Down Expand Up @@ -3825,7 +3826,7 @@ class AppLocalizationsEn extends AppLocalizations {

@override
String get generalSettingsPromptSuggestionsDescription =>
'After each turn, two or three things you might send next, over the composer: click one to put it in the input and edit it, double-click to send it as it is; Tab in an empty input takes the first. The agent writes them at the end of its reply, with no extra request. Applies from the next message.';
'After each turn, two to four things you might send next, over the composer: click one to put it in the input and edit it, double-click to send it as it is; click with ⌘ or Ctrl held to put in more than one, each on its own line; Tab in an empty input takes the first. The agent writes them at the end of its reply, with no extra request. Applies from the next message.';

@override
String generalSettingsCommitAttributionLabel(String name) {
Expand Down
6 changes: 4 additions & 2 deletions lib/l10n/app_localizations_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3247,7 +3247,9 @@ class AppLocalizationsZh extends AppLocalizations {
String get queuedRemove => '移出队列';

@override
String get replySuggestionHint => '单击放进输入框,双击直接发送';
String replySuggestionHint(String key) {
return '单击放进输入框,双击直接发送,按住 $key 单击可多选';
}

@override
String get stopConfirmMessage => '要停止 Agent 吗?';
Expand Down Expand Up @@ -3673,7 +3675,7 @@ class AppLocalizationsZh extends AppLocalizations {

@override
String get generalSettingsPromptSuggestionsDescription =>
'每轮结束后,在输入框上方给出两三句你可能想发的话:单击放进输入框润色,双击直接发送;输入框空着时按 Tab 采用第一句。由 Agent 在回复末尾顺手写出,不额外请求模型。从下一条消息起生效。';
'每轮结束后,在输入框上方给出两到四句你可能想发的话:单击放进输入框润色,双击直接发送;按住 ⌘ 或 Ctrl 单击可多选,每句一行;输入框空着时按 Tab 采用第一句。由 Agent 在回复末尾顺手写出,不额外请求模型。从下一条消息起生效。';

@override
String generalSettingsCommitAttributionLabel(String name) {
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@
"queuedEdit": "撤回并编辑",
"queuedSendNow": "中断当前任务,立即发送",
"queuedRemove": "移出队列",
"replySuggestionHint": "单击放进输入框,双击直接发送",
"replySuggestionHint": "单击放进输入框,双击直接发送,按住 {key} 单击可多选",
"stopConfirmMessage": "要停止 Agent 吗?",
"stopConfirmDetail": "{count, plural, other{后台运行中的 {count} 个任务也会一并停止。}}",
"stopConfirmStop": "停止",
Expand Down Expand Up @@ -1052,7 +1052,7 @@
"generalSettingsQueuedAfterTurn": "当前任务完成后依次执行",
"generalSettingsQueuedDuringTurn": "插入当前任务",
"generalSettingsPromptSuggestions": "推荐回复",
"generalSettingsPromptSuggestionsDescription": "每轮结束后,在输入框上方给出两三句你可能想发的话:单击放进输入框润色,双击直接发送;输入框空着时按 Tab 采用第一句。由 Agent 在回复末尾顺手写出,不额外请求模型。从下一条消息起生效。",
"generalSettingsPromptSuggestionsDescription": "每轮结束后,在输入框上方给出两到四句你可能想发的话:单击放进输入框润色,双击直接发送;按住 ⌘ 或 Ctrl 单击可多选,每句一行;输入框空着时按 Tab 采用第一句。由 Agent 在回复末尾顺手写出,不额外请求模型。从下一条消息起生效。",
"generalSettingsCommitAttributionLabel": "提交署名: {name}",
"generalSettingsAttributionAgent": "跟随 Agent",
"generalSettingsAttributionAgentDetail": "Agent 自带的署名(如 Claude Code 的),或你在 ~/.claude/settings.json 中设置的 attribution。",
Expand Down
Loading