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>
191 lines
5.6 KiB
Dart
191 lines
5.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../domain/run_decisions.dart';
|
|
import '../domain/run_models.dart';
|
|
import 'action_refusal.dart';
|
|
import 'decision_wording.dart';
|
|
|
|
/// Sends the draft to the server. Returns null on success, or an
|
|
/// [ActionRefusal] with the server's words verbatim; the prompt stays open
|
|
/// with the draft intact and dismissal available immediately.
|
|
typedef DecisionSubmit = Future<ActionRefusal?> Function(DecisionDraft draft);
|
|
|
|
/// Opens the native decision prompt for [decision].
|
|
Future<void> showHumanDecisionPrompt({
|
|
required BuildContext context,
|
|
required PendingDecision decision,
|
|
required DecisionSubmit onSubmit,
|
|
}) {
|
|
final prompt = _DecisionPrompt(decision: decision, onSubmit: onSubmit);
|
|
return showDialog<void>(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (_) => prompt,
|
|
);
|
|
}
|
|
|
|
class _DecisionPrompt extends StatefulWidget {
|
|
const _DecisionPrompt({required this.decision, required this.onSubmit});
|
|
|
|
final PendingDecision decision;
|
|
final DecisionSubmit onSubmit;
|
|
|
|
@override
|
|
State<_DecisionPrompt> createState() => _DecisionPromptState();
|
|
}
|
|
|
|
class _DecisionPromptState extends State<_DecisionPrompt> {
|
|
DecisionDraft _draft = const DecisionDraft();
|
|
late final TextEditingController _feedback = TextEditingController();
|
|
bool _sending = false;
|
|
bool _checking = false;
|
|
bool _blocked = false;
|
|
String? _error;
|
|
|
|
@override
|
|
void dispose() {
|
|
_feedback.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _select(String option) {
|
|
if (_sending) return;
|
|
setState(() => _draft = _draft.select(option));
|
|
}
|
|
|
|
void _feedbackChanged(String value) => _draft = _draft.withFeedback(value);
|
|
|
|
void _cancel() {
|
|
if (!_sending) Navigator.of(context).pop();
|
|
}
|
|
|
|
Future<void> _confirm() async {
|
|
if (_sending || _checking || _blocked || !_draft.canSubmit) return;
|
|
setState(() {
|
|
_sending = true;
|
|
_error = null;
|
|
});
|
|
final refusal = await widget.onSubmit(_draft);
|
|
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;
|
|
|
|
Widget _material(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return AlertDialog(
|
|
scrollable: true,
|
|
title: const Text(decisionWaitingTitle),
|
|
content: _body(
|
|
errorStyle: TextStyle(color: theme.colorScheme.error),
|
|
options: RadioGroup<String>(
|
|
groupValue: _draft.selected,
|
|
onChanged: (value) {
|
|
if (value != null) _select(value);
|
|
},
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
for (final option in widget.decision.options)
|
|
RadioListTile<String>(
|
|
value: option.key,
|
|
enabled: !_sending,
|
|
title: Text(option.displayLabel),
|
|
subtitle: _target(option),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
feedback: TextField(
|
|
key: decisionFeedbackKey,
|
|
controller: _feedback,
|
|
enabled: !_sending,
|
|
decoration: const InputDecoration(labelText: decisionFeedbackLabel),
|
|
textInputAction: TextInputAction.done,
|
|
onChanged: _feedbackChanged,
|
|
onSubmitted: (_) => _confirm(),
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: _sending ? null : _cancel,
|
|
child: const Text(decisionCancelLabel),
|
|
),
|
|
FilledButton(
|
|
onPressed: _confirmDisabled || !_draft.canSubmit ? null : _confirm,
|
|
child: Text(_sending ? decisionSendingLabel : decisionConfirmLabel),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _body({
|
|
required TextStyle errorStyle,
|
|
required Widget options,
|
|
required Widget feedback,
|
|
}) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text(decisionMeta(widget.decision)),
|
|
if (decisionExhaustedText(widget.decision) case final text
|
|
when text.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Text(text, key: decisionExhaustedKey),
|
|
),
|
|
if (widget.decision.instructions.trim().isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Text(widget.decision.instructions),
|
|
),
|
|
Padding(padding: const EdgeInsets.only(top: 8), child: options),
|
|
Padding(padding: const EdgeInsets.only(top: 8), child: feedback),
|
|
if (_error case final error?)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Text(error, key: decisionErrorKey, style: errorStyle),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget? _target(DecisionOption option) {
|
|
final text = _targetText(option);
|
|
return text == null ? null : Text(text);
|
|
}
|
|
|
|
String? _targetText(DecisionOption option) {
|
|
final text = decisionTargetText(option.target);
|
|
return text.isEmpty ? null : text;
|
|
}
|
|
}
|