Merge branch 'worktree-agent-a785be85dc8fbff78'

This commit is contained in:
2026-12-02 20:15:14 +00:00
26 changed files with 1105 additions and 96 deletions
@@ -19,7 +19,9 @@ import '../domain/chat_commands.dart';
import 'chat_command_actions.dart';
import 'chat_command_palette.dart';
import 'chat_composer_controller.dart';
import 'chat_send_later_menu.dart';
import 'chat_send_usage_ring.dart';
import '../domain/chat_send_later.dart';
import 'chat_thread_controller.dart';
import 'chat_composer_paste_focus.dart';
import 'chat_harness_command_loader.dart';
@@ -792,8 +794,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
/// Builds the chips' exact wire parts and hands them to the composer with the
/// draft's text and operation id. The chips clear with the text as the
/// prompt leaves; a refusal that restores the text restores them too, so
/// the draft and its files stay together.
Future<void> _send() async {
/// the draft and its files stay together. A [sendAt] (epoch ms, from
/// "Send later…") asks the server to hold the message until then.
Future<void> _send({int sendAt = 0}) async {
final composer = widget.composer;
if (_uploading || composer.sending || composer.draft.trim().isEmpty) {
return;
@@ -849,7 +852,7 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
if (keptAttachments.isNotEmpty) {
setState(() => _replaceAttachments(const [], const []));
}
final accepted = await composer.send(attachments: parts);
final accepted = await composer.send(attachments: parts, sendAt: sendAt);
if (!mounted || accepted || keptAttachments.isEmpty) return;
if (_attachments.isEmpty && composer.draft == sentText) {
setState(() => _replaceAttachments(keptAttachments, keptBytes));
@@ -1354,21 +1357,38 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
// One shape with or without usage (a report never remounts the
// button): the hover text can grow with usage, while assistive
// technology still names the button by its label alone.
button: (tooltip) => Semantics(
label: label,
child: Tooltip(
message: tooltip,
excludeFromSemantics: true,
child: IconButton.filled(
key: const Key('chat-composer-primary'),
style: tinted == null
? null
: IconButton.styleFrom(
backgroundColor: tinted.primary,
foregroundColor: tinted.onPrimary,
),
onPressed: enabled ? press : null,
icon: const Icon(Icons.arrow_upward),
button: (tooltip) => ChatSendLaterMenu(
// Only an ordinary message can be scheduled, not a command or a
// shell line.
enabled:
enabled &&
!_paletteCompletes() &&
!chatDraftIsShell(composer.draft) &&
chatCommandWord(composer.draft) == null,
info: tooltip == label ? null : tooltip.substring(label.length).trim(),
usageReset: (now) => chatSendLaterUsageReset(usage?.accountUsage, now),
onSchedule: (at) => unawaited(_send(sendAt: at.millisecondsSinceEpoch)),
builder: (context, open) => Semantics(
label: label,
child: Tooltip(
message: tooltip,
excludeFromSemantics: true,
// On an enabled button a touch long-press opens Send later…,
// whose menu repeats the usage line; a disabled one shows the
// tooltip. A pointer still shows the tooltip on hover.
triggerMode: enabled ? TooltipTriggerMode.manual : null,
child: IconButton.filled(
onLongPress: open,
key: const Key('chat-composer-primary'),
style: tinted == null
? null
: IconButton.styleFrom(
backgroundColor: tinted.primary,
foregroundColor: tinted.onPrimary,
),
onPressed: enabled ? press : null,
icon: const Icon(Icons.arrow_upward),
),
),
),
),
@@ -0,0 +1,150 @@
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/services.dart';
import '../domain/chat_send_later.dart';
import 'chat_schedule_time.dart';
const String chatSendLaterLabel = 'Send later…';
const String chatSendLaterPickLabel = 'Pick a time…';
/// The send button's secondary action: right-click, long-press, the context
/// menu key or Shift+F10 on it (or the screen reader's custom action) opens
/// "Send later…" with quick times and a time picker. A chosen time is handed
/// to [onSchedule]; the message takes the ordinary send path with `send_at`.
///
/// On touch the long-press opens this menu instead of the button's tooltip,
/// so the tooltip's account and usage line ([info]) heads the menu.
class ChatSendLaterMenu extends StatefulWidget {
const ChatSendLaterMenu({
super.key,
required this.enabled,
required this.onSchedule,
required this.builder,
this.info,
this.usageReset,
this.now = DateTime.now,
});
/// Whether the draft is a message that can be scheduled.
final bool enabled;
final String? info;
final DateTime? Function(DateTime now)? usageReset;
final void Function(DateTime at) onSchedule;
/// Builds the send button, given the callback that opens the menu.
final Widget Function(BuildContext context, VoidCallback open) builder;
final DateTime Function() now;
@override
State<ChatSendLaterMenu> createState() => _ChatSendLaterMenuState();
}
class _ChatSendLaterMenuState extends State<ChatSendLaterMenu> {
final _menu = MenuController();
void _open([Offset? position]) {
if (_menu.isOpen) _menu.close();
setState(() {});
_menu.open(position: position);
}
Future<void> _pickTime() async {
final now = widget.now();
final initial = TimeOfDay.fromDateTime(now.add(const Duration(hours: 1)));
final picked = await showTimePicker(
context: context,
initialTime: TimeOfDay(hour: initial.hour, minute: 0),
helpText: 'Send at',
// The same 24-hour clock as "Scheduled · sends at 21:03".
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
child: child!,
),
);
if (!mounted || picked == null || !widget.enabled) return;
widget.onSchedule(
chatSendLaterAt(widget.now(), picked.hour, picked.minute),
);
}
String _label(BuildContext context, ChatSendLaterChoice choice) {
final time = chatScheduleTime(context, choice.at, now: widget.now);
return switch (choice.kind) {
ChatSendLaterKind.halfHour => 'In 30 minutes · $time',
ChatSendLaterKind.hour => 'In 1 hour · $time',
ChatSendLaterKind.tomorrowMorning => 'Tomorrow at 9:00',
ChatSendLaterKind.usageReset => 'At usage reset · $time',
};
}
@override
Widget build(BuildContext context) {
final now = widget.now();
final choices = chatSendLaterChoices(
now,
usageReset: widget.usageReset?.call(now),
);
final theme = Theme.of(context);
final info = widget.info;
return MenuAnchor(
controller: _menu,
menuChildren: [
if (info != null && info.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
child: Text(
info,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
),
Padding(
key: const Key('chat-send-later-title'),
padding: const EdgeInsets.fromLTRB(12, 8, 12, 4),
child: Row(
mainAxisSize: MainAxisSize.min,
spacing: 12,
children: [
Icon(
Icons.schedule_send,
color: theme.colorScheme.onSurfaceVariant,
),
Text(chatSendLaterLabel, style: theme.textTheme.titleSmall),
],
),
),
for (final choice in choices)
MenuItemButton(
key: Key('chat-send-later-${choice.kind.name}'),
onPressed: widget.enabled
? () => widget.onSchedule(choice.at)
: null,
child: Text(_label(context, choice)),
),
MenuItemButton(
key: const Key('chat-send-later-pick'),
leadingIcon: const Icon(Icons.access_time),
onPressed: widget.enabled ? _pickTime : null,
child: const Text(chatSendLaterPickLabel),
),
],
child: CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.contextMenu): _open,
const SingleActivator(LogicalKeyboardKey.f10, shift: true): _open,
},
child: GestureDetector(
onSecondaryTapUp: (details) => _open(details.localPosition),
child: Semantics(
customSemanticsActions: {
const CustomSemanticsAction(label: chatSendLaterLabel): _open,
},
child: widget.builder(context, _open),
),
),
),
);
}
}