Chat info: Session section with native id, resume command and export
The chat information sheet gains a Session section: the harness's native session id (copy), harness, directory, a verified resume command (copy) and Export conversation (Markdown), Export JSON and, for Claude Code, Export native session (the JSONL transcript). Server: chat_sessions rows carry resume_command and native_export; new chat_export command builds Markdown/JSON from the same paged history chat_messages serves (bounded at 8 MiB), refuses non-operator sessions. App: exports go through the artifact file bridge (web download, share sheet on phones).
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../artifacts/actions/artifact_file.dart';
|
||||
import '../../artifacts/actions/artifact_file_bridge.dart';
|
||||
import '../../artifacts/actions/artifact_transfer.dart';
|
||||
import '../data/chat_repository.dart';
|
||||
import '../domain/chat_session_handoff.dart';
|
||||
|
||||
/// Exports one chat through `chat_export` and hands the file to the host the
|
||||
/// same way the artifact viewer does: a browser download on the web, the share
|
||||
/// sheet (which offers saving) on phones. One export runs at a time.
|
||||
class ChatExportController extends ChangeNotifier {
|
||||
ChatExportController({
|
||||
required this.repository,
|
||||
required this.sessionId,
|
||||
this.bridge = const ArtifactFileBridge(),
|
||||
bool? share,
|
||||
}) : share = share ?? !kIsWeb;
|
||||
|
||||
final ChatRepository repository;
|
||||
final String sessionId;
|
||||
final ArtifactFileBridge bridge;
|
||||
|
||||
/// True hands the file to the share sheet; false downloads/saves it.
|
||||
final bool share;
|
||||
|
||||
ChatExportFormat? _active;
|
||||
String? _status;
|
||||
bool _disposed = false;
|
||||
|
||||
ChatExportFormat? get active => _active;
|
||||
bool get busy => _active != null;
|
||||
String? get status => _status;
|
||||
|
||||
Future<void> export(ChatExportFormat format) async {
|
||||
if (busy) return;
|
||||
final useShare = share && bridge.canShare;
|
||||
if (!useShare && !bridge.canDownload) {
|
||||
_set(null, bridge.downloadUnavailableMessage);
|
||||
return;
|
||||
}
|
||||
_set(format, 'Preparing export…');
|
||||
final JsonMap file;
|
||||
try {
|
||||
file = await repository.export(sessionId, format.wire);
|
||||
} catch (error) {
|
||||
_set(null, 'Could not export the chat: $error');
|
||||
return;
|
||||
}
|
||||
final artifact = ArtifactFile(
|
||||
name: '${file['name']}',
|
||||
mimeType: '${file['mime'] ?? ''}'.isEmpty
|
||||
? 'text/plain'
|
||||
: '${file['mime']}',
|
||||
bytes: Uint8List.fromList(utf8.encode('${file['content'] ?? ''}')),
|
||||
);
|
||||
ArtifactTransferResult result;
|
||||
try {
|
||||
result = useShare
|
||||
? await bridge.shareFile(artifact)
|
||||
: await bridge.saveFile(artifact);
|
||||
} catch (error) {
|
||||
_set(null, 'Could not save ${artifact.name}: $error');
|
||||
return;
|
||||
}
|
||||
final truncated = file['truncated'] == true
|
||||
? ' Older messages were left out to fit the size limit.'
|
||||
: '';
|
||||
final message = switch (result.state) {
|
||||
ArtifactTransferState.saved => 'Exported ${artifact.name}.$truncated',
|
||||
ArtifactTransferState.shared => 'Shared ${artifact.name}.$truncated',
|
||||
ArtifactTransferState.canceled => 'Export canceled.',
|
||||
_ => result.message.isEmpty ? 'Export failed.' : result.message,
|
||||
};
|
||||
_set(null, message);
|
||||
}
|
||||
|
||||
void _set(ChatExportFormat? active, String? status) {
|
||||
_active = active;
|
||||
_status = status;
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../ui/text/monospace.dart';
|
||||
import '../domain/chat_session_handoff.dart';
|
||||
import '../ui/sessions/chat_create_fields.dart';
|
||||
import 'chat_export_controller.dart';
|
||||
|
||||
/// The info sheet's "Session" section: the harness's native session id with a
|
||||
/// copy control, the harness and the working directory, the verified terminal
|
||||
/// command that resumes the session, and the export actions.
|
||||
class ChatSessionSection extends StatefulWidget {
|
||||
const ChatSessionSection({
|
||||
super.key,
|
||||
required this.handoff,
|
||||
required this.exporter,
|
||||
required this.cupertino,
|
||||
});
|
||||
|
||||
final ChatSessionHandoff handoff;
|
||||
final ChatExportController exporter;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<ChatSessionSection> createState() => _ChatSessionSectionState();
|
||||
}
|
||||
|
||||
class _ChatSessionSectionState extends State<ChatSessionSection> {
|
||||
/// Which copy control last succeeded, shown as "Copied" for a moment.
|
||||
String? _copied;
|
||||
Timer? _reset;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_reset?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _copy(String key, String text) async {
|
||||
await Clipboard.setData(ClipboardData(text: text));
|
||||
if (!mounted) return;
|
||||
setState(() => _copied = key);
|
||||
_reset?.cancel();
|
||||
_reset = Timer(const Duration(seconds: 2), () {
|
||||
if (mounted) setState(() => _copied = null);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = widget.cupertino;
|
||||
final handoff = widget.handoff;
|
||||
final secondary = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final body = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyLarge;
|
||||
final title = cupertino
|
||||
? CupertinoTheme.of(
|
||||
context,
|
||||
).textTheme.textStyle.copyWith(fontWeight: FontWeight.w600)
|
||||
: Theme.of(context).textTheme.titleSmall;
|
||||
final label =
|
||||
(cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodySmall)
|
||||
?.copyWith(color: secondary);
|
||||
final mono = body?.copyWith(fontFamily: appMonospaceFamily);
|
||||
final muted = body?.copyWith(color: secondary);
|
||||
|
||||
Widget fact(String key, String name, String value, {bool code = false}) {
|
||||
final known = value.isNotEmpty;
|
||||
return Padding(
|
||||
key: Key('chat-session-$key'),
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(name, style: label),
|
||||
Text(
|
||||
known ? value : 'Unavailable',
|
||||
key: Key('chat-session-value-$key'),
|
||||
style: !known ? muted : (code ? mono : body),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: widget.exporter,
|
||||
builder: (context, _) {
|
||||
final exporter = widget.exporter;
|
||||
final status = exporter.status;
|
||||
return Padding(
|
||||
key: const Key('chat-session-section'),
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(24, 12, 24, 6),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Session', style: title),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Expanded(
|
||||
child: fact('id', 'Session ID', handoff.id, code: true),
|
||||
),
|
||||
_ActionButton(
|
||||
key: const Key('chat-session-copy-id'),
|
||||
cupertino: cupertino,
|
||||
label: _copied == 'id' ? 'Copied' : 'Copy',
|
||||
semanticsLabel: _copied == 'id'
|
||||
? 'Copied'
|
||||
: 'Copy session ID',
|
||||
icon: _copied == 'id'
|
||||
? (cupertino ? CupertinoIcons.checkmark : Icons.check)
|
||||
: (cupertino
|
||||
? CupertinoIcons.doc_on_doc
|
||||
: Icons.copy_outlined),
|
||||
onPressed: handoff.id.isEmpty
|
||||
? null
|
||||
: () => _copy('id', handoff.id),
|
||||
),
|
||||
],
|
||||
),
|
||||
fact('harness', 'Harness', chatBackendLabel(handoff.backend)),
|
||||
fact('directory', 'Directory', handoff.directory, code: true),
|
||||
if (handoff.resumeCommand.isNotEmpty)
|
||||
fact(
|
||||
'resume',
|
||||
'Resume in a terminal',
|
||||
handoff.resumeCommand,
|
||||
code: true,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
if (handoff.resumeCommand.isNotEmpty)
|
||||
_ActionButton(
|
||||
key: const Key('chat-session-copy-resume'),
|
||||
cupertino: cupertino,
|
||||
label: _copied == 'resume'
|
||||
? 'Copied'
|
||||
: 'Copy resume command',
|
||||
icon: _copied == 'resume'
|
||||
? (cupertino ? CupertinoIcons.checkmark : Icons.check)
|
||||
: (cupertino
|
||||
? CupertinoIcons
|
||||
.chevron_left_slash_chevron_right
|
||||
: Icons.terminal),
|
||||
onPressed: () => _copy('resume', handoff.resumeCommand),
|
||||
),
|
||||
_exportButton(
|
||||
ChatExportFormat.markdown,
|
||||
'Export conversation',
|
||||
cupertino
|
||||
? CupertinoIcons.square_arrow_up
|
||||
: Icons.ios_share,
|
||||
),
|
||||
_exportButton(
|
||||
ChatExportFormat.json,
|
||||
'Export JSON',
|
||||
cupertino ? CupertinoIcons.doc_text : Icons.data_object,
|
||||
),
|
||||
if (handoff.nativeExport)
|
||||
_exportButton(
|
||||
ChatExportFormat.native,
|
||||
'Export native session',
|
||||
cupertino
|
||||
? CupertinoIcons.doc
|
||||
: Icons.description_outlined,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (status != null && status.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(
|
||||
status,
|
||||
key: const Key('chat-session-export-status'),
|
||||
style: label,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _exportButton(ChatExportFormat format, String label, IconData icon) {
|
||||
final exporter = widget.exporter;
|
||||
return _ActionButton(
|
||||
key: Key('chat-session-export-${format.wire}'),
|
||||
cupertino: widget.cupertino,
|
||||
label: label,
|
||||
icon: icon,
|
||||
busy: exporter.active == format,
|
||||
onPressed: exporter.busy ? null : () => exporter.export(format),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A standard text button with a leading icon, in the host's style.
|
||||
class _ActionButton extends StatelessWidget {
|
||||
const _ActionButton({
|
||||
super.key,
|
||||
required this.cupertino,
|
||||
required this.label,
|
||||
required this.icon,
|
||||
required this.onPressed,
|
||||
this.semanticsLabel,
|
||||
this.busy = false,
|
||||
});
|
||||
|
||||
final bool cupertino;
|
||||
final String label;
|
||||
final String? semanticsLabel;
|
||||
final IconData icon;
|
||||
final VoidCallback? onPressed;
|
||||
final bool busy;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Widget leading = busy
|
||||
? (cupertino
|
||||
? const CupertinoActivityIndicator()
|
||||
: const SizedBox.square(
|
||||
dimension: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
))
|
||||
: Icon(icon, size: 18);
|
||||
final child = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
leading,
|
||||
const SizedBox(width: 6),
|
||||
Flexible(child: Text(label, semanticsLabel: semanticsLabel)),
|
||||
],
|
||||
);
|
||||
final button = cupertino
|
||||
? CupertinoButton(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||
onPressed: onPressed,
|
||||
child: child,
|
||||
)
|
||||
: TextButton(onPressed: onPressed, child: child);
|
||||
return button;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,11 @@ import '../ui/sessions/session_actions.dart';
|
||||
import '../ui/transcript/chat_markdown_view.dart';
|
||||
import '../ui/transcript/chat_message_view.dart';
|
||||
import '../ui/transcript/chat_injected_rows.dart';
|
||||
import '../../artifacts/actions/artifact_file_bridge.dart';
|
||||
import '../domain/chat_session_handoff.dart';
|
||||
import 'chat_account_usage_section.dart';
|
||||
import 'chat_export_controller.dart';
|
||||
import 'chat_session_section.dart';
|
||||
import 'chat_background_tasks.dart';
|
||||
import 'chat_command_actions.dart';
|
||||
import 'chat_composer_bar.dart';
|
||||
@@ -75,6 +79,7 @@ class ChatThreadView extends StatefulWidget {
|
||||
this.onCreatedSession,
|
||||
this.onSessionRenamed,
|
||||
this.onSessionClosed,
|
||||
this.fileBridge = const ArtifactFileBridge(),
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
@@ -96,6 +101,9 @@ class ChatThreadView extends StatefulWidget {
|
||||
/// `/close` was accepted: the conversation is finished here as on the web.
|
||||
final VoidCallback? onSessionClosed;
|
||||
|
||||
/// The host file actions the info sheet's export uses; tests inject one.
|
||||
final ArtifactFileBridge fileBridge;
|
||||
|
||||
/// The list row's title when this visit knows it; a deep link may not.
|
||||
final String title;
|
||||
|
||||
@@ -332,16 +340,31 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
Future<void> _openInfo() async {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final exporter = ChatExportController(
|
||||
repository: ChatRepository(widget.gateway),
|
||||
sessionId: widget.sessionId,
|
||||
bridge: widget.fileBridge,
|
||||
);
|
||||
try {
|
||||
await _showInfo(cupertino, exporter);
|
||||
} finally {
|
||||
exporter.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showInfo(bool cupertino, ChatExportController exporter) async {
|
||||
final handoff = ChatSessionHandoff.from(widget.sessionId, widget.session);
|
||||
Widget sheet() => _ChatInfoSheet(
|
||||
controller: _controller,
|
||||
handoff: handoff,
|
||||
exporter: exporter,
|
||||
);
|
||||
if (cupertino) {
|
||||
await showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (sheetContext) => Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: SafeArea(
|
||||
child: CupertinoPopupSurface(
|
||||
child: _ChatInfoSheet(controller: _controller),
|
||||
),
|
||||
),
|
||||
child: SafeArea(child: CupertinoPopupSurface(child: sheet())),
|
||||
),
|
||||
);
|
||||
return;
|
||||
@@ -351,7 +374,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
showDragHandle: true,
|
||||
isScrollControlled: true,
|
||||
useSafeArea: true,
|
||||
builder: (sheetContext) => _ChatInfoSheet(controller: _controller),
|
||||
builder: (sheetContext) => sheet(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1541,9 +1564,15 @@ String _chatInfoDollars(num value) {
|
||||
/// The "Chat information" panel. It rebuilds from the controller, so metrics
|
||||
/// that arrive while it is open replace the displayed snapshot.
|
||||
class _ChatInfoSheet extends StatelessWidget {
|
||||
const _ChatInfoSheet({required this.controller});
|
||||
const _ChatInfoSheet({
|
||||
required this.controller,
|
||||
required this.handoff,
|
||||
required this.exporter,
|
||||
});
|
||||
|
||||
final ChatThreadController controller;
|
||||
final ChatSessionHandoff handoff;
|
||||
final ChatExportController exporter;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -1586,6 +1615,12 @@ class _ChatInfoSheet extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
ChatSessionSection(
|
||||
handoff: handoff,
|
||||
exporter: exporter,
|
||||
cupertino: cupertino,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
);
|
||||
if (!cupertino) return SingleChildScrollView(child: content);
|
||||
|
||||
@@ -178,6 +178,20 @@ class ChatRepository {
|
||||
gateway.call('chat_rename', {
|
||||
'chat_rename': {'session_id': sessionId, 'title': title.trim()},
|
||||
});
|
||||
|
||||
/// The chat as one file: `chat_export_file` with name, mime and content.
|
||||
/// A reply without a file is refused rather than saved as an empty file.
|
||||
Future<JsonMap> export(String sessionId, String format) async {
|
||||
final reply = await gateway.call('chat_export', {
|
||||
'chat_export': {'session_id': sessionId, 'format': format},
|
||||
});
|
||||
final file = reply['chat_export_file'];
|
||||
if (file is! Map || '${file['name'] ?? ''}'.trim().isEmpty) {
|
||||
throw StateError('The server did not return an export file.');
|
||||
}
|
||||
return file.cast<String, dynamic>();
|
||||
}
|
||||
|
||||
Future<JsonMap> star(String sessionId, bool starred) =>
|
||||
gateway.call('chat_star', {
|
||||
'chat_query': {'session_id': sessionId, 'starred': starred},
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
|
||||
/// The facts the info sheet's "Session" section shows, read from the chat's
|
||||
/// `chat_sessions` row.
|
||||
///
|
||||
/// The chat id is the harness's native session id (Claude Code session UUID,
|
||||
/// Codex thread id, OpenCode `ses_` id). The resume command and native export
|
||||
/// flag come from the server, which checked each form against the harness
|
||||
/// CLI; an older server sends neither, and nothing is invented here.
|
||||
class ChatSessionHandoff {
|
||||
const ChatSessionHandoff({
|
||||
required this.id,
|
||||
required this.backend,
|
||||
required this.directory,
|
||||
required this.resumeCommand,
|
||||
required this.nativeExport,
|
||||
});
|
||||
|
||||
/// [row] may be null when the conversation was opened by id alone.
|
||||
factory ChatSessionHandoff.from(String sessionId, JsonMap? row) {
|
||||
String text(String key) => '${row?[key] ?? ''}'.trim();
|
||||
final id = text('id');
|
||||
return ChatSessionHandoff(
|
||||
id: id.isEmpty ? sessionId.trim() : id,
|
||||
backend: row == null
|
||||
? ''
|
||||
: (text('backend').isEmpty ? 'opencode' : text('backend')),
|
||||
directory: text('directory'),
|
||||
resumeCommand: text('resume_command'),
|
||||
nativeExport: row?['native_export'] == true,
|
||||
);
|
||||
}
|
||||
|
||||
final String id;
|
||||
|
||||
/// Empty when the row is unknown; a row without a backend is OpenCode.
|
||||
final String backend;
|
||||
final String directory;
|
||||
final String resumeCommand;
|
||||
final bool nativeExport;
|
||||
}
|
||||
|
||||
/// The formats `chat_export` accepts.
|
||||
enum ChatExportFormat {
|
||||
markdown('markdown'),
|
||||
json('json'),
|
||||
native('native');
|
||||
|
||||
const ChatExportFormat(this.wire);
|
||||
final String wire;
|
||||
}
|
||||
@@ -39,6 +39,17 @@ Future<FakeChatGateway> _thread(
|
||||
return gateway;
|
||||
}
|
||||
|
||||
/// "Unavailable" inside the usage metric rows only; the Session section says
|
||||
/// it too for a conversation opened without its list row.
|
||||
final _metricUnavailable = find.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget.key is ValueKey<String> &&
|
||||
(widget.key! as ValueKey<String>).value.startsWith('chat-info-metric-'),
|
||||
),
|
||||
matching: find.text('Unavailable'),
|
||||
);
|
||||
|
||||
Future<void> _openInfo(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(const Key('chat-info')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -109,7 +120,7 @@ void main() {
|
||||
|
||||
await _openInfo(tester);
|
||||
|
||||
expect(find.text('Unavailable'), findsNWidgets(4));
|
||||
expect(_metricUnavailable, findsNWidgets(4));
|
||||
expect(find.text('0'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-info-close')));
|
||||
@@ -128,7 +139,7 @@ void main() {
|
||||
await tester.pump();
|
||||
await _openInfo(tester);
|
||||
|
||||
expect(find.text('Unavailable'), findsNothing);
|
||||
expect(_metricUnavailable, findsNothing);
|
||||
expect(find.text('0 tok/s'), findsOneWidget);
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('0 / 1,000'), findsOneWidget);
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/artifacts/actions/artifact_file.dart';
|
||||
import 'package:pipelines_app/features/artifacts/actions/artifact_file_bridge.dart';
|
||||
import 'package:pipelines_app/features/artifacts/actions/artifact_transfer.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_session_handoff.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
const _id = '0b6f1c2e-1111-4222-8333-444455556666';
|
||||
const _resume = 'cd /work/app && claude --resume $_id';
|
||||
|
||||
JsonMap _row({String backend = 'claude', bool native = true}) => {
|
||||
'id': _id,
|
||||
'title': 'Fix tests',
|
||||
'backend': backend,
|
||||
'directory': '/work/app',
|
||||
'resume_command': _resume,
|
||||
'native_export': native,
|
||||
};
|
||||
|
||||
/// Answers chat_export with a fixed file; everything else as the thread fake.
|
||||
class _ExportGateway extends FakeChatGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (type != 'chat_export') return super.call(type, fields);
|
||||
calls.add((type: type, fields: fields));
|
||||
final format = fields['chat_export']['format'];
|
||||
return {
|
||||
'type': 'chat_export',
|
||||
'chat_export_file': {
|
||||
'session_id': _id,
|
||||
'format': format,
|
||||
'name': format == 'json' ? 'Fix-tests.json' : 'Fix-tests.md',
|
||||
'mime': format == 'json' ? 'application/json' : 'text/markdown',
|
||||
'content': '# Fix tests\n',
|
||||
'messages': 1,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Widget _host(Widget child, bool cupertino) => cupertino
|
||||
? CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.light),
|
||||
home: CupertinoPageScaffold(child: child),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
Future<
|
||||
({_ExportGateway gateway, List<ArtifactFile> shared, List<String> clipboard})
|
||||
>
|
||||
_open(WidgetTester tester, {required bool cupertino, JsonMap? row}) async {
|
||||
tester.view.physicalSize = const Size(800, 2400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final clipboard = <String>[];
|
||||
final messenger =
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
messenger.setMockMethodCallHandler(SystemChannels.platform, (call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
clipboard.add('${(call.arguments as Map)['text']}');
|
||||
}
|
||||
return null;
|
||||
});
|
||||
addTearDown(
|
||||
() => messenger.setMockMethodCallHandler(SystemChannels.platform, null),
|
||||
);
|
||||
final gateway = _ExportGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage([]);
|
||||
final shared = <ArtifactFile>[];
|
||||
final bridge = ArtifactFileBridge(
|
||||
shareSupported: true,
|
||||
downloadSupported: true,
|
||||
share: (file) async {
|
||||
shared.add(file);
|
||||
return const ArtifactTransferResult(ArtifactTransferState.shared, '');
|
||||
},
|
||||
download: (file) async {
|
||||
shared.add(file);
|
||||
return const ArtifactTransferResult(ArtifactTransferState.saved, '');
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: _id,
|
||||
session: row ?? _row(),
|
||||
onBack: () {},
|
||||
fileBridge: bridge,
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('chat-info')));
|
||||
await tester.pumpAndSettle();
|
||||
return (gateway: gateway, shared: shared, clipboard: clipboard);
|
||||
}
|
||||
|
||||
Future<void> _tap(WidgetTester tester, Key key) async {
|
||||
await tester.ensureVisible(find.byKey(key));
|
||||
await tester.tap(find.byKey(key));
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'cupertino' : 'material';
|
||||
|
||||
testWidgets('$host: shows the native id, harness and directory', (
|
||||
tester,
|
||||
) async {
|
||||
await _open(tester, cupertino: cupertino);
|
||||
expect(find.text('Session'), findsOneWidget);
|
||||
expect(find.text('Session ID'), findsOneWidget);
|
||||
expect(find.text(_id), findsOneWidget);
|
||||
expect(find.text('Claude'), findsOneWidget);
|
||||
expect(find.text('/work/app'), findsOneWidget);
|
||||
expect(find.text(_resume), findsOneWidget);
|
||||
expect(find.text('Export native session'), findsOneWidget);
|
||||
expect(find.bySemanticsLabel('Copy session ID'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('$host: copies the id and the resume command', (tester) async {
|
||||
final opened = await _open(tester, cupertino: cupertino);
|
||||
await _tap(tester, const Key('chat-session-copy-id'));
|
||||
expect(opened.clipboard, [_id]);
|
||||
expect(find.text('Copied'), findsOneWidget);
|
||||
await _tap(tester, const Key('chat-session-copy-resume'));
|
||||
expect(opened.clipboard, [_id, _resume]);
|
||||
await tester.pump(const Duration(seconds: 3));
|
||||
expect(find.text('Copied'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('$host: export hands the server file to the file action', (
|
||||
tester,
|
||||
) async {
|
||||
final opened = await _open(tester, cupertino: cupertino);
|
||||
await _tap(tester, const Key('chat-session-export-markdown'));
|
||||
await tester.pumpAndSettle();
|
||||
final request = opened.gateway.calls.lastWhere(
|
||||
(call) => call.type == 'chat_export',
|
||||
);
|
||||
expect(request.fields['chat_export'], {
|
||||
'session_id': _id,
|
||||
'format': 'markdown',
|
||||
});
|
||||
expect(opened.shared, hasLength(1));
|
||||
final file = opened.shared.single;
|
||||
expect(file.name, 'Fix-tests.md');
|
||||
expect(file.mimeType, 'text/markdown');
|
||||
expect(utf8.decode(file.bytes), '# Fix tests\n');
|
||||
expect(find.text('Shared Fix-tests.md.'), findsOneWidget);
|
||||
|
||||
await _tap(tester, const Key('chat-session-export-json'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened.shared.last.name, 'Fix-tests.json');
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('no native export or resume command when the row has none', (
|
||||
tester,
|
||||
) async {
|
||||
await _open(
|
||||
tester,
|
||||
cupertino: false,
|
||||
row: {'id': _id, 'directory': '/work/app'},
|
||||
);
|
||||
expect(find.text('OpenCode'), findsOneWidget);
|
||||
expect(find.text('Export native session'), findsNothing);
|
||||
expect(find.text('Copy resume command'), findsNothing);
|
||||
expect(find.text('Export conversation'), findsOneWidget);
|
||||
});
|
||||
|
||||
test('a conversation opened by id alone keeps the id', () {
|
||||
final handoff = ChatSessionHandoff.from('ses_abc', null);
|
||||
expect(handoff.id, 'ses_abc');
|
||||
expect(handoff.backend, '');
|
||||
expect(handoff.resumeCommand, '');
|
||||
});
|
||||
}
|
||||
@@ -26,6 +26,16 @@ int get _hits => int.tryParse(_params['hits'] ?? '') ?? 0;
|
||||
int get _chats => int.tryParse(_params['chats'] ?? '') ?? 0;
|
||||
bool get perfRunGraph => _params['graph'] == '1';
|
||||
|
||||
/// `?harness=claude|codex` makes the chats that harness's (default OpenCode),
|
||||
/// with the resume command the server would send for it.
|
||||
String get _harness => _params['harness'] ?? 'opencode';
|
||||
|
||||
String _resumeCommand(String id) => switch (_harness) {
|
||||
'claude' => 'cd /workspace/demo && claude --resume $id',
|
||||
'codex' => 'cd /workspace/demo && codex resume $id',
|
||||
_ => 'cd /workspace/demo && opencode --session $id',
|
||||
};
|
||||
|
||||
/// Whether a chat scroll option (tool/perf/chat_scroll_fixture.dart) shapes
|
||||
/// the transcripts instead of the bench's short markdown history.
|
||||
bool get _scrollVariety => ['msgs', 'rich', 'older'].any(_params.containsKey);
|
||||
@@ -142,9 +152,28 @@ JsonMap? perfChatReply(JsonMap request) {
|
||||
'id': 'perf-chat-$i',
|
||||
'title': 'Fixture chat ${i + 1}',
|
||||
'directory': '/workspace/demo',
|
||||
// Server-shaped handoff facts (chat_sessions rows carry them).
|
||||
if (_harness != 'opencode') 'backend': _harness,
|
||||
'resume_command': _resumeCommand('perf-chat-$i'),
|
||||
'native_export': _harness == 'claude',
|
||||
},
|
||||
],
|
||||
};
|
||||
case 'chat_export':
|
||||
final body = request['chat_export'];
|
||||
final format = body is Map ? '${body['format'] ?? ''}' : '';
|
||||
final json = format == 'json';
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_export',
|
||||
'chat_export_file': {
|
||||
'session_id': body is Map ? body['session_id'] : '',
|
||||
'format': format,
|
||||
'name': json ? 'Fixture-chat.json' : 'Fixture-chat.md',
|
||||
'mime': json ? 'application/json' : 'text/markdown',
|
||||
'content': json ? '{"messages":[]}\n' : '# Fixture chat\n',
|
||||
},
|
||||
};
|
||||
case 'chat_subscribe':
|
||||
return {'id': id, 'type': 'chat_subscribed'};
|
||||
case 'chat_shells':
|
||||
|
||||
Reference in New Issue
Block a user