Merge branches 'worktree-agent-a6019135c1d229f82' and 'worktree-agent-a64fb2f79d15cc2be' into worktree-agent-a717651aa412e3b7c

This commit is contained in:
2026-12-03 00:41:39 +00:00
19 changed files with 1053 additions and 49 deletions
@@ -32,33 +32,10 @@ class StageCaptureSection extends StatelessWidget {
final status = stage.stepStatus.trim().toLowerCase();
final pending =
capture == null && (status == 'running' || status == 'waiting');
final meta = [
'Visit ${stage.visit}',
if (stage.stepStatus.isNotEmpty) stage.stepStatus,
].join(' · ');
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(meta, style: Theme.of(context).textTheme.bodySmall),
if (capture != null) ...[
Text(
fileChangesSummary(capture),
style: Theme.of(context).textTheme.bodySmall,
),
if (capture.scope.isNotEmpty)
Text(
'Scope: ${capture.scope}',
style: Theme.of(context).textTheme.bodySmall,
),
],
],
),
),
StageCaptureHeading(stage: stage),
const Divider(height: 1),
if (capture == null)
_CaptureNote(
@@ -99,6 +76,38 @@ class StageCaptureSection extends StatelessWidget {
}
}
/// A stage/visit capture's heading: the visit and step status, the capture's
/// summary and its scope.
class StageCaptureHeading extends StatelessWidget {
const StageCaptureHeading({super.key, required this.stage});
final StageCapture stage;
@override
Widget build(BuildContext context) {
final capture = stage.capture;
final small = Theme.of(context).textTheme.bodySmall;
final meta = [
'Visit ${stage.visit}',
if (stage.stepStatus.isNotEmpty) stage.stepStatus,
].join(' · ');
return Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(meta, style: small),
if (capture != null) ...[
Text(fileChangesSummary(capture), style: small),
if (capture.scope.isNotEmpty)
Text('Scope: ${capture.scope}', style: small),
],
],
),
);
}
}
/// One changed file: its kind, path and line counts; tapping opens its diff.
/// [dense] draws it on one compact line (the path, then the counts), for a
/// card that lists many files in little space.
@@ -0,0 +1,248 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../domain/file_change.dart';
import '../domain/unified_patch.dart';
import '../domain/change_kind.dart';
import '../domain/change_wording.dart';
import 'capture_section.dart' show changeKindIcon;
import 'change_style.dart';
import 'file_diff_viewer.dart';
/// The window width from which the Changes surface shows its files beside
/// the selected file's diff instead of one row per file.
const double changesSplitMinWidth = 1000;
/// The narrowest pane that still fits the file list beside a readable diff;
/// a desktop window's detail pane beside the run list is usually narrower
/// than the window threshold.
const double changesSplitMinPaneWidth = 720;
/// Whether a Changes pane [paneWidth] wide splits into list and diff.
bool changesSplitFits(BuildContext context, double paneWidth) =>
MediaQuery.sizeOf(context).width >= changesSplitMinWidth &&
paneWidth >= changesSplitMinPaneWidth;
/// A desktop review layout: the changed files as a compact list on the left
/// and the selected file's diff on the right, like a code review tool.
///
/// While the view has focus, `j`/ArrowDown select the next file and
/// `k`/ArrowUp the previous one; Enter opens the selected file on its own
/// page. Keys typed into a text field are never taken.
class ChangesSplitView extends StatefulWidget {
const ChangesSplitView({super.key, required this.files, this.heading});
/// The files to review, in list order. Must not be empty.
final List<FileChange> files;
/// Shown above the file list (a visit's heading).
final Widget? heading;
@override
State<ChangesSplitView> createState() => _ChangesSplitViewState();
}
class _ChangesSplitViewState extends State<ChangesSplitView> {
final _focus = FocusNode(debugLabel: 'changes split');
final _listScroll = ScrollController();
List<GlobalKey> _rowKeys = const [];
int _index = 0;
@override
void initState() {
super.initState();
_rowKeys = _keysFor(widget.files);
}
@override
void didUpdateWidget(ChangesSplitView oldWidget) {
super.didUpdateWidget(oldWidget);
if (identical(oldWidget.files, widget.files)) return;
// Keep the same file selected across a refreshed reply when it is still
// listed; otherwise stay at the same position.
final path = oldWidget.files.isEmpty
? null
: oldWidget.files[_index.clamp(0, oldWidget.files.length - 1)].path;
final kept = widget.files.indexWhere((file) => file.path == path);
_index = kept >= 0
? kept
: _index.clamp(0, widget.files.isEmpty ? 0 : widget.files.length - 1);
_rowKeys = _keysFor(widget.files);
}
static List<GlobalKey> _keysFor(List<FileChange> files) => [
for (final file in files) GlobalKey(debugLabel: 'change row ${file.path}'),
];
@override
void dispose() {
_focus.dispose();
_listScroll.dispose();
super.dispose();
}
void _select(int index, {bool focus = false}) {
if (focus) _focus.requestFocus();
if (index < 0 || index >= widget.files.length) return;
final forward = index > _index;
if (index != _index) setState(() => _index = index);
// Keep the selected row in view once it is laid out at its new state.
WidgetsBinding.instance.addPostFrameCallback((_) {
final row = _rowKeys[index].currentContext;
if (row == null || !row.mounted) return;
Scrollable.ensureVisible(
row,
alignmentPolicy: forward
? ScrollPositionAlignmentPolicy.keepVisibleAtEnd
: ScrollPositionAlignmentPolicy.keepVisibleAtStart,
);
});
}
void _step(int delta) =>
_select((_index + delta).clamp(0, widget.files.length - 1));
KeyEventResult _handle(FocusNode node, KeyEvent event) {
if (event is KeyUpEvent) return KeyEventResult.ignored;
final primary = FocusManager.instance.primaryFocus;
final focused = primary?.context;
if (primary != node &&
focused != null &&
(focused.widget is EditableText ||
focused.findAncestorWidgetOfExactType<EditableText>() != null)) {
return KeyEventResult.ignored;
}
final keyboard = HardwareKeyboard.instance;
if (keyboard.isControlPressed ||
keyboard.isMetaPressed ||
keyboard.isAltPressed) {
return KeyEventResult.ignored;
}
final key = event.logicalKey;
if (key == LogicalKeyboardKey.arrowDown || key == LogicalKeyboardKey.keyJ) {
_step(1);
} else if (key == LogicalKeyboardKey.arrowUp ||
key == LogicalKeyboardKey.keyK) {
_step(-1);
} else if (event is KeyDownEvent &&
(key == LogicalKeyboardKey.enter ||
key == LogicalKeyboardKey.numpadEnter)) {
_openPage();
} else {
return KeyEventResult.ignored;
}
return KeyEventResult.handled;
}
void _openPage() =>
showFileDiffViewer(context, widget.files[_index], files: widget.files);
@override
Widget build(BuildContext context) {
final files = widget.files;
final index = _index.clamp(0, files.length - 1);
final file = files[index];
return LayoutBuilder(
builder: (context, constraints) {
final listWidth = (constraints.maxWidth * 0.28).clamp(260.0, 380.0);
return Focus(
focusNode: _focus,
onKeyEvent: _handle,
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(
width: listWidth,
child: Semantics(
container: true,
identifier: 'changes-file-list',
label: 'Changed files',
explicitChildNodes: true,
child: SingleChildScrollView(
key: const ValueKey('changes-split-list'),
controller: _listScroll,
padding: const EdgeInsets.only(bottom: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
?widget.heading,
for (var i = 0; i < files.length; i++)
_SplitFileRow(
key: _rowKeys[i],
file: files[i],
selected: i == index,
onTap: () => _select(i, focus: true),
),
],
),
),
),
),
const VerticalDivider(width: 1),
Expanded(
child: FileDiffViewer(
key: ValueKey<String>('changes-split-diff-${file.path}'),
file: file,
),
),
],
),
);
},
);
}
}
/// One file in the split list: its name with its folder below, so a long
/// path never hides the file name, and its line counts.
class _SplitFileRow extends StatelessWidget {
const _SplitFileRow({
super.key,
required this.file,
required this.selected,
required this.onTap,
});
final FileChange file;
final bool selected;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final mono = nativeDiffText(DefaultTextStyle.of(context).style);
final slash = file.path.lastIndexOf('/');
final name = slash < 0 ? file.path : file.path.substring(slash + 1);
final folder = slash < 0 ? '' : file.path.substring(0, slash);
return Semantics(
container: true,
button: true,
selected: selected,
label:
'Show diff for ${file.path}. '
'${changeKindTitle(file.kind)} · ${changeFileMeta(file)}',
excludeSemantics: true,
onTap: onTap,
child: ListTile(
dense: true,
visualDensity: VisualDensity.compact,
minLeadingWidth: 20,
selected: selected,
selectedTileColor: theme.colorScheme.secondaryContainer,
selectedColor: theme.colorScheme.onSecondaryContainer,
leading: Icon(changeKindIcon(file.kind), size: 20),
title: Text(
name,
style: mono,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
subtitle: folder.isEmpty
? null
: Text(folder, maxLines: 1, overflow: TextOverflow.ellipsis),
trailing: ChangeStatText(changeStat(file.added, file.removed)),
onTap: onTap,
),
);
}
}
@@ -6,6 +6,7 @@ import '../domain/change_wording.dart';
import '../domain/file_change.dart';
import '../domain/run_changes.dart';
import 'capture_section.dart';
import 'changes_split_view.dart';
import 'change_style.dart';
import 'file_diff_viewer.dart';
import 'visit_pager.dart';
@@ -97,7 +98,14 @@ class _ChangesViewerState extends State<ChangesViewer> {
static const _query = '';
@override
Widget build(BuildContext context) {
Widget build(BuildContext context) => LayoutBuilder(
builder: (context, constraints) =>
_build(context, split: changesSplitFits(context, constraints.maxWidth)),
);
/// [split] shows the files beside the selected file's diff (a wide pane)
/// rather than one row per file opening its own page.
Widget _build(BuildContext context, {required bool split}) {
final run = _run;
final captures = _captures;
final showSummary = widget.showSummary;
@@ -106,6 +114,7 @@ class _ChangesViewerState extends State<ChangesViewer> {
);
final note = showSummary ? runChangesNote(run) : '';
final visit = captures.isEmpty ? null : captures[_visitIndex];
final visitFiles = visit?.capture?.files ?? const <FileChange>[];
final hasVisitPager = !widget.finalOnly && captures.length > 1;
final pager = hasVisitPager
? ChangesVisitPager(
@@ -158,7 +167,17 @@ class _ChangesViewerState extends State<ChangesViewer> {
),
if (showSummary) const Divider(height: 1),
// The run's final changes: every changed path once, as it ended.
if (widget.finalOnly)
if (widget.finalOnly && split && run.files.isNotEmpty)
Expanded(
child: Padding(
padding: withBarClearance(context, EdgeInsets.zero),
child: ChangesSplitView(
key: const ValueKey<String>('changes-final-split'),
files: run.files,
),
),
)
else if (widget.finalOnly)
Expanded(
child: run.files.isEmpty
? SingleChildScrollView(
@@ -184,7 +203,31 @@ class _ChangesViewerState extends State<ChangesViewer> {
],
),
),
if (!widget.finalOnly)
if (!widget.finalOnly &&
split &&
visit != null &&
visitFiles.isNotEmpty)
Expanded(
child: Padding(
padding: hasVisitPager
? withBarClearance(context, EdgeInsets.zero)
: withTopBarClearance(context, EdgeInsets.zero),
child: ChangesSplitView(
key: ValueKey<String>(
'changes-visit-split-${visit.stage}-${visit.sequence}',
),
files: visitFiles,
heading: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
StageCaptureHeading(stage: visit),
const Divider(height: 1),
],
),
),
),
)
else if (!widget.finalOnly)
Expanded(
child: visit == null
? SingleChildScrollView(
+17
View File
@@ -1,3 +1,5 @@
import 'dart:async';
import '../../ui/adaptive/segmented_bar.dart';
import '../../shell/destination.dart';
import '../../shell/detail_page.dart';
@@ -15,6 +17,7 @@ import 'pending_run_store.dart';
import 'widgets/pipeline_bar_buttons.dart';
import 'widgets/pipeline_detail_panel.dart';
import 'widgets/pipeline_list_panel.dart';
import 'ui/run_pipeline_from_list.dart';
export 'pipeline_models.dart' show PipelineDetail, PipelineVersion;
@@ -223,6 +226,18 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
return _isRoutePin(detail) ? key : null;
}
/// A list row's Run: the same start flow as the detail's Run button.
void _runFromList(BuildContext context, PipelineSummary pipeline) =>
unawaited(
startPipelineRunFromList(
context: context,
pipeline: pipeline,
controller: _controller,
gateway: widget.gateway,
onRunStarted: widget.onRunStarted,
),
);
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
@@ -262,6 +277,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
child: PipelineListPanel(
controller: _controller,
onOpenInChat: widget.onOpenPipelineInChat,
onRun: _runFromList,
),
);
}
@@ -270,6 +286,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
child: PipelineListPanel(
controller: _controller,
onOpenInChat: widget.onOpenPipelineInChat,
onRun: _runFromList,
),
),
detailIdentity: _controller.selectedId,
@@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../pipeline_models.dart';
import '../pipeline_repository.dart';
import '../pipelines_controller.dart';
import 'run_pipeline_flow.dart';
import 'run_pipeline_wording.dart';
/// A list row's Run: reads the row's pipeline at its listed version, then
/// opens the same start flow as the detail's Run button. Nothing starts until
/// the form's own confirm; a refused read is shown, never a guessed form.
Future<void> startPipelineRunFromList({
required BuildContext context,
required PipelineSummary pipeline,
required PipelinesController controller,
required ApiGateway gateway,
ValueChanged<int>? onRunStarted,
}) async {
if (pipeline.archived) return;
final PipelineDetail detail;
try {
detail = await PipelinesRepository(
gateway,
).getPipeline(pipeline.id, pipeline.version);
} catch (error) {
if (!context.mounted) return;
ScaffoldMessenger.maybeOf(
context,
)?.showSnackBar(SnackBar(content: Text(describeRunPipelineError(error))));
return;
}
if (!context.mounted) return;
await openRunPipelineFlow(
context: context,
controller: controller,
detail: detail,
gateway: gateway,
onRunStarted: onRunStarted,
);
}
@@ -14,7 +14,8 @@ import '../pipelines_controller.dart';
import 'pipeline_controls.dart';
import 'pipeline_filter_page.dart';
import 'pipeline_scope_control.dart';
import '../../../ui/layout/app_overflow_menu.dart';
import '../../../shell/list_detail_policy.dart';
import 'pipeline_row_actions.dart';
/// The list's horizontal rhythm, matching the web's toolbar and row inset
/// (`var(--space-s)`: 12px). The detail pane keeps its own content padding.
@@ -26,12 +27,17 @@ class PipelineListPanel extends StatelessWidget {
super.key,
required this.controller,
this.onOpenInChat,
this.onRun,
});
final PipelinesController controller;
final Future<void> Function(BuildContext, PipelineSummary, PipelineRun?)?
onOpenInChat;
/// Opens the New run form for a row's pipeline (its menu's Run…, and its
/// trailing Run button on a wide list); null offers neither.
final void Function(BuildContext, PipelineSummary)? onRun;
@override
Widget build(BuildContext context) {
final filters = controller.filters;
@@ -230,6 +236,23 @@ class PipelineListPanel extends StatelessWidget {
final now = DateTime.now();
// The default padding is the media padding: the controls start below the
// top bar and the last row clears the floating tab bar.
return LayoutBuilder(
builder: (context, constraints) =>
_rows(context, header, items, now, constraints.maxWidth),
);
}
Widget _rows(
BuildContext context,
List<Widget> header,
List<PipelineSummary> items,
DateTime now,
double width,
) {
// A wide layout's list, beside its detail and wide enough, gives each row
// its own Run button beside its menu; a phone keeps Run in the menu.
final wide =
showsListBesideDetail(context) && width >= kPipelineRowRunButtonWidth;
return ListView.builder(
key: const Key('pipeline-list'),
itemCount: header.length + items.length,
@@ -271,22 +294,16 @@ class PipelineListPanel extends StatelessWidget {
: Text(
ServerContext.metadata(context, runStateLabel(badge.state)),
),
menu: onOpenInChat == null
? null
: AppOverflowMenu<bool>(
key: Key('pipeline-row-more-menu-${pipeline.id}'),
label: 'Pipeline actions',
sheetTitle: pipeline.displayName,
actions: const [
AppMenuAction<bool>(
value: true,
label: 'Send to chat…',
icon: Icons.chat_bubble_outline,
),
],
onSelected: (context, _) =>
onOpenInChat!(context, pipeline, run),
),
menu: pipelineRowActions(
pipeline: pipeline,
wide: wide,
onRun: onRun == null
? null
: (context) => onRun!(context, pipeline),
onOpenInChat: onOpenInChat == null
? null
: (context) => onOpenInChat!(context, pipeline, run),
),
);
},
);
@@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import '../../../ui/layout/app_overflow_menu.dart';
import '../pipeline_models.dart';
import '../ui/run_pipeline_wording.dart';
/// The pipeline list's width from which each row shows its own Run button
/// beside its menu; a narrower list keeps Run in the menu only.
const double kPipelineRowRunButtonWidth = 360;
const pipelineRowRunLabel = 'Run…';
Key pipelineRowRunKey(int id) => ValueKey('pipeline-row-run-$id');
Key pipelineRowRunMenuKey(int id) => ValueKey('pipeline-row-run-menu-$id');
Key pipelineRowMenuKey(int id) => ValueKey('pipeline-row-more-menu-$id');
enum _PipelineRowAction { run, sendToChat }
/// A pipeline row's trailing actions: its menu (Run…, Send to chat…) and, on
/// a [wide] list, a Run button before it. Run is not offered for an archived
/// pipeline, as its detail offers none. Null when there is nothing to offer.
Widget? pipelineRowActions({
required PipelineSummary pipeline,
required bool wide,
void Function(BuildContext)? onRun,
void Function(BuildContext)? onOpenInChat,
}) {
final run = pipeline.archived ? null : onRun;
final actions = [
if (run != null)
AppMenuAction(
key: pipelineRowRunMenuKey(pipeline.id),
value: _PipelineRowAction.run,
label: pipelineRowRunLabel,
icon: Icons.play_arrow_rounded,
),
if (onOpenInChat != null)
const AppMenuAction(
value: _PipelineRowAction.sendToChat,
label: 'Send to chat…',
icon: Icons.chat_bubble_outline,
),
];
if (actions.isEmpty) return null;
final menu = AppOverflowMenu<_PipelineRowAction>(
key: pipelineRowMenuKey(pipeline.id),
label: 'Pipeline actions',
sheetTitle: pipeline.displayName,
actions: actions,
onSelected: (context, action) => switch (action) {
_PipelineRowAction.run => run!(context),
_PipelineRowAction.sendToChat => onOpenInChat!(context),
},
);
if (!wide || run == null) return menu;
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Builder(
builder: (context) => TextButton.icon(
key: pipelineRowRunKey(pipeline.id),
onPressed: () => run(context),
icon: const Icon(Icons.play_arrow_rounded),
label: Text(
runPipelineActionLabel,
semanticsLabel: 'Run ${pipeline.displayName}',
),
),
),
menu,
],
);
}
@@ -11,12 +11,19 @@ bool canRetryRun(JsonMap? run) {
/// Whether [run] can be started again with its inputs: a finished run that
/// succeeded, was canceled or was interrupted, and names its pipeline. A
/// failed run has Retry instead.
bool canRunAgain(JsonMap? run) {
/// failed run has Retry instead in menus (see [canStartRunAgain]).
bool canRunAgain(JsonMap? run) =>
canStartRunAgain(run) && run!['status'] != 'failed';
/// Whether the New run form can be pre-filled from [run]: any finished run,
/// failed included, that names its pipeline. A failed run's banner offers it
/// beside Retry.
bool canStartRunAgain(JsonMap? run) {
if (run == null || run['executing'] == true) return false;
final pipeline = run['pipeline_id'];
return const {
'succeeded',
'failed',
'canceled',
'interrupted',
}.contains(run['status']) &&
+1 -1
View File
@@ -38,7 +38,7 @@ Future<void> startRunAgainFlow({
required ApiGateway gateway,
ValueChanged<int>? onRunStarted,
}) async {
if (!canRunAgain(run)) return;
if (!canStartRunAgain(run)) return;
final pipelineId = (run['pipeline_id'] as num).toInt();
final JsonMap full;
final PipelineDetail detail;
@@ -26,9 +26,11 @@ Widget buildMaterialRunDetail({
String? initialStageKey,
int? initialVisit,
void Function(String draft)? onSendToChat,
Widget? failureActions,
}) {
return RunDetailTabs(
run: run,
failureActions: failureActions,
copying: copying,
copyStatus: copyStatus,
onCopy: onCopy,
@@ -30,6 +30,7 @@ Widget runDetailSummaryTab({
ExpansibleController? inputController,
ExpansibleController? outputController,
Widget? graphPreview,
Widget? failureActions,
}) {
final rows = detailSummaryRows(run);
final identity = detailSummaryIdentity(run);
@@ -61,7 +62,9 @@ Widget runDetailSummaryTab({
),
),
),
SliverToBoxAdapter(child: RunFailureBanner(run: run)),
SliverToBoxAdapter(
child: RunFailureBanner(run: run, actions: failureActions),
),
SliverToBoxAdapter(
child: WarningsSection(messages: warningMessages(run['warnings'])),
),
@@ -56,10 +56,15 @@ class RunDetailTabs extends StatefulWidget {
this.initialStageKey,
this.initialVisit,
this.onSendToChat,
this.failureActions,
});
final JsonMap run;
/// What a failed run's "Why it failed" banner offers (Retry, Run again…,
/// Open in chat); null offers none.
final Widget? failureActions;
/// The host's own header: status, the run actions and notices. It floats
/// outside the tab body, so switching tabs never drops an action.
final Widget header;
@@ -458,6 +463,7 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
onCopy: widget.onCopy,
inputController: _inputSection,
outputController: _outputSection,
failureActions: widget.failureActions,
graphPreview: RunGraphPreview(
graph: detailGraph(widget.run),
run: widget.run,
@@ -12,6 +12,7 @@ import 'run_more_menu.dart';
import 'run_pipeline_link.dart';
import 'run_detail_content.dart';
import 'run_detail_material.dart';
import 'run_failure_actions.dart';
import 'runs_controller.dart';
import '../../../core/error_advice.dart';
import '../../../ui/status/error_notice.dart';
@@ -96,6 +97,14 @@ class _RunDetailViewState extends State<RunDetailView> {
onSendToChat: widget.onSendToChat == null
? null
: (draft) => widget.onSendToChat!(context, run, draft),
failureActions: RunFailureActions(
run: run,
gateway: widget.gateway,
onRunChanged: widget.controller.acceptRunDetail,
onRunOpened: widget.onRunOpened,
onRunAgain: widget.onRunAgain,
onOpenInChat: widget.onOpenInChat,
),
);
// The top bar becomes the run's: Back to the list, its title over its
// number, pipeline and version (a link to that pipeline when the host
@@ -181,14 +190,41 @@ class _RunDetailViewState extends State<RunDetailView> {
: widget.controller.error ?? 'Run details unavailable.';
// Back stays available while the detail is pending as well as after a
// failure, so a slow or refused request can never trap the destination.
// The more menu is there from the first frame: while the detail loads its
// items are listed from the run's list row, disabled until the detail
// they act on arrives.
final pending = _pendingRun();
return ShellBar(
title: 'Run',
onBack: widget.onBack,
hideNavigation: true,
actions: [
if (loading && pending != null)
RunMoreMenu(
run: pending,
gateway: widget.gateway,
onRunChanged: widget.controller.acceptRunDetail,
onDeleted: widget.controller.applyDeletion,
onOpenInChat: widget.onOpenInChat,
onRunAgain: widget.onRunAgain,
pending: true,
),
],
child: _placeholderBody(loading, message),
);
}
/// The selected run as its list row knows it, else only its id; null when
/// no run is selected.
JsonMap? _pendingRun() {
final id = widget.controller.selectedRunId;
if (id == null) return null;
for (final run in widget.controller.runs) {
if (run['id'] == id) return run;
}
return {'id': id};
}
Widget _placeholderBody(bool loading, String message) {
return Center(
child: Column(
@@ -0,0 +1,95 @@
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../actions/retry_action.dart';
import '../actions/retry_eligibility.dart';
import '../actions/retry_wording.dart';
import 'run_again_flow.dart';
const runFailureRetryKey = ValueKey<String>('run-failure-retry');
const runFailureRunAgainKey = ValueKey<String>('run-failure-run-again');
const runFailureOpenInChatKey = ValueKey<String>('run-failure-open-in-chat');
const runFailureOpenInChatLabel = 'Open in chat';
/// What a failed run's "Why it failed" banner offers: Retry (the server's
/// retry, as the more menu's), Run again… (the New run form pre-filled from
/// the run) and Open in chat (the run's send-to-chat flow, with its context).
///
/// Each is the existing action; one the host cannot apply is omitted. It stays
/// mounted while a picked flow runs, so a retry's result reaches the run.
class RunFailureActions extends StatefulWidget {
const RunFailureActions({
super.key,
required this.run,
required this.gateway,
required this.onRunChanged,
this.onRunOpened,
this.onRunAgain,
this.onOpenInChat,
});
final JsonMap run;
final ApiGateway gateway;
final ValueChanged<JsonMap> onRunChanged;
final ValueChanged<num>? onRunOpened;
final ValueChanged<JsonMap>? onRunAgain;
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
@override
State<RunFailureActions> createState() => _RunFailureActionsState();
}
class _RunFailureActionsState extends State<RunFailureActions> {
void _retry() => openRetryRunPrompt(
context,
run: widget.run,
gateway: widget.gateway,
onRunChanged: widget.onRunChanged,
onRunOpened: widget.onRunOpened,
owns: (owned) => mounted && retryRunId(widget.run) == owned,
);
@override
Widget build(BuildContext context) {
final run = widget.run;
final scheme = Theme.of(context).colorScheme;
final onBanner = TextButton.styleFrom(
foregroundColor: scheme.onErrorContainer,
);
final runAgain = widget.onRunAgain;
final openInChat = widget.onOpenInChat;
return Wrap(
spacing: 8,
runSpacing: 4,
children: [
if (retryRunId(run) != null && canRetryRun(run))
FilledButton.icon(
key: runFailureRetryKey,
style: FilledButton.styleFrom(
backgroundColor: scheme.error,
foregroundColor: scheme.onError,
),
onPressed: _retry,
icon: const Icon(Icons.replay),
label: const Text(retryActionLabel),
),
if (runAgain != null && canStartRunAgain(run))
TextButton.icon(
key: runFailureRunAgainKey,
style: onBanner,
onPressed: () => runAgain(run),
icon: const Icon(Icons.edit_note),
label: const Text(runAgainActionLabel),
),
if (openInChat != null)
TextButton.icon(
key: runFailureOpenInChatKey,
style: onBanner,
onPressed: () => openInChat(context, run),
icon: const Icon(Icons.chat_bubble_outline),
label: const Text(runFailureOpenInChatLabel),
),
],
);
}
}
@@ -6,10 +6,15 @@ import '../domain/run_outcome_line.dart';
/// The run Summary's prominent "Why it failed" note: a failed run's recorded
/// failure reason (else its diagnostic), selectable, at the top of the
/// Summary so the reason is read before the facts. Nothing for other runs.
///
/// [actions] (the run's Retry, Run again… and Open in chat; see
/// `RunFailureActions`) sit under the reason, so what to do next is beside
/// why it failed.
class RunFailureBanner extends StatelessWidget {
const RunFailureBanner({super.key, required this.run});
const RunFailureBanner({super.key, required this.run, this.actions});
final JsonMap run;
final Widget? actions;
@override
Widget build(BuildContext context) {
@@ -53,6 +58,10 @@ class RunFailureBanner extends StatelessWidget {
color: scheme.onErrorContainer,
),
),
if (actions case final actions?) ...[
const SizedBox(height: 8),
actions,
],
],
),
),
@@ -72,8 +72,13 @@ class RunMoreMenu extends StatefulWidget {
this.onOpenInChat,
this.onRunAgain,
this.menuKey = runMoreMenuKey,
this.pending = false,
});
/// The run's detail is still loading: [run] is its list row (or only its
/// id), so the items are listed but disabled until the detail arrives.
final bool pending;
/// Opens the New run form pre-filled from this run (finished runs that
/// did not fail); without it the menu offers no Run again.
final ValueChanged<JsonMap>? onRunAgain;
@@ -168,6 +173,7 @@ class _RunMoreMenuState extends State<RunMoreMenu> {
_RunMoreItem.openInChat => Icons.chat_bubble_outline,
},
destructive: item == _RunMoreItem.delete,
enabled: !widget.pending,
),
],
onSelected: _pick,