Merge: search finds chats and opens them

This commit is contained in:
2026-11-03 13:02:16 +00:00
31 changed files with 1659 additions and 118 deletions
+4
View File
@@ -387,6 +387,10 @@ class _PipelinesAppState extends State<PipelinesApp>
);
route = AppRoute.run(runId);
}
case SearchChatTarget(:final sessionId):
// The Chat tab selects the routed session in its list and shows its
// thread, exactly as a chat notification opens it.
route = AppRoute.chatSession(sessionId);
}
if (route == null) return;
setState(() => _pendingRunSearch = selection);
@@ -0,0 +1,47 @@
import '../../../core/api_gateway.dart';
import 'search_row.dart';
/// The chat payload of a `chat` search hit, or null for any other hit.
JsonMap? searchChatOf(JsonMap hit) {
final chat = hit['chat'];
return hit['kind'] == 'chat' && chat is Map
? Map<String, dynamic>.from(chat)
: null;
}
/// A chat hit's row: the chat's title, its harness and directory as the
/// muted facts, and the matching message's snippet when message text matched.
/// It opens only with the server's own `chat:<session id>` target.
SearchRowView searchChatRowView(
JsonMap chat, {
required String query,
required String? target,
required String? recency,
}) {
final title = '${chat['title'] ?? ''}'.trim();
final directory = '${chat['directory'] ?? ''}'.trim();
final snippet = '${chat['snippet'] ?? ''}';
final facts = [
searchHarnessLabel('${chat['backend'] ?? ''}'),
if (directory.isNotEmpty) directory,
if (chat['closed'] == true) 'closed',
].join(' · ');
return SearchRowView(
title: title.isEmpty ? 'Untitled chat' : title,
secondary: facts,
kindLabel: 'Chat',
snippet: snippet.isEmpty ? null : snippet,
snippetSpans: snippetSpans(snippet, query),
recency: recency,
target: target,
);
}
/// The harness's display name, matching the server's own names; an unknown
/// harness shows as sent.
String searchHarnessLabel(String backend) => switch (backend) {
'claude' => 'Claude Code',
'codex' => 'Codex',
'' || 'opencode' => 'OpenCode',
_ => backend,
};
@@ -0,0 +1,83 @@
import '../../../core/api_gateway.dart';
import '../data/search_repository.dart';
import 'search_models.dart';
import 'search_query.dart';
/// Wording for a server whose search does not know the `chat` kind (it
/// predates chat search and rejects the kind by name).
const unsupportedChatSearchCopy =
'This server does not search chats. Update the Pipelines server to '
'include them.';
final _unknownKind = RegExp(r'unknown search kind', caseSensitive: false);
/// The Chats section's state: one `kind: chat` request per sent query, run
/// beside (never instead of, nor ahead of) the run/artifact search, so the
/// server's transcript readback cannot delay the other results.
class SearchChatSlice {
List<JsonMap> results = const [];
bool loading = false;
bool loaded = false;
bool truncated = false;
String? error;
void clear() {
results = const [];
loading = false;
loaded = false;
truncated = false;
error = null;
}
/// Requests chats for [query]. [current] reports whether this request is
/// still the newest edit; a stale reply is dropped without a change.
Future<void> load(
SearchRepository repository,
String query, {
required bool Function() current,
required void Function() changed,
}) async {
loading = true;
error = null;
changed();
try {
final response = await repository.search(
query: query,
kind: SearchKind.chat,
);
if (!current()) return;
if (response == null) {
results = const [];
truncated = false;
error = unsupportedChatSearchCopy;
} else {
results = response.results
.where((hit) => hit['kind'] == SearchKind.chat.wire)
.toList(growable: false);
truncated = response.truncated;
}
} catch (failure) {
if (!current()) return;
results = const [];
truncated = false;
final text = searchFailureText(failure);
error = _unknownKind.hasMatch(text) || text == unsupportedSearchCopy
? unsupportedChatSearchCopy
: text;
}
loading = false;
loaded = true;
changed();
}
/// A short honest note under the Chats section: why chats are missing, or
/// that the server's bounds left some transcripts unsearched.
String? get note {
if (error != null) return error;
if (truncated) {
return "Some chats were not searched within the server's time or "
'result limit.';
}
return null;
}
}
@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
import '../../../core/api_gateway.dart';
import '../data/search_repository.dart';
import 'search_chat_slice.dart';
import 'search_models.dart';
import 'search_query.dart';
import 'search_row.dart';
@@ -24,6 +25,7 @@ class OmniSearchController extends ChangeNotifier {
final SearchRepository repository;
final Duration debounce;
final SearchSequencer _sequencer = SearchSequencer();
final SearchChatSlice _chats = SearchChatSlice();
Timer? _timer;
bool _disposed = false;
@@ -51,7 +53,35 @@ class OmniSearchController extends ChangeNotifier {
int get scannedBytes => _scannedBytes;
int get cap => _cap;
int get scanBoundBytes => _scanBoundBytes;
String? get error => _error;
/// The failure the body shows: the run search's, or with the Chats kind
/// selected (no run search is sent) the chat search's.
String? get error =>
_error ?? (parsed.kind == SearchKind.chat ? _chats.error : null);
/// Chat hits for the Chats section: shown for every kind that searches
/// chats (all kinds, or Chats alone).
List<JsonMap> get shownChats =>
_searchesChats(parsed.kind) ? _chats.results : const [];
/// The Chats section's note: why chats are missing, or that the server's
/// bounds left some unsearched. With Chats selected alone a failure is the
/// body's error instead, so only the bounds note remains.
String? get chatsNote => switch (parsed.kind) {
SearchKind.all => _chats.note,
SearchKind.chat when _chats.error == null => _chats.note,
_ => null,
};
/// Whether the Chats section is drawn as its own group above the others.
bool get showsChatSection =>
parsed.kind == SearchKind.all &&
(shownChats.isNotEmpty || chatsNote != null);
static bool _searchesChats(SearchKind kind) =>
kind == SearchKind.all || kind == SearchKind.chat;
bool get _hasShown => shownResults.isNotEmpty || shownChats.isNotEmpty;
/// The results already in hand, re-narrowed to the effective kind so the list
/// always matches the control while a narrowed request loads.
@@ -64,18 +94,22 @@ class OmniSearchController extends ChangeNotifier {
}
SearchBodyKind get bodyKind {
if (_error != null) return SearchBodyKind.error;
if (shownResults.isNotEmpty) return SearchBodyKind.results;
if (_loading && _results.isEmpty) return SearchBodyKind.searching;
if (error != null) return SearchBodyKind.error;
if (_hasShown || showsChatSection) return SearchBodyKind.results;
if ((_loading && _results.isEmpty) || _chats.loading) {
return SearchBodyKind.searching;
}
if (emptyMessage != null) return SearchBodyKind.empty;
return SearchBodyKind.idle;
}
/// A thin progress report above retained results while a newer query loads.
bool get showProgress => _loading && _results.isNotEmpty;
bool get showProgress =>
(_loading && _results.isNotEmpty) ||
(_chats.loading && _chats.results.isNotEmpty);
String? get emptyMessage {
if (_error != null || _loading || shownResults.isNotEmpty) return null;
if (error != null || _loading || _chats.loading || _hasShown) return null;
final effective = parsed;
if (effective.query.trim().isEmpty) {
if (!_loaded || effective.kind == SearchKind.all) return null;
@@ -171,14 +205,39 @@ class OmniSearchController extends ChangeNotifier {
Future<void> _send(SearchEdit sent) async {
final effective = parseSearchQuery(sent.query, _selectedKind);
final query = effective.query.trim();
final chatsOnly = effective.kind == SearchKind.chat;
// The run/artifact search goes first; the chat search follows as its own
// request, so a slow transcript readback never holds the other results.
final runs = chatsOnly
? null
: repository.search(query: query, kind: effective.kind);
if (_searchesChats(effective.kind) && (query.isNotEmpty || chatsOnly)) {
unawaited(
_chats.load(
repository,
query,
current: () => _sequencer.accepts(sent.token) && !_disposed,
changed: _notify,
),
);
} else {
_chats.clear();
}
if (runs == null) {
_results = const [];
_truncated = false;
_loading = false;
_loaded = true;
_error = null;
_notify();
return;
}
_loading = true;
_error = null;
_notify();
try {
final response = await repository.search(
query: effective.query.trim(),
kind: effective.kind,
);
final response = await runs;
if (!_sequencer.accepts(sent.token) || _disposed) return;
if (response == null) {
_loading = false;
@@ -207,6 +266,7 @@ class OmniSearchController extends ChangeNotifier {
}
void _clearResults() {
_chats.clear();
_results = const [];
_truncated = false;
_scannedSteps = 0;
@@ -9,6 +9,7 @@ enum SearchKind {
step('step', 'Steps'),
field('field', 'Fields'),
artifact('artifact', 'Artifacts'),
chat('chat', 'Chats'),
version('version', 'Versions');
const SearchKind(this.wire, this.label);
@@ -1,5 +1,6 @@
import '../../../core/api_gateway.dart';
import '../../../ui/text/relative_time.dart';
import 'search_chat_row.dart';
import 'search_format.dart';
export 'search_format.dart' show humanBytes, formatSearchTimestamp;
@@ -129,6 +130,15 @@ SearchRowView searchRowView(JsonMap hit, String query) {
target: target,
);
}
final chat = searchChatOf(hit);
if (chat != null) {
return searchChatRowView(
chat,
query: query,
target: target,
recency: recency,
);
}
final kind = _nonBlank(hit['kind']);
return SearchRowView(
title: _nonBlank(hit['target']) ?? 'Unrecognised result',
@@ -191,6 +201,7 @@ String? _serverTarget(JsonMap hit) {
'step',
'field',
'artifact',
'chat',
].any((key) => _map(hit[key]) != null);
return known ? target : null;
}
@@ -1,15 +1,16 @@
import '../../../core/api_gateway.dart';
/// The kind of recorded entity a resolved target names.
enum SearchTargetKind { pipeline, version, run, step, field, artifact }
enum SearchTargetKind { pipeline, version, run, step, field, artifact, chat }
/// The exact identity behind a recorded search hit.
///
/// [wire] is the server's own stable target token
/// (`internal/protocol/search.go`): `pipeline:<id>`, `pipeline:<id>:v<version>`,
/// `run:<id>`, `run:<id>:<sequence>`, `run:<id>:<sequence>:<field>` or the
/// recorded artifact URL. It is derived from the typed payload, never copied
/// from the hit, and [SearchTarget.fromWire] accepts it back.
/// `run:<id>`, `run:<id>:<sequence>`, `run:<id>:<sequence>:<field>`, the
/// recorded artifact URL or `chat:<session id>`. It is derived from the typed
/// payload, never copied from the hit, and [SearchTarget.fromWire] accepts it
/// back.
///
/// The token is the identity: two targets that serialise to the same token are
/// the same target even when one of them also carries recorded visit facts the
@@ -63,6 +64,10 @@ sealed class SearchTarget {
// The server's artifact target is its own relative file URL
// (`/artifacts/<run>/<step>/<name>`); an absolute form is accepted only when
// it carries that same path.
if (token.startsWith('chat:')) {
final session = token.substring('chat:'.length);
return session.trim().isEmpty ? null : SearchChatTarget(session);
}
if (token.startsWith('/artifacts/')) return SearchArtifactTarget(token);
if (token.startsWith('http://') || token.startsWith('https://')) {
final uri = Uri.tryParse(token);
@@ -172,6 +177,21 @@ final class SearchArtifactTarget extends SearchTarget {
String get wire => url;
}
/// An operator chat session hit. [messageId] is the matching message when the
/// hit matched message text; the token names only the session.
final class SearchChatTarget extends SearchTarget {
const SearchChatTarget(this.sessionId, {this.messageId});
final String sessionId;
final String? messageId;
@override
SearchTargetKind get kind => SearchTargetKind.chat;
@override
String get wire => 'chat:$sessionId';
}
/// Either the exact [SearchTarget] a hit names, or the reason it names none.
sealed class SearchTargetResolution {
const SearchTargetResolution();
@@ -272,6 +292,17 @@ SearchTargetResolution _identityFor(JsonMap hit) {
return ResolvedSearchTarget(SearchFieldTarget(runId, sequence, name));
}
final chat = _payload(hit, 'chat');
if (chat != null) {
final session = _text(chat['session_id']);
if (session == null) {
return const UnresolvedSearchTarget('chat session id is missing');
}
return ResolvedSearchTarget(
SearchChatTarget(session, messageId: _text(chat['message_id'])),
);
}
final artifact = _payload(hit, 'artifact');
if (artifact != null) {
final url = _text(artifact['url']);
@@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart';
import '../../../core/api_gateway.dart';
import '../domain/search_controller.dart';
import 'search_result_row.dart';
import 'search_result_slivers.dart';
import 'search_layout.dart';
/// The Cupertino search view: an optional status header and the shared list
@@ -59,18 +59,13 @@ class CupertinoSearchBody extends StatelessWidget {
),
];
case SearchBodyKind.results:
return [
SliverList.builder(
itemCount: controller.shownResults.length,
itemBuilder: (context, index) => SearchResultRow(
hit: controller.shownResults[index],
query: query,
onOpen: onOpen,
cupertino: true,
divider: index < controller.shownResults.length - 1,
),
),
];
return searchResultSlivers(
controller: controller,
query: query,
onOpen: onOpen,
cupertino: true,
message: (text) => _CupertinoMessage(message: text),
);
case SearchBodyKind.empty:
return [
SliverToBoxAdapter(
@@ -82,7 +77,7 @@ class CupertinoSearchBody extends StatelessWidget {
SliverFillRemaining(
hasScrollBody: false,
child: _CupertinoMessage(
message: 'Search pipelines, runs and artifacts.',
message: 'Search pipelines, runs, artifacts and chats.',
),
),
];
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../domain/search_controller.dart';
import 'search_result_row.dart';
import 'search_result_slivers.dart';
import 'search_layout.dart';
/// The Material search view: an optional status header and a flat native
@@ -50,18 +50,13 @@ class MaterialSearchBody extends StatelessWidget {
SliverFillRemaining(hasScrollBody: false, child: _Searching()),
];
case SearchBodyKind.results:
return [
SliverList.builder(
itemCount: controller.shownResults.length,
itemBuilder: (context, index) => SearchResultRow(
hit: controller.shownResults[index],
query: query,
onOpen: onOpen,
cupertino: false,
divider: index < controller.shownResults.length - 1,
),
),
];
return searchResultSlivers(
controller: controller,
query: query,
onOpen: onOpen,
cupertino: false,
message: (text) => _SearchMessage(message: text),
);
case SearchBodyKind.empty:
return [
SliverToBoxAdapter(
@@ -73,7 +68,7 @@ class MaterialSearchBody extends StatelessWidget {
SliverFillRemaining(
hasScrollBody: false,
child: _SearchMessage(
message: 'Search pipelines, runs and artifacts.',
message: 'Search pipelines, runs, artifacts and chats.',
),
),
];
@@ -12,7 +12,7 @@ const searchBarControlsKey = ValueKey<String>('search.bar');
const searchTokenHint =
'Filter with t:pipeline or type:artifact (pipeline, run, step, field, '
'artifact, version). Last type wins; choosing Kind replaces it. Quote '
'artifact, chat, version). Last type wins; choosing Kind replaces it. Quote '
'tokens to search literally.';
/// Search's controls as the top bar's main pill (in place of a title): the
@@ -57,7 +57,7 @@ class SearchBarControls extends StatelessWidget {
autofocus: autofocus,
inBar: true,
cupertino: cupertino,
placeholder: 'Search pipelines, runs and artifacts',
placeholder: 'Search pipelines, runs, artifacts and chats',
onChanged: onChanged,
onSubmitted: (_) => onSubmitted(),
onCleared: onCleared,
@@ -11,7 +11,9 @@ import 'search_result_view.dart';
/// artifact's picture), the title with its recency, and one muted line that
/// names the kind and then shows the snippet (its first query occurrence
/// emphasised by weight, never by parsing server text as markup) or, without
/// one, the kind's own facts. An artifact hit's open choices are its menu.
/// one, the kind's own facts. A chat hit with a matching message shows its
/// harness and directory, then the snippet on a second line. An artifact
/// hit's open choices are its menu.
class SearchResultRow extends StatelessWidget {
const SearchResultRow({
super.key,
@@ -46,33 +48,55 @@ class SearchResultRow extends StatelessWidget {
),
title: Text(row.title),
time: row.recency,
subtitle: Text.rich(_line(row)),
subtitle: kind == 'chat' && row.snippet != null
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text.rich(_facts(row)),
Text.rich(TextSpan(children: _snippet(row))),
],
)
: Text.rich(_line(row)),
compactSubtitle: kind == 'chat' && row.snippet != null
? Text.rich(TextSpan(children: _snippet(row)))
: null,
menu: searchArtifactActions(context, hit),
);
}
TextSpan _line(SearchRowView row) {
final snippet = row.snippet;
return TextSpan(
children: [
TextSpan(
text: row.kindLabel,
style: const TextStyle(fontWeight: FontWeight.w600),
),
const TextSpan(text: ' · '),
if (snippet == null)
TextSpan(text: row.secondary)
else
for (final span in row.snippetSpans)
TextSpan(
text: span.text,
style: span.matched
? const TextStyle(fontWeight: FontWeight.bold)
: null,
),
],
);
}
TextSpan _line(SearchRowView row) => row.snippet == null
? _facts(row)
: TextSpan(children: [_kind(row), ..._snippet(row)]);
/// The kind, then the kind's own facts (a chat's harness and directory).
TextSpan _facts(SearchRowView row) => TextSpan(
children: [
_kind(row),
TextSpan(text: row.secondary),
],
);
TextSpan _kind(SearchRowView row) => TextSpan(
children: [
TextSpan(
text: row.kindLabel,
style: const TextStyle(fontWeight: FontWeight.w600),
),
const TextSpan(text: ' · '),
],
);
/// The snippet with its first query occurrence emphasised by weight.
List<TextSpan> _snippet(SearchRowView row) => [
for (final span in row.snippetSpans)
TextSpan(
text: span.text,
style: span.matched
? const TextStyle(fontWeight: FontWeight.bold)
: null,
),
];
}
IconData searchMaterialIcon(String kind) => switch (kind) {
@@ -82,6 +106,7 @@ IconData searchMaterialIcon(String kind) => switch (kind) {
'step' => Icons.arrow_forward,
'field' => Icons.notes,
'artifact' => Icons.attach_file,
'chat' => Icons.chat_bubble_outline,
_ => Icons.help_outline,
};
@@ -92,5 +117,6 @@ IconData searchCupertinoIcon(String kind) => switch (kind) {
'step' => CupertinoIcons.arrow_right,
'field' => CupertinoIcons.doc_text,
'artifact' => CupertinoIcons.paperclip,
'chat' => CupertinoIcons.chat_bubble,
_ => CupertinoIcons.question_circle,
};
@@ -0,0 +1,71 @@
import 'package:flutter/widgets.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/layout/section_heading.dart';
import '../domain/search_controller.dart';
import '../domain/search_models.dart';
import 'search_bounds_note.dart';
import 'search_result_row.dart';
const searchChatsSectionKey = ValueKey<String>('search.section.chats');
const searchOthersSectionKey = ValueKey<String>('search.section.others');
const searchChatsNoteKey = ValueKey<String>('search.chats.note');
/// The results body shared by both hosts. With every kind searched, chat hits
/// lead as their own "Chats" group above the pipeline/run/artifact hits; with
/// Chats selected alone they are the list. A run search with no hits still
/// says so under the Chats group.
List<Widget> searchResultSlivers({
required OmniSearchController controller,
required String query,
required ValueChanged<JsonMap> onOpen,
required bool cupertino,
required Widget Function(String message) message,
}) {
final chats = controller.shownChats;
final others = controller.shownResults;
final grouped = controller.showsChatSection;
final note = controller.chatsNote;
Widget rows(List<JsonMap> hits) => SliverList.builder(
itemCount: hits.length,
itemBuilder: (context, index) => SearchResultRow(
hit: hits[index],
query: query,
onOpen: onOpen,
cupertino: cupertino,
divider: index < hits.length - 1,
),
);
final empty = controller.emptyMessage;
return [
if (grouped)
SliverToBoxAdapter(
child: SectionHeading(
key: searchChatsSectionKey,
title: chats.isEmpty ? 'Chats' : 'Chats (${chats.length})',
header: true,
),
),
if (chats.isNotEmpty) rows(chats),
if (note != null)
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: SearchBoundsNote(key: searchChatsNoteKey, text: note),
),
),
if (grouped && others.isNotEmpty)
const SliverToBoxAdapter(
child: SectionHeading(
key: searchOthersSectionKey,
title: 'Pipelines and runs',
header: true,
),
),
if (others.isNotEmpty) rows(others),
if (others.isEmpty &&
controller.parsed.kind != SearchKind.chat &&
empty != null)
SliverToBoxAdapter(child: message(empty)),
];
}
@@ -0,0 +1,131 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/search/search_screen.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import 'search_wiring_test.dart'
show pumpApp, reply, replyRunList, tapTab, waitForSearch;
const _session = 'ses_chatsearch1';
Map<String, dynamic> _results(String kind, List<Map<String, dynamic>> hits) => {
'type': 'search_results',
'search_results': {
'query': 'flaky',
'kind': kind,
'results': hits,
'truncated': false,
'scanned_steps': 0,
'scanned_bytes': 0,
'cap': 50,
'scan_bound_bytes': 1 << 20,
},
};
/// The whole path from the Search tab: a typed query, the run search and the
/// chat search the app sends after it, then a tap on the chat hit opens that
/// chat in the Chat tab with its session selected.
void main() {
for (final cupertino in [false, true]) {
testWidgets('${cupertino ? 'Cupertino' : 'Material'}: a chat hit opens '
'its chat in the Chat tab', (tester) async {
tester.view.physicalSize = const Size(900, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final channel = FakeChannel()..readyCompleter.complete();
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
);
addTearDown(provider.dispose);
await pumpApp(
tester,
channel: channel,
client: PipelinesClient(channelFactory: (_) => channel),
provider: provider,
cupertino: cupertino,
);
await replyRunList(tester, channel);
await tapTab(tester, 'Search');
await tester.pump();
await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100));
await tester.enterText(
find.byKey(const ValueKey('search.field')),
'flaky',
);
await tester.pump(const Duration(milliseconds: 300));
final runs = await waitForSearch(tester, channel);
channel.incoming.add(jsonEncode({'id': runs['id'], ..._results('', [])}));
await tester.pump();
await tester.pump();
final chats = await waitForSearch(tester, channel, chats: true);
expect(chats['search'], {'query': 'flaky', 'kind': 'chat', 'limit': 0});
channel.incoming.add(
jsonEncode({
'id': chats['id'],
..._results('chat', [
{
'kind': 'chat',
'target': 'chat:$_session',
'score': 1,
'matched_field': 'message',
'chat': {
'session_id': _session,
'title': 'Fix CI',
'directory': '/work/api',
'backend': 'claude',
'message_id': 'm2',
'snippet': 'the flaky retry loop',
},
},
]),
}),
);
await tester.pump();
await tester.pump();
expect(find.text('Chats (1)'), findsOneWidget);
expect(find.textContaining('the flaky retry loop'), findsOneWidget);
await tester.tap(
find.byKey(const ValueKey('search.result.chat:$_session')),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pump(const Duration(milliseconds: 400));
expect(provider.value.uri.path, '/chat/$_session');
expect(find.byType(SearchScreen), findsNothing);
final screen = tester.widget<ChatScreen>(find.byType(ChatScreen));
expect(screen.initialSessionId, _session);
await reply(
tester,
channel,
'chat_sessions',
body: {
'type': 'chat_sessions',
'chat_sessions': [
{
'id': _session,
'title': 'Fix CI',
'directory': '/work/api',
'backend': 'claude',
},
],
},
);
await tester.pump(const Duration(milliseconds: 400));
expect(find.text('Fix CI'), findsWidgets);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}
}
+67 -10
View File
@@ -50,6 +50,63 @@ Future<Map<String, dynamic>> waitForRequest(
fail('Timed out waiting for $type #$index');
}
/// The search requests the app sent: the run/artifact searches, or with
/// [chats] the `kind: chat` searches it sends after each of them.
List<Map<String, dynamic>> searchRequestsOf(
FakeChannel channel, {
bool chats = false,
}) => requestsOf(channel, 'search')
.where(
(request) => ((request['search'] as Map?)?['kind'] == 'chat') == chats,
)
.toList();
Future<Map<String, dynamic>> waitForSearch(
WidgetTester tester,
FakeChannel channel, {
int index = 0,
bool chats = false,
}) async {
for (var attempt = 0; attempt < 80; attempt++) {
final requests = searchRequestsOf(channel, chats: chats);
if (index < requests.length) return requests[index];
await tester.pump(const Duration(milliseconds: 5));
}
fail('Timed out waiting for ${chats ? 'chat ' : ''}search #$index');
}
/// Answers the [index]th chat search (sent after each run search's reply)
/// with no chats, so the app's serialized requests continue.
Future<void> replyChatSearch(
WidgetTester tester,
FakeChannel channel, {
int index = 0,
}) async {
final request = await waitForSearch(
tester,
channel,
index: index,
chats: true,
);
channel.incoming.add(
jsonEncode({
'id': request['id'],
'type': 'search_results',
'search_results': {
'query': (request['search'] as Map)['query'],
'kind': 'chat',
'results': <JsonMap>[],
'cap': 50,
'scanned_steps': 0,
'scanned_bytes': 0,
'scan_bound_bytes': 1 << 20,
},
}),
);
await tester.pump();
await tester.pump();
}
Future<void> reply(
WidgetTester tester,
FakeChannel channel,
@@ -106,7 +163,7 @@ Future<void> searchArtifactHit(
await tester.pump(const Duration(milliseconds: 100));
await tester.enterText(find.byKey(const ValueKey('search.field')), 'report');
await tester.pump(const Duration(milliseconds: 300));
final request = await waitForRequest(tester, channel, 'search', index: index);
final request = await waitForSearch(tester, channel, index: index);
channel.incoming.add(
jsonEncode({
'id': request['id'],
@@ -125,6 +182,7 @@ Future<void> searchArtifactHit(
);
await tester.pump();
await tester.pump();
await replyChatSearch(tester, channel, index: index);
}
/// Selects the artifact hit, leaving run 7's `get_run` request unanswered.
@@ -401,7 +459,7 @@ void main() {
);
await tester.pump(const Duration(milliseconds: 300));
final request = await waitForRequest(tester, channel, 'search');
final request = await waitForSearch(tester, channel);
expect(request['search'], {'query': 'release', 'kind': '', 'limit': 0});
channel.incoming.add(
jsonEncode({
@@ -421,6 +479,7 @@ void main() {
);
await tester.pump();
await tester.pump();
await replyChatSearch(tester, channel);
expect(find.text('Run 7 · Preserved run'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('search.result.run:7')));
@@ -437,7 +496,8 @@ void main() {
expect(find.text('Run 7'), findsWidgets);
// One app socket carried the search and the run reads.
expect(sockets, 1);
expect(requestsOf(channel, 'search'), hasLength(1));
expect(searchRequestsOf(channel), hasLength(1));
expect(searchRequestsOf(channel, chats: true), hasLength(1));
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
@@ -480,12 +540,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 100));
await tester.enterText(find.byKey(const ValueKey('search.field')), query);
await tester.pump(const Duration(milliseconds: 300));
final request = await waitForRequest(
tester,
channel,
'search',
index: index,
);
final request = await waitForSearch(tester, channel, index: index);
channel.incoming.add(
jsonEncode({
'id': request['id'],
@@ -504,6 +559,7 @@ void main() {
);
await tester.pump();
await tester.pump();
await replyChatSearch(tester, channel, index: index);
}
// An artifact hit opens the run's Artifacts tab and that artifact's viewer.
@@ -592,7 +648,7 @@ void main() {
'report',
);
await tester.pump(const Duration(milliseconds: 300));
final request = await waitForRequest(tester, channel, 'search');
final request = await waitForSearch(tester, channel);
channel.incoming.add(
jsonEncode({
'id': request['id'],
@@ -611,6 +667,7 @@ void main() {
);
await tester.pump();
await tester.pump();
await replyChatSearch(tester, channel);
await tester.tap(
find.byKey(const ValueKey('search.result./artifacts/7/2/report.txt')),
@@ -0,0 +1,160 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/search/domain/search_chat_slice.dart';
import 'package:pipelines_app/features/search/domain/search_controller.dart';
import 'package:pipelines_app/features/search/domain/search_models.dart';
import 'search_test_support.dart';
const runHit = {
'kind': 'run',
'target': 'run:7',
'run': {'id': 7},
};
void main() {
test('an all-kind search sends the run search, then chats as their own '
'request, and shows runs before chats answer', () async {
final gateway = QueuedGateway(holdChats: true);
final controller = controllerFor(gateway);
addTearDown(controller.dispose);
controller.updateQuery('flaky');
await pumpEventQueue();
expect(gateway.lastSearch, {'query': 'flaky', 'kind': '', 'limit': 0});
expect(gateway.chatCalls.single['search'], {
'query': 'flaky',
'kind': 'chat',
'limit': 0,
});
gateway.succeed(0, envelope([runHit]));
await pumpEventQueue();
expect(controller.shownResults.single['target'], 'run:7');
expect(controller.bodyKind, SearchBodyKind.results);
expect(controller.shownChats, isEmpty);
expect(controller.showsChatSection, isFalse);
gateway.chatPending.single.complete(
envelope([
chatHit('ses_a', snippet: 'the flaky retry'),
// A non-chat row in a chat reply is not a chat.
runHit,
]),
);
await pumpEventQueue();
expect(controller.shownChats.single['target'], 'chat:ses_a');
expect(controller.showsChatSection, isTrue);
expect(controller.shownResults.single['target'], 'run:7');
expect(controller.chatsNote, isNull);
});
test('chat hits alone keep the body out of its empty state', () async {
final gateway = QueuedGateway(holdChats: true);
final controller = controllerFor(gateway);
addTearDown(controller.dispose);
controller.updateQuery('fix');
await pumpEventQueue();
gateway.succeed(0, envelope(const []));
await pumpEventQueue();
// Runs answered empty while chats still load: still searching.
expect(controller.bodyKind, SearchBodyKind.searching);
expect(controller.emptyMessage, isNull);
gateway.chatPending.single.complete(envelope([chatHit('ses_a')]));
await pumpEventQueue();
expect(controller.bodyKind, SearchBodyKind.results);
expect(controller.emptyMessage, isNull);
});
test(
'a narrowed kind sends no chat search; Chats alone sends only chats',
() async {
final gateway = QueuedGateway();
final controller = controllerFor(gateway);
addTearDown(controller.dispose);
controller.updateQuery('t:run flaky');
await pumpEventQueue();
expect(gateway.calls, hasLength(1));
expect(gateway.chatCalls, isEmpty);
controller.selectKind(SearchKind.chat);
await pumpEventQueue();
expect(gateway.calls, hasLength(1));
expect(gateway.chatCalls.single['search'], {
'query': 'flaky',
'kind': 'chat',
'limit': 0,
});
expect(controller.shownResults, isEmpty);
expect(controller.showsChatSection, isFalse);
},
);
test('a stale chat reply never replaces the newest query', () async {
final gateway = QueuedGateway(holdChats: true);
final controller = controllerFor(gateway);
addTearDown(controller.dispose);
controller.updateQuery('first');
await pumpEventQueue();
controller.updateQuery('second');
await pumpEventQueue();
expect(gateway.chatCalls, hasLength(2));
gateway.chatPending[0].complete(envelope([chatHit('ses_old')]));
await pumpEventQueue();
expect(controller.shownChats, isEmpty);
gateway.chatPending[1].complete(envelope([chatHit('ses_new')]));
await pumpEventQueue();
expect(controller.shownChats.single['target'], 'chat:ses_new');
});
test('a server without chat search says so beside its run results, and '
'is the error with Chats selected', () async {
final gateway = QueuedGateway(holdChats: true);
final controller = controllerFor(gateway);
addTearDown(controller.dispose);
controller.updateQuery('flaky');
await pumpEventQueue();
gateway.succeed(0, envelope([runHit]));
gateway.chatPending.single.completeError(
StateError(
'unknown search kind "chat"; use one of pipeline, version, run, '
'step, field, artifact',
),
);
await pumpEventQueue();
expect(controller.error, isNull);
expect(controller.shownResults, hasLength(1));
expect(controller.chatsNote, unsupportedChatSearchCopy);
expect(controller.showsChatSection, isTrue);
controller.selectKind(SearchKind.chat);
await pumpEventQueue();
gateway.chatPending.last.completeError(
StateError('unknown search kind "chat"'),
);
await pumpEventQueue();
expect(controller.error, unsupportedChatSearchCopy);
expect(controller.bodyKind, SearchBodyKind.error);
});
test('a truncated chat reply carries a bounds note', () async {
final gateway = QueuedGateway(holdChats: true);
final controller = controllerFor(gateway);
addTearDown(controller.dispose);
controller.updateQuery('flaky');
await pumpEventQueue();
gateway.succeed(0, envelope(const []));
gateway.chatPending.single.complete(
envelope([chatHit('ses_a')], truncated: true),
);
await pumpEventQueue();
expect(controller.chatsNote, contains('not searched'));
});
}
@@ -0,0 +1,73 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/search/domain/search_row.dart';
import 'package:pipelines_app/features/search/domain/search_target.dart';
import 'search_test_support.dart' show chatHit;
void main() {
test('a message hit shows the title, harness and directory and its '
'snippet with the match split out', () {
final row = searchRowView(
chatHit('ses_a', snippet: 'the FLAKY retry'),
'flaky',
);
expect(row.title, 'Fix CI');
expect(row.kindLabel, 'Chat');
expect(row.secondary, 'Claude Code · /work/api');
expect(row.snippet, 'the FLAKY retry');
expect(row.snippetSpans.map((span) => (span.text, span.matched)), [
('the ', false),
('FLAKY', true),
(' retry', false),
]);
expect(row.target, 'chat:ses_a');
expect(row.openable, isTrue);
});
test('a title hit has no snippet; closed and untitled chats say so', () {
final base = chatHit('ses_b', title: ' ');
final hit = {
...base,
'chat': <String, dynamic>{
...(base['chat'] as Map),
'backend': '',
'closed': true,
},
};
final row = searchRowView(hit, 'x');
expect(row.title, 'Untitled chat');
expect(row.secondary, 'OpenCode · /work/api · closed');
expect(row.snippet, isNull);
});
test('a chat hit resolves to its session, keeping the matched message', () {
final resolved = searchTargetFor(chatHit('ses_a'));
expect(resolved, isA<ResolvedSearchTarget>());
final target = (resolved as ResolvedSearchTarget).target;
expect(target, isA<SearchChatTarget>());
expect((target as SearchChatTarget).sessionId, 'ses_a');
expect(target.kind, SearchTargetKind.chat);
expect(target.wire, 'chat:ses_a');
final message = chatHit('ses_a', snippet: 'x');
(message['chat'] as Map)['message_id'] = 'm9';
final withMessage =
(searchTargetFor(message) as ResolvedSearchTarget).target
as SearchChatTarget;
expect(withMessage.messageId, 'm9');
expect(withMessage, target);
expect(SearchTarget.fromWire('chat:ses_a'), target);
expect(SearchTarget.fromWire('chat:'), isNull);
});
test('a chat hit without a session id or with a mismatched target is not '
'openable', () {
final missing = chatHit('ses_a');
(missing['chat'] as Map).remove('session_id');
expect(searchTargetFor(missing), isA<UnresolvedSearchTarget>());
final mismatched = {...chatHit('ses_a'), 'target': 'chat:ses_b'};
expect(searchTargetFor(mismatched), isA<UnresolvedSearchTarget>());
});
}
@@ -0,0 +1,124 @@
import 'package:flutter/cupertino.dart';
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/search/search_screen.dart';
import 'package:pipelines_app/features/search/ui/search_result_slivers.dart';
import 'search_screen_test.dart'
show ImmediateGateway, field, response, search, useNarrowSurface;
import 'search_test_support.dart' show chatHit;
/// Run hits for every kind but chat; chat hits for the chat request.
JsonMap replies(String query, String kind) => kind == 'chat'
? response([
chatHit('ses_a', title: 'API refactor', snippet: 'the release retry'),
chatHit('ses_b', title: 'Release notes'),
])
: response([field]);
Widget host(Widget child, {required bool cupertino}) =>
cupertino ? CupertinoApp(home: child) : MaterialApp(home: child);
void main() {
for (final cupertino in [false, true]) {
final platform = cupertino ? 'Cupertino' : 'Material';
testWidgets('$platform: chat hits lead as a Chats group with title, '
'harness, directory and snippet, and open their chat', (tester) async {
useNarrowSurface(tester);
final gateway = ImmediateGateway(replies);
JsonMap? opened;
await tester.pumpWidget(
host(
SearchScreen(
gateway: gateway,
onOpen: (value) => opened = value,
cupertino: cupertino,
),
cupertino: cupertino,
),
);
await search(tester, 'release');
expect(gateway.calls.single['search'], {
'query': 'release',
'kind': '',
'limit': 0,
});
expect(gateway.chatCalls.single['search'], {
'query': 'release',
'kind': 'chat',
'limit': 0,
});
expect(find.text('Chats (2)'), findsOneWidget);
expect(find.text('Pipelines and runs'), findsOneWidget);
final chats = tester.getTopLeft(find.byKey(searchChatsSectionKey));
final others = tester.getTopLeft(find.byKey(searchOthersSectionKey));
final chatRow = find.byKey(const ValueKey('search.result.chat:ses_a'));
final runRow = find.byKey(
const ValueKey('search.result.run:11:4:output'),
);
expect(chats.dy, lessThan(tester.getTopLeft(chatRow).dy));
expect(tester.getTopLeft(chatRow).dy, lessThan(others.dy));
expect(others.dy, lessThan(tester.getTopLeft(runRow).dy));
expect(find.text('API refactor'), findsOneWidget);
expect(find.text('Release notes'), findsOneWidget);
expect(
find.textContaining('Chat · Claude Code · /work/api'),
findsNWidgets(2),
);
expect(find.textContaining('the release retry'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(chatRow);
await tester.pump();
expect(opened?['target'], 'chat:ses_a');
expect((opened?['chat'] as Map)['session_id'], 'ses_a');
});
}
testWidgets('Chats selected alone lists chats without group headings', (
tester,
) async {
useNarrowSurface(tester);
final gateway = ImmediateGateway(replies);
await tester.pumpWidget(
MaterialApp(
home: SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false),
),
);
await search(tester, 't:chat release');
expect(gateway.calls, isEmpty);
expect(gateway.chatCalls, hasLength(1));
expect(find.text('API refactor'), findsOneWidget);
expect(find.byKey(searchChatsSectionKey), findsNothing);
expect(find.byKey(searchOthersSectionKey), findsNothing);
});
testWidgets('an older server without chat search keeps its run results and '
'says chats were not searched', (tester) async {
useNarrowSurface(tester);
final gateway = ImmediateGateway((query, kind) {
if (kind == 'chat') {
throw StateError('unknown search kind "chat"; use one of pipeline');
}
return response([field]);
});
await tester.pumpWidget(
MaterialApp(
home: SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false),
),
);
await search(tester, 'release');
expect(
find.byKey(const ValueKey('search.result.run:11:4:output')),
findsOneWidget,
);
expect(find.byKey(searchChatsNoteKey), findsOneWidget);
expect(find.textContaining('does not search chats'), findsOneWidget);
});
}
@@ -14,6 +14,7 @@ void main() {
'step',
'field',
'artifact',
'chat',
'version',
]);
expect(SearchKind.values.map((kind) => kind.label), [
@@ -23,6 +24,7 @@ void main() {
'Steps',
'Fields',
'Artifacts',
'Chats',
'Versions',
]);
expect(SearchKind.fromWire('run'), SearchKind.run);
@@ -10,10 +10,13 @@ class RecordingGateway implements ApiGateway {
final JsonMap Function(String query, String kind) reply;
final calls = <JsonMap>[];
/// The `kind: chat` searches sent beside the others.
final chatCalls = <JsonMap>[];
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add(Map.of(fields));
final search = Map<String, dynamic>.from(fields['search'] as Map);
(search['kind'] == 'chat' ? chatCalls : calls).add(Map.of(fields));
return reply(search['query'] as String, search['kind'] as String);
}
@@ -56,7 +59,7 @@ void main() {
expect(gateway.calls, isEmpty);
expect(
find.text('Search pipelines, runs and artifacts.'),
find.text('Search pipelines, runs, artifacts and chats.'),
findsOneWidget,
);
expect(find.textContaining('No matches'), findsNothing);
@@ -10,10 +10,13 @@ class ImmediateGateway implements ApiGateway {
final JsonMap Function(String query, String kind) reply;
final calls = <JsonMap>[];
/// The `kind: chat` searches sent beside the others.
final chatCalls = <JsonMap>[];
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add(Map.of(fields));
final search = Map<String, dynamic>.from(fields['search'] as Map);
(search['kind'] == 'chat' ? chatCalls : calls).add(Map.of(fields));
return reply(search['query'] as String, search['kind'] as String);
}
@@ -29,6 +32,8 @@ class FailingThenSucceedingGateway implements ApiGateway {
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
final search = fields['search'];
if (search is Map && search['kind'] == 'chat') return success;
calls++;
if (calls == 1) throw StateError('unknown command: search');
return success;
@@ -4,12 +4,28 @@ import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/search/data/search_repository.dart';
import 'package:pipelines_app/features/search/domain/search_controller.dart';
/// Queues run/artifact searches in [calls]/[pending]. A `kind: chat` search
/// (sent beside every all-kind search) is recorded in [chatCalls] and, unless
/// [holdChats] is set, answered at once with no chats.
class QueuedGateway implements ApiGateway {
QueuedGateway({this.holdChats = false});
final bool holdChats;
final calls = <JsonMap>[];
final pending = <Completer<JsonMap>>[];
final chatCalls = <JsonMap>[];
final chatPending = <Completer<JsonMap>>[];
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
final search = fields['search'];
if (search is Map && search['kind'] == 'chat') {
chatCalls.add(Map.of(fields));
if (!holdChats) return Future.value(envelope(const []));
final completer = Completer<JsonMap>();
chatPending.add(completer);
return completer.future;
}
calls.add(Map.of(fields));
final completer = Completer<JsonMap>();
pending.add(completer);
@@ -48,3 +64,18 @@ OmniSearchController controllerFor(ApiGateway gateway) => OmniSearchController(
repository: SearchRepository(gateway),
debounce: Duration.zero,
);
/// A server-shaped `kind: chat` hit; a [snippet] makes it a message match.
JsonMap chatHit(String id, {String title = 'Fix CI', String? snippet}) => {
'kind': 'chat',
'target': 'chat:$id',
'score': snippet == null ? 3 : 1,
'matched_field': snippet == null ? 'title' : 'message',
'chat': {
'session_id': id,
'title': title,
'directory': '/work/api',
'backend': 'claude',
'snippet': ?snippet,
},
};
+79
View File
@@ -0,0 +1,79 @@
// Server-shaped `kind: chat` search replies over the `?chats=N` sessions
// (tool/perf/perf_fixture.dart), so Search can show and open chat hits in
// captures. Without `?chats=` there are no chats and no hits.
import 'package:pipelines_app/core/api_gateway.dart';
import 'perf_fixture.dart';
/// Hits the way `internal/server/search_chats.go` answers: a title or
/// directory match from the registry row, else the newest transcript message
/// whose text matches, with a snippet around the match. One hit per chat, best
/// match first. A blank query lists every chat.
List<JsonMap> perfChatSearchHits(String query) {
final needle = query.trim().toLowerCase();
final hits = <JsonMap>[];
for (final row in perfChatRows()) {
final title = '${row['title'] ?? ''}';
final directory = '${row['directory'] ?? ''}';
final chat = <String, dynamic>{
'session_id': row['id'],
'title': title,
'directory': directory,
'backend': row['backend'] ?? 'opencode',
'updated_at': ?row['updated_at'],
};
String field;
int score;
if (needle.isEmpty) {
field = '';
score = 0;
} else if (title.toLowerCase().contains(needle)) {
field = 'title';
score = 3;
} else if (directory.toLowerCase().contains(needle)) {
field = 'directory';
score = 2;
} else {
final match = _newestMatch(needle);
if (match == null) continue;
field = 'message';
score = 1;
chat
..['message_id'] = 'perf-m${match.index}'
..['role'] = match.index.isEven ? 'user' : 'assistant'
..['snippet'] = match.snippet;
}
final updated = row['updated_at'];
hits.add({
'kind': 'chat',
'target': 'chat:${row['id']}',
'score': score,
'matched_field': field,
if (updated is int)
'recency': DateTime.fromMillisecondsSinceEpoch(
updated,
isUtc: true,
).toIso8601String(),
'chat': chat,
});
}
hits.sort((a, b) => (b['score'] as int).compareTo(a['score'] as int));
return hits;
}
({int index, String snippet})? _newestMatch(String needle) {
for (var m = 19; m >= 0; m--) {
final line = perfChatMessageText(m).replaceAll(RegExp(r'\s+'), ' ');
final at = line.toLowerCase().indexOf(needle);
if (at < 0) continue;
final start = at - 40 < 0 ? 0 : at - 40;
final end = at + needle.length + 40 > line.length
? line.length
: at + needle.length + 40;
final snippet =
'${start > 0 ? '…' : ''}${line.substring(start, end)}'
'${end < line.length ? '…' : ''}';
return (index: m, snippet: snippet);
}
return null;
}
+7
View File
@@ -264,3 +264,10 @@ JsonMap? perfChatReply(JsonMap request) {
}
return null;
}
/// The `?chats=N` list rows, as chat_sessions serves them.
List<JsonMap> perfChatRows() => [for (var i = 0; i < _chats; i++) _chatRow(i)];
/// The text of message `perf-m<m>` in the bench's short transcript, newest
/// last (20 messages).
String perfChatMessageText(int m) => m.isEven ? 'Question $m' : _answer(m);
@@ -28,6 +28,7 @@ import 'package:web/web.dart' as web;
import 'package:web_socket_channel/web_socket_channel.dart';
import 'perf/backdrop_census.dart';
import 'perf/chat_search_fixture.dart';
import 'perf/chat_scroll_fixture.dart';
import 'perf/chat_scroll_probe.dart';
import 'perf/frame_log.dart';
@@ -449,6 +450,24 @@ JsonMap? probeReply(JsonMap request) {
}
final query = (search['query'] as String).trim().toLowerCase();
final kind = search['kind'] as String;
if (kind == 'chat') {
// The server answers chats as their own request (search_chats.go).
return {
'id': id,
'type': 'search_results',
'search_results': {
'query': search['query'],
'kind': kind,
'results': perfChatSearchHits(query),
'truncated': false,
'scanned_steps': 0,
'scanned_bytes': 0,
'cap': 50,
'scan_bound_bytes': 1048576,
'scanned_chats': 3,
},
};
}
final results = [
for (final entry in probeHits)
if ((kind.isEmpty || entry.hit['kind'] == kind) &&