ebe79ebed0
Run detail gains a Findings tab (open-count badge) listing the server's findings ledger with status and minimum-severity filters and expandable event history; visit grants show as an Extra visits summary fact. The resume retry prompt can grant 1-5 extra visits to the exhausted stage or a chosen graph stage (never sent on restart), suggested when the run failed on a visit limit. A loop-exhaustion decision waiting on a model stage is now decidable from its recorded options, with readable labels, targets and the visit count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
194 lines
5.5 KiB
Dart
194 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'action_refusal.dart';
|
|
import 'retry_extra_visits_field.dart';
|
|
import 'retry_intent.dart';
|
|
import 'retry_wording.dart';
|
|
|
|
/// Sends the confirmed retry intent. Returns null once the server has accepted
|
|
/// it, or an [ActionRefusal] carrying the server's words verbatim; the prompt
|
|
/// then stays open with dismissal available immediately.
|
|
typedef RetrySubmit = Future<ActionRefusal?> Function(RetryIntent intent);
|
|
|
|
/// Opens the native retry confirmation for [runId].
|
|
///
|
|
/// The first confirmation offers resume (the default) and a secondary
|
|
/// `Restart from start` confirmation, exactly like the browser's retry dialog.
|
|
/// Nothing is sent until the operator presses a confirm action; `Keep` only
|
|
/// closes the prompt.
|
|
Future<void> showRetryRunPrompt({
|
|
required BuildContext context,
|
|
required num runId,
|
|
required RetrySubmit onSubmit,
|
|
List<String> stages = const [],
|
|
bool suggestExtraVisits = false,
|
|
}) {
|
|
final prompt = _RetryPrompt(
|
|
runId: runId,
|
|
onSubmit: onSubmit,
|
|
stages: stages,
|
|
suggestExtraVisits: suggestExtraVisits,
|
|
);
|
|
return showDialog<void>(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (_) => prompt,
|
|
);
|
|
}
|
|
|
|
class _RetryPrompt extends StatefulWidget {
|
|
const _RetryPrompt({
|
|
required this.runId,
|
|
required this.onSubmit,
|
|
required this.stages,
|
|
required this.suggestExtraVisits,
|
|
});
|
|
|
|
final num runId;
|
|
final RetrySubmit onSubmit;
|
|
|
|
/// The run's graph stage keys, offered as the extra visits' stage.
|
|
final List<String> stages;
|
|
|
|
/// Whether the run failed on an exhausted loop.
|
|
final bool suggestExtraVisits;
|
|
|
|
@override
|
|
State<_RetryPrompt> createState() => _RetryPromptState();
|
|
}
|
|
|
|
class _RetryPromptState extends State<_RetryPrompt> {
|
|
RetryMode _mode = RetryMode.resume;
|
|
int? _extraVisits;
|
|
String? _extraStage;
|
|
String? _requestKey;
|
|
bool _sending = false;
|
|
bool _checking = false;
|
|
bool _blocked = false;
|
|
bool _attempted = false;
|
|
String? _error;
|
|
|
|
void _keep() {
|
|
if (!_sending) Navigator.of(context).pop();
|
|
}
|
|
|
|
void _restart() {
|
|
if (_sending || _checking || _attempted) return;
|
|
setState(() {
|
|
_mode = RetryMode.restart;
|
|
_error = null;
|
|
});
|
|
}
|
|
|
|
Future<void> _confirm() async {
|
|
if (_sending || _checking || _blocked) return;
|
|
setState(() {
|
|
_sending = true;
|
|
_attempted = true;
|
|
_error = null;
|
|
});
|
|
final intent = RetryIntent(
|
|
mode: _mode,
|
|
requestKey: _requestKey ??= newRetryRequestKey(widget.runId),
|
|
extraVisits: _extraVisits,
|
|
extraStage: _extraStage,
|
|
);
|
|
final refusal = await widget.onSubmit(intent);
|
|
if (!mounted) return;
|
|
if (refusal == null) {
|
|
Navigator.of(context).pop();
|
|
return;
|
|
}
|
|
final check = refusal.stillPossible;
|
|
setState(() {
|
|
_sending = false;
|
|
_error = refusal.message;
|
|
_checking = check != null;
|
|
});
|
|
if (check == null) return;
|
|
bool? stillPossible;
|
|
try {
|
|
stillPossible = await check;
|
|
} catch (_) {
|
|
// The action reports re-read failures as null; never fabricate one here.
|
|
}
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_checking = false;
|
|
_blocked = stillPossible == false;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return PopScope(canPop: !_sending, child: _material(context));
|
|
}
|
|
|
|
bool get _confirmDisabled => _sending || _checking || _blocked;
|
|
bool get _showRestart => _mode == RetryMode.resume && !_attempted;
|
|
|
|
Widget _material(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return AlertDialog(
|
|
scrollable: true,
|
|
title: Text(_dialogTitle),
|
|
content: _body(errorStyle: TextStyle(color: theme.colorScheme.error)),
|
|
actions: [
|
|
if (_showRestart)
|
|
TextButton(
|
|
key: retryRestartKey,
|
|
onPressed: _sending || _checking ? null : _restart,
|
|
child: const Text(restartConfirmLabel),
|
|
),
|
|
TextButton(
|
|
key: retryKeepKey,
|
|
onPressed: _sending ? null : _keep,
|
|
child: const Text(retryKeepLabel),
|
|
),
|
|
FilledButton(
|
|
key: retryConfirmKey,
|
|
onPressed: _confirmDisabled ? null : _confirm,
|
|
child: Text(_confirmLabel),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _body({required TextStyle errorStyle}) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text(_dialogMessage),
|
|
// Extra visits extend a resumed run only; once sent, the intent (and
|
|
// its idempotency key) is fixed.
|
|
if (_mode == RetryMode.resume)
|
|
RetryExtraVisitsField(
|
|
visits: _extraVisits,
|
|
stage: _extraStage,
|
|
stages: widget.stages,
|
|
suggested: widget.suggestExtraVisits,
|
|
enabled: !_attempted,
|
|
onVisitsChanged: (value) => setState(() => _extraVisits = value),
|
|
onStageChanged: (value) => setState(() => _extraStage = value),
|
|
),
|
|
if (_error case final error?)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Text(error, key: retryErrorKey, style: errorStyle),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
String get _dialogTitle => _mode == RetryMode.restart
|
|
? restartDialogTitle(widget.runId)
|
|
: retryDialogTitle(widget.runId);
|
|
|
|
String get _dialogMessage =>
|
|
_mode == RetryMode.restart ? restartDialogMessage : retryDialogMessage;
|
|
|
|
String get _confirmLabel =>
|
|
_mode == RetryMode.restart ? restartConfirmLabel : retryConfirmLabel;
|
|
}
|