merge(app): bring main into runs-pipeline-url; main's filter menu supersedes the lane's pipeline menu

This commit is contained in:
2026-10-22 22:21:45 +01:00
42 changed files with 3607 additions and 127 deletions
+94 -2
View File
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
@@ -9,7 +10,10 @@ import '../core/transport/pipelines_client.dart';
import '../shell/adaptive_shell.dart';
import '../shell/destination.dart';
import '../features/attention/notify/notification_controller.dart';
import '../features/attention/notify/chat_question_notices.dart';
import '../features/attention/notify/notification_store.dart';
import '../features/attention/runtime/attention_controller.dart';
import '../features/attention/runtime/attention_store.dart';
import '../features/runs/ui/run_search_selection.dart';
import '../features/search/domain/search_target.dart';
import '../features/settings/settings_screen.dart';
@@ -88,6 +92,21 @@ class _PipelinesAppState extends State<PipelinesApp>
late final NotificationController _notifications = NotificationController(
store: const SharedPreferencesNotificationStore(),
);
ChatQuestionNotices? _chatQuestionNotices;
/// One attention surface for the app: the Runs heading's bell draws from it
/// and the shell mirrors its count on the Runs tab, so the badge is visible
/// from every destination. The Runs list seeds the rows when it loads; pushed
/// `run_event` frames are folded here so the count moves while another
/// destination is shown, and a replaced socket drops the status baseline.
late final AttentionController _attention = AttentionController(
store: const SharedPreferencesAttentionStore(),
);
StreamSubscription<JsonMap>? _attentionFrames;
int _attentionEpoch = 0;
/// The count the shell's Runs tab shows; only a changed count rebuilds it.
final ValueNotifier<int> _attentionCount = ValueNotifier<int>(0);
@override
void initState() {
@@ -115,6 +134,12 @@ class _PipelinesAppState extends State<PipelinesApp>
_cupertino = widget.cupertino ?? _platformIsCupertino;
_notifications.onOpenRun = (id) => _delegate.goTo(AppRoute.run(id));
unawaited(_notifications.load());
unawaited(_attention.load());
_attentionFrames = _session.gateway.frames
.where((frame) => frame['type'] == 'run_event')
.listen(_attention.observeFrame);
_session.addListener(_attentionSessionChanged);
_attention.addListener(_attentionChanged);
_delegate = AppRouterDelegate(
initial: initial,
cupertino: _cupertino,
@@ -126,6 +151,17 @@ class _PipelinesAppState extends State<PipelinesApp>
builder: _buildShell,
);
_delegate.addListener(_routeChanged);
_chatQuestionNotices = ChatQuestionNotices(
gateway: _session.gateway,
canNotify: () => _notifications.canNotify,
activeChatSessionId: () {
final route = _delegate.shellRoute;
return route.kind == AppRouteKind.chat ? route.chatSessionId : null;
},
sessionTitle: _chatSessionTitle,
openChat: (id) => _delegate.goTo(AppRoute.chatSession(id)),
bridge: _notifications.bridge,
);
_config = RouterConfig<AppRoute>(
routeInformationParser: const AppRouteParser(),
routerDelegate: _delegate,
@@ -137,7 +173,13 @@ class _PipelinesAppState extends State<PipelinesApp>
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_session.removeListener(_attentionSessionChanged);
unawaited(_attentionFrames?.cancel());
_attention.removeListener(_attentionChanged);
_attention.dispose();
_attentionCount.dispose();
_notifications.dispose();
_chatQuestionNotices?.dispose();
_delegate.removeListener(_routeChanged);
_delegate.dispose();
if (_ownsProvider) {
@@ -161,6 +203,33 @@ class _PipelinesAppState extends State<PipelinesApp>
unawaited(_session.retry());
}
/// A replaced socket drops the attention status baseline so the gap cannot
/// replay a transition; the Runs list's next read reseeds the rows.
void _attentionSessionChanged() {
final epoch = _session.connectionEpoch;
if (epoch == _attentionEpoch) return;
_attentionEpoch = epoch;
_attention.resetForReconnect();
}
/// Mirrors the controller's entry count for the shell. The Runs list seeds
/// the rows from inside its own build, and the shell sits above that layout
/// scope, so a count that changes mid-build lands after the frame; a pushed
/// frame arrives outside any build and applies at once.
void _attentionChanged() {
if (!mounted) return;
final count = _attention.entries.length;
if (count == _attentionCount.value) return;
if (SchedulerBinding.instance.schedulerPhase ==
SchedulerPhase.persistentCallbacks) {
SchedulerBinding.instance.addPostFrameCallback(
(_) => _attentionChanged(),
);
return;
}
_attentionCount.value = count;
}
@override
Widget build(BuildContext context) =>
MyApp.router(cupertino: _cupertino, routerConfig: _config);
@@ -199,9 +268,12 @@ class _PipelinesAppState extends State<PipelinesApp>
case SearchRunTarget(:final runId):
route = AppRoute.run(runId);
case SearchStepTarget(:final runId, :final stage, :final visit):
// The server records a 1-based visit number; the route's `visit` is the
// zero-based index into the recorded timeline.
final index = visit == null || visit < 1 ? null : visit - 1;
route = stage == null
? AppRoute.run(runId)
: AppRoute.run.stage(runId, stage, visit: visit);
: AppRoute.run.stage(runId, stage, visit: index);
case SearchFieldTarget(:final runId, :final sequence, :final field):
selection = RunSearchSelection(
runId: runId,
@@ -242,6 +314,16 @@ class _PipelinesAppState extends State<PipelinesApp>
setState(() => _pendingRunSearch = null);
}
Future<String?> _chatSessionTitle(String id) async {
final reply = await _session.gateway.call('chat_sessions');
final sessions = reply['chat_sessions'];
if (sessions is! List) return null;
for (final value in sessions) {
if (value is Map && value['id'] == id) return '${value['title'] ?? ''}';
}
return null;
}
/// The Templates page above Settings. Closing it restores the same Settings
/// screen instance, so an edited field or an open connection state survives.
Widget _buildSchedules(BuildContext context) => SchedulesDestination(
@@ -277,7 +359,16 @@ class _PipelinesAppState extends State<PipelinesApp>
_delegate.goTo(AppRoute.run(id));
}
Widget _buildShell(BuildContext context, AppRoute route) => AdaptiveShell(
/// The shell rebuilds its Runs tab badge from the attention count alone; the
/// destination bodies keep their state through it.
Widget _buildShell(BuildContext context, AppRoute route) =>
ValueListenableBuilder<int>(
valueListenable: _attentionCount,
builder: (context, count, _) => _shellFor(route, count),
);
Widget _shellFor(AppRoute route, int attentionCount) => AdaptiveShell(
attentionCount: attentionCount,
cupertino: _cupertino,
destination: _destinationOf(route.kind),
onDestinationSelected: (destination) =>
@@ -310,6 +401,7 @@ class _PipelinesAppState extends State<PipelinesApp>
initialDecide: route.decide,
listRefreshToken: _runsRefresh,
notifications: _notifications,
attention: _attention,
onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
onBack: (id) => _delegate.goTo(
id == null ? AppRoute.runs : AppRoute.runsForPipeline(id),
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import '../features/attention/notify/notification_controller.dart';
import '../features/attention/runtime/attention_controller.dart';
import '../features/runs/screen.dart';
import '../ui/adaptive/host.dart';
import 'app_session.dart';
@@ -28,6 +29,7 @@ class RunsDestination extends StatelessWidget {
this.onPipelineFilterChanged,
this.listRefreshToken = 0,
this.notifications,
this.attention,
});
final AppSession session;
@@ -56,6 +58,9 @@ class RunsDestination extends StatelessWidget {
/// The app-level notification capability shared with Settings.
final NotificationController? notifications;
/// The app-level attention controller the shell's Runs tab badge reads.
final AttentionController? attention;
@override
Widget build(BuildContext context) => AnimatedBuilder(
animation: session,
@@ -98,6 +103,7 @@ class RunsDestination extends StatelessWidget {
syncToken: session.connectionEpoch,
listRefreshToken: listRefreshToken,
notifications: notifications,
attention: attention,
onRunSelected: onRunSelected,
onBack: onBack,
onPipelineFilterChanged: onPipelineFilterChanged,