Files
pipelines/app/tool/perf/perf_fixture.dart
T
alan 0dc805ae0e Chat: show the active Claude account in the send tooltip, menu and limit banner
usage.account now carries the email and organization of the account
Claude Code is signed in to (from its initialize account, or the saved
account just switched to), sent at process start and after a switch.
The app shows it as the send tooltip's usage prefix, the Claude account
menu subtitle, the usage-limit banner's status line and the info sheet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:33:46 +00:00

551 lines
19 KiB
Dart

// Extra fixture data for the interaction bench (tool/perf/interaction_bench.mjs)
// over the full-app probe (tool/search_selection_probe_entry.dart). Every
// option defaults to off, so other captures see the fixture unchanged.
//
// `?hits=N` N more `release` run hits in Search;
// `?chats=N` N chat sessions in the chat list, each opening a short
// markdown transcript;
// `?graph=1` run 7 carries its pinned graph (plan -> build);
// `?quota=claude|opencode|limit|warn80|warn95` (with `?chats=N`) pushes a
// usage frame with that harness's account quota after a chat
// subscribes; `limit` is Claude Code with its 5-hour window
// exhausted and the transcript ending on Claude Code's limit
// refusal, `warn80` and `warn95` with it at 84% and 96% (the
// send ring's warning tones) and the weekly window at 60% and
// 88%; otherwise the weekly window is at 93%.
// `?colors=1` (with `?chats=N`) names the chats, stars and colours some of
// them, and keeps colours picked with chat_color;
// `?activity=1` (with `?chats=N`) lists a running chat, one with
// background tasks and idle ones;
// `?automations=N` reports N native automations for the selected chat;
// `?msgs=`, `?rich=1`, `?older=1`, `?live=N` vary the chat transcripts for
// scroll captures (tool/perf/chat_scroll_fixture.dart).
// `?question=` pushes an agent question (tool/perf/chat_question_fixture.dart).
// `?shell=1` lists operator shell commands in every chat
// (tool/perf/chat_shell_fixture.dart).
// `/new` in a fixture chat moves it to a fresh, empty session
// (tool/perf/chat_new_session_fixture.dart).
import 'package:pipelines_app/core/api_gateway.dart';
import 'chat_claude_accounts_fixture.dart';
import 'chat_effort_fixture.dart';
import 'chat_catalog_fixture.dart';
import 'chat_new_session_fixture.dart';
import 'chat_turn_diff_fixture.dart';
import 'chat_question_fixture.dart';
import 'chat_shell_fixture.dart';
import 'terminal_fixture.dart';
import 'chat_shown_fixture.dart';
import 'chat_scroll_fixture.dart';
Map<String, String> _params = const {};
DateTime? _exampleTaskStarted;
/// Reads the options from the page URL's query, before the app rewrites it.
void configurePerfFixture(Map<String, String> params) {
_params = params;
_exampleTaskStarted = DateTime.now().toUtc().subtract(
const Duration(minutes: 4, seconds: 40),
);
configureChatScrollFixture(params);
configureChatShownPush(params);
configureChatClaudeAccountsFixture(params);
configureChatQuestionFixture(params);
configureChatShellFixture(params);
configureTerminalFixture(params);
}
int get _hits => int.tryParse(_params['hits'] ?? '') ?? 0;
int get _chats => int.tryParse(_params['chats'] ?? '') ?? 0;
bool get perfRunGraph => _params['graph'] == '1';
bool get _colors => _params['colors'] == '1';
/// `?activity=1` (with `?chats=N`): the first chat's turn is running, the
/// second is idle with two background tasks, the rest are idle, as the
/// server's `activity` row field reports them.
JsonMap? _activityFor(int i) {
if (_params['activity'] != '1') return null;
return switch (i) {
0 => {'turn_running': true, 'background_tasks': 1, 'seq': 3},
1 => {'background_tasks': 2, 'seq': 2},
// A turn blocked on the operator: an approval and a question unanswered.
2 => {'turn_running': true, 'awaiting_operator': 2, 'seq': 4},
_ => {'seq': 1},
};
}
/// `?colors=1`: titles, directories, stars and colours per chat index.
const _colorTitles = [
'Release notes',
'api refactor',
'Billing bug',
'Docs pass',
'Flaky test',
'Onboarding',
'Perf sweep',
'Search UX',
];
const _colorStarred = {0, 1, 3};
const _colorNames = ['teal', 'purple', null, 'amber', 'red', null, 'blue'];
final Map<String, String?> _pickedColors = {};
final _chatCatalog = ChatCatalogFixture();
JsonMap _chatRow(int i) {
final id = perfChatId(i);
if (!_colors) {
return {
'id': id,
'title': 'Fixture chat ${i + 1}',
'directory': '/workspace/demo',
if (_params['header'] == '1') ...{
..._chatCatalog.rowFields(id),
...chatEffortRowFields(id),
},
// Server-shaped handoff facts (chat_sessions rows carry them).
if (_harness != 'opencode') 'backend': _harness,
'resume_command': _resumeCommand(id),
'native_export': _harness == 'claude',
'activity': ?_activityFor(i),
};
}
final color = _pickedColors.containsKey(id)
? _pickedColors[id]
: _colorNames[i % _colorNames.length];
return {
'id': id,
'title': _colorTitles[i % _colorTitles.length],
'directory': i.isEven ? '/workspace/demo' : '/workspace/site',
'model': 'claude-opus',
if (_params['header'] == '1') ...{
'mode': 'default',
'mode_name': 'Ask for permission',
},
'backend': 'claude',
'updated_at': DateTime.now().millisecondsSinceEpoch - (i + 1) * 600000,
if (_colorStarred.contains(i)) 'starred': true,
'color': ?color,
'activity': ?_activityFor(i),
};
}
/// `?harness=claude|codex` makes the chats that harness's (default OpenCode),
/// with the resume command the server would send for it.
String get _harness => _params['harness'] ?? 'opencode';
String _resumeCommand(String id) => switch (_harness) {
'claude' => 'cd /workspace/demo && claude --resume $id',
'codex' => 'cd /workspace/demo && codex resume $id',
_ => 'cd /workspace/demo && opencode --session $id',
};
/// Whether a chat scroll option (tool/perf/chat_scroll_fixture.dart) shapes
/// the transcripts instead of the bench's short markdown history.
bool get _scrollVariety => ['msgs', 'rich', 'older'].any(_params.containsKey);
/// Unsolicited envelopes that follow a reply: the `?quota=` usage frame.
List<JsonMap> perfChatFollowUps(JsonMap request) {
final terminal = terminalFixtureFollowUps(request);
if (terminal.isNotEmpty) return terminal;
final answered = chatQuestionFollowUps(request);
if (answered.isNotEmpty) return answered;
final shell = chatShellFollowUps(request);
if (shell.isNotEmpty) return shell;
if (_scheduledPrompt(request) case final prompt?) {
return [
{
'type': 'chat_queue',
'chat_queue': {
'session_id': prompt['session_id'],
'prompts': [
{
'operation_id': prompt['operation_id'],
'native_message_id': prompt['native_message_id'],
'text': prompt['text'],
'send_at': prompt['send_at'],
},
],
},
},
];
}
final quota = _params['quota'];
if (_chats == 0 || quota == null || request['type'] != 'chat_subscribe') {
return const [];
}
final now = DateTime.now();
int at(Duration offset) => now.add(offset).millisecondsSinceEpoch;
final account = quota == 'opencode'
? {'harness': 'OpenCode', 'unsupported': true}
: {
'harness': 'Claude Code',
'source': 'rate_limit_event',
'plan': 'max',
'as_of': at(const Duration(minutes: -4)),
'windows': [
{
'id': 'five_hour',
'label': '5-hour',
'used_percent': switch (quota) {
'limit' => 100,
'warn80' => 84,
'warn95' => 96,
_ => 42,
},
'resets_at': at(
const Duration(hours: 2, minutes: 14, seconds: 30),
),
},
{
'id': 'seven_day',
'label': 'Weekly',
'used_percent': switch (quota) {
'warn80' => 60,
'warn95' => 88,
_ => 93,
},
'resets_at': at(const Duration(days: 3, hours: 5)),
},
],
};
return [
{
'type': 'chat_event',
'chat_event': {
'session_id': (request['chat_subscribe'] as Map?)?['session_id'],
'kind': 'usage',
'usage': {
'scope': 'session',
'total_tokens': 132408,
'context_tokens': 42000,
'context_window': 200000,
'account': chatClaudeNamedAccount(account),
},
},
},
];
}
/// A `chat_prompt` body carrying `send_at`, or null.
Map? _scheduledPrompt(JsonMap request) {
if (request['type'] != 'chat_prompt') return null;
final body = request['chat_prompt'];
return body is Map && body['send_at'] is num ? body : null;
}
/// Run 7's pinned graph for `?graph=1`.
JsonMap perfRunGraphFixture() => {
'name': 'Release train',
'stages': [
{
'key': 'plan',
'type': 'model',
'edges': {'success': 'build', 'error': '#'},
},
{
'key': 'build',
'type': 'model',
'edges': {'success': 'plan', 'error': '#failure'},
},
],
};
/// Filler run hits for a query that `release` text matches.
List<JsonMap> perfSearchHits(String query, String kind) {
if (_hits == 0 || (kind.isNotEmpty && kind != 'run')) return const [];
if (query.isNotEmpty && !'release filler run'.contains(query)) {
return const [];
}
return [
for (var i = 0; i < _hits; i++)
{
'kind': 'run',
'target': 'run:${1000 + i}',
'score': 1,
'recency': '2026-10-18T08:42:00Z',
'run': {
'id': 1000 + i,
'pipeline_name': 'Release filler $i',
'status': i % 3 == 0 ? 'failed' : 'succeeded',
'workspace': '/srv/probe/release',
'created_at': '2026-10-18T08:12:00Z',
'finished_at': '2026-10-18T08:42:00Z',
},
},
];
}
String _answer(int i) =>
'## Answer $i\n\nSome **bold** text with `code`.\n\n'
'```dart\n${List.generate(8, (l) => 'final v$l = $i * $l;').join('\n')}'
'\n```\n\n- one\n- two\n';
/// Chat replies for `?chats=N`, or null to fall through to the fixture.
JsonMap? perfChatReply(JsonMap request) {
final terminal = terminalFixtureReply(request);
if (terminal != null) return terminal;
if (_chats == 0) return null;
final accounts = chatClaudeAccountsReply(request);
if (accounts != null) return accounts;
final question = chatQuestionReply(request);
if (question != null) return question;
final shell = chatShellReply(request);
if (shell != null) return shell;
final id = request['id'];
if (_params['header'] == '1') {
final catalog = _chatCatalog.reply(request);
if (catalog != null) return {'id': id, ...catalog};
}
switch ('${request['type']}') {
case 'chat_effort':
return {'id': id, ...chatEffortReply(request)};
case 'chat_sessions':
return {
'id': id,
'type': 'chat_sessions',
'chat_sessions': [for (var i = 0; i < _chats; i++) _chatRow(i)],
};
case 'chat_color':
final query = request['chat_query'];
final session = query is Map ? '${query['session_id'] ?? ''}' : '';
final color = query is Map ? query['color'] as String? : null;
_pickedColors[session] = color;
final row = _chatRow(perfChatIndex(session));
return {
'id': id,
'type': 'chat_color',
'chat_session': row,
'chat_sessions': [row],
};
case 'chat_export':
final body = request['chat_export'];
final format = body is Map ? '${body['format'] ?? ''}' : '';
final json = format == 'json';
return {
'id': id,
'type': 'chat_export',
'chat_export_file': {
'session_id': body is Map ? body['session_id'] : '',
'format': format,
'name': json ? 'Fixture-chat.json' : 'Fixture-chat.md',
'mime': json ? 'application/json' : 'text/markdown',
'content': json ? '{"messages":[]}\n' : '# Fixture chat\n',
},
};
case 'chat_new_session':
return perfChatNewSessionReply(request, _chatRow);
case 'chat_subscribe':
return {
'id': id,
'type': 'chat_subscribed',
if (_params['shown'] == '1')
'chat_shown': chatShownFixture(
(request['chat_subscribe'] as Map?)?['session_id'],
),
};
case 'chat_prompt':
// Accepted, as the server does; no reply follows, so a capture can
// watch the sent message itself.
return {
'id': id,
'type': 'chat_prompt',
// A scheduled prompt (`send_at`) is always held, as the server does.
'chat_queued': _scheduledPrompt(request) != null,
if (_params['steered'] == '1') 'chat_steered': true,
};
case 'chat_unqueue':
// The fixture holds at most the one scheduled prompt: removing it
// leaves the queue empty.
final body = request['chat_unqueue'];
final unqueue = body is Map ? body : const {};
return {
'id': id,
'type': 'chat_unqueue',
'chat_queue': {
'session_id': unqueue['session_id'],
'prompts': const [],
'removed': unqueue['operation_id'],
},
};
case 'chat_shells':
return {
'id': id,
'type': 'chat_shells',
'chat_shells':
(_params['tasks'] == 'rich' || _params['tasks'] == 'example')
? backgroundTaskFixture()
: const [],
};
case 'chat_automations':
final query = request['chat_query'];
final session = query is Map ? '${query['session_id'] ?? ''}' : '';
final count = int.tryParse(_params['automations'] ?? '');
return {
'id': id,
'type': 'chat_automations',
'chat_automations': count == null
? {'session_id': session, 'status': 'unavailable'}
: {
'session_id': session,
'provider': _harness,
'status': 'supported',
'active_count': count,
'observed_at_ms': DateTime.now().millisecondsSinceEpoch,
},
};
case 'chat_shell_output':
final outputQuery = request['chat_shell_output_query'];
final outputId = outputQuery is Map ? outputQuery['shell_id'] : null;
final selectedTask =
(_params['tasks'] == 'rich' || _params['tasks'] == 'example')
? backgroundTaskFixture()
.where((task) => task['id'] == outputId)
.firstOrNull
: null;
return {
'id': id,
'type': 'chat_shell_output',
'chat_shell_output': selectedTask == null
? {'unavailable': true}
: {
'shell': selectedTask,
'output':
'Checking the integration changes…\nTargeted checks passed.\nReviewing remaining findings.',
'cursor': 0,
},
};
case 'chat_messages':
final query = request['chat_query'];
final session = query is Map ? '${query['session_id'] ?? ''}' : '';
if (perfChatIsFresh(session)) {
return {
'id': id,
'type': 'chat_messages',
'chat_history': {
'messages': const [],
'next_cursor': '',
'has_more': false,
},
};
}
if (_scrollVariety) {
return {
'id': id,
'type': 'chat_messages',
'chat_history': chatScrollHistory(
session,
perfChatIndex(session),
query is Map ? '${query['cursor'] ?? ''}' : '',
),
};
}
return {
'id': id,
'type': 'chat_messages',
'chat_history': {
'messages': [
for (var i = 0; i < 20; i++)
{
'id': 'perf-m$i',
'role': i.isEven ? 'user' : 'assistant',
if (_params['timestamps'] == '1')
'created_at': DateTime.utc(
2026,
11,
5,
9,
i,
).millisecondsSinceEpoch,
'parts': [
{
'type': 'text',
'text': i.isEven ? 'Question $i' : _answer(i),
},
],
},
if (_params['quota'] == 'limit')
{
'id': 'perf-limit-refusal',
'role': 'assistant',
'parts': [
{
'type': 'text',
'text':
"You've hit your 5-hour limit · resets 5:20pm "
'(Europe/London) · out of usage credits',
},
],
},
],
'next_cursor': '',
'has_more': false,
},
if (_params['turndiffs'] == '1')
'chat_turn_diffs': chatTurnDiffFixtureList(session),
};
case 'chat_turn_diff':
return chatTurnDiffFixtureReply(id, 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);
/// Opt-in recorded task facts for background-list captures; never contacts a backend.
List<JsonMap> backgroundTaskFixture() {
if (_params['tasks'] == 'example') {
const title = 'Reading screenshots/intake-ui-review-r2/23-more-menu.png';
return [
{
'id': 'task-screenshot',
'status': 'running',
'command': title,
'description': title,
'progress': title,
'task_type': 'local_agent',
'started_at': _exampleTaskStarted!.millisecondsSinceEpoch,
'updated_at': _exampleTaskStarted!
.add(const Duration(minutes: 4))
.millisecondsSinceEpoch,
'last_tool': 'Read',
'tool_count': 37,
'token_count': 120905,
},
];
}
return [
{
'id': 'task-review',
'status': 'running',
'command': 'Agent: Review the integration changes',
'task_type': 'agent',
'description': 'Review the integration changes',
'started_at': DateTime.utc(2026, 11, 6, 9, 5).millisecondsSinceEpoch,
'updated_at': DateTime.utc(2026, 11, 6, 9, 24).millisecondsSinceEpoch,
'progress': 'Checking tests and reviewing the remaining findings',
'last_tool': 'Read',
'tool_count': 18,
'token_count': 12450,
},
{
'id': 'task-checks',
'status': 'running',
'command': 'flutter analyze && integration checks',
'task_type': 'shell',
'started_at': DateTime.utc(2026, 11, 6, 9, 18).millisecondsSinceEpoch,
'progress': 'Analyzing application sources',
'tool_count': 0,
},
{
'id': 'task-legacy',
'status': 'running',
'command': 'Wait for upstream release',
'duration_ms': 74000,
},
];
}