App: open a chat, the terminal or a diff in a new window

"Open in new window" sits beside Float: the chat pane and chat list row
menus, a floating chat window's title bar, the terminal options menu and
the diff bar, plus Alt+Shift+Y for the chat with the keyboard (listed in
the shortcut help). Once the window opens the item leaves the main window
as Float takes a pane out of the tiling.

The window is its own app instance at /window/chat/<id>,
/window/terminal?tab=<key> or /window/diff/<token>: only that item, named
after it, with "Bring back to main window". It has its own connection and
writes no shared layout (no open-chat workspace, window store or terminal
layout) and posts no notifications, so they stay the main window's.

Web opens a popup window (a blocked popup offers a tab); Linux and macOS
start a second process with --detached (Flutter's multi-window API is still
experimental); Android and iOS hide the action. The capture kit gains a
follow step for windows a page opens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:47:42 +00:00
parent c4de1de27b
commit 61c7eee2b0
46 changed files with 3223 additions and 72 deletions
@@ -0,0 +1,96 @@
import 'dart:convert';
import 'dart:ui';
import 'detached_platform_stub.dart'
if (dart.library.js_interop) 'detached_platform_web.dart'
if (dart.library.io) 'detached_platform_io.dart'
as host;
import 'detached_route.dart';
/// How a launch went.
enum DetachedLaunch {
/// The window is open (or an open one came to the front).
opened,
/// The browser blocked the popup; a click may open it as a tab.
blocked,
/// Nothing could be opened.
failed,
}
/// A message between a detached window and the main window, as JSON.
typedef DetachedMessage = Map<String, Object?>;
/// The platform's side of detached windows: opening one, the messages they
/// send back to the main window, and a hand-over of data too large for a
/// URL (a diff's files).
///
/// - Web: `window.open` with popup features, `postMessage` to the opener,
/// and `localStorage` for the hand-over.
/// - Linux and macOS: a second process of the app with `--detached <path>`,
/// a line on its standard output, and a temporary file.
/// - Android and iOS: unsupported.
abstract class DetachedPlatform {
/// The app's platform.
static DetachedPlatform instance = host.createDetachedPlatform();
/// Extra query parameters every detached browser window's URL carries.
/// The capture fixture sets its own (`chats=2`, `theme=dark`), so the
/// window it opens runs on the same fixture; the app sets none.
static Map<String, String> Function()? extraQuery;
/// Whether this platform can open detached windows.
bool get supported;
/// Opens [route] in a new window of [size] named [title]; [tab] opens a
/// browser tab instead (from a click, after a blocked popup).
Future<DetachedLaunch> launch(
DetachedRoute route, {
required String title,
required Size size,
bool tab = false,
});
/// Messages the detached windows send to this (main) window.
Stream<DetachedMessage> get messages;
/// Keeps [json] for the window that will ask for [token].
Future<void> put(String token, String json);
/// The data kept under [token], for this window; null when there is none.
Future<String?> take(String token);
/// Sends [message] to the main window that opened this one; false when
/// there is none to receive it.
Future<bool> sendToMain(DetachedMessage message);
/// Closes this detached window.
Future<void> closeSelf();
/// Opens the full app (the main window) at [appPath], in place of this
/// detached window; false when this platform cannot.
Future<bool> becomeMain(String appPath);
}
/// The detached window this launch opens, or null for the main window: the
/// browser location on the web, `--detached <path>` (or the environment) on
/// a desktop.
DetachedRoute? detachedLaunchRoute(List<String> args) =>
host.launchedDetachedRoute(args);
/// The marker a message carries, so the main window ignores anything else.
const detachedMessageMarker = 'pipelines.detached.v1';
String encodeDetachedMessage(DetachedMessage message) =>
jsonEncode({...message, 'marker': detachedMessageMarker});
DetachedMessage? decodeDetachedMessage(String text) {
try {
final value = jsonDecode(text);
if (value is! Map || value['marker'] != detachedMessageMarker) return null;
return Map<String, Object?>.from(value)..remove('marker');
} on FormatException {
return null;
}
}