Add labelled run entry points

Make starting runs discoverable from pipeline details and the Runs tab. Share the existing launch flow, add an active-pipeline picker, and update walkthrough guidance with focused widget coverage.
This commit is contained in:
2026-11-12 10:53:09 +00:00
parent 24618964ce
commit fc86a8257c
14 changed files with 820 additions and 153 deletions
@@ -0,0 +1,11 @@
import '../core/api_gateway.dart';
import '../core/servers/server_scope.dart';
import 'server_endpoint.dart';
/// The scope that isolates a server's pending launch intents. Pipelines and
/// Runs must compute the same scope, or a lost reply could be retried under a
/// different key from the one the Pipelines tab would check.
String pendingRunScope(ApiGateway gateway, ServerEndpoint server) {
final identity = serverIdentity(gateway);
return identity == null ? server.uri?.toString() ?? '' : 'profile:$identity';
}
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import '../core/servers/server_scope.dart';
import '../features/pipelines/screen.dart';
import '../ui/adaptive/top_bar_notices.dart';
import 'app_session.dart';
import 'connection_status.dart';
import 'pending_run_scope.dart';
import 'server_endpoint.dart';
/// The Pipelines destination: the read-only browser plus honest status.
@@ -82,9 +82,7 @@ class PipelinesDestination extends StatelessWidget {
Widget _pipelinesScreen() => PipelinesScreen(
gateway: session.gateway,
endpoint: serverIdentity(session.gateway) == null
? server.uri?.toString() ?? ''
: 'profile:${serverIdentity(session.gateway)}',
endpoint: pendingRunScope(session.gateway, server),
legacyEndpoints: legacyPendingEndpoints,
embedded: true,
active: active,
@@ -2,11 +2,13 @@ import 'package:flutter/material.dart';
import '../features/attention/notify/notification_controller.dart';
import '../features/attention/runtime/attention_controller.dart';
import '../features/pipelines/pending_run_store.dart';
import '../features/runs/screen.dart';
import '../features/runs/ui/run_pipeline_link.dart';
import '../ui/adaptive/top_bar_notices.dart';
import 'app_session.dart';
import 'connection_status.dart';
import 'pending_run_scope.dart';
import 'server_endpoint.dart';
/// The Runs destination: the loaded screen plus an honest connection status.
@@ -100,6 +102,9 @@ class RunsDestination extends StatelessWidget {
listRefreshToken: listRefreshToken,
notifications: notifications,
attention: attention,
pendingRunStore: SharedPreferencesPendingRunStore(
pendingRunScope(session.gateway, server),
),
onRunSelected: onRunSelected,
onBack: onBack,
onPipelineFilterChanged: onPipelineFilterChanged,
@@ -1,21 +1,16 @@
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../core/transport/connection_state.dart';
import '../../runs/data/runs_repository.dart';
import '../../../ui/adaptive/segmented_bar_overflow.dart';
import '../pipeline_models.dart';
import '../pipelines_controller.dart';
import '../run_pipeline_intent.dart';
import '../widgets/pipeline_bar_buttons.dart';
import 'run_pipeline_dialog.dart';
import 'run_pipeline_flow.dart';
import 'run_pipeline_wording.dart';
/// The pipeline detail's Run action.
///
/// Nothing is requested until the dialog's confirm. A confirmed attempt sends
/// the web's exact `run_pipeline` body against the pinned resolved version; a
/// lost reply keeps the intent so the next deliberate press checks by the same
/// request key before resending. Only the id the server names is opened.
const _runIcon = Icons.play_arrow_rounded;
/// The pipeline detail's Run action: a labelled button that opens the shared
/// start flow ([openRunPipelineFlow]).
class RunPipelineAction extends StatefulWidget {
const RunPipelineAction({
super.key,
@@ -26,8 +21,8 @@ class RunPipelineAction extends StatefulWidget {
this.inBar = false,
});
/// The compact icon-and-word button of a top bar's actions pill instead
/// of an inline button.
/// The compact button of a top bar's actions pill instead of an inline
/// button. A narrow bar moves it into its More menu, labelled.
final bool inBar;
final PipelinesController controller;
@@ -45,143 +40,38 @@ class RunPipelineAction extends StatefulWidget {
class _RunPipelineActionState extends State<RunPipelineAction> {
bool _dialogOpen = false;
int get _pipelineId => widget.detail.id;
int get _version => widget.detail.resolvedVersion;
Future<void> _open() async {
if (_dialogOpen) return;
_dialogOpen = true;
try {
final pending = await widget.controller.loadPendingRun(
_pipelineId,
_version,
);
if (!mounted) return;
await showRunPipelineDialog(
await openRunPipelineFlow(
context: context,
controller: widget.controller,
detail: widget.detail,
gateway: widget.gateway,
pending: pending,
onSubmit: _submit,
onPendingChanged: (intent) {
if (intent == null) {
widget.controller.clearPendingRun(_pipelineId, _version);
} else {
widget.controller.rememberPendingRun(intent);
}
},
onAccepted: _accepted,
onRunStarted: widget.onRunStarted,
);
} finally {
_dialogOpen = false;
}
}
void _accepted(JsonMap run) {
final id = runPipelineRunId(run);
if (id == null) return;
widget.controller.clearPendingRun(_pipelineId, _version);
widget.onRunStarted?.call(id);
}
Future<RunPipelineOutcome> _submit(RunPipelineIntent intent) async {
final repository = RunsRepository(widget.gateway);
final pending = widget.controller.pendingRunFor(
intent.pipelineId,
intent.version,
);
if (pending?.requestKey == intent.requestKey) {
// A previous send may have been admitted even though its reply was lost.
// Check before resending the same key; the server dedupes either way.
try {
final existing = await repository.runByRequestKey(intent.requestKey);
if (existing != null) return _accept(existing);
} catch (error) {
widget.controller.rememberPendingRun(intent);
return RunPipelineRefused(
'${describeRunPipelineError(error)}$runPipelineUnknownSuffix',
admissionUnknown: true,
);
}
}
try {
final run = await repository.startRun(
pipelineId: intent.pipelineId,
version: intent.version,
prompt: intent.prompt,
workspace: intent.workspace,
requestKey: intent.requestKey,
notifyMode: intent.notifyMode.wireValue,
outputFormat: intent.outputFormat.wireValue,
);
final accepted = _accept(run);
if (accepted is RunPipelineAccepted) return accepted;
// A reply without a usable run id is not navigable: read the admitted run
// by key rather than inventing an id or starting another run.
return _refuse(repository, intent, 'The server returned no run id.');
} on ProtocolError catch (error) {
return _refuse(repository, intent, describeRunPipelineError(error));
} on RunsRepositoryException catch (error) {
return _refuse(repository, intent, describeRunPipelineError(error));
} catch (error) {
widget.controller.rememberPendingRun(intent);
return RunPipelineRefused(
'${describeRunPipelineError(error)}$runPipelineUnknownSuffix',
admissionUnknown: true,
);
}
}
/// A reply is only accepted when it names a usable run id.
RunPipelineOutcome _accept(JsonMap run) {
if (runPipelineRunId(run) == null) {
return const RunPipelineRefused(
'The server returned no run id.',
admissionUnknown: false,
);
}
widget.controller.clearPendingRun(widget.detail.id, _version);
return RunPipelineAccepted(run);
}
/// A confirmed refusal: prove by key that no run was admitted before letting
/// the operator correct the fields and try with a fresh key.
Future<RunPipelineOutcome> _refuse(
RunsRepository repository,
RunPipelineIntent intent,
String message,
) async {
try {
final existing = await repository.runByRequestKey(intent.requestKey);
if (existing != null) return _accept(existing);
widget.controller.clearPendingRun(intent.pipelineId, intent.version);
return RunPipelineRefused(message, admissionUnknown: false);
} catch (_) {
// Admission cannot be proven either way: keep the intent immutable.
widget.controller.rememberPendingRun(intent);
return RunPipelineRefused(
'$message$runPipelineUnknownSuffix',
admissionUnknown: true,
);
}
}
@override
Widget build(BuildContext context) {
final label = const Text(runPipelineActionLabel);
if (widget.inBar) {
return pipelineBarIconButton(
context,
key: runPipelineActionKey,
label: 'Run ${widget.detail.displayName}',
icon: Icons.play_arrow_rounded,
onPressed: _open,
);
}
return FilledButton(
final button = FilledButton.icon(
key: runPipelineActionKey,
onPressed: _open,
child: label,
icon: const Icon(_runIcon),
label: const Text(runPipelineActionLabel),
);
if (!widget.inBar) return button;
return SegmentedOverflowAction(
overflowEntry: SegmentedOverflowEntry(
label: runPipelineActionLabel,
icon: _runIcon,
onPressed: _open,
),
child: button,
);
}
}
@@ -0,0 +1,155 @@
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../core/transport/connection_state.dart';
import '../../runs/data/runs_repository.dart';
import '../pipeline_models.dart';
import '../pipelines_controller.dart';
import '../run_pipeline_intent.dart';
import 'run_pipeline_dialog.dart';
import 'run_pipeline_wording.dart';
/// The one Run start flow, shared by a pipeline's Run action and the Runs
/// tab's New run picker.
///
/// Nothing is requested until the dialog's confirm. A confirmed attempt sends
/// the web's exact `run_pipeline` body against the pinned resolved version; a
/// lost reply keeps the intent so the next deliberate press checks by the same
/// request key before resending. Only the id the server names is reported.
Future<void> openRunPipelineFlow({
required BuildContext context,
required PipelinesController controller,
required PipelineDetail detail,
required ApiGateway gateway,
ValueChanged<int>? onRunStarted,
}) async {
final pipelineId = detail.id;
final version = detail.resolvedVersion;
final pending = await controller.loadPendingRun(pipelineId, version);
if (!context.mounted) return;
await showRunPipelineDialog(
context: context,
detail: detail,
gateway: gateway,
pending: pending,
onSubmit: (intent) => _submit(controller, gateway, intent),
onPendingChanged: (intent) {
if (intent == null) {
controller.clearPendingRun(pipelineId, version);
} else {
controller.rememberPendingRun(intent);
}
},
onAccepted: (run) {
final id = runPipelineRunId(run);
if (id == null) return;
controller.clearPendingRun(pipelineId, version);
onRunStarted?.call(id);
},
);
}
Future<RunPipelineOutcome> _submit(
PipelinesController controller,
ApiGateway gateway,
RunPipelineIntent intent,
) async {
final repository = RunsRepository(gateway);
final pending = controller.pendingRunFor(intent.pipelineId, intent.version);
if (pending?.requestKey == intent.requestKey) {
// A previous send may have been admitted even though its reply was lost.
// Check before resending the same key; the server dedupes either way.
try {
final existing = await repository.runByRequestKey(intent.requestKey);
if (existing != null) {
return _accept(controller, intent, existing);
}
} catch (error) {
controller.rememberPendingRun(intent);
return RunPipelineRefused(
'${describeRunPipelineError(error)}$runPipelineUnknownSuffix',
admissionUnknown: true,
);
}
}
try {
final run = await repository.startRun(
pipelineId: intent.pipelineId,
version: intent.version,
prompt: intent.prompt,
workspace: intent.workspace,
requestKey: intent.requestKey,
notifyMode: intent.notifyMode.wireValue,
outputFormat: intent.outputFormat.wireValue,
);
final accepted = _accept(controller, intent, run);
if (accepted is RunPipelineAccepted) return accepted;
// A reply without a usable run id is not navigable: read the admitted run
// by key rather than inventing an id or starting another run.
return _refuse(
controller,
repository,
intent,
'The server returned no run id.',
);
} on ProtocolError catch (error) {
return _refuse(
controller,
repository,
intent,
describeRunPipelineError(error),
);
} on RunsRepositoryException catch (error) {
return _refuse(
controller,
repository,
intent,
describeRunPipelineError(error),
);
} catch (error) {
controller.rememberPendingRun(intent);
return RunPipelineRefused(
'${describeRunPipelineError(error)}$runPipelineUnknownSuffix',
admissionUnknown: true,
);
}
}
/// A reply is only accepted when it names a usable run id.
RunPipelineOutcome _accept(
PipelinesController controller,
RunPipelineIntent intent,
JsonMap run,
) {
if (runPipelineRunId(run) == null) {
return const RunPipelineRefused(
'The server returned no run id.',
admissionUnknown: false,
);
}
controller.clearPendingRun(intent.pipelineId, intent.version);
return RunPipelineAccepted(run);
}
/// A confirmed refusal: prove by key that no run was admitted before letting
/// the operator correct the fields and try with a fresh key.
Future<RunPipelineOutcome> _refuse(
PipelinesController controller,
RunsRepository repository,
RunPipelineIntent intent,
String message,
) async {
try {
final existing = await repository.runByRequestKey(intent.requestKey);
if (existing != null) return _accept(controller, intent, existing);
controller.clearPendingRun(intent.pipelineId, intent.version);
return RunPipelineRefused(message, admissionUnknown: false);
} catch (_) {
// Admission cannot be proven either way: keep the intent immutable.
controller.rememberPendingRun(intent);
return RunPipelineRefused(
'$message$runPipelineUnknownSuffix',
admissionUnknown: true,
);
}
}
+88 -13
View File
@@ -11,10 +11,15 @@ import '../attention/notify/notification_controller.dart';
import '../../ui/layout/content_width.dart';
import '../attention/runtime/attention_controller.dart';
import '../attention/runtime/attention_store.dart';
import '../pipelines/pending_run_store.dart';
import '../pipelines/pipeline_repository.dart';
import '../pipelines/pipelines_controller.dart';
import 'actions/decision_action.dart';
import 'data/runs_repository.dart';
import 'data/runs_sort_store.dart';
import 'domain/run_decisions.dart';
import 'ui/new_run_button.dart';
import 'ui/new_run_flow.dart';
import 'ui/run_pipeline_link.dart';
import 'ui/run_detail_view.dart';
import 'ui/run_search_selection.dart';
@@ -47,6 +52,7 @@ class RunsScreen extends StatefulWidget {
this.notifications,
this.attention,
this.sortStore = const SharedPreferencesRunsSortStore(),
this.pendingRunStore = const SharedPreferencesPendingRunStore(''),
});
final ApiGateway gateway;
@@ -94,12 +100,24 @@ class RunsScreen extends StatefulWidget {
/// Where the list's sort choice persists; tests inject a memory store.
final RunsSortStore sortStore;
/// Where a New run's pending launch intent persists, under the same endpoint
/// scope the Pipelines tab uses. Tests inject a memory store.
final PendingRunStore pendingRunStore;
@override
State<RunsScreen> createState() => _RunsScreenState();
}
/// The vertical band the New run button occupies over the list's bottom edge:
/// its margin, the extended button's height and its margin again.
const double _newRunBand = 88;
class _RunsScreenState extends State<RunsScreen> {
late final RunsController controller;
/// Starts a run from the New run picker. Its state is only the pending
/// launch intent; the pipeline itself is read when the operator picks one.
late final PipelinesController _launches;
num? _shownRunId;
int? _reportedPipelineId;
bool _applyingRoutePipeline = false;
@@ -118,6 +136,10 @@ class _RunsScreenState extends State<RunsScreen> {
RunsRepository(widget.gateway),
sortStore: widget.sortStore,
);
_launches = PipelinesController(
PipelinesRepository(widget.gateway),
pendingRunStore: widget.pendingRunStore,
);
// A deleted open run closes its detail; the route returns to the list.
controller.onOpenRunRemoved = () =>
widget.onBack?.call(controller.pipelineId);
@@ -234,6 +256,23 @@ class _RunsScreenState extends State<RunsScreen> {
widget.onBack?.call(controller.pipelineId);
}
/// The New run picker, then the same start flow a pipeline's Run opens.
void _startNewRun() => unawaited(
startNewRunFlow(
context: context,
controller: _launches,
gateway: widget.gateway,
onRunStarted: _newRunStarted,
),
);
/// An accepted launch re-reads the list so its row appears, then opens the
/// run the same way a row tap does.
void _newRunStarted(int id) {
unawaited(controller.resync());
_select(id);
}
@override
void dispose() {
controller.removeListener(_selectionChanged);
@@ -241,6 +280,7 @@ class _RunsScreenState extends State<RunsScreen> {
controller.removeListener(_detailChanged);
_page.dispose();
controller.dispose();
_launches.dispose();
super.dispose();
}
@@ -285,20 +325,55 @@ class _RunsScreenState extends State<RunsScreen> {
onClosed: _back,
builder: (context) => _detail(() => Navigator.of(context).maybePop()),
);
final list = AnimatedBuilder(
animation: controller,
builder: (context, _) => ContentWidth(
child: RunsList(
active: narrow ? !selected : true,
controller: controller,
onSelected: _select,
syncToken: widget.syncToken,
attentionStore: widget.attentionStore,
attentionNow: widget.attentionNow,
notifications: widget.notifications,
attention: widget.attention,
// The New run button floats over the list's bottom-right corner while the
// list is the visible view. The list reserves the button's band in its
// bottom padding, so its last row rests above the button, and the overlay
// lifts clear of the shell's bar like the list's own clearance does.
final list = Stack(
fit: StackFit.expand,
children: [
AnimatedBuilder(
animation: controller,
builder: (context, _) {
final showsButton = !(narrow && selected);
final media = MediaQuery.of(context);
return MediaQuery(
data: media.copyWith(
padding: media.padding.copyWith(
bottom:
media.padding.bottom + (showsButton ? _newRunBand : 0),
),
),
child: ContentWidth(
child: RunsList(
active: narrow ? !selected : true,
controller: controller,
onSelected: _select,
syncToken: widget.syncToken,
attentionStore: widget.attentionStore,
attentionNow: widget.attentionNow,
notifications: widget.notifications,
attention: widget.attention,
),
),
);
},
),
),
AnimatedBuilder(
animation: controller,
builder: (context, _) => narrow && selected
? const SizedBox.shrink()
: Positioned(
left: 16,
right: 16,
bottom: 16 + MediaQuery.paddingOf(context).bottom,
child: Align(
alignment: AlignmentDirectional.bottomEnd,
child: NewRunButton(onPressed: _startNewRun),
),
),
),
],
);
if (narrow) return list;
return ListDetailPanes(
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
/// The Runs tab's New run action: an extended floating button that opens the
/// pipeline picker. It is labelled, so it needs no tooltip of its own.
class NewRunButton extends StatelessWidget {
const NewRunButton({super.key, required this.onPressed});
final VoidCallback onPressed;
@override
Widget build(BuildContext context) => FloatingActionButton.extended(
key: const Key('runs-new-run'),
onPressed: onPressed,
icon: const Icon(Icons.add),
label: const Text('New run'),
);
}
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../pipelines/pipeline_models.dart';
import '../../pipelines/pipeline_repository.dart';
import '../../pipelines/pipelines_controller.dart';
import '../../pipelines/ui/run_pipeline_flow.dart';
import '../../pipelines/ui/run_pipeline_wording.dart';
import 'new_run_picker.dart';
/// The Runs tab's New run: pick an active pipeline, read its latest version,
/// then the same start flow a pipeline's Run action opens.
Future<void> startNewRunFlow({
required BuildContext context,
required PipelinesController controller,
required ApiGateway gateway,
ValueChanged<int>? onRunStarted,
}) async {
final repository = PipelinesRepository(gateway);
final pipelineId = await pickPipelineForNewRun(context, repository);
if (pipelineId == null || !context.mounted) return;
final PipelineDetail detail;
try {
detail = await repository.getPipeline(pipelineId, 0);
} 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,
);
}
@@ -0,0 +1,143 @@
import 'package:flutter/material.dart';
import '../../pipelines/pipeline_models.dart';
import '../../pipelines/pipeline_repository.dart';
import '../../pipelines/ui/run_pipeline_wording.dart';
/// Whether an active pipeline matches a picker search by name. An empty query
/// matches every pipeline.
bool pipelineMatchesQuery(PipelineSummary pipeline, String query) {
final needle = query.trim().toLowerCase();
if (needle.isEmpty) return true;
return pipeline.displayName.toLowerCase().contains(needle);
}
/// Opens the searchable list of active pipelines. Resolves to the chosen
/// pipeline's id, or null when the picker is dismissed.
Future<int?> pickPipelineForNewRun(
BuildContext context,
PipelinesRepository repository,
) => showDialog<int>(
context: context,
builder: (_) => _PipelinePicker(repository: repository),
);
class _PipelinePicker extends StatefulWidget {
const _PipelinePicker({required this.repository});
final PipelinesRepository repository;
@override
State<_PipelinePicker> createState() => _PipelinePickerState();
}
class _PipelinePickerState extends State<_PipelinePicker> {
late Future<List<PipelineSummary>> _pipelines = _loadActive();
String _query = '';
/// Archived pipelines cannot run, so the picker offers only active ones.
Future<List<PipelineSummary>> _loadActive() async {
final all = await widget.repository.listPipelines();
return all.where((pipeline) => !pipeline.archived).toList(growable: false);
}
void _retry() => setState(() => _pipelines = _loadActive());
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Dialog(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 480, maxHeight: 560),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text('Choose a pipeline', style: theme.textTheme.titleLarge),
const Padding(padding: EdgeInsets.only(top: 12)),
TextField(
key: const Key('new-run-search'),
decoration: const InputDecoration(
hintText: 'Search pipelines',
prefixIcon: Icon(Icons.search),
),
onChanged: (value) => setState(() => _query = value),
),
const Padding(padding: EdgeInsets.only(top: 8)),
Flexible(child: _body(context)),
],
),
),
),
);
}
Widget _body(BuildContext context) {
return FutureBuilder<List<PipelineSummary>>(
future: _pipelines,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const Padding(
padding: EdgeInsets.all(24),
child: Center(child: CircularProgressIndicator()),
);
}
if (snapshot.hasError) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
describeRunPipelineError(snapshot.error!),
style: TextStyle(color: Theme.of(context).colorScheme.error),
),
TextButton(onPressed: _retry, child: const Text('Retry')),
],
);
}
final active = snapshot.data ?? const <PipelineSummary>[];
if (active.isEmpty) {
return const _Notice('No active pipelines.');
}
final matches = active
.where((pipeline) => pipelineMatchesQuery(pipeline, _query))
.toList(growable: false);
if (matches.isEmpty) {
return const _Notice('No pipeline matches the search.');
}
return ListView(
shrinkWrap: true,
children: [
for (final pipeline in matches)
ListTile(
key: ValueKey<String>('new-run-pipeline-${pipeline.id}'),
title: Text(
pipeline.displayName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
subtitle: Text(
'v${pipeline.version} · ${pipeline.stages} stages',
),
onTap: () => Navigator.of(context).pop(pipeline.id),
),
],
);
},
);
}
}
class _Notice extends StatelessWidget {
const _Notice(this.message);
final String message;
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.all(16),
child: Text(message, style: TextStyle(color: Theme.of(context).hintColor)),
);
}
@@ -61,7 +61,7 @@ const walkthroughSteps = <WalkthroughStep>[
points: <String>[
'Pipelines tab: open a workflow and fill in its inputs.',
'Runs tab: follow a run as it works, then read what it produced.',
'Choose Run on a workflow to start one.',
'Press Run on a workflow, or New run on the Runs tab, to start one.',
],
),
WalkthroughStep(