feat(ui): complete M1 Milestone - read-only Dashboard and Detail Pane with status.sh integration
This commit is contained in:
@@ -1,121 +1,155 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:mam_core/mam_core.dart';
|
||||
|
||||
import 'src/providers/session_providers.dart';
|
||||
import 'src/theme/app_theme.dart';
|
||||
import 'src/widgets/detail_pane.dart';
|
||||
import 'src/widgets/session_table.dart';
|
||||
import 'src/widgets/stale_banner.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
runApp(const ProviderScope(child: MamDesktopApp()));
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
class MamDesktopApp extends StatelessWidget {
|
||||
const MamDesktopApp({super.key});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
// This is the theme of your application.
|
||||
//
|
||||
// TRY THIS: Try running your application with "flutter run". You'll see
|
||||
// the application has a purple toolbar. Then, without quitting the app,
|
||||
// try changing the seedColor in the colorScheme below to Colors.green
|
||||
// and then invoke "hot reload" (save your changes or press the "hot
|
||||
// reload" button in a Flutter-supported IDE, or press "r" if you used
|
||||
// the command line to start the app).
|
||||
//
|
||||
// Notice that the counter didn't reset back to zero; the application
|
||||
// state is not lost during the reload. To reset the state, use hot
|
||||
// restart instead.
|
||||
//
|
||||
// This works for code too, not just values: Most code changes can be
|
||||
// tested with just a hot reload.
|
||||
colorScheme: .fromSeed(seedColor: Colors.deepPurple),
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
title: 'multi-agent-mux',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: buildAppTheme(),
|
||||
home: const DashboardScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
class DashboardScreen extends ConsumerWidget {
|
||||
const DashboardScreen({super.key});
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final pollAsync = ref.watch(sessionsPollProvider);
|
||||
|
||||
return Scaffold(
|
||||
body: DecoratedBox(
|
||||
decoration: const BoxDecoration(gradient: backgroundGradient),
|
||||
child: SafeArea(
|
||||
child: pollAsync.when(
|
||||
data: (poll) => _DashboardBody(poll: poll),
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stackTrace) => _ErrorScreen(error: error),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
// This call to setState tells the Flutter framework that something has
|
||||
// changed in this State, which causes it to rerun the build method below
|
||||
// so that the display can reflect the updated values. If we changed
|
||||
// _counter without calling setState(), then the build method would not be
|
||||
// called again, and so nothing would appear to happen.
|
||||
_counter++;
|
||||
});
|
||||
}
|
||||
class _ErrorScreen extends StatelessWidget {
|
||||
final Object error;
|
||||
const _ErrorScreen({required this.error});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// This method is rerun every time setState is called, for instance as done
|
||||
// by the _incrementCounter method above.
|
||||
//
|
||||
// The Flutter framework has been optimized to make rerunning build methods
|
||||
// fast, so that you can just rebuild anything that needs updating rather
|
||||
// than having to individually change instances of widgets.
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
// TRY THIS: Try changing the color here to a specific color (to
|
||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
||||
// change color while the other colors stay the same.
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
// Center is a layout widget. It takes a single child and positions it
|
||||
// in the middle of the parent.
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
// Column is also a layout widget. It takes a list of children and
|
||||
// arranges them vertically. By default, it sizes itself to fit its
|
||||
// children horizontally, and tries to be as tall as its parent.
|
||||
//
|
||||
// Column has various properties to control how it sizes itself and
|
||||
// how it positions its children. Here we use mainAxisAlignment to
|
||||
// center the children vertically; the main axis here is the vertical
|
||||
// axis because Columns are vertical (the cross axis would be
|
||||
// horizontal).
|
||||
//
|
||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
||||
// action in the IDE, or press "p" in the console), to see the
|
||||
// wireframe for each widget.
|
||||
mainAxisAlignment: .center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('You have pushed the button this many times:'),
|
||||
const Icon(Icons.error_outline, color: AppColors.danger, size: 40),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
'Failed to start status polling:\n$error',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(color: AppColors.danger),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DashboardBody extends ConsumerWidget {
|
||||
final SessionsPoll poll;
|
||||
const _DashboardBody({required this.poll});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final selectedName = ref.watch(selectedSessionNameProvider);
|
||||
final sessions = poll.snapshot?.sessions ?? const <SessionRow>[];
|
||||
final matches = sessions.where((s) => s.name == selectedName);
|
||||
final selectedRow = matches.isEmpty ? null : matches.first;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
_TopBar(poll: poll),
|
||||
StaleBanner(poll: poll),
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: SessionTable(
|
||||
sessions: sessions,
|
||||
selectedName: selectedName,
|
||||
onSelect: (name) =>
|
||||
ref.read(selectedSessionNameProvider.notifier).state =
|
||||
name,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 380, child: DetailPane(session: selectedRow)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TopBar extends StatelessWidget {
|
||||
final SessionsPoll poll;
|
||||
const _TopBar({required this.poll});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final count = poll.snapshot?.sessions.length ?? 0;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text(
|
||||
'multi-agent-mux',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accent.withValues(alpha: 0.18),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
'$count session${count == 1 ? '' : 's'}',
|
||||
style: const TextStyle(
|
||||
color: AppColors.accent2,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:mam_core/mam_core.dart';
|
||||
|
||||
import '../status_script_locator.dart';
|
||||
|
||||
/// The single [SessionService] instance for this app run — owns the
|
||||
/// resolved path to `status.sh`.
|
||||
final sessionServiceProvider = Provider<SessionService>((ref) {
|
||||
return SessionService(statusScriptPath: locateStatusScript());
|
||||
});
|
||||
|
||||
/// Polling + stale/backoff (D6) sits in `mam_core`; this provider just wires
|
||||
/// it up. `apps/mam_desktop` does not reimplement the timer/backoff logic.
|
||||
final statusRepositoryProvider = Provider<StatusRepository>((ref) {
|
||||
return StatusRepository(sessionService: ref.watch(sessionServiceProvider));
|
||||
});
|
||||
|
||||
/// Reactive stream of [SessionsPoll] the UI subscribes to. 4s base interval
|
||||
/// on success, backing off to 6s/15s on repeated `status.sh` failures.
|
||||
final sessionsPollProvider = StreamProvider<SessionsPoll>((ref) {
|
||||
final repo = ref.watch(statusRepositoryProvider);
|
||||
return repo.watch();
|
||||
});
|
||||
|
||||
/// Currently selected row name for the Master-Detail layout.
|
||||
final selectedSessionNameProvider = StateProvider<String?>((ref) => null);
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'dart:io';
|
||||
|
||||
/// Locates `status.sh` by walking up from the current working directory to
|
||||
/// the repo root (marked by `.git`), then descending a fixed path — robust
|
||||
/// regardless of which subdirectory `flutter run` happens to be invoked
|
||||
/// from, unlike a hardcoded relative path.
|
||||
String locateStatusScript() {
|
||||
var dir = Directory.current;
|
||||
while (!Directory('${dir.path}/.git').existsSync()) {
|
||||
final parent = dir.parent;
|
||||
if (parent.path == dir.path) {
|
||||
throw StateError(
|
||||
'Could not locate the repo root (.git) from ${Directory.current.path}. '
|
||||
'Run mam_desktop from within the multi-agent-mux repo checkout.',
|
||||
);
|
||||
}
|
||||
dir = parent;
|
||||
}
|
||||
|
||||
final scriptPath =
|
||||
'${dir.path}/.agents/skills/multi-agent-mux-status/scripts/status.sh';
|
||||
if (!File(scriptPath).existsSync()) {
|
||||
throw StateError('status.sh not found at $scriptPath');
|
||||
}
|
||||
return scriptPath;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AppColors {
|
||||
AppColors._();
|
||||
|
||||
static const bgTop = Color(0xFF0B0F1A);
|
||||
static const bgBottom = Color(0xFF141B2E);
|
||||
static const accent = Color(0xFF7C5CFF);
|
||||
static const accent2 = Color(0xFF19C6E0);
|
||||
static const surface = Color(0xFF171E31);
|
||||
static const surfaceAlt = Color(0xFF1E2740);
|
||||
static const border = Color(0xFF2A3350);
|
||||
static const textPrimary = Color(0xFFEAF0FF);
|
||||
static const textSecondary = Color(0xFF93A0C4);
|
||||
static const danger = Color(0xFFFF5C7A);
|
||||
static const warning = Color(0xFFFFB454);
|
||||
static const success = Color(0xFF4CE0B3);
|
||||
}
|
||||
|
||||
const backgroundGradient = LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.bgTop, AppColors.bgBottom],
|
||||
);
|
||||
|
||||
ThemeData buildAppTheme() {
|
||||
final base = ThemeData(brightness: Brightness.dark, useMaterial3: true);
|
||||
return base.copyWith(
|
||||
scaffoldBackgroundColor: AppColors.bgTop,
|
||||
colorScheme: base.colorScheme.copyWith(
|
||||
primary: AppColors.accent,
|
||||
secondary: AppColors.accent2,
|
||||
surface: AppColors.surface,
|
||||
error: AppColors.danger,
|
||||
),
|
||||
textTheme: base.textTheme.apply(
|
||||
bodyColor: AppColors.textPrimary,
|
||||
displayColor: AppColors.textPrimary,
|
||||
),
|
||||
dividerColor: AppColors.border,
|
||||
cardTheme: CardThemeData(
|
||||
color: AppColors.surface,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: const BorderSide(color: AppColors.border),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:mam_core/mam_core.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
class _KV {
|
||||
final String label;
|
||||
final String value;
|
||||
final bool copyable;
|
||||
const _KV(this.label, this.value, {this.copyable = false});
|
||||
}
|
||||
|
||||
class DetailPane extends StatelessWidget {
|
||||
final SessionRow? session;
|
||||
const DetailPane({super.key, required this.session});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = session;
|
||||
return DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.surface, AppColors.surfaceAlt],
|
||||
),
|
||||
border: Border(left: BorderSide(color: AppColors.border)),
|
||||
),
|
||||
child: s == null ? const _EmptyDetail() : _DetailContent(session: s),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EmptyDetail extends StatelessWidget {
|
||||
const _EmptyDetail();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'Select a session to see details',
|
||||
style: TextStyle(color: AppColors.textSecondary),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DetailContent extends StatelessWidget {
|
||||
final SessionRow session;
|
||||
const _DetailContent({required this.session});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = session;
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_Header(session: s),
|
||||
const SizedBox(height: 24),
|
||||
_Section(
|
||||
title: 'PANE',
|
||||
entries: [
|
||||
_KV('pid', s.pane.pid?.toString() ?? '?'),
|
||||
_KV('cwd', s.pane.cwd ?? '?'),
|
||||
_KV('cmd', s.pane.cmd ?? '?'),
|
||||
_KV('cmd_full', s.pane.cmdFull ?? '?', copyable: true),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_Section(
|
||||
title: 'ATTACH',
|
||||
entries: [
|
||||
_KV('attach_command', s.attachCommand ?? '?', copyable: true),
|
||||
_KV('start_command', s.startCommand ?? '?', copyable: true),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_Section(
|
||||
title: 'STATUS',
|
||||
entries: [
|
||||
_KV('last_visible_status', s.lastVisibleStatus ?? '?'),
|
||||
_KV('resume_state', s.resumeState),
|
||||
_KV('job_id', s.jobId),
|
||||
_KV('job_status', s.jobStatus),
|
||||
_KV(
|
||||
'drift_classes',
|
||||
s.driftClasses.isEmpty ? '-' : s.driftClasses.join(', '),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Header extends StatelessWidget {
|
||||
final SessionRow session;
|
||||
const _Header({required this.session});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = session;
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.accent, AppColors.accent2],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.accent.withValues(alpha: 0.35),
|
||||
blurRadius: 24,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
s.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
_Pill(text: s.status.toUpperCase()),
|
||||
_Pill(text: s.tmuxAlive ? 'TMUX ALIVE' : 'TMUX DEAD'),
|
||||
if (s.role != null) _Pill(text: s.role!.toUpperCase()),
|
||||
_Pill(text: 'SERVER: ${s.server}'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Pill extends StatelessWidget {
|
||||
final String text;
|
||||
const _Pill({required this.text});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.25),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Section extends StatelessWidget {
|
||||
final String title;
|
||||
final List<_KV> entries;
|
||||
const _Section({required this.title, required this.entries});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
color: AppColors.textSecondary,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 1.2,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
...entries.map((e) => _KVRow(entry: e)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _KVRow extends StatelessWidget {
|
||||
final _KV entry;
|
||||
const _KVRow({required this.entry});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 130,
|
||||
child: Text(
|
||||
entry.label,
|
||||
style: const TextStyle(
|
||||
color: AppColors.textSecondary,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: SelectableText(
|
||||
entry.value,
|
||||
style: const TextStyle(
|
||||
color: AppColors.textPrimary,
|
||||
fontSize: 13,
|
||||
fontFamily: 'monospace',
|
||||
),
|
||||
),
|
||||
),
|
||||
if (entry.copyable)
|
||||
SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: IconButton(
|
||||
padding: EdgeInsets.zero,
|
||||
icon: const Icon(
|
||||
Icons.copy,
|
||||
size: 15,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
tooltip: 'Copy',
|
||||
onPressed: () =>
|
||||
Clipboard.setData(ClipboardData(text: entry.value)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
import 'package:data_table_2/data_table_2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mam_core/mam_core.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
class SessionTable extends StatelessWidget {
|
||||
final List<SessionRow> sessions;
|
||||
final String? selectedName;
|
||||
final ValueChanged<String> onSelect;
|
||||
|
||||
const SessionTable({
|
||||
super.key,
|
||||
required this.sessions,
|
||||
required this.selectedName,
|
||||
required this.onSelect,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: DataTable2(
|
||||
columnSpacing: 16,
|
||||
horizontalMargin: 16,
|
||||
minWidth: 900,
|
||||
headingRowColor: WidgetStateProperty.all(AppColors.surfaceAlt),
|
||||
headingTextStyle: const TextStyle(
|
||||
color: AppColors.textSecondary,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 12,
|
||||
letterSpacing: 0.6,
|
||||
),
|
||||
dataRowHeight: 44,
|
||||
empty: const Center(
|
||||
child: Text(
|
||||
'(no sessions registered)',
|
||||
style: TextStyle(color: AppColors.textSecondary),
|
||||
),
|
||||
),
|
||||
columns: const [
|
||||
DataColumn2(label: Text('NAME'), size: ColumnSize.L),
|
||||
DataColumn2(label: Text('SERVER'), size: ColumnSize.S),
|
||||
DataColumn2(label: Text('YAML'), size: ColumnSize.S),
|
||||
DataColumn2(label: Text('TMUX'), size: ColumnSize.S),
|
||||
DataColumn2(label: Text('CMD'), size: ColumnSize.S),
|
||||
DataColumn2(label: Text('RESUME'), size: ColumnSize.S),
|
||||
DataColumn2(label: Text('JOB_ID'), size: ColumnSize.S),
|
||||
DataColumn2(label: Text('JOB_STATUS'), size: ColumnSize.S),
|
||||
DataColumn2(label: Text('DRIFT'), size: ColumnSize.S),
|
||||
],
|
||||
rows: sessions.map((s) {
|
||||
final selected = s.name == selectedName;
|
||||
return DataRow2(
|
||||
selected: selected,
|
||||
color: selected
|
||||
? WidgetStateProperty.all(
|
||||
AppColors.accent.withValues(alpha: 0.16),
|
||||
)
|
||||
: null,
|
||||
onTap: () => onSelect(s.name),
|
||||
cells: [
|
||||
DataCell(
|
||||
Text(
|
||||
s.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
s.server,
|
||||
style: const TextStyle(color: AppColors.textSecondary),
|
||||
),
|
||||
),
|
||||
DataCell(_StatusChip(status: s.status)),
|
||||
DataCell(_TmuxChip(alive: s.tmuxAlive)),
|
||||
DataCell(
|
||||
Text(
|
||||
s.pane.cmd ?? '?',
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
s.resumeState,
|
||||
style: const TextStyle(color: AppColors.textSecondary),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
s.jobId,
|
||||
style: const TextStyle(color: AppColors.textSecondary),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
s.jobStatus,
|
||||
style: const TextStyle(color: AppColors.textSecondary),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
s.hasDrift
|
||||
? Text(
|
||||
s.driftClasses.join(','),
|
||||
style: const TextStyle(
|
||||
color: AppColors.warning,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'-',
|
||||
style: TextStyle(color: AppColors.textSecondary),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StatusChip extends StatelessWidget {
|
||||
final String status;
|
||||
const _StatusChip({required this.status});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Color color;
|
||||
switch (status) {
|
||||
case 'running':
|
||||
color = AppColors.success;
|
||||
case 'stopped':
|
||||
case 'terminated':
|
||||
case 'archived':
|
||||
color = AppColors.textSecondary;
|
||||
default:
|
||||
color = AppColors.warning;
|
||||
}
|
||||
return Text(
|
||||
status,
|
||||
style: TextStyle(color: color, fontWeight: FontWeight.w600),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TmuxChip extends StatelessWidget {
|
||||
final bool alive;
|
||||
const _TmuxChip({required this.alive});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(
|
||||
alive ? 'alive' : 'dead',
|
||||
style: TextStyle(
|
||||
color: alive ? AppColors.success : AppColors.danger,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mam_core/mam_core.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// D6: when `status.sh` polling fails, the last good snapshot is kept and
|
||||
/// this banner surfaces staleness instead of the dashboard silently
|
||||
/// blanking out or crashing.
|
||||
class StaleBanner extends StatelessWidget {
|
||||
final SessionsPoll poll;
|
||||
const StaleBanner({super.key, required this.poll});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!poll.stale) return const SizedBox.shrink();
|
||||
|
||||
final lastOk = poll.lastOkAt;
|
||||
final lastOkText = lastOk == null
|
||||
? '?'
|
||||
: '${lastOk.hour.toString().padLeft(2, '0')}:'
|
||||
'${lastOk.minute.toString().padLeft(2, '0')}:'
|
||||
'${lastOk.second.toString().padLeft(2, '0')}';
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
color: AppColors.warning.withValues(alpha: 0.15),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
color: AppColors.warning,
|
||||
size: 18,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'⚠ status snapshot stale (last ok: $lastOkText)',
|
||||
style: const TextStyle(
|
||||
color: AppColors.warning,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,74 @@
|
||||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility in the flutter_test package. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mam_core/mam_core.dart';
|
||||
|
||||
import 'package:mam_desktop/main.dart';
|
||||
import 'package:mam_desktop/src/providers/session_providers.dart';
|
||||
import 'package:mam_desktop/src/theme/app_theme.dart';
|
||||
import 'package:mam_desktop/src/widgets/detail_pane.dart';
|
||||
import 'package:mam_desktop/src/widgets/session_table.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const MyApp());
|
||||
testWidgets('SessionTable renders rows and drives selection', (tester) async {
|
||||
final rows = [
|
||||
SessionRow(
|
||||
name: 'demo-session',
|
||||
server: 'default',
|
||||
status: 'running',
|
||||
tmuxAlive: true,
|
||||
pane: const Pane(
|
||||
pid: 123,
|
||||
cwd: '/x',
|
||||
cmd: 'claude',
|
||||
cmdFull: 'claude --foo',
|
||||
),
|
||||
role: 'creator',
|
||||
resumeState: 'yes',
|
||||
jobId: '-',
|
||||
jobStatus: '-',
|
||||
attachCommand: 'tmux attach -t demo-session',
|
||||
driftClasses: const ['B'],
|
||||
),
|
||||
];
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('1'), findsNothing);
|
||||
String? selected;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: buildAppTheme(),
|
||||
home: Scaffold(
|
||||
body: SessionTable(
|
||||
sessions: rows,
|
||||
selectedName: null,
|
||||
onSelect: (name) => selected = name,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Tap the '+' icon and trigger a frame.
|
||||
await tester.tap(find.byIcon(Icons.add));
|
||||
expect(find.text('demo-session'), findsOneWidget);
|
||||
expect(find.text('running'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('demo-session'));
|
||||
await tester.pump();
|
||||
expect(selected, 'demo-session');
|
||||
});
|
||||
|
||||
// Verify that our counter has incremented.
|
||||
expect(find.text('0'), findsNothing);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
testWidgets('DetailPane shows placeholder when nothing selected', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: buildAppTheme(),
|
||||
home: const Scaffold(body: DetailPane(session: null)),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Select a session to see details'), findsOneWidget);
|
||||
});
|
||||
|
||||
test('selectedSessionNameProvider defaults to null', () {
|
||||
final container = ProviderContainer();
|
||||
addTearDown(container.dispose);
|
||||
expect(container.read(selectedSessionNameProvider), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user