Complete prompt presets, body-priority panes and clearer chat and stage layouts

This commit is contained in:
2026-10-25 23:11:06 +00:00
parent de1b62791f
commit 121ace1cee
31 changed files with 990 additions and 396 deletions
@@ -13,13 +13,11 @@ import 'chat_create_dialog_frame.dart';
import 'chat_create_fields.dart';
import 'chat_prompt_chooser.dart';
/// The instructions field's helper and the model note, verbatim from the web.
/// The instructions field's helper and the creation-time model behavior.
const String chatCreateInstructionsHelper =
"Preloaded as this chat's session instructions. The agent still reads the "
"repository's AGENTS.md and skills.";
const String chatCreateModelNote =
"This server has no request for choosing a chat's model, so a new chat "
"uses the server's default.";
const String chatCreateModelNote = "New chats start with the server's default model.";
class ChatDraft {
const ChatDraft({
@@ -83,9 +81,7 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
SharedPreferencesChatCreatePromptStore(
serverId: serverStorageScope(serverIdentity(widget.repository.gateway)),
);
final _instructions = TextEditingController(
text: chatDefaultSessionInstructions,
);
final _instructions = TextEditingController();
final _name = TextEditingController();
/// The name follows the folder and harness until the operator edits it.
@@ -97,6 +93,7 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
/// A user's choice or edit wins over any pending saved-prompt read.
bool _promptTouched = false;
String _promptChoice = ChatPromptChooser.custom;
String _customPrompt = '';
ChatCreatePrompt? _savedPrompt;
int _recall = 0;
List<String> _directories = const [];
@@ -159,6 +156,7 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
}
bool get _catalogReady => !_loading && _catalogError == null;
bool get _promptReady => !_sendPrompt || _instructions.text.trim().isNotEmpty;
/// A folder or harness pick: the default name follows it, and the prompt
/// choice last made there comes back.
@@ -169,21 +167,35 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
_name.text = defaultChatName(directory, chatBackendLabel(backend));
}
final recall = ++_recall;
setState(() {
_savedPrompt = null;
if (_promptChoice == ChatPromptChooser.lastUsed) {
_promptChoice = ChatPromptChooser.custom;
_customPrompt = _instructions.text;
}
});
final saved = await _prompts.read(backend, directory);
if (!mounted || recall != _recall) return;
if (_promptTouched) return;
setState(() {
// Prompt text can be recalled, but sending it always requires an
// explicit choice in this new-chat dialog.
_sendPrompt = false;
_instructions.text = saved?.text ?? chatDefaultSessionInstructions;
_savedPrompt = saved;
_promptChoice = ChatPromptChooser.custom;
if (!_promptTouched) {
_sendPrompt = false;
_instructions.clear();
_promptChoice = ChatPromptChooser.custom;
}
});
}
void _selectPrompt(String choice) {
if (!mounted ||
_submitting ||
(choice == ChatPromptChooser.lastUsed && _savedPrompt == null)) {
return;
}
setState(() {
if (_promptChoice == ChatPromptChooser.custom) {
_customPrompt = _instructions.text;
}
_promptTouched = true;
_promptChoice = choice;
if (choice == ChatPromptChooser.careful) {
@@ -193,6 +205,7 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
_instructions.text = _savedPrompt!.text;
_sendPrompt = true;
} else {
_instructions.text = _customPrompt;
_sendPrompt = true;
}
});
@@ -200,8 +213,14 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
Future<void> _submit() async {
if (!_catalogReady || _submitting) return;
if (!_promptReady) {
setState(() => _formError = 'Enter a prompt or choose a pre-filled one.');
return;
}
final directory = _directory ?? chatHomeDirectory;
final backend = _backend ?? '';
final sendPrompt = _sendPrompt;
final promptText = _instructions.text;
setState(() {
_submitting = true;
_formError = null;
@@ -215,17 +234,20 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
: name,
directory: directory,
backend: backend,
instructions: _sendPrompt ? _instructions.text : '',
instructions: sendPrompt ? promptText : '',
),
widget.operationId,
);
// Next time in this folder with this harness, the same choice.
unawaited(
_prompts.write(backend, directory, (
send: _sendPrompt,
text: _instructions.text,
)),
);
// Only an actually sent prompt becomes Last used. Starting a promptless
// chat must not erase a saved preset (or wait for its pending read).
if (sendPrompt) {
unawaited(
_prompts.write(backend, directory, (
send: sendPrompt,
text: promptText,
)),
);
}
if (!mounted) return;
Navigator.pop(context, session);
} catch (error) {
@@ -298,10 +320,12 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
controller: _instructions,
minLines: 2,
maxLines: 4,
onChanged: (_) {
placeholder: 'Write your custom prompt',
onChanged: (value) {
setState(() {
_promptTouched = true;
_promptChoice = ChatPromptChooser.custom;
_customPrompt = value;
});
},
)
@@ -311,10 +335,14 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
controller: _instructions,
minLines: 2,
maxLines: 4,
onChanged: (_) {
decoration: const InputDecoration(
hintText: 'Write your custom prompt',
),
onChanged: (value) {
setState(() {
_promptTouched = true;
_promptChoice = ChatPromptChooser.custom;
_customPrompt = value;
});
},
),
@@ -347,7 +375,7 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
return ChatCreateDialogFrame(
content: content,
canSubmit: _catalogReady,
canSubmit: _catalogReady && _promptReady,
submitting: _submitting,
onCancel: () => Navigator.pop(context),
onSubmit: _submit,
@@ -156,7 +156,7 @@ class _CupertinoSessionRow extends StatelessWidget {
final meta = chatSessionMetaLines(session);
final recency = relativeChatSessionTime(session['updated_at']);
final status = chatSessionRowStatus(session, unseen: unseen);
final statusStyle = TextStyle(
final statusStyle = theme.textTheme.tabLabelTextStyle.copyWith(
color: status == 'Closed' ? secondary : theme.primaryColor,
);
return Semantics(
@@ -166,28 +166,14 @@ class _CupertinoSessionRow extends StatelessWidget {
backgroundColor: selected
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
: null,
leading: Icon(
sessionCupertinoIcon(session),
color: selected ? theme.primaryColor : null,
),
// As on the web: the title with the unread/closed word trailing, then
// the muted `recency · directory · model` line.
title: ChatSessionRowContent(
title: chatSessionTitle(session),
status: status,
recency: recency.isEmpty ? null : recency,
meta: meta,
titleStyle: theme.textTheme.textStyle.copyWith(
fontWeight: FontWeight.w600,
leading: Icon(
sessionCupertinoIcon(session),
color: selected ? theme.primaryColor : null,
),
metaStyle: TextStyle(color: secondary),
statusStyle: statusStyle,
),
subtitle: null,
onTap: () => onOpen(session),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
actions: [
SessionStarButton(
key: Key('chat-star-$id'),
session: session,
@@ -200,7 +186,20 @@ class _CupertinoSessionRow extends StatelessWidget {
onSelected: _select,
),
],
title: chatSessionTitle(session),
status: status,
recency: recency.isEmpty ? null : recency,
meta: meta,
titleStyle: theme.textTheme.textStyle.copyWith(
fontWeight: FontWeight.w600,
),
metaStyle: theme.textTheme.tabLabelTextStyle.copyWith(
color: secondary,
),
statusStyle: statusStyle,
),
subtitle: null,
onTap: () => onOpen(session),
),
);
}
@@ -161,33 +161,21 @@ class _MaterialSessionRow extends StatelessWidget {
final meta = chatSessionMetaLines(session);
final recency = relativeChatSessionTime(session['updated_at']);
final status = chatSessionRowStatus(session, unseen: unseen);
final statusStyle = TextStyle(
color: status == 'Closed' ? secondary : theme.colorScheme.primary,
);
final statusStyle =
theme.textTheme.labelSmall?.copyWith(
color: status == 'Closed' ? secondary : theme.colorScheme.primary,
) ??
TextStyle(color: theme.colorScheme.primary);
return ListTile(
key: Key('chat-row-$id'),
selected: selected,
selectedTileColor: theme.colorScheme.secondaryContainer,
selectedColor: theme.colorScheme.onSecondaryContainer,
leading: Icon(sessionMaterialIcon(session)),
// As on the web: the title with the unread/closed word trailing, then
// the muted `recency · directory · model` line.
title: ChatSessionRowContent(
title: chatSessionTitle(session),
status: status,
recency: recency.isEmpty ? null : recency,
meta: meta,
titleStyle:
theme.textTheme.titleSmall ??
const TextStyle(fontWeight: FontWeight.w600),
metaStyle: TextStyle(color: secondary),
statusStyle: statusStyle,
),
subtitle: null,
onTap: () => onOpen(session),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
leading: Icon(sessionMaterialIcon(session)),
actions: [
SessionStarButton(
key: Key('chat-star-$id'),
session: session,
@@ -197,10 +185,23 @@ class _MaterialSessionRow extends StatelessWidget {
key: Key('chat-actions-$id'),
session: session,
duplicateTitles: duplicateTitles,
onSelected: (action) => _select(action),
onSelected: _select,
),
],
title: chatSessionTitle(session),
status: status,
recency: recency.isEmpty ? null : recency,
meta: meta,
titleStyle:
theme.textTheme.titleSmall ??
const TextStyle(fontWeight: FontWeight.w600),
metaStyle:
theme.textTheme.bodySmall?.copyWith(color: secondary) ??
TextStyle(color: secondary),
statusStyle: statusStyle,
),
subtitle: null,
onTap: () => onOpen(session),
);
}
@@ -13,6 +13,8 @@ class ChatSessionRowContent extends StatelessWidget {
required this.titleStyle,
required this.metaStyle,
required this.statusStyle,
this.leading,
this.actions = const [],
});
final String title;
@@ -22,6 +24,8 @@ class ChatSessionRowContent extends StatelessWidget {
final TextStyle titleStyle;
final TextStyle metaStyle;
final TextStyle statusStyle;
final Widget? leading;
final List<Widget> actions;
@override
Widget build(BuildContext context) {
@@ -35,13 +39,25 @@ class ChatSessionRowContent extends StatelessWidget {
overflow: TextOverflow.ellipsis,
style: titleStyle,
),
if (status != null) ...[
if (status != null || leading != null) ...[
const SizedBox(height: 2),
Align(
alignment: AlignmentDirectional.centerStart,
child: _StatusLabel(status: status!, style: statusStyle),
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
children: [
?leading,
if (status != null)
_StatusLabel(status: status!, style: statusStyle),
],
),
],
for (final line in meta)
Text(
line,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: metaStyle,
),
if (recency != null && recency!.isNotEmpty) ...[
const SizedBox(height: 3),
Align(
@@ -54,12 +70,10 @@ class ChatSessionRowContent extends StatelessWidget {
),
),
],
for (final line in meta)
Text(
line,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: metaStyle,
if (actions.isNotEmpty)
Align(
alignment: AlignmentDirectional.centerEnd,
child: Wrap(alignment: WrapAlignment.end, children: actions),
),
],
);
@@ -77,7 +91,7 @@ class _StatusLabel extends StatelessWidget {
if (status != 'New') {
return Text(
status,
maxLines: 2,
maxLines: 1,
style: style.copyWith(fontWeight: FontWeight.w600),
);
}
@@ -89,7 +103,7 @@ class _StatusLabel extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1),
child: Text(
status,
maxLines: 2,
maxLines: 1,
style: style.copyWith(
color: Colors.white,
fontWeight: FontWeight.w700,
@@ -17,6 +17,7 @@ import '../pipeline_query.dart';
import '../pipelines_controller.dart';
import 'pipeline_controls.dart';
import 'pipeline_filter_page.dart';
import 'pipeline_scope_control.dart';
/// The list's horizontal rhythm, matching the web's toolbar and row inset
/// (`var(--space-s)`: 12px). The detail pane keeps its own content padding.
@@ -72,23 +73,10 @@ class PipelineListPanel extends StatelessWidget {
schedule: value ? ScheduleFilter.scheduled : ScheduleFilter.any,
),
);
final control = useCupertinoControls(context)
? CupertinoSlidingSegmentedControl<bool>(
key: const Key('pipeline-scope'),
groupValue: scheduled,
onValueChanged: (value) => pick(value ?? false),
children: const {false: Text('All'), true: Text('Scheduled')},
)
: SegmentedButton<bool>(
key: const Key('pipeline-scope'),
showSelectedIcon: false,
segments: const [
ButtonSegment(value: false, label: Text('All')),
ButtonSegment(value: true, label: Text('Scheduled')),
],
selected: {scheduled},
onSelectionChanged: (value) => pick(value.single),
);
final control = PipelineScopeControl(
scheduled: scheduled,
onSelected: pick,
);
return Padding(
padding: const EdgeInsets.fromLTRB(
kPipelineListInset,
@@ -313,7 +301,12 @@ class PipelineListPanel extends StatelessWidget {
],
)
: controller.runsLoaded
? Text('no runs recorded', style: style)
? Text(
'no runs recorded',
style: style,
maxLines: 2,
overflow: TextOverflow.ellipsis,
)
: const SizedBox.shrink();
return _measured(
Column(
@@ -322,7 +315,14 @@ class PipelineListPanel extends StatelessWidget {
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(child: Text(what, style: style)),
Expanded(
child: Text(
what,
style: style,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
if (shape != null) ...[
const SizedBox(width: 8),
// The miniature keeps to its corner and scales down when narrow.
@@ -0,0 +1,119 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'pipeline_controls.dart';
/// Uses a native picker when the segmented labels cannot fit at the user's
/// text scale. The decision is content-measured, not a fixed pane width.
class PipelineScopeControl extends StatelessWidget {
const PipelineScopeControl({
super.key,
required this.scheduled,
required this.onSelected,
});
final bool scheduled;
final ValueChanged<bool> onSelected;
static const labels = {false: 'All', true: 'Scheduled'};
@override
Widget build(BuildContext context) {
final cupertino = useCupertinoControls(context);
final style = cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.labelLarge;
var requiredWidth = kMinInteractiveDimension * labels.length;
for (final label in labels.values) {
final painter = TextPainter(
text: TextSpan(text: label, style: style),
textDirection: Directionality.of(context),
textScaler: MediaQuery.textScalerOf(context),
)..layout();
requiredWidth += painter.width;
painter.dispose();
}
return LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth >= requiredWidth) {
return cupertino
? CupertinoSlidingSegmentedControl<bool>(
key: const Key('pipeline-scope'),
groupValue: scheduled,
onValueChanged: (value) => onSelected(value ?? false),
children: {
for (final entry in labels.entries)
entry.key: Text(entry.value),
},
)
: SegmentedButton<bool>(
key: const Key('pipeline-scope'),
showSelectedIcon: false,
segments: [
for (final entry in labels.entries)
ButtonSegment(value: entry.key, label: Text(entry.value)),
],
selected: {scheduled},
onSelectionChanged: (value) => onSelected(value.single),
);
}
if (!cupertino) {
return DropdownButton<bool>(
key: const Key('pipeline-scope'),
value: scheduled,
isExpanded: true,
items: [
for (final entry in labels.entries)
DropdownMenuItem(
value: entry.key,
child: Text(
entry.value,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
onChanged: (value) {
if (value != null) onSelected(value);
},
);
}
return CupertinoButton(
key: const Key('pipeline-scope'),
padding: EdgeInsets.zero,
onPressed: () => showCupertinoModalPopup<void>(
context: context,
builder: (sheetContext) => CupertinoActionSheet(
title: const Text('Pipeline scope'),
actions: [
for (final entry in labels.entries)
CupertinoActionSheetAction(
onPressed: () {
Navigator.of(sheetContext).pop();
if (context.mounted) onSelected(entry.key);
},
child: Text(entry.value),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.of(sheetContext).pop(),
child: const Text('Cancel'),
),
),
),
child: Row(
children: [
Expanded(
child: Text(
labels[scheduled]!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const Icon(CupertinoIcons.chevron_down),
],
),
);
},
);
}
}
+10 -5
View File
@@ -141,11 +141,16 @@ class _RunVisitPaneState extends State<RunVisitPane> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.visit.stage,
key: const Key('run-visit-title'),
style: style.stageTitle,
softWrap: true,
Semantics(
container: true,
header: true,
identifier: 'run-stage-heading',
child: Text(
widget.visit.stage,
key: const Key('run-visit-title'),
style: style.stageTitle,
softWrap: true,
),
),
const SizedBox(height: 4),
Wrap(
+40 -18
View File
@@ -249,24 +249,46 @@ class RunListRow extends StatelessWidget {
color: secondary,
fontSize: (base.fontSize ?? 14) - 1,
);
Widget line(String? start, String? end, TextStyle style, {Key? key}) => Row(
key: key,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
start ?? '',
style: style,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
if (end != null) ...[
const SizedBox(width: 12),
Text(end, style: style),
],
],
);
Widget line(String? start, String? end, TextStyle style, {Key? key}) =>
LayoutBuilder(
key: key,
builder: (context, constraints) {
Widget text(String value) => Text(
value,
style: style,
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
if (end == null) return text(start ?? '');
final measure = TextPainter(
text: TextSpan(text: end, style: style),
textDirection: Directionality.of(context),
textScaler: MediaQuery.textScalerOf(context),
)..layout();
final fits = measure.width + 12 < constraints.maxWidth;
measure.dispose();
if (!fits) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
text(start ?? ''),
Align(
alignment: AlignmentDirectional.centerEnd,
child: text(end),
),
],
);
}
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: text(start ?? '')),
const SizedBox(width: 12),
text(end),
],
);
},
);
final scheduled = run['scheduled'] == true;
final body = Row(
crossAxisAlignment: CrossAxisAlignment.start,
+15 -11
View File
@@ -189,17 +189,21 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
: Column(
children: [
Expanded(child: _destinationStack(contents, index)),
CupertinoTabBar(
currentIndex: index,
onTap: (value) =>
_select(AppDestination.values[value]),
items: _items((destination) {
final item = destinationDetails(destination);
return BottomNavigationBarItem(
icon: _icon(destination, item.cupertinoIcon),
label: item.label,
);
}),
// Match CupertinoTabScaffold's native tab-label policy;
// content elsewhere still follows the user's scaler.
MediaQuery.withNoTextScaling(
child: CupertinoTabBar(
currentIndex: index,
onTap: (value) =>
_select(AppDestination.values[value]),
items: _items((destination) {
final item = destinationDetails(destination);
return BottomNavigationBarItem(
icon: _icon(destination, item.cupertinoIcon),
label: item.label,
);
}),
),
),
],
),
+49 -27
View File
@@ -1,3 +1,5 @@
import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -6,13 +8,16 @@ import '../ui/adaptive/host.dart';
/// At least this wide, a destination keeps its list beside the open item
/// (with the destination rail) instead of pushing the item as its own page.
const double kListDetailMinWidth = 600;
const double _bodyWindowTarget = 0.6;
const double _bodyWindowMinimum = 0.5;
const double _bodyAvailableMaximum = 0.75;
/// Whether the window at [context] shows list and detail side by side.
bool showsListBesideDetail(BuildContext context) =>
MediaQuery.sizeOf(context).width >= kListDetailMinWidth;
/// Equal flexible panes, shared by Pipelines, Runs and Chat. No destination
/// supplies a pixel width, minimum/maximum pane width or split ratio.
/// One body-priority policy for all destinations, derived from the full window
/// and actual available space after navigation. No fixed pixel pane widths.
class ListDetailPanes extends StatelessWidget {
const ListDetailPanes({super.key, required this.list, required this.detail});
@@ -27,33 +32,50 @@ class ListDetailPanes extends StatelessWidget {
color: CupertinoColors.separator.resolveFrom(context),
)
: const VerticalDivider(width: 1);
return Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: SizedBox.expand(
key: const ValueKey('list-detail-list'),
child: Semantics(
container: true,
explicitChildNodes: true,
identifier: 'list-detail-list',
child: list,
return LayoutBuilder(
builder: (context, constraints) {
final window = MediaQuery.sizeOf(context).width;
// Target 60% of the full window. Keep at least half for the body while
// leaving a flexible share for native list controls on tighter windows.
final requestedMinimum = window * _bodyWindowMinimum;
final minimum = constraints.maxWidth > requestedMinimum
? requestedMinimum
: constraints.maxWidth * _bodyWindowMinimum;
final maximum = math.max(
minimum,
constraints.maxWidth * _bodyAvailableMaximum,
);
final bodyWidth = (window * _bodyWindowTarget).clamp(minimum, maximum);
return Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: SizedBox.expand(
key: const ValueKey('list-detail-list'),
child: Semantics(
container: true,
explicitChildNodes: true,
identifier: 'list-detail-list',
child: list,
),
),
),
),
),
divider,
Expanded(
child: SizedBox.expand(
key: const ValueKey('list-detail-body'),
child: Semantics(
container: true,
explicitChildNodes: true,
identifier: 'list-detail-body',
child: detail,
divider,
SizedBox(
width: bodyWidth,
child: SizedBox.expand(
key: const ValueKey('list-detail-body'),
child: Semantics(
container: true,
explicitChildNodes: true,
identifier: 'list-detail-body',
child: detail,
),
),
),
),
),
],
],
);
},
);
}
}