From 5425001d82d8e7ed92b00f708d3c71e118c12794 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 13 Nov 2026 18:43:14 +0000 Subject: [PATCH] Send artifacts, runs and pipelines to a new or existing chat One picker offers a new chat (the saved Open in chat harness and model) or any open chat. An existing chat gets the reference appended to its draft and focused, never sent. Artifacts gain the action in their viewer and gallery; the run and pipeline item becomes Send to chat. --- app/lib/application/pipelines_app.dart | 43 ++++- app/lib/application/runs_destination.dart | 3 + app/lib/application/send_to_chat.dart | 180 ++++++++++++++++++ .../domain/artifact_chat_context.dart | 50 +++++ .../artifacts/ui/artifact_gallery_action.dart | 17 ++ .../artifacts/ui/artifact_gallery_page.dart | 30 +++ .../artifacts/ui/artifact_viewer_bar.dart | 9 + .../artifacts/ui/artifact_viewer_body.dart | 3 + .../artifacts/ui/artifact_viewer_page.dart | 5 + app/lib/features/chat/chat_pane_content.dart | 4 + app/lib/features/chat/chat_runtime.dart | 29 +++ .../chat_composer_controller.dart | 10 + .../chat/conversation/chat_thread_view.dart | 7 + .../widgets/pipeline_archive_action.dart | 4 +- .../widgets/pipeline_list_panel.dart | 2 +- app/lib/features/runs/screen.dart | 5 + .../features/runs/ui/run_detail_material.dart | 2 + app/lib/features/runs/ui/run_detail_tabs.dart | 14 ++ app/lib/features/runs/ui/run_detail_view.dart | 5 + .../features/runs/ui/run_detail_visit.dart | 3 + .../runs/ui/run_detail_visit_artifacts.dart | 18 ++ .../runs/ui/run_detail_visit_documents.dart | 22 +++ .../runs/ui/run_detail_visit_sections.dart | 5 + .../runs/ui/run_detail_visit_session.dart | 3 + app/lib/features/runs/ui/run_more_menu.dart | 4 +- app/test/application/open_in_chat_test.dart | 158 +++++++++++++-- .../ui/artifact_gallery_page_test.dart | 93 +++++++++ .../ui/artifact_viewer_page_test.dart | 8 + app/tool/search_selection_probe_entry.dart | 25 +++ 29 files changed, 742 insertions(+), 19 deletions(-) create mode 100644 app/lib/application/send_to_chat.dart create mode 100644 app/lib/features/artifacts/domain/artifact_chat_context.dart diff --git a/app/lib/application/pipelines_app.dart b/app/lib/application/pipelines_app.dart index 0dc0f545..23adcefd 100644 --- a/app/lib/application/pipelines_app.dart +++ b/app/lib/application/pipelines_app.dart @@ -26,6 +26,7 @@ import '../features/attention/runtime/attention_controller.dart'; import '../features/attention/runtime/attention_store.dart'; import '../features/runs/ui/run_search_selection.dart'; import '../features/artifacts/domain/artifact_groups.dart'; +import '../features/artifacts/domain/artifact_chat_context.dart'; import '../features/artifacts/domain/artifact_record.dart'; import '../features/artifacts/ui/artifact_viewer_page.dart'; import '../features/artifacts/domain/gallery_navigation.dart'; @@ -49,6 +50,7 @@ import 'app_terminals.dart'; import '../features/chat/chat_runtime.dart'; import '../features/chat/windows/chat_windows.dart'; import 'open_in_chat.dart'; +import 'send_to_chat.dart'; import '../features/pipelines/pipeline_models.dart'; import '../features/chat/workspace/chat_float_store.dart'; import '../features/terminal/terminal_layout.dart'; @@ -153,7 +155,7 @@ class _PipelinesAppState extends State ? await settingsWorkspace(serverIdentity(_session.gateway) ?? '') : directory; if (!context.mounted) return; - await openReferenceInChat( + await showSendToChatPicker( context: context, runtime: _chatRuntime, selectChat: (id) => _delegate.goTo(AppRoute.chatSession(id)), @@ -182,7 +184,7 @@ class _PipelinesAppState extends State ? await settingsWorkspace(serverIdentity(_session.gateway) ?? '') : directory; if (!context.mounted) return; - await openReferenceInChat( + await showSendToChatPicker( context: context, runtime: _chatRuntime, selectChat: (id) => _delegate.goTo(AppRoute.chatSession(id)), @@ -203,6 +205,26 @@ class _PipelinesAppState extends State } } + Future _sendArtifactToChat( + BuildContext context, + JsonMap run, + String draft, + ) async { + final directory = '${run['workspace'] ?? run['directory'] ?? ''}'.trim(); + final fallback = directory.isEmpty + ? await settingsWorkspace(serverIdentity(_session.gateway) ?? '') + : directory; + if (!context.mounted) return; + await showSendToChatPicker( + context: context, + runtime: _chatRuntime, + selectChat: (id) => _delegate.goTo(AppRoute.chatSession(id)), + directory: fallback, + title: 'Artifact · Run #${run['id'] ?? ''}', + draft: draft, + ); + } + late final AppSession _session; late final AppRouterDelegate _delegate; late final ElevationPrompt _elevationPrompt = elevationDialogPrompt( @@ -947,6 +969,22 @@ class _PipelinesAppState extends State groups: [group], selectedIdentity: artifactVisitIdentityOf(group, record), configuredEndpoint: configuredGatewayEndpoint(_session.gateway), + onSendToChat: (page) => _sendArtifactToChat( + context, + {'id': route.runId}, + artifactChatReference( + ArtifactChatContext( + runId: '${route.runId}', + runTitle: 'Run ${route.runId}', + pipelineName: 'Unknown', + stageKey: 'notification', + visit: route.artifactSequence, + configuredEndpoint: configuredGatewayEndpoint(_session.gateway), + ), + page.group, + page.artifact, + ), + ), ); } @@ -1047,6 +1085,7 @@ class _PipelinesAppState extends State onOpenPipeline: (id, version) => _delegate.goTo(AppRoute.pipeline(id, version: version)), onOpenInChat: _openRunInChat, + onSendToChat: _sendArtifactToChat, ), ), AppDestination.chat: (_) => ChatDestination( diff --git a/app/lib/application/runs_destination.dart b/app/lib/application/runs_destination.dart index a66271c2..6dffbe39 100644 --- a/app/lib/application/runs_destination.dart +++ b/app/lib/application/runs_destination.dart @@ -36,6 +36,7 @@ class RunsDestination extends StatelessWidget { this.notifications, this.attention, this.onOpenInChat, + this.onSendToChat, }); final AppSession session; @@ -68,6 +69,7 @@ class RunsDestination extends StatelessWidget { /// The app-level attention controller the shell's Runs tab badge reads. final AttentionController? attention; final Future Function(BuildContext, JsonMap)? onOpenInChat; + final Future Function(BuildContext, JsonMap, String)? onSendToChat; @override Widget build(BuildContext context) => AnimatedBuilder( @@ -113,5 +115,6 @@ class RunsDestination extends StatelessWidget { onPipelineFilterChanged: onPipelineFilterChanged, onOpenPipeline: onOpenPipeline, onOpenInChat: onOpenInChat, + onSendToChat: onSendToChat, ); } diff --git a/app/lib/application/send_to_chat.dart b/app/lib/application/send_to_chat.dart new file mode 100644 index 00000000..63b74ed9 --- /dev/null +++ b/app/lib/application/send_to_chat.dart @@ -0,0 +1,180 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; + +import '../features/chat/chat_runtime.dart'; +import '../features/chat/domain/chat_sessions.dart'; +import '../features/chat/ui/sessions/chat_create_fields.dart'; +import '../ui/adaptive/app_popups.dart'; +import 'open_in_chat.dart'; + +/// Shows the common destination picker used by runs, pipelines and artifacts. +/// The draft is always placed in the composer; no option sends it. +Future showSendToChatPicker({ + required BuildContext context, + required ChatRuntime runtime, + required ValueChanged selectChat, + required String directory, + required String title, + required String draft, +}) async { + if (runtime.sessions.loading && runtime.sessions.sessions.isEmpty) { + unawaited(runtime.sessions.refresh()); + } + final choice = await showAppDetails<_ChatChoice>( + context, + maxWidth: 600, + builder: (context) => _SendToChatSheet(runtime: runtime, title: title), + ); + if (!context.mounted || choice == null) return; + if (choice.newChat) { + await openReferenceInChat( + context: context, + runtime: runtime, + selectChat: selectChat, + directory: directory, + title: title, + draft: draft, + ); + return; + } + final id = choice.id; + if (id == null || id.isEmpty) return; + await runtime.appendDraft(id, draft); + selectChat(id); + runtime.composerFocus.request(id); +} + +class _ChatChoice { + const _ChatChoice.newChat() : newChat = true, id = null; + const _ChatChoice.existing(this.id) : newChat = false; + final bool newChat; + final String? id; +} + +class _SendToChatSheet extends StatefulWidget { + const _SendToChatSheet({required this.runtime, required this.title}); + final ChatRuntime runtime; + final String title; + + @override + State<_SendToChatSheet> createState() => _SendToChatSheetState(); +} + +class _SendToChatSheetState extends State<_SendToChatSheet> { + final _search = TextEditingController(); + String _query = ''; + + @override + void initState() { + super.initState(); + _search.addListener(() => setState(() => _query = _search.text)); + widget.runtime.sessions.addListener(_changed); + } + + void _changed() { + if (mounted) setState(() {}); + } + + @override + void dispose() { + widget.runtime.sessions.removeListener(_changed); + _search.dispose(); + super.dispose(); + } + + List> get _rows { + final rows = filterChatSessions(widget.runtime.sessions.sessions, _query) + .where((row) { + final id = '${row['id'] ?? ''}'; + return id.isNotEmpty && + row['closed_at'] == null && + row['closed'] != true; + }) + .toList(); + final active = widget.runtime.sessions.activeSessionId; + rows.sort((a, b) { + int priority(Map row) { + final id = '${row['id'] ?? ''}'; + if (id == active) return 0; + if (widget.runtime.openedForWork.contains(id)) return 1; + return 2; + } + + final byPriority = priority(a).compareTo(priority(b)); + if (byPriority != 0) return byPriority; + return chatSessionMillis( + b['updated_at'], + ).compareTo(chatSessionMillis(a['updated_at'])); + }); + return rows; + } + + @override + Widget build(BuildContext context) { + final sessions = _rows; + return Padding( + padding: const EdgeInsets.fromLTRB(20, 0, 20, 20), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text('Send to chat', style: Theme.of(context).textTheme.titleLarge), + const SizedBox(height: 12), + TextField( + controller: _search, + decoration: const InputDecoration( + labelText: 'Search chats', + prefixIcon: Icon(Icons.search), + border: OutlineInputBorder(), + ), + ), + const SizedBox(height: 8), + ConstrainedBox( + constraints: BoxConstraints( + maxHeight: MediaQuery.sizeOf(context).height * .55, + ), + child: ListView( + // As tall as its rows up to the cap, then it scrolls: a short + // list leaves no empty space, a long one fits phone sheets and + // desktop dialogs. + shrinkWrap: true, + children: [ + ListTile( + leading: const Icon(Icons.add_comment_outlined), + title: const Text('New chat'), + subtitle: const Text('Use the saved Open in chat settings'), + onTap: () => + Navigator.of(context).pop(const _ChatChoice.newChat()), + ), + if (sessions.isEmpty) + ListTile( + leading: const Icon(Icons.forum_outlined), + title: Text( + widget.runtime.sessions.loading + ? 'Loading chats…' + : _query.isEmpty + ? 'No existing chats' + : 'No chats match this search', + ), + ), + for (final row in sessions) + ListTile( + leading: const Icon(Icons.chat_bubble_outline), + title: Text(chatSessionTitle(row)), + subtitle: Text( + '${'${row['directory'] ?? ''}'.trim().isEmpty ? 'No folder' : row['directory']}' + ' · ${chatBackendLabel('${row['backend'] ?? row['harness'] ?? ''}')}', + ), + onTap: () => Navigator.of( + context, + ).pop(_ChatChoice.existing('${row['id']}')), + ), + ], + ), + ), + ], + ), + ); + } +} diff --git a/app/lib/features/artifacts/domain/artifact_chat_context.dart b/app/lib/features/artifacts/domain/artifact_chat_context.dart new file mode 100644 index 00000000..f659197d --- /dev/null +++ b/app/lib/features/artifacts/domain/artifact_chat_context.dart @@ -0,0 +1,50 @@ +import '../../../core/api_gateway.dart'; +import 'artifact_record.dart'; +import 'artifact_url.dart'; +import 'artifact_groups.dart'; + +/// Run provenance supplied by the owner of an artifact gallery. +class ArtifactChatContext { + const ArtifactChatContext({ + required this.runId, + required this.runTitle, + required this.pipelineName, + this.pipelineVersion, + this.stageKey, + this.visit, + this.configuredEndpoint = '', + this.recordedSteps = const {}, + }); + + final String runId; + final String runTitle; + final String pipelineName; + final String? pipelineVersion; + final String? stageKey; + final int? visit; + final String configuredEndpoint; + final JsonMap recordedSteps; +} + +String artifactChatReference( + ArtifactChatContext context, + ArtifactGroup group, + ArtifactRecord artifact, +) { + final resolved = artifact.hasUrl + ? resolveArtifactUrl(context.configuredEndpoint, artifact.url) + : null; + final readable = resolved == null + ? 'The server did not provide a safe readable URL for this artifact; ' + 'inspect the run to locate it.' + : 'The chat agent can read it at ${resolved.url}'; + final version = context.pipelineVersion == null + ? '' + : ' v${context.pipelineVersion}'; + return 'Artifact "${artifact.name}" from run ${context.runId} ' + '("${context.runTitle}"), pipeline "${context.pipelineName}"$version, ' + 'stage "${context.stageKey ?? group.stageKey}", visit ' + '${context.visit ?? group.visit}. $readable. ' + 'Use `pipelines inspect ${context.runId}` for the authoritative run ' + 'and artifact metadata.'; +} diff --git a/app/lib/features/artifacts/ui/artifact_gallery_action.dart b/app/lib/features/artifacts/ui/artifact_gallery_action.dart index 49ee0983..8e02ad41 100644 --- a/app/lib/features/artifacts/ui/artifact_gallery_action.dart +++ b/app/lib/features/artifacts/ui/artifact_gallery_action.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../../../core/transport/pipelines_client.dart'; +import '../domain/artifact_chat_context.dart'; import 'artifact_external_open.dart'; import 'artifact_gallery_page.dart'; @@ -42,10 +43,12 @@ class RunArtifactsButton extends StatelessWidget { super.key, required this.run, required this.gateway, + this.onSendToChat, }); final JsonMap run; final ApiGateway gateway; + final void Function(String draft)? onSendToChat; @override Widget build(BuildContext context) { @@ -55,6 +58,16 @@ class RunArtifactsButton extends StatelessWidget { steps: steps, executing: _runExecuting(run), configuredEndpoint: configuredGatewayEndpoint(gateway), + artifactChatContext: ArtifactChatContext( + runId: '${run['id'] ?? ''}', + runTitle: '${run['title'] ?? run['name'] ?? ''}', + pipelineName: '${run['name'] ?? ''}', + pipelineVersion: run['version'] is num + ? (run['version'] as num).toInt().toString() + : null, + configuredEndpoint: configuredGatewayEndpoint(gateway), + ), + onSendToChat: onSendToChat, ); return OutlinedButton.icon( key: runArtifactsButtonKey, @@ -74,6 +87,8 @@ Future showArtifactGallery( bool executing = false, String configuredEndpoint = '', ArtifactExternalOpen openExternal = openArtifactExternally, + ArtifactChatContext? artifactChatContext, + void Function(String draft)? onSendToChat, }) { final page = ArtifactGalleryPage( steps: List.unmodifiable(steps), @@ -81,6 +96,8 @@ Future showArtifactGallery( executing: executing, configuredEndpoint: configuredEndpoint, openExternal: openExternal, + artifactChatContext: artifactChatContext, + onSendToChat: onSendToChat, ); return Navigator.of( context, diff --git a/app/lib/features/artifacts/ui/artifact_gallery_page.dart b/app/lib/features/artifacts/ui/artifact_gallery_page.dart index 3f55d203..1b6cfc7b 100644 --- a/app/lib/features/artifacts/ui/artifact_gallery_page.dart +++ b/app/lib/features/artifacts/ui/artifact_gallery_page.dart @@ -15,6 +15,7 @@ import '../domain/artifact_record.dart'; import '../domain/artifact_selection.dart'; import '../domain/artifact_summary.dart'; import '../domain/artifact_url.dart'; +import '../domain/artifact_chat_context.dart'; import 'artifact_external_open.dart'; import 'artifact_selection_facts.dart'; import 'artifact_viewer_content.dart'; @@ -56,6 +57,8 @@ class ArtifactGalleryPage extends StatefulWidget { this.initiallyCollapsed = false, this.openArtifactUrl, this.onOpenArtifactHandled, + this.artifactChatContext, + this.onSendToChat, }); final List steps; @@ -83,6 +86,8 @@ class ArtifactGalleryPage extends StatefulWidget { /// [onOpenArtifactHandled] with whether its groups record that URL. final String? openArtifactUrl; final ValueChanged? onOpenArtifactHandled; + final ArtifactChatContext? artifactChatContext; + final void Function(String draft)? onSendToChat; @override State createState() => _ArtifactGalleryPageState(); @@ -296,6 +301,16 @@ class _ArtifactGalleryPageState extends State { fetch: widget.fetch, markdownBuilder: widget.markdownBuilder, fileBridge: widget.fileBridge, + onSendToChat: + widget.artifactChatContext == null || widget.onSendToChat == null + ? null + : (page) => widget.onSendToChat!( + artifactChatReference( + widget.artifactChatContext!, + page.group, + page.artifact, + ), + ), ), ), ); @@ -356,6 +371,21 @@ class _ArtifactGalleryPageState extends State { onPressed: () => _open(resolved, dialogContext), child: const Text('Open in browser'), ), + if (widget.artifactChatContext != null && widget.onSendToChat != null) + TextButton( + key: const Key('artifact-send-to-chat'), + onPressed: () { + Navigator.of(dialogContext).pop(); + widget.onSendToChat!( + artifactChatReference( + widget.artifactChatContext!, + group, + artifact, + ), + ); + }, + child: const Text('Send to chat…'), + ), ], ), ); diff --git a/app/lib/features/artifacts/ui/artifact_viewer_bar.dart b/app/lib/features/artifacts/ui/artifact_viewer_bar.dart index 3545e9bd..b9790328 100644 --- a/app/lib/features/artifacts/ui/artifact_viewer_bar.dart +++ b/app/lib/features/artifacts/ui/artifact_viewer_bar.dart @@ -35,6 +35,7 @@ class ArtifactViewerBar extends StatelessWidget { required this.onNext, this.fullscreen = false, this.onFullscreen, + this.onSendToChat, }); final PagedArtifact page; @@ -55,6 +56,7 @@ class ArtifactViewerBar extends StatelessWidget { /// Enters (inline) or leaves (in full screen) the full-screen view; absent, /// the control is not drawn. final VoidCallback? onFullscreen; + final VoidCallback? onSendToChat; @override Widget build(BuildContext context) { @@ -145,5 +147,12 @@ class ArtifactViewerBar extends StatelessWidget { icon: fullscreen ? Icons.fullscreen_exit : Icons.fullscreen, onPressed: toggle, ), + if (onSendToChat != null) + ArtifactIconAction( + key: const Key('artifact-send-to-chat'), + label: 'Send to chat…', + icon: Icons.chat_outlined, + onPressed: onSendToChat!, + ), ]; } diff --git a/app/lib/features/artifacts/ui/artifact_viewer_body.dart b/app/lib/features/artifacts/ui/artifact_viewer_body.dart index 552a2227..4baa9a5a 100644 --- a/app/lib/features/artifacts/ui/artifact_viewer_body.dart +++ b/app/lib/features/artifacts/ui/artifact_viewer_body.dart @@ -51,6 +51,7 @@ class ArtifactViewerBody extends StatelessWidget { this.onFullscreen, this.onImageZoomChanged, this.imageZoomed = false, + this.onSendToChat, }); /// The inert HTML renderer; tests inject a plain stand-in. @@ -64,6 +65,7 @@ class ArtifactViewerBody extends StatelessWidget { final ValueChanged? onImageZoomChanged; final bool imageZoomed; + final VoidCallback? onSendToChat; /// Loads the current page's preview again after a failure. final VoidCallback? onRetry; @@ -156,6 +158,7 @@ class ArtifactViewerBody extends StatelessWidget { onNext: onNext, fullscreen: fullscreen, onFullscreen: onFullscreen, + onSendToChat: onSendToChat, ), child: swipe, ); diff --git a/app/lib/features/artifacts/ui/artifact_viewer_page.dart b/app/lib/features/artifacts/ui/artifact_viewer_page.dart index bc06aef7..aa0fc0a9 100644 --- a/app/lib/features/artifacts/ui/artifact_viewer_page.dart +++ b/app/lib/features/artifacts/ui/artifact_viewer_page.dart @@ -51,6 +51,7 @@ class ArtifactViewerPage extends StatefulWidget { this.openExternal = openArtifactExternally, this.fileBridge = const ArtifactFileBridge(), this.htmlBuilder = defaultArtifactHtml, + this.onSendToChat, }); final List groups; @@ -79,6 +80,7 @@ class ArtifactViewerPage extends StatefulWidget { /// The inert HTML renderer; tests inject a plain stand-in. final ArtifactHtmlBuilder htmlBuilder; + final ValueChanged? onSendToChat; @override State createState() => _ArtifactViewerPageState(); @@ -305,6 +307,9 @@ class _ArtifactViewerPageState extends State onFullscreen: fullscreen ? () => Navigator.of(context).maybePop() : enterFullscreen, + onSendToChat: widget.onSendToChat == null + ? null + : () => widget.onSendToChat!(page), ); // Left/right arrows walk the same list as the Previous/Next buttons, // wherever focus is on the page, its top bar's controls included. diff --git a/app/lib/features/chat/chat_pane_content.dart b/app/lib/features/chat/chat_pane_content.dart index 86d06e4a..0982cb43 100644 --- a/app/lib/features/chat/chat_pane_content.dart +++ b/app/lib/features/chat/chat_pane_content.dart @@ -119,6 +119,10 @@ Widget buildChatPaneContent({ paneControls: placement.paneControls?.call(context) ?? const [], paneCommands: placement.paneCommands, onComposerFocus: placement.onComposerFocus, + onComposerReady: (composer) => + runtime.registerComposer(sessionId, composer), + onComposerDisposed: (composer) => + runtime.unregisterComposer(sessionId, composer), ), ), ), diff --git a/app/lib/features/chat/chat_runtime.dart b/app/lib/features/chat/chat_runtime.dart index c40d8822..2443b732 100644 --- a/app/lib/features/chat/chat_runtime.dart +++ b/app/lib/features/chat/chat_runtime.dart @@ -10,6 +10,7 @@ import 'conversation/chat_models.dart'; import 'conversation/chat_row_widgets.dart'; import 'conversation/chat_scroll.dart'; import 'conversation/chat_transcript_cache.dart'; +import 'conversation/chat_composer_controller.dart'; import 'conversation/composer_focus_request.dart'; import 'data/chat_repository.dart'; import 'ui/sessions/chat_sessions_body.dart'; @@ -127,6 +128,32 @@ class ChatRuntime extends ChangeNotifier { /// Puts the keyboard in an opened chat's composer once it is built. final ChatComposerFocusRequests composerFocus = ChatComposerFocusRequests(); + /// Mounted composers are registered so external actions can append without + /// sending. A selection made before a pane mounts is queued here. + final Map composers = {}; + final Map> _pendingAppends = {}; + + void registerComposer(String id, ChatComposerController composer) { + composers[id] = composer; + final pending = _pendingAppends.remove(id); + if (pending != null) { + for (final text in pending) { + unawaited(composer.appendDraft(text)); + } + } + } + + void unregisterComposer(String id, ChatComposerController composer) { + if (identical(composers[id], composer)) composers.remove(id); + } + + Future appendDraft(String id, String text) { + final composer = composers[id]; + if (composer != null) return composer.appendDraft(text); + (_pendingAppends[id] ??= []).add(text); + return Future.value(); + } + /// The line a just-created conversation opens on, tied to the selection /// `/new` made. Leaving that conversation drops it, so a later reopen is /// an ordinary visit. @@ -251,6 +278,8 @@ class ChatRuntime extends ChangeNotifier { sessions.dispose(); folds.dispose(); composerFocus.dispose(); + composers.clear(); + _pendingAppends.clear(); super.dispose(); } } diff --git a/app/lib/features/chat/conversation/chat_composer_controller.dart b/app/lib/features/chat/conversation/chat_composer_controller.dart index 2aa16802..d08173ad 100644 --- a/app/lib/features/chat/conversation/chat_composer_controller.dart +++ b/app/lib/features/chat/conversation/chat_composer_controller.dart @@ -139,6 +139,16 @@ class ChatComposerController extends ChangeNotifier { return _persistDraft(text); } + /// Appends external, unsent context to the current draft. This deliberately + /// does not use [send], so selecting "Send to chat" can never create a + /// prompt request. + Future appendDraft(String text) { + if (_disposed || text.isEmpty) return Future.value(); + final current = _draft.trimRight(); + final next = current.isEmpty ? text : '$current\n$text'; + return setDraft(next); + } + /// Sends the non-blank draft as one plain message, carrying [attachments] in /// draft order. Only the wire text is trimmed. The intent is stored on the /// device until the server accepts it. A refusal restores the exact draft diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index 9c923312..67706b75 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -129,6 +129,8 @@ class ChatThreadView extends StatefulWidget { this.useNativeBack = false, this.pasteTarget = true, this.ownsPasteWhenFocused = false, + this.onComposerReady, + this.onComposerDisposed, }); final ApiGateway gateway; @@ -147,6 +149,8 @@ class ChatThreadView extends StatefulWidget { /// See [ChatComposerBar.ownsPasteWhenFocused]. final bool ownsPasteWhenFocused; + final void Function(ChatComposerController composer)? onComposerReady; + final void Function(ChatComposerController composer)? onComposerDisposed; /// Sets the chat's shared colour (a palette name, null for none) from the /// information sheet; null leaves the sheet without the Colour choice. @@ -532,6 +536,7 @@ class _ChatThreadViewState extends State { onAccepted: (send, queued) => _controller.promptAccepted(send.operationId, queued: queued), ); + widget.onComposerReady?.call(composer); if (widget.initialDraft != null) { unawaited(composer.setDraft(widget.initialDraft!)); } @@ -685,6 +690,7 @@ class _ChatThreadViewState extends State { _images = ChatAttachmentImages(widget.gateway); } _controller.dispose(); + oldWidget.onComposerDisposed?.call(_composer); _composer.dispose(); _shellRuns.dispose(); _shellRuns = _attachShellRuns(); @@ -773,6 +779,7 @@ class _ChatThreadViewState extends State { widget.paneCommands?.removeListener(_takeCommands); widget.paneCommands?.setFinished(widget.sessionId, false); _scroll.dispose(); + widget.onComposerDisposed?.call(_composer); _composer.dispose(); _controller.dispose(); _shellRuns.dispose(); diff --git a/app/lib/features/pipelines/widgets/pipeline_archive_action.dart b/app/lib/features/pipelines/widgets/pipeline_archive_action.dart index 18e7e06f..64a56e33 100644 --- a/app/lib/features/pipelines/widgets/pipeline_archive_action.dart +++ b/app/lib/features/pipelines/widgets/pipeline_archive_action.dart @@ -37,7 +37,7 @@ Widget pipelineActionsMenu( ), if (onOpenInChat != null) SegmentedMenuChoice( - label: 'Open in chat', + label: 'Send to chat…', onSelected: () => onOpenInChat(context, detail, null), ), ], @@ -55,7 +55,7 @@ Widget pipelineActionsMenu( if (onOpenInChat != null) const AppMenuAction( value: false, - label: 'Open in chat', + label: 'Send to chat…', icon: Icons.chat_bubble_outline, ), ], diff --git a/app/lib/features/pipelines/widgets/pipeline_list_panel.dart b/app/lib/features/pipelines/widgets/pipeline_list_panel.dart index 95d0896a..7e958e32 100644 --- a/app/lib/features/pipelines/widgets/pipeline_list_panel.dart +++ b/app/lib/features/pipelines/widgets/pipeline_list_panel.dart @@ -280,7 +280,7 @@ class PipelineListPanel extends StatelessWidget { actions: const [ AppMenuAction( value: true, - label: 'Open in chat', + label: 'Send to chat…', icon: Icons.chat_bubble_outline, ), ], diff --git a/app/lib/features/runs/screen.dart b/app/lib/features/runs/screen.dart index bd2f3229..bb014580 100644 --- a/app/lib/features/runs/screen.dart +++ b/app/lib/features/runs/screen.dart @@ -54,6 +54,7 @@ class RunsScreen extends StatefulWidget { this.sortStore = const SharedPreferencesRunsSortStore(), this.pendingRunStore = const SharedPreferencesPendingRunStore(''), this.onOpenInChat, + this.onSendToChat, }); final ApiGateway gateway; @@ -105,6 +106,7 @@ class RunsScreen extends StatefulWidget { /// scope the Pipelines tab uses. Tests inject a memory store. final PendingRunStore pendingRunStore; final Future Function(BuildContext, JsonMap)? onOpenInChat; + final Future Function(BuildContext, JsonMap, String)? onSendToChat; @override State createState() => _RunsScreenState(); @@ -303,6 +305,9 @@ class _RunsScreenState extends State { onRunOpened: _select, onOpenPipeline: widget.onOpenPipeline, onOpenInChat: widget.onOpenInChat, + onSendToChat: widget.onSendToChat == null + ? null + : (context, run, draft) => widget.onSendToChat!(context, run, draft), initialStageKey: widget.initialStageKey, initialVisit: widget.initialVisit, ); diff --git a/app/lib/features/runs/ui/run_detail_material.dart b/app/lib/features/runs/ui/run_detail_material.dart index e07bb2f3..d9553682 100644 --- a/app/lib/features/runs/ui/run_detail_material.dart +++ b/app/lib/features/runs/ui/run_detail_material.dart @@ -25,6 +25,7 @@ Widget buildMaterialRunDetail({ required String configuredEndpoint, String? initialStageKey, int? initialVisit, + void Function(String draft)? onSendToChat, }) { return RunDetailTabs( run: run, @@ -36,6 +37,7 @@ Widget buildMaterialRunDetail({ configuredEndpoint: configuredEndpoint, initialStageKey: initialStageKey, initialVisit: initialVisit, + onSendToChat: onSendToChat, // A glass strip under the top bar: as wide as its content. header: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/app/lib/features/runs/ui/run_detail_tabs.dart b/app/lib/features/runs/ui/run_detail_tabs.dart index 940078a6..0ee737dc 100644 --- a/app/lib/features/runs/ui/run_detail_tabs.dart +++ b/app/lib/features/runs/ui/run_detail_tabs.dart @@ -12,6 +12,7 @@ import '../../../core/api_gateway.dart'; import '../../graph/widgets/run_graph_view.dart'; import '../../artifacts/ui/artifact_gallery_action.dart'; import '../../artifacts/ui/artifact_gallery_page.dart'; +import '../../artifacts/domain/artifact_chat_context.dart'; import '../../changes/changes.dart'; import 'run_changes_action.dart'; import 'run_detail_content.dart'; @@ -54,6 +55,7 @@ class RunDetailTabs extends StatefulWidget { required this.configuredEndpoint, this.initialStageKey, this.initialVisit, + this.onSendToChat, }); final JsonMap run; @@ -83,6 +85,7 @@ class RunDetailTabs extends StatefulWidget { /// The zero-based index among [initialStageKey]'s recorded visits. Null opens /// the stage's latest visit, exactly as a Graph node click does. final int? initialVisit; + final void Function(String draft)? onSendToChat; @override State createState() => _RunDetailTabsState(); @@ -333,6 +336,7 @@ class _RunDetailTabsState extends State { gateway: widget.gateway, onRunChanged: widget.onRunChanged, configuredEndpoint: widget.configuredEndpoint, + onSendToChat: widget.onSendToChat, onClose: () => Navigator.of(pageContext).pop(), ) : const Center(child: Text('This visit is no longer recorded.')); @@ -493,6 +497,16 @@ class _RunDetailTabsState extends State { embedded: true, openArtifactUrl: _searchArtifactUrl, onOpenArtifactHandled: _searchArtifactHandled, + artifactChatContext: ArtifactChatContext( + runId: '${widget.run['id'] ?? ''}', + runTitle: '${widget.run['title'] ?? widget.run['name'] ?? ''}', + pipelineName: '${widget.run['name'] ?? ''}', + pipelineVersion: widget.run['version'] is num + ? (widget.run['version'] as num).toInt().toString() + : null, + configuredEndpoint: widget.configuredEndpoint, + ), + onSendToChat: widget.onSendToChat, ); case RunDetailTab.changes: final viewer = ChangesViewer( diff --git a/app/lib/features/runs/ui/run_detail_view.dart b/app/lib/features/runs/ui/run_detail_view.dart index 305e2ab8..3ee2abef 100644 --- a/app/lib/features/runs/ui/run_detail_view.dart +++ b/app/lib/features/runs/ui/run_detail_view.dart @@ -25,6 +25,7 @@ class RunDetailView extends StatefulWidget { this.initialStageKey, this.initialVisit, this.onOpenInChat, + this.onSendToChat, }); final RunsController controller; @@ -46,6 +47,7 @@ class RunDetailView extends StatefulWidget { final String? initialStageKey; final int? initialVisit; final Future Function(BuildContext, JsonMap)? onOpenInChat; + final Future Function(BuildContext, JsonMap, String)? onSendToChat; @override State createState() => _RunDetailViewState(); @@ -85,6 +87,9 @@ class _RunDetailViewState extends State { configuredEndpoint: endpoint, initialStageKey: widget.initialStageKey, initialVisit: widget.initialVisit, + onSendToChat: widget.onSendToChat == null + ? null + : (draft) => widget.onSendToChat!(context, run, draft), ); // The top bar becomes the run's: Back to the list, its title over its // number, pipeline and version (a link to that pipeline when the host diff --git a/app/lib/features/runs/ui/run_detail_visit.dart b/app/lib/features/runs/ui/run_detail_visit.dart index 90d4e0fc..b30c6b00 100644 --- a/app/lib/features/runs/ui/run_detail_visit.dart +++ b/app/lib/features/runs/ui/run_detail_visit.dart @@ -22,6 +22,7 @@ class RunVisitPane extends StatefulWidget { required this.onRunChanged, required this.configuredEndpoint, required this.onClose, + this.onSendToChat, }); final JsonMap run; @@ -41,6 +42,7 @@ class RunVisitPane extends StatefulWidget { final String configuredEndpoint; final VoidCallback onClose; + final void Function(String draft)? onSendToChat; @override State createState() => _RunVisitPaneState(); @@ -86,6 +88,7 @@ class _RunVisitPaneState extends State { gateway: widget.gateway, onRunChanged: widget.onRunChanged, configuredEndpoint: widget.configuredEndpoint, + onSendToChat: widget.onSendToChat, facts: RunVisitFactsView(step: widget.step), ), ], diff --git a/app/lib/features/runs/ui/run_detail_visit_artifacts.dart b/app/lib/features/runs/ui/run_detail_visit_artifacts.dart index 23ee33b7..d796cb19 100644 --- a/app/lib/features/runs/ui/run_detail_visit_artifacts.dart +++ b/app/lib/features/runs/ui/run_detail_visit_artifacts.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; +import '../../artifacts/domain/artifact_chat_context.dart'; import '../../artifacts/ui/artifact_gallery_page.dart'; /// The visit's recorded stage artifacts, in recorded order. @@ -20,6 +21,8 @@ class RunVisitArtifacts extends StatelessWidget { required this.visitIndex, required this.runSteps, required this.configuredEndpoint, + required this.run, + this.onSendToChat, }); final JsonMap step; @@ -29,6 +32,8 @@ class RunVisitArtifacts extends StatelessWidget { final List runSteps; final String configuredEndpoint; + final JsonMap run; + final void Function(String draft)? onSendToChat; /// The same gallery as the run's Artifacts tab, focused on this visit. @override @@ -40,6 +45,19 @@ class RunVisitArtifacts extends StatelessWidget { focusIndex: runSteps.isEmpty ? 0 : visitIndex, configuredEndpoint: configuredEndpoint, embedded: true, + artifactChatContext: ArtifactChatContext( + runId: '${run['id'] ?? ''}', + runTitle: '${run['title'] ?? run['name'] ?? ''}', + pipelineName: '${run['name'] ?? ''}', + pipelineVersion: run['version'] is num + ? (run['version'] as num).toInt().toString() + : null, + stageKey: '${step['stage'] ?? ''}', + visit: visitIndex + 1, + configuredEndpoint: configuredEndpoint, + recordedSteps: step, + ), + onSendToChat: onSendToChat, ), ); } diff --git a/app/lib/features/runs/ui/run_detail_visit_documents.dart b/app/lib/features/runs/ui/run_detail_visit_documents.dart index 558387b5..6a39cbf3 100644 --- a/app/lib/features/runs/ui/run_detail_visit_documents.dart +++ b/app/lib/features/runs/ui/run_detail_visit_documents.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../../artifacts/domain/artifact_capture.dart'; +import '../../artifacts/domain/artifact_chat_context.dart'; import '../../artifacts/domain/artifact_document.dart'; import '../../artifacts/domain/artifact_groups.dart'; import '../../artifacts/domain/artifact_record.dart'; @@ -20,11 +21,13 @@ class RunVisitDocuments extends StatelessWidget { required this.step, required this.run, required this.configuredEndpoint, + this.onSendToChat, }); final JsonMap step; final JsonMap run; final String configuredEndpoint; + final void Function(String draft)? onSendToChat; int _visitNumber() { final steps = run['steps']; @@ -80,6 +83,25 @@ class RunVisitDocuments extends StatelessWidget { groups: [group], selectedIdentity: artifactVisitIdentityOf(group, artifact), configuredEndpoint: configuredEndpoint, + onSendToChat: onSendToChat == null + ? null + : (page) => onSendToChat!( + artifactChatReference( + ArtifactChatContext( + runId: '${run['id'] ?? ''}', + runTitle: '${run['title'] ?? run['name'] ?? ''}', + pipelineName: '${run['name'] ?? ''}', + pipelineVersion: run['version'] is num + ? (run['version'] as num).toInt().toString() + : null, + stageKey: '${step['stage'] ?? group.stageKey}', + visit: _visitNumber(), + configuredEndpoint: configuredEndpoint, + ), + page.group, + page.artifact, + ), + ), ); Navigator.of( context, diff --git a/app/lib/features/runs/ui/run_detail_visit_sections.dart b/app/lib/features/runs/ui/run_detail_visit_sections.dart index 27b364fd..9a72f34d 100644 --- a/app/lib/features/runs/ui/run_detail_visit_sections.dart +++ b/app/lib/features/runs/ui/run_detail_visit_sections.dart @@ -96,6 +96,7 @@ Widget runVisitSectionBody({ required ApiGateway gateway, required ValueChanged onRunChanged, required String configuredEndpoint, + void Function(String draft)? onSendToChat, Widget? facts, }) { Widget body(RunVisitSection section) => runVisitSectionBody( @@ -108,6 +109,7 @@ Widget runVisitSectionBody({ gateway: gateway, onRunChanged: onRunChanged, configuredEndpoint: configuredEndpoint, + onSendToChat: onSendToChat, ); switch (section) { case RunVisitSection.summary: @@ -139,6 +141,8 @@ Widget runVisitSectionBody({ visitIndex: visitIndex, runSteps: runSteps, configuredEndpoint: configuredEndpoint, + run: run, + onSendToChat: onSendToChat, ); case RunVisitSection.changes: // Only this visit's own capture; the run's final state is the run's @@ -157,6 +161,7 @@ Widget runVisitSectionBody({ gateway: gateway, onRunChanged: onRunChanged, configuredEndpoint: configuredEndpoint, + onSendToChat: onSendToChat, ); case RunVisitSection.definition: return RunVisitDefinition(run: run, stageKey: stageKey); diff --git a/app/lib/features/runs/ui/run_detail_visit_session.dart b/app/lib/features/runs/ui/run_detail_visit_session.dart index b70e9c8d..a2c42e8c 100644 --- a/app/lib/features/runs/ui/run_detail_visit_session.dart +++ b/app/lib/features/runs/ui/run_detail_visit_session.dart @@ -33,6 +33,7 @@ class RunVisitSession extends StatefulWidget { required this.gateway, required this.onRunChanged, required this.configuredEndpoint, + this.onSendToChat, this.openExternal = openArtifactExternally, }); @@ -42,6 +43,7 @@ class RunVisitSession extends StatefulWidget { final ValueChanged onRunChanged; final String configuredEndpoint; final ArtifactExternalOpen openExternal; + final void Function(String draft)? onSendToChat; @override State createState() => _RunVisitSessionState(); @@ -108,6 +110,7 @@ class _RunVisitSessionState extends State { step: widget.step, run: widget.run, configuredEndpoint: widget.configuredEndpoint, + onSendToChat: widget.onSendToChat, ), ]; // Flat on the page on both hosts; the turn documents below are a flat diff --git a/app/lib/features/runs/ui/run_more_menu.dart b/app/lib/features/runs/ui/run_more_menu.dart index 4bbc3ca3..67b9c007 100644 --- a/app/lib/features/runs/ui/run_more_menu.dart +++ b/app/lib/features/runs/ui/run_more_menu.dart @@ -16,8 +16,8 @@ import '../domain/run_models.dart' show runIdentity; const runMoreMenuKey = ValueKey('run-more-menu'); const deleteRunActionKey = ValueKey('run-delete-action'); const deleteRunActionLabel = 'Delete run'; -const openRunInChatActionKey = ValueKey('run-open-in-chat-action'); -const openRunInChatActionLabel = 'Open in chat'; +const openRunInChatActionKey = ValueKey('run-send-to-chat-action'); +const openRunInChatActionLabel = 'Send to chat…'; /// Whether the run has anything for its more menu. [deletable] says the host /// can apply a deletion, so a finished run offers Delete run. diff --git a/app/test/application/open_in_chat_test.dart b/app/test/application/open_in_chat_test.dart index 14f7c624..890eacc9 100644 --- a/app/test/application/open_in_chat_test.dart +++ b/app/test/application/open_in_chat_test.dart @@ -4,8 +4,13 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/application/open_in_chat.dart'; +import 'package:pipelines_app/application/send_to_chat.dart'; import 'package:pipelines_app/application/open_in_chat_preferences.dart'; import 'package:pipelines_app/features/chat/chat_runtime.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_chat_context.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart'; import 'package:pipelines_app/features/chat/ui/sessions/chat_create_fields.dart'; import 'package:pipelines_app/features/pipelines/pipeline_models.dart'; import 'package:pipelines_app/features/pipelines/pipeline_repository.dart'; @@ -58,6 +63,96 @@ void main() { runtime.dispose(); }); + testWidgets('Send to chat lists and searches existing chats', (tester) async { + final gateway = FakeChatGateway() + ..sessionsReply = { + 'chat_sessions': [ + { + 'id': 'older', + 'title': 'Old notes', + 'directory': '/archive', + 'backend': 'codex', + 'updated_at': '2026-10-01T00:00:00Z', + }, + { + 'id': 'release', + 'title': 'Release review', + 'directory': '/work', + 'backend': 'claude', + 'updated_at': '2026-10-20T00:00:00Z', + }, + ], + }; + final runtime = ChatRuntime(gateway: gateway); + await tester.pumpWidget(const MaterialApp(home: Scaffold())); + final picker = showSendToChatPicker( + context: tester.element(find.byType(Scaffold)), + runtime: runtime, + selectChat: (_) {}, + directory: '/work', + title: 'Artifact', + draft: 'artifact', + ); + await tester.pumpAndSettle(); + expect(find.text('New chat'), findsOneWidget); + expect(find.text('Release review'), findsOneWidget); + expect(find.text('Old notes'), findsOneWidget); + // A short list is only as tall as its rows, with no empty space below. + final rows = tester + .widgetList(find.byType(ListTile)) + .map((tile) => tester.getSize(find.byWidget(tile)).height) + .fold(0, (sum, height) => sum + height); + expect(tester.getSize(find.byType(ListView)).height, closeTo(rows, 1)); + await tester.enterText(find.byType(TextField), 'release'); + await tester.pump(); + expect(find.text('Release review'), findsOneWidget); + expect(find.text('Old notes'), findsNothing); + await tester.tap(find.text('New chat')); + await picker; + runtime.dispose(); + }); + + testWidgets('Send to chat appends an existing draft and focuses it', ( + tester, + ) async { + final gateway = FakeChatGateway() + ..sessionsReply = { + 'chat_sessions': [ + { + 'id': 'existing', + 'title': 'Existing chat', + 'directory': '/work', + 'backend': 'opencode', + 'updated_at': '2026-10-20T00:00:00Z', + }, + ], + }; + final runtime = ChatRuntime(gateway: gateway); + final composer = ChatComposerController(gateway, 'existing'); + await composer.setDraft('Before'); + runtime.registerComposer('existing', composer); + var selected = ''; + await tester.pumpWidget(const MaterialApp(home: Scaffold())); + final picker = showSendToChatPicker( + context: tester.element(find.byType(Scaffold)), + runtime: runtime, + selectChat: (id) => selected = id, + directory: '/work', + title: 'Artifact', + draft: 'Artifact details', + ); + await tester.pumpAndSettle(); + await tester.tap(find.text('Existing chat')); + await picker; + await tester.pump(); + expect(selected, 'existing'); + expect(composer.draft, 'Before\nArtifact details'); + expect(runtime.composerFocus.take('existing'), isTrue); + expect(gateway.calls.where((call) => call.type == 'chat_send'), isEmpty); + composer.dispose(); + runtime.dispose(); + }); + testWidgets('a harness the server no longer offers falls back to the ' 'default, without the saved model', (tester) async { SharedPreferences.setMockInitialValues({}); @@ -140,6 +235,45 @@ void main() { ); }); + test('artifact references identify provenance and inspection', () { + final reference = artifactChatReference( + const ArtifactChatContext( + runId: '42', + runTitle: 'Build', + pipelineName: 'Release', + stageKey: 'test', + visit: 2, + configuredEndpoint: 'ws://server.example/connect', + ), + const ArtifactGroup( + stageKey: 'test', + visit: 2, + artifacts: [ + ArtifactRecord( + name: 'report.txt', + contentType: 'text/plain', + sizeBytes: 12, + url: '/artifacts/42/2/report.txt', + raw: {}, + ), + ], + ), + const ArtifactRecord( + name: 'report.txt', + contentType: 'text/plain', + sizeBytes: 12, + url: '/artifacts/42/2/report.txt', + raw: {}, + ), + ); + expect(reference, contains('report.txt')); + expect(reference, contains('pipelines inspect 42')); + expect( + reference, + contains('http://server.example/artifacts/42/2/report.txt'), + ); + }); + test('open in chat keeps the more menu available', () { expect(showRunMoreMenu({'id': 42}, canOpenInChat: true), isTrue); }); @@ -226,7 +360,7 @@ void main() { runtime.dispose(); }); - testWidgets('run list More selects Open in chat on desktop', (tester) async { + testWidgets('run list More selects Send to chat on desktop', (tester) async { final run = { 'id': 42, 'title': 'Build', @@ -256,12 +390,12 @@ void main() { await tester.tap(find.byKey(const Key('run-list-more-menu-42'))); await tester.pumpAndSettle(); - expect(find.text('Open in chat'), findsOneWidget); - await tester.tap(find.text('Open in chat')); + expect(find.text('Send to chat…'), findsOneWidget); + await tester.tap(find.text('Send to chat…')); expect(selected, same(run)); }); - testWidgets('run detail More selects Open in chat from the phone sheet', ( + testWidgets('run detail More selects Send to chat from the phone sheet', ( tester, ) async { final run = {'id': 42, 'title': 'Build'}; @@ -291,12 +425,12 @@ void main() { await tester.tap(find.byTooltip('More actions')); await tester.pumpAndSettle(); - expect(find.text('Open in chat'), findsOneWidget); - await tester.tap(find.text('Open in chat')); + expect(find.text('Send to chat…'), findsOneWidget); + await tester.tap(find.text('Send to chat…')); expect(selected, same(run)); }); - testWidgets('pipeline list row More selects Open in chat with latest run', ( + testWidgets('pipeline list row More selects Send to chat with latest run', ( tester, ) async { final fixture = PipelineFixture(); @@ -328,14 +462,14 @@ void main() { await tester.tap(find.byKey(const Key('pipeline-row-more-menu-1'))); await tester.pumpAndSettle(); - expect(find.text('Open in chat'), findsOneWidget); - await tester.tap(find.text('Open in chat')); + expect(find.text('Send to chat…'), findsOneWidget); + await tester.tap(find.text('Send to chat…')); expect(selected?.id, 1); expect(selectedRun?.id, 42); }); testWidgets( - 'pipeline detail actions select Open in chat from phone overflow', + 'pipeline detail actions select Send to chat from phone overflow', (tester) async { final fixture = PipelineFixture(); final gateway = gatewayFor(fixture); @@ -365,8 +499,8 @@ void main() { await tester.tap(find.byTooltip('Pipeline actions')); await tester.pumpAndSettle(); - expect(find.text('Open in chat'), findsOneWidget); - await tester.tap(find.text('Open in chat')); + expect(find.text('Send to chat…'), findsOneWidget); + await tester.tap(find.text('Send to chat…')); expect(selected?.id, detail.id); }, ); diff --git a/app/test/features/artifacts/ui/artifact_gallery_page_test.dart b/app/test/features/artifacts/ui/artifact_gallery_page_test.dart index 57f7f029..db0ba750 100644 --- a/app/test/features/artifacts/ui/artifact_gallery_page_test.dart +++ b/app/test/features/artifacts/ui/artifact_gallery_page_test.dart @@ -3,6 +3,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_chat_context.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_gallery_page.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart'; @@ -116,6 +117,98 @@ void main() { expect(_inDialog('Artifacts · 1 recorded'), findsOneWidget); }); + testWidgets('artifact details offer Send to chat and pass its reference', ( + tester, + ) async { + String? draft; + final steps = [ + step( + stage: 'build', + sequence: 1, + visit: 1, + artifacts: [ + _recorded( + 'build.log', + url: '/artifacts/42/1/build.log', + contentType: 'text/plain', + ), + ], + ), + ]; + tester.view.physicalSize = const Size(800, 1000); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget( + MaterialApp( + home: ArtifactGalleryPage( + steps: steps, + configuredEndpoint: 'http://server.example/connect', + artifactChatContext: const ArtifactChatContext( + runId: '42', + runTitle: 'Build', + pipelineName: 'Release', + stageKey: 'build', + visit: 1, + configuredEndpoint: 'http://server.example/connect', + ), + onSendToChat: (value) => draft = value, + ), + ), + ); + await tester.pumpAndSettle(); + + await tester.tap(find.text('build.log')); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('artifact-send-to-chat'))); + await tester.pumpAndSettle(); + + expect(draft, contains('build.log')); + expect(draft, contains('pipelines inspect 42')); + }); + + testWidgets('artifact viewer offers Send to chat', (tester) async { + String? draft; + final steps = [ + step( + stage: 'build', + sequence: 1, + visit: 1, + artifacts: [ + _recorded( + 'build.log', + url: '/artifacts/42/1/build.log', + contentType: 'text/plain', + ), + ], + ), + ]; + await tester.pumpWidget( + MaterialApp( + home: ArtifactGalleryPage( + steps: steps, + configuredEndpoint: 'http://server.example/connect', + artifactChatContext: const ArtifactChatContext( + runId: '42', + runTitle: 'Build', + pipelineName: 'Release', + stageKey: 'build', + visit: 1, + configuredEndpoint: 'http://server.example/connect', + ), + onSendToChat: (value) => draft = value, + ), + ), + ); + await tester.pumpAndSettle(); + + await tester.tap(find.text('build.log')); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('artifact-send-to-chat'))); + await tester.pumpAndSettle(); + + expect(draft, contains('build.log')); + }); + testWidgets('capture notes and partial label come from the visit step', ( tester, ) async { diff --git a/app/test/features/artifacts/ui/artifact_viewer_page_test.dart b/app/test/features/artifacts/ui/artifact_viewer_page_test.dart index 4072820e..1cff466e 100644 --- a/app/test/features/artifacts/ui/artifact_viewer_page_test.dart +++ b/app/test/features/artifacts/ui/artifact_viewer_page_test.dart @@ -9,11 +9,13 @@ import 'package:pipelines_app/features/artifacts/ui/artifact_video_player.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart'; import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart'; +import 'package:pipelines_app/features/artifacts/domain/gallery_navigation.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_external_open.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_gallery_page.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_content.dart' show ArtifactPreviewBody, artifactPreviewRetryKey; import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_fetch.dart'; +import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_bar.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart'; import 'package:pipelines_app/ui/adaptive/glass_pill.dart'; @@ -44,6 +46,7 @@ Future _pumpViewer( ArtifactFetch? fetch, Widget Function(BuildContext, String)? markdownBuilder, ArtifactExternalOpen? openExternal, + ValueChanged? onSendToChat, double bottomClearance = 0, }) async { final page = ArtifactViewerPage( @@ -54,6 +57,7 @@ Future _pumpViewer( markdownBuilder: markdownBuilder ?? (context, value) => SelectableText(value), openExternal: openExternal ?? (_) async => true, + onSendToChat: onSendToChat, ); final child = MediaQuery( data: MediaQueryData(padding: EdgeInsets.only(bottom: bottomClearance)), @@ -393,10 +397,12 @@ void main() { _group([second], visit: 2), _group([third], visit: 3), ]; + String? sent; await _pumpViewer( tester, groups: groups, selected: artifactVisitIdentity(groups[0], first), + onSendToChat: (page) => sent = page.artifact.name, ); expect(find.text('1 of 3 · image/png'), findsOneWidget); @@ -413,6 +419,8 @@ void main() { await tester.tap(find.byKey(artifactNextKey)); await tester.pumpAndSettle(); expect(find.text('2 of 3 · image/png'), findsOneWidget); + await tester.tap(find.byKey(const Key('artifact-send-to-chat'))); + expect(sent, 'b.png'); await showFacts(tester); expect(find.text('review · visit 2'), findsOneWidget); await hideFacts(tester); diff --git a/app/tool/search_selection_probe_entry.dart b/app/tool/search_selection_probe_entry.dart index d08f7441..44cf9810 100644 --- a/app/tool/search_selection_probe_entry.dart +++ b/app/tool/search_selection_probe_entry.dart @@ -176,6 +176,26 @@ bool _turnFiles = false; /// into the same "unsupported request" error as an incomplete server. final _probeChats = {}; int _probeChatSequence = 0; + +void _installUiReviewChats() { + _probeChats + ..['ui-review'] = { + 'id': 'ui-review', + 'title': 'UI review', + 'directory': '/Users/fixture/workspace', + 'backend': 'opencode', + 'updated_at': '2026-10-20T09:05:00Z', + 'closed_at': null, + } + ..['release-chat'] = { + 'id': 'release-chat', + 'title': 'Release train', + 'directory': '/Users/fixture/workspace', + 'backend': 'opencode', + 'updated_at': '2026-10-20T09:00:00Z', + 'closed_at': null, + }; +} const List _turnFileNames = [ 'input.md', 'memory.md', @@ -852,6 +872,10 @@ class _FixtureSink implements WebSocketSink { /// fallback for `/runs/7`) can still open a deep location: /// /// `?route=/runs/7/stage/build%3Fvisit%3D1` opens that app location; +/// `?ui-review=1&route=/runs/7` exposes the run More menu's +/// `Send to chat…` picker with existing chats at both desktop and phone +/// capture sizes; opening the Artifacts tab and an artifact row exposes the +/// equivalent artifact action; /// `?runs=200` / `?steps=60` append filler runs / run-7 steps for scroll /// performance captures; /// `?running=1` adds an executing run 8 whose duration ticks; @@ -878,6 +902,7 @@ Future main() async { AnimationSpeedController.instance.restore(), ]); final params = fixtureParams(); + if (params['ui-review'] == '1') _installUiReviewChats(); if (params['liveRun'] == '1') _liveRunStatus = 'running'; installHostProbes(params); // `?connect=1` (native only) opens the real launch flow with no saved