Files
pipelines/app/lib/features/chat/shell/chat_shell_runs_dismissal.dart
T
alan cf9f71f27c Show dismissed commands as an answer footer chip; move Copy to the left gutter
Dismissed shell runs leave the transcript and fold into a "N commands"
chip in the footer of the first answer at or after each run (the last
answer for newer runs, or a row of its own without any answer). The chip
opens the turn sheet (wide) or a full-screen page (narrow) listing the
commands; each opens its output read-only with Copy output, Send to agent
and Restore.

On a wide conversation the answer's Copy button moves out of the footer
into a 48 px gutter left of the reading column (chatCopyGutter), shown on
hover or focus on desktops and always on touch; narrow widths keep it in
the footer.
2026-11-09 23:47:14 +00:00

93 lines
3.1 KiB
Dart

part of 'chat_shell_runs_controller.dart';
/// Dismissing finished command cards for every client of the chat, the
/// dismissed runs the server keeps (the transcript's command history), and
/// Restore, which puts a card back.
extension ChatShellRunsDismissal on ChatShellRunsController {
/// The dismissed runs this copy holds, oldest first.
List<ChatShellRun> get dismissedRuns =>
[..._dismissed.values]
..sort((a, b) => a.startedAt.compareTo(b.startedAt));
/// One dismissed run, or null once it was restored (or aged out).
ChatShellRun? dismissedRun(String id) => _dismissed[id];
/// Dismisses finished runs [ids] for every client of the chat: their cards
/// go at once into the command history and come back (with the refusal) if
/// the server refuses. Returns the refusal, or null. A running command is
/// never dismissed.
Future<String?> dismiss(List<String> ids) async {
final removed = [
for (final id in ids)
if (_runs[id] case final run? when !run.running) run,
];
if (removed.isEmpty) return null;
for (final run in removed) {
_remove(run.id);
}
_changed(membership: true);
try {
await _repository.dismiss(sessionId, [for (final r in removed) r.id]);
return null;
} catch (error) {
if (_disposed) return null;
final reason = _reason(error);
for (final run in removed) {
_gone.remove(run.id);
_dismissed.remove(run.id);
_runs[run.id] = run;
_errors[run.id] = reason;
}
_changed(membership: true);
return reason;
}
}
/// Puts dismissed runs [ids] back in the transcript as cards, for every
/// client. Returns the refusal, or null.
Future<String?> restore(List<String> ids) async {
try {
final restored = await _repository.restore(sessionId, ids);
if (_disposed) return null;
for (final run in restored) {
_gone.remove(run.id);
_dismissed.remove(run.id);
final held = _runs[run.id];
final keep = held != null && held.outputEnd >= run.outputEnd;
_runs[run.id] = keep ? held.withLifecycle(run) : run;
if (!keep) terminals.replaced(run);
}
_changed(membership: true);
return null;
} catch (error) {
return _reason(error);
}
}
/// The dismissed run [id] with everything the server kept of its output
/// and its plain-text rendering, for the history's read-only output view.
Future<ChatShellRun> fullOutput(String id) =>
_repository.output(sessionId, id);
/// Folds a readback's dismissed runs into the history. Runs this copy
/// dismissed but the readback does not list yet stay held.
void _holdDismissed(List<ChatShellRun> runs) {
for (final run in runs) {
_gone.add(run.id);
_dismissed[run.id] = run;
}
}
/// Takes [id]'s card out of the transcript; a held copy moves into the
/// command history.
void _remove(String id) {
if (_runs[id] case final run?) _dismissed[id] = run;
_gone.add(id);
_runs.remove(id);
_errors.remove(id);
_shares.remove(id);
_stopping.remove(id);
terminals.removed(id);
}
}