a6f0f0a1cb
A draft starting with ! shows a Shell mode indicator and runs through chat_shell_run instead of being sent to the agent; the chat's actions menu gains Run command. Each run is a terminal-style card among the turns with live output, Stop, its exit status, Copy output and Send to agent.
150 lines
4.9 KiB
Dart
150 lines
4.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/text/monospace.dart';
|
|
import '../../../ui/theme/app_theme.dart';
|
|
import '../conversation/chat_card_styles.dart';
|
|
import '../ui/sessions/chat_adaptive.dart';
|
|
import 'chat_shell_card_actions.dart';
|
|
import 'chat_shell_output_view.dart';
|
|
import 'chat_shell_run.dart';
|
|
import 'chat_shell_runs_controller.dart';
|
|
import 'chat_shell_status.dart';
|
|
|
|
/// One operator command in the transcript, as a terminal-style card in the
|
|
/// reading column: the command and folder, its live output, a spinner and
|
|
/// Stop while it runs, then its exit status, Copy output and Send to agent.
|
|
///
|
|
/// It listens to [controller] itself, so streamed output rebuilds only this
|
|
/// card, never the transcript.
|
|
class ChatShellRunCard extends StatefulWidget {
|
|
const ChatShellRunCard({
|
|
super.key,
|
|
required this.controller,
|
|
required this.runId,
|
|
});
|
|
|
|
final ChatShellRunsController controller;
|
|
final String runId;
|
|
|
|
@override
|
|
State<ChatShellRunCard> createState() => _ChatShellRunCardState();
|
|
}
|
|
|
|
class _ChatShellRunCardState extends State<ChatShellRunCard> {
|
|
bool _expanded = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino =
|
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
return ListenableBuilder(
|
|
listenable: widget.controller,
|
|
builder: (context, _) {
|
|
final run = widget.controller.run(widget.runId);
|
|
if (run == null) return const SizedBox.shrink();
|
|
final body = _body(context, run, cupertino);
|
|
return Semantics(
|
|
identifier: 'chat-shell-run-card',
|
|
container: true,
|
|
child: cupertino
|
|
? CupertinoListSection.insetGrouped(
|
|
backgroundColor: AppColors.groupedBackground,
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
children: [
|
|
Padding(padding: const EdgeInsets.all(16), child: body),
|
|
],
|
|
)
|
|
: Card(
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: body,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _body(BuildContext context, ChatShellRun run, bool cupertino) {
|
|
final controller = widget.controller;
|
|
final error = controller.errorFor(run.id);
|
|
final command = (chatCardBodyStyle(context, cupertino) ?? const TextStyle())
|
|
.copyWith(fontFamily: appMonospaceFamily, fontWeight: FontWeight.w600);
|
|
return Column(
|
|
key: ValueKey<String>('chat-shell-run-${run.id}'),
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.only(end: 12),
|
|
child: Icon(
|
|
cupertino
|
|
? CupertinoIcons.chevron_left_slash_chevron_right
|
|
: Icons.terminal,
|
|
color: chatCardSecondaryColor(context, cupertino),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'\$ ${run.command}',
|
|
key: const Key('chat-shell-run-command'),
|
|
style: command,
|
|
),
|
|
if (run.directory.isNotEmpty)
|
|
Text(
|
|
run.directory,
|
|
style: chatCardSecondaryStyle(context, cupertino),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
ChatShellStatus(run: run, cupertino: cupertino),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
ChatShellOutputView(
|
|
run: run,
|
|
cupertino: cupertino,
|
|
expanded: _expanded,
|
|
),
|
|
if (run.error.isNotEmpty && !run.running)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Text(
|
|
run.error,
|
|
style: chatCardSecondaryStyle(context, cupertino),
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
ChatShellCardActions(
|
|
run: run,
|
|
controller: controller,
|
|
cupertino: cupertino,
|
|
expanded: _expanded,
|
|
onToggleExpanded: () => setState(() => _expanded = !_expanded),
|
|
),
|
|
if (error != null)
|
|
Semantics(
|
|
liveRegion: true,
|
|
child: Text(
|
|
error,
|
|
key: const Key('chat-shell-run-error'),
|
|
style:
|
|
(chatCardBodyStyle(context, cupertino) ?? const TextStyle())
|
|
.copyWith(color: chatCardErrorColor(context, cupertino)),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|