Notebook design: numbered In/Out cells, tool sub-cells and an input-cell composer

Adds the Notebook design (TranscriptStyle.cells, ComposerStyle.cell), a
white/charcoal IDE theme with light grey cells, hairlines and 5px corners.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 23:24:03 +00:00
parent 9436067bf2
commit 113063b040
21 changed files with 2202 additions and 33 deletions
@@ -0,0 +1,283 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/domain/chat_cell_numbers.dart';
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/notebook/notebook_input_cell.dart';
import 'package:pipelines_app/features/chat/ui/transcript/notebook/notebook_tool_cell.dart';
import 'package:pipelines_app/features/chat/ui/transcript/notebook/notebook_tool_cells.dart';
import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_quote.dart';
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_activity_rows.dart';
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_prompt_line.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
JsonMap _row(JsonMap message) => transcriptRows([message]).single;
final JsonMap _operator = _row({
'id': 'u1',
'role': 'user',
'parts': [
{'type': 'text', 'text': 'Fix the Windows paths.'},
],
});
JsonMap _tool(String id, String name, String status, {String output = ''}) => {
'type': 'tool',
'id': id,
'name': name,
'time': {'created': 1000, 'completed': 2200},
'state': {
'status': status,
'input': {'command': 'go test ./...'},
if (output.isNotEmpty)
'content': [
{'type': 'text', 'text': output},
],
if (status == 'error') 'error': {'message': 'exit status 1'},
},
};
const String _longOutput = 'ok pkg/a\nok pkg/b\nok pkg/c\nok pkg/d\nPASS';
JsonMap _agent({bool streaming = false}) => {
..._row({
'id': 'a1',
'role': 'assistant',
'parts': [
_tool('t1', 'Bash', 'completed', output: _longOutput),
_tool('t2', 'Read', 'error'),
{'type': 'text', 'text': 'Fixed the separators.'},
],
}),
if (streaming) 'streaming': true,
};
final JsonMap _followup = _row({
'id': 'f1',
'role': 'user',
'origin': 'followup',
'client': 'Agent follow-up',
'parts': [
{'type': 'text', 'text': 'Check whether run 42 finished.'},
],
});
Widget _host(
AppDesign design,
List<(JsonMap, int?)> rows, {
double width = 900,
}) => MaterialApp(
theme: design.light(),
home: Scaffold(
body: Center(
child: SizedBox(
width: width,
child: ListView(
children: [
for (final (row, cell) in rows)
ChatMessageView(
row: row,
cell: cell,
textBuilder: chatMarkdownText,
),
],
),
),
),
),
);
Finder _label(String text) => find.byWidgetPredicate(
(widget) =>
widget is Text &&
widget.key == const Key('chat-notebook-gutter-label') &&
widget.data == text,
);
void main() {
test('cells number each operator turn and pair its answers', () {
final rows = <JsonMap>[
{'kind': 'assistant', 'key': 'early'},
{'kind': 'user', 'key': 'u1'},
{'kind': 'assistant', 'key': 'a1'},
{'kind': 'system_notice', 'key': 'n1'},
{'kind': 'assistant', 'key': 'a1b'},
{'kind': 'user', 'key': 'f1'},
{'kind': 'assistant', 'key': 'chat-pending-response'},
];
expect(chatCellNumbers(rows), {
'u1': 1,
'a1': 1,
'a1b': 1,
'f1': 2,
'chat-pending-response': 2,
});
// Derived from the turn order alone: the same history numbers the same.
expect(chatCellNumbers(rows), chatCellNumbers([...rows]));
});
testWidgets('Notebook: In and Out cells with right-aligned gutter labels', (
tester,
) async {
await tester.pumpWidget(
_host(AppDesign.notebook, [(_operator, 3), (_agent(), 3)]),
);
expect(find.byType(NotebookInputCell), findsOneWidget);
expect(find.byType(TerminalPromptLine), findsNothing);
expect(find.byType(PaperQuote), findsNothing);
final inLabel = _label('In [3]:');
final outLabel = _label('Out [3]:');
expect(inLabel, findsOneWidget);
expect(outLabel, findsOneWidget);
// One gutter: both labels end in the same column, left of the cells.
expect(
tester.getTopRight(inLabel).dx,
closeTo(tester.getTopRight(outLabel).dx, 0.5),
);
final cell = find.byType(NotebookInputCell);
expect(
tester.getTopRight(inLabel).dx,
lessThan(tester.getTopLeft(cell).dx),
);
// The prompt's and the answer's text share one column.
expect(
tester.getTopLeft(find.text('Fix the Windows paths.')).dx,
closeTo(tester.getTopLeft(find.text('Fixed the separators.')).dx, 0.5),
);
// The label sits on the prompt's first line.
final labelBox = tester.getRect(inLabel);
final textBox = tester.getRect(find.text('Fix the Windows paths.'));
expect(labelBox.bottom, closeTo(textBox.bottom, 3));
});
testWidgets('Notebook: a prompt not yet run reads In [ ]:', (tester) async {
await tester.pumpWidget(_host(AppDesign.notebook, [(_operator, null)]));
expect(_label('In [ ]:'), findsOneWidget);
});
testWidgets('Notebook: tool calls are collapsed sub-cells that expand in '
'place', (tester) async {
await tester.pumpWidget(_host(AppDesign.notebook, [(_agent(), 1)]));
expect(find.byType(NotebookToolCells), findsOneWidget);
expect(find.byType(TerminalActivityRows), findsNothing);
final cells = find.byType(NotebookToolCell);
expect(cells, findsNWidgets(2));
// Collapsed: the first lines of the output, "+N lines", the duration and
// the status on the right.
expect(find.byKey(const Key('chat-notebook-tool-preview')), findsWidgets);
expect(find.text('+2 lines'), findsOneWidget);
expect(find.text('1.2s'), findsNWidgets(2));
expect(find.byKey(const Key('chat-notebook-tool-output')), findsNothing);
expect(find.textContaining('PASS'), findsNothing);
await tester.tap(find.byKey(const Key('chat-notebook-tool-header')).first);
await tester.pump();
expect(find.byKey(const Key('chat-notebook-tool-output')), findsOneWidget);
expect(find.textContaining('PASS'), findsOneWidget);
expect(find.text('+2 lines'), findsNothing);
await tester.tap(find.byKey(const Key('chat-notebook-tool-header')).first);
await tester.pump();
expect(find.byKey(const Key('chat-notebook-tool-output')), findsNothing);
// The status line still opens the activity details.
await tester.tap(find.byKey(const Key('chat-turn-activity')));
await tester.pumpAndSettle();
expect(find.text('Activity details'), findsOneWidget);
});
testWidgets('Notebook: a long turn folds its earlier calls', (tester) async {
final row = _row({
'id': 'a9',
'role': 'assistant',
'parts': [
for (var i = 0; i < notebookToolMaxCalls + 3; i++)
_tool('t$i', 'Read', 'completed', output: 'line $i'),
],
});
await tester.pumpWidget(_host(AppDesign.notebook, [(row, 1)]));
expect(find.byType(NotebookToolCell), findsNWidgets(notebookToolMaxCalls));
await tester.tap(find.byKey(const Key('chat-notebook-tool-earlier')));
await tester.pump();
expect(
find.byType(NotebookToolCell),
findsNWidgets(notebookToolMaxCalls + 3),
);
});
testWidgets('Notebook: a running turn shows Jupyter\'s [*] busy marker', (
tester,
) async {
await tester.pumpWidget(
_host(AppDesign.notebook, [(_agent(streaming: true), 2)]),
);
expect(_label('Out [2]:'), findsOneWidget);
final busy = find.byKey(const Key('chat-notebook-busy'));
expect(busy, findsOneWidget);
expect(tester.widget<Text>(busy).data, '[*]');
expect(
tester.getTopLeft(busy).dy,
greaterThan(tester.getTopLeft(_label('Out [2]:')).dy),
);
await tester.pumpWidget(_host(AppDesign.notebook, [(_agent(), 2)]));
expect(find.byKey(const Key('chat-notebook-busy')), findsNothing);
});
testWidgets('Notebook: a follow-up is an In cell with a scheduled tag', (
tester,
) async {
await tester.pumpWidget(_host(AppDesign.notebook, [(_followup, 4)]));
expect(_label('In [4]:'), findsOneWidget);
expect(find.byType(NotebookScheduledCell), findsOneWidget);
final tag = find.byKey(const Key('chat-notebook-scheduled-tag'));
expect(
find.descendant(of: tag, matching: find.text('scheduled')),
findsOneWidget,
);
expect(find.text('Follow-up from agent'), findsOneWidget);
expect(find.text('Check whether run 42 finished.'), findsOneWidget);
});
testWidgets('Notebook: at phone width the gutter collapses to an inline '
'label above the cell', (tester) async {
await tester.pumpWidget(
_host(AppDesign.notebook, [(_operator, 1), (_agent(), 1)], width: 380),
);
final label = _label('In [1]:');
final cell = find.byType(NotebookInputCell);
expect(
tester.getBottomLeft(label).dy,
lessThanOrEqualTo(tester.getTopLeft(cell).dy),
);
expect(tester.getTopLeft(label).dx, closeTo(tester.getTopLeft(cell).dx, 4));
});
for (final design in [
AppDesign.standard,
AppDesign.terminal,
AppDesign.paper,
]) {
testWidgets('${design.label} is unchanged: no cells, even with a number', (
tester,
) async {
await tester.pumpWidget(
_host(design, [
(_operator, 1),
(_agent(streaming: true), 1),
(_followup, 2),
]),
);
expect(find.byKey(const Key('chat-notebook-gutter-label')), findsNothing);
expect(find.byType(NotebookInputCell), findsNothing);
expect(find.byType(NotebookToolCells), findsNothing);
expect(find.byType(NotebookScheduledCell), findsNothing);
expect(find.byKey(const Key('chat-notebook-busy')), findsNothing);
if (design == AppDesign.standard) {
expect(find.byType(ChatUserBubble), findsOneWidget);
}
});
}
}
+128
View File
@@ -0,0 +1,128 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/notebook/notebook_cell_frame.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
import '../../features/chat/conversation/chat_composer_bar_fixtures.dart';
ThemeData _theme(Brightness brightness, {String? font}) =>
brightness == Brightness.dark
? AppDesign.notebook.dark(fontFamily: font)
: AppDesign.notebook.light(fontFamily: font);
Widget _thread(ComposerBarGateway gateway, AppDesign design) => MaterialApp(
theme: design.light(),
home: Scaffold(
body: ChatThreadView(
gateway: gateway,
sessionId: 's',
session: const {'id': 's', 'directory': '/Users/ada/repos/tank'},
syncToken: 0,
onBack: () {},
drafts: MemoryChatDraftStore(),
),
),
);
void main() {
test('Notebook is listed with a stable id, a label and one line', () {
expect(AppDesign.fromId('notebook'), AppDesign.notebook);
expect(AppDesign.notebook.label, 'Notebook');
expect(AppDesign.notebook.description, isNot(contains('\n')));
expect(AppDesign.notebook.usesInterfaceFont, isTrue);
});
test('Notebook tokens: cells transcript, cell composer, washed row, '
'4-6px corners, hairlines, flat', () {
for (final brightness in Brightness.values) {
final theme = _theme(brightness);
final tokens = theme.extension<AppDesignTokens>()!;
expect(tokens.design, AppDesign.notebook);
expect(tokens.transcript, TranscriptStyle.cells);
expect(tokens.terminal, isFalse);
expect(tokens.composer, ComposerStyle.cell);
expect(tokens.selectedRow, SelectedRowStyle.washed);
expect(tokens.radius, inInclusiveRange(4, 6));
expect(tokens.flat, isTrue);
expect(tokens.frame, theme.colorScheme.outlineVariant);
expect(tokens.ansi, isNotNull);
// Reading text keeps the interface sans.
expect(tokens.reading.family, isNull);
}
});
test('Notebook pages: white by day, neutral charcoal by night, cells a '
'step off the page', () {
final light = _theme(Brightness.light);
expect(light.scaffoldBackgroundColor, const Color(0xFFFFFFFF));
final dark = _theme(Brightness.dark);
expect(
dark.scaffoldBackgroundColor.computeLuminance(),
inExclusiveRange(0.005, 0.03),
);
for (final theme in [light, dark]) {
final scheme = theme.colorScheme;
expect(scheme.surfaceContainerLow, isNot(scheme.surface));
expect(scheme.onSurface, isNot(scheme.onSurfaceVariant));
}
});
test('Notebook keeps the interface font and caches its themes', () {
expect(
_theme(Brightness.light, font: 'Inter').textTheme.bodyLarge?.fontFamily,
'Inter',
);
expect(identical(_theme(Brightness.dark), _theme(Brightness.dark)), isTrue);
expect(
AppDesign.notebook.build(Brightness.light),
_theme(Brightness.light),
);
});
testWidgets('Notebook: the composer is an In [ ]: input cell whose frame '
'takes the accent on focus', (tester) async {
final gateway = ComposerBarGateway();
addTearDown(gateway.close);
await tester.pumpWidget(_thread(gateway, AppDesign.notebook));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-composer-pill')), findsNothing);
expect(find.byKey(const Key('chat-composer-underline')), findsNothing);
final cell = find.byKey(const Key('chat-composer-cell'));
expect(cell, findsOneWidget);
expect(
find.descendant(of: cell, matching: find.text('In [ ]:')),
findsOneWidget,
);
for (final key in [
'chat-composer-attach',
'chat-composer-field',
'chat-composer-primary',
]) {
expect(
find.descendant(of: cell, matching: find.byKey(Key(key))),
findsOneWidget,
);
}
final scheme = Theme.of(tester.element(cell)).colorScheme;
Color frame() {
final paint = tester.widget<CustomPaint>(
find
.descendant(
of: find.byKey(const Key('chat-composer-cell-frame')),
matching: find.byType(CustomPaint),
)
.first,
);
return (paint.painter! as NotebookCellPainter).border;
}
expect(frame(), scheme.outlineVariant);
await tester.tap(find.byKey(const Key('chat-composer-field')));
await tester.pumpAndSettle();
expect(frame(), scheme.primary);
});
}