App: findings ledger tab, retry extra visits and exhaustion decisions

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>
This commit is contained in:
2026-12-03 12:45:43 +00:00
parent c4de1de27b
commit ebe79ebed0
27 changed files with 1255 additions and 14 deletions
@@ -8,14 +8,58 @@ class PendingDecision {
required this.stageKey,
required this.instructions,
required this.options,
this.exhausted,
});
final num runId;
final String runLabel;
final String stageKey;
final String instructions;
final List<DecisionOption> options;
/// The exhausted loop a server-created decision is about; null for a
/// declared human stage.
final ExhaustedLoop? exhausted;
}
/// The loop whose visits ran out, from a waiting step's `exhausted` output:
/// the model stage, the visit it reached and its limit.
class ExhaustedLoop {
const ExhaustedLoop({
required this.stage,
required this.visit,
required this.maxVisits,
required this.targets,
});
final String stage;
final int? visit;
final int? maxVisits;
/// Where each option leads, by option key.
final Map<String, String> targets;
static ExhaustedLoop? parse(dynamic output) {
final value = output is Map ? output['exhausted'] : null;
if (value is! Map) return null;
final targets = value['targets'];
return ExhaustedLoop(
stage: _string(value['stage']).trim(),
visit: _int(value['visit']),
maxVisits: _int(value['max_visits']),
targets: targets is Map
? {for (final e in targets.entries) '${e.key}': _string(e.value)}
: const {},
);
}
}
/// Readable labels for the options of a server-created exhaustion decision.
const exhaustedOptionLabels = {
'accept': 'Accept as is',
'continue': 'One more round',
'abort': 'Abort',
};
JsonMap? lastWaitingStep(List<dynamic> steps) {
for (final value in steps.reversed) {
if (value is Map && value['status'] == 'waiting') {
@@ -68,26 +112,37 @@ PendingDecision? pendingDecision(JsonMap? run) {
}
}
}
if (declaration?['type'] != null && declaration!['type'] != 'human') {
final output = step?['output'];
final options = waitingOptions(output);
// A loop that exhausted its visits waits on its own (model) stage with the
// options the server recorded; any other non-human stage is not a decision.
final exhausted = ExhaustedLoop.parse(output);
final declared = exhausted == null || options.isEmpty;
if (declared &&
declaration?['type'] != null &&
declaration!['type'] != 'human') {
return null;
}
final edges = declaration?['edges'];
final options = waitingOptions(step?['output']);
final dynamic edges = exhausted != null && !declared
? exhausted.targets
: declaration?['edges'];
final keys = options.isNotEmpty ? options : humanOptions(edges);
if (keys.isEmpty) return null;
final instructions = waitingPrompt(step?['output']).trim().isNotEmpty
? waitingPrompt(step?['output'])
final instructions = waitingPrompt(output).trim().isNotEmpty
? waitingPrompt(output)
: _string(declaration?['prompt']);
return PendingDecision(
runId: run['id'] is num ? run['id'] as num : 0,
runLabel: runIdentity(run['title'], run['name']).label,
stageKey: stage,
instructions: instructions,
exhausted: declared ? null : exhausted,
options: keys
.map(
(key) => DecisionOption(
key,
target: _targetLabel(key, edges is Map ? edges[key] : null),
label: declared ? '' : exhaustedOptionLabels[key] ?? '',
),
)
.toList(),
@@ -108,3 +163,5 @@ String _targetLabel(String option, dynamic target) {
bool _positive(dynamic value) => value is num && value > 0;
String _string(dynamic value) => value == null ? '' : '$value';
int? _int(dynamic value) =>
value is num ? value.toInt() : int.tryParse(_string(value).trim());
@@ -0,0 +1,151 @@
import '../../../core/api_gateway.dart';
/// A finding's severity, most severe first. Unknown wire values parse as null
/// and are kept visible under the "all" severity filter only.
enum FindingSeverity {
critical,
important,
minor,
nit;
static FindingSeverity? parse(dynamic value) {
final text = '${value ?? ''}'.trim().toLowerCase();
for (final severity in values) {
if (severity.name == text) return severity;
}
return null;
}
}
/// The ledger statuses the server records for a finding.
const findingStatuses = ['open', 'fixed', 'dismissed', 'settled'];
/// One recorded status change of a finding.
class FindingEvent {
const FindingEvent({
required this.sequence,
required this.stage,
required this.status,
required this.reason,
});
final int? sequence;
final String stage;
final String status;
final String reason;
}
/// One entry of the run's findings ledger, as the server recorded it.
class RunFinding {
const RunFinding({
required this.id,
required this.severityText,
required this.origin,
required this.location,
required this.summary,
required this.status,
required this.reason,
required this.raisedBy,
required this.raisedSequence,
required this.updatedBy,
required this.updatedSequence,
required this.events,
});
final String id;
/// The severity exactly as recorded; [severity] is its parsed form.
final String severityText;
final String origin;
final String location;
final String summary;
final String status;
final String reason;
final String raisedBy;
final int? raisedSequence;
final String updatedBy;
final int? updatedSequence;
final List<FindingEvent> events;
FindingSeverity? get severity => FindingSeverity.parse(severityText);
bool get isOpen => status == 'open';
}
/// The run's findings ledger; empty when the server sent none (older servers).
List<RunFinding> runFindings(JsonMap? run) {
final list = run?['findings'];
if (list is! List) return const [];
return [
for (final item in list.whereType<Map>())
if (_text(item['id']).isNotEmpty || _text(item['summary']).isNotEmpty)
RunFinding(
id: _text(item['id']),
severityText: _text(item['severity']).toLowerCase(),
origin: _text(item['origin']),
location: _text(item['location']),
summary: _text(item['summary']),
status: _text(item['status']).toLowerCase(),
reason: _text(item['reason']),
raisedBy: _text(item['raised_by']),
raisedSequence: _int(item['raised_sequence']),
updatedBy: _text(item['updated_by']),
updatedSequence: _int(item['updated_sequence']),
events: _events(item['events']),
),
];
}
/// How many findings are still open.
int openFindingCount(Iterable<RunFinding> findings) =>
findings.where((finding) => finding.isOpen).length;
/// The status filter a fresh Findings view starts on: open items when any
/// are open, otherwise everything.
String? defaultFindingStatus(Iterable<RunFinding> findings) =>
openFindingCount(findings) > 0 ? 'open' : null;
/// The findings matching [status] (null = all) at or above [minSeverity]
/// (null = all), in their recorded order.
List<RunFinding> filterFindings(
Iterable<RunFinding> findings, {
String? status,
FindingSeverity? minSeverity,
}) => [
for (final finding in findings)
if ((status == null || finding.status == status) &&
(minSeverity == null ||
(finding.severity != null &&
finding.severity!.index <= minSeverity.index)))
finding,
];
/// The run's extra visit grants as `review +1, implement +2`, or null when
/// none were granted.
String? visitGrantsSummary(JsonMap? run) {
final grants = run?['visit_grants'];
if (grants is! Map) return null;
final parts = [
for (final entry in grants.entries)
if (_int(entry.value) case final count? when count > 0)
'${entry.key} +$count',
];
return parts.isEmpty ? null : parts.join(', ');
}
List<FindingEvent> _events(dynamic value) {
if (value is! List) return const [];
return [
for (final item in value.whereType<Map>())
FindingEvent(
sequence: _int(item['sequence']),
stage: _text(item['stage']),
status: _text(item['status']).toLowerCase(),
reason: _text(item['reason']),
),
];
}
String _text(dynamic value) => value == null ? '' : '$value'.trim();
int? _int(dynamic value) =>
value is num ? value.toInt() : int.tryParse(_text(value));
+6 -1
View File
@@ -323,9 +323,14 @@ class RunListResult {
}
class DecisionOption {
const DecisionOption(this.key, {this.target = ''});
const DecisionOption(this.key, {this.target = '', this.label = ''});
final String key;
final String target;
/// A readable label for a server-defined option; empty shows [key].
final String label;
String get displayLabel => label.trim().isEmpty ? key : label;
}
class DecisionDraft {