App: dark-aware HTML views, run cards, changed/missing file notes, one card width, dense diff rows

show_html documents that declare dark support follow the app theme; others
stay light. Tool description and skill docs say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 19:54:58 +00:00
parent d204ce3187
commit f02ff56dfe
27 changed files with 1086 additions and 61 deletions
+17 -7
View File
@@ -53,6 +53,7 @@ import '../shell/windows/window_kind.dart';
import '../shell/windows/window_manager.dart';
import '../shell/windows/window_store.dart';
import 'app_terminals.dart';
import '../features/chat/chat_run_opener.dart';
import '../features/chat/chat_runtime.dart';
import '../features/changes/windows/diff_windows.dart';
import '../features/chat/windows/chat_windows.dart';
@@ -736,13 +737,22 @@ class _PipelinesAppState extends State<PipelinesApp>
const SharedPreferencesWalkthroughStore();
@override
Widget build(BuildContext context) => widget.servers == null
? MyApp.router(routerConfig: _config)
: ServerContext(
connections: widget.servers!,
serverId: widget.serverId,
child: MyApp.router(routerConfig: _config),
);
Widget build(BuildContext context) {
// A chat's run card (show_run) opens the run's detail.
final app = ChatRunOpener(
openRun: _openRunFromChat,
child: MyApp.router(routerConfig: _config),
);
return widget.servers == null
? app
: ServerContext(
connections: widget.servers!,
serverId: widget.serverId,
child: app,
);
}
void _openRunFromChat(int id) => _delegate.goTo(AppRoute.run(id));
/// Open a result through the exact identity the hit records. An unresolvable
/// hit navigates nowhere: the screen already presents it read-only rather than
@@ -0,0 +1,63 @@
/// How a recorded HTML document follows the app's light or dark theme.
///
/// A document opts into dark mode by saying it supports it: a
/// `prefers-color-scheme` media query, a `color-scheme` declaration (CSS or
/// `<meta>`) or the `light-dark()` colour function. Such a document is shown
/// in the app's scheme; any other document keeps the light scheme on a white
/// page, because its own colours were chosen for that and may be unreadable
/// on a dark canvas.
///
/// The frame's browser does not reliably pass the app's preference into a
/// sandboxed document (and a phone's web view knows only the system's), so
/// the scheme is written into the document itself: a leading
/// `<meta name="color-scheme">` naming only the chosen scheme (the browser
/// paints its default canvas and text, form controls and `light-dark()` in
/// it), and each `prefers-color-scheme` query is replaced by one that is
/// always true or always false for that scheme.
library;
final RegExp _darkAware = RegExp(
r'prefers-color-scheme|color-scheme|light-dark\(',
caseSensitive: false,
);
final RegExp _schemeQuery = RegExp(
r'\(\s*prefers-color-scheme\s*:\s*(light|dark)\s*\)',
caseSensitive: false,
);
final RegExp _headOpen = RegExp(r'<head(\s[^>]*)?>', caseSensitive: false);
/// A media feature that always holds, and one that never does (a negative
/// length makes the query invalid, which evaluates to false).
const String _always = '(min-width: 0px)';
const String _never = '(max-width: -1px)';
/// Whether [html] declares that it styles itself for dark mode.
bool artifactHtmlSupportsDark(String html) => _darkAware.hasMatch(html);
/// The colour scheme [html] is shown in: `dark` only when the app is dark
/// ([dark]) and the document supports it, else `light`.
String artifactHtmlScheme(String html, {required bool dark}) =>
dark && artifactHtmlSupportsDark(html) ? 'dark' : 'light';
/// [html] fixed to its [artifactHtmlScheme] (see the library comment).
String artifactHtmlForScheme(String html, {required bool dark}) {
final scheme = artifactHtmlScheme(html, dark: dark);
final queried = html.replaceAllMapped(
_schemeQuery,
(match) => match[1]!.toLowerCase() == scheme ? _always : _never,
);
final meta = '<meta name="color-scheme" content="$scheme">';
final head = _headOpen.firstMatch(queried);
if (head != null) {
return queried.replaceRange(head.end, head.end, meta);
}
// Before everything else, but after a doctype: content ahead of the
// doctype would put the document in quirks mode.
final doctype = _doctype.firstMatch(queried);
final at = doctype?.end ?? 0;
return queried.replaceRange(at, at, meta);
}
final RegExp _doctype = RegExp(r'^\s*<!doctype[^>]*>', caseSensitive: false);
@@ -1,5 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import '../domain/artifact_html_theme.dart';
import 'artifact_fullscreen.dart';
import 'artifact_html_view_native.dart'
if (dart.library.js_interop) 'artifact_html_view_web.dart'
@@ -16,11 +17,19 @@ typedef ArtifactHtmlBuilder =
/// live frame. The mobile web views pinch natively and offer none.
const bool artifactHtmlZoomButtons = impl.inertHtmlZoomButtons;
/// Whether a recorded HTML document at [context] is shown in the dark scheme
/// (when it supports one): the app's own theme, not the system's.
bool artifactHtmlDark(BuildContext context) =>
Theme.of(context).brightness == Brightness.dark;
/// Renders a recorded HTML document inertly: on the web in an iframe whose
/// empty `sandbox` blocks scripts, forms, popups and navigation; on Android and
/// iOS in a web view with JavaScript disabled and navigation refused. The
/// document never runs code with the app's origin or credentials.
///
/// A document that supports dark mode follows the app's theme
/// ([artifactHtmlForScheme]); any other keeps a white page.
///
/// The preview stops at the floating bars instead of passing behind them: on
/// the web the iframe is a platform view that takes every click over its
/// area, even where a bar is drawn on top, which left the viewer's actions
@@ -40,6 +49,7 @@ Widget defaultArtifactHtml(BuildContext context, String html) {
html: html,
interactive: fullscreen != null,
zoom: fullscreen?.htmlZoom,
dark: artifactHtmlDark(context),
),
),
);
@@ -4,6 +4,7 @@ import 'package:flutter/widgets.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../domain/artifact_html_links.dart';
import '../domain/artifact_html_theme.dart';
import 'artifact_external_open.dart';
/// The mobile web views pinch-zoom natively (Android's built-in zoom, which
@@ -29,10 +30,15 @@ class InertHtmlView extends StatefulWidget {
this.interactive = false,
this.zoom,
this.openExternal = openArtifactExternally,
this.dark = false,
});
final String html;
/// Whether the app is in its dark theme: a document that supports dark mode
/// is loaded in it ([artifactHtmlForScheme]).
final bool dark;
/// Opens a link's http(s)/mailto address outside the artifact.
final ArtifactExternalOpen openExternal;
final bool interactive;
@@ -66,7 +72,9 @@ class _InertHtmlViewState extends State<InertHtmlView> {
onNavigationRequest: _decide,
),
)
..loadHtmlString(widget.html);
..loadHtmlString(_document);
String get _document => artifactHtmlForScheme(widget.html, dark: widget.dark);
/// Links: a place in the document scrolls there; an http(s)/mailto address
/// opens in the system's handler, never inside this view; anything else
@@ -91,9 +99,9 @@ class _InertHtmlViewState extends State<InertHtmlView> {
@override
void didUpdateWidget(covariant InertHtmlView oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.html != widget.html) {
if (oldWidget.html != widget.html || oldWidget.dark != widget.dark) {
_loaded = false;
_controller.loadHtmlString(widget.html);
_controller.loadHtmlString(_document);
}
}
@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:web/web.dart' as web;
import '../domain/artifact_html_theme.dart';
import 'artifact_html_links_web.dart';
/// The frame's document cannot be pinched: a pinch over it is a page zoom,
@@ -23,6 +24,10 @@ const bool inertHtmlZoomButtons = true;
/// document reflows and still scrolls inside it. In the app, Chrome returns
/// the frame's document to its top when a zoom step resizes it.
///
/// The document follows the app's theme ([dark]) when it supports dark mode
/// ([artifactHtmlForScheme]); the frame's own `color-scheme` matches, so the
/// browser paints the page's canvas in that scheme rather than always white.
///
/// While another route covers this one (a menu, a sheet) the frame stops
/// taking pointers: a platform view takes every click over its area, even
/// where Flutter draws that menu on top.
@@ -32,10 +37,14 @@ class InertHtmlView extends StatefulWidget {
required this.html,
this.interactive = false,
this.zoom,
this.dark = false,
});
final String html;
/// Whether the app is in its dark theme.
final bool dark;
/// The full-screen view's frame. Pointers already reach the frame directly
/// on the web, inline as in full screen.
final bool interactive;
@@ -91,16 +100,20 @@ class _InertHtmlViewState extends State<InertHtmlView> {
_covered = covered;
_style();
}
final scheme = artifactHtmlScheme(widget.html, dark: widget.dark);
return HtmlElementView.fromTagName(
key: ValueKey<int>(widget.html.hashCode),
key: ValueKey<(int, String)>((widget.html.hashCode, scheme)),
tagName: 'iframe',
onElementCreated: (element) {
final frame = element as web.HTMLIFrameElement;
frame.setAttribute('sandbox', artifactHtmlSandbox);
frame.srcdoc = artifactHtmlWithInertLinks(widget.html).toJS;
frame.srcdoc = artifactHtmlWithInertLinks(
artifactHtmlForScheme(widget.html, dark: widget.dark),
).toJS;
frame.style
..border = 'none'
..backgroundColor = 'white';
..colorScheme = scheme
..backgroundColor = scheme == 'dark' ? 'Canvas' : 'white';
_frame = frame;
_style();
},
@@ -100,19 +100,42 @@ class StageCaptureSection extends StatelessWidget {
}
/// One changed file: its kind, path and line counts; tapping opens its diff.
/// [dense] draws it on one compact line (the path, then the counts), for a
/// card that lists many files in little space.
class ChangeFileRow extends StatelessWidget {
const ChangeFileRow({super.key, required this.file, required this.onOpen});
const ChangeFileRow({
super.key,
required this.file,
required this.onOpen,
this.dense = false,
});
final FileChange file;
final ValueChanged<FileChange> onOpen;
final bool dense;
@override
Widget build(BuildContext context) {
final mono = nativeDiffText(DefaultTextStyle.of(context).style);
final leading = Icon(changeKindIcon(file.kind));
final title = Text(file.path, style: mono);
final subtitle = ChangeStatText(changeFileMeta(file));
const trailing = Icon(Icons.chevron_right);
final leading = Icon(changeKindIcon(file.kind), size: dense ? 20 : null);
final Widget title = dense
? Row(
children: [
Expanded(
child: Text(
file.path,
style: mono,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 12),
ChangeStatText(changeFileMeta(file)),
],
)
: Text(file.path, style: mono);
final subtitle = dense ? null : ChangeStatText(changeFileMeta(file));
final trailing = dense ? null : const Icon(Icons.chevron_right);
return Semantics(
container: true,
button: true,
@@ -124,6 +147,9 @@ class ChangeFileRow extends StatelessWidget {
excludeSemantics: true,
onTap: () => onOpen(file),
child: ListTile(
dense: dense,
visualDensity: dense ? VisualDensity.compact : null,
minLeadingWidth: dense ? 20 : null,
leading: leading,
title: title,
subtitle: subtitle,
@@ -0,0 +1,17 @@
import 'package:flutter/widgets.dart';
/// Opens a run's detail from inside a chat (a `show_run` card). The app shell
/// provides it above every chat surface; without one a run card is not
/// activatable.
class ChatRunOpener extends InheritedWidget {
const ChatRunOpener({super.key, required this.openRun, required super.child});
final ValueChanged<int> openRun;
static ValueChanged<int>? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ChatRunOpener>()?.openRun;
@override
bool updateShouldNotify(ChatRunOpener oldWidget) =>
openRun != oldWidget.openRun;
}
@@ -12,6 +12,8 @@ class ChatShownDiff {
required this.base,
required this.baseCommit,
required this.head,
this.headRevision = '',
this.paths = const [],
required this.committedOnly,
required this.files,
required this.additions,
@@ -29,6 +31,12 @@ class ChatShownDiff {
base: _text(body['base']),
baseCommit: _text(body['base_commit']),
head: _text(body['head']),
headRevision: _text(body['head_revision']),
paths: [
if (body['paths'] case final List paths)
for (final path in paths)
if (_text(path).isNotEmpty) _text(path),
],
committedOnly: body['committed_only'] == true,
files: _count(body['files']),
additions: _count(body['additions']),
@@ -43,6 +51,13 @@ class ChatShownDiff {
final String base;
final String baseCommit;
final String head;
/// The revision compared instead of the work tree (`show_diff` head), or
/// empty.
final String headRevision;
/// The paths or globs the comparison is limited to; empty for all.
final List<String> paths;
final bool committedOnly;
final int files;
final int additions;
@@ -57,14 +72,25 @@ class ChatShownDiff {
return parts.isEmpty ? repo : parts.last;
}
/// What was compared, in words: the branch against its base and whether
/// uncommitted work is included.
/// What was compared, in words: the branch (or the given revision) against
/// its base, whether uncommitted work is included, and the paths it is
/// limited to.
String get comparison {
final limited = paths.isEmpty
? ''
: ' · ${paths.length <= 3 ? paths.join(', ') : '${paths.take(3).join(', ')} +${paths.length - 3}'}';
return '${_compared()}$limited';
}
String _compared() {
final where = repoName.isEmpty ? '' : '$repoName · ';
if (headRevision.isNotEmpty) {
return '$where$headRevision vs ${base.isEmpty ? 'HEAD' : base}';
}
final head = this.head.isEmpty ? 'HEAD' : this.head;
final against = base.isEmpty
? (baseCommit.isEmpty ? 'no commits yet' : 'uncommitted changes')
: '$head vs $base${committedOnly ? ' · committed only' : ' · with uncommitted work'}';
final where = repoName.isEmpty ? '' : '$repoName · ';
return base.isEmpty ? '$where$head · $against' : '$where$against';
}
@@ -2,15 +2,18 @@ import '../../../core/api_gateway.dart';
import 'chat_transcript.dart';
/// Entries a chat's model showed the operator through the Pipelines tools
/// (`show_file`, `show_image`, `show_html`, `show_diff`, `notify`).
/// (`show_file`, `show_image`, `show_html`, `show_diff`, `show_run`,
/// `notify`).
///
/// The server keeps them per chat, outside the harness transcript: the
/// `chat_subscribe` reply carries the retained list (oldest first) and a
/// pushed `chat_shown` frame carries each new or updated item. Items are keyed
/// by `id`; a later copy replaces the held one in place.
/// by `id`; a later copy replaces the held one in place. The server sends one
/// when the model replaces a card (`replace`) and when a shown run changes;
/// either keeps the item's `created_at`, so the card stays where it was.
/// The recorded kinds.
const chatShownKinds = {'file', 'image', 'html', 'diff', 'notify'};
const chatShownKinds = {'file', 'image', 'html', 'diff', 'run', 'notify'};
/// The transcript row kind an item is drawn as.
const String chatShownRowKind = 'shown';
@@ -52,7 +55,7 @@ List<JsonMap> mergeChatShownItems(
/// `pipelines/show_file`.
final RegExp _pipelinesTool = RegExp(
r'^(?:mcp__pipelines__|pipelines_|pipelines/)'
r'(?:show_file|show_image|show_html|show_diff|notify)$',
r'(?:show_file|show_image|show_html|show_diff|show_run|notify)$',
);
/// Whether [part] is a call of a Pipelines tool whose result the transcript
@@ -0,0 +1,72 @@
import '../../../core/api_gateway.dart';
import '../../pipelines/pipeline_format.dart' show formatDuration;
import '../../runs/domain/run_events.dart' show isTerminalRunStatus;
/// A `show_run` item's run, as the server records it
/// (`internal/protocol/chat_shown.go` ChatShownRunBody). The server pushes the
/// item again whenever the run changes, so this is always its latest state.
class ChatShownRun {
const ChatShownRun({
required this.id,
required this.pipeline,
required this.title,
required this.status,
required this.outcome,
required this.currentStage,
required this.startedAt,
required this.finishedAt,
});
/// The run of a `run` item, or null for any other item or a malformed one.
static ChatShownRun? of(JsonMap item) {
final body = item['run'];
if (item['kind'] != 'run' || body is! Map) return null;
final id = body['id'];
if (id is! num || id <= 0) return null;
return ChatShownRun(
id: id.toInt(),
pipeline: _text(body['pipeline']),
title: _text(body['title']),
status: _text(body['status']),
outcome: _text(body['outcome']),
currentStage: _text(body['current_stage']),
startedAt: _millis(body['started_at']),
finishedAt: _millis(body['finished_at']),
);
}
final int id;
final String pipeline;
final String title;
final String status;
final String outcome;
final String currentStage;
final int? startedAt;
final int? finishedAt;
/// Whether the run has ended (succeeded, failed, canceled, interrupted).
bool get finished => isTerminalRunStatus(status);
/// The status in words: the outcome of a finished run when it says more.
String get statusLabel {
final word = status.isEmpty ? 'unknown' : status;
final label = '${word[0].toUpperCase()}${word.substring(1)}';
return finished && outcome.isNotEmpty && outcome != status
? '$label · $outcome'
: label;
}
/// How long it ran, or has been running at [now] (epoch milliseconds); null
/// without a start time.
String? duration(int now) {
final start = startedAt;
if (start == null) return null;
final end = finishedAt ?? (finished ? null : now);
if (end == null) return null;
return formatDuration((end - start) ~/ 1000);
}
}
String _text(Object? value) => '${value ?? ''}'.trim();
int? _millis(Object? value) => value is num && value > 0 ? value.toInt() : null;
@@ -8,6 +8,7 @@ import 'chat_shown_file_card.dart';
import 'chat_shown_html_card.dart';
import 'chat_shown_link_image.dart';
import 'chat_shown_notify_row.dart';
import 'chat_shown_run_card.dart';
/// One transcript row of kind `shown` ([withChatShownItems]): what the model
/// showed through a Pipelines tool, drawn by its recorded kind. [endpoint] is
@@ -37,6 +38,7 @@ class ChatShownCard extends StatelessWidget {
'notify' => ChatShownNotifyRow(item: item),
'html' => ChatShownHtmlCard(item: item, htmlBuilder: htmlBuilder),
'diff' => ChatShownDiffCard(item: item),
'run' => ChatShownRunCard(item: item),
'image' when path.isEmpty => ChatShownLinkImage(
item: item,
openExternal: viewer.openExternal,
@@ -41,7 +41,6 @@ class _ChatShownDiffCardState extends State<ChatShownDiffCard> {
: files.take(chatShownDiffPreviewFiles).toList();
return ChatShownSurface(
label: 'Shown diff $title',
maxWidth: 720,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -92,6 +91,7 @@ class _ChatShownDiffCardState extends State<ChatShownDiffCard> {
ChangeFileRow(
key: ValueKey<String>('chat-shown-diff-file-${file.path}'),
file: file,
dense: true,
onOpen: (file) =>
showFileDiffViewer(context, file, files: files),
),
@@ -32,6 +32,26 @@ DirectoryEntry chatShownEntry(JsonMap item) {
);
}
/// What happened to a shown file since: the server compares the live file
/// with what was shown (or checks its snapshot still exists) when it lists a
/// chat's items.
enum ChatShownFileState { current, changed, missing }
ChatShownFileState chatShownFileState(JsonMap item) =>
switch ('${item['state'] ?? ''}') {
'changed' => ChatShownFileState.changed,
'missing' => ChatShownFileState.missing,
_ => ChatShownFileState.current,
};
/// The https address a fetched web image came from, or empty.
String chatShownSourceUrl(JsonMap item) {
final uri = Uri.tryParse('${item['url'] ?? ''}'.trim());
return uri != null && uri.scheme == 'https' && uri.host.isNotEmpty
? uri.toString()
: '';
}
/// The largest logical height an inline shown image takes.
const double chatShownImageMaxHeight = 280;
@@ -39,6 +59,12 @@ const double chatShownImageMaxHeight = 280;
/// card with its kind glyph, name and size, and the first lines of a text
/// document. Activating either opens the Files viewer (preview and download)
/// over the chat machine's `/files` endpoint ([endpoint]).
///
/// A small file is a snapshot taken when it was shown, so later edits do not
/// change the card. A larger one is the live file: the card says when it has
/// changed since it was shown, and when it (or a snapshot) no longer exists,
/// in which case nothing is loaded or opened. A web image the server fetched
/// names the address it came from.
class ChatShownFileCard extends StatelessWidget {
const ChatShownFileCard({
super.key,
@@ -54,17 +80,25 @@ class ChatShownFileCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final entry = chatShownEntry(item);
final urls = resolveFileUrls(endpoint, entry.path);
final state = chatShownFileState(item);
final missing = state == ChatShownFileState.missing;
final urls = missing ? null : resolveFileUrls(endpoint, entry.path);
final image = isThumbnailFile(entry.name) && urls != null;
final source = chatShownSourceUrl(item);
final kind = artifactKindLabel(
artifactKind(fileContentType(entry.name), entry.name),
);
final title = chatShownTitle(item, entry.name);
final subtitle = [
if (title != entry.name) entry.name,
kind,
fileSizeLabel(entry.size),
].join(' · ');
final title = chatShownTitle(
item,
source.isEmpty ? entry.name : Uri.parse(source).host,
);
final subtitle = source.isNotEmpty
? source
: [
if (title != entry.name) entry.name,
kind,
fileSizeLabel(entry.size),
].join(' · ');
void open() => viewer.open(context, endpoint: endpoint, entry: entry);
final heading = Padding(
padding: const EdgeInsets.all(12),
@@ -74,12 +108,26 @@ class ChatShownFileCard extends StatelessWidget {
leading: image
? null
: Icon(
fileIcon(entry),
missing ? Icons.hide_source_outlined : fileIcon(entry),
size: 32,
color: chatShownSecondary(context),
),
),
);
final note = switch (state) {
ChatShownFileState.current => null,
ChatShownFileState.changed => (
Icons.update,
'Changed since shown',
'The file has changed since it was shown; opening it shows the '
'current version.',
),
ChatShownFileState.missing => (
Icons.hide_source_outlined,
'No longer exists',
'The file was moved or deleted after it was shown.',
),
};
final body = Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -91,6 +139,8 @@ class ChatShownFileCard extends StatelessWidget {
fetch: viewer.fetch,
),
heading,
if (note != null)
_StateNote(icon: note.$1, label: note.$2, detail: note.$3),
if (!image && urls != null)
ChatShownFileLines(
entry: entry,
@@ -99,12 +149,53 @@ class ChatShownFileCard extends StatelessWidget {
),
],
);
final isImage = image || '${item['kind']}' == 'image';
return ChatShownSurface(
label: image ? 'Shown image $title' : 'Shown file $title',
child: Semantics(
button: true,
onTap: open,
child: InkWell(onTap: open, child: body),
label: isImage ? 'Shown image $title' : 'Shown file $title',
child: missing
? body
: Semantics(
button: true,
onTap: open,
child: InkWell(onTap: open, child: body),
),
);
}
}
/// The line under a shown file's heading that says it changed or is gone.
class _StateNote extends StatelessWidget {
const _StateNote({
required this.icon,
required this.label,
required this.detail,
});
final IconData icon;
final String label;
final String detail;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final color = theme.colorScheme.tertiary;
return Tooltip(
message: detail,
child: Padding(
key: const Key('chat-shown-file-state'),
padding: const EdgeInsetsDirectional.fromSTEB(12, 0, 12, 12),
child: Row(
children: [
Icon(icon, size: 18, color: color),
const SizedBox(width: 8),
Expanded(
child: Text(
label,
style: theme.textTheme.labelMedium?.copyWith(color: color),
),
),
],
),
),
);
}
@@ -138,7 +229,11 @@ class _ChatShownPicture extends StatelessWidget {
return ConstrainedBox(
constraints: const BoxConstraints(maxHeight: chatShownImageMaxHeight),
child: Image(
image: ResizeImage.resizeIfNeeded((560 * ratio).round(), null, source),
image: ResizeImage.resizeIfNeeded(
(chatShownCardMaxWidth * ratio).round(),
null,
source,
),
fit: BoxFit.contain,
semanticLabel: name,
loadingBuilder: (_, child, progress) =>
@@ -73,7 +73,6 @@ class ChatShownHtmlCard extends StatelessWidget {
);
return ChatShownSurface(
label: 'Shown view $title',
maxWidth: 720,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -0,0 +1,151 @@
import 'dart:async';
import 'package:flutter/material.dart';
import '../../../../../core/api_gateway.dart';
import '../../../chat_run_opener.dart';
import '../../../domain/chat_shown_run.dart';
import 'chat_shown_surface.dart';
/// The glyph of a run status.
IconData chatShownRunIcon(String status) => switch (status) {
'succeeded' => Icons.check_circle_outline,
'failed' => Icons.error_outline,
'canceled' => Icons.cancel_outlined,
'interrupted' => Icons.pause_circle_outline,
'waiting' => Icons.front_hand_outlined,
'queued' => Icons.schedule,
_ => Icons.play_circle_outline,
};
Color _statusColor(ColorScheme colors, String status) => switch (status) {
'succeeded' => colors.primary,
'failed' || 'interrupted' => colors.error,
'waiting' => colors.tertiary,
_ => colors.onSurfaceVariant,
};
/// A pipeline run the model showed through `show_run`: the pipeline, the
/// run's title, its status, current stage and how long it has run. The server
/// pushes the item again as the run changes; while it runs the duration ticks
/// here. Activating it opens the run ([ChatRunOpener]).
class ChatShownRunCard extends StatefulWidget {
const ChatShownRunCard({super.key, required this.item, this.now});
final JsonMap item;
/// The clock, for tests.
final DateTime Function()? now;
@override
State<ChatShownRunCard> createState() => _ChatShownRunCardState();
}
class _ChatShownRunCardState extends State<ChatShownRunCard> {
Timer? _tick;
int get _now => (widget.now?.call() ?? DateTime.now()).millisecondsSinceEpoch;
@override
void initState() {
super.initState();
_schedule();
}
@override
void didUpdateWidget(covariant ChatShownRunCard oldWidget) {
super.didUpdateWidget(oldWidget);
_schedule();
}
/// Ticks once a second while the run has not finished, so its duration
/// keeps counting; a finished run's card is static.
void _schedule() {
final running = ChatShownRun.of(widget.item)?.finished == false;
if (running && _tick == null) {
_tick = Timer.periodic(const Duration(seconds: 1), (_) {
if (mounted) setState(() {});
});
} else if (!running) {
_tick?.cancel();
_tick = null;
}
}
@override
void dispose() {
_tick?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
final run = ChatShownRun.of(widget.item);
if (run == null) return const SizedBox.shrink();
final theme = Theme.of(context);
final colors = theme.colorScheme;
final secondary = chatShownSecondary(context);
final title = chatShownTitle(
widget.item,
run.title.isEmpty ? 'Run ${run.id}' : run.title,
);
final pipeline = run.pipeline.isEmpty ? 'Run' : run.pipeline;
final duration = run.duration(_now);
final status = run.statusLabel;
final facts = [
'#${run.id}',
if (!run.finished && run.currentStage.isNotEmpty) run.currentStage,
?duration,
].join(' · ');
final open = ChatRunOpener.maybeOf(context);
final body = Padding(
padding: const EdgeInsetsDirectional.fromSTEB(12, 10, 12, 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
ChatShownHeading(
title: title,
subtitle: pipeline,
leading: Icon(Icons.play_lesson_outlined, color: secondary),
trailing: open == null
? null
: Icon(Icons.chevron_right, color: secondary),
),
const SizedBox(height: 8),
Wrap(
spacing: 8,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Chip(
key: const Key('chat-shown-run-status'),
avatar: Icon(
chatShownRunIcon(run.status),
color: _statusColor(colors, run.status),
),
label: Text(status),
visualDensity: VisualDensity.compact,
),
Text(
facts,
key: const Key('chat-shown-run-facts'),
style: theme.textTheme.bodySmall?.copyWith(color: secondary),
),
],
),
],
),
);
return ChatShownSurface(
label: 'Shown run $title',
child: open == null
? body
: Semantics(
button: true,
onTap: () => open(run.id),
child: InkWell(onTap: () => open(run.id), child: body),
),
);
}
}
@@ -12,20 +12,18 @@ String chatShownTitle(JsonMap item, String fallback) {
return title.isEmpty ? fallback : title;
}
/// The width every shown card (file, image, view, diff, run) is held to, so
/// the entries of one transcript line up whatever their kind.
const double chatShownCardMaxWidth = 720;
/// The outlined card a shown entry sits in, on the agent's side of the
/// transcript, at most [maxWidth] wide.
/// transcript, at most [chatShownCardMaxWidth] wide.
class ChatShownSurface extends StatelessWidget {
const ChatShownSurface({
super.key,
required this.label,
required this.child,
this.maxWidth = 560,
});
const ChatShownSurface({super.key, required this.label, required this.child});
/// The entry's accessible name ("Shown file", "Shown view", ...).
final String label;
final Widget child;
final double maxWidth;
@override
Widget build(BuildContext context) {
@@ -43,7 +41,7 @@ class ChatShownSurface extends StatelessWidget {
child: Align(
alignment: AlignmentDirectional.centerStart,
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxWidth),
constraints: const BoxConstraints(maxWidth: chatShownCardMaxWidth),
child: card,
),
),
+13 -4
View File
@@ -140,10 +140,19 @@ that row stays visible because it can contain other code.
operator's scheduled prompt, a follow-up that is not due yet does not hold
the FIFO queue: `chatQueueHead` skips it, so the operator's prompts go
through.
- **HTML theme.** The client passes the app's brightness into the sandbox
(`color-scheme` on the frame plus a `color-scheme` meta in the document), so
`prefers-color-scheme` follows the operator's theme; the tool description
tells the model to style for both.
- **HTML theme.** A document that declares dark support
(`prefers-color-scheme`, `color-scheme` or `light-dark()`) is shown in the
app's theme (not the system's): `artifact_html_theme.dart` inserts a
`color-scheme` meta naming that scheme and rewrites each
`prefers-color-scheme` query to always/never match, and the web frame gets the
same `color-scheme` (canvas `Canvas` when dark). Any other document stays
light on white, since its colours were chosen for that. The tool description
tells the model so.
- **Cards.** Every shown card is held to one width (`chatShownCardMaxWidth`,
720). Diff file rows are one dense line (path, counts). A run card shows
pipeline, title, status chip, `#id · stage · duration` (ticking while it
runs) and opens the run. File cards show "Changed since shown" / "No longer
exists" (a missing file loads and opens nothing).
## Per-harness registration
@@ -0,0 +1,83 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_html_theme.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_html_view.dart';
const _aware = '''<!doctype html><html><head><style>
body{background:#fff;color:#111}
@media (prefers-color-scheme: dark){body{background:#111;color:#eee}}
@media (prefers-color-scheme:light){.hint{display:block}}
</style></head><body>Hi</body></html>''';
const _plain = '<!DOCTYPE html><body style="color:#222">No dark styles</body>';
void main() {
test('only a document that supports dark mode is shown dark', () {
expect(artifactHtmlSupportsDark(_aware), isTrue);
expect(artifactHtmlSupportsDark(_plain), isFalse);
expect(
artifactHtmlSupportsDark('<p style="color: light-dark(#000, #fff)">'),
isTrue,
);
expect(artifactHtmlScheme(_aware, dark: true), 'dark');
expect(artifactHtmlScheme(_aware, dark: false), 'light');
expect(artifactHtmlScheme(_plain, dark: true), 'light');
});
test('a dark-aware document gets the app scheme and fixed queries', () {
final dark = artifactHtmlForScheme(_aware, dark: true);
expect(
dark,
contains('<head><meta name="color-scheme" content="dark"><style>'),
);
expect(dark, contains('@media (min-width: 0px){body{background:#111'));
expect(dark, contains('@media (max-width: -1px){.hint'));
expect(dark, isNot(contains('prefers-color-scheme')));
final light = artifactHtmlForScheme(_aware, dark: false);
expect(light, contains('<meta name="color-scheme" content="light">'));
expect(light, contains('@media (max-width: -1px){body{background:#111'));
expect(light, contains('@media (min-width: 0px){.hint'));
});
test('a document without dark styles stays light, after its doctype', () {
final shown = artifactHtmlForScheme(_plain, dark: true);
expect(
shown,
'<!DOCTYPE html><meta name="color-scheme" content="light">'
'<body style="color:#222">No dark styles</body>',
);
expect(
artifactHtmlForScheme('<svg viewBox="0 0 1 1"></svg>', dark: true),
startsWith('<meta name="color-scheme" content="light"><svg'),
);
});
testWidgets('the HTML view follows the app theme, not the system', (
tester,
) async {
bool? seen;
Future<void> pump(ThemeMode mode) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(brightness: Brightness.light),
darkTheme: ThemeData(brightness: Brightness.dark),
themeMode: mode,
home: Builder(
builder: (context) {
seen = artifactHtmlDark(context);
return const SizedBox();
},
),
),
);
// The theme change animates; read it once settled.
await tester.pumpAndSettle();
}
await pump(ThemeMode.dark);
expect(seen, isTrue);
await pump(ThemeMode.light);
expect(seen, isFalse);
});
}
@@ -58,6 +58,25 @@ void main() {
);
});
test('a replaced card keeps its place in the transcript', () {
final held = [_item('a', 100, kind: 'run'), _item('b', 200)];
final replaced = {
..._item('a', 100, kind: 'run'),
'updated_at': 300,
'title': 'A, now finished',
};
final merged = mergeChatShownItems(held, [replaced]);
final rows = withChatShownItems(
[
{'kind': 'user', 'key': 'u', 'created_at': 150},
],
merged,
hasMore: false,
);
expect(_shape(rows), ['shown:a', 'user:u', 'shown:b']);
expect((rows.first['item'] as Map)['title'], 'A, now finished');
});
group('withChatShownItems', () {
final messages = [
_message('u1', 'user', 100),
@@ -144,4 +144,51 @@ void main() {
findsOneWidget,
);
});
testWidgets('a head revision and paths are named in the comparison', (
tester,
) async {
final item = _item();
final diff = item['diff'] as JsonMap;
diff['head_revision'] = 'pipelines/run-123';
diff['paths'] = ['app/lib', '*.go', 'docs', 'web'];
await _pump(tester, item);
expect(
find.text(
'pipelines · pipelines/run-123 vs main · app/lib, *.go, docs +1',
),
findsOneWidget,
);
});
testWidgets('file rows are one dense line each', (tester) async {
await _pump(tester, _item());
final row = find.byType(ChangeFileRow).first;
expect(tester.getSize(row).height, lessThanOrEqualTo(48));
// The counts share the path's line instead of a subtitle below it.
expect(
tester.getCenter(find.text('app/lib/a.dart')).dy,
closeTo(tester.getCenter(row).dy, 2),
);
});
test('run items are a recorded kind and show_run calls are hidden', () {
expect(chatShownKinds, contains('run'));
expect(
chatPipelinesToolRepresented({
'type': 'tool',
'name': 'pipelines_show_run',
'state': {'status': 'completed'},
}),
isTrue,
);
expect(
chatPipelinesToolRepresented({
'type': 'tool',
'name': 'mcp__pipelines__schedule_followup',
'state': {'status': 'completed'},
}),
isFalse,
);
});
}
@@ -0,0 +1,209 @@
import 'dart:convert';
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/artifacts/ui/artifact_viewer_fetch.dart';
import 'package:pipelines_app/features/chat/chat_run_opener.dart';
import 'package:pipelines_app/features/chat/files/files_urls.dart';
import 'package:pipelines_app/features/chat/files/files_viewer.dart';
import 'package:pipelines_app/features/chat/ui/transcript/shown/chat_shown_card.dart';
import 'package:pipelines_app/features/chat/ui/transcript/shown/chat_shown_run_card.dart';
import 'package:pipelines_app/features/chat/ui/transcript/shown/chat_shown_surface.dart';
const _png =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==';
final _start = DateTime.utc(2026, 12, 1, 9);
JsonMap _run(String status, {int? finishedMinutes, String stage = 'review'}) =>
{
'id': 'r',
'kind': 'run',
'created_at': 1,
'run': {
'id': 42,
'pipeline': 'Feature',
'title': 'Add show_run',
'status': status,
'current_stage': stage,
'started_at': _start.millisecondsSinceEpoch,
if (finishedMinutes != null)
'finished_at': _start
.add(Duration(minutes: finishedMinutes))
.millisecondsSinceEpoch,
},
};
void main() {
late FileUrlResolver original;
final fetched = <Uri>[];
final opened = <int>[];
setUp(() {
original = resolveFileUrls;
resolveFileUrls = (endpoint, path) => fileUrls(endpoint, path);
fetched.clear();
opened.clear();
});
tearDown(() => resolveFileUrls = original);
final viewer = FilesViewer(
fetch: (uri) async {
fetched.add(uri);
final path = uri.queryParameters['path'] ?? '';
return ArtifactFetchResult(
status: 200,
bytes: path.endsWith('.png')
? base64Decode(_png)
: utf8.encode('line one\n'),
);
},
);
Future<void> pump(WidgetTester tester, Widget card) async {
await tester.binding.setSurfaceSize(const Size(1400, 900));
addTearDown(() => tester.binding.setSurfaceSize(null));
await tester.pumpWidget(
ChatRunOpener(
openRun: opened.add,
child: MaterialApp(
home: Scaffold(body: SingleChildScrollView(child: card)),
),
),
);
await tester.pump();
await tester.pump();
}
Widget shown(JsonMap item) => ChatShownCard(
row: {'kind': 'shown', 'item': item},
endpoint: 'ws://peer.example.test/peers/abc/connect',
viewer: viewer,
htmlBuilder: (_, _) => const SizedBox.expand(),
);
testWidgets('a changed live file says so and still opens', (tester) async {
await pump(
tester,
shown({
'id': 'c',
'kind': 'file',
'path': '/home/demo/notes.txt',
'size': 40,
'state': 'changed',
}),
);
await tester.pumpAndSettle();
expect(find.text('Changed since shown'), findsOneWidget);
expect(find.byKey(const Key('chat-shown-file-lines')), findsOneWidget);
expect(find.byType(InkWell), findsOneWidget);
});
testWidgets('a missing file says so and loads nothing', (tester) async {
await pump(
tester,
shown({
'id': 'm',
'kind': 'image',
'path': '/home/demo/gone.png',
'size': 10,
'state': 'missing',
}),
);
await tester.pumpAndSettle();
expect(find.text('No longer exists'), findsOneWidget);
expect(find.byType(Image), findsNothing);
expect(fetched, isEmpty);
expect(find.byType(InkWell), findsNothing);
});
testWidgets('a fetched web image draws its snapshot and names the address', (
tester,
) async {
await pump(
tester,
shown({
'id': 'w',
'kind': 'image',
'path': '/home/demo/.local/share/pipelines/chat-shown/s/w/cat.png',
'name': 'cat.png',
'snapshot': true,
'url': 'https://images.example.test/cat.png',
}),
);
expect(find.text('images.example.test'), findsOneWidget);
expect(find.text('https://images.example.test/cat.png'), findsOneWidget);
expect(find.text('No longer exists'), findsNothing);
});
testWidgets('a running run ticks its duration and opens the run', (
tester,
) async {
var now = _start.add(const Duration(minutes: 2, seconds: 5));
await pump(tester, ChatShownRunCard(item: _run('running'), now: () => now));
expect(find.text('Add show_run'), findsOneWidget);
expect(find.text('Feature'), findsOneWidget);
expect(find.text('Running'), findsOneWidget);
expect(find.text('#42 · review · 2m 5s'), findsOneWidget);
expect(find.bySemanticsLabel(RegExp('Shown run Add show_run')), findsOne);
now = now.add(const Duration(seconds: 3));
await tester.pump(const Duration(seconds: 1));
expect(find.text('#42 · review · 2m 8s'), findsOneWidget);
await tester.tap(find.text('Add show_run'));
expect(opened, [42]);
});
testWidgets('a finished run shows its outcome and final duration', (
tester,
) async {
final item = _run('failed', finishedMinutes: 7);
(item['run'] as Map)['outcome'] = 'tests_failed';
await pump(tester, shown(item));
expect(find.text('Failed · tests_failed'), findsOneWidget);
expect(find.text('#42 · 7m 0s'), findsOneWidget);
expect(find.byIcon(Icons.error_outline), findsOneWidget);
});
testWidgets('a replaced run item updates the same card in place', (
tester,
) async {
final now = _start.add(const Duration(minutes: 1));
Widget card(JsonMap item) => ChatShownRunCard(
key: const ValueKey('chat-shown-r'),
item: item,
now: () => now,
);
await pump(tester, card(_run('running')));
final state = tester.state(find.byType(ChatShownRunCard));
await pump(tester, card(_run('succeeded', finishedMinutes: 4)));
expect(tester.state(find.byType(ChatShownRunCard)), same(state));
expect(find.text('Succeeded'), findsOneWidget);
expect(find.text('#42 · 4m 0s'), findsOneWidget);
});
testWidgets('file, image, view, diff and run cards share one width', (
tester,
) async {
final items = <JsonMap>[
{'id': 'f', 'kind': 'file', 'path': '/home/demo/a.txt', 'size': 1},
{'id': 'i', 'kind': 'image', 'path': '/home/demo/a.png', 'size': 1},
{'id': 'h', 'kind': 'html', 'html': '<p>x</p>', 'html_bytes': 8},
{
'id': 'd',
'kind': 'diff',
'diff': {'repo': '/r', 'files': 0, 'additions': 0, 'deletions': 0},
},
_run('running'),
];
for (final item in items) {
await pump(tester, shown(item));
final card = find.byType(Card);
expect(card, findsOneWidget, reason: '${item['kind']}');
expect(
tester.getSize(card).width,
chatShownCardMaxWidth,
reason: '${item['kind']}',
);
}
});
}
+160
View File
@@ -0,0 +1,160 @@
// `?shown=2` (with `?chats=N&timestamps=1&files=1`): the subscribe reply
// carries the newer shown entries instead of the `shown=1` set, after the
// bench transcript's last answer: a dark-aware and a light-only HTML view, a
// run card running and one finished, a file changed since it was shown, an
// image that no longer exists, a web image the server fetched, and a diff of
// a revision limited to some paths.
import 'package:pipelines_app/core/api_gateway.dart';
int _at(int minute, int second) =>
DateTime.utc(2026, 11, 5, 9, minute, second).millisecondsSinceEpoch;
const String _darkAware = '''
<!doctype html><html><head><style>
:root{color-scheme:light dark}
body{margin:0;padding:12px;font:14px system-ui;background:#fafafa;color:#1b1b1f}
.bar{height:18px;border-radius:4px;background:#1e88e5;margin:6px 0}
@media (prefers-color-scheme: dark){
body{background:#1b1b1f;color:#e6e1e5}
.bar{background:#90caf9}
}
</style></head><body>
<strong>Stage durations (follows the theme)</strong>
<div class="bar" style="width:40%"></div><div>Build 2m 10s</div>
<div class="bar" style="width:80%"></div><div>Test 4m 02s</div>
<div class="bar" style="width:15%"></div><div>Release 38s</div>
</body></html>''';
const String _lightOnly = '''
<!doctype html><html><body style="margin:0;padding:12px;font:14px system-ui">
<strong>Plain document (no dark styles)</strong>
<p>Its own colours were chosen for a light page, so it stays light.</p>
<table border="1" cellpadding="4" style="border-collapse:collapse">
<tr><th>Stage</th><th>Result</th></tr>
<tr><td>Build</td><td style="color:#2e7d32">passed</td></tr>
<tr><td>Test</td><td style="color:#c62828">failed</td></tr>
</table></body></html>''';
int get _now => DateTime.now().millisecondsSinceEpoch;
/// The retained entries the fixture's subscribe reply carries for `shown=2`.
JsonMap chatShownToolsFixture(Object? sessionId) => {
'session_id': sessionId,
'items': [
{
'id': 'shown-dark-html',
'kind': 'html',
'created_at': _at(19, 10),
'title': 'Stage durations',
'html': _darkAware,
'html_bytes': _darkAware.length,
'height_hint': 160,
},
{
'id': 'shown-light-html',
'kind': 'html',
'created_at': _at(19, 15),
'title': 'Light-only view',
'html': _lightOnly,
'html_bytes': _lightOnly.length,
'height_hint': 170,
},
{
'id': 'shown-run-live',
'kind': 'run',
'created_at': _at(19, 20),
'run': {
'id': 7,
'pipeline': 'Release',
'title': 'Publish the 4.2 release notes',
'status': 'running',
'current_stage': 'review',
'started_at': _now - 754000,
},
},
{
'id': 'shown-run-done',
'kind': 'run',
'created_at': _at(19, 25),
'run': {
'id': 6,
'pipeline': 'Feature',
'title': 'Add show_run to the chat tools',
'status': 'failed',
'outcome': 'tests_failed',
'started_at': _at(1, 0),
'finished_at': _at(9, 30),
},
},
{
'id': 'shown-changed',
'kind': 'file',
'created_at': _at(19, 30),
'path': '/srv/probe/release/server.log',
'name': 'server.log',
'size': 9437184,
'mime': 'text/plain',
'mod_time': _at(19, 0),
'sha256': 'f' * 64,
'state': 'changed',
},
{
'id': 'shown-missing',
'kind': 'image',
'created_at': _at(19, 35),
'title': 'Old screenshot',
'path': '/srv/probe/release/old-screenshot.png',
'name': 'old-screenshot.png',
'size': 8000000,
'mime': 'image/png',
'state': 'missing',
},
{
'id': 'shown-fetched',
'kind': 'image',
'created_at': _at(19, 40),
'path': '/srv/probe/.local/share/pipelines/chat-shown/s/f/icon.jpg',
'name': 'icon.jpg',
'size': 2400,
'mime': 'image/jpeg',
'snapshot': true,
'url': 'https://images.example.test/brand/icon.jpg',
},
{
'id': 'shown-head-diff',
'kind': 'diff',
'created_at': _at(19, 45),
'title': 'Run 123 against main',
'diff_bytes': 180,
'diff': {
'repo': '/srv/probe/pipelines',
'base': 'main',
'base_commit': '79e51834a1b2',
'head_revision': 'pipelines/run-123',
'paths': ['internal/chattools', '*.md'],
'files': 2,
'additions': 3,
'deletions': 1,
'changes': {
'status': 'complete',
'skipped': 0,
'files': [
{
'path': 'internal/chattools/tools.go',
'kind': 'modified',
'patch':
'@@ -6,2 +6,3 @@\n \tToolShowDiff = "show_diff"\n'
'-\tToolNotify = "notify"\n+\tToolShowRun = "show_run"\n'
'+\tToolNotify = "notify"\n',
},
{
'path': 'README.md',
'kind': 'modified',
'patch': '@@ -1 +1,2 @@\n line\n+show_run\n',
},
],
},
},
},
],
};
+5
View File
@@ -36,6 +36,7 @@ import 'chat_question_fixture.dart';
import 'chat_shell_fixture.dart';
import 'terminal_fixture.dart';
import 'chat_shown_fixture.dart';
import 'chat_shown_tools_fixture.dart';
import 'chat_scroll_fixture.dart';
Map<String, String> _params = const {};
@@ -341,6 +342,10 @@ JsonMap? perfChatReply(JsonMap request) {
'chat_shown': chatShownFixture(
(request['chat_subscribe'] as Map?)?['session_id'],
),
if (_params['shown'] == '2')
'chat_shown': chatShownToolsFixture(
(request['chat_subscribe'] as Map?)?['session_id'],
),
};
case 'chat_prompt':
// Accepted, as the server does; no reply follows, so a capture can
+1 -1
View File
@@ -77,7 +77,7 @@ only when asked). Stage use: `references/format.md`.
## In a Pipelines chat
A chat's agent has a `pipelines` MCP server: `show_file`, `show_image`,
`show_html` (follows the operator's light/dark theme), `show_diff` (show the
`show_html` (follows the light/dark theme when it styles for dark), `show_diff` (show the
operator changes, e.g. before a pull request; `head`, `paths`), `show_run` (a
live run card), `schedule_followup` (come back to this chat later) and `notify`
(phone, only when the operator must look now). Show instead of telling the
+1 -1
View File
@@ -21,7 +21,7 @@ regenerate, or a file you rewrote.
| --- | --- | --- |
| `show_file` | `path`, `title?`, `replace?` | Any file the operator should see: images inline, other files as a preview card. Use instead of naming a path. A file up to 5 MiB is copied when shown, so the card keeps that version; a larger one stays linked and its card says "changed since shown" or "no longer exists". |
| `show_image` | `url_or_path`, `title?`, `alt?`, `replace?` | A home `image/*` file, or an `https://` URL that Pipelines downloads and keeps (public hosts only, PNG/JPEG/GIF/WebP/AVIF/BMP, at most 10 MiB, no credentials, no redirect to plain http). A failed download is an error and nothing is shown. |
| `show_html` | `html`, `title?`, `height_hint?` (120-600), `replace?` | Self-contained HTML/SVG: diagrams, charts, tables. Sandboxed: no JavaScript, no network; inline CSS/SVG, `<details>`, `:hover`. Follows the operator's light/dark theme: style both with `@media (prefers-color-scheme: dark)` or `Canvas`/`CanvasText`, or set your own background and text colours. Refused above 512 KiB. |
| `show_html` | `html`, `title?`, `height_hint?` (120-600), `replace?` | Self-contained HTML/SVG: diagrams, charts, tables. Sandboxed: no JavaScript, no network; inline CSS/SVG, `<details>`, `:hover`. Follows the operator's light/dark theme only when it declares dark support: `@media (prefers-color-scheme: dark)`, `color-scheme` or `light-dark()`; anything else is always shown light, on white. Refused above 512 KiB. |
| `show_diff` | `path?`, `base?`, `head?`, `paths?`, `committed_only?`, `title?`, `replace?` | A Git diff card when the operator asks to see the changes, or before submitting a pull request. No `base`: uncommitted work (staged, unstaged, untracked) against HEAD. `base` (e.g. `main`): everything since the merge base, which is what a PR contains, plus uncommitted work unless `committed_only`. `head` (e.g. `pipelines/run-123`): that revision instead of the work tree, against `base` or HEAD. `paths`: repository-relative files, directories or globs (`*.go`), at most 50. Pipelines runs Git; do not paste the diff. |
| `show_run` | `run_id`, `title?`, `replace?` | A live card for a run: pipeline, title, status, current stage, duration; it updates as the run progresses and opens the run when tapped. |
| `schedule_followup` | `message`, `at?` or `after_minutes?` | Queue a prompt to yourself in this chat, 1 minute to 7 days ahead (`at` is RFC 3339). It is a scheduled message from "Agent follow-up" the operator can remove; it does not hold the operator's own messages back, and is delivered when the chat is free at that time. At most 3 pending per chat. Do not wait for it in the current turn. |
+3 -3
View File
@@ -112,9 +112,9 @@ func definitions() []toolDefinition {
Description: "Render a self-contained HTML or SVG document inline in the Pipelines chat: diagrams, charts, tables, small visual views. " +
"It is shown in a sandbox with no scripts, no network and no access to the app: use inline CSS and inline SVG, " +
"<details> for expandable parts and CSS :hover for interaction; JavaScript does not run and external resources do not load. " +
"The view follows the operator's light or dark theme (color-scheme and prefers-color-scheme): style for both with " +
"@media (prefers-color-scheme: dark) or CSS system colors (Canvas, CanvasText), or set your own background and text colors; " +
"unstyled text uses the theme's default colors. " +
"A document that supports dark mode follows the operator's light or dark theme: style for both with " +
"@media (prefers-color-scheme: dark), a color-scheme declaration or light-dark() colors (with color-scheme, " +
"unstyled text and the page use the theme's Canvas/CanvasText). A document without any of these is always shown light, on white. " +
"The operator can open it full screen. At most 512 KiB. The result names the item's id: pass it as replace to update the view.",
InputSchema: objectSchema([]string{"html"}, map[string]any{
"html": stringProperty("The complete HTML (or a bare <svg>) document."),
+1 -1
View File
@@ -83,7 +83,7 @@ func (s *chatToolService) run(ctx context.Context, sessionID, tool, id string, a
return fail("Nothing was shown: html is not valid UTF-8.")
}
item := protocol.ChatShownItem{Kind: protocol.ChatShownHTML, Title: boundedLine(in.Title, 200), HTML: in.HTML, HTMLBytes: len(in.HTML), HeightHint: clampHeightHint(in.HeightHint)}
return &item, chattools.Result{Text: fmt.Sprintf("Shown in the operator's Pipelines chat (%s, sandboxed: scripts and network are disabled; it follows the operator's light or dark theme).", humanBytes(int64(len(in.HTML))))}
return &item, chattools.Result{Text: fmt.Sprintf("Shown in the operator's Pipelines chat (%s, sandboxed: scripts and network are disabled; it follows the operator's light or dark theme only if it styles itself for dark mode).", humanBytes(int64(len(in.HTML))))}
case chattools.ToolShowDiff:
var in struct {
Path string `json:"path"`