Label machine provenance and choose server before chat harness

This commit is contained in:
2026-11-08 16:46:23 +00:00
parent 3fbfb85ace
commit 4c57c50a0f
18 changed files with 466 additions and 21 deletions
@@ -1,3 +1,4 @@
import '../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -80,7 +81,7 @@ class ChatThreadHeader extends StatelessWidget {
: null,
title: title.isEmpty ? 'Chat' : title,
titleLeading: heroIdentity,
subtitle: folder,
subtitle: ServerContext.metadata(context, folder),
subtitleIcon: cupertino
? CupertinoIcons.folder
: Icons.folder_outlined,
@@ -1,3 +1,4 @@
import '../../../../core/servers/server_context.dart';
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -78,6 +79,7 @@ class ChatCompactSidebar extends StatelessWidget {
final title = chatSessionTitle(row);
final details = [
title,
?ServerContext.maybeOf(context)?.name,
if (chatSessionSubtitle(row).isNotEmpty) chatSessionSubtitle(row),
if (relativeChatSessionTime(row['updated_at']).isNotEmpty)
'Updated ${relativeChatSessionTime(row['updated_at'])} ago',
@@ -146,6 +148,13 @@ class ChatCompactSidebar extends StatelessWidget {
: Icons.menu_open,
),
const Text('Expand', textAlign: TextAlign.center),
if (ServerContext.maybeOf(context)?.name case final name?)
Text(
name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
],
),
onExpand,
@@ -1,3 +1,4 @@
import '../../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -31,7 +32,7 @@ class ChatCreateDialogFrame extends StatelessWidget {
final label = submitting ? 'Creating…' : chatCreateConfirmLabel;
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return CupertinoAlertDialog(
title: const Text(chatCreateTitle),
title: Text(ServerContext.metadata(context, chatCreateTitle)),
content: content,
actions: [
CupertinoDialogAction(
@@ -48,7 +49,7 @@ class ChatCreateDialogFrame extends StatelessWidget {
);
}
return AlertDialog(
title: const Text(chatCreateTitle),
title: Text(ServerContext.metadata(context, chatCreateTitle)),
content: content,
actions: [
TextButton(
@@ -0,0 +1,83 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/servers/server_catalog.dart';
import '../../../../core/servers/server_context.dart';
import 'chat_adaptive.dart';
/// Select the machine before reading its harnesses or directory listing.
Future<SavedServer?> chooseChatMachine(BuildContext context) async {
final scope = ServerContext.maybeOf(context);
final servers = scope?.notifier?.catalog.servers ?? const <SavedServer>[];
if (servers.isEmpty) return null;
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return showCupertinoModalPopup<SavedServer>(
context: context,
builder: (context) => CupertinoActionSheet(
title: const Text('New chat on…'),
message: const Text(
'Choose a machine. Its configured harnesses appear next.',
),
actions: [
for (final server in servers)
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context, server),
child: Text(server.name),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
}
return showDialog<SavedServer>(
context: context,
builder: (context) => SimpleDialog(
title: const Text('New chat on…'),
children: [
for (final server in servers)
SimpleDialogOption(
onPressed: () => Navigator.pop(context, server),
child: ListTile(
leading: const Icon(Icons.computer),
title: Text(server.name),
subtitle: Text(Uri.parse(server.endpoints.first).host),
),
),
],
),
);
}
Future<void> showChatMachineError(BuildContext context, String message) {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return showCupertinoDialog<void>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: const Text('Machine unavailable'),
content: Text(message),
actions: [
CupertinoDialogAction(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
}
return showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Machine unavailable'),
content: Text(message),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
}
@@ -1,3 +1,4 @@
import '../../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'chat_adaptive.dart';
@@ -87,7 +88,7 @@ class ChatSessionSubtitle extends StatelessWidget {
style: TextStyle(fontWeight: FontWeight.w600),
),
if (closed && metadata.isNotEmpty) const TextSpan(text: ' · '),
TextSpan(text: metadata),
TextSpan(text: ServerContext.metadata(context, metadata)),
],
),
style: TextStyle(color: chatMetadataForeground(context)),
@@ -1,3 +1,5 @@
import '../../../../core/servers/server_context.dart';
import 'chat_machine_picker.dart';
import '../../../../ui/adaptive/segmented_bar.dart';
import 'dart:async';
@@ -176,7 +178,39 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
await _controller.close(_sessionId(session));
}
Future<void> _newChat() async {
bool _openingRequestedChat = false;
void _resumeNewChatIntent() {
final scope = ServerContext.maybeOf(context);
if (_openingRequestedChat ||
scope == null ||
!scope.notifier!.takeNewChatIntent(scope.serverId)) {
return;
}
_openingRequestedChat = true;
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (!mounted) return;
await _newChat(chooseMachine: false);
_openingRequestedChat = false;
});
}
Future<void> _newChat({bool chooseMachine = true}) async {
final scope = ServerContext.maybeOf(context);
if (chooseMachine && scope != null) {
final selected = await chooseChatMachine(context);
if (!mounted || selected == null) return;
if (selected.id != scope.serverId) {
final switched = await scope.notifier!.requestNewChat(selected.id);
if (!switched && mounted) {
await showChatMachineError(
context,
scope.notifier!.error ?? 'The machine could not be selected.',
);
}
return;
}
}
// One id per create intent: a refusal retried in the dialog reuses it.
final operationId = 'native-chat-${DateTime.now().microsecondsSinceEpoch}';
final session = await showChatCreateDialog(
@@ -257,6 +291,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
@override
Widget build(BuildContext context) {
_resumeNewChatIntent();
return ListenableBuilder(
listenable: _controller,
builder: (context, _) {
@@ -1,3 +1,4 @@
import '../../../core/servers/server_context.dart';
import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
@@ -203,7 +204,7 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
);
return ShellBar(
title: detail.displayName,
subtitle: pipelineSubtitle(detail),
subtitle: ServerContext.metadata(context, pipelineSubtitle(detail)),
actions: _actions(context, detail),
child: panel,
);
@@ -1,3 +1,4 @@
import '../../../core/servers/server_context.dart';
import '../../../ui/layout/app_list_avatar.dart';
import '../../../ui/layout/app_list_row.dart';
import 'package:flutter/cupertino.dart';
@@ -242,14 +243,18 @@ class PipelineListPanel extends StatelessWidget {
color: runStatusColor(badge.state).resolveFrom(context),
semanticLabel: runStateLabel(badge.state),
),
subtitle: Text(_rowMetadata(pipeline)),
subtitle: Text(
ServerContext.metadata(context, _rowMetadata(pipeline)),
),
// A narrow pane keeps the latest state, the useful decision signal;
// stage counts, schedules and version live in the detail instead.
// Do not turn an in-flight or failed run-history read into a false
// no-runs claim: the line stays blank until history is known.
compactSubtitle: badge == null
? const SizedBox.shrink()
: Text(runStateLabel(badge.state)),
? Text(ServerContext.metadata(context, ''))
: Text(
ServerContext.metadata(context, runStateLabel(badge.state)),
),
);
},
);
@@ -1,3 +1,4 @@
import '../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -150,7 +151,7 @@ class _RunDetailViewState extends State<RunDetailView> {
if (inShellBar) {
return ShellBar(
title: title,
subtitle: subtitle,
subtitle: ServerContext.metadata(context, subtitle),
onTitlePressed: openPipeline,
expandableTitle: true,
titleAction: pipelineAction,
@@ -170,7 +171,7 @@ class _RunDetailViewState extends State<RunDetailView> {
onPressed: widget.onBack,
),
title: title,
subtitle: subtitle,
subtitle: ServerContext.metadata(context, subtitle),
onTitlePressed: openPipeline,
expandableTitle: true,
titleAction: pipelineAction,
@@ -1,3 +1,4 @@
import '../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -85,6 +86,7 @@ class RunListRow extends StatelessWidget {
String subtitle(DateTime now) {
final facts = runRowFacts(run, now);
return [
?ServerContext.maybeOf(context)?.name,
?pipelineLabel,
if (scheduled) 'Scheduled',
?facts.duration,
@@ -99,6 +101,7 @@ class RunListRow extends StatelessWidget {
String compactSubtitle(DateTime now) {
final facts = runRowFacts(run, now);
return [
?ServerContext.maybeOf(context)?.name,
?pipelineLabel,
if (scheduled) 'Scheduled',
if (run['executing'] == true && facts.progress != null) facts.progress!,
@@ -16,6 +16,35 @@ class ServerConnections extends ChangeNotifier {
bool _disposed = false;
ServerCatalog get catalog => _catalog;
String? _newChatServerId;
String? get newChatServerId => _newChatServerId;
/// A browser navigation may carry only this non-secret create intent.
void restoreNewChatIntent(String id) {
if (id == _catalog.active?.id) _newChatServerId = id;
}
bool takeNewChatIntent(String? id) {
if (id == null || id != _newChatServerId || id != _catalog.active?.id) {
return false;
}
_newChatServerId = null;
return true;
}
/// Keep the intent outside the app that selecting another machine disposes.
Future<bool> requestNewChat(String id) async {
if (_busy || _disposed) return false;
_newChatServerId = id;
final selected = await _change(
() => _catalog.select(id),
activate: true,
rollbackSelection: true,
);
if (!selected) _newChatServerId = null;
return selected;
}
bool get busy => _busy;
String? get error => _error;
@@ -63,11 +92,15 @@ class ServerConnections extends ChangeNotifier {
(_catalog.active?.id == server.id || _catalog.active == null),
);
Future<bool> select(String id, {bool activate = true}) => _change(
() => _catalog.select(id),
activate: activate,
rollbackSelection: true,
);
Future<bool> select(String id, {bool activate = true}) {
if (_busy || _disposed) return Future.value(false);
_newChatServerId = null;
return _change(
() => _catalog.select(id),
activate: activate,
rollbackSelection: true,
);
}
Future<bool> remove(String id) =>
_change(() => _catalog.remove(id), activate: _catalog.active?.id == id);