Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat(mobile): send any file to a harness from the key bar's image key

tony21dee5dc6f8d
diff --git a/mobile/lib/phone/terminal_file_send.dart b/mobile/lib/phone/terminal_file_send.dart
new file mode 100644
index 000000000..210f915a8
--- /dev/null
+++ b/mobile/lib/phone/terminal_file_send.dart
@@ -0,0 +1,91 @@
+import 'package:file_selector/file_selector.dart';
+import 'package:flutter/foundation.dart';
+import 'package:flutter/services.dart';
+
+import 'package:harness_mobile/terminal/terminal_binary.dart'
+ show terminalLocalPasteFileMaxPayloadBytes;
+import 'package:harness_mobile/terminal/terminal_session.dart';
+
+/// Opens the system's document picker for one file — Files on iOS, the Storage Access Framework on
+/// Android. Null is the person backing out. Replaced in tests, where there is no picker to open.
+@visibleForTesting
+Future<XFile?> Function() pickTerminalFile = () => openFile();
+
+/// Said when the terminal the file was meant for is no longer the one to send it to.
+const fileSendChangedMessage =
+ 'The terminal changed before the file was sent, so nothing was sent.';
+
+/// Sends a file the person picks to [session] — the key bar's "Choose a file", the phone's half of
+/// dropping a file on a desktop pane. The machine writes the bytes to disk there and pastes that
+/// path into the prompt (`pasteFile` in the CLI's terminalStreamManager.ts), so the agent can
+/// read a PDF, a log or a zip it could not otherwise reach.
+///
+/// The caller checks `MachineState.terminalPasteFileAvailable` first: a CLI that never advertised
+/// it does not know the upload kind, and the bytes would go nowhere.
+///
+/// Every outcome worth telling the person about goes to [report]; backing out of the picker says
+/// nothing. A file that cannot go is said in the desktop's words for a dropped one: it could not
+/// be read, or it is larger than 20 MB.
+///
+/// ⚠️ **The file lands only in the stream it was picked for.** The picker can stay open for as long
+/// as the person likes, and in that time the page can have been swiped away or its stream taken
+/// over or reconnected. Nothing is sent unless [stillShowing] holds, the session still accepts
+/// input and its stream id is the one it had when the key was tapped — otherwise [report] hears
+/// [fileSendChangedMessage].
+Future<void> sendFileToTerminal({
+ required TerminalSession session,
+ required bool Function() stillShowing,
+ required void Function(String message) report,
+}) async {
+ final streamId = session.streamId;
+ bool stillOwnsSend() =>
+ stillShowing() && session.acceptsInput && session.streamId == streamId;
+
+ final XFile? picked;
+ try {
+ picked = await pickTerminalFile();
+ } on PlatformException {
+ report('Could not open the picker.');
+ return;
+ }
+ if (picked == null) return;
+ final name = picked.name;
+ // Measured before it is read: a file past the limit is refused without holding all of it.
+ try {
+ if (await picked.length() > terminalLocalPasteFileMaxPayloadBytes) {
+ report(
+ '$name is larger than ${_mb(terminalLocalPasteFileMaxPayloadBytes)}',
+ );
+ return;
+ }
+ } catch (_) {
+ // No size to read is no reason to refuse yet: the read below says whether the file is there.
+ }
+ final Uint8List bytes;
+ try {
+ bytes = await picked.readAsBytes();
+ } catch (_) {
+ report('Could not read $name');
+ return;
+ }
+ if (bytes.length > terminalLocalPasteFileMaxPayloadBytes) {
+ report(
+ '$name is larger than ${_mb(terminalLocalPasteFileMaxPayloadBytes)}',
+ );
+ return;
+ }
+ if (bytes.isEmpty) {
+ report('$name is empty.');
+ return;
+ }
+ if (!stillOwnsSend()) {
+ report(fileSendChangedMessage);
+ return;
+ }
+ if (!await session.pasteFile(name.isEmpty ? 'file' : name, bytes)) {
+ report('The file could not be sent.');
+ }
+}
+
+/// The desktop's `_mb`: a byte limit in whole megabytes.
+String _mb(int bytes) => '${bytes ~/ (1024 * 1024)} MB';
diff --git a/mobile/lib/phone/terminal_input_dock.dart b/mobile/lib/phone/terminal_input_dock.dart
index f518876e8..51b6bfaa0 100644
--- a/mobile/lib/phone/terminal_input_dock.dart
+++ b/mobile/lib/phone/terminal_input_dock.dart
@@ -36,6 +36,7 @@ class TerminalInputDock extends StatefulWidget {
this.onPaste,
this.onPickImage,
this.onTakePhoto,
+ this.onPickFile,
this.questionOpen = false,
this.hints = const [],
});
@@ -62,6 +63,9 @@ class TerminalInputDock extends StatefulWidget {
final VoidCallback? onPickImage;
final VoidCallback? onTakePhoto;
+ /// Any other file — see [TerminalKeyBar.onPickFile].
+ final VoidCallback? onPickFile;
+
/// How long the row takes to open or close, matched to the software
/// keyboard's own slide: iOS animates its keyboard over 250ms and Android
/// over roughly the same, both decelerating into place.
@@ -132,6 +136,7 @@ class _TerminalInputDockState extends State<TerminalInputDock>
onPaste: widget.onPaste,
onPickImage: widget.onPickImage,
onTakePhoto: widget.onTakePhoto,
+ onPickFile: widget.onPickFile,
questionOpen: widget.questionOpen,
// An agent's prompt takes `↵`; a plain shell does not — see
// [TerminalKeyBar.enginePrompt].
diff --git a/mobile/lib/phone/terminal_key_bar.dart b/mobile/lib/phone/terminal_key_bar.dart
index f7848777b..d2e3d6504 100644
--- a/mobile/lib/phone/terminal_key_bar.dart
+++ b/mobile/lib/phone/terminal_key_bar.dart
@@ -72,6 +72,7 @@ class TerminalKeyBar extends StatefulWidget {
this.onPaste,
this.onPickImage,
this.onTakePhoto,
+ this.onPickFile,
this.questionOpen = false,
this.enginePrompt = false,
this.hints = const [],
@@ -133,6 +134,10 @@ class TerminalKeyBar extends StatefulWidget {
final VoidCallback? onPickImage;
final VoidCallback? onTakePhoto;
+ /// Sending any other file, from the same key. Null on a pane whose machine never advertised
+ /// `terminalPasteFileAvailable`, for the same reason.
+ final VoidCallback? onPickFile;
+
@override
State<TerminalKeyBar> createState() => _TerminalKeyBarState();
}
@@ -142,6 +147,9 @@ class _TerminalKeyBarState extends State<TerminalKeyBar>
bool get _canSendImage =>
widget.onPickImage != null || widget.onTakePhoto != null;
+ /// Whether the send key is drawn at all: a picture, or a file, can go.
+ bool get _canSend => _canSendImage || widget.onPickFile != null;
+
/// Whether the phone's clipboard holds anything `paste` would send: text,
/// or an image where this pane takes one. The key is drawn only then — a
/// `paste` that answers "nothing on the clipboard" is a key that did
@@ -213,37 +221,46 @@ class _TerminalKeyBarState extends State<TerminalKeyBar>
action();
}
- /// The image key: asks WHICH picture, then hands off.
+ /// The send key: asks WHICH picture — or a file — then hands off.
///
/// The sheet only appears where there is a choice to make. A build with just
- /// one of the two wired goes straight there instead — a sheet with a single
+ /// one of them wired goes straight there instead — a sheet with a single
/// row is a tap spent on nothing.
void _sendImage(BuildContext context) {
final pick = widget.onPickImage;
final photo = widget.onTakePhoto;
- if (pick == null) {
- photo?.call();
- return;
- }
- if (photo == null) {
- pick();
- return;
- }
- showPhoneSheet(
- context,
- title: 'Send a picture to this harness',
- actions: [
+ final file = widget.onPickFile;
+ final actions = [
+ if (pick != null)
PhoneSheetAction(
icon: LucideIcons.image300,
label: 'Choose from library',
onTap: pick,
),
+ if (photo != null)
PhoneSheetAction(
icon: LucideIcons.camera300,
label: 'Take a photo',
onTap: photo,
),
- ],
+ if (file != null)
+ PhoneSheetAction(
+ icon: LucideIcons.paperclip300,
+ label: 'Choose a file',
+ onTap: file,
+ ),
+ ];
+ if (actions.length == 1) {
+ actions.single.onTap();
+ return;
+ }
+ if (actions.isEmpty) return;
+ showPhoneSheet(
+ context,
+ title: file == null
+ ? 'Send a picture to this harness'
+ : 'Send to this harness',
+ actions: actions,
);
}
@@ -426,10 +443,16 @@ class _TerminalKeyBarState extends State<TerminalKeyBar>
// were the same kind of thing, and an image button that looks like `esc`
// reads as something that will be typed at the agent.
final apart = <_Slot>[
- if (_canSendImage)
+ // Named for a picture wherever one can go — the file is one more row behind it — and
+ // for a file only where nothing else can.
+ if (_canSend)
_key(
- label: 'img',
- semanticLabel: 'Send image',
+ label: _canSendImage ? 'img' : 'file',
+ semanticLabel: !_canSendImage
+ ? 'Send file'
+ : widget.onPickFile != null
+ ? 'Send image or file'
+ : 'Send image',
onTap: () => _sendImage(context),
),
// The way back to a full screen of output, which on a phone is the only
diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dart
index 36a8c9f97..a3c73d837 100644
--- a/mobile/lib/phone/terminal_page.dart
+++ b/mobile/lib/phone/terminal_page.dart
@@ -58,6 +58,7 @@ import 'terminal_action_column.dart';
import 'terminal_chrome_scroll.dart';
import 'terminal_input_dock.dart';
import 'terminal_copy.dart';
+import 'terminal_file_send.dart';
import 'terminal_paste.dart';
import 'terminal_search.dart';
import 'tty.dart';
@@ -1947,6 +1948,36 @@ class _TerminalPageState extends State<TerminalPage>
}
}
+ /// The key bar's "Choose a file": the system's document picker, then the file to the machine,
+ /// which pastes its path there — see [sendFileToTerminal]. One picker at a time, shared with the
+ /// image picker ([_picking]): two system sheets stacked would be one too many.
+ Future<void> _sendFile(TerminalSession session) async {
+ if (_picking || !session.acceptsInput) return;
+ _picking = true;
+ final messenger = ScaffoldMessenger.maybeOf(context);
+ try {
+ await sendFileToTerminal(
+ session: session,
+ stillShowing: () =>
+ mounted &&
+ widget.isActive &&
+ identical(
+ widget.notifier
+ .paneOfAgent(widget.machineId, widget.agentId)
+ ?.session,
+ session,
+ ),
+ report: (message) {
+ if (mounted) {
+ messenger?.showSnackBar(SnackBar(content: Text(message)));
+ }
+ },
+ );
+ } finally {
+ _picking = false;
+ }
+ }
+
/// The composer starts OPEN here, and the phone owns that answer rather than the pane.
///
@override
@@ -2474,6 +2505,12 @@ class _TerminalPageState extends State<TerminalPage>
_sendImage(session, ImageSource.camera),
)
: null,
+ // The same rule for any other file: only a CLI that advertises
+ // `pasteFile` writes it out there.
+ onPickFile:
+ machine?.terminalPasteFileAvailable == true
+ ? () => unawaited(_sendFile(session))
+ : null,
),
],
),
diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock
index 488867a55..798521f08 100644
--- a/mobile/pubspec.lock
+++ b/mobile/pubspec.lock
@@ -177,6 +177,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.1"
+ file_selector:
+ dependency: "direct main"
+ description:
+ name: file_selector
+ sha256: bd15e43e9268db636b53eeaca9f56324d1622af30e5c34d6e267649758c84d9a
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.1.0"
+ file_selector_android:
+ dependency: transitive
+ description:
+ name: file_selector_android
+ sha256: d670cd0ce77a2e785b18d8b4d0a8d6a222d6a813ec9b7ddf2790a1b4fb6fa92c
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.5.2+11"
+ file_selector_ios:
+ dependency: transitive
+ description:
+ name: file_selector_ios
+ sha256: "5b42ec0ef7626124b4624ea244341e9df780406793c204e89fa68a2e71af115c"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.5.3+7"
file_selector_linux:
dependency: transitive
description:
@@ -201,6 +225,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.7.0"
+ file_selector_web:
+ dependency: transitive
+ description:
+ name: file_selector_web
+ sha256: "73181fbc5257776d8ecaa6a94ab3c8e920ad143b9132a6d984a9271dfc6928d3"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.9.5"
file_selector_windows:
dependency: transitive
description:
@@ -1101,4 +1133,4 @@ packages:
version: "0.0.6"
sdks:
dart: ">=3.13.0 <4.0.0"
- flutter: ">=3.44.0"
+ flutter: ">=3.47.0"
diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml
index 9ad3f89de..d67609db4 100644
--- a/mobile/pubspec.yaml
+++ b/mobile/pubspec.yaml
@@ -61,6 +61,11 @@ dependencies:
# are re-encoded to PNG before they leave — see `terminal/image_transcode.dart`
# for why the whole pipe past this point accepts nothing else.
image_picker: ^1.2.3
+ # Sending any other file to an agent — a PDF, a log, a zip — from the same key: the system's own
+ # document picker (Files on iOS, the Storage Access Framework on Android), which hands over one
+ # file the person chose and asks for no storage permission. The bytes go out as the CLI's
+ # `pasteFile` upload, which writes them on that machine and pastes the path.
+ file_selector: ^1.1.0
# Talking to an agent: tapping the terminal opens voice input before the
# keyboard (`phone/voice_input_panel.dart`). This only RECORDS — 16 kHz mono
diff --git a/mobile/test/phone_edge/focus_behavior_test.dart b/mobile/test/phone_edge/focus_behavior_test.dart
index 01ba44a1a..31557825f 100644
--- a/mobile/test/phone_edge/focus_behavior_test.dart
+++ b/mobile/test/phone_edge/focus_behavior_test.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:convert';
+import 'package:file_selector/file_selector.dart' show XFile;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -11,6 +12,7 @@ import 'package:harness_mobile/phone/machines_tab.dart';
import 'package:harness_mobile/phone/phone_search_catalog.dart'
show phoneAgentId;
import 'package:harness_mobile/phone/phone_shell_scope.dart';
+import 'package:harness_mobile/phone/terminal_file_send.dart';
import 'package:harness_mobile/phone/terminal_page.dart';
import 'package:harness_mobile/phone/terminal_search.dart';
import 'package:harness_mobile/phone/settings_page.dart';
@@ -1518,6 +1520,67 @@ void main() {
});
});
+ group('a file', () {
+ testWidgets('where the computer takes one: behind the same key, and out '
+ 'as an upload under its name', (tester) async {
+ final restore = pickTerminalFile;
+ addTearDown(() => pickTerminalFile = restore);
+ var picks = 0;
+ pickTerminalFile = () async {
+ picks++;
+ // Named by its path, as a picked file is on a phone.
+ return XFile.fromData(
+ Uint8List.fromList(utf8.encode('log line')),
+ path: '/picked/server.log',
+ );
+ };
+ final focus = await _Focus.open(tester);
+ focus.app.stateOf('m')!
+ ..terminalImagePasteAvailable = true
+ ..terminalPasteFileAvailable = true;
+ focus.fill();
+ await frames(tester);
+ await focus.tapPrompt();
+ await tester.pump();
+ raiseKeyboard(tester);
+ await frames(tester);
+
+ await tester.tap(
+ find.byKey(const ValueKey('terminal-key-Send image or file')),
+ );
+ await frames(tester);
+ await tester.tap(find.text('Choose a file'));
+ await frames(tester);
+
+ expect(picks, 1);
+ final begin = focus.sent
+ .where((frame) => frame.$1 == 'terminal_chunked_upload_begin')
+ .single
+ .$2;
+ expect(begin['uploadKind'], 'file');
+ expect(begin['filename'], 'server.log');
+ await focus.close();
+ });
+
+ testWidgets('where it does not, the key offers pictures only', (
+ tester,
+ ) async {
+ final focus = await _Focus.open(tester);
+ focus.app.stateOf('m')!.terminalImagePasteAvailable = true;
+ focus.fill();
+ await frames(tester);
+ await focus.tapPrompt();
+ await tester.pump();
+ raiseKeyboard(tester);
+ await frames(tester);
+
+ await tester.tap(find.byKey(const ValueKey('terminal-key-Send image')));
+ await frames(tester);
+ expect(find.text('Choose a file'), findsNothing);
+ await focus.close();
+ });
+ });
+
group('the sample', () {
testWidgets('its end card: set up a computer, or keep playing', (
tester,
diff --git a/mobile/test/terminal_file_send_test.dart b/mobile/test/terminal_file_send_test.dart
new file mode 100644
index 000000000..93db0c9fa
--- /dev/null
+++ b/mobile/test/terminal_file_send_test.dart
@@ -0,0 +1,217 @@
+import 'dart:async';
+
+import 'package:file_selector/file_selector.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/phone/terminal_file_send.dart';
+import 'package:harness_mobile/terminal/terminal_binary.dart';
+import 'package:harness_mobile/terminal/terminal_session.dart';
+
+import 'terminal_panel_fixture.dart';
+
+/// A picked file whose size and bytes are said separately — what the picker hands over for a file
+/// it can measure without reading, or one it cannot read at all.
+class _File extends XFile {
+ _File(super.path, {this.size, this.content, this.unreadable = false});
+
+ final int? size;
+ final Uint8List? content;
+ final bool unreadable;
+
+ @override
+ String get name => path;
+
+ @override
+ Future<int> length() async => size ?? content?.length ?? 0;
+
+ @override
+ Future<Uint8List> readAsBytes() async {
+ if (unreadable) throw const _Unreadable();
+ return content ?? Uint8List(0);
+ }
+}
+
+class _Unreadable implements Exception {
+ const _Unreadable();
+}
+
+/// The key bar's "Choose a file", without the page around it: what it sends, and when it refuses
+/// to send at all.
+void main() {
+ late List<(String, Map<String, dynamic>)> sent;
+ late List<String> reports;
+ late TerminalSession session;
+ late Future<XFile?> Function() restore;
+
+ setUp(() {
+ sent = [];
+ reports = [];
+ session = controllingSession(
+ send: (type, payload) async {
+ sent.add((type, payload));
+ return true;
+ },
+ sendBinary: (_) async => true,
+ );
+ restore = pickTerminalFile;
+ });
+
+ tearDown(() {
+ pickTerminalFile = restore;
+ session.dispose();
+ });
+
+ Future<void> sendPicked(XFile? file, {bool Function()? stillShowing}) {
+ pickTerminalFile = () async => file;
+ return sendFileToTerminal(
+ session: session,
+ stillShowing: stillShowing ?? () => true,
+ report: reports.add,
+ );
+ }
+
+ List<String> types() => [for (final (type, _) in sent) type];
+
+ test('the file goes out as an upload under its own name', () async {
+ unawaited(
+ sendPicked(_File('report.pdf', content: Uint8List.fromList([1, 2, 3]))),
+ );
+ await pumpEventQueue();
+
+ final begin = sent.firstWhere(
+ (s) => s.$1 == 'terminal_chunked_upload_begin',
+ );
+ expect(begin.$2['uploadKind'], 'file');
+ expect(begin.$2['filename'], 'report.pdf');
+ expect(begin.$2['totalBytes'], 3);
+ expect(reports, isEmpty);
+ });
+
+ test('backing out of the picker says nothing and sends nothing', () async {
+ await sendPicked(null);
+
+ expect(sent, isEmpty);
+ expect(reports, isEmpty);
+ });
+
+ test('a picker that cannot open says so', () async {
+ pickTerminalFile = () async => throw PlatformException(code: 'denied');
+
+ await sendFileToTerminal(
+ session: session,
+ stillShowing: () => true,
+ report: reports.add,
+ );
+
+ expect(reports, ['Could not open the picker.']);
+ expect(sent, isEmpty);
+ });
+
+ test('a file over the limit is refused before it is read, in the '
+ 'desktop’s words', () async {
+ await sendPicked(
+ _File(
+ 'big.zip',
+ size: terminalLocalPasteFileMaxPayloadBytes + 1,
+ unreadable: true,
+ ),
+ );
+
+ expect(reports, ['big.zip is larger than 20 MB']);
+ expect(sent, isEmpty);
+ });
+
+ test('a file that grew past the limit by the time it was read is still '
+ 'refused', () async {
+ await sendPicked(
+ _File(
+ 'big.zip',
+ size: 1,
+ content: Uint8List(terminalLocalPasteFileMaxPayloadBytes + 1),
+ ),
+ );
+
+ expect(reports, ['big.zip is larger than 20 MB']);
+ expect(sent, isEmpty);
+ });
+
+ test('a file that cannot be read says which', () async {
+ await sendPicked(_File('locked.key', size: 4, unreadable: true));
+
+ expect(reports, ['Could not read locked.key']);
+ expect(sent, isEmpty);
+ });
+
+ test('an empty file is not sent', () async {
+ await sendPicked(_File('empty.txt', content: Uint8List(0)));
+
+ expect(reports, ['empty.txt is empty.']);
+ expect(sent, isEmpty);
+ });
+
+ test(
+ 'a stream that changed while the picker was open gets nothing',
+ () async {
+ pickTerminalFile = () async {
+ session.streamId = 's2';
+ return _File('notes.md', content: Uint8List.fromList([1]));
+ };
+
+ await sendFileToTerminal(
+ session: session,
+ stillShowing: () => true,
+ report: reports.add,
+ );
+
+ expect(reports, [fileSendChangedMessage]);
+ expect(types(), isNot(contains('terminal_chunked_upload_begin')));
+ },
+ );
+
+ test('a page no longer showing this session sends nothing', () async {
+ var showing = true;
+ pickTerminalFile = () async {
+ showing = false;
+ return _File('notes.md', content: Uint8List.fromList([1]));
+ };
+
+ await sendFileToTerminal(
+ session: session,
+ stillShowing: () => showing,
+ report: reports.add,
+ );
+
+ expect(reports, [fileSendChangedMessage]);
+ expect(sent, isEmpty);
+ });
+
+ test('a stream taken over while the picker was open gets nothing', () async {
+ pickTerminalFile = () async {
+ session.status = TerminalSessionStatus.takenOver;
+ return _File('notes.md', content: Uint8List.fromList([1]));
+ };
+
+ await sendFileToTerminal(
+ session: session,
+ stillShowing: () => true,
+ report: reports.add,
+ );
+
+ expect(reports, [fileSendChangedMessage]);
+ expect(types(), isNot(contains('terminal_chunked_upload_begin')));
+ });
+
+ test('an upload the machine refuses says it could not be sent', () async {
+ final done = sendPicked(
+ _File('notes.md', content: Uint8List.fromList([1, 2])),
+ );
+ await pumpEventQueue();
+ await session.handleFrame('terminal_chunked_upload_begin_result', {
+ 'streamId': session.streamId,
+ 'accepted': false,
+ });
+ await done;
+
+ expect(reports, ['The file could not be sent.']);
+ });
+}
diff --git a/mobile/test/terminal_key_bar_test.dart b/mobile/test/terminal_key_bar_test.dart
index 0467e930a..6613f38c4 100644
--- a/mobile/test/terminal_key_bar_test.dart
+++ b/mobile/test/terminal_key_bar_test.dart
@@ -885,24 +885,26 @@ void main() {
});
group('img', () {
- Widget bar({VoidCallback? pick, VoidCallback? photo}) => MaterialApp(
- home: Scaffold(
- body: Align(
- alignment: Alignment.bottomCenter,
- child: SizedBox(
- width: 375,
- child: TerminalKeyBar(
- terminal: terminal,
- enabled: true,
- enginePrompt: true,
- onDismissKeyboard: () {},
- onPickImage: pick,
- onTakePhoto: photo,
+ Widget bar({VoidCallback? pick, VoidCallback? photo, VoidCallback? file}) =>
+ MaterialApp(
+ home: Scaffold(
+ body: Align(
+ alignment: Alignment.bottomCenter,
+ child: SizedBox(
+ width: 375,
+ child: TerminalKeyBar(
+ terminal: terminal,
+ enabled: true,
+ enginePrompt: true,
+ onDismissKeyboard: () {},
+ onPickImage: pick,
+ onTakePhoto: photo,
+ onPickFile: file,
+ ),
+ ),
),
),
- ),
- ),
- );
+ );
final image = find.byKey(const ValueKey('terminal-key-Send image'));
final newline = find.byKey(const ValueKey('terminal-key-Newline'));
final hide = find.byKey(const ValueKey('terminal-key-Hide keyboard'));
@@ -940,6 +942,48 @@ void main() {
expect((picks, photos), (0, 1));
expect(outbound, isEmpty, reason: 'nothing typed at the agent');
});
+
+ testWidgets('where a file can go too, it is one more row behind the same '
+ 'key', (tester) async {
+ var picks = 0, photos = 0, files = 0;
+ await tester.pumpWidget(
+ bar(pick: () => picks++, photo: () => photos++, file: () => files++),
+ );
+ final key = find.byKey(const ValueKey('terminal-key-Send image or file'));
+ expect(find.descendant(of: key, matching: find.text('img')), findsOne);
+ await tester.tap(key);
+ await tester.pumpAndSettle();
+ expect(find.text('Send to this harness'), findsOneWidget);
+ expect(find.text('Choose from library'), findsOneWidget);
+ expect(find.text('Take a photo'), findsOneWidget);
+
+ await tester.tap(find.text('Choose a file'));
+ await tester.pumpAndSettle();
+ expect((picks, photos, files), (0, 0, 1));
+ expect(outbound, isEmpty, reason: 'nothing typed at the agent');
+ });
+
+ testWidgets('a picture alone keeps its own sheet title', (tester) async {
+ await tester.pumpWidget(bar(pick: () {}, photo: () {}));
+ await tester.tap(image);
+ await tester.pumpAndSettle();
+ expect(find.text('Send a picture to this harness'), findsOneWidget);
+ expect(find.text('Choose a file'), findsNothing);
+ });
+
+ testWidgets('where only a file can go, the key says so and opens the '
+ 'picker at once', (tester) async {
+ var files = 0;
+ await tester.pumpWidget(bar(file: () => files++));
+ expect(image, findsNothing);
+ final key = find.byKey(const ValueKey('terminal-key-Send file'));
+ expect(find.descendant(of: key, matching: find.text('file')), findsOne);
+
+ await tester.tap(key);
+ await tester.pumpAndSettle();
+ expect(files, 1);
+ expect(find.text('Choose a file'), findsNothing, reason: 'no sheet');
+ });
});
group('paste comes and goes with the clipboard', () {