Add first-run walkthrough

Guide new users through connecting a server, configuring an agent harness, starting runs, and chatting with agents. Persist completion per device and offer the walkthrough again for empty servers or from Settings, with widget coverage and implementation notes.
This commit is contained in:
2026-11-12 02:23:15 +00:00
parent 2330f50268
commit 30ba70ade8
14 changed files with 1430 additions and 26 deletions
@@ -13,4 +13,5 @@ abstract final class SettingsKeys {
static const keyboardShortcuts = ValueKey<String>(
'settings.keyboardShortcuts',
);
static const walkthrough = ValueKey<String>('settings.walkthrough');
}
@@ -37,6 +37,7 @@ import 'server_connections.dart';
import 'saved_servers_section.dart';
import 'managed_connection_section.dart';
import 'settings_keyboard_shortcuts_section.dart';
import 'settings_walkthrough_section.dart';
part 'settings_topic_pages.dart';
@@ -85,7 +85,10 @@ extension _SettingsTopicPages on _SettingsScreenState {
SettingsGroup(
title: 'Help',
leadingRows: true,
children: const [SettingsKeyboardShortcutsSection()],
children: const [
SettingsKeyboardShortcutsSection(),
SettingsWalkthroughSection(),
],
),
if (widget.onOpenSchedules case final open?)
SettingsGroup(
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import '../walkthrough/first_run_walkthrough.dart';
import 'settings_keys.dart';
import 'settings_row.dart';
/// Reopens the first-run walkthrough. It only shows the walkthrough; it never
/// changes the device's seen record.
class SettingsWalkthroughSection extends StatelessWidget {
const SettingsWalkthroughSection({super.key});
@override
Widget build(BuildContext context) => SettingsRow(
key: SettingsKeys.walkthrough,
leading: const Icon(Icons.school_outlined),
title: const Text('Show the walkthrough'),
subtitle: const Text(
'Four short steps: connect, set up an agent, run, chat.',
),
chevron: true,
onTap: () => showFirstRunWalkthrough(context),
);
}
@@ -0,0 +1,183 @@
import 'package:flutter/material.dart';
import '../../ui/adaptive/app_popups.dart';
import 'walkthrough_harness_command.dart';
import 'walkthrough_steps.dart';
/// Opens the walkthrough as a Material details sheet on phones and a dialog on
/// wide windows. [onClosed] runs once however it closes (Skip, Done, the close
/// button or a tap outside), so the caller can record it as seen.
Future<void> showFirstRunWalkthrough(
BuildContext context, {
Future<void> Function()? onClosed,
}) async {
await showAppDetails<void>(
context,
maxWidth: 560,
builder: (sheet) =>
FirstRunWalkthrough(onClose: () => Navigator.of(sheet).pop()),
);
await onClosed?.call();
}
/// The four-page stepper: Back and Next between pages, Skip on every page and
/// Done on the last. Every control is a standard Material button; the layout
/// wraps rather than clipping at large text scales.
class FirstRunWalkthrough extends StatefulWidget {
const FirstRunWalkthrough({
super.key,
required this.onClose,
this.steps = walkthroughSteps,
});
/// Called by Skip, Done and the close button.
final VoidCallback onClose;
final List<WalkthroughStep> steps;
@override
State<FirstRunWalkthrough> createState() => _FirstRunWalkthroughState();
}
class _FirstRunWalkthroughState extends State<FirstRunWalkthrough> {
int _index = 0;
bool get _last => _index == widget.steps.length - 1;
void _back() => setState(() => _index = _index > 0 ? _index - 1 : 0);
void _next() => setState(() => _index = _last ? _index : _index + 1);
@override
Widget build(BuildContext context) {
final step = widget.steps[_index];
final theme = Theme.of(context);
final content = Semantics(
scopesRoute: true,
namesRoute: true,
explicitChildNodes: true,
label: 'Pipelines walkthrough',
child: Padding(
padding: const EdgeInsets.fromLTRB(24, 8, 24, 24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(
'Step ${_index + 1} of ${widget.steps.length}',
key: const ValueKey<String>('walkthrough.progress'),
style: theme.textTheme.labelLarge,
),
const SizedBox(height: 8),
LinearProgressIndicator(value: (_index + 1) / widget.steps.length),
const SizedBox(height: 20),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Icon(step.icon, color: theme.colorScheme.primary),
const SizedBox(width: 12),
Expanded(
child: Text(
step.title,
key: ValueKey<String>('walkthrough.title.$_index'),
style: theme.textTheme.headlineSmall,
),
),
],
),
const SizedBox(height: 12),
Text(step.body, style: theme.textTheme.bodyLarge),
for (final point in step.points) ...<Widget>[
const SizedBox(height: 8),
_Point(text: point),
],
if (step.showsHarnessCommand) ...<Widget>[
const SizedBox(height: 16),
const WalkthroughHarnessCommand(),
],
const SizedBox(height: 24),
_Footer(
last: _last,
canGoBack: _index > 0,
onBack: _back,
onNext: _last ? widget.onClose : _next,
onSkip: widget.onClose,
),
],
),
),
);
// A wide window wraps the sheet's content in its own scroll view; a phone
// sheet does not, so the page scrolls here at large text scales.
return usesDesktopPopups(context)
? content
: SingleChildScrollView(child: content);
}
}
class _Point extends StatelessWidget {
const _Point({required this.text});
final String text;
@override
Widget build(BuildContext context) => Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Padding(
padding: EdgeInsets.only(top: 2),
child: Icon(Icons.circle, size: 6),
),
const SizedBox(width: 12),
Expanded(
child: Text(text, style: Theme.of(context).textTheme.bodyMedium),
),
],
);
}
class _Footer extends StatelessWidget {
const _Footer({
required this.last,
required this.canGoBack,
required this.onBack,
required this.onNext,
required this.onSkip,
});
final bool last;
final bool canGoBack;
final VoidCallback onBack;
final VoidCallback onNext;
final VoidCallback onSkip;
@override
Widget build(BuildContext context) => Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
runSpacing: 8,
children: <Widget>[
TextButton(
key: const ValueKey<String>('walkthrough.skip'),
onPressed: onSkip,
child: const Text('Skip'),
),
Wrap(
spacing: 8,
runSpacing: 8,
children: <Widget>[
TextButton(
key: const ValueKey<String>('walkthrough.back'),
onPressed: canGoBack ? onBack : null,
child: const Text('Back'),
),
FilledButton(
key: const ValueKey<String>('walkthrough.next'),
onPressed: onNext,
child: Text(last ? 'Done' : 'Next'),
),
],
),
],
);
}
@@ -0,0 +1,200 @@
import 'dart:async';
import 'package:flutter/widgets.dart';
import '../../core/api_gateway.dart';
import 'first_run_walkthrough.dart';
import 'walkthrough_store.dart';
/// Reports whether the server has no pipelines, runs or chats yet. Returns null
/// when any of the three lists cannot be read, so an unreadable server never
/// triggers the walkthrough.
Future<bool?> serverHasNoWorkYet(ApiGateway? gateway) async {
if (gateway == null) return null;
try {
final replies = await Future.wait(<Future<JsonMap>>[
gateway.call('list_pipelines', {'include_archived': true}),
gateway.call('list_runs'),
gateway.call('chat_sessions'),
]);
final lists = <Object?>[
replies[0]['pipelines'],
replies[1]['runs'],
replies[2]['chat_sessions'],
];
if (lists.any((list) => list is! List)) return null;
return lists.every((list) => (list as List).isEmpty);
} catch (_) {
return null;
}
}
/// Offers the walkthrough from the Pipelines page, which is the first screen a
/// new user sees. It is offered when:
///
/// * the device has not finished or skipped it yet (first launch, once); or
/// * the device already has, and the connected server has no pipelines, runs
/// or chats, and that server has not been offered it before.
///
/// The server check needs a connected session. While disconnected it waits, and
/// it runs again on each new connection until the server answers. A check that
/// cannot read the server leaves the gate open to retry; a decided check (the
/// walkthrough shown, or the server has work) ends it for this mount.
///
/// Nothing is shown while the store cannot be read, because an unavailable
/// store reports "seen". The check runs only while [enabled] (the Pipelines tab
/// is the one showing).
class FirstRunWalkthroughGate extends StatefulWidget {
const FirstRunWalkthroughGate({
super.key,
required this.child,
required this.store,
required this.enabled,
required this.serverScope,
required this.connection,
required this.connected,
this.gateway,
});
final Widget child;
final WalkthroughStore store;
/// Whether the Pipelines page is the one showing.
final bool enabled;
/// The connected server's scope, recorded when the walkthrough is offered.
final String serverScope;
/// Notifies when the connection may have changed; the gate re-reads
/// [connected] on each notification.
final Listenable connection;
/// Whether the server session is connected right now.
final bool Function() connected;
/// The connected server's gateway, used for the empty-server check.
final ApiGateway? gateway;
@override
State<FirstRunWalkthroughGate> createState() =>
_FirstRunWalkthroughGateState();
}
class _FirstRunWalkthroughGateState extends State<FirstRunWalkthroughGate> {
/// The offer is decided for this mount: shown, or nothing left to offer.
bool _decided = false;
/// An offer is in flight.
bool _running = false;
/// A new connection arrived while an offer was in flight.
bool _connectedAgain = false;
late bool _wasConnected;
@override
void initState() {
super.initState();
_wasConnected = widget.connected();
widget.connection.addListener(_onConnectionChanged);
_scheduleIfEnabled();
}
@override
void didUpdateWidget(FirstRunWalkthroughGate oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.connection != widget.connection) {
oldWidget.connection.removeListener(_onConnectionChanged);
widget.connection.addListener(_onConnectionChanged);
}
_scheduleIfEnabled();
}
@override
void dispose() {
widget.connection.removeListener(_onConnectionChanged);
super.dispose();
}
/// Acts only on a disconnected-to-connected transition, so frequent session
/// notifications while connected never repeat the server check.
void _onConnectionChanged() {
final connected = widget.connected();
final became = connected && !_wasConnected;
_wasConnected = connected;
if (!became || _decided) return;
if (_running) {
_connectedAgain = true;
return;
}
_scheduleIfEnabled();
}
void _scheduleIfEnabled() {
if (_decided || _running || !widget.enabled) return;
_running = true;
// A connection can arrive between frames; the post-frame callback needs a
// frame, so request one explicitly.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!_active) {
// Pipelines is hidden (or the gate is gone): release the flag so a
// later enable reschedules the offer through didUpdateWidget.
_running = false;
return;
}
unawaited(_runOffer());
});
WidgetsBinding.instance.ensureVisualUpdate();
}
/// The gate may offer only while mounted and while the Pipelines page is the
/// one showing. Checked after every await and before every show.
bool get _active => mounted && widget.enabled;
Future<void> _runOffer() async {
try {
await _offer();
} finally {
_running = false;
final again = _connectedAgain;
_connectedAgain = false;
if (again && !_decided) _scheduleIfEnabled();
}
}
Future<void> _offer() async {
final seen = await widget.store.isSeen();
if (!_active) return;
if (!seen) {
_decided = true;
await _showIfActive();
return;
}
if (await widget.store.wasOffered(widget.serverScope)) {
if (!_active) return;
_decided = true;
return;
}
// Wait for a connection; the connection listener runs the check again.
if (!widget.connected()) return;
final empty = await serverHasNoWorkYet(widget.gateway);
if (!_active) return;
// Unreadable: stay open so the next connection retries the check.
if (empty == null) return;
_decided = true;
if (!empty) return;
await widget.store.markOffered(widget.serverScope);
await _showIfActive();
}
Future<void> _showIfActive() async {
if (!_active) return;
await _show();
}
Future<void> _show() async {
await showFirstRunWalkthrough(context, onClosed: widget.store.markSeen);
}
@override
Widget build(BuildContext context) => widget.child;
}
@@ -0,0 +1,86 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'walkthrough_steps.dart';
/// The harness page's command: an agent picker and the one command it selects,
/// with a single copy button for that command.
class WalkthroughHarnessCommand extends StatefulWidget {
const WalkthroughHarnessCommand({super.key});
@override
State<WalkthroughHarnessCommand> createState() =>
_WalkthroughHarnessCommandState();
}
class _WalkthroughHarnessCommandState extends State<WalkthroughHarnessCommand> {
String _agent = harnessAgents.first;
bool _copied = false;
Future<void> _copy(String command) async {
try {
await Clipboard.setData(ClipboardData(text: command));
} catch (_) {
// The command stays selectable, so a failed copy never claims success.
return;
}
if (!mounted) return;
setState(() => _copied = true);
}
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final command = harnessSetupCommand(_agent);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text('Agent', style: Theme.of(context).textTheme.labelLarge),
const SizedBox(height: 8),
Wrap(
spacing: 8,
runSpacing: 8,
children: <Widget>[
for (final agent in harnessAgents)
ChoiceChip(
key: ValueKey<String>('walkthrough.agent.$agent'),
label: Text(agent),
selected: agent == _agent,
onSelected: (_) => setState(() {
_agent = agent;
_copied = false;
}),
),
],
),
const SizedBox(height: 12),
DecoratedBox(
decoration: BoxDecoration(
color: scheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.only(left: 12, right: 4),
child: Row(
children: <Widget>[
Expanded(
child: SelectableText(
command,
key: const ValueKey<String>('walkthrough.command'),
style: Theme.of(context).textTheme.bodyLarge,
),
),
IconButton(
key: const ValueKey<String>('walkthrough.copy'),
tooltip: _copied ? 'Command copied' : 'Copy command',
onPressed: () => _copy(command),
icon: Icon(_copied ? Icons.check : Icons.copy_outlined),
),
],
),
),
),
],
);
}
}
@@ -0,0 +1,79 @@
import 'package:flutter/material.dart';
/// One page of the first-run walkthrough. Pure content: no widgets, so the
/// copy can be checked without pumping a tree.
class WalkthroughStep {
const WalkthroughStep({
required this.icon,
required this.title,
required this.body,
this.points = const <String>[],
this.showsHarnessCommand = false,
});
final IconData icon;
final String title;
final String body;
/// Short labelled facts shown under the body, one per line.
final List<String> points;
/// Whether this page shows the harness setup command picker.
final bool showsHarnessCommand;
}
/// The agents `pipelines harness setup` accepts, in the order they are offered.
const harnessAgents = <String>['claude', 'codex', 'opencode', 'pi'];
/// The command for [agent], exactly as a terminal should run it.
String harnessSetupCommand(String agent) => 'pipelines harness setup $agent';
/// The four walkthrough pages, in order.
const walkthroughSteps = <WalkthroughStep>[
WalkthroughStep(
icon: Icons.hub_outlined,
title: 'Welcome to Pipelines',
body:
'Pipelines runs reusable AI workflows and holds chats with coding '
'agents. Both live on your server, so start by connecting this app '
'to it.',
points: <String>[
'Pipelines: workflows you define once and run again.',
'Chats: conversations with coding agents on the server.',
'Connect: open Settings, then Connection, enter the Server URL and '
'choose Connect.',
],
),
WalkthroughStep(
icon: Icons.build_circle_outlined,
title: 'Set up an agent harness',
body:
'A harness lets Pipelines drive a coding agent. Choose the agent you '
'use, then run its setup command in a terminal.',
showsHarnessCommand: true,
),
WalkthroughStep(
icon: Icons.play_circle_outline,
title: 'Start a run',
body:
'Pipelines shows your workflows. Runs shows every run with its '
'progress and results.',
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.',
],
),
WalkthroughStep(
icon: Icons.forum_outlined,
title: 'Chat with an agent',
body:
'The Chat tab lists your conversations. Open one to read the thread '
'and reply.',
points: <String>[
'Float: pop a chat into its own window while you work elsewhere.',
'Terminal: open a terminal beside the Chat tab for direct commands.',
'New chat starts a conversation with an agent.',
],
),
];
@@ -0,0 +1,118 @@
import 'package:shared_preferences/shared_preferences.dart';
/// The device-level key for "the first-run walkthrough was finished or skipped".
/// It is per device, not per server, so a new server never repeats it.
const String walkthroughSeenKey = 'pipelines.next.firstRunWalkthrough.v1';
/// The key listing the server scopes that were already offered the walkthrough
/// because they had no pipelines, runs or chats yet.
const String walkthroughOfferedKey = 'pipelines.next.walkthroughOffered.v1';
/// The persistence seam for the walkthrough. A store that cannot be read or
/// written reports "seen" and "offered", so an unavailable store never nags.
abstract interface class WalkthroughStore {
Future<bool> isSeen();
Future<void> markSeen();
Future<bool> wasOffered(String serverScope);
Future<void> markOffered(String serverScope);
}
Future<SharedPreferences?> _openPreferences() async {
try {
return await SharedPreferences.getInstance();
} catch (_) {
return null;
}
}
/// `shared_preferences`-backed storage under the `pipelines.next` keys.
///
/// [open] is the seam for an unavailable platform store (tests pass one that
/// yields null); production opens the real preferences.
class SharedPreferencesWalkthroughStore implements WalkthroughStore {
const SharedPreferencesWalkthroughStore({this.open = _openPreferences});
final Future<SharedPreferences?> Function() open;
Future<SharedPreferences?> _preferences() => open();
@override
Future<bool> isSeen() async {
final preferences = await _preferences();
if (preferences == null) return true;
try {
return preferences.getBool(walkthroughSeenKey) ?? false;
} catch (_) {
return true;
}
}
@override
Future<void> markSeen() async {
final preferences = await _preferences();
if (preferences == null) return;
try {
await preferences.setBool(walkthroughSeenKey, true);
} catch (_) {
// Nothing to report: the walkthrough is still dismissed for this run.
}
}
@override
Future<bool> wasOffered(String serverScope) async {
final preferences = await _preferences();
if (preferences == null) return true;
try {
final offered = preferences.getStringList(walkthroughOfferedKey);
return offered?.contains(serverScope) ?? false;
} catch (_) {
return true;
}
}
@override
Future<void> markOffered(String serverScope) async {
final preferences = await _preferences();
if (preferences == null) return;
try {
final offered = <String>{
...?preferences.getStringList(walkthroughOfferedKey),
serverScope,
};
await preferences.setStringList(walkthroughOfferedKey, offered.toList());
} catch (_) {
// A failed write only means the offer may show again later.
}
}
}
/// An in-memory store for tests and previews. It never touches the platform
/// store, so a fixture cannot mark a real device as seen.
class MemoryWalkthroughStore implements WalkthroughStore {
MemoryWalkthroughStore({this.seen = false, Set<String>? offered})
: _offered = {...?offered};
/// Whether the walkthrough is marked seen.
bool seen;
final Set<String> _offered;
/// The server scopes already offered the walkthrough.
Set<String> get offered => Set.unmodifiable(_offered);
@override
Future<bool> isSeen() async => seen;
@override
Future<void> markSeen() async => seen = true;
@override
Future<bool> wasOffered(String serverScope) async =>
_offered.contains(serverScope);
@override
Future<void> markOffered(String serverScope) async =>
_offered.add(serverScope);
}