Record chat shell commands with fixture captures and a note
Show Expand only when output can overflow and drop the final newline from the drawn output. The full-app probe lists shell runs with ?shell=1 so the cards, Shell mode and Run command dialog can be captured in Chrome.
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
// Operator shell commands for the full-app probe (`?shell=1`, with
|
||||
// `?chats=N`): every fixture chat lists four recorded runs (succeeded, failed,
|
||||
// stopped and one still running), and chat_shell_run/stop/share answer as the
|
||||
// server does, with the frames that follow.
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
bool _enabled = false;
|
||||
DateTime _base = DateTime.now();
|
||||
|
||||
void configureChatShellFixture(Map<String, String> params) {
|
||||
_enabled = params['shell'] == '1';
|
||||
_base = DateTime.now().subtract(const Duration(minutes: 3));
|
||||
}
|
||||
|
||||
int _at(int seconds) =>
|
||||
_base.add(Duration(seconds: seconds)).millisecondsSinceEpoch;
|
||||
|
||||
String _session(JsonMap request) {
|
||||
final body = request['chat_shell_run_request'] ?? request['chat_query'];
|
||||
return body is Map ? '${body['session_id'] ?? ''}' : '';
|
||||
}
|
||||
|
||||
JsonMap _run(
|
||||
String session,
|
||||
String id,
|
||||
String command,
|
||||
int started, {
|
||||
String status = 'exited',
|
||||
int? exitCode,
|
||||
int duration = 0,
|
||||
String output = '',
|
||||
}) => {
|
||||
'id': id,
|
||||
'session_id': session,
|
||||
'command': command,
|
||||
'directory': '/Users/operator/src/pipelines',
|
||||
'status': status,
|
||||
'exit_code': ?exitCode,
|
||||
'started_at': _at(started),
|
||||
if (status != 'running') 'ended_at': _at(started) + duration,
|
||||
'duration_ms': duration,
|
||||
'output': output,
|
||||
'output_bytes': output.length,
|
||||
};
|
||||
|
||||
List<JsonMap> _runs(String session) => [
|
||||
_run(
|
||||
session,
|
||||
'run_status',
|
||||
'git status --short',
|
||||
0,
|
||||
exitCode: 0,
|
||||
duration: 84,
|
||||
output:
|
||||
' M app/lib/features/chat/shell/chat_shell_run_card.dart\n'
|
||||
'?? app/notes/chat-shell-commands.md\n',
|
||||
),
|
||||
_run(
|
||||
session,
|
||||
'run_tests',
|
||||
'go test ./internal/server -run ChatShell',
|
||||
20,
|
||||
exitCode: 1,
|
||||
duration: 4210,
|
||||
output:
|
||||
'${[for (final name in _tests) '=== RUN TestChatShell$name\n--- PASS: TestChatShell$name (0.0${name.length % 9}s)\n'].join()}'
|
||||
'--- FAIL: TestChatShellStopInterruptsTheGroup (0.21s)\n'
|
||||
' chat_shell_run_test.go:112: stopped record = {Status:exited}\n'
|
||||
'FAIL\n'
|
||||
'FAIL\tgit.a-wan.net/alan/pipelines/internal/server\t0.611s\n'
|
||||
'FAIL\n',
|
||||
),
|
||||
_run(
|
||||
session,
|
||||
'run_watch',
|
||||
'tail -f /var/log/system.log',
|
||||
40,
|
||||
status: 'stopped',
|
||||
duration: 15200,
|
||||
output: 'Nov 9 15:58:01 host kernel[0]: wake reason: EC.LidOpen\n',
|
||||
),
|
||||
_run(
|
||||
session,
|
||||
'run_build',
|
||||
'flutter build web --target tool/search_selection_probe_entry.dart',
|
||||
60,
|
||||
status: 'running',
|
||||
output:
|
||||
'Compiling lib/main.dart for the Web...\n'
|
||||
'Font asset "CupertinoIcons.ttf" was tree-shaken.\n',
|
||||
),
|
||||
];
|
||||
|
||||
JsonMap? chatShellReply(JsonMap request) {
|
||||
if (!_enabled) return null;
|
||||
final id = request['id'];
|
||||
final session = _session(request);
|
||||
final body = request['chat_shell_run_request'];
|
||||
final runId = body is Map ? '${body['run_id'] ?? ''}' : '';
|
||||
switch ('${request['type']}') {
|
||||
case 'chat_shell_runs':
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_shell_runs',
|
||||
'chat_shell_runs': _runs(session),
|
||||
};
|
||||
case 'chat_shell_run':
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_shell_run',
|
||||
'chat_shell_run': _run(
|
||||
session,
|
||||
'run_new',
|
||||
body is Map ? '${body['command'] ?? ''}' : '',
|
||||
180,
|
||||
status: 'running',
|
||||
),
|
||||
};
|
||||
case 'chat_shell_stop':
|
||||
return {'id': id, 'type': 'chat_shell_stop'};
|
||||
case 'chat_shell_run_output':
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_shell_run_output',
|
||||
'chat_shell_run': _runs(session).firstWhere(
|
||||
(run) => run['id'] == runId,
|
||||
orElse: () => _runs(session).first,
|
||||
),
|
||||
};
|
||||
case 'chat_shell_share':
|
||||
return {'id': id, 'type': 'chat_prompt'};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// The frames the server pushes after a run starts or is stopped.
|
||||
List<JsonMap> chatShellFollowUps(JsonMap request) {
|
||||
if (!_enabled) return const [];
|
||||
final session = _session(request);
|
||||
JsonMap frame(JsonMap body) => {
|
||||
'type': 'chat_shell_run_event',
|
||||
'chat_shell_run_event': {'session_id': session, ...body},
|
||||
};
|
||||
switch ('${request['type']}') {
|
||||
case 'chat_shell_run':
|
||||
const text = 'hello from the fixture shell\n';
|
||||
final body = request['chat_shell_run_request'];
|
||||
return [
|
||||
frame({
|
||||
'run_id': 'run_new',
|
||||
'output': text,
|
||||
'offset': 0,
|
||||
'end': text.length,
|
||||
}),
|
||||
frame({
|
||||
'run_id': 'run_new',
|
||||
'run': _run(
|
||||
session,
|
||||
'run_new',
|
||||
body is Map ? '${body['command'] ?? ''}' : '',
|
||||
180,
|
||||
exitCode: 0,
|
||||
duration: 37,
|
||||
),
|
||||
}),
|
||||
];
|
||||
case 'chat_shell_stop':
|
||||
final run = _runs(session).last
|
||||
..['status'] = 'stopped'
|
||||
..['duration_ms'] = 9100;
|
||||
return [
|
||||
frame({'run_id': run['id'], 'run': run}),
|
||||
];
|
||||
}
|
||||
return const [];
|
||||
}
|
||||
|
||||
const _tests = [
|
||||
'RunStreamsToEveryWatcherAndPersists',
|
||||
'RunLimitsAndRefusals',
|
||||
'ShareQueuesAnOrdinaryPrompt',
|
||||
'RetainsBoundedTail',
|
||||
'ShutdownAndRestartInterrupt',
|
||||
'OutputKeepsCharactersWhole',
|
||||
];
|
||||
@@ -16,12 +16,15 @@
|
||||
// `?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_new_session_fixture.dart';
|
||||
import 'chat_question_fixture.dart';
|
||||
import 'chat_shell_fixture.dart';
|
||||
import 'chat_scroll_fixture.dart';
|
||||
|
||||
Map<String, String> _params = const {};
|
||||
@@ -35,6 +38,7 @@ void configurePerfFixture(Map<String, String> params) {
|
||||
);
|
||||
configureChatScrollFixture(params);
|
||||
configureChatQuestionFixture(params);
|
||||
configureChatShellFixture(params);
|
||||
}
|
||||
|
||||
int get _hits => int.tryParse(_params['hits'] ?? '') ?? 0;
|
||||
@@ -126,6 +130,8 @@ bool get _scrollVariety => ['msgs', 'rich', 'older'].any(_params.containsKey);
|
||||
List<JsonMap> perfChatFollowUps(JsonMap request) {
|
||||
final answered = chatQuestionFollowUps(request);
|
||||
if (answered.isNotEmpty) return answered;
|
||||
final shell = chatShellFollowUps(request);
|
||||
if (shell.isNotEmpty) return shell;
|
||||
final quota = _params['quota'];
|
||||
if (_chats == 0 || quota == null || request['type'] != 'chat_subscribe') {
|
||||
return const [];
|
||||
@@ -226,6 +232,8 @@ JsonMap? perfChatReply(JsonMap request) {
|
||||
if (_chats == 0) return null;
|
||||
final question = chatQuestionReply(request);
|
||||
if (question != null) return question;
|
||||
final shell = chatShellReply(request);
|
||||
if (shell != null) return shell;
|
||||
final id = request['id'];
|
||||
switch ('${request['type']}') {
|
||||
case 'chat_sessions':
|
||||
|
||||
Reference in New Issue
Block a user