Draw chat shell runs in an xterm terminal that takes typed input

The card's output area is now an xterm.dart emulator kept per run by the
controller: it is fed the raw stream in order, takes typing and paste while
the command runs (with a key toolbar and a soft-keyboard field on touch
platforms), resizes the process to its layout, opens printed links, shrinks
finished runs to their output and opens full screen. A reconnect resumes from
the byte the card holds; Copy output copies the server's plain text.
This commit is contained in:
2026-11-09 20:08:33 +00:00
parent 355b722a1d
commit 89882d90f3
20 changed files with 1428 additions and 201 deletions
@@ -2,9 +2,11 @@ import 'dart:async';
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/chat/conversation/chat_draft_store.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:xterm/xterm.dart';
import '../conversation/chat_thread_fixtures.dart';
@@ -15,6 +17,9 @@ class ShellGateway implements ApiGateway {
final _frames = StreamController<JsonMap>.broadcast();
List<JsonMap> runs = const [];
String? refusal;
/// The reply to a `chat_shell_run_output` that resumes from an offset.
JsonMap? resumeReply;
int _serial = 0;
@override
@@ -47,6 +52,9 @@ class ShellGateway implements ApiGateway {
),
};
case 'chat_shell_run_output':
if (body['after'] != null && resumeReply != null) {
return {'chat_shell_run': resumeReply};
}
return {
'chat_shell_run': runs.firstWhere((r) => r['id'] == body['run_id']),
};
@@ -84,6 +92,9 @@ JsonMap shellRecord(
int? exitCode,
String output = '',
int durationMs = 0,
bool terminal = false,
String text = '',
int outputStart = 0,
}) => {
'id': id,
'session_id': 's',
@@ -95,9 +106,27 @@ JsonMap shellRecord(
'ended_at': ?(status == 'running' ? null : 1000 + durationMs),
'duration_ms': durationMs,
'output': output,
'output_bytes': output.length,
'output_start': outputStart,
'output_bytes': outputStart + output.length,
if (terminal) ...{'terminal': true, 'cols': 100, 'rows': 30},
if (text.isNotEmpty) 'text': text,
};
/// The text the run card's terminal draws, one row per line, trailing blank
/// rows dropped.
String terminalText(WidgetTester tester, {int index = 0}) {
final view = tester.widgetList<TerminalView>(find.byType(TerminalView));
final buffer = view.elementAt(index).terminal.buffer;
final lines = [
for (var y = 0; y < buffer.height; y++)
buffer.lines[y].getText().trimRight(),
];
while (lines.isNotEmpty && lines.last.isEmpty) {
lines.removeLast();
}
return lines.join('\n');
}
Widget shellThread(ShellGateway gateway, {bool cupertino = false}) {
final thread = ChatThreadView(
gateway: gateway,