Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(input-handoff): 代输入——把需要主人填写的输入步骤交给主人 (#6009)

Chris Zhang3f4ec18ec53a
diff --git a/AGENTS.md b/AGENTS.md
index d624db7724..e7193c30e3 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -57,6 +57,9 @@
- 修改 IM 工具授权、来源消息、多端确认或暂停期间的确认回执,或新增 IM 渠道前,
必须先读 `docs/product-rules/im-permission-confirmation.md`;Desktop、Mobile 与共享
packages 共用同一最终决定,渠道收到回答不代表执行已恢复。
+- 新增或修改代输入(`request_input_handoff`、宿主步骤读取与执行、代输入卡、终端 askpass、
+ 单窗口实时画面、设备码识别,或任何经手主人填写值的路径)前,必须先读
+ `docs/product-rules/input-handoff.md`:主人填写的值只交给宿主执行,不进模型、记录、日志、IM 与推送。
- 修改账号用量上限的判定、重置时刻来源,或普通任务/目标模式撞上限额后的等待与自动继续前,
必须先读 `docs/product-rules/usage-limit-auto-continue.md`。
- 新增或修改自动发送/远程发送消息的路径、消息来源标签,或发给模型的来源说明前,必须先读
diff --git a/apps/desktop/native/remote-desktop/macos-capture.m b/apps/desktop/native/remote-desktop/macos-capture.m
index cc4e5f90b3..615949bdf1 100644
--- a/apps/desktop/native/remote-desktop/macos-capture.m
+++ b/apps/desktop/native/remote-desktop/macos-capture.m
@@ -66,7 +66,20 @@ static NSString *standardCursorShape(NSCursor *cursor) {
return @"default";
}
-static NSDictionary *readCursor(CGDirectDisplayID display) {
+// Window-only views report the cursor relative to the window's live frame.
+static CGRect windowBounds(CGWindowID window) {
+ CFArrayRef list = CGWindowListCopyWindowInfo(kCGWindowListOptionIncludingWindow, window);
+ CGRect bounds = CGRectNull;
+ if (list && CFArrayGetCount(list) > 0) {
+ CFDictionaryRef info = CFArrayGetValueAtIndex(list, 0);
+ CFDictionaryRef raw = CFDictionaryGetValue(info, kCGWindowBounds);
+ if (!raw || !CGRectMakeWithDictionaryRepresentation(raw, &bounds)) bounds = CGRectNull;
+ }
+ if (list) CFRelease(list);
+ return bounds;
+}
+
+static NSDictionary *readCursor(CGRect bounds) {
// Read on the main queue. currentSystemCursor returns the actual global shape,
// including cursors supplied by other applications (not this helper's cursor).
typedef boolean_t (*CursorVisible)(void);
@@ -86,8 +99,7 @@ static NSDictionary *readCursor(CGDirectDisplayID display) {
if (!event) return nil;
CGPoint point = CGEventGetLocation(event);
CFRelease(event);
- CGRect bounds = CGDisplayBounds(display);
- if (bounds.size.width <= 0 || bounds.size.height <= 0) return nil;
+ if (CGRectIsNull(bounds) || bounds.size.width <= 0 || bounds.size.height <= 0) return nil;
NSPoint hot = cursor.hotSpot;
return @{
@"visible": visible() && CGRectContainsPoint(bounds, point) ? @YES : @NO,
@@ -103,11 +115,21 @@ static NSDictionary *readCursor(CGDirectDisplayID display) {
int main(int argc, const char *argv[]) {
@autoreleasepool {
- // Overlay: <display> cursor-overlay <fps> <quality> <physical max edge, 0 = logical> <max JPEG bytes> [excluded]
+ // Overlay: <display> cursor-overlay <fps> <quality> <physical max edge, 0 = logical> <max JPEG bytes> [excluded | window:<id>]
BOOL overlay = (argc == 7 || argc == 8) && strcmp(argv[2], "cursor-overlay") == 0;
if (argc != 2 && argc != 3 && !overlay) return 2;
NSString *excluded = (overlay && argc == 8) || (!overlay && argc == 3)
? [NSString stringWithUTF8String:argv[argc - 1]] : @"";
+ // 代输入 live view: only this one window is captured, never the rest of the screen.
+ CGWindowID onlyWindow = 0;
+ if ([excluded hasPrefix:@"window:"]) {
+ char *windowEnd = NULL;
+ const char *digits = argv[argc - 1] + 7;
+ unsigned long id = strtoul(digits, &windowEnd, 10);
+ if (!overlay || !*digits || *windowEnd || id == 0 || id > UINT32_MAX) return 2;
+ onlyWindow = (CGWindowID)id;
+ excluded = @"";
+ }
int fps = overlay && strcmp(argv[3], "60") == 0 ? 60 : (overlay ? 30 : 15);
double quality = overlay ? atof(argv[4]) : 0.55;
if (quality < 0.1 || quality > 1) return 2;
@@ -127,7 +149,7 @@ int main(int argc, const char *argv[]) {
StartStream start = (StartStream)dlsym(RTLD_DEFAULT, "CGDisplayStreamStart");
const CFStringRef *intervalKey = dlsym(RTLD_DEFAULT, "kCGDisplayStreamMinimumFrameTime");
const CFStringRef *cursorKey = dlsym(RTLD_DEFAULT, "kCGDisplayStreamShowCursor");
- if (!excluded.length && (!create || !start || !intervalKey || !cursorKey)) return 4;
+ if (!excluded.length && !onlyWindow && (!create || !start || !intervalKey || !cursorKey)) return 4;
CGDirectDisplayID display = (uint32_t)value;
size_t width = CGDisplayPixelsWide(display), height = CGDisplayPixelsHigh(display);
if (!width || !height) return 2;
@@ -165,7 +187,9 @@ int main(int argc, const char *argv[]) {
NSData *data;
if (overlay) {
__block NSDictionary *cursor = nil;
- if (separateCursor) dispatch_sync(dispatch_get_main_queue(), ^{ cursor = readCursor(display); });
+ if (separateCursor) dispatch_sync(dispatch_get_main_queue(), ^{
+ cursor = readCursor(onlyWindow ? windowBounds(onlyWindow) : CGDisplayBounds(display));
+ });
NSDictionary *frame = @{@"jpeg": [latest base64EncodedStringWithOptions:0], @"cursor": cursor ?: [NSNull null]};
NSMutableData *line = [[NSJSONSerialization dataWithJSONObject:frame options:0 error:NULL] mutableCopy];
[line appendBytes:"\n" length:1];
@@ -208,7 +232,43 @@ int main(int argc, const char *argv[]) {
reply();
}
};
- if (excluded.length) {
+ if (onlyWindow) {
+ double backing = 1;
+ CGDisplayModeRef displayMode = CGDisplayCopyDisplayMode(display);
+ if (displayMode) {
+ backing = MAX(1.0, (double)CGDisplayModeGetPixelHeight(displayMode) / MAX(1.0, (double)CGDisplayPixelsHigh(display)));
+ CGDisplayModeRelease(displayMode);
+ }
+ if (!physicalEdge) backing = 1; // the logical tier stays in points
+ [SCShareableContent getShareableContentExcludingDesktopWindows:YES onScreenWindowsOnly:YES
+ completionHandler:^(SCShareableContent *content, NSError *error) {
+ if (error) _exit(5);
+ SCWindow *selected = nil;
+ for (SCWindow *candidate in content.windows) if (candidate.windowID == onlyWindow) selected = candidate;
+ // A window that is gone or hidden is never replaced by anything else.
+ if (!selected || selected.frame.size.width < 1 || selected.frame.size.height < 1) _exit(5);
+ SCContentFilter *filter = [[SCContentFilter alloc] initWithDesktopIndependentWindow:selected];
+ double windowWidth = selected.frame.size.width * backing, windowHeight = selected.frame.size.height * backing;
+ double fit = MIN(1.0, edgeLimit / MAX(windowWidth, windowHeight));
+ SCStreamConfiguration *config = [SCStreamConfiguration new];
+ config.width = MAX(2, (size_t)(windowWidth * fit) & ~(size_t)1);
+ config.height = MAX(2, (size_t)(windowHeight * fit) & ~(size_t)1);
+ // Fill the frame, so a point in the picture is the same fraction of the window.
+ if ([config respondsToSelector:@selector(setScalesToFit:)]) [config setValue:@YES forKey:@"scalesToFit"];
+ if ([config respondsToSelector:@selector(setPreservesAspectRatio:)]) [config setValue:@NO forKey:@"preservesAspectRatio"];
+ config.minimumFrameInterval = CMTimeMake(1, fps);
+ config.showsCursor = NO;
+ config.pixelFormat = kCVPixelFormatType_32BGRA;
+ config.queueDepth = 3;
+ PrivacyCaptureOutput *output = [PrivacyCaptureOutput new];
+ output.handler = receiveFrame;
+ output.stream = [[SCStream alloc] initWithFilter:filter configuration:config delegate:output];
+ NSError *failure = nil;
+ if (![output.stream addStreamOutput:output type:SCStreamOutputTypeScreen sampleHandlerQueue:queue error:&failure]) _exit(5);
+ CFRetain((__bridge CFTypeRef)output);
+ [output.stream startCaptureWithCompletionHandler:^(NSError *failure) { if (failure) _exit(5); }];
+ }];
+ } else if (excluded.length) {
NSArray<NSString *> *ids = [excluded componentsSeparatedByString:@","];
// Explicit exclusion is mandatory: NSWindowSharingNone alone is ignored
// by modern ScreenCaptureKit. Never fall back to an unfiltered stream.
diff --git a/apps/desktop/native/remote-desktop/macos-input.swift b/apps/desktop/native/remote-desktop/macos-input.swift
index eb2da0ec3a..e911db4d52 100644
--- a/apps/desktop/native/remote-desktop/macos-input.swift
+++ b/apps/desktop/native/remote-desktop/macos-input.swift
@@ -4,6 +4,7 @@ import AppKit
import IOKit.graphics
import Security
import Darwin
+import Vision
#if !DESKTOP_INPUT_TEST
// This guard precedes every entrypoint, including selection and permission UI.
@@ -188,7 +189,81 @@ func releaseAll() {
for b in Array(buttons) { mouse(b, false) }
for k in Array(keys) { key(k, false) }
}
+// ── 代输入 live view: input reaches only one window of one app ──
+// Started with `--window <CGWindowID> <pid>`. Pointer positions arrive as 0–1
+// fractions of that window and follow it if it moves; a press or hover must land
+// where the window is on top, a drag stays inside it, and releases always land.
+// Keys and text go only while the app is focused, never to system shortcuts.
+struct HandoffConfine { let window: CGWindowID; let pid: Int32 }
+var confine: HandoffConfine?
+func confineFrame(_ c: HandoffConfine) -> CGRect? {
+ guard let infos = CGWindowListCopyWindowInfo([.optionIncludingWindow], c.window) as? [[String: Any]],
+ let info = infos.first, (info[kCGWindowOwnerPID as String] as? Int32) == c.pid,
+ info[kCGWindowIsOnscreen as String] as? Bool ?? false,
+ let raw = info[kCGWindowBounds as String] as? NSDictionary,
+ let bounds = CGRect(dictionaryRepresentation: raw), bounds.width >= 1, bounds.height >= 1 else { return nil }
+ return bounds
+}
+/** The app taking keyboard input right now, read live (a CLI tool's NSWorkspace can lag). */
+func confineFocusedPid() -> Int32? {
+ let system = AXUIElementCreateSystemWide()
+ AXUIElementSetMessagingTimeout(system, 0.3)
+ guard let app = handoffElement(handoffAttr(system, kAXFocusedApplicationAttribute)) else { return nil }
+ var pid: Int32 = 0
+ return AXUIElementGetPid(app, &pid) == .success ? pid : nil
+}
+/**
+ * Keys go to the focused window of the focused app. Only the confined window
+ * itself may take them: another window of the same app (another browser
+ * window) is refused, whatever the live view shows.
+ */
+func confineFocusedWindow(_ c: HandoffConfine) -> Bool {
+ guard confineFocusedPid() == c.pid, let bounds = confineFrame(c) else { return false }
+ let app = AXUIElementCreateApplication(c.pid)
+ AXUIElementSetMessagingTimeout(app, 0.3)
+ guard let window = handoffElement(handoffAttr(app, kAXFocusedWindowAttribute)), let frame = handoffFrame(window) else { return false }
+ return handoffSameFrame(frame, [Double(bounds.minX), Double(bounds.minY), Double(bounds.width), Double(bounds.height)])
+}
+let confineSystemKeys: Set<String> = ["Tab", "Space", "Backquote", "Escape", "ArrowLeft", "ArrowRight", "ArrowDown", "ArrowUp"]
+func confined(_ event: [String: Any], _ c: HandoffConfine) -> [String: Any]? {
+ switch event["kind"] as? String {
+ case "move", "button":
+ let up = event["kind"] as? String == "button" && event["down"] as? Bool == false
+ guard let frame = confineFrame(c) else {
+ // The window is gone: only let go of what is held, where it is.
+ return up ? event.merging(["x": Double(location.x), "y": Double(location.y)]) { $1 } : nil
+ }
+ guard let x = event["x"] as? Double, let y = event["y"] as? Double, x.isFinite, y.isFinite else { return nil }
+ let point = CGPoint(x: frame.minX + min(max(x, 0), 1) * (frame.width - 1),
+ y: frame.minY + min(max(y, 0), 1) * (frame.height - 1))
+ let result = event.merging(["x": Double(point.x), "y": Double(point.y)]) { $1 }
+ if up || !buttons.isEmpty { return result }
+ return handoffOwnsPoint(c.pid, point) ? result : nil
+ case "key":
+ guard let code = event["code"] as? String, let native = keyCodes[code], let down = event["down"] as? Bool else { return nil }
+ if !down { return keys.contains(native) ? event : nil }
+ if code.hasPrefix("F"), code.count <= 3, Int(code.dropFirst()) != nil { return nil }
+ let command = keys.contains(55), control = keys.contains(59)
+ if (command || control) && confineSystemKeys.contains(code) || command && control { return nil }
+ return confineFocusedWindow(c) ? event : nil
+ case "text":
+ return confineFocusedWindow(c) ? event : nil
+ case "scroll":
+ guard let frame = confineFrame(c), frame.contains(location), handoffOwnsPoint(c.pid, location) else { return nil }
+ return event
+ default:
+ return nil
+ }
+}
func apply(_ event: [String: Any]) {
+ if let c = confine, event["kind"] as? String != "release" {
+ guard let allowed = confined(event, c) else { return }
+ applyEvent(allowed)
+ } else {
+ applyEvent(event)
+ }
+}
+func applyEvent(_ event: [String: Any]) {
guard let kind = event["kind"] as? String else { return }
if kind == "release" { releaseAll(); return }
if kind == "move" || kind == "button" {
@@ -248,10 +323,561 @@ struct PrivacyInputGate {
}
}
+// MARK: - Input handoff (代输入)
+// One JSON request on stdin, one JSON reply on stdout. Owner values arrive only
+// on stdin and are never printed. Text fields only report whether they contain
+// text; secure fields never report a value or length.
+
+let handoffMaxWalked = 6000
+let handoffMaxEmitted = 1500
+let handoffMaxDepth = 64
+let handoffInteresting: Set<String> = [
+ "AXButton", "AXLink", "AXTextField", "AXTextArea", "AXComboBox", "AXPopUpButton",
+ "AXCheckBox", "AXRadioButton", "AXRadioGroup", "AXMenuButton", "AXStaticText",
+ "AXHeading", "AXWebArea", "AXDateTimeArea", "AXDisclosureTriangle", "AXTabGroup", "AXSearchField",
+ "AXMenuItem", "AXSheet",
+]
+
+func handoffAttr(_ element: AXUIElement, _ name: String) -> CFTypeRef? {
+ var value: CFTypeRef?
+ return AXUIElementCopyAttributeValue(element, name as CFString, &value) == .success ? value : nil
+}
+func handoffString(_ element: AXUIElement, _ name: String, limit: Int = 300) -> String? {
+ guard let raw = handoffAttr(element, name) else { return nil }
+ var text: String?
+ if let value = raw as? String { text = value }
+ else if let value = raw as? NSAttributedString { text = value.string }
+ else if CFGetTypeID(raw) == CFURLGetTypeID() { text = (raw as! URL).absoluteString }
+ guard let result = text?.trimmingCharacters(in: .whitespacesAndNewlines), !result.isEmpty else { return nil }
+ return String(result.prefix(limit))
+}
+func handoffBool(_ element: AXUIElement, _ name: String) -> Bool? {
+ guard let raw = handoffAttr(element, name) else { return nil }
+ if let value = raw as? Bool { return value }
+ if let value = raw as? NSNumber { return value.boolValue }
+ return nil
+}
+func handoffFrame(_ element: AXUIElement) -> [Double]? {
+ var point = CGPoint.zero, size = CGSize.zero
+ guard let p = handoffAttr(element, kAXPositionAttribute), let s = handoffAttr(element, kAXSizeAttribute),
+ CFGetTypeID(p) == AXValueGetTypeID(), CFGetTypeID(s) == AXValueGetTypeID(),
+ AXValueGetValue(p as! AXValue, .cgPoint, &point), AXValueGetValue(s as! AXValue, .cgSize, &size) else { return nil }
+ return [Double(point.x), Double(point.y), Double(size.width), Double(size.height)]
+}
+func handoffChildren(_ element: AXUIElement) -> [AXUIElement] {
+ guard let raw = handoffAttr(element, kAXChildrenAttribute), let children = raw as? [AXUIElement] else { return [] }
+ return children
+}
+func handoffElement(_ raw: CFTypeRef?) -> AXUIElement? {
+ guard let raw = raw, CFGetTypeID(raw) == AXUIElementGetTypeID() else { return nil }
+ return (raw as! AXUIElement)
+}
+func handoffIsSecure(_ element: AXUIElement) -> Bool {
+ handoffString(element, kAXSubroleAttribute) == "AXSecureTextField"
+}
+/** Identity checked before acting: structure and labels only, never values. */
+func handoffFingerprint(_ element: AXUIElement) -> String {
+ let titleElement = handoffElement(handoffAttr(element, kAXTitleUIElementAttribute))
+ return [
+ handoffString(element, kAXRoleAttribute) ?? "",
+ handoffString(element, kAXSubroleAttribute) ?? "",
+ handoffString(element, kAXTitleAttribute) ?? "",
+ handoffString(element, kAXDescriptionAttribute) ?? "",
+ handoffString(element, kAXPlaceholderValueAttribute) ?? "",
+ titleElement.flatMap { handoffString($0, kAXValueAttribute) ?? handoffString($0, kAXTitleAttribute) } ?? "",
+ ].joined(separator: "|")
+}
+func handoffPrepare(_ app: AXUIElement) {
+ AXUIElementSetMessagingTimeout(app, 0.5)
+ // Chromium/Electron only build their web accessibility tree for assistive clients.
+ AXUIElementSetAttributeValue(app, "AXManualAccessibility" as CFString, kCFBooleanTrue)
+}
+func handoffWindows(_ app: AXUIElement) -> [AXUIElement] {
+ guard let raw = handoffAttr(app, kAXWindowsAttribute), let windows = raw as? [AXUIElement] else { return [] }
+ return windows
+}
+func handoffResolveWindow(_ app: AXUIElement, _ request: [String: Any]) -> (AXUIElement, Int)? {
+ let windows = handoffWindows(app)
+ if let spec = request["window"] as? [String: Any] {
+ let title = spec["title"] as? String
+ if let index = spec["index"] as? Int, index >= 0, index < windows.count,
+ title == nil || handoffString(windows[index], kAXTitleAttribute) ?? "" == title! { return (windows[index], index) }
+ if let title = title, let index = windows.firstIndex(where: { handoffString($0, kAXTitleAttribute) ?? "" == title }) {
+ return (windows[index], index)
+ }
+ return nil
+ }
+ for name in [kAXFocusedWindowAttribute, kAXMainWindowAttribute] {
+ if let window = handoffElement(handoffAttr(app, name)),
+ let index = windows.firstIndex(where: { CFEqual($0, window) }) { return (window, index) }
+ }
+ return windows.isEmpty ? nil : (windows[0], 0)
+}
+func handoffResolveRef(_ window: AXUIElement, _ ref: String) -> AXUIElement? {
+ var element = window
+ for part in ref.split(separator: ".") {
+ guard let index = Int(part) else { return nil }
+ let children = handoffChildren(element)
+ guard index >= 0, index < children.count else { return nil }
+ element = children[index]
+ }
+ return element
+}
+func handoffNode(_ element: AXUIElement, ref: String, depth: Int, inAlert: Bool) -> [String: Any]? {
+ guard let role = handoffString(element, kAXRoleAttribute) else { return nil }
+ let subrole = handoffString(element, kAXSubroleAttribute)
+ let alertGroup = subrole == "AXApplicationAlert" || subrole == "AXApplicationAlertDialog"
+ guard handoffInteresting.contains(role) || alertGroup else { return nil }
+ var node: [String: Any] = ["ref": ref, "role": role, "depth": depth, "fp": handoffFingerprint(element)]
+ if let subrole = subrole { node["subrole"] = subrole }
+ if let title = handoffString(element, kAXTitleAttribute) { node["title"] = title }
+ if let description = handoffString(element, kAXDescriptionAttribute) { node["desc"] = description }
+ if let placeholder = handoffString(element, kAXPlaceholderValueAttribute) { node["placeholder"] = placeholder }
+ if let help = handoffString(element, kAXHelpAttribute) { node["help"] = help }
+ if let identifier = handoffString(element, "AXDOMIdentifier", limit: 64) { node["domId"] = identifier }
+ if let titleElement = handoffElement(handoffAttr(element, kAXTitleUIElementAttribute)),
+ let text = handoffString(titleElement, kAXValueAttribute) ?? handoffString(titleElement, kAXTitleAttribute) {
+ node["titleElement"] = text
+ }
+ node["enabled"] = handoffBool(element, kAXEnabledAttribute) ?? true
+ if handoffBool(element, kAXFocusedAttribute) == true { node["focused"] = true }
+ if handoffBool(element, "AXRequired") == true { node["required"] = true }
+ if let frame = handoffFrame(element) { node["frame"] = frame }
+ if inAlert || alertGroup { node["alert"] = true }
+ switch role {
+ case "AXTextField", "AXTextArea", "AXComboBox", "AXSearchField", "AXDateTimeArea":
+ if handoffIsSecure(element) {
+ node["secure"] = true
+ } else if let raw = handoffAttr(element, kAXValueAttribute), let text = raw as? String {
+ node["hasValue"] = !text.isEmpty
+ }
+ case "AXCheckBox", "AXRadioButton":
+ if let raw = handoffAttr(element, kAXValueAttribute), let number = raw as? NSNumber { node["checked"] = number.intValue != 0 }
+ case "AXPopUpButton", "AXStaticText", "AXHeading":
+ if let value = handoffString(element, kAXValueAttribute) { node["value"] = value }
+ case "AXWebArea", "AXLink":
+ if let url = handoffString(element, kAXURLAttribute, limit: 2048) { node["url"] = url }
+ default: break
+ }
+ if role == "AXPopUpButton" || role == "AXComboBox" {
+ let items = handoffMenuItems(element, limit: 200)
+ if !items.isEmpty { node["options"] = items }
+ }
+ if handoffBool(element, kAXExpandedAttribute) == true { node["expanded"] = true }
+ return node
+}
+/** Menu items already exposed under a pop-up (web selects) without opening it. */
+func handoffMenuItems(_ element: AXUIElement, limit: Int) -> [String] {
+ var result: [String] = []
+ var stack: [(AXUIElement, Int)] = handoffChildren(element).map { ($0, 0) }
+ while result.count < limit, case let (current, depth)? = stack.popLast() {
+ let role = handoffString(current, kAXRoleAttribute)
+ if role == "AXMenuItem" || role == "AXListItem" || role == "AXStaticText" && depth > 0 {
+ if let title = handoffString(current, kAXTitleAttribute) ?? handoffString(current, kAXValueAttribute)
+ ?? handoffString(current, kAXDescriptionAttribute) {
+ result.append(title)
+ continue
+ }
+ }
+ if depth < 3 { stack.append(contentsOf: handoffChildren(current).reversed().map { ($0, depth + 1) }) }
+ }
+ return result
+}
+func handoffSnapshot(_ request: [String: Any]) -> [String: Any] {
+ guard let pid = request["pid"] as? Int32 ?? (request["pid"] as? Int).map({ Int32($0) }),
+ let running = NSRunningApplication(processIdentifier: pid) else { return ["error": "target_gone"] }
+ let app = AXUIElementCreateApplication(pid)
+ handoffPrepare(app)
+ guard let resolved = handoffResolveWindow(app, request) else { return ["error": "target_gone"] }
+ let (window, index) = resolved
+ var nodes: [[String: Any]] = []
+ var walked = 0
+ var stack: [(AXUIElement, String, Int, Bool)] = handoffChildren(window).enumerated().reversed().map { ($0.element, String($0.offset), 1, false) }
+ while case let (element, ref, depth, inAlert)? = stack.popLast() {
+ walked += 1
+ if walked > handoffMaxWalked || nodes.count >= handoffMaxEmitted { break }
+ let node = handoffNode(element, ref: ref, depth: depth, inAlert: inAlert)
+ if let node = node { nodes.append(node) }
+ let role = node?["role"] as? String
+ // Interactive leaves: their children are presentation details or menu items read above.
+ if ["AXButton", "AXTextField", "AXTextArea", "AXPopUpButton", "AXComboBox", "AXStaticText", "AXCheckBox", "AXRadioButton", "AXSearchField", "AXMenuItem"].contains(role ?? "") { continue }
+ if depth >= handoffMaxDepth { continue }
+ let alert = inAlert || node?["alert"] as? Bool == true
+ let children = handoffChildren(element)
+ for (offset, child) in children.enumerated().reversed() { stack.append((child, "\(ref).\(offset)", depth + 1, alert)) }
+ }
+ var result: [String: Any] = [
+ "pid": Int(pid), "app": running.localizedName ?? "", "bundleId": running.bundleIdentifier ?? "",
+ "frontmost": NSWorkspace.shared.frontmostApplication?.processIdentifier == pid,
+ "window": ["index": index, "title": handoffString(window, kAXTitleAttribute) ?? "",
+ "frame": handoffFrame(window) ?? [], "modal": handoffBool(window, kAXModalAttribute) ?? false] as [String: Any],
+ "nodes": nodes, "truncated": walked > handoffMaxWalked || nodes.count >= handoffMaxEmitted,
+ ]
+ if let focused = handoffElement(handoffAttr(app, kAXFocusedUIElementAttribute)), handoffIsSecure(focused) {
+ result["secureFocused"] = true
+ }
+ return result
+}
+/**
+ * Whether the agent's next keystrokes would land in a password field: the
+ * element at a screen point (top-left origin) of this app, or the app's
+ * focused element. Reads roles only, never values.
+ */
+func handoffSecureTarget(_ request: [String: Any]) -> [String: Any] {
+ guard let pid = request["pid"] as? Int32 ?? (request["pid"] as? Int).map({ Int32($0) }),
+ NSRunningApplication(processIdentifier: pid) != nil else { return ["error": "target_gone"] }
+ let app = AXUIElementCreateApplication(pid)
+ AXUIElementSetMessagingTimeout(app, 0.5)
+ var element: AXUIElement?
+ if let point = request["point"] as? [Double], point.count == 2 {
+ var hit: AXUIElement?
+ if AXUIElementCopyElementAtPosition(app, Float(point[0]), Float(point[1]), &hit) == .success { element = hit }
+ } else {
+ element = handoffElement(handoffAttr(app, kAXFocusedUIElementAttribute))
+ }
+ // A secure field may report an inner text element at the point; check two parents.
+ var current = element
+ for _ in 0..<3 {
+ guard let candidate = current else { break }
+ if handoffIsSecure(candidate) { return ["secure": true] }
+ current = handoffElement(handoffAttr(candidate, kAXParentAttribute))
+ }
+ return ["secure": false]
+}
+func handoffWindowList() -> [String: Any] {
+ var pids = Set<Int32>()
+ if let infos = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] {
+ for info in infos where (info[kCGWindowLayer as String] as? Int) == 0 {
+ if let pid = info[kCGWindowOwnerPID as String] as? Int32 { pids.insert(pid) }
+ }
+ }
+ var apps: [[String: Any]] = []
+ for pid in pids {
+ guard let running = NSRunningApplication(processIdentifier: pid), running.activationPolicy == .regular else { continue }
+ let element = AXUIElementCreateApplication(pid)
+ AXUIElementSetMessagingTimeout(element, 0.3)
+ let focused = handoffElement(handoffAttr(element, kAXFocusedWindowAttribute))
+ let windows = handoffWindows(element).enumerated().map { offset, window -> [String: Any] in
+ ["index": offset, "title": handoffString(window, kAXTitleAttribute) ?? "",
+ "frame": handoffFrame(window) ?? [], "focused": focused.map { CFEqual($0, window) } ?? false,
+ "minimized": handoffBool(window, kAXMinimizedAttribute) ?? false]
+ }
+ apps.append(["pid": Int(pid), "app": running.localizedName ?? "", "bundleId": running.bundleIdentifier ?? "",
+ "windows": windows])
+ }
+ return ["frontmost": Int(NSWorkspace.shared.frontmostApplication?.processIdentifier ?? 0), "apps": apps]
+}
+let handoffSource = CGEventSource(stateID: .privateState)
+func handoffKey(_ code: CGKeyCode, flags: CGEventFlags = []) {
+ for down in [true, false] {
+ let event = CGEvent(keyboardEventSource: handoffSource, virtualKey: code, keyDown: down)
+ event?.flags = flags
+ event?.post(tap: .cghidEventTap)
+ usleep(6000)
+ }
+}
+/// Typed keys travel through the window server's queue, while an accessibility press reaches the
+/// app at once: give the queue time to drain so a press right after cannot overtake the last keys.
+func handoffTypeAndSettle(_ text: String) {
+ handoffType(text)
+ usleep(useconds_t(min(1_500_000, 300_000 + 10_000 * text.count)))
+}
+func handoffType(_ text: String) {
+ for character in text {
+ var units = Array(String(character).utf16)
+ for down in [true, false] {
+ let event = CGEvent(keyboardEventSource: handoffSource, virtualKey: 0, keyDown: down)
+ event?.keyboardSetUnicodeString(stringLength: units.count, unicodeString: &units)
+ event?.post(tap: .cghidEventTap)
+ }
+ usleep(4000)
+ }
+}
+func handoffClick(_ frame: [Double]) {
+ guard frame.count == 4, frame[2] > 0, frame[3] > 0 else { return }
+ let point = CGPoint(x: frame[0] + frame[2] / 2, y: frame[1] + frame[3] / 2)
+ for type in [CGEventType.leftMouseDown, .leftMouseUp] {
+ let event = CGEvent(mouseEventSource: handoffSource, mouseType: type, mouseCursorPosition: point, mouseButton: .left)
+ event?.setIntegerValueField(.mouseEventClickState, value: 1)
+ event?.post(tap: .cghidEventTap)
+ usleep(20000)
+ }
+}
+func handoffFocused(_ app: AXUIElement, is element: AXUIElement) -> Bool {
+ guard let focused = handoffElement(handoffAttr(app, kAXFocusedUIElementAttribute)) else { return false }
+ return CFEqual(focused, element)
+}
+/// The app that takes typed keys right now, read fresh from accessibility: this short-lived
+/// process never runs its event loop, so NSWorkspace's frontmost app goes stale inside it.
+func handoffFrontPid() -> Int32? {
+ let system = AXUIElementCreateSystemWide()
+ for _ in 0..<3 {
+ if let focused = handoffElement(handoffAttr(system, kAXFocusedApplicationAttribute)) {
+ var pid: pid_t = 0
+ if AXUIElementGetPid(focused, &pid) == .success { return pid }
+ }
+ usleep(20000)
+ }
+ return nil
+}
+func handoffWaitFront(_ pid: Int32, _ seconds: Double) -> Bool {
+ let deadline = Date().addingTimeInterval(seconds)
+ while handoffFrontPid() != pid {
+ if Date() >= deadline { return false }
+ usleep(40000)
+ }
+ return true
+}
+/// Bring the window forward. Reports whether its app now takes keys: typing must never go anywhere else.
+@discardableResult
+func handoffActivate(_ pid: Int32, _ window: AXUIElement) -> Bool {
+ let front = handoffFrontPid() == pid
+ if !front {
+ _ = NSRunningApplication(processIdentifier: pid)?.activate(options: [.activateIgnoringOtherApps])
+ AXUIElementSetAttributeValue(AXUIElementCreateApplication(pid), kAXFrontmostAttribute as CFString, kCFBooleanTrue)
+ }
+ AXUIElementPerformAction(window, kAXRaiseAction as CFString)
+ AXUIElementSetAttributeValue(window, kAXMainAttribute as CFString, kCFBooleanTrue)
+ if front || handoffWaitFront(pid, 0.6) { return true }
+ // macOS may refuse to bring another app forward for a background helper. A click on the window's
+ // own title bar still does, as the owner's click would; only when that spot is the bare window.
+ guard let frame = handoffFrame(window), frame[2] > 60, frame[3] > 30 else { return false }
+ let point = CGPoint(x: frame[0] + frame[2] / 2, y: frame[1] + 8)
+ var hit: AXUIElement?
+ guard handoffOwnsPoint(pid, point),
+ AXUIElementCopyElementAtPosition(AXUIElementCreateApplication(pid), Float(point.x), Float(point.y), &hit) == .success,
+ let spot = hit, ["AXWindow", "AXStaticText"].contains(handoffString(spot, kAXRoleAttribute) ?? "")
+ else { return false }
+ handoffClick([point.x - 0.5, point.y - 0.5, 1, 1])
+ return handoffWaitFront(pid, 1.0)
+}
+/// A synthesized click lands on whatever is on top there: only click where this app's window is.
+func handoffClickOwned(_ pid: Int32, _ frame: [Double]) -> Bool {
+ guard frame.count == 4, handoffOwnsPoint(pid, CGPoint(x: frame[0] + frame[2] / 2, y: frame[1] + frame[3] / 2)) else { return false }
+ handoffClick(frame)
+ return true
+}
+func handoffFocus(_ app: AXUIElement, _ element: AXUIElement) -> Bool {
+ AXUIElementSetAttributeValue(element, kAXFocusedAttribute as CFString, kCFBooleanTrue)
+ usleep(80000)
+ if handoffFocused(app, is: element) { return true }
+ var pid: pid_t = 0
+ if AXUIElementGetPid(app, &pid) == .success, let frame = handoffFrame(element), handoffClickOwned(pid, frame) { usleep(120000) }
+ return handoffFocused(app, is: element)
+}
+func handoffAct(_ request: [String: Any]) -> [String: Any] {
+ guard let pid = request["pid"] as? Int32 ?? (request["pid"] as? Int).map({ Int32($0) }),
+ NSRunningApplication(processIdentifier: pid) != nil else { return ["error": "target_gone"] }
+ let app = AXUIElementCreateApplication(pid)
+ handoffPrepare(app)
+ guard let window = handoffResolveWindow(app, request)?.0 else { return ["error": "target_gone"] }
+ guard let ref = request["ref"] as? String, ref.count <= 512,
+ let element = handoffResolveRef(window, ref) else { return ["error": "stale"] }
+ if let expected = request["fp"] as? String, handoffFingerprint(element) != expected { return ["error": "stale"] }
+ if handoffBool(element, kAXEnabledAttribute) == false { return ["error": "disabled"] }
+ let kind = request["kind"] as? String ?? ""
+ let front = handoffActivate(pid, window)
+ switch kind {
+ case "press":
+ if AXUIElementPerformAction(element, kAXPressAction as CFString) != .success {
+ guard let frame = handoffFrame(element), handoffClickOwned(pid, frame) else { return ["error": "action_failed"] }
+ }
+ return ["ok": true]
+ case "text":
+ guard let value = request["value"] as? String, value.utf16.count <= 4096 else { return ["error": "invalid"] }
+ let secure = handoffIsSecure(element)
+ if !secure, AXUIElementSetAttributeValue(element, kAXValueAttribute as CFString, value as CFString) == .success,
+ (handoffAttr(element, kAXValueAttribute) as? String) == value {
+ _ = handoffFocus(app, element)
+ return ["ok": true, "method": "set"]
+ }
+ // Keys go to whichever app is in front: never type unless it is this one.
+ guard front, handoffFocus(app, element), handoffFrontPid() == pid else { return ["error": "focus_failed"] }
+ handoffKey(0, flags: .maskCommand) // select all
+ handoffKey(51) // delete
+ guard handoffFocused(app, is: element), handoffFrontPid() == pid else { return ["error": "focus_failed"] }
+ handoffTypeAndSettle(value)
+ guard handoffFocused(app, is: element) else { return ["error": "focus_lost"] }
+ if secure {
+ if let count = handoffAttr(element, kAXNumberOfCharactersAttribute) as? NSNumber {
+ return count.intValue == value.count ? ["ok": true, "method": "typed"] : ["error": "verify_failed"]
+ }
+ return ["ok": true, "method": "typed", "unverified": true]
+ }
+ return (handoffAttr(element, kAXValueAttribute) as? String) == value
+ ? ["ok": true, "method": "typed"] : ["ok": true, "method": "typed", "unverified": true]
+ case "key":
+ guard let name = request["value"] as? String, let code: CGKeyCode = ["return": 36, "escape": 53, "tab": 48][name]
+ else { return ["error": "invalid"] }
+ if name == "return", !handoffFocused(app, is: element) { _ = handoffFocus(app, element) }
+ guard front, handoffFrontPid() == pid else { return ["error": "focus_failed"] }
+ handoffKey(code)
+ return ["ok": true]
+ default:
+ return ["error": "invalid"]
+ }
+}
+// ── Screenshot steps: a step the owner answers on a picture of the window ──
+let handoffEditableRoles: Set<String> = ["AXTextField", "AXTextArea", "AXComboBox", "AXSearchField"]
+func handoffPid(_ request: [String: Any]) -> Int32? {
+ request["pid"] as? Int32 ?? (request["pid"] as? Int).map({ Int32($0) })
+}
+func handoffNumbers(_ raw: Any?, count: Int) -> [Double]? {
+ guard let values = raw as? [Any], values.count == count else { return nil }
+ let numbers = values.compactMap { ($0 as? NSNumber)?.doubleValue }
+ return numbers.count == count && numbers.allSatisfy({ $0.isFinite }) ? numbers : nil
+}
+func handoffSameFrame(_ a: [Double]?, _ b: [Double]) -> Bool {
+ guard let a = a, a.count == 4, b.count == 4 else { return false }
+ return zip(a, b).allSatisfy { abs($0 - $1) <= 1 }
+}
+/** Bring the window to the front so it can be photographed, and report where it is. */
+func handoffRaise(_ request: [String: Any]) -> [String: Any] {
+ guard let pid = handoffPid(request), NSRunningApplication(processIdentifier: pid) != nil else { return ["error": "target_gone"] }
+ let app = AXUIElementCreateApplication(pid)
+ handoffPrepare(app)
+ guard let window = handoffResolveWindow(app, request)?.0 else { return ["error": "target_gone"] }
+ handoffActivate(pid, window)
+ usleep(180000)
+ guard let frame = handoffFrame(window), frame[2] > 0, frame[3] > 0 else { return ["error": "target_gone"] }
+ var result: [String: Any] = ["frame": frame]
+ if let id = handoffWindowID(pid, frame) { result["windowId"] = Int(id) }
+ return result
+}
+/** The window server's id for this app's window at this frame, for a live view of just that window. */
+func handoffWindowID(_ pid: Int32, _ frame: [Double]) -> CGWindowID? {
+ guard let infos = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]]
+ else { return nil }
+ for info in infos where (info[kCGWindowLayer as String] as? Int) == 0 && (info[kCGWindowOwnerPID as String] as? Int32) == pid {
+ guard let raw = info[kCGWindowBounds as String] as? NSDictionary, let bounds = CGRect(dictionaryRepresentation: raw),
+ handoffSameFrame([Double(bounds.minX), Double(bounds.minY), Double(bounds.width), Double(bounds.height)], frame),
+ let id = info[kCGWindowNumber as String] as? Int, id > 0 else { continue }
+ return CGWindowID(id)
+ }
+ return nil
+}
+/** The window-server id of the app's window at this frame, without bringing it forward (watching a code). */
+func handoffWindowIDFor(_ request: [String: Any]) -> [String: Any] {
+ guard let pid = handoffPid(request), NSRunningApplication(processIdentifier: pid) != nil,
+ let frame = request["frame"] as? [Double], frame.count == 4, frame.allSatisfy({ $0.isFinite }) else { return ["error": "target_gone"] }
+ guard let id = handoffWindowID(pid, frame) else { return ["error": "target_gone"] }
+ return ["windowId": Int(id)]
+}
+/** Whether the app's focused element takes typing, and whether it is a password field. Roles only. */
+func handoffFocusedField(_ request: [String: Any]) -> [String: Any] {
+ guard let pid = handoffPid(request), NSRunningApplication(processIdentifier: pid) != nil else { return ["error": "target_gone"] }
+ let app = AXUIElementCreateApplication(pid)
+ AXUIElementSetMessagingTimeout(app, 0.5)
+ guard let focused = handoffElement(handoffAttr(app, kAXFocusedUIElementAttribute)) else { return ["editable": false, "secure": false] }
+ let secure = handoffIsSecure(focused)
+ let editable = secure || handoffEditableRoles.contains(handoffString(focused, kAXRoleAttribute) ?? "")
+ return ["editable": editable, "secure": secure]
+}
+/** The frontmost on-screen window under a point belongs to this app (a click there reaches it). */
+func handoffOwnsPoint(_ pid: Int32, _ point: CGPoint) -> Bool {
+ guard let infos = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID) as? [[String: Any]] else { return false }
+ for info in infos {
+ if (info[kCGWindowAlpha as String] as? Double ?? 1) <= 0.01 { continue }
+ guard let raw = info[kCGWindowBounds as String] as? NSDictionary,
+ let bounds = CGRect(dictionaryRepresentation: raw), bounds.contains(point) else { continue }
+ return (info[kCGWindowOwnerPID as String] as? Int32) == pid
+ }
+ return false
+}
+/**
+ * Owner input on a screenshot step. The window must still be where it was
+ * photographed; a tap must land inside it and on top; typing goes to the
+ * focused field only, and a password goes only into a password field.
+ */
+func handoffPointer(_ request: [String: Any]) -> [String: Any] {
+ guard let pid = handoffPid(request), NSRunningApplication(processIdentifier: pid) != nil else { return ["error": "target_gone"] }
+ let app = AXUIElementCreateApplication(pid)
+ handoffPrepare(app)
+ guard let window = handoffResolveWindow(app, request)?.0 else { return ["error": "target_gone"] }
+ guard let expected = handoffNumbers(request["windowFrame"], count: 4) else { return ["error": "invalid"] }
+ let front = handoffActivate(pid, window)
+ usleep(120000)
+ guard handoffSameFrame(handoffFrame(window), expected) else { return ["error": "moved"] }
+ switch request["kind"] as? String {
+ case "tap":
+ guard let point = handoffNumbers(request["point"], count: 2), let area = handoffNumbers(request["area"], count: 4),
+ CGRect(x: area[0], y: area[1], width: area[2], height: area[3]).contains(CGPoint(x: point[0], y: point[1]))
+ else { return ["error": "invalid"] }
+ let target = CGPoint(x: point[0], y: point[1])
+ guard handoffOwnsPoint(pid, target) else { return ["error": "covered"] }
+ handoffClick([target.x - 0.5, target.y - 0.5, 1, 1])
+ return ["ok": true]
+ case "type":
+ guard let value = request["value"] as? String, value.utf16.count <= 4096 else { return ["error": "invalid"] }
+ guard let focused = handoffElement(handoffAttr(app, kAXFocusedUIElementAttribute)) else { return ["error": "focus_failed"] }
+ let secure = handoffIsSecure(focused)
+ let wantsSecure = request["secure"] as? Bool ?? false
+ guard secure || handoffEditableRoles.contains(handoffString(focused, kAXRoleAttribute) ?? "") else { return ["error": "focus_failed"] }
+ // A password typed for a password field never lands in a visible one, and the reverse.
+ guard secure == wantsSecure else { return ["error": "moved"] }
+ guard front, handoffFrontPid() == pid else { return ["error": "focus_failed"] }
+ handoffTypeAndSettle(value)
+ if request["submit"] as? Bool == true { handoffKey(36) }
+ return ["ok": true]
+ default:
+ return ["error": "invalid"]
+ }
+}
+func handoffRespond(_ value: [String: Any]) -> Never {
+ guard let data = try? JSONSerialization.data(withJSONObject: value), let json = String(data: data, encoding: .utf8) else { exit(2) }
+ print(json); fflush(stdout); exit(0)
+}
+
+/// 代输入 scan-to-sign-in: the QR codes in one photographed window, with what
+/// each says and where it sits (fractions of the picture, top-left origin).
+/// The picture arrives in memory and is never written anywhere.
+func handoffDetectQr(_ data: Data) -> [[String: Any]] {
+ guard let source = CGImageSourceCreateWithData(data as CFData, nil),
+ let image = CGImageSourceCreateImageAtIndex(source, 0, nil) else { return [] }
+ let request = VNDetectBarcodesRequest()
+ request.symbologies = [.qr]
+ guard (try? VNImageRequestHandler(cgImage: image, options: [:]).perform([request])) != nil else { return [] }
+ var found: [[String: Any]] = []
+ var seen = Set<String>()
+ for case let code as VNBarcodeObservation in request.results ?? [] {
+ guard let text = code.payloadStringValue, !text.isEmpty, text.utf16.count <= 2048, seen.insert(text).inserted else { continue }
+ let box = code.boundingBox
+ found.append(["text": text, "box": [Double(box.minX), Double(1 - box.maxY), Double(box.width), Double(box.height)]])
+ if found.count >= 8 { break }
+ }
+ return found
+}
+
#if !DESKTOP_INPUT_TEST
if CommandLine.arguments.contains("--check") {
print(AXIsProcessTrusted() ? "ready" : "permission"); exit(0)
}
+if CommandLine.arguments == [CommandLine.arguments[0], "--handoff-qr"] {
+ // One photographed window (JPEG) on stdin: its byte length on a line, then the bytes. Main keeps
+ // stdin open (closing it would fail the caller check), so the length marks the end. The reply says
+ // only what QR codes it shows.
+ let limit = 24 << 20
+ var header: [UInt8] = []
+ while header.count <= 12 {
+ var byte: UInt8 = 0
+ guard read(STDIN_FILENO, &byte, 1) == 1 else { break }
+ if byte == 10 { break }
+ header.append(byte)
+ }
+ guard let length = Int(String(decoding: header, as: UTF8.self)), length > 0, length <= limit else {
+ handoffRespond(["error": "invalid"])
+ }
+ var data = Data()
+ var chunk = [UInt8](repeating: 0, count: 65536)
+ while data.count < length {
+ let count = read(STDIN_FILENO, &chunk, min(chunk.count, length - data.count))
+ if count <= 0 { break }
+ data.append(chunk, count: count)
+ }
+ guard data.count == length, let session = CGSessionCopyCurrentDictionary() as? [String: Any],
+ !(session["CGSSessionScreenIsLocked"] as? Bool ?? false) else { handoffRespond(["error": "unavailable"]) }
+ handoffRespond(["codes": handoffDetectQr(data)])
+}
if CommandLine.arguments.contains("--lock-state") {
guard let state = CGSessionCopyCurrentDictionary() as? [String: Any],
state[kCGSessionLoginDoneKey as String] as? Bool == true else { print("unavailable"); exit(0) }
@@ -284,6 +910,32 @@ if CommandLine.arguments.count == 2 && CommandLine.arguments[1] == "--lock-scree
exit(2)
}
guard AXIsProcessTrusted() else { print("permission"); fflush(stdout); exit(2) }
+if CommandLine.arguments == [CommandLine.arguments[0], "--handoff"] {
+ // A single bounded request; values stay on stdin and are never echoed.
+ var bytes: [UInt8] = []
+ while bytes.count <= 65536 {
+ var byte: UInt8 = 0
+ guard read(STDIN_FILENO, &byte, 1) == 1 else { break }
+ if byte == 10 { break }
+ bytes.append(byte)
+ }
+ guard bytes.count <= 65536, let request = try? JSONSerialization.jsonObject(with: Data(bytes)) as? [String: Any],
+ let session = CGSessionCopyCurrentDictionary() as? [String: Any] else { handoffRespond(["error": "unavailable"]) }
+ bytes.withUnsafeMutableBufferPointer { buffer in for i in buffer.indices { buffer[i] = 0 } }
+ // A locked screen is never read or typed into; the owner unlocks the computer first.
+ if session["CGSSessionScreenIsLocked"] as? Bool ?? false { handoffRespond(["error": "locked"]) }
+ switch request["op"] as? String {
+ case "windows": handoffRespond(handoffWindowList())
+ case "snapshot": handoffRespond(handoffSnapshot(request))
+ case "act": handoffRespond(handoffAct(request))
+ case "secure": handoffRespond(handoffSecureTarget(request))
+ case "raise": handoffRespond(handoffRaise(request))
+ case "windowid": handoffRespond(handoffWindowIDFor(request))
+ case "focused": handoffRespond(handoffFocusedField(request))
+ case "pointer": handoffRespond(handoffPointer(request))
+ default: handoffRespond(["error": "invalid"])
+ }
+}
if CommandLine.arguments == [CommandLine.arguments[0], "--privacy-input"] {
var heartbeat = Date()
var previousApp: NSRunningApplication?
@@ -347,6 +999,11 @@ if CommandLine.arguments == [CommandLine.arguments[0], "--privacy-input"] {
CFRunLoopRun()
exit(0)
}
+if CommandLine.arguments.count == 4 && CommandLine.arguments[1] == "--window" {
+ guard let window = UInt32(CommandLine.arguments[2]), window > 0,
+ let pid = Int32(CommandLine.arguments[3]), pid > 0 else { exit(2) }
+ confine = HandoffConfine(window: window, pid: pid)
+}
print("ready"); fflush(stdout)
let watchdog = DispatchSource.makeTimerSource(queue: .global())
watchdog.schedule(deadline: .now() + 1, repeating: 1)
diff --git a/apps/desktop/native/remote-desktop/macos-input.test.swift b/apps/desktop/native/remote-desktop/macos-input.test.swift
index e4f280e05c..518d0bfff0 100644
--- a/apps/desktop/native/remote-desktop/macos-input.test.swift
+++ b/apps/desktop/native/remote-desktop/macos-input.test.swift
@@ -49,3 +49,45 @@ for phase in [0, 1, 2, 0] {
precondition(wheelGate.consume(physical: true, press: nil, down: false, trigger: false, scroll: true) == (true, phase == 0))
precondition(wheelGate.swallowed.isEmpty)
}
+
+// 代输入 live view: decisions only, nothing is posted. A window id and pid that
+// cannot exist stand in for a window that is gone or an app that is not focused.
+do {
+ let absent = HandoffConfine(window: 0xFFFF_FFF0, pid: 99_999_999)
+ keys = []; buttons = []; location = CGPoint(x: 40, y: 50)
+ precondition(confined(["kind": "move", "x": 0.5, "y": 0.5], absent) == nil, "No window, no pointer")
+ precondition(confined(["kind": "button", "button": 0, "down": true, "x": 0.5, "y": 0.5], absent) == nil)
+ let up = confined(["kind": "button", "button": 0, "down": false, "x": 0.9, "y": 0.9], absent)
+ precondition(up?["x"] as? Double == 40 && up?["y"] as? Double == 50, "A release always lands where the pointer is")
+ precondition(confined(["kind": "scroll", "dx": 0.0, "dy": 3.0], absent) == nil)
+ precondition(confined(["kind": "text", "text": "a"], absent) == nil, "Typing only while the app is focused")
+ precondition(confined(["kind": "key", "code": "KeyA", "down": true], absent) == nil)
+ precondition(confined(["kind": "key", "code": "F3", "down": true], absent) == nil, "No function keys")
+ precondition(confined(["kind": "key", "code": "KeyA", "down": false], absent) == nil, "Nothing to release")
+ keys = [0]
+ precondition(confined(["kind": "key", "code": "KeyA", "down": false], absent) != nil, "A held key is always released")
+ keys = [55]
+ precondition(confined(["kind": "key", "code": "Tab", "down": true], absent) == nil, "No app switcher")
+ keys = [55, 59]
+ precondition(confined(["kind": "key", "code": "KeyQ", "down": true], absent) == nil, "No lock-screen shortcut")
+ precondition(confined(["kind": "wheel"], absent) == nil)
+ keys = []
+}
+print("native window confinement passed")
+
+// 代输入 scan-to-sign-in: a code drawn into a larger picture is found, with its content and place.
+do {
+ let filter = CIFilter(name: "CIQRCodeGenerator")!
+ filter.setValue("https://login.example.com/qr?token=abc".data(using: .utf8), forKey: "inputMessage")
+ let code = filter.outputImage!.transformed(by: CGAffineTransform(scaleX: 8, y: 8))
+ let canvas = CIImage(color: .white).cropped(to: CGRect(x: 0, y: 0, width: 1200, height: 800))
+ let placed = code.transformed(by: CGAffineTransform(translationX: 700, y: 300)).composited(over: canvas)
+ let rep = NSBitmapImageRep(ciImage: placed)
+ let jpeg = rep.representation(using: .jpeg, properties: [.compressionFactor: 0.85])!
+ let codes = handoffDetectQr(jpeg)
+ precondition(codes.count == 1 && codes[0]["text"] as? String == "https://login.example.com/qr?token=abc", "The code says what it was made with")
+ let box = codes[0]["box"] as! [Double]
+ precondition(box[0] > 0.55 && box[0] < 0.65 && box[1] > 0.2 && box[1] < 0.36, "Top-left origin, as fractions")
+ precondition(handoffDetectQr(Data([1, 2, 3])).isEmpty, "Not a picture, no codes")
+}
+print("native qr detection passed")
diff --git a/apps/desktop/src/main/agent-island/service.ts b/apps/desktop/src/main/agent-island/service.ts
index 0e10be947b..f7bee60500 100644
--- a/apps/desktop/src/main/agent-island/service.ts
+++ b/apps/desktop/src/main/agent-island/service.ts
@@ -268,6 +268,7 @@ function safeSessionActionSummary(snapshot: AgentIslandSessionSnapshot): string
if (snapshot.interactionKind === 'ask_user_question') return '等待用户回答';
if (snapshot.interactionKind === 'plan_review') return '等待计划确认';
if (snapshot.interactionKind === 'plugin_setup') return '等待插件配置';
+ if (snapshot.interactionKind === 'input_handoff') return '等待代输入';
return '等待用户确认';
}
if (snapshot.phase === 'completed') return '运行已正常结束';
@@ -1083,10 +1084,12 @@ export class AgentIslandService {
this.publish();
}
+ /** Host-owned waits (plugin setup, input handoff) shown as attention until dismissed. */
handlePluginSetupInteraction(
sessionId: string,
requestId: string,
detail: string,
+ kind: 'plugin_setup' | 'input_handoff' = 'plugin_setup',
): void {
const hydrated = this.hydrateMeta({ sessionId });
setAgentIslandStrings(this.state, buildAgentIslandStrings());
@@ -1101,7 +1104,9 @@ export class AgentIslandService {
applyAgentIslandInteractionRequest(
this.state,
hydrated,
- { kind: 'plugin_setup', requestId, detail },
+ kind === 'input_handoff'
+ ? { kind: 'input_handoff', requestId, detail }
+ : { kind: 'plugin_setup', requestId, detail },
Date.now(),
);
this.ensureMetadata(hydrated.sessionId);
diff --git a/apps/desktop/src/main/agent-island/state.ts b/apps/desktop/src/main/agent-island/state.ts
index 3fc6ff798b..b10547a2aa 100644
--- a/apps/desktop/src/main/agent-island/state.ts
+++ b/apps/desktop/src/main/agent-island/state.ts
@@ -47,11 +47,8 @@ import {
export type AgentIslandInteractionRequest =
| InteractionRequest
- | {
- kind: 'plugin_setup';
- requestId: string;
- detail: string;
- };
+ | { kind: 'plugin_setup'; requestId: string; detail: string }
+ | { kind: 'input_handoff'; requestId: string; detail: string };
export const AGENT_ISLAND_COMPLETION_DWELL_MS = 5_000;
export const AGENT_ISLAND_ERROR_DWELL_MS = 12_000;
@@ -2791,7 +2788,7 @@ function detailForInteraction(
request: AgentIslandInteractionRequest,
wording: ToolRowWording,
): string {
- if (request.kind === 'plugin_setup') return request.detail;
+ if (request.kind === 'plugin_setup' || request.kind === 'input_handoff') return request.detail;
if (request.kind === 'permission') {
// 权限确认:requireCommandVisible 保证用户批准的真实命令始终可见。
return formatIslandToolDetail(request.toolName, request.input, { wording, requireCommandVisible: true }, {
diff --git a/apps/desktop/src/main/device-link/ipc.ts b/apps/desktop/src/main/device-link/ipc.ts
index 4dc318159b..85878c5865 100644
--- a/apps/desktop/src/main/device-link/ipc.ts
+++ b/apps/desktop/src/main/device-link/ipc.ts
@@ -11,8 +11,8 @@ import { currentOauthIdentityScope, trustOauthPeer } from '../plugin-oauth/deskt
import { RemotePluginOauthUnsupportedError, resolveOauthPeerIdentity } from '../plugin-oauth/identityResolver.js';
import { getDeviceId } from '../authManager.js';
import { copyPrivateDeviceCode } from '../plugin-oauth/deviceCodeClipboard.js';
-import { PLUGIN_OAUTH_CHANNEL, PLUGIN_OAUTH_LOCAL_CHANNEL, PLUGIN_SECRET_LOCAL_CHANNEL, PLUGIN_CONNECTION_LOCAL_CHANNEL } from '@cindy/device-link';
-import { handleAssistPluginOauth, handleSubmitPluginSecret, handleSubmitPluginConnection } from '../plugin-oauth/localIpc.js';
+import { PLUGIN_OAUTH_CHANNEL, PLUGIN_OAUTH_LOCAL_CHANNEL, PLUGIN_SECRET_LOCAL_CHANNEL, PLUGIN_CONNECTION_LOCAL_CHANNEL, INPUT_HANDOFF_LOCAL_CHANNEL, INPUT_HANDOFF_REMOTE_LOCAL_CHANNEL, INPUT_HANDOFF_LOCAL_PICTURE_CHANNEL, INPUT_HANDOFF_REMOTE_PICTURE_CHANNEL, INPUT_HANDOFF_REMOTE_PICTURE_ANSWER_CHANNEL } from '@cindy/device-link';
+import { handleAssistPluginOauth, handleSubmitPluginSecret, handleSubmitPluginConnection, handleSubmitInputHandoff, handleOpenInputHandoffPicture, handleAnswerInputHandoffPicture, type LocalOauthDeps } from '../plugin-oauth/localIpc.js';
import { LocalDeviceCodeSessions } from '../plugin-oauth/deviceCodeSessions.js';
import { PLUGIN_OAUTH_DEVICE_CODE_CHANNEL } from '../../shared/pluginOauthDeviceCode.js';
import { getActiveAppSession, isAppSessionBoundaryPending } from '../appSessionState.js';
@@ -602,7 +602,10 @@ export async function handleInvoke(
if (typeof channel !== 'string' || !channel.trim()) {
throwIpcError('INVALID_PARAMS', 'channel is required');
}
- if (channel === PLUGIN_OAUTH_CHANNEL || channel === PLUGIN_SECRET_LOCAL_CHANNEL || channel === PLUGIN_CONNECTION_LOCAL_CHANNEL)
+ if (channel === PLUGIN_OAUTH_CHANNEL || channel === PLUGIN_SECRET_LOCAL_CHANNEL || channel === PLUGIN_CONNECTION_LOCAL_CHANNEL
+ || channel === INPUT_HANDOFF_LOCAL_CHANNEL || channel === INPUT_HANDOFF_REMOTE_LOCAL_CHANNEL
+ || channel === INPUT_HANDOFF_LOCAL_PICTURE_CHANNEL || channel === INPUT_HANDOFF_REMOTE_PICTURE_CHANNEL
+ || channel === INPUT_HANDOFF_REMOTE_PICTURE_ANSWER_CHANNEL)
throwIpcError('PERMISSION_DENIED', 'Authorization transport is Host-only');
let callArgs = Array.isArray(args) ? args : [];
@@ -1428,41 +1431,60 @@ export function registerDeviceLinkIpc(deps: DeviceLinkIpcDeps = defaultDeps()):
try { return await deviceCodes.handle(scope, raw); }
catch { throwIpcError('PRECONDITION_FAILED', 'Authorization code unavailable; retry from the current card'); }
});
- const authorizationHandler = (mode: 'oauth' | 'secret' | 'connection') => async (event: import('electron').IpcMainInvokeEvent, raw: unknown) => {
+ const localOauthDeps = (event: import('electron').IpcMainInvokeEvent): LocalOauthDeps => ({
+ owner: () => !isAppSessionBoundaryPending() && getActiveAppSession().mode === 'cloud' ? activeOwnerScopeKey() : null,
+ assertTarget: deviceId => {
+ if (event.sender.isDestroyed()) throw new Error('OAUTH_BRIDGE_UNAVAILABLE');
+ assertTrustedAppRendererEvent(event);
+ assertControlTargetEnabled(deps, deviceId);
+ },
+ invoke: deps.invoke,
+ localDeviceId: getDeviceId,
+ identity: (deviceId, assertCurrent) => resolveOauthPeerIdentity({scope: currentOauthIdentityScope, invoke: deps.invoke}, deviceId, assertCurrent),
+ trustIdentity: trustOauthPeer,
+ openExternal: url => shell.openExternal(url),
+ copyDeviceCode: code => copyPrivateDeviceCode(clipboard, code),
+ presentBrowserAuthorization: (target, expiresAt, assertCurrent, reopen) =>
+ deviceCodes.presentBrowser(deviceCodeScope(event), target, expiresAt, assertCurrent, reopen),
+ presentDeviceCode: (target, prompt, assertCurrent, clearClipboard) => deviceCodes.present(deviceCodeScope(event), target, prompt, {
+ assertCurrent,
+ clearClipboard,
+ copy: code => { copyPrivateDeviceCode(clipboard, code); },
+ openExternal: url => shell.openExternal(url),
+ }),
+ });
+ const authorizationFailed = (error: unknown): never => {
+ if (error instanceof RemotePluginOauthUnsupportedError)
+ throwIpcError('UNSUPPORTED_CAPABILITY', 'Update Cindy on the remote device to use remote plugin authorization');
+ throwIpcError('PRECONDITION_FAILED', 'Remote authorization unavailable; retry from the current card');
+ };
+ const authorizationHandler = (mode: 'oauth' | 'secret' | 'connection' | 'input') => async (event: import('electron').IpcMainInvokeEvent, raw: unknown) => {
assertTrustedAppRendererEvent(event);
requireDeviceLinkCapability();
try {
- return await (mode === 'connection' ? handleSubmitPluginConnection : mode === 'secret' ? handleSubmitPluginSecret : handleAssistPluginOauth)({
- owner: () => !isAppSessionBoundaryPending() && getActiveAppSession().mode === 'cloud' ? activeOwnerScopeKey() : null,
- assertTarget: deviceId => {
- if (event.sender.isDestroyed()) throw new Error('OAUTH_BRIDGE_UNAVAILABLE');
- assertTrustedAppRendererEvent(event);
- assertControlTargetEnabled(deps, deviceId);
- },
- invoke: deps.invoke,
- localDeviceId: getDeviceId,
- identity: (deviceId, assertCurrent) => resolveOauthPeerIdentity({scope: currentOauthIdentityScope, invoke: deps.invoke}, deviceId, assertCurrent),
- trustIdentity: trustOauthPeer,
- openExternal: url => shell.openExternal(url),
- copyDeviceCode: code => copyPrivateDeviceCode(clipboard, code),
- presentBrowserAuthorization: (target, expiresAt, assertCurrent, reopen) =>
- deviceCodes.presentBrowser(deviceCodeScope(event), target, expiresAt, assertCurrent, reopen),
- presentDeviceCode: (target, prompt, assertCurrent, clearClipboard) => deviceCodes.present(deviceCodeScope(event), target, prompt, {
- assertCurrent,
- clearClipboard,
- copy: code => { copyPrivateDeviceCode(clipboard, code); },
- openExternal: url => shell.openExternal(url),
- }),
- }, raw);
+ return await (mode === 'input' ? handleSubmitInputHandoff : mode === 'connection' ? handleSubmitPluginConnection : mode === 'secret' ? handleSubmitPluginSecret : handleAssistPluginOauth)(localOauthDeps(event), raw);
} catch (error) {
- if (error instanceof RemotePluginOauthUnsupportedError)
- throwIpcError('UNSUPPORTED_CAPABILITY', 'Update Cindy on the remote device to use remote plugin authorization');
- throwIpcError('PRECONDITION_FAILED', 'Remote authorization unavailable; retry from the current card');
+ return authorizationFailed(error);
}
};
ipcMain.handle(PLUGIN_OAUTH_LOCAL_CHANNEL, authorizationHandler('oauth'));
ipcMain.handle(PLUGIN_SECRET_LOCAL_CHANNEL, authorizationHandler('secret'));
ipcMain.handle(PLUGIN_CONNECTION_LOCAL_CHANNEL, authorizationHandler('connection'));
+ ipcMain.handle(INPUT_HANDOFF_REMOTE_LOCAL_CHANNEL, authorizationHandler('input'));
+ // 代输入 screenshot step on another computer: the sealed picture returns to this window only.
+ ipcMain.handle(INPUT_HANDOFF_REMOTE_PICTURE_CHANNEL, async (event, raw: unknown) => {
+ assertTrustedAppRendererEvent(event);
+ requireDeviceLinkCapability();
+ try {
+ return await handleOpenInputHandoffPicture(localOauthDeps(event), raw, event.sender.id);
+ } catch (error) {
+ return authorizationFailed(error);
+ }
+ });
+ ipcMain.handle(INPUT_HANDOFF_REMOTE_PICTURE_ANSWER_CHANNEL, (event, raw: unknown) => {
+ assertTrustedAppRendererEvent(event);
+ return handleAnswerInputHandoffPicture(raw, event.sender.id);
+ });
const gated =
<T extends unknown[]>(handler: (...args: T) => unknown) =>
(...args: T) => {
diff --git a/apps/desktop/src/main/device-link/sharedTaskDispatch.ts b/apps/desktop/src/main/device-link/sharedTaskDispatch.ts
index 59382be53a..831e7417b2 100644
--- a/apps/desktop/src/main/device-link/sharedTaskDispatch.ts
+++ b/apps/desktop/src/main/device-link/sharedTaskDispatch.ts
@@ -339,5 +339,7 @@ export function captureSharedTaskPush(source: string, channel: string, payload:
sharedTaskMetadataTopic(channel, payload) !== null ||
channel.startsWith('usage:message-') || channel === 'usage:session-spend-changed' || channel === 'usage:session-tokens-changed')) return null;
if (channel === 'maker:event:batch' && (!Array.isArray(row.events) || row.events.some((event) => record(event)?.sessionId !== sessionId))) return null;
+ // 代输入 is the owner's own sign-in step; guests never see or answer it.
+ if (channel === 'maker:interaction-request' && record(row.request)?.kind === 'input_handoff') return null;
return () => capture.isCurrent();
}
diff --git a/apps/desktop/src/main/hook-control/dispatcher.ts b/apps/desktop/src/main/hook-control/dispatcher.ts
index 9cff92459c..154536c7c5 100644
--- a/apps/desktop/src/main/hook-control/dispatcher.ts
+++ b/apps/desktop/src/main/hook-control/dispatcher.ts
@@ -253,7 +253,10 @@ export interface HookRunRequest {
* 连接不在线时直接丢弃, 不缓存不重发(与 turn.end 的离线补发相反)。
*/
onProgress?: (text: string) => void;
- /** Independent, acknowledged channel notice after runtime retirement fails. */
+ /**
+ * Independent, acknowledged channel notice outside the turn result: runtime
+ * retirement failures and the fixed 代输入 pointer.
+ */
onRuntimeRecovery?: (text: string) => Promise<boolean>;
/**
* 执行中交互卡回调(interaction.request 链路)。runner 把 maker 的
diff --git a/apps/desktop/src/main/hook-control/session-runner.ts b/apps/desktop/src/main/hook-control/session-runner.ts
index b4d1c8f587..7eef2aeccc 100644
--- a/apps/desktop/src/main/hook-control/session-runner.ts
+++ b/apps/desktop/src/main/hook-control/session-runner.ts
@@ -112,6 +112,7 @@ import { getDesktopProviderService } from '../maker-host/createDesktopProviderSe
import { beginHeadlessGhostSetupTurn } from '../mcp-integrations/ghostSetupInteractionSurface.js';
import { observeHookTurn, type HookTurnObserver } from './turnObserver.js';
import { bindRuntimeRecoveryNotice } from '../im/shared/runtimeRecoveryNotice.js';
+import { bindInputHandoffChannelNotice } from '../im/shared/inputHandoffChannelNotice.js';
import { beginGroupHistoryAccess } from '../im/shared/groupHistoryAccess.js';
import {
captureChannelAccount,
@@ -1331,6 +1332,11 @@ export function createMakerHookSessionRunner(deps: {
if (getMaker().getSession(session.id) !== session) return false;
return req.onRuntimeRecovery!(text);
}, log);
+ // 代输入: the same independent channel send carries the fixed pointer.
+ if (req.onRuntimeRecovery) bindInputHandoffChannelNotice(session, async (text) => {
+ if (getMaker().getSession(session.id) !== session) return false;
+ return req.onRuntimeRecovery!(text);
+ });
if (req.groupHistoryAccess) {
releaseGroupHistoryAccess = beginGroupHistoryAccess({
sessionId: session.id,
diff --git a/apps/desktop/src/main/im/desktopConfirmNotice.ts b/apps/desktop/src/main/im/desktopConfirmNotice.ts
index bba7e60f6a..4aedfd6fba 100644
--- a/apps/desktop/src/main/im/desktopConfirmNotice.ts
+++ b/apps/desktop/src/main/im/desktopConfirmNotice.ts
@@ -48,19 +48,28 @@ export function buildDesktopConfirmNoticeText(what: string): string {
return `🔔 ${what}正在桌面端 Cindy 等待你的确认;超时将自动取消,如需继续请到桌面端操作。`;
}
+/**
+ * 代输入提示:只给任务名与入口,不含界面内容,也不接收输入(值只走签名加密通道)。
+ * 任务名是原样数据,模板只做拼接。
+ */
+export function buildInputHandoffNoticeText(taskTitle: string): string {
+ return `🔐 需要你帮忙输入:${taskTitle} · 在 Cindy 中打开`;
+}
+
/**
* 组装 fire-and-forget 通知函数(DI 便于单测;生产接线见
* desktopConfirmNoticeWiring.ts)。
*/
export function createDesktopConfirmNotifier(
deps: DesktopConfirmNoticeDeps,
+ buildText: (what: string) => string = buildDesktopConfirmNoticeText,
): (sessionId: string, what: string) => void {
return (sessionId, what) => {
void (async () => {
try {
const openId = await deps.getFeishuOpenId(sessionId);
if (!openId) return;
- await deps.sendFeishuText(openId, buildDesktopConfirmNoticeText(what));
+ await deps.sendFeishuText(openId, buildText(what));
} catch (err) {
deps.logWarn?.(
`desktop-confirm IM notice failed (non-fatal): ${err instanceof Error ? err.message : String(err)}`,
diff --git a/apps/desktop/src/main/im/desktopConfirmNoticeWiring.ts b/apps/desktop/src/main/im/desktopConfirmNoticeWiring.ts
index 73f3fbd241..eaef002fa9 100644
--- a/apps/desktop/src/main/im/desktopConfirmNoticeWiring.ts
+++ b/apps/desktop/src/main/im/desktopConfirmNoticeWiring.ts
@@ -24,7 +24,9 @@ import {
const log = createLogger('im-desktop-confirm-notice');
/** 生产接线:接管绑定 / sessions 行反查 feishuOpenId + 复用 im/host 的 feishuIm 实例。 */
-export function createFeishuDesktopConfirmNotifier(): (sessionId: string, what: string) => void {
+export function createFeishuDesktopConfirmNotifier(
+ buildText?: (what: string) => string,
+): (sessionId: string, what: string) => void {
return createDesktopConfirmNotifier({
async getFeishuOpenId(sessionId) {
return resolveFeishuNoticeTarget(
@@ -48,5 +50,5 @@ export function createFeishuDesktopConfirmNotifier(): (sessionId: string, what:
return feishuIm.sendMarkdownText(openId, markdown);
},
logWarn: (m) => log.warn(m),
- });
+ }, buildText);
}
diff --git a/apps/desktop/src/main/im/shared/__tests__/inputHandoffChannelNotice.test.ts b/apps/desktop/src/main/im/shared/__tests__/inputHandoffChannelNotice.test.ts
new file mode 100644
index 0000000000..3dbd1b7e35
--- /dev/null
+++ b/apps/desktop/src/main/im/shared/__tests__/inputHandoffChannelNotice.test.ts
@@ -0,0 +1,56 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import type { Session } from '@cindy/maker-core';
+import {
+ bindInputHandoffChannelNotice,
+ clearInputHandoffChannelNotices,
+ sendInputHandoffChannelNotice,
+} from '../inputHandoffChannelNotice';
+
+function fakeSession(id: string) {
+ const listeners = new Set<(status: string) => void>();
+ const session = {
+ id,
+ onStatusChange: (listener: (status: string) => void) => {
+ listeners.add(listener);
+ return () => listeners.delete(listener);
+ },
+ } as unknown as Session;
+ return { session, setStatus: (status: string) => listeners.forEach((listener) => listener(status)) };
+}
+
+const log = { warn: vi.fn() };
+afterEach(() => {
+ clearInputHandoffChannelNotices();
+ log.warn.mockClear();
+});
+
+describe('代输入 channel pointer', () => {
+ it('goes to the chat that drives the task, and only while that task is open', async () => {
+ const { session, setStatus } = fakeSession('s1');
+ const deliver = vi.fn(async () => true);
+ expect(sendInputHandoffChannelNotice('s1', 'pointer', log)).toBe(false);
+ bindInputHandoffChannelNotice(session, deliver);
+ expect(sendInputHandoffChannelNotice('s1', 'pointer', log)).toBe(true);
+ expect(deliver).toHaveBeenCalledWith('pointer');
+ expect(sendInputHandoffChannelNotice('other', 'pointer', log)).toBe(false);
+ setStatus('closed');
+ expect(sendInputHandoffChannelNotice('s1', 'pointer', log)).toBe(false);
+ });
+
+ it('a newer binding of the same task replaces the old chat and failures stay quiet', async () => {
+ const first = fakeSession('s1');
+ const second = fakeSession('s1');
+ const old = vi.fn(async () => true);
+ const latest = vi.fn(async () => {
+ throw new Error('offline');
+ });
+ bindInputHandoffChannelNotice(first.session, old);
+ bindInputHandoffChannelNotice(second.session, latest);
+ expect(sendInputHandoffChannelNotice('s1', 'pointer', log)).toBe(true);
+ expect(old).not.toHaveBeenCalled();
+ await vi.waitFor(() => expect(log.warn).toHaveBeenCalled());
+ // The replaced runtime closing later does not drop the newer route.
+ first.setStatus('closed');
+ expect(sendInputHandoffChannelNotice('s1', 'pointer', log)).toBe(true);
+ });
+});
diff --git a/apps/desktop/src/main/im/shared/inputHandoffChannelNotice.ts b/apps/desktop/src/main/im/shared/inputHandoffChannelNotice.ts
new file mode 100644
index 0000000000..94ab12870d
--- /dev/null
+++ b/apps/desktop/src/main/im/shared/inputHandoffChannelNotice.ts
@@ -0,0 +1,60 @@
+import type { Session } from '@cindy/maker-core';
+
+/**
+ * 代输入 pointer for tasks driven from an IM channel (personal bots and the
+ * official Telegram bot). The channel runner binds an independent send for the
+ * task's chat; when a 代输入 card opens, the owner gets one fixed line there
+ * ("需要你帮忙输入 · 在 Cindy 中打开"). The card itself, the screen and every
+ * value stay in Cindy: the channel never shows or receives them.
+ */
+
+interface Route {
+ session: Session;
+ deliver(text: string): Promise<unknown>;
+ cleanup(): void;
+}
+
+const routes = new Map<string, Route>();
+
+export function bindInputHandoffChannelNotice(
+ session: Session,
+ deliver: (text: string) => Promise<unknown>,
+): void {
+ routes.get(session.id)?.cleanup();
+ let offStatus: (() => void) | undefined;
+ const cleanup = (): void => {
+ offStatus?.();
+ if (routes.get(session.id)?.cleanup === cleanup) routes.delete(session.id);
+ };
+ // The deliverer also checks that its runtime is still the task's current one.
+ offStatus = session.onStatusChange?.((status) => {
+ if (status === 'closed' || status === 'error') cleanup();
+ });
+ routes.set(session.id, { session, deliver, cleanup });
+}
+
+/**
+ * Sends the pointer through the task's channel. Returns false when the task is
+ * not driven from a channel, so the caller can use its other notice paths.
+ */
+export function sendInputHandoffChannelNotice(
+ sessionId: string,
+ text: string,
+ log: { warn(message: string): void },
+): boolean {
+ const route = routes.get(sessionId);
+ if (!route) return false;
+ try {
+ void route.deliver(text).then((result) => {
+ if (result === false) log.warn('input handoff channel notice was not delivered');
+ }, () => log.warn('input handoff channel notice delivery failed'));
+ } catch {
+ log.warn('input handoff channel notice delivery failed');
+ }
+ return true;
+}
+
+/** Tests only. */
+export function clearInputHandoffChannelNotices(): void {
+ for (const route of [...routes.values()]) route.cleanup();
+}
diff --git a/apps/desktop/src/main/im/shared/turnRunner.ts b/apps/desktop/src/main/im/shared/turnRunner.ts
index e8c7557461..dd555f1660 100644
--- a/apps/desktop/src/main/im/shared/turnRunner.ts
+++ b/apps/desktop/src/main/im/shared/turnRunner.ts
@@ -35,6 +35,7 @@ import { createHash, randomUUID } from 'node:crypto';
import path from 'node:path';
import { isImAccountScopeClosedError } from '../accountBoundary';
import { bindRuntimeRecoveryNotice } from './runtimeRecoveryNotice';
+import { bindInputHandoffChannelNotice } from './inputHandoffChannelNotice';
import { isImSubagentEvent } from './agentEventScope';
import { isExpiredPermissionDecision, type SharedPermission } from '../../maker-ipc/sharedPermission';
import { presentSharedPermissionCard } from './permissionPresentation';
@@ -1421,6 +1422,11 @@ export function createTurnRunner(
if (sessionStates.get(rowId)?.makerSession !== noticeSession) return false;
return im.sendText(userId, text, { threadTs: noticeScope });
}, log);
+ // 代输入: one fixed pointer in this chat when a card opens for the task.
+ bindInputHandoffChannelNotice(noticeSession, async (text) => {
+ if (sessionStates.get(rowId)?.makerSession !== noticeSession) return false;
+ return im.sendText(userId, text, { threadTs: noticeScope });
+ });
// 策略轮持一张 host turn lease:期间 setPermissionMode 切到 agent 声明为
// turnPermissionPolicy-unsupported 的档位(如 Pi Full Access)会被阻塞到本轮
// 终态,堵死"热切到 bypass 让 bridge 直接放行、策略连冒泡机会都没有"的绕过。
diff --git a/apps/desktop/src/main/input-handoff/__tests__/deviceCode.test.ts b/apps/desktop/src/main/input-handoff/__tests__/deviceCode.test.ts
new file mode 100644
index 0000000000..4b5c9a6a05
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/deviceCode.test.ts
@@ -0,0 +1,96 @@
+import { describe, expect, it } from 'vitest';
+import { isInputHandoffDeviceCode } from '@cindy/device-link';
+import { extractStep } from '../stepExtractor.js';
+import type { NativeAxNode, NativeAxSnapshot } from '../types.js';
+
+const node = (ref: string, role: string, extra: Partial<NativeAxNode> = {}): NativeAxNode => ({
+ ref,
+ role,
+ depth: ref.split('.').length,
+ fp: `${role}|${extra.title ?? extra.desc ?? extra.value ?? ''}`,
+ enabled: true,
+ frame: [100, 100, 200, 30],
+ ...extra,
+});
+
+const snapshot = (nodes: NativeAxNode[], app = 'Code'): NativeAxSnapshot => ({
+ pid: 42,
+ app,
+ bundleId: app === 'Code' ? 'com.microsoft.VSCode' : 'com.google.Chrome',
+ frontmost: true,
+ window: { index: 0, title: 'Sign in', frame: [0, 0, 1200, 900] },
+ nodes,
+});
+
+describe('device-code sign-in', () => {
+ it('finds a code and a link written into one sentence of a native dialog', () => {
+ const step = extractStep(snapshot([
+ node('0', 'AXStaticText', { value: 'Enter code WDJB-MJHT at github.com/login/device to sign in.' }),
+ node('1', 'AXButton', { title: 'Copy & Continue' }),
+ node('2', 'AXButton', { title: 'Cancel' }),
+ ]));
+ expect(step.deviceCode).toEqual({
+ code: 'WDJB-MJHT',
+ url: 'https://github.com/login/device',
+ origin: 'https://github.com',
+ });
+ });
+
+ it('finds a code shown on its own and the page link it points to', () => {
+ const step = extractStep(snapshot([
+ node('0', 'AXWebArea', { url: 'https://login.example.com/device/start', frame: [0, 60, 1200, 840] }),
+ node('0.0', 'AXHeading', { title: 'Sign in on another device', frame: [100, 80, 300, 30] }),
+ node('0.1', 'AXStaticText', { value: 'F3QWE9R2L', frame: [100, 130, 200, 30] }),
+ node('0.2', 'AXLink', { title: 'Open the sign-in page', url: 'https://microsoft.com/devicelogin', frame: [100, 180, 200, 18] }),
+ ], 'Google Chrome'));
+ expect(step.deviceCode).toEqual({
+ code: 'F3QWE9R2L',
+ url: 'https://microsoft.com/devicelogin',
+ origin: 'https://microsoft.com',
+ });
+ });
+
+ it('stays an ordinary step when anything is to be typed or the shape is ambiguous', () => {
+ const typed = extractStep(snapshot([
+ node('0', 'AXStaticText', { value: 'Enter code WDJB-MJHT at github.com/login/device' }),
+ node('1', 'AXTextField', { title: 'Code' }),
+ ]));
+ expect(typed.deviceCode).toBeUndefined();
+ const twoCodes = extractStep(snapshot([
+ node('0', 'AXStaticText', { value: 'Codes WDJB-MJHT and QQRT-77AB at github.com/login/device' }),
+ ]));
+ expect(twoCodes.deviceCode).toBeUndefined();
+ const noLink = extractStep(snapshot([node('0', 'AXStaticText', { value: 'Your code is WDJB-MJHT' })]));
+ expect(noLink.deviceCode).toBeUndefined();
+ const phone = extractStep(snapshot([
+ node('0', 'AXStaticText', { value: 'Call 400-820-8820 or visit example.com/help' }),
+ ]));
+ expect(phone.deviceCode).toBeUndefined();
+ });
+
+ it('never offers a link that is not plain public https', () => {
+ for (const link of [
+ 'http://github.com/login/device',
+ 'https://user:[email protected]/login/device',
+ 'https://192.168.1.2/device',
+ 'https://xn--gthub-zsa.com/login/device',
+ 'javascript:alert(1)',
+ ]) {
+ const step = extractStep(snapshot([
+ node('0', 'AXStaticText', { value: 'WDJB-MJHT' }),
+ node('1', 'AXLink', { title: 'Open', url: link }),
+ ]));
+ expect(step.deviceCode, link).toBeUndefined();
+ }
+ });
+
+ it('the shared check rejects anything a client should not open', () => {
+ const ok = { code: 'WDJB-MJHT', url: 'https://github.com/login/device', origin: 'https://github.com' };
+ expect(isInputHandoffDeviceCode(ok)).toBe(true);
+ expect(isInputHandoffDeviceCode({ ...ok, origin: 'https://evil.example' })).toBe(false);
+ expect(isInputHandoffDeviceCode({ ...ok, url: 'http://github.com/login/device', origin: 'http://github.com' })).toBe(false);
+ expect(isInputHandoffDeviceCode({ ...ok, code: 'wdjb mjht' })).toBe(false);
+ expect(isInputHandoffDeviceCode({ ...ok, extra: 1 })).toBe(false);
+ expect(isInputHandoffDeviceCode(undefined)).toBe(false);
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/fakeDesktop.ts b/apps/desktop/src/main/input-handoff/__tests__/fakeDesktop.ts
new file mode 100644
index 0000000000..c8415b88fa
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/fakeDesktop.ts
@@ -0,0 +1,132 @@
+import type { HandoffDriver } from '../macDriver.js';
+import type { NativeActRequest, NativeAxNode, NativeAxSnapshot, NativeWindowList, PointerRequest } from '../types.js';
+
+const node = (ref: string, role: string, extra: Partial<NativeAxNode> = {}): NativeAxNode => ({
+ ref, role, depth: 1, fp: `${role}|${extra.title ?? ''}`, enabled: true, frame: [10, 10, 100, 20], ...extra,
+});
+
+export type FakeStage = 'choose' | 'account' | 'password' | 'consent' | 'done';
+
+/**
+ * A generic sign-in: pick a method (buttons only) → account name in the app →
+ * password on the browser's sign-in page → consent (buttons only) → back in the app.
+ * Only the account and password steps have anything for the owner to type.
+ */
+export function fakeDesktop(options: {
+ pictures?: boolean;
+ live?: boolean;
+ start?: FakeStage;
+ /** The app turns the account down: pressing Next leaves the form as it was. */
+ rejects?: boolean;
+} = {}) {
+ let stage: FakeStage = options.start ?? 'account';
+ const acts: NativeActRequest[] = [];
+ const pointers: PointerRequest[] = [];
+ const raised: number[] = [];
+ let switched = false;
+ const app = { pid: 10, app: 'Example', bundleId: 'com.example.app' };
+ const browser = { pid: 20, app: 'Google Chrome', bundleId: 'com.google.Chrome' };
+ const inBrowser = () => stage === 'password' || stage === 'consent';
+ const windows = (): NativeWindowList => ({
+ frontmost: inBrowser() || switched ? 20 : 10,
+ apps: [
+ { ...app, windows: [{ index: 0, title: stage === 'done' ? 'Example' : 'Sign in', frame: [0, 0, 800, 600], focused: true, minimized: false }] },
+ // The browser was already open; the app opening the sign-in page turns its window into that page.
+ { ...browser, windows: [{ index: 0, title: stage === 'choose' || stage === 'account' ? 'New Tab' : 'Sign in - Example', frame: [0, 0, 800, 600], focused: true, minimized: false }] },
+ { pid: 1, app: 'Cindy', bundleId: 'host', windows: [{ index: 0, title: 'Cindy', frame: [0, 0, 1, 1], focused: true, minimized: false }] },
+ ],
+ });
+ const snapshot = (pid: number): NativeAxSnapshot => {
+ const base = { pid, frontmost: true, window: { index: 0, title: '', frame: [0, 0, 800, 600] } };
+ if (pid === 20) {
+ const page = (url: string, nodes: NativeAxNode[]) => [node('0', 'AXWebArea', { url, frame: [0, 0, 800, 600] }), ...nodes];
+ const nodes = stage === 'password'
+ ? page('https://auth.example.com/login', [
+ node('0.0', 'AXHeading', { title: 'Enter your password' }),
+ node('0.1', 'AXTextField', { title: 'Password', secure: true }),
+ node('0.2', 'AXButton', { title: 'Sign in' }),
+ node('0.3', 'AXLink', { title: 'Forgot password?' }),
+ ])
+ : stage === 'consent'
+ ? page('https://auth.example.com/consent', [
+ node('0.0', 'AXHeading', { title: 'Allow Example to access your account?' }),
+ node('0.1', 'AXButton', { title: 'Authorize' }),
+ node('0.2', 'AXButton', { title: 'Cancel' }),
+ ])
+ : page('https://auth.example.com/ok', [node('0.0', 'AXStaticText', { value: 'You can close this tab' })]);
+ return { ...base, ...browser, window: { ...base.window, title: 'Sign in - Example' }, nodes };
+ }
+ if (stage === 'choose') return { ...base, ...app, window: { ...base.window, title: 'Sign in' }, nodes: [
+ node('0', 'AXRadioGroup', { desc: 'Sign-in method' }),
+ node('0.0', 'AXRadioButton', { title: 'Personal', checked: true }),
+ node('0.1', 'AXRadioButton', { title: 'Enterprise', checked: false }),
+ node('1', 'AXButton', { title: 'Continue' }),
+ ] };
+ if (stage === 'account' || inBrowser()) return { ...base, ...app, window: { ...base.window, title: 'Sign in' }, nodes: [
+ node('0', 'AXTextField', { title: 'Email' }),
+ node('1', 'AXButton', { title: 'Next' }),
+ ] };
+ return { ...base, ...app, window: { ...base.window, title: 'Example' }, nodes: [
+ node('0', 'AXButton', { title: 'New task' }),
+ node('1', 'AXButton', { title: 'Settings' }),
+ node('2', 'AXTextField', { title: 'Search', subrole: 'AXSearchField' }),
+ ] };
+ };
+ const driver: HandoffDriver = {
+ permission: async () => 'granted',
+ requestPermission: async () => undefined,
+ windows: async () => windows(),
+ snapshot: async (pid) => snapshot(pid),
+ commandLine: async () => '',
+ act: async (request) => {
+ acts.push(request);
+ const press = request.kind === 'press';
+ if (stage === 'choose' && press && request.ref === '1') stage = 'account';
+ else if (stage === 'account' && press && request.ref === '1' && !options.rejects) stage = 'password';
+ else if (stage === 'password' && press && request.ref === '0.2') stage = 'consent';
+ else if (stage === 'consent' && press && request.ref === '0.1') stage = 'done';
+ return { ok: true };
+ },
+ ...(options.pictures
+ ? {
+ capture: async () => {
+ const frame = [0, 0, 800, 600];
+ return { jpeg: Buffer.from(`picture-of-${stage}`), width: 800, height: 600, area: frame, windowFrame: frame };
+ },
+ focusedField: async () => ({ editable: false, secure: false }),
+ // A tap on the main button (bottom right of the picture) moves on like pressing it.
+ pointer: async (request: PointerRequest) => {
+ pointers.push(request);
+ if (request.kind === 'tap' && request.point[0] > 400) {
+ if (stage === 'choose') stage = 'account';
+ else if (stage === 'account') stage = 'password';
+ }
+ return { ok: true as const };
+ },
+ }
+ : {}),
+ ...(options.live
+ ? {
+ raise: async (target: { pid: number }) => {
+ raised.push(target.pid);
+ return { frame: [0, 0, 800, 600], windowId: 900 + target.pid };
+ },
+ }
+ : {}),
+ };
+ return {
+ driver,
+ acts,
+ pointers,
+ raised,
+ stage: () => stage,
+ /** The owner, at the computer, switches to the browser they already had open. */
+ switchToBrowser: () => {
+ switched = true;
+ },
+ /** The owner (in the live view) or the agent moved the screen on, outside the card. */
+ advanceOutside: (next: FakeStage) => {
+ stage = next;
+ },
+ };
+}
diff --git a/apps/desktop/src/main/input-handoff/__tests__/qrCode.test.ts b/apps/desktop/src/main/input-handoff/__tests__/qrCode.test.ts
new file mode 100644
index 0000000000..5edb988f4a
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/qrCode.test.ts
@@ -0,0 +1,33 @@
+import { describe, expect, it, vi } from 'vitest';
+import { qrContent } from '../qrCode.js';
+
+vi.mock('electron', () => ({ app: {}, nativeImage: {}, screen: {}, systemPreferences: {} }));
+const { pickQr, qrCrop } = await import('../windowCapture.js');
+
+describe('代输入 QR code', () => {
+ it('offers web and app links to open, and anything else as text only', () => {
+ expect(qrContent(' https://login.example.com/qr?t=1 ')).toEqual({ text: 'https://login.example.com/qr?t=1', url: 'https://login.example.com/qr?t=1' });
+ for (const text of ['http://login.example.com/qr', 'https://printer.local/pair', 'weixin://dl/login?t=1'])
+ expect(qrContent(text)).toEqual({ text, url: text });
+ for (const text of ['https://user:[email protected]/', 'javascript://x%0Aalert(1)', 'WIFI:S:home;T:WPA;P:secret;;'])
+ expect(qrContent(text)).toEqual({ text });
+ expect(qrContent('')).toBeNull();
+ expect(qrContent('a\u0007b')).toBeNull();
+ expect(qrContent('x'.repeat(2049))).toBeNull();
+ });
+
+ it('cuts the code out with a quiet zone, inside the picture', () => {
+ expect(qrCrop([0.5, 0.25, 0.2, 0.2], { width: 1000, height: 1000 })).toEqual({ x: 476, y: 226, width: 248, height: 248 });
+ // A code at the edge keeps what is there.
+ expect(qrCrop([0, 0, 0.3, 0.3], { width: 1000, height: 1000 })).toEqual({ x: 0, y: 0, width: 336, height: 336 });
+ expect(qrCrop([0.5, 0.5, 0, 0.2], { width: 1000, height: 1000 })).toBeNull();
+ expect(qrCrop([0.5, 0.5, 0.001, 0.001], { width: 1000, height: 1000 })).toBeNull();
+ });
+
+ it('picks the largest code when a window shows several', () => {
+ const small = { text: 'small', box: [0, 0, 0.1, 0.1] };
+ const large = { text: 'large', box: [0.4, 0.4, 0.3, 0.3] };
+ expect(pickQr([small, large])?.text).toBe('large');
+ expect(pickQr([])).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/secretTaint.test.ts b/apps/desktop/src/main/input-handoff/__tests__/secretTaint.test.ts
new file mode 100644
index 0000000000..05d8b85bc3
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/secretTaint.test.ts
@@ -0,0 +1,22 @@
+import { afterEach, describe, expect, it } from 'vitest';
+import { clearSecretPages, hasSecretPages, isSecretPage, markSecretEntered } from '../secretTaint.js';
+
+afterEach(() => clearSecretPages());
+
+describe('secret pages', () => {
+ it('covers the same page until the tab leaves it or the hold expires', () => {
+ markSecretEntered('https://login.example.com/signin?next=%2F#form', 0);
+ expect(hasSecretPages(0)).toBe(true);
+ expect(isSecretPage('https://login.example.com/signin', 1000)).toBe(true);
+ expect(isSecretPage('https://login.example.com/home', 1000)).toBe(false);
+ expect(isSecretPage('https://login.example.com/signin', 16 * 60_000)).toBe(false);
+ expect(hasSecretPages(16 * 60_000)).toBe(false);
+ });
+
+ it('ignores pages it cannot place', () => {
+ markSecretEntered(undefined);
+ markSecretEntered('file:///tmp/x.html');
+ expect(hasSecretPages()).toBe(false);
+ expect(isSecretPage('')).toBe(false);
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/service.test.ts b/apps/desktop/src/main/input-handoff/__tests__/service.test.ts
new file mode 100644
index 0000000000..f3d9615305
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/service.test.ts
@@ -0,0 +1,150 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+import {
+ inputHandoffRecordMessage,
+ parseInputHandoffEndRecord,
+ UI_ACTION_TRIGGER_PREFIX,
+} from '@cindy/maker-shared/synthetic-trigger';
+import { INPUT_HANDOFF_MAX_PER_TASK, InputHandoffService, buildInputHandoffContinuation } from '../service.js';
+import { readInputHandoffSetting } from '../botPolicy.js';
+import { fakeDesktop, type FakeStage } from './fakeDesktop.js';
+
+const services: InputHandoffService[] = [];
+afterEach(() => services.splice(0).forEach((s) => s.cleanupAll()));
+
+function harness(start?: FakeStage) {
+ const desktop = fakeDesktop({ start });
+ const snapshots: InputHandoffSnapshot[] = [];
+ const continued: string[] = [];
+ const notified: InputHandoffSnapshot[] = [];
+ let clock = 0;
+ const service = new InputHandoffService({
+ broadcast: (_channel, payload) => {
+ const request = (payload as { request?: InputHandoffSnapshot }).request;
+ if (request) snapshots.push(request);
+ },
+ createDriver: () => desktop.driver,
+ hostPid: 1,
+ remoteInputAvailable: () => true,
+ continueAgent: async (_session, _request, message) => {
+ continued.push(message);
+ },
+ notifyOwner: (_session, snapshot) => notified.push(snapshot),
+ describeDevice: (deviceId) => (deviceId === 'phone-1' ? { name: 'Synthetic Phone', platform: 'mobile' } : {}),
+ terminalRetentionMs: 0,
+ sessionTiming: { now: () => clock, sleep: async (ms) => { clock += ms; }, finishingDelayMs: 5 },
+ });
+ services.push(service);
+ const latest = () => snapshots[snapshots.length - 1];
+ return { desktop, service, snapshots, latest, continued, notified, advance: (ms: number) => { clock += ms; } };
+}
+
+async function startReady(h: ReturnType<typeof harness>, sessionId = 'task') {
+ const started = h.service.start({ sessionId, purpose: 'Sign in to Example', note: 'Not sure which option', target: { app: 'Example' } });
+ if (!started.ok) throw new Error(started.errorCode);
+ await vi.waitFor(() => expect(h.latest()?.phase).toBe('ready'));
+ return started.requestId;
+}
+
+describe('代输入 owner controls', () => {
+ it('shows the agent note and records which device holds the handoff', async () => {
+ const h = harness();
+ const requestId = await startReady(h);
+ expect(h.latest().note).toBe('Not sure which option');
+ expect(h.latest().holder).toBeUndefined();
+
+ const before = h.latest().revision;
+ expect(h.service.resolve(requestId, { kind: 'input_handoff', action: 'claim', expectedRevision: before }, { deviceId: 'phone-1' })).toBe(true);
+ await vi.waitFor(() => expect(h.latest().holder).toEqual({ deviceId: 'phone-1', name: 'Synthetic Phone', platform: 'mobile' }));
+ // Taking over invalidates an answer another device prepared for the previous revision.
+ expect(h.latest().revision).toBeGreaterThan(before);
+
+ const step = h.latest();
+ const email = step.controls.find((c) => c.kind === 'text')!;
+ const submit = { kind: 'submit' } as const;
+ expect(await h.service.submit(requestId, { expectedRevision: before, values: { [email.id]: '[email protected]' }, action: submit })).toBe(false);
+
+ // The host Desktop takes it back by answering.
+ expect(await h.service.submit(requestId, { expectedRevision: step.revision, values: { [email.id]: '[email protected]' }, action: submit })).toBe(true);
+ await vi.waitFor(() => expect(h.latest().stepNumber).toBe(2));
+ expect(h.latest().holder).toEqual({ local: true });
+ });
+
+ it('keeps a fast answer from the device whose first keystroke claimed the screen', async () => {
+ const h = harness();
+ const requestId = await startReady(h);
+ const before = h.latest();
+ const email = before.controls.find((c) => c.kind === 'text')!;
+ const answer = { expectedRevision: before.revision, values: { [email.id]: '[email protected]' }, action: { kind: 'submit' } as const };
+ // A password manager fills and submits before the claim's new revision reaches the phone.
+ expect(h.service.resolve(requestId, { kind: 'input_handoff', action: 'claim', expectedRevision: before.revision }, { deviceId: 'phone-1' })).toBe(true);
+ expect(h.service.actionable(requestId, before.revision)?.revision).toBe(before.revision);
+ expect(await h.service.submit(requestId, answer, { deviceId: 'phone-1' })).toBe(true);
+ await vi.waitFor(() => expect(h.latest().stepNumber).toBe(2));
+ });
+
+ it('turns the end into a value-free record line naming the answering device', async () => {
+ const h = harness();
+ const requestId = await startReady(h);
+ const step = h.latest();
+ const email = step.controls.find((c) => c.kind === 'text')!;
+ await h.service.submit(requestId, { expectedRevision: step.revision, values: { [email.id]: '[email protected]' }, action: { kind: 'submit' } }, { deviceId: 'phone-1' });
+ await vi.waitFor(() => expect(h.latest().stepNumber).toBe(2));
+ h.service.resolve(requestId, { kind: 'input_handoff', action: 'done', expectedRevision: h.latest().revision });
+ await vi.waitFor(() => expect(h.continued).toHaveLength(1));
+
+ const record = parseInputHandoffEndRecord(`${UI_ACTION_TRIGGER_PREFIX}${h.continued[0]}`)!;
+ expect(record).toMatchObject({ status: 'succeeded', nothingToFill: false, steps: 1, answeredOn: { kind: 'named', name: 'Synthetic Phone' } });
+ expect(inputHandoffRecordMessage(record)).toEqual({ key: 'doneOn', params: { count: 1, device: 'Synthetic Phone' } });
+ expect(h.continued[0]).not.toContain('owner@example');
+ });
+
+ it('never shows a card or pages the owner when there is nothing to type', async () => {
+ const h = harness('choose');
+ const started = h.service.start({ sessionId: 'task', purpose: 'Sign in to Example', target: { app: 'Example' } });
+ expect(started.ok).toBe(true);
+ await vi.waitFor(() => expect(h.continued).toHaveLength(1));
+ expect(h.snapshots).toEqual([]);
+ expect(h.notified).toEqual([]);
+ expect(h.continued[0]).toContain('failure=nothing_to_fill');
+ const record = parseInputHandoffEndRecord(`${UI_ACTION_TRIGGER_PREFIX}${h.continued[0]}`)!;
+ expect(record).toMatchObject({ nothingToFill: true });
+ expect(inputHandoffRecordMessage(record)).toEqual({ key: 'nothingToFill' });
+ });
+
+ it('pages the owner once the fields are ready', async () => {
+ const h = harness();
+ await startReady(h);
+ expect(h.notified).toHaveLength(1);
+ expect(h.notified[0].phase).toBe('ready');
+ });
+
+ it('limits how often one task can page the owner', async () => {
+ const h = harness();
+ for (let i = 0; i < INPUT_HANDOFF_MAX_PER_TASK; i++) {
+ const requestId = await startReady(h);
+ h.service.resolve(requestId, { kind: 'input_handoff', action: 'cancel', expectedRevision: h.latest().revision });
+ await vi.waitFor(() => expect(h.continued).toHaveLength(i + 1));
+ }
+ expect(h.service.start({ sessionId: 'task', purpose: 'Again', target: { app: 'Example' } })).toMatchObject({ ok: false, errorCode: 'RATE_LIMITED' });
+ h.advance(60 * 60_000);
+ expect(h.service.start({ sessionId: 'task', purpose: 'Later', target: { app: 'Example' } }).ok).toBe(true);
+ });
+});
+
+describe('代输入 continuation for the agent', () => {
+ it('asks the owner to unlock a locked computer instead of retrying on its own', () => {
+ const text = buildInputHandoffContinuation({ status: 'failed', reason: 'failure', steps: 0, failure: 'screen_locked' });
+ expect(text).toContain('failure=screen_locked');
+ expect(text).toContain('only after they say it is unlocked');
+ });
+});
+
+describe('teammate 代输入 setting', () => {
+ it('is on unless the owner explicitly turned it off', () => {
+ expect(readInputHandoffSetting('{}')).toBe(true);
+ expect(readInputHandoffSetting('{"inputHandoff":true}')).toBe(true);
+ expect(readInputHandoffSetting('{"inputHandoff":false}')).toBe(false);
+ expect(readInputHandoffSetting('not json')).toBe(true);
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/serviceLiveView.test.ts b/apps/desktop/src/main/input-handoff/__tests__/serviceLiveView.test.ts
new file mode 100644
index 0000000000..3ea091ee80
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/serviceLiveView.test.ts
@@ -0,0 +1,83 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+import { InputHandoffService } from '../service.js';
+import { fakeDesktop } from './fakeDesktop.js';
+
+const services: InputHandoffService[] = [];
+afterEach(() => services.splice(0).forEach((s) => s.cleanupAll()));
+
+function harness(options: { live?: boolean; allowed?: boolean } = {}) {
+ const desktop = fakeDesktop({ live: options.live ?? true });
+ const snapshots: InputHandoffSnapshot[] = [];
+ const allowed = options.allowed ?? true;
+ let clock = 0;
+ const service = new InputHandoffService({
+ broadcast: (_channel, payload) => {
+ const request = (payload as { request?: InputHandoffSnapshot }).request;
+ if (request) snapshots.push(request);
+ },
+ createDriver: () => desktop.driver,
+ hostPid: 1,
+ remoteInputAvailable: () => true,
+ liveViewAvailable: () => allowed,
+ continueAgent: async () => {},
+ terminalRetentionMs: 0,
+ sessionTiming: { now: () => clock, sleep: async (ms) => { clock += ms; }, finishingDelayMs: 5 },
+ });
+ services.push(service);
+ const latest = () => snapshots[snapshots.length - 1]!;
+ return { desktop, service, latest };
+}
+
+async function startReady(h: ReturnType<typeof harness>) {
+ const started = h.service.start({ sessionId: 'task', purpose: 'Sign in to Example', target: { app: 'Example' } });
+ if (!started.ok) throw new Error(started.errorCode);
+ await vi.waitFor(() => expect(h.latest().phase).toBe('ready'));
+ return started.requestId;
+}
+
+describe('代输入 live view of the window', () => {
+ it('is offered while waiting and shows only the window the request is about', async () => {
+ const h = harness();
+ const requestId = await startReady(h);
+ expect(h.latest().liveView).toBe(true);
+ expect(await h.service.liveWindow(requestId)).toEqual({
+ pid: 10,
+ app: 'Example',
+ title: 'Sign in',
+ windowId: 910,
+ frame: [0, 0, 800, 600],
+ });
+ expect(h.desktop.raised).toEqual([10]);
+ expect(await h.service.liveWindow('some-other-request')).toBeNull();
+ });
+
+ it('is not offered where remote desktop is off, or the window cannot be singled out', async () => {
+ const off = harness({ allowed: false });
+ const requestId = await startReady(off);
+ expect(off.latest().liveView).toBeUndefined();
+ expect(await off.service.liveWindow(requestId)).toBeNull();
+ expect(off.desktop.raised).toEqual([]);
+ const none = harness({ live: false });
+ expect(await none.service.liveWindow(await startReady(none))).toBeNull();
+ expect(none.latest().liveView).toBeUndefined();
+ });
+
+ it('catches the card up after the owner works in the live view, and stops once the request ends', async () => {
+ const h = harness();
+ const requestId = await startReady(h);
+ // In the live view the owner typed the account name and continued; the card still shows the old step.
+ h.desktop.advanceOutside('password');
+ h.service.liveViewEnded(requestId);
+ await vi.waitFor(() =>
+ expect(h.latest().controls.some((c) => 'label' in c && c.label === 'Password')).toBe(true),
+ );
+ expect(
+ h.service.resolve(requestId, { kind: 'input_handoff', action: 'cancel', expectedRevision: h.latest().revision }),
+ ).toBe(true);
+ await vi.waitFor(() => expect(h.latest().terminal).toBe(true));
+ expect(h.latest().liveView).toBeUndefined();
+ expect(h.service.isCurrent(requestId)).toBe(false);
+ expect(await h.service.liveWindow(requestId)).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/session.test.ts b/apps/desktop/src/main/input-handoff/__tests__/session.test.ts
new file mode 100644
index 0000000000..59715c7a61
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/session.test.ts
@@ -0,0 +1,208 @@
+import { describe, expect, it, vi } from 'vitest';
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+import { InputHandoffSession, type HandoffResult } from '../session.js';
+import type { HandoffDriver } from '../macDriver.js';
+import { fakeDesktop } from './fakeDesktop.js';
+
+function harness(driver: HandoffDriver, extra: Partial<ConstructorParameters<typeof InputHandoffSession>[0]> = {}) {
+ const published: InputHandoffSnapshot[] = [];
+ const finished: HandoffResult[] = [];
+ let clock = 0;
+ const session = new InputHandoffSession({
+ requestId: 'req1',
+ purpose: 'Sign in to Example',
+ target: { app: 'Example' },
+ timeoutMs: 600_000,
+ hostPid: 1,
+ remoteInput: true,
+ driver,
+ publish: (snapshot) => published.push(snapshot),
+ finish: (result) => finished.push(result),
+ now: () => clock,
+ sleep: async (ms) => { clock += ms; },
+ finishingDelayMs: 5,
+ ...extra,
+ });
+ const latest = () => published[published.length - 1];
+ return { session, published, finished, latest };
+}
+
+const field = (step: InputHandoffSnapshot) => step.controls.find((control) => control.kind === 'text')!;
+
+describe('InputHandoffSession', () => {
+ it('asks only for the fields to type, confirms with the page button and follows the flow across apps', async () => {
+ const desktop = fakeDesktop();
+ const { session, finished, latest } = harness(desktop.driver);
+ await session.start();
+ let step = latest();
+ expect(step.phase).toBe('ready');
+ // Only the field: the page's Next button is Cindy's to press.
+ expect(step.controls).toEqual([{ id: expect.any(String), kind: 'text', label: 'Email', contentType: 'email' }]);
+ expect(await session.submit({ expectedRevision: step.revision, values: { [field(step).id]: '[email protected]' }, action: { kind: 'submit' } })).toBe(true);
+ expect(desktop.acts.map((act) => act.kind)).toEqual(['text', 'press']);
+
+ step = latest();
+ expect(step.stepNumber).toBe(2);
+ expect(step.source).toMatchObject({ app: 'Google Chrome', origin: 'https://auth.example.com' });
+ expect(step.controls.map((control) => control.kind)).toEqual(['text']);
+ await session.submit({ expectedRevision: step.revision, values: { [field(step).id]: 'synthetic-secret' }, action: { kind: 'submit' } });
+
+ // The consent page has only buttons: nothing left for the owner, so it is handed back.
+ expect(latest().phase).toBe('finishing');
+ await vi.waitFor(() => expect(finished).toHaveLength(1));
+ expect(finished[0]).toMatchObject({ status: 'succeeded', reason: 'detected', steps: 2, finalApp: 'Google Chrome' });
+ expect(desktop.stage()).toBe('consent');
+ expect(latest()).toMatchObject({ phase: 'succeeded', terminal: true });
+ expect(JSON.stringify([finished, latest()])).not.toMatch(/owner@example|synthetic-secret/);
+ });
+
+ it('stays on a form that still asks when the owner switches to an app they already had open', async () => {
+ const desktop = fakeDesktop({ rejects: true });
+ const { session, finished, latest } = harness(desktop.driver);
+ await session.start();
+ const step = latest();
+ const press = desktop.driver.act;
+ desktop.driver.act = async (request) => {
+ const result = await press(request);
+ if (request.kind === 'press') desktop.switchToBrowser();
+ return result;
+ };
+ await session.submit({ expectedRevision: step.revision, values: { [field(step).id]: '[email protected]' }, action: { kind: 'submit' } });
+ expect(finished).toHaveLength(0);
+ expect(latest()).toMatchObject({ phase: 'ready', source: { app: 'Example' } });
+ expect(latest().controls.map((control) => control.kind)).toEqual(['text']);
+ });
+
+ it('never types for a request that ended while it waited for the desktop', async () => {
+ // The first handoff holds the desktop; the second queues behind it and is cancelled meanwhile.
+ const first = fakeDesktop();
+ let release!: () => void;
+ const held = new Promise<void>((resolve) => { release = resolve; });
+ const act = first.driver.act;
+ first.driver.act = async (request) => {
+ await held;
+ return act(request);
+ };
+ const a = harness(first.driver);
+ const second = fakeDesktop();
+ const b = harness(second.driver, { requestId: 'req2' });
+ await a.session.start();
+ await b.session.start();
+ const stepA = a.latest();
+ const stepB = b.latest();
+ const runningA = a.session.submit({ expectedRevision: stepA.revision, values: { [field(stepA).id]: '[email protected]' }, action: { kind: 'submit' } });
+ const values = { [field(stepB).id]: '[email protected]' };
+ const queuedB = b.session.submit({ expectedRevision: stepB.revision, values, action: { kind: 'submit' } });
+ await vi.waitFor(() => expect(b.latest().phase).toBe('working'));
+ b.session.cancel();
+ release();
+ await Promise.all([runningA, queuedB]);
+ expect(second.acts).toEqual([]);
+ expect(b.finished[0]).toMatchObject({ status: 'cancelled' });
+ // The values of the ended request are dropped, not kept for later.
+ expect(values).toEqual({});
+ });
+
+ it('ends as screen_locked when the screen locks after the card opened', async () => {
+ const desktop = fakeDesktop();
+ const { session, finished, latest } = harness(desktop.driver);
+ await session.start();
+ const step = latest();
+ const act = desktop.driver.act;
+ let locked = false;
+ desktop.driver.act = async (request) => {
+ const result = await act(request);
+ if (request.kind === 'press') locked = true;
+ return result;
+ };
+ const windows = desktop.driver.windows;
+ desktop.driver.windows = async () => {
+ if (locked) throw new Error('locked');
+ return windows();
+ };
+ const snapshot = desktop.driver.snapshot;
+ desktop.driver.snapshot = async (pid, window) => (locked ? { error: 'locked' } : snapshot(pid, window));
+ await session.submit({ expectedRevision: step.revision, values: { [field(step).id]: '[email protected]' }, action: { kind: 'submit' } });
+ expect(finished).toHaveLength(1);
+ expect(finished[0]).toMatchObject({ status: 'failed', failure: 'screen_locked' });
+ expect(latest()).toMatchObject({ terminal: true });
+ });
+
+ it('ends at once when the screen has nothing to type', async () => {
+ const desktop = fakeDesktop({ start: 'choose' });
+ const { session, finished, published } = harness(desktop.driver);
+ await session.start();
+ expect(finished[0]).toMatchObject({ status: 'cancelled', reason: 'detected', failure: 'nothing_to_fill', steps: 0 });
+ // The radio buttons and Continue never reached the owner.
+ expect(published.every((snapshot) => snapshot.controls.length === 0)).toBe(true);
+ expect(desktop.acts).toEqual([]);
+ });
+
+ it('presses Return in the last field when the page has no main button', async () => {
+ const desktop = fakeDesktop();
+ const driver: HandoffDriver = {
+ ...desktop.driver,
+ snapshot: async (pid, window) => {
+ const raw = await desktop.driver.snapshot(pid, window);
+ return 'nodes' in raw ? { ...raw, nodes: raw.nodes.filter((n) => n.role !== 'AXButton') } : raw;
+ },
+ };
+ const { session, latest } = harness(driver);
+ await session.start();
+ const step = latest();
+ await session.submit({ expectedRevision: step.revision, values: { [field(step).id]: '[email protected]' }, action: { kind: 'submit' } });
+ expect(desktop.acts.map((act) => [act.kind, act.value === 'return' ? 'return' : undefined])).toEqual([['text', undefined], ['key', 'return']]);
+ });
+
+ it('rejects stale or foreign submissions', async () => {
+ const { session, latest } = harness(fakeDesktop().driver);
+ await session.start();
+ const step = latest();
+ const submit = { kind: 'submit' } as const;
+ expect(await session.submit({ expectedRevision: step.revision - 1, values: {}, action: submit })).toBe(false);
+ expect(await session.submit({ expectedRevision: step.revision, values: { nope: 'x' }, action: submit })).toBe(false);
+ // Typing without confirming belongs to screenshot steps only.
+ expect(await session.submit({ expectedRevision: step.revision, values: { [field(step).id]: 'x' }, action: { kind: 'fill' } })).toBe(false);
+ });
+
+ it('lets the owner stay, hand back or cancel', async () => {
+ const desktop = fakeDesktop({ start: 'password' });
+ const { session, finished, latest } = harness(desktop.driver, { finishingDelayMs: 60_000, target: { app: 'Google Chrome' } });
+ await session.start();
+ const step = latest();
+ await session.submit({ expectedRevision: step.revision, values: { [field(step).id]: 'synthetic-secret' }, action: { kind: 'submit' } });
+ expect(latest().phase).toBe('finishing');
+ expect(await session.decide({ kind: 'input_handoff', action: 'stay', expectedRevision: latest().revision })).toBe(true);
+ expect(latest()).toMatchObject({ phase: 'ready', controls: [] });
+ expect(await session.decide({ kind: 'input_handoff', action: 'done', expectedRevision: latest().revision })).toBe(true);
+ expect(finished[0]).toMatchObject({ status: 'succeeded', reason: 'owner' });
+ expect(await session.decide({ kind: 'input_handoff', action: 'cancel', expectedRevision: latest().revision })).toBe(false);
+ });
+
+ it('hands back once only a search box is left', async () => {
+ const desktop = fakeDesktop({ start: 'done' });
+ const { session, finished } = harness(desktop.driver);
+ await session.start();
+ expect(finished[0]).toMatchObject({ failure: 'nothing_to_fill' });
+ });
+
+ it('fails clearly without accessibility permission or target', async () => {
+ const desktop = fakeDesktop();
+ const noPermission = harness({ ...desktop.driver, permission: async () => 'missing' });
+ await noPermission.session.start();
+ expect(noPermission.finished[0]).toMatchObject({ status: 'failed', failure: 'permission' });
+ const noTarget = harness(desktop.driver, { target: { app: 'Missing App' } });
+ await noTarget.session.start();
+ expect(noTarget.finished[0]).toMatchObject({ status: 'failed', failure: 'target_gone' });
+ const host = harness(desktop.driver, { target: { pid: 1 } });
+ await host.session.start();
+ expect(host.finished[0]).toMatchObject({ status: 'failed', failure: 'target_gone' });
+ });
+
+ it('flags agent-controlled browsers', async () => {
+ const desktop = fakeDesktop();
+ const { session, latest } = harness({ ...desktop.driver, commandLine: async () => 'Chromium --remote-debugging-port=9222' });
+ await session.start();
+ expect(latest().agentControlled).toBe(true);
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/sessionDeviceCode.test.ts b/apps/desktop/src/main/input-handoff/__tests__/sessionDeviceCode.test.ts
new file mode 100644
index 0000000000..dcd9b9bddf
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/sessionDeviceCode.test.ts
@@ -0,0 +1,95 @@
+import { describe, expect, it } from 'vitest';
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+import { InputHandoffSession, type HandoffResult } from '../session.js';
+import type { HandoffDriver } from '../macDriver.js';
+import type { NativeAxNode } from '../types.js';
+
+const node = (ref: string, role: string, extra: Partial<NativeAxNode> = {}): NativeAxNode => ({
+ ref, role, depth: 1, fp: `${role}|${extra.title ?? extra.value ?? ''}`, enabled: true, frame: [10, 10, 100, 20], ...extra,
+});
+
+/** A CLI-style app the agent already moved to "sign in with a code": it shows the code and waits. */
+function codeApp() {
+ const app = { pid: 10, app: 'Example', bundleId: 'com.example.app' };
+ const driver: HandoffDriver = {
+ permission: async () => 'granted',
+ requestPermission: async () => undefined,
+ windows: async () => ({
+ frontmost: 10,
+ apps: [{ ...app, windows: [{ index: 0, title: 'Sign in', frame: [0, 0, 800, 600], focused: true, minimized: false }] }],
+ }),
+ snapshot: async () => ({
+ ...app,
+ frontmost: true,
+ window: { index: 0, title: 'Sign in', frame: [0, 0, 800, 600] },
+ nodes: [
+ node('0', 'AXStaticText', { value: 'Open github.com/login/device and enter WDJB-MJHT' }),
+ node('1', 'AXButton', { title: 'Cancel' }),
+ ],
+ }),
+ commandLine: async () => '',
+ act: async () => ({ ok: true }),
+ };
+ return driver;
+}
+
+describe('device-code sign-in in a 代输入 session', () => {
+ it('shows the code to open elsewhere and waits for the owner instead of finishing on its own', async () => {
+ const published: InputHandoffSnapshot[] = [];
+ const finished: HandoffResult[] = [];
+ let clock = 0;
+ const session = new InputHandoffSession({
+ requestId: 'req1',
+ purpose: 'Sign in to Example',
+ target: { app: 'Example' },
+ timeoutMs: 600_000,
+ hostPid: 1,
+ remoteInput: true,
+ driver: codeApp(),
+ publish: (snapshot) => published.push(snapshot),
+ finish: (result) => finished.push(result),
+ now: () => clock,
+ sleep: async (ms) => { clock += ms; },
+ finishingDelayMs: 5,
+ });
+ const latest = () => published[published.length - 1];
+ await session.start();
+
+ // Nothing to type, yet the code still has to be used elsewhere: the card shows it and waits.
+ const code = latest();
+ expect(code.phase).toBe('ready');
+ expect(code.deviceCode).toEqual({ code: 'WDJB-MJHT', url: 'https://github.com/login/device', origin: 'https://github.com' });
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ expect(finished).toHaveLength(0);
+
+ expect(await session.decide({ kind: 'input_handoff', action: 'done', expectedRevision: code.revision })).toBe(true);
+ expect(finished[0]).toMatchObject({ status: 'succeeded', reason: 'owner' });
+ expect(latest().deviceCode).toBeUndefined();
+ });
+});
+
+describe('a locked computer in a 代输入 session', () => {
+ it('ends with screen_locked instead of blaming the window', async () => {
+ const finished: HandoffResult[] = [];
+ const driver: HandoffDriver = {
+ ...codeApp(),
+ windows: async () => {
+ throw new Error('locked');
+ },
+ };
+ const session = new InputHandoffSession({
+ requestId: 'req2',
+ purpose: 'Sign in to Example',
+ target: { app: 'Example' },
+ timeoutMs: 600_000,
+ hostPid: 1,
+ remoteInput: true,
+ driver,
+ publish: () => undefined,
+ finish: (result) => finished.push(result),
+ finishingDelayMs: 5,
+ });
+ await session.start();
+ expect(finished[0]).toMatchObject({ status: 'failed', failure: 'screen_locked' });
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/sessionPicture.test.ts b/apps/desktop/src/main/input-handoff/__tests__/sessionPicture.test.ts
new file mode 100644
index 0000000000..d28768a776
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/sessionPicture.test.ts
@@ -0,0 +1,163 @@
+import { describe, expect, it } from 'vitest';
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+import { InputHandoffSession, type HandoffResult } from '../session.js';
+import type { HandoffDriver } from '../macDriver.js';
+import type { NativeAxNode, NativeAxSnapshot, PointerRequest } from '../types.js';
+
+
+const node = (ref: string, role: string, extra: Partial<NativeAxNode> = {}): NativeAxNode => ({
+ ref, role, depth: 1, fp: `${role}|${extra.title ?? ''}`, enabled: true, frame: [150, 100, 100, 20], ...extra,
+});
+
+type Stage = 'canvas' | 'password' | 'form' | 'done';
+
+/** A self-drawn sign-in (canvas): nothing to read until the owner gets past it on the picture. */
+function canvasDesktop(options: { capture?: boolean; covered?: boolean } = {}) {
+ let stage: Stage = 'canvas';
+ const pointers: PointerRequest[] = [];
+ const jpegs: Buffer[] = [];
+ const app = { pid: 10, app: 'Game', bundleId: 'com.example.game' };
+ const frame = [100, 50, 800, 600];
+ const snapshot = (): NativeAxSnapshot => {
+ const base = { ...app, frontmost: true, window: { index: 0, title: 'Game', frame } };
+ if (stage === 'form')
+ return { ...base, nodes: [node('0', 'AXTextField', { title: 'Nickname' }), node('1', 'AXButton', { title: 'Play' })] };
+ if (stage === 'done') return { ...base, nodes: [node('0', 'AXStaticText', { value: 'Welcome' })] };
+ return { ...base, nodes: [node('0', 'AXStaticText', { value: 'Sign in' })] };
+ };
+ const driver: HandoffDriver = {
+ permission: async () => 'granted',
+ requestPermission: async () => undefined,
+ windows: async () => ({
+ frontmost: 10,
+ apps: [{ ...app, windows: [{ index: 0, title: 'Game', frame, focused: true, minimized: false }] }],
+ }),
+ snapshot: async () => snapshot(),
+ commandLine: async () => '',
+ act: async (request) => {
+ if (stage === 'form' && request.kind === 'press') stage = 'done';
+ return { ok: true };
+ },
+ ...(options.capture === false
+ ? {}
+ : {
+ capture: async () => {
+ const jpeg = Buffer.from(`shot-${stage}`);
+ jpegs.push(jpeg);
+ return { jpeg, width: 1600, height: 1200, area: frame, windowFrame: frame };
+ },
+ }),
+ focusedField: async () => ({ editable: stage === 'password', secure: stage === 'password' }),
+ pointer: async (request) => {
+ pointers.push(request);
+ if (request.kind === 'tap') {
+ if (options.covered) return { error: 'covered' };
+ if (stage === 'canvas') stage = 'password';
+ } else if (stage === 'password' && request.submit) stage = 'form';
+ return { ok: true };
+ },
+ };
+ return { driver, pointers, jpegs, stage: () => stage };
+}
+
+function harness(driver: HandoffDriver) {
+ const published: InputHandoffSnapshot[] = [];
+ const finished: HandoffResult[] = [];
+ let clock = 0;
+ const session = new InputHandoffSession({
+ requestId: 'req1',
+ purpose: 'Sign in to Game',
+ target: { app: 'Game' },
+ timeoutMs: 600_000,
+ hostPid: 1,
+ remoteInput: true,
+ driver,
+ publish: (snapshot) => published.push(snapshot),
+ finish: (result) => finished.push(result),
+ now: () => clock,
+ sleep: async (ms) => { clock += ms; },
+ finishingDelayMs: 5,
+ });
+ return { session, published, finished, latest: () => published[published.length - 1]! };
+}
+
+describe('代输入 screenshot steps', () => {
+ it('answers an unreadable window on its picture, then returns to the form', async () => {
+ const desktop = canvasDesktop();
+ const { session, published, latest } = harness(desktop.driver);
+ await session.start();
+
+ let step = latest();
+ expect(step).toMatchObject({ phase: 'ready', picture: true, controls: [], source: { app: 'Game', window: 'Game' } });
+ const picture = session.pictureFor(step.revision)!;
+ expect(picture).toMatchObject({ mime: 'image/jpeg', width: 1600, height: 1200 });
+ expect(Buffer.from(picture.data, 'base64').toString()).toBe('shot-canvas');
+ // Pixels are handed out only for the step they belong to.
+ expect(session.pictureFor(step.revision - 1)).toBeNull();
+
+ expect(await session.submit({ expectedRevision: step.revision, values: {}, action: { kind: 'tap', x: 0.5, y: 0.25 } })).toBe(true);
+ expect(desktop.pointers[0]).toMatchObject({ kind: 'tap', pid: 10, point: [500, 200], area: [100, 50, 800, 600] });
+
+ step = latest();
+ expect(step).toMatchObject({ phase: 'ready', picture: true, stepNumber: 1 });
+ expect(step.controls).toEqual([{ id: 'typed', kind: 'text', label: '', contentType: 'password' }]);
+ expect(await session.submit({ expectedRevision: step.revision, values: { typed: 'hunter2' }, action: { kind: 'submit' } })).toBe(true);
+ expect(desktop.pointers[1]).toMatchObject({ kind: 'type', value: 'hunter2', submit: true, secure: true });
+
+ step = latest();
+ expect(step.picture).toBeUndefined();
+ expect(step.stepNumber).toBe(2);
+ expect(step.controls.some((control) => control.kind === 'text' && control.label === 'Nickname')).toBe(true);
+ expect(session.pictureFor(step.revision)).toBeNull();
+ // Earlier pictures are wiped once the step moves on; no value or pixels are ever published.
+ expect(desktop.jpegs.every((jpeg) => jpeg.every((byte) => byte === 0))).toBe(true);
+ expect(JSON.stringify(published)).not.toContain('hunter2');
+ expect(JSON.stringify(published)).not.toContain(picture.data);
+ });
+
+ it('accepts only typing into a focused field on a picture', async () => {
+ const desktop = canvasDesktop();
+ const { session, latest } = harness(desktop.driver);
+ await session.start();
+ const step = latest();
+ expect(await session.submit({ expectedRevision: step.revision, values: { typed: 'x' }, action: { kind: 'submit' } })).toBe(false);
+ expect(await session.submit({ expectedRevision: step.revision, values: {}, action: { kind: 'fill' } })).toBe(true);
+ // Typing with no focused field does nothing on the target.
+ expect(desktop.pointers).toHaveLength(0);
+ expect(latest().failure).toBe('action_failed');
+ });
+
+ it('lets the owner ask for the picture of a readable step and go back to the form', async () => {
+ const desktop = canvasDesktop();
+ const { session, latest } = harness(desktop.driver);
+ await session.start();
+ await session.submit({ expectedRevision: latest().revision, values: {}, action: { kind: 'tap', x: 0.1, y: 0.1 } });
+ await session.submit({ expectedRevision: latest().revision, values: { typed: 'pw' }, action: { kind: 'submit' } });
+ const form = latest();
+ expect(form.picture).toBeUndefined();
+
+ expect(await session.decide({ kind: 'input_handoff', action: 'picture', expectedRevision: form.revision })).toBe(true);
+ expect(latest()).toMatchObject({ picture: true, phase: 'ready' });
+ expect(Buffer.from(session.pictureFor(latest().revision)!.data, 'base64').toString()).toBe('shot-form');
+
+ expect(await session.decide({ kind: 'input_handoff', action: 'refresh', expectedRevision: latest().revision })).toBe(true);
+ expect(latest().picture).toBeUndefined();
+ expect(latest().controls.some((control) => control.kind === 'text' && control.label === 'Nickname')).toBe(true);
+ });
+
+ it('reports a covered or moved window instead of tapping something else', async () => {
+ const desktop = canvasDesktop({ covered: true });
+ const { session, latest } = harness(desktop.driver);
+ await session.start();
+ await session.submit({ expectedRevision: latest().revision, values: {}, action: { kind: 'tap', x: 0.5, y: 0.5 } });
+ expect(latest()).toMatchObject({ picture: true, failure: 'action_failed' });
+ expect(desktop.stage()).toBe('canvas');
+ });
+
+ it('fails clearly when the window can be neither read nor photographed', async () => {
+ const { session, finished, published } = harness(canvasDesktop({ capture: false }).driver);
+ await session.start();
+ expect(finished[0]).toMatchObject({ status: 'failed', failure: 'unreadable' });
+ expect(published.some((snapshot) => snapshot.picture)).toBe(false);
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/sessionQr.test.ts b/apps/desktop/src/main/input-handoff/__tests__/sessionQr.test.ts
new file mode 100644
index 0000000000..cc53a52d37
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/sessionQr.test.ts
@@ -0,0 +1,270 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+import { InputHandoffSession, type HandoffResult } from '../session.js';
+import type { HandoffDriver } from '../macDriver.js';
+import type { NativeAxNode, NativeAxSnapshot, NativeWindowList } from '../types.js';
+
+const node = (ref: string, role: string, extra: Partial<NativeAxNode> = {}): NativeAxNode => ({
+ ref, role, depth: 1, fp: `${role}|${extra.title ?? ''}`, enabled: true, frame: [150, 100, 100, 20], ...extra,
+});
+
+type Stage = 'qr' | 'confirm' | 'code' | 'home' | 'closed';
+
+/**
+ * A generic scan-to-sign-in window: a QR code with a button (nothing to type),
+ * then "confirm on your phone" once scanned, then the app's main window.
+ */
+function qrDesktop(options: { web?: boolean } = {}) {
+ let stage: Stage = 'qr';
+ let code = 'https://login.example.com/qr?token=first';
+ let front = 10;
+ let titled: string | null = null;
+ let broken = false;
+ const looks: Array<number[] | null> = [];
+ const app = options.web
+ ? { pid: 10, app: 'Google Chrome', bundleId: 'com.google.Chrome' }
+ : { pid: 10, app: 'Chat', bundleId: 'com.example.chat' };
+ const frame = [100, 50, 400, 500];
+ const title = () => titled ?? (stage === 'home' ? 'Chat' : 'Sign in');
+ const windows = (): NativeWindowList => ({
+ frontmost: front,
+ apps: [
+ { ...app, windows: stage === 'closed' ? [] : [{ index: 0, title: title(), frame, focused: true, minimized: false }] },
+ { pid: 30, app: 'Notes', bundleId: 'com.example.notes', windows: [{ index: 0, title: 'Notes', frame, focused: true, minimized: false }] },
+ ],
+ });
+ const snapshot = (): NativeAxSnapshot => {
+ const base = { ...app, frontmost: true, window: { index: 0, title: title(), frame } };
+ const page = (url: string, nodes: NativeAxNode[]) =>
+ options.web ? [node('9', 'AXWebArea', { url, frame }), ...nodes.map((n) => ({ ...n, ref: `9.${n.ref}` }))] : nodes;
+ if (stage === 'code')
+ return { ...base, nodes: page('https://login.example.com/qr', [node('0', 'AXTextField', { title: 'Code' }), node('1', 'AXButton', { title: 'Verify' })]) };
+ if (stage === 'home')
+ return { ...base, nodes: page('https://app.example.com/', [node('0', 'AXButton', { title: 'New chat' })]) };
+ return {
+ ...base,
+ nodes: page('https://login.example.com/qr', [
+ node('0', 'AXStaticText', { value: stage === 'qr' ? 'Scan to sign in' : 'Confirm on your phone' }),
+ node('1', 'AXButton', { title: 'Switch account' }),
+ ]),
+ };
+ };
+ const driver: HandoffDriver = {
+ permission: async () => 'granted',
+ requestPermission: async () => undefined,
+ windows: async () => windows(),
+ snapshot: async () => snapshot(),
+ commandLine: async () => '',
+ act: async () => ({ ok: true }),
+ capture: async () => ({ jpeg: Buffer.from('window'), width: 800, height: 1000, area: frame, windowFrame: frame }),
+ focusedField: async () => ({ editable: false, secure: false }),
+ pointer: async () => ({ ok: true }),
+ qr: async (_target, at) => {
+ looks.push(at);
+ if (broken) return { error: 'unavailable' as const };
+ if (stage !== 'qr') return null;
+ return { text: code, capture: { jpeg: Buffer.from(`code:${code}`), width: 360, height: 360, area: [200, 150, 180, 180], windowFrame: frame } };
+ },
+ };
+ return {
+ driver,
+ looks,
+ set stage(next: Stage) { stage = next; },
+ set code(next: string) { code = next; },
+ set front(pid: number) { front = pid; },
+ set title(next: string | null) { titled = next; },
+ set broken(next: boolean) { broken = next; },
+ };
+}
+
+function harness(driver: HandoffDriver, app = 'Chat') {
+ const published: InputHandoffSnapshot[] = [];
+ const finished: HandoffResult[] = [];
+ let clock = 0;
+ const session = new InputHandoffSession({
+ requestId: 'req1',
+ purpose: 'Sign in to Chat',
+ target: { app },
+ timeoutMs: 600_000,
+ hostPid: 1,
+ remoteInput: true,
+ driver,
+ publish: (snapshot) => published.push(snapshot),
+ finish: (result) => finished.push(result),
+ now: () => clock,
+ sleep: async (ms) => { clock += ms; },
+ finishingDelayMs: 3000,
+ });
+ return { session, published, finished, latest: () => published[published.length - 1] };
+}
+
+const watch = () => vi.advanceTimersByTimeAsync(2000);
+
+describe('代输入 scan-to-sign-in', () => {
+ beforeEach(() => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
+ });
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ it('hands a QR code on a screen with nothing to type to the owner, with what it says', async () => {
+ const desktop = qrDesktop();
+ const { session, latest } = harness(desktop.driver);
+ await session.start();
+ expect(latest()).toMatchObject({ phase: 'ready', qr: 'scan', picture: true, controls: [], source: { app: 'Chat' } });
+ // The content travels only with the sealed picture, never in the snapshot.
+ expect(JSON.stringify(latest())).not.toContain('token=first');
+ expect(session.pictureFor(latest().revision)).toMatchObject({
+ data: Buffer.from('code:https://login.example.com/qr?token=first').toString('base64'),
+ qr: { text: 'https://login.example.com/qr?token=first', url: 'https://login.example.com/qr?token=first' },
+ });
+ // The first look brings the window forward; it is not left to an agent's guess.
+ expect(desktop.looks).toEqual([null]);
+ session.cancel();
+ });
+
+ it('follows a refreshed code without bringing the window forward again', async () => {
+ const desktop = qrDesktop();
+ const { session, published, latest } = harness(desktop.driver);
+ await session.start();
+ const first = published.length;
+ await watch();
+ expect(published.length).toBe(first);
+ desktop.code = 'https://login.example.com/qr?token=second';
+ await watch();
+ expect(latest()).toMatchObject({ phase: 'ready', qr: 'scan' });
+ expect(session.pictureFor(latest().revision)?.qr?.text).toBe('https://login.example.com/qr?token=second');
+ expect(desktop.looks.slice(1).every((frame) => Array.isArray(frame))).toBe(true);
+ session.cancel();
+ });
+
+ it('waits after the scan, then hands back once the window moves on', async () => {
+ const desktop = qrDesktop();
+ const { session, finished, latest } = harness(desktop.driver);
+ await session.start();
+ desktop.stage = 'confirm';
+ await watch();
+ expect(latest()).toMatchObject({ phase: 'ready', qr: 'scanned', controls: [] });
+ expect(latest().picture).toBeUndefined();
+ expect(session.pictureFor(latest().revision)).toBeNull();
+ await watch();
+ expect(finished).toEqual([]);
+ desktop.stage = 'home';
+ await watch();
+ expect(latest()).toMatchObject({ phase: 'finishing' });
+ await vi.advanceTimersByTimeAsync(3000);
+ expect(finished).toEqual([expect.objectContaining({ status: 'succeeded', reason: 'detected', steps: 1 })]);
+ });
+
+ it('goes back to the code when it comes back (expired, or the scan was cancelled)', async () => {
+ const desktop = qrDesktop();
+ const { session, latest } = harness(desktop.driver);
+ await session.start();
+ desktop.stage = 'confirm';
+ await watch();
+ expect(latest().qr).toBe('scanned');
+ desktop.stage = 'qr';
+ desktop.code = 'https://login.example.com/qr?token=again';
+ await watch();
+ expect(latest()).toMatchObject({ qr: 'scan', picture: true });
+ expect(session.pictureFor(latest().revision)?.qr?.text).toBe('https://login.example.com/qr?token=again');
+ session.cancel();
+ });
+
+ it('keeps waiting when a look at the code fails', async () => {
+ const desktop = qrDesktop();
+ const { session, published, finished } = harness(desktop.driver);
+ await session.start();
+ const before = published.length;
+ desktop.broken = true;
+ await watch();
+ await watch();
+ expect(published.length).toBe(before);
+ expect(published[published.length - 1].qr).toBe('scan');
+ expect(finished).toEqual([]);
+ session.cancel();
+ });
+
+ it('does not take a title change for a sign-in while the code still shows', async () => {
+ const desktop = qrDesktop();
+ const { session, published, finished } = harness(desktop.driver);
+ await session.start();
+ desktop.title = '(1) Sign in';
+ await watch();
+ expect(published[published.length - 1]).toMatchObject({ phase: 'ready', qr: 'scan' });
+ // The flow then really moves on.
+ desktop.title = null;
+ desktop.stage = 'home';
+ await watch();
+ expect(published[published.length - 1]).toMatchObject({ phase: 'finishing' });
+ expect(finished).toEqual([]);
+ session.cancel();
+ });
+
+ it('draws no conclusion while another app covers the window', async () => {
+ const desktop = qrDesktop();
+ const { session, published, finished } = harness(desktop.driver);
+ await session.start();
+ const before = published.length;
+ desktop.front = 30;
+ desktop.stage = 'confirm';
+ await watch();
+ await watch();
+ expect(published.length).toBe(before);
+ // Back in front: now it can be seen that the code was scanned.
+ desktop.front = 10;
+ await watch();
+ expect(published[published.length - 1].qr).toBe('scanned');
+ // A title change while covered still counts: that is this window moving on, not the app in front.
+ desktop.front = 30;
+ desktop.stage = 'home';
+ await watch();
+ expect(published[published.length - 1]).toMatchObject({ phase: 'finishing', source: { app: 'Chat', window: 'Chat' } });
+ expect(finished).toEqual([]);
+ session.cancel();
+ });
+
+ it('asks for what comes next when the scan leads to something to type', async () => {
+ const desktop = qrDesktop({ web: true });
+ const { session, latest } = harness(desktop.driver, 'Google Chrome');
+ await session.start();
+ expect(latest()).toMatchObject({ qr: 'scan', source: { origin: 'https://login.example.com' } });
+ desktop.stage = 'code';
+ await watch();
+ expect(latest()).toMatchObject({ phase: 'ready', controls: [expect.objectContaining({ kind: 'text', label: 'Code' })] });
+ expect(latest().qr).toBeUndefined();
+ session.cancel();
+ });
+
+ it('ends when the window with the code closes', async () => {
+ const desktop = qrDesktop();
+ const { session, finished } = harness(desktop.driver);
+ await session.start();
+ desktop.stage = 'closed';
+ await watch();
+ expect(finished).toEqual([expect.objectContaining({ status: 'succeeded', reason: 'detected' })]);
+ });
+
+ it('shows content that is not a link as text only', async () => {
+ const desktop = qrDesktop();
+ desktop.code = 'WIFI:S:home;T:WPA;P:secret;;';
+ const { session, latest } = harness(desktop.driver);
+ await session.start();
+ expect(session.pictureFor(latest().revision)?.qr).toEqual({ text: 'WIFI:S:home;T:WPA;P:secret;;' });
+ session.cancel();
+ });
+
+ it('shows the whole window when the owner asks to see it, and stops watching the code', async () => {
+ const desktop = qrDesktop();
+ const { session, latest } = harness(desktop.driver);
+ await session.start();
+ await session.decide({ kind: 'input_handoff', action: 'picture', expectedRevision: latest().revision });
+ expect(latest()).toMatchObject({ picture: true });
+ expect(latest().qr).toBeUndefined();
+ const looks = desktop.looks.length;
+ await watch();
+ expect(desktop.looks.length).toBe(looks);
+ session.cancel();
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/sessionSecrets.test.ts b/apps/desktop/src/main/input-handoff/__tests__/sessionSecrets.test.ts
new file mode 100644
index 0000000000..844340607b
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/sessionSecrets.test.ts
@@ -0,0 +1,117 @@
+import { describe, expect, it } from 'vitest';
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+import { isHumanDesktopInputActive } from '../../remote-desktop/inputOwnership.js';
+import type { HandoffDriver } from '../macDriver.js';
+import { InputHandoffSession, type HandoffResult } from '../session.js';
+import type { NativeActRequest, NativeAxNode } from '../types.js';
+
+const node = (ref: string, role: string, extra: Partial<NativeAxNode> = {}): NativeAxNode => ({
+ ref, role, depth: 1, fp: `${role}|${extra.title ?? ''}`, enabled: true, frame: [10, 10, 100, 20], ...extra,
+});
+
+/** A sign-in page in a browser whose address can change under the card. */
+function loginPage(commandLine = '') {
+ let url = 'https://login.example.com/signin';
+ let form = true;
+ const acts: Array<NativeActRequest & { humanActive: boolean }> = [];
+ const browser = { pid: 20, app: 'Google Chrome', bundleId: 'com.google.Chrome' };
+ const driver: HandoffDriver = {
+ permission: async () => 'granted',
+ requestPermission: async () => undefined,
+ windows: async () => ({
+ frontmost: 20,
+ apps: [{ ...browser, windows: [{ index: 0, title: 'Sign in', frame: [0, 0, 800, 600], focused: true, minimized: false }] }],
+ }),
+ snapshot: async () => ({
+ ...browser, frontmost: true, window: { index: 0, title: 'Sign in', frame: [0, 0, 800, 600] },
+ nodes: [
+ node('0', 'AXWebArea', { url, frame: [0, 0, 800, 600] }),
+ ...(form
+ ? [
+ node('0.0', 'AXTextField', { title: 'Email' }),
+ node('0.1', 'AXTextField', { title: 'Password', subrole: 'AXSecureTextField', secure: true }),
+ ]
+ : [node('0.3', 'AXStaticText', { value: 'Choose an account' })]),
+ node('0.2', 'AXButton', { title: 'Sign in' }),
+ ],
+ }),
+ commandLine: async () => commandLine,
+ act: async (request) => {
+ acts.push({ ...request, humanActive: isHumanDesktopInputActive() });
+ return { ok: true };
+ },
+ };
+ return { driver, acts, navigate: (next: string, keepForm = true) => { url = next; form = keepForm; } };
+}
+
+function start(driver: HandoffDriver, onSecretEntered?: (target: { pid: number; url?: string }) => void) {
+ const published: InputHandoffSnapshot[] = [];
+ const finished: HandoffResult[] = [];
+ let clock = 0;
+ const session = new InputHandoffSession({
+ requestId: 'req1', purpose: 'Sign in', target: { app: 'Google Chrome' }, timeoutMs: 600_000, hostPid: 1,
+ remoteInput: true, driver, publish: (s) => published.push(s), finish: (result) => finished.push(result),
+ now: () => clock, sleep: async (ms) => { clock += ms; }, finishingDelayMs: 60_000, settleTimeoutMs: 2000,
+ ...(onSecretEntered ? { onSecretEntered } : {}),
+ });
+ return { session, finished, latest: () => published[published.length - 1] };
+}
+
+function answer(step: InputHandoffSnapshot) {
+ const [email, password] = step.controls.filter((c) => c.kind === 'text');
+ return {
+ expectedRevision: step.revision,
+ values: { [email.id]: '[email protected]', [password.id]: 'synthetic-pass' },
+ action: { kind: 'submit' as const },
+ };
+}
+
+describe('代输入 secrets', () => {
+ it('types while holding the desktop, so the agent cannot act in between', async () => {
+ const page = loginPage();
+ const { session, latest } = start(page.driver);
+ await session.start();
+ await session.submit(answer(latest()));
+ expect(page.acts.length).toBeGreaterThan(0);
+ expect(page.acts.every((act) => act.humanActive)).toBe(true);
+ expect(isHumanDesktopInputActive()).toBe(false);
+ });
+
+ it('fills nothing when the page changed after the owner saw it', async () => {
+ const page = loginPage();
+ const { session, latest } = start(page.driver);
+ await session.start();
+ const step = latest();
+ page.navigate('https://login.example.net/signin');
+ await session.submit(answer(step));
+ expect(page.acts.filter((act) => act.kind === 'text')).toEqual([]);
+ expect(latest()).toMatchObject({ phase: 'ready', failure: 'origin_changed', source: { origin: 'https://login.example.net' } });
+ });
+
+ it('ends as a changed page, not as nothing to fill, when the new page asks for nothing', async () => {
+ const page = loginPage();
+ const { session, finished, latest } = start(page.driver);
+ await session.start();
+ const step = latest();
+ page.navigate('https://login.example.net/choose', false);
+ await session.submit(answer(step));
+ expect(page.acts.filter((act) => act.kind === 'text')).toEqual([]);
+ expect(finished[0]).toMatchObject({ status: 'failed', failure: 'origin_changed' });
+ });
+
+ it('reports a secret typed into a browser the agent drives', async () => {
+ const entered: Array<{ pid: number; url?: string }> = [];
+ const page = loginPage('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --remote-debugging-port=9222');
+ const { session, latest } = start(page.driver, (target) => entered.push(target));
+ await session.start();
+ await session.submit(answer(latest()));
+ expect(entered).toEqual([{ pid: 20, url: 'https://login.example.com/signin' }]);
+
+ const ownChrome = loginPage();
+ const own: unknown[] = [];
+ const second = start(ownChrome.driver, (target) => own.push(target));
+ await second.session.start();
+ await second.session.submit(answer(second.latest()));
+ expect(own).toEqual([]);
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/stepExtractor.test.ts b/apps/desktop/src/main/input-handoff/__tests__/stepExtractor.test.ts
new file mode 100644
index 0000000000..ddf429a706
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/stepExtractor.test.ts
@@ -0,0 +1,149 @@
+import { describe, expect, it } from 'vitest';
+import { contentTypeFor, extractStep } from '../stepExtractor.js';
+import { classifyOrigin } from '../originPolicy.js';
+import type { NativeAxNode, NativeAxSnapshot } from '../types.js';
+
+const node = (ref: string, role: string, extra: Partial<NativeAxNode> = {}): NativeAxNode => ({
+ ref,
+ role,
+ depth: ref.split('.').length,
+ fp: `${role}|${extra.title ?? extra.desc ?? ''}`,
+ enabled: true,
+ frame: [100, 100, 200, 30],
+ ...extra,
+});
+
+const snapshot = (nodes: NativeAxNode[], extra: Partial<NativeAxSnapshot> = {}): NativeAxSnapshot => ({
+ pid: 42,
+ app: 'Google Chrome',
+ bundleId: 'com.google.Chrome',
+ frontmost: true,
+ window: { index: 0, title: 'Sign in', frame: [0, 0, 1200, 900] },
+ nodes,
+ ...extra,
+});
+
+describe('extractStep', () => {
+ it('scopes a browser window to the page and maps a login form to standard fields', () => {
+ const step = extractStep(snapshot([
+ node('0', 'AXButton', { desc: 'Reload', frame: [10, 10, 20, 20] }),
+ node('1', 'AXTextField', { desc: 'Address and search bar', frame: [40, 10, 600, 20] }),
+ node('2', 'AXWebArea', { url: 'https://accounts.example.com/signin?x=1', frame: [0, 60, 1200, 840] }),
+ node('2.0', 'AXHeading', { title: 'Sign in', frame: [100, 80, 300, 30] }),
+ node('2.1', 'AXStaticText', { value: 'Email', frame: [100, 130, 60, 18] }),
+ node('2.2', 'AXTextField', { frame: [100, 150, 300, 30], hasValue: false }),
+ node('2.3', 'AXTextField', { subrole: 'AXSecureTextField', secure: true, title: 'Password', frame: [100, 200, 300, 30] }),
+ node('2.4', 'AXLink', { title: 'Forgot password?', frame: [100, 240, 120, 18] }),
+ node('2.5', 'AXButton', { title: 'Next', frame: [300, 280, 100, 30] }),
+ ]));
+ expect(step.source).toEqual({ app: 'Google Chrome', window: 'Sign in', origin: 'https://accounts.example.com' });
+ const interactive = step.controls.filter((control) => control.kind !== 'note');
+ expect(interactive.map((control) => [control.kind, control.label])).toEqual([
+ ['text', 'Email'],
+ ['text', 'Password'],
+ ['button', 'Forgot password?'],
+ ['button', 'Next'],
+ ]);
+ const [account, password, forgot, next] = interactive as any[];
+ expect(account.contentType).toBe('username');
+ expect(password.contentType).toBe('password');
+ expect(forgot.link).toBe(true);
+ expect(next.primary).toBe(true);
+ expect(step.controls[0]).toEqual({ id: expect.any(String), kind: 'note', tone: 'heading', text: 'Sign in' });
+ expect(step.hasSecure).toBe(true);
+ expect(step.bindings.get(password.id)).toEqual({ kind: 'text', ref: '2.3', fp: expect.any(String), secure: true });
+ expect(JSON.stringify(step.controls)).not.toContain('Address and search bar');
+ // The owner sees only the fields to type.
+ expect(step.shown.map((control) => control.kind === 'text' && control.label)).toEqual(['Email', 'Password']);
+ });
+
+ it('reads a native app choice screen but shows the owner nothing on it', () => {
+ const step = extractStep(snapshot([
+ node('0', 'AXButton', { subrole: 'AXCloseButton', desc: 'close' }),
+ node('1', 'AXRadioGroup', { desc: 'Login method' }),
+ node('1.0', 'AXRadioButton', { title: 'Personal', checked: true }),
+ node('1.1', 'AXRadioButton', { title: 'Enterprise SSO', checked: false }),
+ node('2', 'AXPopUpButton', { title: 'Region', value: 'Global', options: ['Global', 'China'] }),
+ node('3', 'AXCheckBox', { title: 'Remember me', checked: false }),
+ node('4', 'AXButton', { title: 'Continue' }),
+ ], { app: 'Cindy', bundleId: 'com.example.cindy' }));
+ expect(step.source.origin).toBeUndefined();
+ expect(step.controls.map((control) => control.kind)).toEqual(['choice', 'choice', 'toggle', 'button']);
+ const [method, region, remember] = step.controls as any[];
+ expect(method).toMatchObject({ label: 'Login method', selected: 'o0', options: [{ id: 'o0', label: 'Personal' }, { id: 'o1', label: 'Enterprise SSO' }] });
+ expect(region).toMatchObject({ label: 'Region', selected: 'o0' });
+ expect(remember).toMatchObject({ checked: false });
+ // Options and buttons are the agent's: no field means nothing for the owner.
+ expect(step.shown).toEqual([]);
+ expect(step.bindings.get(method.id)).toBeUndefined();
+ });
+
+ it('ignores hidden nodes and app content web areas keep no origin', () => {
+ const step = extractStep(snapshot([
+ node('0', 'AXWebArea', { url: 'file:///Applications/App.app/index.html', frame: [0, 0, 1200, 900] }),
+ node('0.0', 'AXTextField', { title: 'Org code', frame: [0, 0, 1, 0] }),
+ node('0.1', 'AXTextField', { title: 'Organization', frame: [10, 10, 200, 30] }),
+ ], { app: 'App', bundleId: 'com.example.app' }));
+ expect(step.controls.map((control: any) => control.label)).toEqual(['Organization']);
+ expect(step.source.origin).toBeUndefined();
+ });
+
+ it('reports filled fields without values and keeps signatures stable', () => {
+ const nodes = [node('0', 'AXTextField', { title: 'Name', hasValue: true }), node('1', 'AXButton', { title: 'Save' })];
+ const a = extractStep(snapshot(nodes, { bundleId: 'x' }));
+ const b = extractStep(snapshot(nodes, { bundleId: 'x' }));
+ expect(a.controls[0]).toMatchObject({ kind: 'text', filled: true });
+ expect(a.signature).toBe(b.signature);
+ });
+
+ it('caps crowded screens but keeps inputs and the primary action', () => {
+ const nodes: NativeAxNode[] = [];
+ for (let i = 0; i < 60; i++) nodes.push(node(String(i), 'AXLink', { title: `Footer ${i}`, frame: [10, 10 + i, 50, 10] }));
+ nodes.push(node('60', 'AXTextField', { title: 'Code', frame: [10, 700, 100, 30] }));
+ nodes.push(node('61', 'AXButton', { title: 'Verify', frame: [10, 740, 100, 30] }));
+ const step = extractStep(snapshot(nodes, { bundleId: 'x' }));
+ expect(step.controls.length).toBeLessThanOrEqual(40);
+ expect(step.controls.some((control) => control.kind === 'text' && control.contentType === 'one-time-code')).toBe(false);
+ expect(step.controls.some((control) => control.kind === 'text' && control.label === 'Code')).toBe(true);
+ expect(step.controls.some((control) => control.kind === 'button' && control.primary)).toBe(true);
+ expect(step.bindings.size).toBe(step.controls.filter((control) => control.kind !== 'note').length);
+ });
+
+ it('turns alert text into error notes', () => {
+ const step = extractStep(snapshot([
+ node('0', 'AXStaticText', { value: 'Wrong password', alert: true }),
+ node('1', 'AXTextField', { secure: true, title: 'Password' }),
+ ], { bundleId: 'x' }));
+ expect(step.controls[0]).toMatchObject({ kind: 'note', tone: 'error', text: 'Wrong password' });
+ expect(step.shown.map((control) => control.kind)).toEqual(['note', 'text']);
+ });
+});
+
+describe('contentTypeFor', () => {
+ it.each([
+ ['验证码', 'one-time-code'],
+ ['Enter the 6-digit verification code', 'one-time-code'],
+ ['邮箱', 'email'],
+ ['手机号', 'tel'],
+ ['用户名', 'username'],
+ ['Company website URL', 'url'],
+ ['Organization code', 'text'],
+ ])('%s → %s', (label, expected) => {
+ expect(contentTypeFor({ ref: '0', role: 'AXTextField', depth: 1, fp: '' }, label)).toBe(expected);
+ });
+});
+
+describe('classifyOrigin', () => {
+ it.each([
+ ['https://login.example.com/a', true, { origin: 'https://login.example.com' }],
+ ['http://login.example.com/a', true, { origin: 'http://login.example.com', warning: 'insecure' }],
+ ['http://127.0.0.1:8080/', true, { origin: 'http://127.0.0.1:8080', warning: 'local-host' }],
+ ['https://10.0.0.3/login', true, { origin: 'https://10.0.0.3', warning: 'ip-address' }],
+ ['https://xn--pple-43d.com/', true, { origin: 'https://xn--pple-43d.com', warning: 'punycode' }],
+ ['file:///tmp/a.html', true, { origin: 'file://', warning: 'local-file' }],
+ ['file:///tmp/a.html', false, {}],
+ ['app://index.html', false, {}],
+ ])('%s', (url, browser, expected) => {
+ expect(classifyOrigin(url, browser)).toEqual(expected);
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/__tests__/terminalPrompt.test.ts b/apps/desktop/src/main/input-handoff/__tests__/terminalPrompt.test.ts
new file mode 100644
index 0000000000..f84d7d576e
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/__tests__/terminalPrompt.test.ts
@@ -0,0 +1,91 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+import { InputHandoffService } from '../service.js';
+import { buildTerminalPromptStep } from '../terminalPrompt.js';
+
+describe('terminal prompt card', () => {
+ it('maps common prompts to the right standard field', () => {
+ const field = (prompt: string, program: 'sudo' | 'ssh' | 'git' = 'ssh') =>
+ buildTerminalPromptStep(prompt, program).controls[0];
+ expect(field('[sudo] password for someone:', 'sudo')).toMatchObject({ kind: 'text', contentType: 'password' });
+ expect(field("Enter passphrase for key '/Users/someone/.ssh/id_ed25519':")).toMatchObject({ contentType: 'password' });
+ expect(field('(someone@host) Verification code:')).toMatchObject({ contentType: 'one-time-code' });
+ expect(field("Username for 'https://git.example':", 'git')).toMatchObject({ contentType: 'username' });
+ });
+
+ it('shows where a git credential goes and warns about plain http', () => {
+ expect(buildTerminalPromptStep("Password for 'https://[email protected]':", 'git').source)
+ .toEqual({ app: 'git', origin: 'https://git.example' });
+ expect(buildTerminalPromptStep("Password for 'http://git.example':", 'git').source)
+ .toEqual({ app: 'git', origin: 'http://git.example', warning: 'insecure' });
+ });
+
+ it('asks for a typed yes / no for an unknown ssh host key', () => {
+ const step = buildTerminalPromptStep('Are you sure you want to continue connecting (yes/no/[fingerprint])?', 'ssh');
+ expect(step.controls).toEqual([expect.objectContaining({ kind: 'text', contentType: 'text', placeholder: 'yes / no' })]);
+ });
+});
+
+const services: InputHandoffService[] = [];
+afterEach(() => services.splice(0).forEach((s) => s.cleanupAll()));
+
+function harness() {
+ const snapshots: InputHandoffSnapshot[] = [];
+ const continued: string[] = [];
+ const service = new InputHandoffService({
+ broadcast: (_channel, payload) => {
+ const request = (payload as { request?: InputHandoffSnapshot }).request;
+ if (request) snapshots.push(request);
+ },
+ createDriver: () => null,
+ hostPid: 1,
+ remoteInputAvailable: () => true,
+ continueAgent: async (_s, _r, message) => { continued.push(message); },
+ terminalRetentionMs: 0,
+ });
+ services.push(service);
+ const answers: Array<string | null> = [];
+ const ask = (sessionId = 'task', prompt = '[sudo] password for someone:') => service.startTerminalPrompt({
+ sessionId, prompt, program: 'sudo', command: 'sudo -A true', answer: (value) => answers.push(value),
+ });
+ return { service, snapshots, continued, answers, ask, latest: () => snapshots[snapshots.length - 1] };
+}
+
+describe('terminal prompt handoff', () => {
+ it('gives the typed answer to the program only, and the agent gets no message', async () => {
+ const h = harness();
+ const started = h.ask();
+ expect(started.ok).toBe(true);
+ await vi.waitFor(() => expect(h.latest()?.phase).toBe('ready'));
+ expect(h.latest()).toMatchObject({ command: 'sudo -A true', source: { app: 'sudo' } });
+
+ const ok = await h.service.submit(h.latest().requestId, {
+ expectedRevision: h.latest().revision,
+ values: { answer: 'synthetic-pass' },
+ action: { kind: 'submit' },
+ }, { deviceId: 'phone-1' });
+ expect(ok).toBe(true);
+ expect(h.answers).toEqual(['synthetic-pass']);
+ expect(h.latest().phase).toBe('succeeded');
+ expect(JSON.stringify(h.snapshots)).not.toContain('synthetic-pass');
+ await new Promise((resolve) => setTimeout(resolve, 5));
+ expect(h.continued).toEqual([]);
+ });
+
+ it('fails the program when the owner cancels', async () => {
+ const h = harness();
+ h.ask();
+ await vi.waitFor(() => expect(h.latest()?.phase).toBe('ready'));
+ h.service.resolve(h.latest().requestId, { kind: 'input_handoff', action: 'cancel', expectedRevision: h.latest().revision });
+ await vi.waitFor(() => expect(h.answers).toEqual([null]));
+ });
+
+ it('ends quietly when the program stops waiting', async () => {
+ const h = harness();
+ const started = h.ask();
+ await vi.waitFor(() => expect(h.latest()?.phase).toBe('ready'));
+ if (started.ok) started.abandon?.();
+ expect(h.latest()).toMatchObject({ phase: 'failed', failure: 'target_gone', terminal: true });
+ expect(h.answers).toEqual([]);
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/askpass/__tests__/askpass.native.test.ts b/apps/desktop/src/main/input-handoff/askpass/__tests__/askpass.native.test.ts
new file mode 100644
index 0000000000..06b819a282
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/askpass/__tests__/askpass.native.test.ts
@@ -0,0 +1,97 @@
+import { execFile } from 'node:child_process';
+import http from 'node:http';
+import type { AddressInfo } from 'node:net';
+import { afterEach, describe, expect, it } from 'vitest';
+import type { TerminalPromptRequest } from '../../service.js';
+import { AskpassHost, INPUT_HANDOFF_ROUTE_ENV } from '../host.js';
+
+/**
+ * Real processes, no real secrets: git asks a throwaway local server for Basic
+ * auth through its HTTPS transport, exactly as it would for a private remote.
+ * System and global git config are off, so no credential helper stores anything.
+ */
+const runnable = process.platform === 'darwin' || process.platform === 'linux';
+
+const hosts: AskpassHost[] = [];
+const servers: http.Server[] = [];
+afterEach(async () => {
+ await Promise.all(hosts.splice(0).map((h) => h.close()));
+ servers.splice(0).forEach((s) => s.close());
+});
+
+function run(file: string, args: string[], env: NodeJS.ProcessEnv): Promise<{ code: number; stdout: string }> {
+ return new Promise((resolve) => {
+ execFile(file, args, { env, timeout: 30_000 }, (error, stdout) => {
+ resolve({ code: error ? Number((error as { code?: number }).code ?? 1) : 0, stdout: String(stdout) });
+ });
+ });
+}
+
+async function setup(answers: Record<string, string>) {
+ const prompts: TerminalPromptRequest[] = [];
+ const host = new AskpassHost({
+ isDisabledForSession: async () => false,
+ baseEnv: {},
+ startTerminalPrompt: (request) => {
+ prompts.push(request);
+ const key = Object.keys(answers).find((k) => request.prompt.startsWith(k));
+ setTimeout(() => request.answer(key ? answers[key] : null), 10);
+ return { ok: true };
+ },
+ });
+ hosts.push(host);
+ await host.prepare();
+ const env = { ...host.envFor('task-1') };
+ return { host, prompts, env };
+}
+
+describe.runIf(runnable)('代输入 askpass with real programs', () => {
+ it('answers git over HTTP and the value reaches only git', async () => {
+ const seen: string[] = [];
+ const server = http.createServer((req, res) => {
+ seen.push(req.headers.authorization ?? '');
+ if (req.headers.authorization) res.writeHead(404).end();
+ else res.writeHead(401, { 'www-authenticate': 'Basic realm="test"' }).end();
+ });
+ servers.push(server);
+ await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve));
+ const { port } = server.address() as AddressInfo;
+ const { prompts, env } = await setup({ Username: 'someone', Password: 'synthetic-pass' });
+
+ const result = await run('git', ['-c', 'credential.helper=', 'ls-remote', `http://127.0.0.1:${port}/r.git`], {
+ PATH: process.env.PATH,
+ HOME: process.env.HOME,
+ GIT_CONFIG_NOSYSTEM: '1',
+ GIT_CONFIG_GLOBAL: '/dev/null',
+ GIT_TERMINAL_PROMPT: '0',
+ ...env,
+ });
+
+ expect(result.stdout).not.toContain('synthetic-pass');
+ expect(seen).toContain(`Basic ${Buffer.from('someone:synthetic-pass').toString('base64')}`);
+ expect(prompts.map((p) => p.program)).toEqual(['git', 'git']);
+ expect(prompts[0].command).toContain('ls-remote');
+ expect(prompts[0].sessionId).toBe('task-1');
+ });
+
+ it('refuses the helper when the agent calls it directly', async () => {
+ const { prompts, env, host } = await setup({ Password: 'synthetic-pass' });
+ const result = await run('/bin/sh', ['-c', '"$SUDO_ASKPASS" "Password:"'], { PATH: process.env.PATH, ...env });
+ expect(result.code).not.toBe(0);
+ expect(result.stdout).toBe('');
+ expect(prompts).toHaveLength(0);
+ expect(env[INPUT_HANDOFF_ROUTE_ENV]).toBeTruthy();
+ expect(host.helperPath).toBeTruthy();
+ });
+
+ it('refuses a route that was never given to a task', async () => {
+ const { prompts, env } = await setup({ Password: 'synthetic-pass' });
+ const result = await run('/bin/sh', ['-c', '"$SUDO_ASKPASS" "Password:"'], {
+ PATH: process.env.PATH,
+ ...env,
+ [INPUT_HANDOFF_ROUTE_ENV]: 'forged',
+ });
+ expect(result.stdout).toBe('');
+ expect(prompts).toHaveLength(0);
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/askpass/__tests__/processChain.test.ts b/apps/desktop/src/main/input-handoff/askpass/__tests__/processChain.test.ts
new file mode 100644
index 0000000000..7d4e85515a
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/askpass/__tests__/processChain.test.ts
@@ -0,0 +1,80 @@
+import { describe, expect, it } from 'vitest';
+import { verifyAskpassChain, type ProcessFacts, type ProcessProbe } from '../processChain.js';
+
+const USER = 501;
+const SOCK = '/tmp/cindy-ih-x/s';
+const curl = (ppid: number): ProcessFacts => ({
+ pid: 100, ppid, uid: USER, args: `/usr/bin/curl -sS --unix-socket ${SOCK} http://cindy/askpass`,
+});
+
+function probe(processes: Array<ProcessFacts & { exe?: string }>): ProcessProbe {
+ const byPid = new Map(processes.map((p) => [p.pid, p]));
+ return {
+ facts: async (pid) => {
+ const p = byPid.get(pid);
+ return p ? { pid: p.pid, ppid: p.ppid, uid: p.uid, args: p.args } : null;
+ },
+ executable: async (pid) => byPid.get(pid)?.exe ?? null,
+ };
+}
+
+const verify = (processes: Array<ProcessFacts & { exe?: string }>) =>
+ verifyAskpassChain(probe(processes), 100, SOCK, USER);
+
+describe('askpass asker check', () => {
+ it('accepts the real setuid sudo and shows its command', async () => {
+ const verdict = await verify([
+ { ...curl(200), exe: '/usr/bin/curl' },
+ { pid: 200, ppid: 1, uid: 0, args: 'sudo -A launchctl kickstart system/com.example' },
+ ]);
+ expect(verdict).toEqual({ ok: true, asker: { program: 'sudo', command: 'sudo -A launchctl kickstart system/com.example' } });
+ });
+
+ it('refuses a "sudo" that is not running as root', async () => {
+ const verdict = await verify([
+ { ...curl(200), exe: '/usr/bin/curl' },
+ { pid: 200, ppid: 1, uid: USER, args: 'sudo -A true', exe: '/Users/someone/bin/sudo' },
+ ]);
+ expect(verdict).toEqual({ ok: false, reason: 'sudo' });
+ });
+
+ it('accepts system ssh and refuses ssh built somewhere the agent can write', async () => {
+ const ssh = { pid: 200, ppid: 1, uid: USER, args: 'ssh [email protected]' };
+ expect(await verify([{ ...curl(200), exe: '/usr/bin/curl' }, { ...ssh, exe: '/usr/bin/ssh' }]))
+ .toMatchObject({ ok: true, asker: { program: 'ssh' } });
+ expect(await verify([{ ...curl(200), exe: '/usr/bin/curl' }, { ...ssh, exe: '/Users/someone/work/ssh' }]))
+ .toEqual({ ok: false, reason: 'parent' });
+ expect(await verify([{ ...curl(200), exe: '/usr/bin/curl' }, { ...ssh, exe: '/usr/bin/../../tmp/ssh' }]))
+ .toEqual({ ok: false, reason: 'parent' });
+ });
+
+ it('refuses `git credential fill`, which would print the password', async () => {
+ const verdict = await verify([
+ { ...curl(200), exe: '/usr/bin/curl' },
+ { pid: 200, ppid: 1, uid: USER, args: 'git credential fill', exe: '/Library/Developer/CommandLineTools/usr/bin/git' },
+ ]);
+ expect(verdict).toEqual({ ok: false, reason: 'parent' });
+ });
+
+ it('names the git command the agent ran for an HTTPS prompt', async () => {
+ const core = '/Library/Developer/CommandLineTools/usr/libexec/git-core';
+ const verdict = await verify([
+ { ...curl(300), exe: '/usr/bin/curl' },
+ { pid: 300, ppid: 250, uid: USER, args: `${core}/git-remote-https origin https://git.example/r.git`, exe: `${core}/git-remote-http` },
+ { pid: 250, ppid: 200, uid: USER, args: `${core}/git remote-https origin https://git.example/r.git` },
+ { pid: 200, ppid: 1, uid: USER, args: 'git push origin main' },
+ ]);
+ expect(verdict).toEqual({ ok: true, asker: { program: 'git', command: 'git push origin main' } });
+ });
+
+ it('refuses when the asking process is not the helper', async () => {
+ expect(await verify([
+ { pid: 100, ppid: 200, uid: USER, args: 'python3 fake.py', exe: '/usr/bin/python3' },
+ { pid: 200, ppid: 1, uid: 0, args: 'sudo -A true' },
+ ])).toEqual({ ok: false, reason: 'helper' });
+ expect(await verify([
+ { ...curl(200), exe: '/Users/someone/bin/curl' },
+ { pid: 200, ppid: 1, uid: 0, args: 'sudo -A true' },
+ ])).toEqual({ ok: false, reason: 'helper' });
+ });
+});
diff --git a/apps/desktop/src/main/input-handoff/askpass/host.ts b/apps/desktop/src/main/input-handoff/askpass/host.ts
new file mode 100644
index 0000000000..57f32c910b
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/askpass/host.ts
@@ -0,0 +1,210 @@
+import { createHmac, randomBytes } from 'node:crypto';
+import { chmod, mkdtemp, rm, stat, writeFile } from 'node:fs/promises';
+import http from 'node:http';
+import os from 'node:os';
+import path from 'node:path';
+import type { TerminalPromptRequest } from '../service.js';
+import { createSystemProcessProbe, verifyAskpassChain, type ProcessProbe } from './processChain.js';
+
+/**
+ * Terminal password prompts for 代输入. Each local task's shell gets
+ * `SUDO_ASKPASS` / `SSH_ASKPASS` / `GIT_ASKPASS` pointing at a tiny helper.
+ * When `sudo -A`, `ssh` or git over HTTPS needs a password, the helper asks
+ * Cindy over a private Unix socket; Cindy verifies the asking program, shows
+ * the owner a one-step card, and returns the answer to that program only.
+ *
+ * Nothing here logs prompts, commands or answers.
+ */
+
+export const INPUT_HANDOFF_ROUTE_ENV = 'CINDY_INPUT_HANDOFF_ROUTE';
+const ROUTE_HEADER = 'x-cindy-route';
+const PID_HEADER = 'x-cindy-pid';
+const PROMPT_MAX_BYTES = 4096;
+
+export interface AskpassHostDeps {
+ startTerminalPrompt(request: TerminalPromptRequest): { ok: true; abandon?(): void } | { ok: false };
+ /** Teammate owner switch, current policy. Resolves true when 代输入 is off for the task. */
+ isDisabledForSession(sessionId: string): Promise<boolean>;
+ probe?: ProcessProbe;
+ uid?: number;
+ tmpRoot?: string;
+ platform?: NodeJS.Platform;
+ /** Values already set by the user win; ours fill only what is absent. */
+ baseEnv?: NodeJS.ProcessEnv;
+ logger?: { warn(message: string, context?: Record<string, unknown>): void };
+}
+
+/** POSIX sh helper. It holds no secret; the route value comes from the task env. */
+export function askpassHelperScript(socketPath: string): string {
+ const quoted = `'${socketPath.replace(/'/g, `'\\''`)}'`;
+ return [
+ '#!/bin/sh',
+ '# Cindy input handoff: asks the owner for the password this program needs.',
+ `sock=${quoted}`,
+ `route="\${${INPUT_HANDOFF_ROUTE_ENV}:-}"`,
+ '[ -n "$route" ] && [ -S "$sock" ] || exit 1',
+ 'curl=/usr/bin/curl',
+ '[ -x "$curl" ] || exit 1',
+ // exec keeps this pid, so Cindy can check that the asker is this process's parent.
+ `exec "$curl" -sS -f --no-buffer --max-time 3700 --unix-socket "$sock" \\`,
+ ` -H "${ROUTE_HEADER}: $route" -H "${PID_HEADER}: $$" \\`,
+ ' --data-urlencode "prompt=$1" http://cindy/askpass',
+ '',
+ ].join('\n');
+}
+
+export class AskpassHost {
+ private dir: string | null = null;
+ private server: http.Server | null = null;
+ private preparing: Promise<void> | null = null;
+ private readonly key = randomBytes(32);
+ private readonly routes = new Map<string, string>();
+ private readonly probe: ProcessProbe;
+ private readonly uid: number;
+ private readonly platform: NodeJS.Platform;
+
+ constructor(private readonly deps: AskpassHostDeps) {
+ this.platform = deps.platform ?? process.platform;
+ this.probe = deps.probe ?? createSystemProcessProbe(this.platform);
+ this.uid = deps.uid ?? (process.getuid?.() ?? -1);
+ }
+
+ get supported(): boolean {
+ return (this.platform === 'darwin' || this.platform === 'linux') && this.uid >= 0;
+ }
+
+ get socketPath(): string | null {
+ return this.dir ? path.join(this.dir, 's') : null;
+ }
+
+ get helperPath(): string | null {
+ return this.dir ? path.join(this.dir, 'askpass') : null;
+ }
+
+ /** Creates the private directory, helper and socket once; recreates them if the OS cleaned tmp. */
+ prepare(): Promise<void> {
+ if (!this.supported) return Promise.resolve();
+ this.preparing ??= this.doPrepare().finally(() => { this.preparing = null; });
+ return this.preparing;
+ }
+
+ /**
+ * Variables for the commands of one local task. Deterministic for a task in
+ * this app run, so a respawned agent process gets byte-identical env.
+ */
+ envFor(sessionId: string): Record<string, string> {
+ const helper = this.helperPath;
+ if (!this.supported || !helper || !sessionId) return {};
+ void this.prepare();
+ const route = createHmac('sha256', this.key).update(sessionId).digest('base64url').slice(0, 32);
+ this.routes.set(route, sessionId);
+ const base = this.deps.baseEnv ?? process.env;
+ const wanted: Record<string, string> = {
+ [INPUT_HANDOFF_ROUTE_ENV]: route,
+ SUDO_ASKPASS: helper,
+ SSH_ASKPASS: helper,
+ SSH_ASKPASS_REQUIRE: 'force',
+ GIT_ASKPASS: helper,
+ };
+ const out: Record<string, string> = {};
+ for (const [name, value] of Object.entries(wanted)) {
+ if (name === INPUT_HANDOFF_ROUTE_ENV || !base[name]) out[name] = value;
+ }
+ // Without our askpass, forcing it would break the user's own setup.
+ if (!out.SSH_ASKPASS) delete out.SSH_ASKPASS_REQUIRE;
+ return out;
+ }
+
+ async close(): Promise<void> {
+ const server = this.server;
+ this.server = null;
+ if (server) await new Promise<void>((resolve) => server.close(() => resolve()));
+ if (this.dir) await rm(this.dir, { recursive: true, force: true }).catch(() => undefined);
+ this.dir = null;
+ }
+
+ private async doPrepare(): Promise<void> {
+ if (this.dir && this.server?.listening) {
+ const alive = await stat(this.socketPath!).then((s) => s.isSocket(), () => false)
+ && await stat(this.helperPath!).then((s) => s.isFile(), () => false);
+ if (alive) return;
+ await this.close();
+ }
+ const dir = await mkdtemp(path.join(this.deps.tmpRoot ?? os.tmpdir(), 'cindy-ih-'));
+ await chmod(dir, 0o700);
+ const socket = path.join(dir, 's');
+ await writeFile(path.join(dir, 'askpass'), askpassHelperScript(socket), { mode: 0o700 });
+ const server = http.createServer((req, res) => void this.handle(req, res));
+ // Owners may take minutes to answer; the helper bounds its own wait.
+ server.requestTimeout = 0;
+ server.headersTimeout = 10_000;
+ server.timeout = 0;
+ await new Promise<void>((resolve, reject) => {
+ server.once('error', reject);
+ server.listen(socket, () => {
+ server.off('error', reject);
+ resolve();
+ });
+ });
+ await chmod(socket, 0o600).catch(() => undefined);
+ this.dir = dir;
+ this.server = server;
+ }
+
+ private async handle(req: http.IncomingMessage, res: http.ServerResponse): Promise<void> {
+ const refuse = (reason: string) => {
+ if (reason) this.deps.logger?.warn('input handoff askpass refused', { reason });
+ if (!res.headersSent) res.writeHead(403, { 'content-type': 'text/plain' });
+ res.end();
+ };
+ if (req.method !== 'POST' || req.url !== '/askpass') return refuse('request');
+ const sessionId = this.routes.get(String(req.headers[ROUTE_HEADER] ?? ''));
+ const pid = Number(req.headers[PID_HEADER]);
+ const prompt = await readPrompt(req).catch(() => null);
+ if (!sessionId || !Number.isSafeInteger(pid) || prompt === null) return refuse('request');
+ const verdict = await verifyAskpassChain(this.probe, pid, this.socketPath ?? '\u0000', this.uid);
+ if (!verdict.ok) return refuse(verdict.reason);
+ if (await this.deps.isDisabledForSession(sessionId).catch(() => true)) return refuse('disabled');
+ // The body is consumed, so only the connection tells whether the asker is still waiting.
+ if (req.socket.destroyed) return;
+
+ let settled = false;
+ const started = this.deps.startTerminalPrompt({
+ sessionId,
+ prompt,
+ program: verdict.asker.program,
+ command: verdict.asker.command,
+ answer: (value) => {
+ if (settled) return;
+ settled = true;
+ if (value === null || res.destroyed) return refuse('');
+ const body = Buffer.from(`${value}\n`, 'utf8');
+ res.writeHead(200, { 'content-type': 'text/plain', 'content-length': body.length });
+ res.end(body, () => body.fill(0));
+ },
+ });
+ if (!started.ok) {
+ settled = true;
+ return refuse('');
+ }
+ res.on('close', () => {
+ if (!settled) {
+ settled = true;
+ started.abandon?.();
+ }
+ });
+ }
+}
+
+async function readPrompt(req: http.IncomingMessage): Promise<string> {
+ const chunks: Buffer[] = [];
+ let size = 0;
+ for await (const chunk of req) {
+ size += (chunk as Buffer).length;
+ if (size > PROMPT_MAX_BYTES) throw new Error('too large');
+ chunks.push(chunk as Buffer);
+ }
+ const prompt = new URLSearchParams(Buffer.concat(chunks).toString('utf8')).get('prompt');
+ if (prompt === null) throw new Error('missing');
+ return prompt;
+}
diff --git a/apps/desktop/src/main/input-handoff/askpass/index.ts b/apps/desktop/src/main/input-handoff/askpass/index.ts
new file mode 100644
index 0000000000..e0e671f5a1
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/askpass/index.ts
@@ -0,0 +1,22 @@
+import { AskpassHost, type AskpassHostDeps } from './host.js';
+
+let host: AskpassHost | null = null;
+
+export function initInputHandoffAskpass(deps: AskpassHostDeps): AskpassHost {
+ host = new AskpassHost(deps);
+ void host.prepare().catch((error) => {
+ deps.logger?.warn('input handoff askpass unavailable', {
+ error: error instanceof Error ? error.message : String(error),
+ });
+ });
+ return host;
+}
+
+/** `AgentRuntimeConfig.taskShellEnv` for all three harnesses. Empty until ready or when unsupported. */
+export function inputHandoffTaskShellEnv(ctx: { sessionId: string }): Record<string, string> {
+ return host?.envFor(ctx.sessionId) ?? {};
+}
+
+export async function closeInputHandoffAskpass(): Promise<void> {
+ await host?.close();
+}
diff --git a/apps/desktop/src/main/input-handoff/askpass/processChain.ts b/apps/desktop/src/main/input-handoff/askpass/processChain.ts
new file mode 100644
index 0000000000..cdc4f6a511
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/askpass/processChain.ts
@@ -0,0 +1,166 @@
+import { execFile } from 'node:child_process';
+import { readlink } from 'node:fs/promises';
+import path from 'node:path';
+import { promisify } from 'node:util';
+import type { TerminalProgram } from '../terminalPrompt.js';
+
+const exec = promisify(execFile);
+
+/**
+ * Who is asking through Cindy's askpass helper. Only a real system `sudo`,
+ * `ssh` / `ssh-add` or git's HTTPS transport may receive the owner's answer:
+ * those read the helper's output themselves. A direct call by the agent, a
+ * script it wrote, or `git credential fill` (which prints the password) is
+ * refused, so the answer can never come back to the agent through stdout.
+ *
+ * Threat boundary (design 4.3): this stops accidental and prompt-induced
+ * leaks. It is not a sandbox against an agent that is itself malicious and
+ * replaces system tools under a package-manager prefix it can write to.
+ */
+
+export interface ProcessFacts {
+ pid: number;
+ ppid: number;
+ /** Effective uid. */
+ uid: number;
+ args: string;
+}
+
+export interface ProcessProbe {
+ facts(pid: number): Promise<ProcessFacts | null>;
+ /** Real executable path; null when it cannot be read (other users' processes). */
+ executable(pid: number): Promise<string | null>;
+}
+
+export interface VerifiedAsker {
+ program: TerminalProgram;
+ /** The command the owner should recognise, e.g. `sudo -A brew install x` or `git push origin main`. */
+ command: string;
+}
+
+export type ChainVerdict = { ok: true; asker: VerifiedAsker } | { ok: false; reason: string };
+
+/** Install roots that only an administrator or a package manager populates. */
+const SYSTEM_ROOTS: RegExp[] = [
+ /^\/usr\/bin\//,
+ /^\/bin\//,
+ /^\/usr\/libexec\//,
+ /^\/usr\/lib\/git-core\//,
+ /^\/usr\/local\//,
+ /^\/opt\/homebrew\//,
+ /^\/opt\/local\//,
+ /^\/Library\/Developer\/CommandLineTools\//,
+ /^\/Applications\/Xcode[^/]*\.app\/Contents\/Developer\//,
+ /^\/nix\/store\//,
+ /^\/run\/current-system\/sw\//,
+];
+
+const SSH_NAMES = new Set(['ssh', 'ssh-add']);
+const GIT_TRANSPORTS = new Set(['git-remote-http', 'git-remote-https']);
+const COMMAND_MAX = 1000;
+
+function isSystemPath(file: string): boolean {
+ const normal = path.posix.normalize(file);
+ return normal === file && SYSTEM_ROOTS.some((root) => root.test(normal));
+}
+
+function argv0Name(args: string): string {
+ return path.posix.basename(args.trim().split(/\s+/)[0] ?? '');
+}
+
+function shorten(command: string): string {
+ const clean = command.replace(/[\u0000-\u001f\u007f]/g, ' ').trim();
+ return clean.length > COMMAND_MAX ? `${clean.slice(0, COMMAND_MAX - 1)}…` : clean;
+}
+
+/**
+ * @param helperPid pid the helper reported for itself (the curl it exec'd into)
+ * @param expectHelperArg text that must appear in that process's arguments (the private socket path)
+ */
+export async function verifyAskpassChain(
+ probe: ProcessProbe,
+ helperPid: number,
+ expectHelperArg: string,
+ userUid: number,
+): Promise<ChainVerdict> {
+ const helper = await probe.facts(helperPid);
+ if (!helper || helper.uid !== userUid || !helper.args.includes(expectHelperArg) || argv0Name(helper.args) !== 'curl')
+ return { ok: false, reason: 'helper' };
+ const helperExe = await probe.executable(helperPid);
+ if (!helperExe || !isSystemPath(helperExe) || path.posix.basename(helperExe) !== 'curl')
+ return { ok: false, reason: 'helper' };
+
+ const parent = await probe.facts(helper.ppid);
+ if (!parent) return { ok: false, reason: 'parent' };
+ const name = argv0Name(parent.args);
+
+ // sudo is setuid root: an imitation cannot run with an effective uid of 0.
+ if (name === 'sudo') {
+ if (parent.uid !== 0) return { ok: false, reason: 'sudo' };
+ return { ok: true, asker: { program: 'sudo', command: shorten(parent.args) } };
+ }
+
+ if (parent.uid !== userUid) return { ok: false, reason: 'parent' };
+ const exe = await probe.executable(parent.pid);
+ if (!exe || !isSystemPath(exe)) return { ok: false, reason: 'parent' };
+ const exeName = path.posix.basename(exe);
+
+ if (SSH_NAMES.has(exeName)) {
+ return { ok: true, asker: { program: exeName as 'ssh' | 'ssh-add', command: shorten(parent.args) } };
+ }
+ // git prompts for HTTPS credentials from its transport helper only. `git`
+ // itself asking (e.g. `git credential fill`) would print the answer.
+ if (GIT_TRANSPORTS.has(exeName) || GIT_TRANSPORTS.has(name)) {
+ if (!GIT_TRANSPORTS.has(exeName)) return { ok: false, reason: 'git' };
+ return { ok: true, asker: { program: 'git', command: shorten(await gitCommand(probe, parent)) } };
+ }
+ return { ok: false, reason: 'parent' };
+}
+
+/** The git command the agent ran, skipping git's own `git remote-http` hop. */
+async function gitCommand(probe: ProcessProbe, transport: ProcessFacts): Promise<string> {
+ let command = transport.args;
+ let ppid = transport.ppid;
+ for (let depth = 0; depth < 3; depth++) {
+ const up = await probe.facts(ppid);
+ if (!up || argv0Name(up.args) !== 'git') break;
+ command = up.args;
+ if (!/^\S+\s+remote-https?\b/.test(up.args)) break;
+ ppid = up.ppid;
+ }
+ return command;
+}
+
+/** `ps` for process facts; `/proc` on Linux and `lsof` on macOS for the executable. */
+export function createSystemProcessProbe(platform: NodeJS.Platform = process.platform): ProcessProbe {
+ return {
+ async facts(pid) {
+ if (!Number.isSafeInteger(pid) || pid <= 1) return null;
+ try {
+ const { stdout } = await exec('/bin/ps', ['-ww', '-o', 'pid=,ppid=,uid=,args=', '-p', String(pid)], {
+ timeout: 3000,
+ maxBuffer: 256 * 1024,
+ });
+ const match = stdout.trim().match(/^(\d+)\s+(\d+)\s+(\d+)\s+(.*)$/s);
+ if (!match || Number(match[1]) !== pid) return null;
+ return { pid, ppid: Number(match[2]), uid: Number(match[3]), args: match[4] };
+ } catch {
+ return null;
+ }
+ },
+ async executable(pid) {
+ if (!Number.isSafeInteger(pid) || pid <= 1) return null;
+ if (platform === 'linux') return readlink(`/proc/${pid}/exe`).catch(() => null);
+ try {
+ const { stdout } = await exec('/usr/sbin/lsof', ['-n', '-P', '-a', '-p', String(pid), '-d', 'txt', '-Fn'], {
+ timeout: 3000,
+ maxBuffer: 256 * 1024,
+ });
+ const first = stdout.split('\n').find((line) => line.startsWith('n/'));
+ return first ? first.slice(1) : null;
+ } catch {
+ return null;
+ }
+ },
+ };
+}
diff --git a/apps/desktop/src/main/input-handoff/botPolicy.ts b/apps/desktop/src/main/input-handoff/botPolicy.ts
new file mode 100644
index 0000000000..89b35cd655
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/botPolicy.ts
@@ -0,0 +1,37 @@
+import { and, eq } from 'drizzle-orm';
+import { getDbClient } from '../localDb/client/current.js';
+import { botProfiles, botProfileVersions, botSessionLinks, sessions } from '../localDb/schema.js';
+
+/**
+ * Whether the owner turned 代输入 off for the teammate behind this task.
+ * Ordinary tasks are never affected. Reads the teammate's current profile
+ * (not the version a delegation was pinned to), so turning it off applies at
+ * once to every running task of that teammate.
+ */
+export async function isInputHandoffDisabledForSession(sessionId: string): Promise<boolean> {
+ const db = getDbClient().drizzle;
+ const [row] = await db
+ .select({ config: botProfileVersions.capabilitiesJson })
+ .from(botSessionLinks)
+ .innerJoin(sessions, eq(sessions.id, botSessionLinks.sessionId))
+ .innerJoin(botProfiles, eq(botProfiles.id, botSessionLinks.botId))
+ .innerJoin(
+ botProfileVersions,
+ and(eq(botProfileVersions.botId, botProfiles.id), eq(botProfileVersions.version, botProfiles.currentVersion)),
+ )
+ .where(and(eq(botSessionLinks.sessionId, sessionId), eq(sessions.source, 'bot')))
+ .limit(1);
+ if (!row) return false;
+ return readInputHandoffSetting(row.config) === false;
+}
+
+/** `inputHandoff` in a teammate's capabilities JSON; missing or unreadable means allowed. */
+export function readInputHandoffSetting(capabilitiesJson: string): boolean {
+ try {
+ const parsed = JSON.parse(capabilitiesJson) as unknown;
+ if (parsed && typeof parsed === 'object' && (parsed as { inputHandoff?: unknown }).inputHandoff === false) return false;
+ } catch {
+ /* unreadable profile: keep the default */
+ }
+ return true;
+}
diff --git a/apps/desktop/src/main/input-handoff/deviceCode.ts b/apps/desktop/src/main/input-handoff/deviceCode.ts
new file mode 100644
index 0000000000..2d60fd5e9e
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/deviceCode.ts
@@ -0,0 +1,74 @@
+import { isInputHandoffDeviceCode, type InputHandoffDeviceCode } from '@cindy/device-link';
+import type { NativeAxNode } from './types.js';
+import { classifyOrigin } from './originPolicy.js';
+
+/**
+ * Device-code sign-in (代输入): a screen that only shows a short code and a
+ * link to open elsewhere (“go to example.com/device and enter ABCD-1234”).
+ *
+ * Generic shape detection, no product knowledge: one code-shaped token and one
+ * https link on a screen with nothing to fill in. The owner opens the link on
+ * their own device; nothing is typed into the target.
+ */
+
+/** Grouped codes (WDJB-MJHT, ABCD-1234) may sit inside a sentence. */
+const GROUPED = /(?<![A-Za-z0-9-])([A-Z0-9]{3,5}(?:-[A-Z0-9]{3,5}){1,3})(?![A-Za-z0-9-])/g;
+/** Ungrouped codes (F3QWE9R2L) only when they are a whole text of their own. */
+const WHOLE = /^[A-Z0-9]{6,10}$/;
+const URL_IN_TEXT = /\b(?:https:\/\/)?(?:[a-z0-9-]+\.)+[a-z]{2,}\/[^\s"'<>)]*/gi;
+
+const mixed = (code: string) => /[A-Z]/.test(code) && /[0-9]/.test(code);
+/**
+ * Grouped codes may be all letters (WDJB-MJHT); all-digit groups are left out
+ * because phone numbers look the same, and plain hyphenated words are lowercase.
+ */
+const groupedCode = (code: string) => code.replace(/-/g, '').length >= 6 && /[A-Z]/.test(code);
+
+function codesIn(text: string, whole: boolean): string[] {
+ const found = [...text.matchAll(GROUPED)].map((match) => match[1]).filter(groupedCode);
+ const trimmed = text.trim();
+ if (whole && WHOLE.test(trimmed) && mixed(trimmed)) found.push(trimmed);
+ return found;
+}
+
+function httpsLink(raw: string): { url: string; origin: string } | null {
+ const candidate = /^https?:\/\//i.test(raw) ? raw : `https://${raw}`;
+ let parsed: URL;
+ try {
+ parsed = new URL(candidate.replace(/[.,;:!?]+$/, ''));
+ } catch {
+ return null;
+ }
+ if (parsed.protocol !== 'https:' || parsed.username || parsed.password) return null;
+ // Only a plain public https origin: no IP, local host, or look-alike (punycode) domain.
+ const { origin, warning } = classifyOrigin(parsed.href, true);
+ if (!origin || warning) return null;
+ return { url: parsed.href, origin };
+}
+
+export function findDeviceCode(nodes: NativeAxNode[], hasInputs: boolean): InputHandoffDeviceCode | null {
+ if (hasInputs) return null;
+ const codes = new Set<string>();
+ const links = new Map<string, { url: string; origin: string }>();
+ for (const node of nodes) {
+ if (node.role === 'AXLink' && node.url) {
+ const link = httpsLink(node.url);
+ if (link) links.set(link.url, link);
+ }
+ if (node.role !== 'AXStaticText' && node.role !== 'AXHeading' && node.role !== 'AXLink') continue;
+ for (const text of [node.value, node.title, node.desc]) {
+ if (!text) continue;
+ for (const code of codesIn(text, node.role !== 'AXLink')) codes.add(code);
+ for (const match of text.matchAll(URL_IN_TEXT)) {
+ const link = httpsLink(match[0]);
+ if (link) links.set(link.url, link);
+ }
+ }
+ }
+ // Exactly one of each: anything ambiguous stays an ordinary step.
+ if (codes.size !== 1 || links.size !== 1) return null;
+ const [code] = codes;
+ const [link] = links.values();
+ const result = { code, ...link };
+ return isInputHandoffDeviceCode(result) ? result : null;
+}
diff --git a/apps/desktop/src/main/input-handoff/macDriver.ts b/apps/desktop/src/main/input-handoff/macDriver.ts
new file mode 100644
index 0000000000..3b73fd7ebc
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/macDriver.ts
@@ -0,0 +1,255 @@
+import { execFile, spawn } from 'node:child_process';
+import { promisify } from 'node:util';
+import {
+ readDesktopInputPermission,
+ resolveDesktopInputBinary,
+} from '../remote-desktop/inputHost.js';
+import type {
+ FoundQr,
+ NativeActRequest,
+ NativeActResult,
+ NativeAxSnapshot,
+ NativeWindowList,
+ NativeWindowRef,
+ PointerRequest,
+ WindowCapture,
+ WindowCaptureError,
+} from './types.js';
+import { captureWindowArea, captureWindowQr, type DetectedQr } from './windowCapture.js';
+
+const exec = promisify(execFile);
+
+/** Operating-system surface used by a handoff session; faked in tests. */
+export interface HandoffDriver {
+ permission(): Promise<'granted' | 'missing' | 'unknown'>;
+ requestPermission(): Promise<void>;
+ windows(): Promise<NativeWindowList>;
+ snapshot(pid: number, window?: NativeWindowRef): Promise<NativeAxSnapshot | { error: string }>;
+ act(request: NativeActRequest): Promise<NativeActResult>;
+ /** Command line of a process, for agent-controlled target detection only. */
+ commandLine(pid: number): Promise<string>;
+ /** Screenshot steps. Absent where the platform cannot photograph a single window. */
+ capture?(target: { pid: number; window: NativeWindowRef }): Promise<WindowCapture | { error: WindowCaptureError }>;
+ focusedField?(pid: number): Promise<{ editable: boolean; secure: boolean }>;
+ pointer?(request: PointerRequest): Promise<NativeActResult>;
+ /**
+ * Scan-to-sign-in: the QR code in the window, cut out of it, or null when it
+ * shows none. With `frame` the window is photographed where it is, without
+ * bringing it forward (watching a code already shown); otherwise it is raised first.
+ */
+ qr?(target: { pid: number; window: NativeWindowRef }, frame: number[] | null): Promise<FoundQr | null | { error: WindowCaptureError }>;
+ /** Bring the window to the front; its frame and window-server id, for a live view of just that window. */
+ raise?(target: { pid: number; window: NativeWindowRef }): Promise<{ frame: number[]; windowId: number } | { error: WindowCaptureError }>;
+}
+
+/**
+ * Runs the authenticated native helper once per request. Requests travel on
+ * stdin so owner values never appear in argv, environment or logs; replies
+ * never contain them.
+ */
+async function runHelper(request: Record<string, unknown>, timeoutMs: number): Promise<unknown> {
+ const binary = await resolveDesktopInputBinary();
+ return new Promise((resolve, reject) => {
+ // All three descriptors must be pipes: the helper authenticates its caller on each of them.
+ const child = spawn(binary, ['--handoff'], { stdio: 'pipe' });
+ child.stderr.resume();
+ let output = '';
+ let settled = false;
+ const timer = setTimeout(() => {
+ child.kill('SIGKILL');
+ if (!settled) {
+ settled = true;
+ reject(new Error('INPUT_HANDOFF_HELPER_TIMEOUT'));
+ }
+ }, timeoutMs);
+ child.stdout.setEncoding('utf8');
+ child.stdout.on('data', (chunk: string) => {
+ output += chunk;
+ if (output.length > 8_000_000) child.kill('SIGKILL');
+ });
+ child.on('error', (error) => {
+ clearTimeout(timer);
+ if (!settled) {
+ settled = true;
+ reject(error);
+ }
+ });
+ child.on('close', (code) => {
+ clearTimeout(timer);
+ child.stdin.destroy();
+ if (settled) return;
+ settled = true;
+ const line = output.trim();
+ if (line === 'permission') return resolve({ error: 'permission' });
+ if (code === 77) return resolve({ error: 'unavailable' });
+ try {
+ resolve(JSON.parse(line));
+ } catch {
+ resolve({ error: code === 0 ? 'invalid' : 'unavailable' });
+ }
+ });
+ // Stdin stays open until the helper exits: it checks who launched it on each descriptor,
+ // and a closed one fails that check. The request ends at its newline.
+ child.stdin.on('error', () => undefined);
+ child.stdin.write(`${JSON.stringify(request)}\n`);
+ });
+}
+
+/**
+ * QR codes in one photographed window; null when the helper could not look (not "no code").
+ * The picture travels on a pipe only; the reply carries no pixels.
+ */
+async function detectQr(jpeg: Buffer): Promise<DetectedQr[] | null> {
+ const binary = await resolveDesktopInputBinary();
+ const reply = await new Promise<string>((resolve, reject) => {
+ const child = spawn(binary, ['--handoff-qr'], { stdio: 'pipe' });
+ child.stderr.resume();
+ let output = '';
+ const timer = setTimeout(() => child.kill('SIGKILL'), 8000);
+ child.stdout.setEncoding('utf8');
+ child.stdout.on('data', (chunk: string) => {
+ output += chunk;
+ if (output.length > 64_000) child.kill('SIGKILL');
+ });
+ child.on('error', (error) => {
+ clearTimeout(timer);
+ reject(error);
+ });
+ child.on('close', () => {
+ clearTimeout(timer);
+ child.stdin.destroy();
+ resolve(output.trim());
+ });
+ // Its length first, then the picture; stdin stays open (see runHelper).
+ child.stdin.on('error', () => undefined);
+ child.stdin.write(`${jpeg.length}\n`);
+ child.stdin.write(jpeg);
+ });
+ let parsed: { codes?: unknown };
+ try {
+ parsed = JSON.parse(reply) as { codes?: unknown };
+ } catch {
+ return null;
+ }
+ if (!Array.isArray(parsed.codes)) return null;
+ const codes: DetectedQr[] = [];
+ for (const code of parsed.codes) {
+ const entry = code as Partial<DetectedQr>;
+ // Vision may place a code touching the edge slightly outside the picture.
+ if (typeof entry?.text !== 'string' || !Array.isArray(entry.box) || entry.box.length !== 4 ||
+ !entry.box.every((n) => typeof n === 'number' && Number.isFinite(n) && n >= -0.05 && n <= 1.05)) continue;
+ codes.push({ text: entry.text, box: entry.box.map((n) => Math.min(1, Math.max(0, n))) });
+ }
+ return codes;
+}
+
+/**
+ * Whether typing into this app would land in a password field: the element at
+ * a screen point, or the focused element. Used to point the agent at 代输入
+ * instead of typing a secret. Unknown (no permission, helper failure) is false.
+ */
+export async function isSecureInputTarget(target: { pid: number; point?: { x: number; y: number } }): Promise<boolean> {
+ if (process.platform !== 'darwin' || !Number.isSafeInteger(target.pid) || target.pid <= 0) return false;
+ const point = target.point && Number.isFinite(target.point.x) && Number.isFinite(target.point.y)
+ ? [target.point.x, target.point.y] : undefined;
+ try {
+ const result = (await runHelper({ op: 'secure', pid: target.pid, ...(point ? { point } : {}) }, 3000)) as { secure?: unknown };
+ return result?.secure === true;
+ } catch {
+ return false;
+ }
+}
+
+function captureError(error: unknown): WindowCaptureError {
+ return error === 'target_gone' || error === 'permission' || error === 'locked' ? error : 'unavailable';
+}
+
+/** The window-server id of the window at this frame, left where it is (watching a code already shown). */
+async function windowIdAt(pid: number, frame: number[]): Promise<number | { error: WindowCaptureError }> {
+ const found = (await runHelper({ op: 'windowid', pid, frame }, 3000)) as { windowId?: unknown; error?: string };
+ const id = found.windowId;
+ return typeof id === 'number' && Number.isSafeInteger(id) && id > 0 && id <= 0xffff_ffff ? id : { error: captureError(found.error) };
+}
+
+async function raiseWindow(target: { pid: number; window: NativeWindowRef }): Promise<
+ { frame: number[]; windowId?: number } | { error: WindowCaptureError }
+> {
+ const raised = (await runHelper({ op: 'raise', pid: target.pid, window: target.window }, 6000)) as {
+ frame?: unknown;
+ windowId?: unknown;
+ error?: string;
+ };
+ const frame = raised.frame;
+ if (!Array.isArray(frame) || frame.length !== 4 || !frame.every((n) => typeof n === 'number' && Number.isFinite(n)))
+ return { error: captureError(raised.error) };
+ const windowId = raised.windowId;
+ return {
+ frame: frame as number[],
+ ...(typeof windowId === 'number' && Number.isSafeInteger(windowId) && windowId > 0 && windowId <= 0xffff_ffff ? { windowId } : {}),
+ };
+}
+
+export function createMacHandoffDriver(): HandoffDriver {
+ return {
+ async permission() {
+ const status = await readDesktopInputPermission();
+ return status === 'granted' ? 'granted' : status === 'missing' ? 'missing' : 'unknown';
+ },
+ async requestPermission() {
+ const binary = await resolveDesktopInputBinary();
+ await exec(binary, ['--request-permission'], { timeout: 5000, maxBuffer: 1024 }).catch(() => undefined);
+ },
+ async windows() {
+ const result = (await runHelper({ op: 'windows' }, 8000)) as NativeWindowList & { error?: string };
+ if (result.error || !Array.isArray(result.apps)) throw new Error(result.error ?? 'unavailable');
+ return result;
+ },
+ async snapshot(pid, window) {
+ const result = (await runHelper({ op: 'snapshot', pid, ...(window ? { window } : {}) }, 10_000)) as
+ | NativeAxSnapshot
+ | { error: string };
+ return result;
+ },
+ async act(request) {
+ return (await runHelper({ op: 'act', ...request }, 15_000)) as NativeActResult;
+ },
+ async capture(target) {
+ const raised = await raiseWindow(target);
+ if ('error' in raised) return raised;
+ // Only the window's own pixels: without its id there is no picture.
+ return raised.windowId ? captureWindowArea(raised.frame, raised.windowId) : { error: 'unavailable' };
+ },
+ async qr(target, frame) {
+ if (frame) {
+ const id = await windowIdAt(target.pid, frame);
+ return typeof id === 'number' ? captureWindowQr(frame, id, detectQr) : id;
+ }
+ const raised = await raiseWindow(target);
+ if ('error' in raised) return raised;
+ return raised.windowId ? captureWindowQr(raised.frame, raised.windowId, detectQr) : { error: 'unavailable' };
+ },
+ async raise(target) {
+ const raised = await raiseWindow(target);
+ if ('error' in raised) return raised;
+ return raised.windowId ? { frame: raised.frame, windowId: raised.windowId } : { error: 'unavailable' };
+ },
+ async focusedField(pid) {
+ const result = (await runHelper({ op: 'focused', pid }, 3000)) as { editable?: unknown; secure?: unknown };
+ return { editable: result.editable === true, secure: result.secure === true };
+ },
+ async pointer(request) {
+ return (await runHelper({ op: 'pointer', ...request }, 10_000)) as NativeActResult;
+ },
+ async commandLine(pid) {
+ try {
+ const { stdout } = await exec('/bin/ps', ['-o', 'args=', '-p', String(pid)], {
+ timeout: 3000,
+ maxBuffer: 64 * 1024,
+ });
+ return stdout.trim();
+ } catch {
+ return '';
+ }
+ },
+ };
+}
diff --git a/apps/desktop/src/main/input-handoff/originPolicy.ts b/apps/desktop/src/main/input-handoff/originPolicy.ts
new file mode 100644
index 0000000000..300057971b
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/originPolicy.ts
@@ -0,0 +1,53 @@
+import type { InputHandoffOriginWarning } from '@cindy/device-link';
+
+/** Browsers whose page origin is the meaningful identity of what the owner types into. */
+const BROWSER_BUNDLES = [
+ 'com.google.chrome',
+ 'com.apple.safari',
+ 'com.apple.safaritechnologypreview',
+ 'org.mozilla.firefox',
+ 'com.microsoft.edgemac',
+ 'com.brave.browser',
+ 'company.thebrowser.browser',
+ 'com.vivaldi.vivaldi',
+ 'com.operasoftware.opera',
+ 'org.chromium.chromium',
+ 'com.kagi.kagimacos',
+];
+
+export function isBrowserBundle(bundleId: string): boolean {
+ const id = bundleId.toLowerCase();
+ return BROWSER_BUNDLES.some((prefix) => id === prefix || id.startsWith(`${prefix}.`));
+}
+
+const IPV4 = /^\d{1,3}(\.\d{1,3}){3}$/;
+
+/**
+ * Display origin plus a phishing-relevant warning. Origin is shown verbatim so
+ * the owner sees where the value goes; warnings only add caution, never block.
+ */
+export function classifyOrigin(
+ rawUrl: string,
+ browser: boolean,
+): { origin?: string; warning?: InputHandoffOriginWarning } {
+ let url: URL;
+ try {
+ url = new URL(rawUrl);
+ } catch {
+ return {};
+ }
+ if (url.protocol === 'file:') return browser ? { origin: 'file://', warning: 'local-file' } : {};
+ if (url.protocol === 'data:' || url.protocol === 'blob:')
+ return browser ? { origin: url.protocol, warning: 'local-file' } : {};
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return {};
+ const host = url.hostname.toLowerCase();
+ const origin = `${url.protocol}//${url.host}`;
+ if (host === 'localhost' || host.endsWith('.localhost') || host.endsWith('.local') ||
+ host === '127.0.0.1' || host === '[::1]' || host === '::1')
+ return { origin, warning: 'local-host' };
+ if (IPV4.test(host) || host.startsWith('['))
+ return { origin, warning: 'ip-address' };
+ if (host.split('.').some((label) => label.startsWith('xn--'))) return { origin, warning: 'punycode' };
+ if (url.protocol === 'http:') return { origin, warning: 'insecure' };
+ return { origin };
+}
diff --git a/apps/desktop/src/main/input-handoff/qrCode.ts b/apps/desktop/src/main/input-handoff/qrCode.ts
new file mode 100644
index 0000000000..6159de637a
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/qrCode.ts
@@ -0,0 +1,11 @@
+import { inputHandoffQrContent, type InputHandoffQr } from '@cindy/device-link';
+
+/**
+ * What a QR code on the target says, as shown to the owner (scan-to-sign-in).
+ * A link opens on the owner's device the way a phone camera would open the
+ * scanned code: web links (http or https) and app links (`weixin://…`).
+ * Script, inline data and local files are shown as text only.
+ */
+export function qrContent(text: string): InputHandoffQr | null {
+ return inputHandoffQrContent(text);
+}
diff --git a/apps/desktop/src/main/input-handoff/secretTaint.ts b/apps/desktop/src/main/input-handoff/secretTaint.ts
new file mode 100644
index 0000000000..fa62e1a04f
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/secretTaint.ts
@@ -0,0 +1,53 @@
+/**
+ * Pages of an agent-driven browser where the owner just typed a secret through
+ * 代输入. Until that tab leaves the page, the agent's page-reading browser tools
+ * (script evaluation, network requests and bodies, console) are refused there:
+ * the submitted form, or a script, could otherwise hand the secret to the model.
+ *
+ * Kept in memory only; it holds page addresses, never values.
+ */
+
+const TAINT_TTL_MS = 15 * 60_000;
+const MAX_PAGES = 32;
+const tainted = new Map<string, number>();
+
+/** Same document for this purpose: scheme, host, port and path (query and fragment ignored). */
+function pageKey(url: string): string | null {
+ try {
+ const parsed = new URL(url);
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return null;
+ return `${parsed.origin}${parsed.pathname}`;
+ } catch {
+ return null;
+ }
+}
+
+function prune(now: number): void {
+ for (const [key, until] of tainted) if (until <= now) tainted.delete(key);
+}
+
+export function markSecretEntered(url: string | undefined, now = Date.now()): void {
+ const key = url ? pageKey(url) : null;
+ if (!key) return;
+ prune(now);
+ tainted.delete(key);
+ tainted.set(key, now + TAINT_TTL_MS);
+ while (tainted.size > MAX_PAGES) tainted.delete(tainted.keys().next().value as string);
+}
+
+export function hasSecretPages(now = Date.now()): boolean {
+ prune(now);
+ return tainted.size > 0;
+}
+
+export function isSecretPage(url: string | undefined, now = Date.now()): boolean {
+ const key = url ? pageKey(url) : null;
+ if (!key) return false;
+ prune(now);
+ return tainted.has(key);
+}
+
+/** Tests only. */
+export function clearSecretPages(): void {
+ tainted.clear();
+}
diff --git a/apps/desktop/src/main/input-handoff/service.ts b/apps/desktop/src/main/input-handoff/service.ts
new file mode 100644
index 0000000000..8f8a95caab
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/service.ts
@@ -0,0 +1,395 @@
+import { randomUUID } from 'node:crypto';
+import {
+ parseInputHandoffDecision,
+ parseInputHandoffSubmission,
+ type InputHandoffHolder,
+ type InputHandoffPicture,
+ type InputHandoffSnapshot,
+} from '@cindy/device-link';
+import { INPUT_HANDOFF_ENDED_PREFIX } from '@cindy/maker-shared/synthetic-trigger';
+import { MAKER_PUSH } from '../maker-ipc/channels.js';
+import {
+ InputHandoffSession,
+ type HandoffCompletionHints,
+ type HandoffEndReason,
+ type HandoffResult,
+ type HandoffTargetSpec,
+ type LiveHandoffWindow,
+} from './session.js';
+import type { HandoffDriver } from './macDriver.js';
+import { markSecretEntered } from './secretTaint.js';
+import { TerminalPromptSession, type TerminalProgram } from './terminalPrompt.js';
+
+/**
+ * Process-local registry of 代输入 requests. Owns card broadcast, owner
+ * decisions and the agent continuation. Every input path ends here:
+ * the trusted local Desktop channel, the signed remote v3 exchange, and
+ * value-less plain decisions (hand back / cancel / stay / refresh).
+ */
+
+export interface InputHandoffStartRequest {
+ sessionId: string;
+ purpose: string;
+ note?: string;
+ requester?: string;
+ target: HandoffTargetSpec;
+ completeWhen?: HandoffCompletionHints;
+ timeoutMinutes?: number;
+}
+
+export type InputHandoffStartError = 'HANDOFF_ACTIVE' | 'UNSUPPORTED' | 'RATE_LIMITED';
+
+/** A password prompt from a verified terminal program in the task's shell. */
+export interface TerminalPromptRequest {
+ sessionId: string;
+ prompt: string;
+ program: TerminalProgram;
+ command: string;
+ requester?: string;
+ /** Receives the owner's answer once; null when there is none. */
+ answer(value: string | null): void;
+}
+
+/** What the registry needs from a running handoff of either kind. */
+interface HandoffRun {
+ readonly requestId: string;
+ start(): Promise<void>;
+ submit: InputHandoffSession['submit'];
+ decide: InputHandoffSession['decide'];
+ cancel(reason?: HandoffEndReason): void;
+ isActionable(revision: number): boolean;
+ /** Live view of the window (screen steps only; terminal prompts have no window). */
+ liveWindow?(): Promise<LiveHandoffWindow | null>;
+ afterLiveView?(): Promise<void>;
+ /** Screenshot of the current step, when the step is answered on a picture. */
+ pictureFor?(revision: number): InputHandoffPicture | null;
+}
+
+export interface InputHandoffServiceDeps {
+ broadcast(channel: string, payload: unknown): void;
+ createDriver(): HandoffDriver | null;
+ hostPid: number;
+ remoteInputAvailable(): boolean;
+ /** Whether another device may open a live view of the window (remote desktop allowed here). */
+ liveViewAvailable?(): boolean;
+ /** Hidden continuation to the requesting agent; metadata only. */
+ continueAgent(sessionId: string, requestId: string, message: string): Promise<void>;
+ /** Owner attention outside the app (mobile push, Agent Island). Never includes values. */
+ notifyOwner?(sessionId: string, snapshot: InputHandoffSnapshot): void;
+ onClosed?(sessionId: string, requestId: string): void;
+ /** Display facts (name, platform) for a server-verified owner device id. */
+ describeDevice?(deviceId: string): Omit<InputHandoffHolder, 'local' | 'deviceId'>;
+ logger?: { info?(message: string, context?: Record<string, unknown>): void; warn(message: string, context?: Record<string, unknown>): void };
+ terminalRetentionMs?: number;
+ /** Test clock/sleep and countdown overrides passed through to each session. */
+ sessionTiming?: { now?(): number; sleep?(ms: number): Promise<void>; finishingDelayMs?: number };
+}
+
+interface Entry {
+ sessionId: string;
+ session: HandoffRun;
+ snapshot: InputHandoffSnapshot | null;
+ /** The card has been shown. Until the first screen is read there may be nothing for the owner at all. */
+ shown: boolean;
+ /**
+ * No continuation is sent: the task closed, or the agent is still inside the
+ * command that asked (terminal prompts) and simply sees it finish.
+ */
+ silent: boolean;
+ /** How it ended; kept for the short retention so a remote answer that finished it can report success. */
+ result?: HandoffResult;
+}
+
+type StartResult =
+ | { ok: true; requestId: string }
+ | { ok: false; errorCode: InputHandoffStartError; message: string };
+
+export const INPUT_HANDOFF_DEFAULT_TIMEOUT_MINUTES = 15;
+export const INPUT_HANDOFF_MAX_TIMEOUT_MINUTES = 60;
+/** Per-task limit so a looping agent cannot keep paging the owner. */
+export const INPUT_HANDOFF_MAX_PER_TASK = 6;
+export const INPUT_HANDOFF_RATE_WINDOW_MS = 60 * 60_000;
+
+function timeoutMs(minutes: number | undefined): number {
+ return Math.min(
+ INPUT_HANDOFF_MAX_TIMEOUT_MINUTES,
+ Math.max(1, Math.round(minutes ?? INPUT_HANDOFF_DEFAULT_TIMEOUT_MINUTES)),
+ ) * 60_000;
+}
+
+export function buildInputHandoffContinuation(result: HandoffResult): string {
+ const facts = [
+ `status=${result.status}`,
+ `ended_by=${result.reason}`,
+ `steps=${result.steps}`,
+ ...(result.failure ? [`failure=${result.failure}`] : []),
+ ...(result.finalApp ? [`app=${JSON.stringify(result.finalApp)}`] : []),
+ ...(result.finalWindow ? [`window=${JSON.stringify(result.finalWindow)}`] : []),
+ ...(result.finalOrigin ? [`origin=${result.finalOrigin}`] : []),
+ ...(result.answeredOn ? [`answered_on=${answeredOnFact(result.answeredOn)}`] : []),
+ ].join(' ');
+ const next = result.failure === 'nothing_to_fill'
+ ? 'The screen has no field for the owner to type into. Press its buttons or pick its options yourself; request input handoff again only when a field appears that needs the owner.'
+ : result.status === 'succeeded'
+ ? 'The owner\'s fields were typed in and confirmed. Check the current screen yourself and handle any buttons or options left; values they entered were not shared with you.'
+ : result.failure === 'permission'
+ ? 'Cindy lacks macOS Accessibility permission for input handoff. Ask the owner to allow it on this computer, or continue another way.'
+ : result.failure === 'screen_locked'
+ ? 'This computer\'s screen is locked (a display going to sleep locks it too), so nothing was read or typed. Ask the owner to wake and unlock it; request input handoff again only after they say it is unlocked.'
+ : 'The handoff did not complete. Do not retry it automatically; tell the owner what is still needed or continue another way.';
+ return `${INPUT_HANDOFF_ENDED_PREFIX} ${facts}. ${next}`;
+}
+
+function answeredOnFact(holder: InputHandoffHolder): string {
+ if (holder.local) return 'this_computer';
+ const name = holder.name?.replace(/[\u0000-\u001f"]/g, '').trim().slice(0, 60);
+ return name ? JSON.stringify(name) : holder.platform === 'mobile' ? 'phone' : 'another_device';
+}
+
+export class InputHandoffService {
+ private readonly entries = new Map<string, Entry>();
+ private readonly recentStarts = new Map<string, number[]>();
+
+ constructor(private readonly deps: InputHandoffServiceDeps) {}
+
+ start(request: InputHandoffStartRequest): StartResult {
+ const refused = this.admit(request.sessionId);
+ if (refused) return refused;
+ const driver = this.deps.createDriver();
+ if (!driver) return { ok: false, errorCode: 'UNSUPPORTED', message: 'Input handoff is only available on macOS for now.' };
+ return this.launch(request.sessionId, false, (requestId, entry) => new InputHandoffSession({
+ requestId,
+ purpose: request.purpose,
+ ...(request.note ? { note: request.note } : {}),
+ ...(request.requester ? { requester: request.requester } : {}),
+ target: request.target,
+ ...(request.completeWhen ? { completeWhen: request.completeWhen } : {}),
+ timeoutMs: timeoutMs(request.timeoutMinutes),
+ hostPid: this.deps.hostPid,
+ remoteInput: this.deps.remoteInputAvailable(),
+ ...(this.deps.liveViewAvailable ? { liveView: this.deps.liveViewAvailable } : {}),
+ driver,
+ publish: (snapshot) => this.publish(entry, snapshot),
+ finish: (result) => this.finish(entry, result),
+ onSecretEntered: ({ url }) => markSecretEntered(url),
+ ...this.deps.sessionTiming,
+ }));
+ }
+
+ /**
+ * A terminal program in the task asked for a password. The agent did not
+ * call anything and gets no continuation: its command just proceeds once the
+ * program has the answer (or fails without one).
+ */
+ startTerminalPrompt(request: TerminalPromptRequest): StartResult & { abandon?(): void } {
+ const refused = this.admit(request.sessionId);
+ if (refused) return refused;
+ let run: TerminalPromptSession | undefined;
+ const started = this.launch(request.sessionId, true, (requestId, entry) => {
+ run = new TerminalPromptSession({
+ requestId,
+ prompt: request.prompt,
+ program: request.program,
+ command: request.command,
+ ...(request.requester ? { requester: request.requester } : {}),
+ timeoutMs: timeoutMs(undefined),
+ remoteInput: this.deps.remoteInputAvailable(),
+ answer: request.answer,
+ publish: (snapshot) => this.publish(entry, snapshot),
+ finish: (result) => this.finish(entry, result),
+ });
+ return run;
+ });
+ return started.ok ? { ...started, abandon: () => run?.abandon() } : started;
+ }
+
+ private admit(sessionId: string): Extract<StartResult, { ok: false }> | null {
+ const now = this.now();
+ const recent = (this.recentStarts.get(sessionId) ?? []).filter((at) => now - at < INPUT_HANDOFF_RATE_WINDOW_MS);
+ this.recentStarts.set(sessionId, recent);
+ if (recent.length >= INPUT_HANDOFF_MAX_PER_TASK)
+ return { ok: false, errorCode: 'RATE_LIMITED', message: 'Too many input handoffs in this task recently. Tell the owner what is blocked instead of asking again.' };
+ for (const entry of this.entries.values()) {
+ if (entry.sessionId === sessionId && !entry.snapshot?.terminal)
+ return { ok: false, errorCode: 'HANDOFF_ACTIVE', message: 'An input handoff is already waiting for the owner in this task.' };
+ }
+ return null;
+ }
+
+ private launch(sessionId: string, silent: boolean, create: (requestId: string, entry: Entry) => HandoffRun): StartResult {
+ this.recentStarts.get(sessionId)?.push(this.now());
+ const requestId = randomUUID();
+ const entry: Entry = { sessionId, session: null as unknown as HandoffRun, snapshot: null, shown: false, silent };
+ entry.session = create(requestId, entry);
+ this.entries.set(requestId, entry);
+ this.deps.logger?.info?.('input handoff started', { sessionId, requestId, ...(silent ? { kind: 'terminal' } : {}) });
+ void entry.session.start();
+ return { ok: true, requestId };
+ }
+
+ private now(): number {
+ return (this.deps.sessionTiming?.now ?? Date.now)();
+ }
+
+ /** Snapshot for the given request if it is still awaiting this exact revision. */
+ actionable(requestId: string, revision: number): InputHandoffSnapshot | null {
+ const entry = this.entries.get(requestId);
+ if (!entry?.snapshot || !entry.session.isActionable(revision)) return null;
+ // A quiet claim may have moved the revision on; the answer stays bound to the one it was typed against.
+ return entry.snapshot.revision === revision ? entry.snapshot : { ...entry.snapshot, revision };
+ }
+
+ /**
+ * The current step's screenshot. Callers: the executing Desktop's trusted
+ * Renderer and the sealed v3 offer only; never a snapshot, push or log.
+ */
+ picture(requestId: string, revision: number): InputHandoffPicture | null {
+ return this.entries.get(requestId)?.session.pictureFor?.(revision) ?? null;
+ }
+
+ /**
+ * The window a live view should show, raised. Caller: the remote desktop host
+ * only, after its own same-account authorization; never a viewer-named window.
+ */
+ async liveWindow(requestId: string): Promise<LiveHandoffWindow | null> {
+ const entry = this.entries.get(requestId);
+ if (!entry?.snapshot?.liveView || entry.snapshot.terminal) return null;
+ return (await entry.session.liveWindow?.()) ?? null;
+ }
+
+ /** The live view closed; the card catches up with the window. */
+ liveViewEnded(requestId: string): void {
+ void this.entries.get(requestId)?.session.afterLiveView?.().catch(() => undefined);
+ }
+
+ isCurrent(requestId: string): boolean {
+ const entry = this.entries.get(requestId);
+ return !!entry?.snapshot && !entry.snapshot.terminal;
+ }
+
+ /** The handoff ended because it was done (not cancelled, timed out or failed). */
+ succeeded(requestId: string): boolean {
+ return this.entries.get(requestId)?.result?.status === 'succeeded';
+ }
+
+ /** Values path. Callers: trusted Desktop IPC and the signed v3 exchange only. */
+ async submit(requestId: string, raw: unknown, actor: InputHandoffHolder = { local: true }): Promise<boolean> {
+ const entry = this.entries.get(requestId);
+ if (!entry) return false;
+ let submission;
+ try {
+ submission = parseInputHandoffSubmission(raw);
+ } catch {
+ return false;
+ }
+ return entry.session.submit(submission, this.describe(actor));
+ }
+
+ /** Value-less decisions; safe for the plain remote interaction channel. */
+ resolve(requestId: string, raw: unknown, actor: InputHandoffHolder = { local: true }): boolean {
+ const entry = this.entries.get(requestId);
+ const decision = parseInputHandoffDecision(raw);
+ if (!entry || !decision) return false;
+ void entry.session.decide(decision, this.describe(actor)).catch((error) => {
+ this.deps.logger?.warn('input handoff decision failed', {
+ requestId,
+ error: error instanceof Error ? error.message : String(error),
+ });
+ });
+ return true;
+ }
+
+ pendingSnapshots(sessionId?: string): Array<{ sessionId: string; request: InputHandoffSnapshot }> {
+ return [...this.entries.values()]
+ .filter((entry) => entry.shown && entry.snapshot && !entry.snapshot.terminal
+ && (sessionId === undefined || entry.sessionId === sessionId))
+ .map((entry) => ({ sessionId: entry.sessionId, request: entry.snapshot! }));
+ }
+
+ hasPending(sessionId: string): boolean {
+ return this.pendingSnapshots(sessionId).length > 0;
+ }
+
+ cleanupForSession(sessionId: string): void {
+ for (const entry of this.entries.values()) {
+ if (entry.sessionId !== sessionId || entry.snapshot?.terminal) continue;
+ entry.silent = true;
+ entry.session.cancel('session_closed');
+ }
+ }
+
+ cleanupAll(): void {
+ for (const entry of this.entries.values()) {
+ if (entry.snapshot?.terminal) continue;
+ entry.silent = true;
+ entry.session.cancel('session_closed');
+ }
+ }
+
+ private describe(actor: InputHandoffHolder): InputHandoffHolder {
+ if (actor.local || !actor.deviceId) return actor;
+ try {
+ return { ...this.deps.describeDevice?.(actor.deviceId), deviceId: actor.deviceId };
+ } catch {
+ return actor;
+ }
+ }
+
+ private publish(entry: Entry, snapshot: InputHandoffSnapshot): void {
+ entry.snapshot = snapshot;
+ // Nothing reaches the owner before the first screen is read: a screen with nothing
+ // to type ends unseen, leaving only the record line in the task.
+ if (!entry.shown && (snapshot.phase === 'reading' || snapshot.terminal)) return;
+ entry.shown = true;
+ try {
+ this.deps.broadcast(MAKER_PUSH.INTERACTION_REQUEST, { sessionId: entry.sessionId, request: snapshot });
+ } catch (error) {
+ this.deps.logger?.warn('input handoff broadcast failed', {
+ requestId: snapshot.requestId,
+ error: error instanceof Error ? error.message : String(error),
+ });
+ }
+ if (snapshot.phase === 'ready' && !snapshot.terminal) this.deps.notifyOwner?.(entry.sessionId, snapshot);
+ }
+
+ private finish(entry: Entry, result: HandoffResult): void {
+ const requestId = entry.session.requestId;
+ entry.result = result;
+ this.deps.logger?.info?.('input handoff ended', {
+ sessionId: entry.sessionId,
+ requestId,
+ status: result.status,
+ reason: result.reason,
+ steps: result.steps,
+ ...(result.failure ? { failure: result.failure } : {}),
+ });
+ const retention = setTimeout(() => {
+ this.entries.delete(requestId);
+ try {
+ this.deps.broadcast(MAKER_PUSH.INTERACTION_DISMISSED, {
+ sessionId: entry.sessionId,
+ requestId,
+ reason: result.status,
+ });
+ } catch { /* window gone */ }
+ this.deps.onClosed?.(entry.sessionId, requestId);
+ }, this.deps.terminalRetentionMs ?? 4000);
+ retention.unref?.();
+ if (entry.silent) return;
+ void this.deps.continueAgent(entry.sessionId, requestId, buildInputHandoffContinuation(result)).catch((error) => {
+ this.deps.logger?.warn('input handoff continuation failed', {
+ requestId,
+ error: error instanceof Error ? error.message : String(error),
+ });
+ });
+ }
+}
+
+let singleton: InputHandoffService | null = null;
+export function initInputHandoffService(deps: InputHandoffServiceDeps): InputHandoffService {
+ singleton = new InputHandoffService(deps);
+ return singleton;
+}
+export function getInputHandoffService(): InputHandoffService | null {
+ return singleton;
+}
diff --git a/apps/desktop/src/main/input-handoff/session.ts b/apps/desktop/src/main/input-handoff/session.ts
new file mode 100644
index 0000000000..4173e3f6df
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/session.ts
@@ -0,0 +1,1082 @@
+import {
+ INPUT_HANDOFF_PICTURE_TEXT_ID,
+ validateInputHandoffSubmissionForStep,
+ type InputHandoffControl,
+ type InputHandoffDecision,
+ type InputHandoffFailure,
+ type InputHandoffHolder,
+ type InputHandoffPhase,
+ type InputHandoffPicture,
+ type InputHandoffQr,
+ type InputHandoffSnapshot,
+ type InputHandoffSource,
+ type InputHandoffSubmission,
+} from '@cindy/device-link';
+import { HumanDesktopInput } from '../remote-desktop/inputOwnership.js';
+import type { HandoffDriver } from './macDriver.js';
+import { qrContent } from './qrCode.js';
+import { extractStep, type ExtractedStep } from './stepExtractor.js';
+import type {
+ ControlBinding,
+ FoundQr,
+ HandoffTarget,
+ NativeActKind,
+ NativeActResult,
+ NativeAxSnapshot,
+ NativeWindowList,
+ WindowCapture,
+} from './types.js';
+
+/** The current screenshot step; the JPEG is wiped as soon as the step is left. */
+interface PictureStep extends WindowCapture {
+ /** A text field had focus when photographed; the card shows one box for it. */
+ field?: 'text' | 'password';
+ /** Scan-to-sign-in: the picture is a QR code cut out of the window, and this is what it says. */
+ qr?: InputHandoffQr;
+}
+
+/** How often a QR code on screen is looked at again, to follow a refresh or see that it was scanned. */
+const QR_WATCH_MS = 2000;
+
+/** Where the flow stood when its QR code was first shown; leaving it means the scan went through. */
+interface QrBaseline {
+ pid: number;
+ windowIndex: number;
+ windowTitle: string;
+ url?: string;
+}
+
+/**
+ * Something on the step the owner is asked for: a field to type into, or a
+ * sign-in code to use on their own device.
+ */
+const actionable = (step: ExtractedStep) =>
+ !!step.deviceCode || step.shown.some((control) => control.kind === 'text');
+
+/** The window's structure can be read (it has controls), whether or not any are for the owner. */
+const readable = (step: ExtractedStep) => step.controls.some((control) => control.kind !== 'note');
+
+export interface HandoffTargetSpec {
+ app?: string;
+ pid?: number;
+ windowTitle?: string;
+}
+
+export interface HandoffCompletionHints {
+ windowClosed?: boolean;
+ textAppears?: string;
+ urlContains?: string;
+}
+
+export type HandoffEndReason = 'owner' | 'detected' | 'cancelled' | 'timeout' | 'failure' | 'session_closed';
+
+export interface HandoffResult {
+ status: 'succeeded' | 'cancelled' | 'failed' | 'expired';
+ reason: HandoffEndReason;
+ steps: number;
+ failure?: InputHandoffFailure;
+ finalApp?: string;
+ finalWindow?: string;
+ finalOrigin?: string;
+ /** Device that answered the last applied step; absent when no values were applied. */
+ answeredOn?: InputHandoffHolder;
+}
+
+/** The window a live view shows, located by the host when the owner opens it. */
+export interface LiveHandoffWindow {
+ pid: number;
+ app: string;
+ title?: string;
+ windowId: number;
+ /** Screen frame in points: x, y, width, height. */
+ frame: number[];
+}
+
+export interface HandoffSessionOptions {
+ requestId: string;
+ purpose: string;
+ note?: string;
+ requester?: string;
+ target: HandoffTargetSpec;
+ completeWhen?: HandoffCompletionHints;
+ timeoutMs: number;
+ /** Cindy itself; never a handoff target and never followed into. */
+ hostPid: number;
+ remoteInput: boolean;
+ /** Whether another device may open a live view of the window right now (remote desktop allowed). */
+ liveView?: () => boolean;
+ driver: HandoffDriver;
+ publish(snapshot: InputHandoffSnapshot): void;
+ finish(result: HandoffResult): void;
+ /** A secret was typed into a page the agent controls (automation browser); restrict its page reads. */
+ onSecretEntered?(target: { pid: number; url?: string }): void;
+ now?: () => number;
+ sleep?: (ms: number) => Promise<void>;
+ finishingDelayMs?: number;
+ settleTimeoutMs?: number;
+}
+
+const realSleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
+
+/**
+ * Handoffs move keyboard focus; only one may act on the desktop at a time.
+ * While Cindy types for the owner it holds the same lease as remote-desktop
+ * input, so the agent's own Computer Use waits and must observe again after.
+ */
+let desktopTurn: Promise<unknown> = Promise.resolve();
+function withDesktopTurn<T>(work: () => Promise<T>): Promise<T> {
+ const owned = async () => {
+ const lease = new HumanDesktopInput();
+ const turn = lease.begin([]);
+ try {
+ await turn.ready;
+ return await work();
+ } finally {
+ turn.complete();
+ lease.release();
+ }
+ };
+ const run = desktopTurn.then(owned, owned);
+ desktopTurn = run.catch(() => undefined);
+ return run;
+}
+
+function sameHolder(a: InputHandoffHolder, b: InputHandoffHolder): boolean {
+ return a.local === true ? b.local === true : b.local !== true && a.deviceId === b.deviceId;
+}
+
+const AUTOMATION_FLAGS = /--(remote-debugging-(port|pipe)|enable-automation|headless)\b/;
+
+/**
+ * One 代输入 request: a loop of read step → owner answers → act → wait for
+ * the screen to settle → read the next step, until the flow ends.
+ *
+ * The agent never sees steps or values. It only receives the final result.
+ */
+export class InputHandoffSession {
+ private revision = 0;
+ private unheldClaimFrom: number | null = null;
+ private phase: InputHandoffPhase = 'reading';
+ private failure: InputHandoffFailure | undefined;
+ private target: HandoffTarget | null = null;
+ private initial: HandoffTarget | null = null;
+ private step: ExtractedStep | null = null;
+ private stepNumber = 0;
+ private submissions = 0;
+ private finishingUntil: number | undefined;
+ private finishingTimer: ReturnType<typeof setTimeout> | undefined;
+ private expiryTimer: ReturnType<typeof setTimeout> | undefined;
+ private agentControlled = false;
+ private stayedOn: string | undefined;
+ private holder: InputHandoffHolder | undefined;
+ private answeredOn: InputHandoffHolder | undefined;
+ private ended = false;
+ private busy = false;
+ private picture: PictureStep | null = null;
+ /** The owner chose the screenshot for this flow; stays until they go back to the form. */
+ private pictureChosen = false;
+ /** Scan-to-sign-in: a code is on screen (`scan`), or it went away and the sign-in is finishing (`scanned`). */
+ private qrState: 'scan' | 'scanned' | null = null;
+ private qrBaseline: QrBaseline | null = null;
+ private qrTimer: ReturnType<typeof setTimeout> | undefined;
+ private qrChecking = false;
+ private readonly now: () => number;
+ private readonly sleep: (ms: number) => Promise<void>;
+
+ constructor(private readonly options: HandoffSessionOptions) {
+ this.now = options.now ?? Date.now;
+ this.sleep = options.sleep ?? realSleep;
+ this.options = { ...options, driver: this.watchLock(options.driver) };
+ }
+
+ /**
+ * A screen that locks while the card is open ends the handoff as
+ * screen_locked, whichever read, action or wait noticed it first.
+ */
+ private watchLock(driver: HandoffDriver): HandoffDriver {
+ const locked = () => {
+ if (!this.ended) this.end('failed', 'failure', 'screen_locked');
+ };
+ return new Proxy(driver, {
+ get: (target, property, receiver) => {
+ const value: unknown = Reflect.get(target, property, receiver);
+ if (typeof value !== 'function') return value;
+ return async (...args: unknown[]) => {
+ try {
+ const result: unknown = await value.apply(target, args);
+ if (result && typeof result === 'object' && (result as { error?: unknown }).error === 'locked') locked();
+ return result;
+ } catch (error) {
+ if (error instanceof Error && error.message === 'locked') locked();
+ throw error;
+ }
+ };
+ },
+ });
+ }
+
+ get requestId(): string {
+ return this.options.requestId;
+ }
+
+ snapshot(): InputHandoffSnapshot {
+ const step = this.step;
+ const picture = this.picture && this.phase === 'ready' ? this.picture : null;
+ const controls: InputHandoffControl[] = picture
+ ? picture.field && !picture.qr
+ ? [{ id: INPUT_HANDOFF_PICTURE_TEXT_ID, kind: 'text', label: '', contentType: picture.field }]
+ : []
+ : this.qrState === 'scanned'
+ ? []
+ : this.phase === 'ready' || this.phase === 'finishing'
+ ? step?.shown ?? []
+ : [];
+ const qr = this.phase !== 'ready' ? null : picture?.qr ? 'scan' : this.qrState === 'scanned' ? 'scanned' : null;
+ return {
+ kind: 'input_handoff',
+ requestId: this.options.requestId,
+ revision: this.revision,
+ phase: this.phase,
+ purpose: this.options.purpose,
+ ...(this.options.note ? { note: this.options.note } : {}),
+ ...(this.holder ? { holder: { ...this.holder } } : {}),
+ ...(this.options.requester ? { requester: this.options.requester } : {}),
+ source: this.source(),
+ stepNumber: Math.max(1, this.stepNumber),
+ controls,
+ ...(this.finishingUntil !== undefined && this.phase === 'finishing' ? { finishingUntil: this.finishingUntil } : {}),
+ ...(this.failure ? { failure: this.failure } : {}),
+ ...(this.agentControlled ? { agentControlled: true as const } : {}),
+ ...(this.options.remoteInput && !this.ended ? { remoteInput: true as const } : {}),
+ ...(this.ended ? { terminal: true as const } : {}),
+ ...(picture ? { picture: true as const } : {}),
+ ...(this.liveViewOffered() ? { liveView: true as const } : {}),
+ ...(!picture && !qr && this.phase === 'ready' && step?.deviceCode ? { deviceCode: { ...step.deviceCode } } : {}),
+ ...(qr ? { qr } : {}),
+ };
+ }
+
+ private liveViewOffered(): boolean {
+ return !this.ended && !!this.target && !!this.options.driver.raise
+ && (this.phase === 'ready' || this.phase === 'finishing') && this.options.liveView?.() === true;
+ }
+
+ /**
+ * The owner opened a live view of the window: bring it to the front and say
+ * where it is. Only while this request is waiting for the owner.
+ */
+ async liveWindow(): Promise<LiveHandoffWindow | null> {
+ const driver = this.options.driver;
+ const target = this.target;
+ if (!target || !driver.raise || !this.liveViewOffered() || this.busy) return null;
+ const raised = await withDesktopTurn(() => driver.raise!(target)).catch(() => null);
+ if (!raised || 'error' in raised || this.ended || this.target !== target) return null;
+ return {
+ pid: target.pid,
+ app: target.app,
+ ...(target.window.title ? { title: target.window.title } : {}),
+ windowId: raised.windowId,
+ frame: raised.frame,
+ };
+ }
+
+ /** The live view closed: read the window again, so the card shows where things are now. */
+ async afterLiveView(): Promise<void> {
+ if (this.ended || this.busy || this.phase !== 'ready') return;
+ await this.decide({ kind: 'input_handoff', action: 'refresh', expectedRevision: this.revision });
+ }
+
+ /** The current screenshot, for the executing Desktop and the sealed offer only. */
+ pictureFor(revision: number): InputHandoffPicture | null {
+ const picture = this.picture;
+ if (!picture || !this.isActionable(revision)) return null;
+ return {
+ mime: 'image/jpeg',
+ width: picture.width,
+ height: picture.height,
+ data: picture.jpeg.toString('base64'),
+ ...(picture.qr ? { qr: { ...picture.qr } } : {}),
+ };
+ }
+
+ isActionable(revision: number): boolean {
+ return !this.ended && !this.busy && this.phase === 'ready' && this.acceptsRevision(revision);
+ }
+
+ /** The current revision, or the one just before this screen was taken while nobody held it (see `decide`). */
+ private acceptsRevision(revision: number): boolean {
+ return revision === this.revision || (this.unheldClaimFrom !== null && revision === this.unheldClaimFrom && this.revision === revision + 1);
+ }
+
+ async start(): Promise<void> {
+ this.publish('reading');
+ this.expiryTimer = setTimeout(() => this.end('expired', 'timeout', 'timeout'), this.options.timeoutMs);
+ this.expiryTimer.unref?.();
+ try {
+ const permission = await this.options.driver.permission();
+ if (permission !== 'granted') {
+ if (permission === 'missing') await this.options.driver.requestPermission();
+ if ((await this.options.driver.permission()) !== 'granted') {
+ this.end('failed', 'failure', 'permission');
+ return;
+ }
+ }
+ const target = this.resolveTarget(await this.options.driver.windows());
+ if (!target) {
+ this.end('failed', 'failure', 'target_gone');
+ return;
+ }
+ await this.useTarget(target);
+ this.initial = target;
+ const step = await this.read().catch(() => null);
+ if (step && actionable(step)) {
+ this.present(step);
+ return;
+ }
+ // Nothing to type, but a QR code to scan (scan-to-sign-in, in any app or page).
+ this.step = step;
+ if (await this.showQr()) {
+ this.publish('ready');
+ return;
+ }
+ // A readable screen without a field to type into ends at once: its buttons and options are the agent's.
+ if (step && readable(step)) {
+ this.present(step);
+ return;
+ }
+ // Nothing readable in the window's structure (canvas, self-drawn UI): answer on a picture of it.
+ if (await this.showPicture()) {
+ this.publish('ready');
+ return;
+ }
+ // Neither its structure nor a picture of it can reach the owner.
+ this.end('failed', 'failure', 'unreadable');
+ } catch (error) {
+ // A locked screen is not read at all: say so, rather than blame the window.
+ this.end('failed', 'failure', error instanceof Error && error.message === 'locked' ? 'screen_locked' : 'unreadable');
+ }
+ }
+
+ /** Owner values. Returns false when the step is no longer the one the owner answered. */
+ async submit(submission: InputHandoffSubmission, actor?: InputHandoffHolder): Promise<boolean> {
+ if (!this.isActionable(submission.expectedRevision)) return false;
+ // The revision before a quiet claim is good only for the device that claimed.
+ if (submission.expectedRevision !== this.revision && !(actor && this.holder && sameHolder(actor, this.holder))) return false;
+ if (!validateInputHandoffSubmissionForStep({ ...this.snapshot(), revision: submission.expectedRevision }, submission)) return false;
+ if (this.picture) return this.submitPicture(this.picture, submission, actor);
+ const current = this.step;
+ if (!current) return false;
+ this.busy = true;
+ // Answering a step is starting to handle it: this device now holds the handoff.
+ if (actor) this.holder = actor;
+ this.clearFinishing();
+ this.failure = undefined;
+ this.publish('working');
+ const before = { signature: current.signature, windows: await this.options.driver.windows().catch(() => null) };
+ let outcome: boolean | 'origin_changed' = false;
+ try {
+ outcome = await withDesktopTurn(() => this.perform(current, submission));
+ } catch {
+ outcome = false;
+ } finally {
+ for (const key of Object.keys(submission.values)) delete submission.values[key];
+ }
+ if (this.ended) return true;
+ const ok = outcome === true;
+ if (outcome !== 'origin_changed') this.submissions++;
+ if (ok) this.answeredOn = actor ?? this.answeredOn;
+ try {
+ const next = await this.awaitSettled(before.signature, before.windows);
+ if (this.ended) return true;
+ if (next === 'ended') {
+ this.end('succeeded', 'detected');
+ return true;
+ }
+ if (outcome !== 'origin_changed') this.stepNumber++;
+ if (!ok) this.failure = outcome === 'origin_changed' ? 'origin_changed' : 'action_failed';
+ if (outcome === 'origin_changed' && !actionable(next)) {
+ // The page changed under the owner and now asks for nothing: say what happened, not "nothing to fill".
+ this.end('failed', 'failure', 'origin_changed');
+ return true;
+ }
+ // After a password, the next screen may ask to scan a code (a second factor).
+ if (ok && !actionable(next) && !this.hintsMet(next)) {
+ this.step = next;
+ if (await this.showQr()) {
+ this.publish('ready');
+ return true;
+ }
+ }
+ this.present(next, !ok);
+ } catch {
+ // The next screen cannot be read as a form: show it as a picture instead.
+ this.step = null;
+ if (!(await this.showPicture().catch(() => false))) this.failure = 'unreadable';
+ this.publish('ready');
+ } finally {
+ this.busy = false;
+ }
+ return true;
+ }
+
+ async decide(decision: InputHandoffDecision, actor?: InputHandoffHolder): Promise<boolean> {
+ if (this.ended || decision.expectedRevision !== this.revision) return false;
+ if (decision.action === 'cancel') {
+ this.end('cancelled', 'cancelled');
+ return true;
+ }
+ if (decision.action === 'claim') {
+ if (!actor || this.busy) return false;
+ if (this.holder && sameHolder(this.holder, actor)) return true;
+ // Taking over bumps the revision, so an answer already in flight from the
+ // previous holder is rejected as stale instead of racing this device. Taking
+ // a screen nobody held keeps the answer it was typed against valid (a
+ // password manager can fill and submit before the claim comes back).
+ const unheld = this.holder ? null : this.revision;
+ this.holder = actor;
+ this.publish(this.phase);
+ this.unheldClaimFrom = unheld;
+ return true;
+ }
+ if (this.busy) return false;
+ if (decision.action === 'done') {
+ this.end('succeeded', 'owner');
+ return true;
+ }
+ if (decision.action === 'stay') {
+ if (this.phase !== 'finishing') return false;
+ this.clearFinishing();
+ this.stayedOn = this.step?.signature;
+ this.publish('ready');
+ return true;
+ }
+ if (decision.action === 'picture') {
+ // The card's form does not match what the owner needs to see (a captcha image, a slider…).
+ if (this.phase !== 'ready') return false;
+ if (this.picture && !this.picture.qr) return true;
+ this.busy = true;
+ try {
+ // On a QR step this shows the whole window instead of just the code.
+ this.stopQr();
+ this.pictureChosen = true;
+ if (await this.showPicture()) this.failure = undefined;
+ else {
+ this.pictureChosen = false;
+ this.failure = 'picture_unavailable';
+ }
+ this.publish('ready');
+ } finally {
+ this.busy = false;
+ }
+ return true;
+ }
+ // refresh: re-read, following whatever is now in front; from a picture this is "back to the form".
+ this.busy = true;
+ this.pictureChosen = false;
+ try {
+ const windows = await this.options.driver.windows().catch(() => null);
+ const follow = windows ? this.followTarget(windows, null) : null;
+ if (follow === 'ended') {
+ this.end('succeeded', 'detected');
+ return true;
+ }
+ if (follow) await this.useTarget(follow);
+ const step = await this.read().catch(() => null);
+ if (step && actionable(step)) {
+ this.failure = undefined;
+ this.present(step, true);
+ return true;
+ }
+ this.step = step;
+ if (await this.showQr()) {
+ this.failure = undefined;
+ this.publish('ready');
+ return true;
+ }
+ if (step && !this.picture) {
+ this.failure = undefined;
+ this.present(step, true);
+ return true;
+ }
+ if (await this.showPicture()) this.failure = undefined;
+ else {
+ this.dropPicture();
+ this.failure = 'unreadable';
+ }
+ this.publish('ready');
+ } finally {
+ this.busy = false;
+ }
+ return true;
+ }
+
+ cancel(reason: HandoffEndReason = 'cancelled'): void {
+ this.end('cancelled', reason);
+ }
+
+ // ── internals ──────────────────────────────────────────────────────────
+
+ private publish(phase: InputHandoffPhase): void {
+ this.phase = phase;
+ this.revision++;
+ this.options.publish(this.snapshot());
+ }
+
+ private present(step: ExtractedStep, suppressAutoFinish = false): void {
+ this.stopQr();
+ this.dropPicture();
+ this.step = step;
+ if (this.submissions === 0 && !actionable(step)) {
+ // Nothing was asked of the owner yet and there is nothing to type: hand the screen back to the agent.
+ this.end('cancelled', 'detected', 'nothing_to_fill');
+ return;
+ }
+ if (this.stepNumber === 0) this.stepNumber = 1;
+ if (!suppressAutoFinish && this.shouldFinish(step)) {
+ this.finishingUntil = this.now() + (this.options.finishingDelayMs ?? 3000);
+ this.publish('finishing');
+ this.finishingTimer = setTimeout(() => {
+ if (this.phase === 'finishing') this.end('succeeded', 'detected');
+ }, this.options.finishingDelayMs ?? 3000);
+ this.finishingTimer.unref?.();
+ return;
+ }
+ this.publish('ready');
+ }
+
+ /** The agent said what the end looks like, and this screen shows it. */
+ private hintsMet(step: ExtractedStep): boolean {
+ const hints = this.options.completeWhen;
+ if (hints?.textAppears && step.texts.some((text) => text.includes(hints.textAppears!))) return true;
+ return !!hints?.urlContains && !!step.url?.includes(hints.urlContains);
+ }
+
+ private shouldFinish(step: ExtractedStep): boolean {
+ if (this.stayedOn !== undefined && this.stayedOn === step.signature) return false;
+ if (this.hintsMet(step)) return true;
+ // A sign-in code is still waiting to be used on the owner's device; they say when they are done.
+ if (step.deviceCode) return false;
+ // Generic end: after the owner answered, nothing is left to type. Buttons from here on are the agent's.
+ return this.submissions > 0 && !actionable(step);
+ }
+
+ /** What the card says it shows: the page when it can be read, otherwise the window. */
+ private source(): InputHandoffSource {
+ if (this.step) return this.step.source;
+ const app = this.target?.app ?? this.options.target.app ?? '';
+ return this.target?.window.title ? { app, window: this.target.window.title } : { app };
+ }
+
+ /** Photographs the target window for this step. False when the platform or permission does not allow it. */
+ private async showPicture(): Promise<boolean> {
+ const driver = this.options.driver;
+ const target = this.target;
+ if (!target || !driver.capture) return false;
+ const shot = await withDesktopTurn(() => driver.capture!(target)).catch(() => null);
+ if (!shot || 'error' in shot) return false;
+ const focus = await driver.focusedField?.(target.pid).catch(() => null);
+ this.stopQr();
+ this.dropPicture();
+ this.picture = { ...shot, ...(focus?.editable ? { field: focus.secure ? 'password' : 'text' } : {}) };
+ if (this.stepNumber === 0) this.stepNumber = 1;
+ return true;
+ }
+
+ private dropPicture(): void {
+ this.picture?.jpeg.fill(0);
+ this.picture = null;
+ }
+
+ /**
+ * Scan-to-sign-in: looks for a QR code in the target window and, when there
+ * is one, makes it this step. Works on any app or page; nothing product-specific.
+ */
+ private async showQr(): Promise<boolean> {
+ const driver = this.options.driver;
+ const target = this.target;
+ if (!target || !driver.qr || this.pictureChosen) return false;
+ const found = await withDesktopTurn(() => driver.qr!(target, null)).catch(() => null);
+ if (!found || 'error' in found) return false;
+ const qr = qrContent(found.text);
+ if (!qr || this.ended) {
+ found.capture.jpeg.fill(0);
+ return false;
+ }
+ this.dropPicture();
+ this.picture = { ...found.capture, qr };
+ this.qrState = 'scan';
+ const current = this.target ?? target;
+ this.qrBaseline = {
+ pid: current.pid,
+ windowIndex: current.window.index,
+ windowTitle: current.window.title,
+ ...(this.step?.url ? { url: this.step.url } : {}),
+ };
+ if (this.stepNumber === 0) this.stepNumber = 1;
+ this.watchQr();
+ return true;
+ }
+
+ private stopQr(): void {
+ if (this.qrTimer) clearTimeout(this.qrTimer);
+ this.qrTimer = undefined;
+ this.qrState = null;
+ this.qrBaseline = null;
+ }
+
+ private watchQr(): void {
+ if (this.qrTimer) clearTimeout(this.qrTimer);
+ const tick = async () => {
+ this.qrTimer = undefined;
+ if (this.ended || !this.qrState) return;
+ await this.checkQr().catch(() => undefined);
+ if (!this.ended && this.qrState && !this.qrTimer) {
+ this.qrTimer = setTimeout(() => void tick(), QR_WATCH_MS);
+ this.qrTimer.unref?.();
+ }
+ };
+ this.qrTimer = setTimeout(() => void tick(), QR_WATCH_MS);
+ this.qrTimer.unref?.();
+ }
+
+ /**
+ * Looks at the window again while its code waits to be scanned: a new code
+ * (refreshed or expired) replaces the old one; a code that went away means
+ * it was scanned, and leaving the page (a new window, address or title)
+ * means the sign-in went through. Anything the owner did meanwhile wins:
+ * a look that raced it is dropped.
+ */
+ private async checkQr(): Promise<void> {
+ const driver = this.options.driver;
+ const target = this.target;
+ if (!target || !driver.qr || this.busy || this.phase !== 'ready' || this.qrChecking) return;
+ const revision = this.revision;
+ const current = () => !this.ended && !this.busy && this.revision === revision && this.qrState !== null;
+ this.qrChecking = true;
+ try {
+ const windows = await driver.windows().catch(() => null);
+ if (!windows || !current()) return;
+ const mine = windows.apps.find((entry) => entry.pid === target.pid);
+ const window = mine?.windows.find((w) => w.index === target.window.index && w.title === target.window.title)
+ ?? mine?.windows.find((w) => w.title === target.window.title);
+ const otherFocused = windows.frontmost === target.pid && mine?.windows.some((w) => w.focused && !w.minimized && w !== window);
+ if (!window || otherFocused) {
+ // The window closed, changed its title, or a new one of the same app took over. Whatever
+ // other app happens to be in front is not followed: it says nothing about this sign-in.
+ const follow = this.followTarget({ ...windows, frontmost: target.pid }, null);
+ if (follow === 'ended') {
+ this.submissions++;
+ this.end('succeeded', 'detected');
+ return;
+ }
+ if (!follow) return;
+ // Nothing changes until the look is known to be current: an owner tap meanwhile keeps its window.
+ const agentControlled = follow.pid === target.pid
+ ? this.agentControlled
+ : AUTOMATION_FLAGS.test(await driver.commandLine(follow.pid).catch(() => ''));
+ if (!current()) return;
+ // A title that changed while the code still shows (a counter, a tab badge) is not a sign-in.
+ const frame = windows.apps.find((entry) => entry.pid === follow.pid)?.windows
+ .find((w) => w.index === follow.window.index && w.title === follow.window.title)?.frame;
+ const still = frame && frame.length === 4 ? await driver.qr(follow, frame).catch(() => null) : null;
+ if (!current()) {
+ if (still && !('error' in still)) still.capture.jpeg.fill(0);
+ return;
+ }
+ this.target = follow;
+ this.agentControlled = agentControlled;
+ const stillQr = still && !('error' in still) ? qrContent(still.text) : null;
+ if (still && !('error' in still) && stillQr) {
+ this.showFoundQr(still, stillQr);
+ return;
+ }
+ if (still && !('error' in still)) still.capture.jpeg.fill(0);
+ await this.qrLeft(true, current);
+ return;
+ }
+ // Another app in front (or the window minimized) hides the code: no conclusion from what cannot be seen.
+ if (window.minimized || windows.frontmost !== target.pid || !window.focused) return;
+ // A look that failed says nothing about the code: keep waiting.
+ const found = await driver.qr(target, window.frame).catch(() => ({ error: 'unavailable' as const }));
+ if (!current()) {
+ if (found && !('error' in found)) found.capture.jpeg.fill(0);
+ return;
+ }
+ if (found && 'error' in found) return;
+ const qr = found ? qrContent(found.text) : null;
+ if (found && qr) {
+ if (this.qrState === 'scan' && this.picture?.qr?.text === qr.text) {
+ found.capture.jpeg.fill(0);
+ return;
+ }
+ // A new code, or the code came back (expired, or the scan was cancelled on the phone).
+ this.showFoundQr(found, qr);
+ return;
+ }
+ found?.capture.jpeg.fill(0);
+ await this.qrLeft(false, current);
+ } finally {
+ this.qrChecking = false;
+ }
+ }
+
+ /** Shows a code found while waiting, in the window now followed. */
+ private showFoundQr(found: FoundQr, qr: InputHandoffQr): void {
+ this.dropPicture();
+ this.picture = { ...found.capture, qr };
+ this.qrState = 'scan';
+ this.failure = undefined;
+ const target = this.target;
+ if (target && this.qrBaseline) {
+ this.qrBaseline = { ...this.qrBaseline, pid: target.pid, windowIndex: target.window.index, windowTitle: target.window.title };
+ }
+ this.publish('ready');
+ }
+
+ /** The code is no longer on screen; `moved` when the flow went to another window. */
+ private async qrLeft(moved: boolean, current: () => boolean): Promise<void> {
+ const step = await this.read().catch(() => null);
+ if (!current()) return;
+ const baseline = this.qrBaseline;
+ if (step && actionable(step)) {
+ // Something to type next (for example a code sent after the scan).
+ this.submissions++;
+ this.stepNumber++;
+ this.present(step);
+ return;
+ }
+ const navigated = moved || (!!step && !!baseline?.url && !!step.url && step.url !== baseline.url) ||
+ (!!step && this.hintsMet(step));
+ if (navigated) {
+ // The page moved on: the scan went through. Hand back after the usual countdown.
+ this.submissions++;
+ this.stepNumber++;
+ if (step) {
+ this.present(step);
+ return;
+ }
+ this.end('succeeded', 'detected');
+ return;
+ }
+ if (this.qrState === 'scanned') return;
+ // Still the same page without its code: scanned, and waiting (for example a confirmation on the phone).
+ this.dropPicture();
+ if (step) this.step = step;
+ this.qrState = 'scanned';
+ this.publish('ready');
+ }
+
+ /** One tap, or typing into the focused field, on a screenshot step; then show what came next. */
+ private async submitPicture(
+ picture: PictureStep,
+ submission: InputHandoffSubmission,
+ actor?: InputHandoffHolder,
+ ): Promise<boolean> {
+ this.busy = true;
+ if (actor) this.holder = actor;
+ this.clearFinishing();
+ this.failure = undefined;
+ this.publish('working');
+ const before = await this.options.driver.windows().catch(() => null);
+ let outcome: boolean | 'origin_changed' = false;
+ try {
+ outcome = await withDesktopTurn(() => this.performPicture(picture, submission));
+ } catch {
+ outcome = false;
+ } finally {
+ for (const key of Object.keys(submission.values)) delete submission.values[key];
+ }
+ try {
+ if (this.ended) return true;
+ if (outcome !== 'origin_changed') this.submissions++;
+ if (outcome === true) this.answeredOn = actor ?? this.answeredOn;
+ const failure: InputHandoffFailure | undefined = outcome === true ? undefined
+ : outcome === 'origin_changed' ? 'origin_changed' : 'action_failed';
+ await this.sleep(700);
+ const windows = await this.options.driver.windows().catch(() => null);
+ if (windows) {
+ const follow = this.followTarget(windows, before);
+ if (follow === 'ended') {
+ this.end('succeeded', 'detected');
+ return true;
+ }
+ if (follow) await this.useTarget(follow);
+ }
+ if (this.ended) return true;
+ const step = await this.read().catch(() => null);
+ if (step && actionable(step) && !this.pictureChosen) {
+ // The screen can be read again and asks for typing: back to the card.
+ this.stepNumber++;
+ this.failure = failure;
+ this.present(step, failure !== undefined);
+ return true;
+ }
+ this.step = step;
+ this.failure = failure;
+ // A code to scan is (still) there, for example after tapping an expired one to refresh it.
+ if (await this.showQr()) {
+ this.publish('ready');
+ return true;
+ }
+ if (step && readable(step) && !this.pictureChosen) {
+ // Done when nothing is left to type.
+ this.stepNumber++;
+ this.present(step, failure !== undefined);
+ return true;
+ }
+ // No code any more: stop watching for one while the window is shown as a picture.
+ this.stopQr();
+ if (!(await this.showPicture())) {
+ this.dropPicture();
+ this.failure = 'picture_unavailable';
+ }
+ this.publish('ready');
+ } finally {
+ this.busy = false;
+ }
+ return true;
+ }
+
+ private async performPicture(
+ picture: PictureStep,
+ submission: InputHandoffSubmission,
+ ): Promise<boolean | 'origin_changed'> {
+ const driver = this.options.driver;
+ const target = this.target;
+ if (this.ended || !target || !driver.pointer) return false;
+ const base = { pid: target.pid, window: target.window, windowFrame: picture.windowFrame };
+ const action = submission.action;
+ let result: NativeActResult;
+ if (action.kind === 'tap') {
+ const [x, y, w, h] = picture.area;
+ result = await driver.pointer({ kind: 'tap', ...base, area: picture.area, point: [x + action.x * w, y + action.y * h] });
+ } else {
+ const typed = submission.values[INPUT_HANDOFF_PICTURE_TEXT_ID];
+ const value = typeof typed === 'string' ? typed : '';
+ if (!picture.field || (action.kind === 'fill' && !value)) return false;
+ const secure = picture.field === 'password';
+ result = await driver.pointer({ kind: 'type', ...base, value, submit: action.kind === 'submit', secure });
+ if ('ok' in result && result.ok && secure && value && this.agentControlled) {
+ this.options.onSecretEntered?.({ pid: target.pid, ...(this.step?.url ? { url: this.step.url } : {}) });
+ }
+ }
+ if ('error' in result && result.error === 'moved') return 'origin_changed';
+ return 'ok' in result && result.ok === true;
+ }
+
+ private clearFinishing(): void {
+ if (this.finishingTimer) clearTimeout(this.finishingTimer);
+ this.finishingTimer = undefined;
+ this.finishingUntil = undefined;
+ }
+
+ private end(status: HandoffResult['status'], reason: HandoffEndReason, failure?: InputHandoffFailure): void {
+ if (this.ended) return;
+ this.ended = true;
+ this.clearFinishing();
+ this.stopQr();
+ this.dropPicture();
+ if (this.expiryTimer) clearTimeout(this.expiryTimer);
+ this.failure = failure;
+ const phase: InputHandoffPhase = status === 'succeeded' ? 'succeeded' : status === 'expired' ? 'expired'
+ : status === 'cancelled' ? 'cancelled' : 'failed';
+ this.publish(phase);
+ this.options.finish({
+ status,
+ reason,
+ steps: this.submissions,
+ ...(failure ? { failure } : {}),
+ ...(this.target ? { finalApp: this.target.app } : {}),
+ ...(this.target?.window.title ? { finalWindow: this.target.window.title.slice(0, 200) } : {}),
+ ...(this.step?.source.origin ? { finalOrigin: this.step.source.origin } : {}),
+ ...(this.answeredOn ? { answeredOn: { ...this.answeredOn } } : {}),
+ });
+ }
+
+ private resolveTarget(list: NativeWindowList): HandoffTarget | null {
+ const spec = this.options.target;
+ const candidates = list.apps.filter((app) => app.pid !== this.options.hostPid && app.windows.some((w) => !w.minimized));
+ let app = spec.pid !== undefined ? candidates.find((entry) => entry.pid === spec.pid) : undefined;
+ if (!app && spec.app) {
+ const wanted = spec.app.trim().toLowerCase();
+ app = candidates.find((entry) => entry.app.toLowerCase() === wanted || entry.bundleId.toLowerCase() === wanted)
+ ?? candidates.find((entry) => entry.app.toLowerCase().includes(wanted));
+ }
+ if (!app && spec.pid === undefined && !spec.app) app = candidates.find((entry) => entry.pid === list.frontmost);
+ if (!app) return null;
+ const visibleWindows = app.windows.filter((window) => !window.minimized);
+ const title = spec.windowTitle?.toLowerCase();
+ const window = (title ? visibleWindows.find((w) => w.title.toLowerCase().includes(title)) : undefined)
+ ?? visibleWindows.find((w) => w.focused)
+ ?? visibleWindows[0];
+ if (!window) return null;
+ return { pid: app.pid, app: app.app, bundleId: app.bundleId, window: { index: window.index, title: window.title } };
+ }
+
+ private async useTarget(target: HandoffTarget): Promise<void> {
+ if (this.target?.pid !== target.pid) {
+ this.agentControlled = AUTOMATION_FLAGS.test(await this.options.driver.commandLine(target.pid));
+ }
+ this.target = target;
+ }
+
+ private async read(): Promise<ExtractedStep | null> {
+ if (!this.target) return null;
+ const raw = await this.options.driver.snapshot(this.target.pid, this.target.window);
+ if ('error' in raw) return null;
+ this.target = { ...this.target, window: { index: raw.window.index, title: raw.window.title } };
+ return extractStep(raw as NativeAxSnapshot);
+ }
+
+ private async act(binding: ControlBinding, kind: NativeActKind, value?: string): Promise<boolean> {
+ // Checked before every fill and press: an ended request never touches the window again.
+ if (this.ended || !this.target) return false;
+ const request = { pid: this.target.pid, window: this.target.window, ref: binding.ref, fp: binding.fp, kind, ...(value !== undefined ? { value } : {}) };
+ let result: NativeActResult = await this.options.driver.act(request);
+ if (!('ok' in result && result.ok) && 'error' in result && result.error === 'stale') {
+ // The screen re-rendered; find the same element by identity and retry once.
+ const fresh = await this.options.driver.snapshot(this.target.pid, this.target.window);
+ if ('error' in fresh) return false;
+ const matches = fresh.nodes.filter((node) => node.fp === binding.fp);
+ if (matches.length !== 1 || this.ended) return false;
+ result = await this.options.driver.act({ ...request, ref: matches[0].ref, window: { index: fresh.window.index, title: fresh.window.title } });
+ }
+ return 'ok' in result && result.ok === true;
+ }
+
+ /** Some forms enable their button only after input events settle. */
+ private async pressSettled(binding: ControlBinding & { kind: 'press' }): Promise<boolean> {
+ for (let attempt = 0; attempt < 3; attempt++) {
+ if (await this.act(binding, 'press')) return true;
+ await this.sleep(300);
+ }
+ return false;
+ }
+
+ /** The page a secret is about to go into is still the one the owner was shown. */
+ private async sameSurface(step: ExtractedStep): Promise<boolean> {
+ if (!this.target) return false;
+ const raw = await this.options.driver.snapshot(this.target.pid, this.target.window);
+ if ('error' in raw || raw.window.title !== this.target.window.title) return false;
+ return extractStep(raw).source.origin === step.source.origin;
+ }
+
+ private async perform(step: ExtractedStep, submission: InputHandoffSubmission): Promise<boolean | 'origin_changed'> {
+ // Waiting for the desktop may outlast the request (cancelled, timed out, task closed): then nothing is typed.
+ if (this.ended) return false;
+ let lastText: (ControlBinding & { kind: 'text' }) | undefined;
+ let secretEntered = false;
+ // Secrets are bound to the page the owner saw: re-check it before typing anything in this step.
+ const carriesSecret = step.controls.some((control) => {
+ const binding = step.bindings.get(control.id);
+ return binding?.kind === 'text' && binding.secure && typeof submission.values[control.id] === 'string';
+ });
+ if (carriesSecret && !(await this.sameSurface(step))) return 'origin_changed';
+ for (const control of step.shown) {
+ if (!Object.hasOwn(submission.values, control.id)) continue;
+ const value = submission.values[control.id];
+ const binding = step.bindings.get(control.id);
+ if (binding?.kind !== 'text' || typeof value !== 'string') return false;
+ if (!(await this.act(binding, 'text', value))) return false;
+ if (binding.secure && !secretEntered) {
+ secretEntered = true;
+ if (this.agentControlled && this.target) {
+ this.options.onSecretEntered?.({ pid: this.target.pid, ...(step.url ? { url: step.url } : {}) });
+ }
+ }
+ lastText = binding;
+ await this.sleep(60);
+ }
+ // The owner only typed; confirm with the page's own main button, as they would, else Return.
+ const primary = step.controls.find((control) => control.kind === 'button' && control.primary);
+ const button = primary && step.bindings.get(primary.id);
+ if (button?.kind === 'press') return this.pressSettled(button);
+ const field = lastText ?? [...step.bindings.values()].find((b): b is ControlBinding & { kind: 'text' } => b.kind === 'text');
+ return !!field && this.act(field, 'key', 'return');
+ }
+
+ /**
+ * Wait until the screen stops changing, following the flow into a new
+ * window or another app (for example a browser opened for authorization).
+ */
+ private async awaitSettled(previous: string, before: NativeWindowList | null): Promise<ExtractedStep | 'ended'> {
+ const deadline = this.now() + (this.options.settleTimeoutMs ?? 15_000);
+ const start = this.now();
+ let last: ExtractedStep | null = null;
+ let stableReads = 0;
+ await this.sleep(400);
+ while (!this.ended) {
+ const windows = await this.options.driver.windows().catch(() => null);
+ if (windows) {
+ const asks = last ? actionable(last) : !!this.step && actionable(this.step);
+ const follow = this.followTarget(windows, before, asks);
+ if (follow === 'ended') return 'ended';
+ if (follow && (follow.pid !== this.target?.pid || follow.window.index !== this.target?.window.index ||
+ follow.window.title !== this.target?.window.title)) {
+ await this.useTarget(follow);
+ last = null;
+ stableReads = 0;
+ }
+ }
+ const step = await this.read().catch(() => null);
+ if (step) {
+ if (last && last.signature === step.signature) stableReads++;
+ else stableReads = 0;
+ last = step;
+ const changed = step.signature !== previous;
+ if (stableReads >= 1 && (changed || this.now() - start >= 4000)) return step;
+ }
+ if (this.now() >= deadline) {
+ if (last) return last;
+ throw new Error('INPUT_HANDOFF_UNREADABLE');
+ }
+ await this.sleep(350);
+ }
+ return last ?? 'ended';
+ }
+
+ /** Decide which window the flow now lives in. `'ended'` when nothing remains to follow. */
+ private followTarget(list: NativeWindowList, before: NativeWindowList | null, currentAsks = false): HandoffTarget | 'ended' | null {
+ const current = this.target;
+ if (!current) return null;
+ const hints = this.options.completeWhen;
+ const app = (pid: number) => list.apps.find((entry) => entry.pid === pid);
+ const toTarget = (entry: NativeWindowList['apps'][number], window: NativeWindowList['apps'][number]['windows'][number]): HandoffTarget => ({
+ pid: entry.pid, app: entry.app, bundleId: entry.bundleId, window: { index: window.index, title: window.title },
+ });
+ // Another app came to the front (for example the browser for an authorization page). While the
+ // form still asks the owner for something, only a window that just opened or changed counts:
+ // someone switching to an app they already had open is not where the sign-in went.
+ if (list.frontmost !== current.pid && list.frontmost !== this.options.hostPid) {
+ const front = app(list.frontmost);
+ const window = front?.windows.find((w) => w.focused && !w.minimized) ?? front?.windows.find((w) => !w.minimized);
+ const unchanged = !!window && !!before?.apps.find((entry) => entry.pid === list.frontmost)?.windows
+ .some((w) => w.index === window.index && w.title === window.title);
+ if (front && window && !(currentAsks && unchanged)) return toTarget(front, window);
+ }
+ const mine = app(current.pid);
+ const sameWindow = mine?.windows.find((w) => w.index === current.window.index && w.title === current.window.title)
+ ?? mine?.windows.find((w) => w.title === current.window.title);
+ // A new window in the same app took focus (dialogs, popups, sign-in windows).
+ const focused = mine?.windows.find((w) => w.focused && !w.minimized);
+ if (focused && focused !== sameWindow) {
+ const existedBefore = before?.apps.find((entry) => entry.pid === current.pid)?.windows
+ .some((w) => w.title === focused.title && w.index === focused.index);
+ if (!existedBefore || !sameWindow) return toTarget(mine!, focused);
+ }
+ if (sameWindow) return null;
+ // The window closed.
+ if (hints?.windowClosed && this.initial && current.pid === this.initial.pid &&
+ current.window.title === this.initial.window.title) return 'ended';
+ if (mine) {
+ const next = mine.windows.find((w) => w.focused && !w.minimized) ?? mine.windows.find((w) => !w.minimized);
+ if (next) return toTarget(mine, next);
+ }
+ const origin = this.initial && app(this.initial.pid);
+ if (origin && origin.pid !== current.pid) {
+ const next = origin.windows.find((w) => w.focused && !w.minimized) ?? origin.windows.find((w) => !w.minimized);
+ if (next) return toTarget(origin, next);
+ }
+ return 'ended';
+ }
+}
diff --git a/apps/desktop/src/main/input-handoff/stepExtractor.ts b/apps/desktop/src/main/input-handoff/stepExtractor.ts
new file mode 100644
index 0000000000..3351d12f76
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/stepExtractor.ts
@@ -0,0 +1,419 @@
+import {
+ INPUT_HANDOFF_LABEL_MAX_CHARS,
+ INPUT_HANDOFF_MAX_CONTROLS,
+ INPUT_HANDOFF_MAX_OPTIONS,
+ type InputHandoffContentType,
+ type InputHandoffControl,
+ type InputHandoffDeviceCode,
+ type InputHandoffSource,
+} from '@cindy/device-link';
+import type { ControlBinding, NativeAxNode, NativeAxSnapshot, ScreenControl } from './types.js';
+import { classifyOrigin, isBrowserBundle } from './originPolicy.js';
+import { findDeviceCode } from './deviceCode.js';
+
+/**
+ * Maps one native accessibility snapshot to a card step.
+ *
+ * Generic by design: no site or product knowledge. Web pages are scoped to
+ * their visible page area (not the browser toolbar); native windows use every
+ * visible control. Text-field values are never part of the input.
+ */
+
+export interface ExtractedStep {
+ /** Everything readable on the step; the Host keeps it to act and to detect changes. */
+ controls: ScreenControl[];
+ /**
+ * What the owner is asked for: the text fields to type into and any error
+ * about them. Empty when the step has nothing to type; buttons, pick lists,
+ * boxes, headings and links stay with the agent.
+ */
+ shown: InputHandoffControl[];
+ bindings: Map<string, ControlBinding>;
+ source: InputHandoffSource;
+ /** Stable when the visible structure is unchanged; used for settle and change detection. */
+ signature: string;
+ hasSecure: boolean;
+ /** Full page URL of the scoped web content, for completion hints only. */
+ url?: string;
+ /** All visible text, for completion hints only. Never shown to the agent. */
+ texts: string[];
+ /** A sign-in code plus a link to open elsewhere, when that is all the step asks for. */
+ deviceCode?: InputHandoffDeviceCode;
+}
+
+const SKIPPED_SUBROLES = new Set([
+ 'AXCloseButton',
+ 'AXMinimizeButton',
+ 'AXZoomButton',
+ 'AXFullScreenButton',
+ 'AXToolbarButton',
+ 'AXSortButton',
+ 'AXIncrementArrow',
+ 'AXDecrementArrow',
+]);
+const TEXT_ROLES = new Set(['AXTextField', 'AXTextArea', 'AXSearchField', 'AXComboBox', 'AXDateTimeArea']);
+const BUTTON_ROLES = new Set(['AXButton', 'AXLink', 'AXMenuButton', 'AXDisclosureTriangle', 'AXMenuItem']);
+const PRIMARY_LABEL =
+ /^(next|continue|sign ?in|log ?in|login|submit|confirm|allow|authori[sz]e|accept|approve|ok|done|verify|send|proceed|下一步|继续|登录|登入|提交|确认|确定|允许|授权|同意|验证|完成|发送|进入)\b/i;
+
+const clip = (text: string) =>
+ text.replace(/\s+/g, ' ').trim().slice(0, INPUT_HANDOFF_LABEL_MAX_CHARS);
+
+function visible(node: NativeAxNode, windowFrame: number[]): boolean {
+ const frame = node.frame;
+ if (!frame || frame.length !== 4) return false;
+ const [x, y, w, h] = frame;
+ if (w < 2 || h < 2) return false;
+ if (windowFrame.length !== 4) return true;
+ const [wx, wy, ww, wh] = windowFrame;
+ return x + w > wx && y + h > wy && x < wx + ww && y < wy + wh;
+}
+
+const isWithin = (ref: string, scope: string) => ref === scope || ref.startsWith(`${scope}.`);
+const parentRef = (ref: string) => ref.slice(0, Math.max(0, ref.lastIndexOf('.')));
+
+function area(node: NativeAxNode): number {
+ return node.frame && node.frame.length === 4 ? node.frame[2] * node.frame[3] : 0;
+}
+
+function ownLabel(node: NativeAxNode): string | undefined {
+ for (const candidate of [node.titleElement, node.title, node.desc, node.placeholder, node.help]) {
+ if (candidate && candidate.trim()) return clip(candidate);
+ }
+ return undefined;
+}
+
+function buttonLabel(node: NativeAxNode): string | undefined {
+ for (const candidate of [node.title, node.desc, node.value, node.titleElement, node.help]) {
+ if (candidate && candidate.trim()) return clip(candidate);
+ }
+ return undefined;
+}
+
+function textOf(node: NativeAxNode): string | undefined {
+ for (const candidate of [node.value, node.title, node.desc]) {
+ if (candidate && candidate.trim()) return clip(candidate);
+ }
+ return undefined;
+}
+
+/** Nearest preceding static text above or to the left of the field. */
+function nearbyLabel(field: NativeAxNode, texts: Array<{ node: NativeAxNode; index: number }>, index: number) {
+ const frame = field.frame!;
+ let best: { text: string; distance: number } | undefined;
+ for (const entry of texts) {
+ if (entry.index >= index) break;
+ const label = textOf(entry.node);
+ const other = entry.node.frame;
+ if (!label || !other || label.length > 80) continue;
+ const above = other[1] + other[3] <= frame[1] + 4 && frame[1] - (other[1] + other[3]) <= 48 &&
+ other[0] < frame[0] + frame[2] && other[0] + other[2] > frame[0] - 8;
+ const left = Math.abs(other[1] + other[3] / 2 - (frame[1] + frame[3] / 2)) <= frame[3] &&
+ other[0] + other[2] <= frame[0] + 4 && frame[0] - (other[0] + other[2]) <= 240;
+ if (!above && !left) continue;
+ const distance = above ? frame[1] - (other[1] + other[3]) : frame[0] - (other[0] + other[2]);
+ if (!best || distance <= best.distance) best = { text: label, distance };
+ }
+ return best?.text;
+}
+
+export function contentTypeFor(node: NativeAxNode, label: string): InputHandoffContentType {
+ if (node.secure) return 'password';
+ const hint = [label, node.placeholder, node.domId, node.desc, node.title].filter(Boolean).join(' ');
+ if (/(one[- ]?time|\botp\b|verification code|security code|auth(entication)? code|2fa|two[- ]?(factor|step)|验证码|动态码|校验码|安全码)/i.test(hint))
+ return 'one-time-code';
+ if (/(e-?mail|邮箱|邮件)/i.test(hint)) return 'email';
+ if (/(phone|mobile|\btel\b|手机|电话)/i.test(hint)) return 'tel';
+ if (/(user ?name|\blogin\b|account|用户名|账号|帐号|工号|登录名)/i.test(hint)) return 'username';
+ if (/(\burl\b|website|网址|域名)/i.test(hint)) return 'url';
+ if (node.role === 'AXSearchField' || node.subrole === 'AXSearchField' || /(search|搜索)/i.test(hint))
+ return 'search';
+ return 'text';
+}
+
+function signatureOf(source: InputHandoffSource, controls: ScreenControl[]): string {
+ return JSON.stringify([
+ source.app,
+ source.window ?? '',
+ source.origin ?? '',
+ controls.map((control) =>
+ control.kind === 'note'
+ ? ['n', control.tone, control.text]
+ : control.kind === 'choice'
+ ? ['c', control.label, control.selected ?? '', control.options.length]
+ : control.kind === 'toggle'
+ ? ['t', control.label, control.checked]
+ : control.kind === 'text'
+ ? ['x', control.label, control.contentType, control.filled ?? false]
+ : ['b', control.label],
+ ),
+ ]);
+}
+
+export function extractStep(snapshot: NativeAxSnapshot): ExtractedStep {
+ const windowFrame = snapshot.window.frame ?? [];
+ const browser = isBrowserBundle(snapshot.bundleId);
+ const nodes = snapshot.nodes.filter((node) => visible(node, windowFrame));
+
+ // Scope web pages to their largest visible web area (drops browser toolbars and tab strips).
+ const webAreas = nodes.filter((node) => node.role === 'AXWebArea');
+ const topWeb = webAreas
+ .filter((area) => !webAreas.some((other) => other !== area && isWithin(area.ref, other.ref)))
+ .sort((a, b) => area(b) - area(a))[0];
+ const scoped = topWeb ? nodes.filter((node) => isWithin(node.ref, topWeb.ref)) : nodes;
+
+ // Modal sheets take over the window.
+ const sheet = scoped.find((node) => node.role === 'AXSheet');
+ const inScope = sheet ? scoped.filter((node) => isWithin(node.ref, sheet.ref)) : scoped;
+
+ const origin = topWeb?.url && (browser || /^https?:/i.test(topWeb.url))
+ ? classifyOrigin(topWeb.url, browser)
+ : undefined;
+
+ const textNodes: Array<{ node: NativeAxNode; index: number }> = [];
+ inScope.forEach((node, index) => {
+ if (node.role === 'AXStaticText') textNodes.push({ node, index });
+ });
+
+ const controls: ScreenControl[] = [];
+ const bindings = new Map<string, ControlBinding>();
+ const usedLabels = new Set<string>();
+ const radioGroups = new Map<string, { label: string; members: NativeAxNode[] }>();
+ let next = 0;
+ const id = () => `c${next++}`;
+ /** Where each control sits in the tree, to place explanatory lines in reading order. */
+ const refs = new Map<string, string>();
+ let hasSecure = false;
+ let lastTextControl: Extract<InputHandoffControl, { kind: 'text' }> | undefined;
+
+ const groupOf = (radio: NativeAxNode): string => {
+ const group = inScope
+ .filter((node) => (node.role === 'AXRadioGroup' || node.role === 'AXTabGroup') && isWithin(radio.ref, node.ref))
+ .sort((a, b) => b.ref.length - a.ref.length)[0];
+ return group?.ref ?? parentRef(radio.ref);
+ };
+
+ inScope.forEach((node, index) => {
+ if (node.subrole && SKIPPED_SUBROLES.has(node.subrole)) return;
+ if (TEXT_ROLES.has(node.role)) {
+ const label = ownLabel(node) ?? nearbyLabel(node, textNodes, index) ?? '';
+ if (label) usedLabels.add(label);
+ let contentType = contentTypeFor(node, label);
+ if (contentType === 'password') {
+ hasSecure = true;
+ // Pair the preceding field as the account for password managers.
+ if (lastTextControl && (lastTextControl.contentType === 'text' || lastTextControl.contentType === 'email'))
+ lastTextControl.contentType = 'username';
+ }
+ const controlId = id();
+ const suggestions = node.role === 'AXComboBox' && node.options?.length
+ ? node.options.slice(0, INPUT_HANDOFF_MAX_OPTIONS).map((option, i) => ({ id: `o${i}`, label: clip(option) }))
+ : undefined;
+ const control: Extract<InputHandoffControl, { kind: 'text' }> = {
+ id: controlId,
+ kind: 'text',
+ label,
+ contentType,
+ ...(node.placeholder && node.placeholder !== label ? { placeholder: clip(node.placeholder) } : {}),
+ ...(node.role === 'AXTextArea' ? { multiline: true as const } : {}),
+ ...(node.hasValue ? { filled: true as const } : {}),
+ ...(suggestions ? { suggestions } : {}),
+ };
+ controls.push(control);
+ lastTextControl = control;
+ bindings.set(controlId, { kind: 'text', ref: node.ref, fp: node.fp, secure: !!node.secure });
+ refs.set(controlId, node.ref);
+ return;
+ }
+ // Pop-ups, boxes and radios are the agent's to operate; they are read only to tell steps apart.
+ if (node.role === 'AXPopUpButton' && (node.options?.length || node.value)) {
+ const label = ownLabel(node) ?? nearbyLabel(node, textNodes, index) ?? '';
+ const options = (node.options ?? []).slice(0, INPUT_HANDOFF_MAX_OPTIONS).map((option, i) => ({
+ id: `o${i}`,
+ label: clip(option),
+ }));
+ const controlId = id();
+ const selected = options.find((option) => option.label === node.value)?.id;
+ controls.push({ id: controlId, kind: 'choice', label, options, ...(selected ? { selected } : {}) });
+ refs.set(controlId, node.ref);
+ return;
+ }
+ if (node.role === 'AXCheckBox') {
+ const label = buttonLabel(node) ?? nearbyLabel(node, textNodes, index);
+ if (!label) return;
+ const controlId = id();
+ controls.push({ id: controlId, kind: 'toggle', label, checked: !!node.checked });
+ refs.set(controlId, node.ref);
+ return;
+ }
+ if (node.role === 'AXRadioButton') {
+ const key = groupOf(node);
+ const groupNode = inScope.find((candidate) => candidate.ref === key);
+ const existing = radioGroups.get(key);
+ if (existing) {
+ existing.members.push(node);
+ return;
+ }
+ const label = (groupNode && ownLabel(groupNode)) ?? '';
+ radioGroups.set(key, { label, members: [node] });
+ // Placeholder keeps document order; filled in below.
+ controls.push({ id: `radio:${key}`, kind: 'choice', label, options: [] });
+ return;
+ }
+ if (BUTTON_ROLES.has(node.role) || (node.role === 'AXPopUpButton')) {
+ const label = buttonLabel(node);
+ if (!label) return;
+ const controlId = id();
+ controls.push({
+ id: controlId,
+ kind: 'button',
+ label,
+ ...(node.role === 'AXLink' ? { link: true as const } : {}),
+ });
+ bindings.set(controlId, { kind: 'press', ref: node.ref, fp: node.fp });
+ refs.set(controlId, node.ref);
+ return;
+ }
+ if (node.role === 'AXHeading') {
+ const text = textOf(node);
+ if (text) controls.push({ id: id(), kind: 'note', tone: 'heading', text });
+ return;
+ }
+ if (node.role === 'AXStaticText' && node.alert) {
+ const text = textOf(node);
+ if (text) controls.push({ id: id(), kind: 'note', tone: 'error', text });
+ }
+ });
+
+ // Resolve radio placeholders into choices.
+ for (let i = 0; i < controls.length; i++) {
+ const control = controls[i];
+ if (control.kind !== 'choice' || !control.id.startsWith('radio:')) continue;
+ const group = radioGroups.get(control.id.slice('radio:'.length))!;
+ const controlId = id();
+ const shown = group.members
+ .map((member) => ({ member, label: buttonLabel(member) }))
+ .filter((entry): entry is { member: NativeAxNode; label: string } => !!entry.label)
+ .slice(0, INPUT_HANDOFF_MAX_OPTIONS)
+ .map((entry, index) => ({ id: `o${index}`, label: entry.label, checked: !!entry.member.checked }));
+ if (shown.length === 0) {
+ controls.splice(i--, 1);
+ continue;
+ }
+ const selected = shown.find((option) => option.checked)?.id;
+ controls[i] = {
+ id: controlId,
+ kind: 'choice',
+ label: group.label,
+ options: shown.map(({ id: optionId, label }) => ({ id: optionId, label })),
+ ...(selected ? { selected } : {}),
+ };
+ refs.set(controlId, group.members[0].ref);
+ }
+
+ // Short pages: a few explanatory lines that are not field labels, so a changed message counts as a new step.
+ const interactive = controls.filter((control) => control.kind !== 'note').length;
+ if (interactive <= 12 && textNodes.length <= 24) {
+ let added = 0;
+ for (const { node, index } of textNodes) {
+ if (added >= 3 || node.alert) continue;
+ const text = textOf(node);
+ if (!text || text.length < 4 || usedLabels.has(text)) continue;
+ if (controls.some((control) => control.kind !== 'note' && control.label === text)) continue;
+ // Insert before the first control that comes after this text in document order.
+ const position = controlIndexAfter(inScope, controls, refs, index);
+ controls.splice(position, 0, { id: id(), kind: 'note', tone: 'info', text });
+ added++;
+ }
+ }
+
+ // Exactly one primary action: the first labelled like a submit, after the last input.
+ const lastInput = controls.reduce((last, control, i) => (
+ control.kind === 'text' || control.kind === 'choice' || control.kind === 'toggle' ? i : last
+ ), -1);
+ const primary = controls.findIndex(
+ (control, i) => control.kind === 'button' && !control.link && i > lastInput && PRIMARY_LABEL.test(control.label),
+ );
+ if (primary >= 0) (controls[primary] as Extract<ScreenControl, { kind: 'button' }>).primary = true;
+
+ const capped = capControls(controls, bindings);
+ const source: InputHandoffSource = {
+ app: clip(snapshot.app) || snapshot.bundleId || 'App',
+ ...(snapshot.window.title ? { window: clip(snapshot.window.title) } : {}),
+ ...(origin?.origin ? { origin: origin.origin } : {}),
+ ...(origin?.warning ? { warning: origin.warning } : {}),
+ };
+ if (!source.warning && topWeb && hasSecure) {
+ // A password field inside a nested page from another origin.
+ const secureNode = inScope.find((node) => node.secure);
+ const frameArea = secureNode && webAreas
+ .filter((area) => area !== topWeb && isWithin(secureNode.ref, area.ref))
+ .sort((a, b) => b.ref.length - a.ref.length)[0];
+ const nested = frameArea?.url ? classifyOrigin(frameArea.url, browser) : undefined;
+ if (nested?.origin && origin?.origin && nested.origin !== origin.origin) source.warning = 'embedded-frame';
+ }
+ const texts = inScope.map((node) => textOf(node)).filter((text): text is string => !!text);
+ const deviceCode = findDeviceCode(inScope, capped.some((control) => control.kind === 'text'));
+ return {
+ controls: capped,
+ shown: deviceCode ? [] : ownerControls(capped),
+ bindings,
+ source,
+ signature: signatureOf(source, capped),
+ hasSecure,
+ ...(topWeb?.url ? { url: topWeb.url } : {}),
+ texts,
+ ...(deviceCode ? { deviceCode } : {}),
+ };
+}
+
+/**
+ * Only what needs the owner: the text fields to type into, plus any error the
+ * page shows about them. Buttons, pick lists and boxes stay with the agent, so
+ * a step without a text field asks the owner for nothing.
+ */
+function ownerControls(controls: ScreenControl[]): InputHandoffControl[] {
+ const shown = (control: ScreenControl): control is InputHandoffControl =>
+ (control.kind === 'text' && control.contentType !== 'search') || (control.kind === 'note' && control.tone === 'error');
+ // A search box alone (a page after sign-in) is not something the owner was asked for.
+ if (!controls.some((control) => control.kind === 'text' && control.contentType !== 'search')) return [];
+ return controls.filter(shown);
+}
+
+function controlIndexAfter(
+ nodes: NativeAxNode[],
+ controls: ScreenControl[],
+ refs: Map<string, string>,
+ nodeIndex: number,
+): number {
+ const order = new Map(nodes.map((node, index) => [node.ref, index]));
+ for (let i = 0; i < controls.length; i++) {
+ const ref = refs.get(controls[i].id);
+ if (ref !== undefined && (order.get(ref) ?? -1) > nodeIndex) return i;
+ }
+ return controls.length;
+}
+
+/** Keep inputs and primary actions when a screen is crowded; links go first. */
+function capControls(
+ controls: ScreenControl[],
+ bindings: Map<string, ControlBinding>,
+): ScreenControl[] {
+ if (controls.length <= INPUT_HANDOFF_MAX_CONTROLS) return controls;
+ const rank = (control: ScreenControl) =>
+ control.kind === 'text' || control.kind === 'choice' ? 0
+ : control.kind === 'button' && control.primary ? 0
+ : control.kind === 'note' && control.tone !== 'info' ? 1
+ : control.kind === 'toggle' ? 1
+ : control.kind === 'button' && !control.link ? 2
+ : 3;
+ const keep = new Set(
+ controls
+ .map((control, index) => ({ control, index }))
+ .sort((a, b) => rank(a.control) - rank(b.control) || a.index - b.index)
+ .slice(0, INPUT_HANDOFF_MAX_CONTROLS)
+ .map((entry) => entry.control.id),
+ );
+ for (const control of controls) if (!keep.has(control.id)) bindings.delete(control.id);
+ return controls.filter((control) => keep.has(control.id));
+}
diff --git a/apps/desktop/src/main/input-handoff/terminalPrompt.ts b/apps/desktop/src/main/input-handoff/terminalPrompt.ts
new file mode 100644
index 0000000000..aedc2011b4
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/terminalPrompt.ts
@@ -0,0 +1,225 @@
+import {
+ validateInputHandoffSubmissionForStep,
+ type InputHandoffContentType,
+ type InputHandoffControl,
+ type InputHandoffDecision,
+ type InputHandoffHolder,
+ type InputHandoffPhase,
+ type InputHandoffSnapshot,
+ type InputHandoffSource,
+ type InputHandoffSubmission,
+} from '@cindy/device-link';
+import { classifyOrigin } from './originPolicy.js';
+import type { HandoffEndReason, HandoffResult } from './session.js';
+
+/**
+ * 代输入 for a password prompt from a terminal program (sudo, ssh, git over
+ * HTTPS). The program asked through Cindy's askpass helper; the owner's answer
+ * goes straight back to that program and never to the agent, whose command is
+ * still running and simply continues.
+ */
+
+export type TerminalProgram = 'sudo' | 'ssh' | 'ssh-add' | 'git';
+
+export interface TerminalPromptStep {
+ purpose: string;
+ source: InputHandoffSource;
+ /** One field; whatever the owner types goes back to the program as the answer. */
+ controls: [Extract<InputHandoffControl, { kind: 'text' }>];
+}
+
+const FIELD_ID = 'answer';
+
+const PROMPT_MAX = 300;
+const URL_IN_PROMPT = /\bhttps?:\/\/[^\s'"]+/i;
+
+function contentTypeFor(prompt: string, program: TerminalProgram): InputHandoffContentType {
+ if (/verification code|one[- ]time|\botp\b|authenticator|token code|验证码/i.test(prompt)) return 'one-time-code';
+ if (/^\s*username\b|\buser ?name for\b|^\s*login:/i.test(prompt)) return 'username';
+ if (/pass(word|phrase)|\bpin\b|密码|口令/i.test(prompt) || program === 'sudo') return 'password';
+ // Anything else a terminal program asks through askpass is treated as secret.
+ return 'password';
+}
+
+export function buildTerminalPromptStep(rawPrompt: string, program: TerminalProgram): TerminalPromptStep {
+ const prompt = rawPrompt.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, '').trim().slice(0, PROMPT_MAX)
+ || (program === 'sudo' ? 'Password:' : 'Input:');
+ const url = prompt.match(URL_IN_PROMPT)?.[0];
+ const { origin, warning } = url ? classifyOrigin(url, true) : {};
+ const source: InputHandoffSource = {
+ app: program,
+ ...(origin ? { origin } : {}),
+ ...(warning ? { warning } : {}),
+ };
+ // ssh asks to trust an unknown host key with a typed yes/no (or the fingerprint); it is not a secret.
+ const confirm = /\(yes\/no(\/\[fingerprint\])?\)\??\s*$/i.test(prompt);
+ return {
+ purpose: prompt,
+ source,
+ controls: [{
+ id: FIELD_ID,
+ kind: 'text',
+ label: '',
+ contentType: confirm ? 'text' : contentTypeFor(prompt, program),
+ ...(confirm ? { placeholder: 'yes / no' } : {}),
+ }],
+ };
+}
+
+export interface TerminalPromptSessionOptions {
+ requestId: string;
+ prompt: string;
+ program: TerminalProgram;
+ command: string;
+ requester?: string;
+ timeoutMs: number;
+ remoteInput: boolean;
+ publish(snapshot: InputHandoffSnapshot): void;
+ finish(result: HandoffResult): void;
+ /** Delivers the answer to the waiting program; null makes it fail. Called once. */
+ answer(value: string | null): void;
+}
+
+function sameHolder(a: InputHandoffHolder, b: InputHandoffHolder): boolean {
+ return a.local === true ? b.local === true : b.local !== true && a.deviceId === b.deviceId;
+}
+
+export class TerminalPromptSession {
+ private revision = 0;
+ private unheldClaimFrom: number | null = null;
+ private phase: InputHandoffPhase = 'ready';
+ private holder: InputHandoffHolder | undefined;
+ private answeredOn: InputHandoffHolder | undefined;
+ private answered = false;
+ private failure: HandoffResult['failure'];
+ private ended = false;
+ private expiryTimer: ReturnType<typeof setTimeout> | undefined;
+ private readonly step: TerminalPromptStep;
+
+ constructor(private readonly options: TerminalPromptSessionOptions) {
+ this.step = buildTerminalPromptStep(options.prompt, options.program);
+ }
+
+ get requestId(): string {
+ return this.options.requestId;
+ }
+
+ snapshot(): InputHandoffSnapshot {
+ return {
+ kind: 'input_handoff',
+ requestId: this.options.requestId,
+ revision: this.revision,
+ phase: this.phase,
+ purpose: this.step.purpose,
+ ...(this.holder ? { holder: { ...this.holder } } : {}),
+ ...(this.options.requester ? { requester: this.options.requester } : {}),
+ command: this.options.command,
+ source: this.step.source,
+ stepNumber: 1,
+ controls: this.phase === 'ready' ? this.step.controls : [],
+ ...(this.failure ? { failure: this.failure } : {}),
+ ...(this.options.remoteInput && !this.ended ? { remoteInput: true as const } : {}),
+ ...(this.ended ? { terminal: true as const } : {}),
+ };
+ }
+
+ isActionable(revision: number): boolean {
+ return !this.ended && this.phase === 'ready' && this.acceptsRevision(revision);
+ }
+
+ /** The current revision, or the one just before this screen was taken while nobody held it (see `decide`). */
+ private acceptsRevision(revision: number): boolean {
+ return revision === this.revision || (this.unheldClaimFrom !== null && revision === this.unheldClaimFrom && this.revision === revision + 1);
+ }
+
+ async start(): Promise<void> {
+ this.publish('ready');
+ this.expiryTimer = setTimeout(() => this.end('expired', 'timeout', 'timeout'), this.options.timeoutMs);
+ this.expiryTimer.unref?.();
+ }
+
+ async submit(submission: InputHandoffSubmission, actor?: InputHandoffHolder): Promise<boolean> {
+ if (!this.isActionable(submission.expectedRevision)) return false;
+ // The revision before a quiet claim is good only for the device that claimed.
+ if (submission.expectedRevision !== this.revision && !(actor && this.holder && sameHolder(actor, this.holder))) return false;
+ if (!validateInputHandoffSubmissionForStep({ ...this.snapshot(), revision: submission.expectedRevision }, submission)) return false;
+ let value: string | undefined;
+ try {
+ value = submission.values[FIELD_ID];
+ if (typeof value !== 'string' || submission.action.kind !== 'submit') return false;
+ this.answeredOn = actor ?? { local: true };
+ this.deliver(value);
+ } finally {
+ for (const key of Object.keys(submission.values)) delete submission.values[key];
+ value = undefined;
+ }
+ this.end('succeeded', 'owner');
+ return true;
+ }
+
+ async decide(decision: InputHandoffDecision, actor?: InputHandoffHolder): Promise<boolean> {
+ if (this.ended || decision.expectedRevision !== this.revision) return false;
+ switch (decision.action) {
+ case 'cancel':
+ case 'done':
+ this.end('cancelled', 'cancelled');
+ return true;
+ case 'claim': {
+ if (!actor) return false;
+ if (this.holder && sameHolder(this.holder, actor)) return true;
+ const unheld = this.holder ? null : this.revision;
+ this.holder = actor;
+ this.publish(this.phase);
+ this.unheldClaimFrom = unheld;
+ return true;
+ }
+ case 'refresh':
+ this.publish(this.phase);
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ cancel(reason: HandoffEndReason = 'cancelled'): void {
+ this.end('cancelled', reason);
+ }
+
+ /** The asking program went away (finished, killed or timed out on its side). */
+ abandon(): void {
+ this.answered = true;
+ this.end('failed', 'failure', 'target_gone');
+ }
+
+ private deliver(value: string | null): void {
+ if (this.answered) return;
+ this.answered = true;
+ this.options.answer(value);
+ }
+
+ private publish(phase: InputHandoffPhase): void {
+ this.phase = phase;
+ this.revision++;
+ this.options.publish(this.snapshot());
+ }
+
+ private end(status: HandoffResult['status'], reason: HandoffEndReason, failure?: HandoffResult['failure']): void {
+ if (this.ended) return;
+ this.ended = true;
+ if (this.expiryTimer) clearTimeout(this.expiryTimer);
+ this.failure = failure;
+ this.deliver(null);
+ const phase: InputHandoffPhase = status === 'succeeded' ? 'succeeded' : status === 'expired' ? 'expired'
+ : status === 'cancelled' ? 'cancelled' : 'failed';
+ this.publish(phase);
+ this.options.finish({
+ status,
+ reason,
+ steps: status === 'succeeded' ? 1 : 0,
+ ...(failure ? { failure } : {}),
+ finalApp: this.options.program,
+ ...(this.step.source.origin ? { finalOrigin: this.step.source.origin } : {}),
+ ...(this.answeredOn ? { answeredOn: { ...this.answeredOn } } : {}),
+ });
+ }
+}
diff --git a/apps/desktop/src/main/input-handoff/types.ts b/apps/desktop/src/main/input-handoff/types.ts
new file mode 100644
index 0000000000..69365fb120
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/types.ts
@@ -0,0 +1,128 @@
+import type { InputHandoffControl, InputHandoffOption } from '@cindy/device-link';
+
+/**
+ * Host-side shapes for 代输入. Native nodes come from the macOS AX helper
+ * (`macos-input.swift --handoff`); they never contain text-field values.
+ */
+
+/**
+ * Everything the Host reads on a step. Only text fields and their errors are
+ * ever shown to the owner; the rest tells steps apart and finds the page's
+ * main button.
+ */
+export type ScreenControl =
+ | InputHandoffControl
+ | { id: string; kind: 'button'; label: string; primary?: true; link?: true }
+ | { id: string; kind: 'choice'; label: string; options: InputHandoffOption[]; selected?: string }
+ | { id: string; kind: 'toggle'; label: string; checked: boolean }
+ | { id: string; kind: 'note'; text: string; tone: 'heading' | 'info' };
+
+export interface NativeAxNode {
+ ref: string;
+ role: string;
+ subrole?: string;
+ depth: number;
+ /** Structure-and-label identity checked again before acting. */
+ fp: string;
+ title?: string;
+ desc?: string;
+ placeholder?: string;
+ help?: string;
+ domId?: string;
+ titleElement?: string;
+ /** Static text, heading text or the selected title of a pop-up. Never a text-field value. */
+ value?: string;
+ enabled?: boolean;
+ focused?: boolean;
+ required?: boolean;
+ frame?: number[];
+ alert?: boolean;
+ secure?: boolean;
+ hasValue?: boolean;
+ checked?: boolean;
+ url?: string;
+ options?: string[];
+ expanded?: boolean;
+}
+
+export interface NativeWindowRef {
+ index: number;
+ title: string;
+}
+
+export interface NativeAxSnapshot {
+ pid: number;
+ app: string;
+ bundleId: string;
+ frontmost: boolean;
+ window: NativeWindowRef & { frame: number[]; modal?: boolean };
+ nodes: NativeAxNode[];
+ truncated?: boolean;
+ secureFocused?: boolean;
+}
+
+export interface NativeWindowList {
+ frontmost: number;
+ apps: Array<{
+ pid: number;
+ app: string;
+ bundleId: string;
+ windows: Array<NativeWindowRef & { frame: number[]; focused: boolean; minimized: boolean }>;
+ }>;
+}
+
+export type NativeActKind = 'press' | 'text' | 'key';
+
+export interface NativeActRequest {
+ pid: number;
+ window: NativeWindowRef;
+ ref: string;
+ fp: string;
+ kind: NativeActKind;
+ /** Owner value for `text` / key name for `key`. Sent on stdin only. */
+ value?: string;
+}
+
+export type NativeActResult =
+ | { ok: true; method?: string; unverified?: boolean }
+ | { ok?: false; error: string };
+
+/**
+ * Where the Host acts on the target: the owner's text fields, and the page's
+ * main button it presses to confirm. Kept in Main only; never projected.
+ */
+export type ControlBinding =
+ | { kind: 'press'; ref: string; fp: string }
+ | { kind: 'text'; ref: string; fp: string; secure: boolean };
+
+/** One step photographed for the owner. In memory only; never written to disk. */
+export interface WindowCapture {
+ jpeg: Buffer;
+ width: number;
+ height: number;
+ /** Photographed area in screen points (x, y, w, h): the window, clipped to its display. */
+ area: number[];
+ /** The whole window's frame when photographed; input is refused once it moves. */
+ windowFrame: number[];
+}
+
+/** `locked`: the screen is locked; nothing was photographed. */
+export type WindowCaptureError = 'permission' | 'unavailable' | 'target_gone' | 'locked';
+
+/** A QR code in the target window: the code cut out of it, and what it says. In memory only. */
+export interface FoundQr {
+ capture: WindowCapture;
+ text: string;
+}
+
+/** Owner input on a screenshot step. Values travel on stdin only. */
+export type PointerRequest =
+ | { kind: 'tap'; pid: number; window: NativeWindowRef; windowFrame: number[]; area: number[]; point: [number, number] }
+ | { kind: 'type'; pid: number; window: NativeWindowRef; windowFrame: number[]; value: string; submit: boolean; secure: boolean };
+
+export interface HandoffTarget {
+ pid: number;
+ app: string;
+ bundleId: string;
+ window: NativeWindowRef;
+}
diff --git a/apps/desktop/src/main/input-handoff/windowCapture.ts b/apps/desktop/src/main/input-handoff/windowCapture.ts
new file mode 100644
index 0000000000..4101569cf6
--- /dev/null
+++ b/apps/desktop/src/main/input-handoff/windowCapture.ts
@@ -0,0 +1,149 @@
+import { nativeImage, screen, systemPreferences, type NativeImage } from 'electron';
+import { photographMacWindow } from '../remote-desktop/nativeCapture.js';
+import { INPUT_HANDOFF_PICTURE_MAX_BYTES } from '@cindy/device-link';
+import type { FoundQr, WindowCapture, WindowCaptureError } from './types.js';
+
+/** Longest side sent to the owner: legible on a phone, small enough for one sealed offer. */
+const MAX_SIDE = 1400;
+const QUALITIES = [72, 60, 48, 38];
+
+interface Rect {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+}
+
+/** Largest JPEG that fits the offer budget, shrinking the picture only when quality alone is not enough. */
+export function fitJpeg(image: NativeImage): { jpeg: Buffer; width: number; height: number } | null {
+ let current = image;
+ const size = current.getSize();
+ if (Math.max(size.width, size.height) > MAX_SIDE) {
+ current = size.width >= size.height
+ ? current.resize({ width: MAX_SIDE, quality: 'good' })
+ : current.resize({ height: MAX_SIDE, quality: 'good' });
+ }
+ for (let attempt = 0; attempt < 3; attempt++) {
+ for (const quality of QUALITIES) {
+ const jpeg = current.toJPEG(quality);
+ if (jpeg.length <= INPUT_HANDOFF_PICTURE_MAX_BYTES) {
+ const { width, height } = current.getSize();
+ return { jpeg, width, height };
+ }
+ jpeg.fill(0);
+ }
+ const { width } = current.getSize();
+ current = current.resize({ width: Math.max(320, Math.round(width * 0.7)), quality: 'good' });
+ }
+ return null;
+}
+
+/**
+ * Photographs one window by its window-server id, in memory: its own pixels,
+ * never whatever covers it, and never the rest of the display. Nothing is
+ * written to disk.
+ */
+async function photographWindow(
+ frame: number[],
+ windowId: number,
+): Promise<{ image: NativeImage; area: number[] } | { error: WindowCaptureError }> {
+ if (process.platform === 'darwin' && systemPreferences.getMediaAccessStatus('screen') !== 'granted')
+ return { error: 'permission' };
+ const [x, y, w, h] = frame;
+ if (!(w >= 8 && h >= 8)) return { error: 'unavailable' };
+ const display = screen.getDisplayMatching({ x, y, width: w, height: h });
+ const jpeg = await photographMacWindow(String(display.id), windowId).catch(() => null);
+ if (!jpeg) return { error: 'unavailable' };
+ const image = nativeImage.createFromBuffer(jpeg);
+ jpeg.fill(0);
+ if (image.isEmpty()) return { error: 'unavailable' };
+ // The picture fills the whole window, so a point in it is the same fraction of the window.
+ return { image, area: [...frame] };
+}
+
+export async function captureWindowArea(
+ frame: number[],
+ windowId: number,
+): Promise<WindowCapture | { error: WindowCaptureError }> {
+ const shot = await photographWindow(frame, windowId);
+ if ('error' in shot) return shot;
+ const fitted = fitJpeg(shot.image);
+ if (!fitted) return { error: 'unavailable' };
+ return { ...fitted, area: shot.area, windowFrame: [...frame] };
+}
+
+/** A QR code found in a picture: its content and place, as fractions (x, y, w, h) with a top-left origin. */
+export interface DetectedQr {
+ text: string;
+ box: number[];
+}
+
+/** Longest side of the code sent to the owner: crisp enough to scan from another screen or a saved photo. */
+const QR_MAX_SIDE = 720;
+
+/**
+ * Where to cut the code out of the window: its box plus a quiet zone around
+ * it (scanners need one), in picture pixels, kept inside the picture.
+ */
+export function qrCrop(box: number[], size: { width: number; height: number }): Rect | null {
+ const [bx, by, bw, bh] = box;
+ if (![bx, by, bw, bh].every((n) => Number.isFinite(n)) || bw <= 0 || bh <= 0) return null;
+ const margin = Math.max(bw * size.width, bh * size.height) * 0.12;
+ const left = Math.max(0, Math.floor(bx * size.width - margin));
+ const top = Math.max(0, Math.floor(by * size.height - margin));
+ const right = Math.min(size.width, Math.ceil((bx + bw) * size.width + margin));
+ const bottom = Math.min(size.height, Math.ceil((by + bh) * size.height + margin));
+ if (right - left < 16 || bottom - top < 16) return null;
+ return { x: left, y: top, width: right - left, height: bottom - top };
+}
+
+/** The code the owner should scan: the largest one in the window. */
+export function pickQr(codes: DetectedQr[]): DetectedQr | null {
+ let best: DetectedQr | null = null;
+ for (const code of codes) {
+ if (!best || code.box[2] * code.box[3] > best.box[2] * best.box[3]) best = code;
+ }
+ return best;
+}
+
+/**
+ * Looks for a QR code in one window (scan-to-sign-in). Returns the code cut
+ * out of the window with its content, null when there is none. The window
+ * photo stays in memory; `detect` reads it from a pipe.
+ */
+export async function captureWindowQr(
+ frame: number[],
+ windowId: number,
+ detect: (jpeg: Buffer) => Promise<DetectedQr[] | null>,
+): Promise<FoundQr | null | { error: WindowCaptureError }> {
+ const shot = await photographWindow(frame, windowId);
+ if ('error' in shot) return shot;
+ const scan = shot.image.toJPEG(90);
+ let codes: DetectedQr[] | null;
+ try {
+ codes = await detect(scan);
+ } finally {
+ scan.fill(0);
+ }
+ // The detector could not look: say so, so a waiting code is not taken as scanned.
+ if (!codes) return { error: 'unavailable' };
+ const code = pickQr(codes);
+ if (!code) return null;
+ const size = shot.image.getSize();
+ const cut = qrCrop(code.box, size);
+ if (!cut) return null;
+ let image = shot.image.crop(cut);
+ if (Math.max(cut.width, cut.height) > QR_MAX_SIDE) image = image.resize({ width: QR_MAX_SIDE, quality: 'good' });
+ const fitted = fitJpeg(image);
+ if (!fitted) return null;
+ const [x, y, w, h] = shot.area;
+ return {
+ text: code.text,
+ capture: {
+ ...fitted,
+ // Taps on the code (for example "tap to refresh" on an expired one) land on the code in the window.
+ area: [x + (cut.x / size.width) * w, y + (cut.y / size.height) * h, (cut.width / size.width) * w, (cut.height / size.height) * h],
+ windowFrame: [...frame],
+ },
+ };
+}
diff --git a/apps/desktop/src/main/maker-host/pi-host.ts b/apps/desktop/src/main/maker-host/pi-host.ts
index a6d7b01f68..09c11dcd58 100644
--- a/apps/desktop/src/main/maker-host/pi-host.ts
+++ b/apps/desktop/src/main/maker-host/pi-host.ts
@@ -33,6 +33,7 @@ import { app } from 'electron';
import { readModelContextLimit } from './model-context-limit-store.js';
import { toolchainThreadCapEnv } from './toolchain-thread-cap.js';
+import { inputHandoffTaskShellEnv } from '../input-handoff/askpass/index.js';
import {
PiAgent,
@@ -859,6 +860,8 @@ function buildDesktopPiRuntimeConfig(): AgentRuntimeConfig {
const ripgrepPath = getRipgrepBinaryPath();
const config: AgentRuntimeConfig = {
behaviorFlags: (ctx) => ctx.spawnMode === 'remote' ? {} : toolchainThreadCapEnv(),
+ // 代输入: sudo / ssh / git password prompts of this task go to the owner.
+ taskShellEnv: inputHandoffTaskShellEnv,
// 保留 host 共用身份段,再追加 Pi 专属行为段;maker-core 会整体追加到 Pi 原生 prompt。
systemPrompt: composePiSystemPrompt(hostSystemPrompt, piSystemPrompt),
// Pi 的 grep 以及 Cindy 覆盖的 find 都固定复用随 Desktop 校验、打包的 rg。
diff --git a/apps/desktop/src/main/maker-host/runtime-configs.ts b/apps/desktop/src/main/maker-host/runtime-configs.ts
index 5c7f880093..eb68830d2c 100644
--- a/apps/desktop/src/main/maker-host/runtime-configs.ts
+++ b/apps/desktop/src/main/maker-host/runtime-configs.ts
@@ -29,6 +29,7 @@ import { readMemorySettings } from './memory-settings-store.js';
import { readSubagentModelSettings } from './subagent-model-settings-store.js';
import { shouldKeepSubagentOverrideForParent } from './subagent-override-route.js';
import { toolchainThreadCapEnv } from './toolchain-thread-cap.js';
+import { inputHandoffTaskShellEnv } from '../input-handoff/askpass/index.js';
import {
assessModelSwitchContext,
shouldHandoffAfterContextAssessment,
@@ -180,6 +181,8 @@ export function buildDesktopClaudeRuntimeConfig(endpointFn: () => string): Agent
// 核数算,远端机器的资源不归本设置管。设置关闭时为空对象,零影响。
...(ctx.spawnMode === 'remote' ? {} : toolchainThreadCapEnv()),
}),
+ // 代输入: sudo / ssh / git password prompts of this task go to the owner.
+ taskShellEnv: inputHandoffTaskShellEnv,
// 产品身份 + Skill 来源优先级 + Claude 专属段,按顺序拼接后给 maker-core append。
systemPrompt: composeHostPrompt(claudeSystemPrompt),
// Maker Memory 需要的 user-data 绝对路径 (maker-core 没 Electron 依赖, 必须 host 注入)。
@@ -300,6 +303,8 @@ export const desktopCodexRuntimeConfig: AgentRuntimeConfig = {
// 附近注释),所以这里仍按 spawnMode 分流让代码自证,不依赖"远端不走本函数"
// 这种会过期的假设(对抗式预审发现)。
behaviorFlags: (ctx) => (ctx.spawnMode === 'remote' ? {} : toolchainThreadCapEnv()),
+ // 代输入: sudo / ssh / git password prompts of this task go to the owner.
+ taskShellEnv: inputHandoffTaskShellEnv,
// 产品身份 + Skill 来源优先级 + Codex 专属段。
systemPrompt: composeHostPrompt(codexSystemPrompt),
// lazy getter(与 endpoint/memoryEnabled 同一惯用法,issue #1956):import 期
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 63e2282a1d..33f6588fc9 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -182,7 +182,7 @@ import { isRetainableProjectSession } from '../../shared/sessionSource.js';
import { initializePluginOauthCards } from '../plugin-oauth/cards.js';
import { currentOauthIdentityScope, loadOauthSigningKey } from '../plugin-oauth/desktopIdentity.js';
import { readDeviceLinkSettings, readLastKnownDeviceNames } from '../device-link/settings-store.js';
-import { getDeviceLinkStatus, getMobileNotifyGeneration, sendMobileBotGroupNotify } from '../device-link/index.js';
+import { getDeviceLinkStatus, getMobileNotifyGeneration, sendMobileBotGroupNotify, sendMobileSessionNotify } from '../device-link/index.js';
import type { AgentMeta, Session as RendererSession } from '../../renderer/lib/ccAgent.types';
import {
deriveAutoTitleSeed,
@@ -219,6 +219,8 @@ import {
type GhostGrantConfirmInteractionSnapshot,
} from '../cindy-brain/ghostGrantConfirmBridge.js';
import { createFeishuDesktopConfirmNotifier } from '../im/desktopConfirmNoticeWiring.js';
+import { buildInputHandoffNoticeText } from '../im/desktopConfirmNotice.js';
+import { sendInputHandoffChannelNotice } from '../im/shared/inputHandoffChannelNotice.js';
import { bindingStore } from '../im/binding.js';
import { isHeadlessGhostSetupTurn } from '../mcp-integrations/ghostSetupInteractionSurface.js';
import {
@@ -563,7 +565,9 @@ import { withChatServer } from './chatServer.js';
import { createBotGroupPlanDecider } from './botGroupPlanDecider.js';
import { botGroupMembersVisibleRemotely, registerBotGroupRemoteResourceProvider } from './botGroupRemoteResourceProvider.js';
import { broadcastBotGroupRemoteResourceChanged } from './botGroupRemoteResourceInvalidation.js';
-import { getBotGroupStepNotificationBody } from '../sessionNotificationCopy.js';
+import { getBotGroupStepNotificationBody, getInputHandoffNotificationBody } from '../sessionNotificationCopy.js';
+import { readSessionTitle } from '../im/shared/controlProjects.js';
+import { readSessionNotificationPreview } from '../localDb/sessionNotificationPreview.js';
import { createBotGroupWorkDir } from './botGroupWorkDir.js';
import { createBotGroupAttachmentStore } from './botGroupAttachments.js';
import { requestUtilityText } from '../utility-model/oneShotCandidates.js';
@@ -950,6 +954,13 @@ import {
import { createOrcaRemoteWorkers, isExecutionDeviceCandidate, type OrcaRemoteWorkers } from './orcaRemoteWorkers.js';
import { getReceivedShares, providerShareAgentDeviceId } from '../device-link/providerShareGuest.js';
import { ORCA_EXECUTION_DEVICES_CHANNEL } from '@cindy/device-link';
+import { INPUT_HANDOFF_LOCAL_CHANNEL, INPUT_HANDOFF_LOCAL_PICTURE_CHANNEL, type InputHandoffHolder, type InputHandoffSnapshot } from '@cindy/device-link';
+import { getInputHandoffService, initInputHandoffService } from '../input-handoff/service.js';
+import { closeInputHandoffAskpass, initInputHandoffAskpass } from '../input-handoff/askpass/index.js';
+import { onQuit } from '../lifecycle.js';
+import { isInputHandoffDisabledForSession } from '../input-handoff/botPolicy.js';
+import { createMacHandoffDriver } from '../input-handoff/macDriver.js';
+import { supportsRemotePluginOauth } from '../plugin-oauth/runtime.js';
import {
parseOrcaRemoteLead,
serializeOrcaRemoteLead,
@@ -2931,6 +2942,118 @@ const ghostSetupInteractionBridge = initGhostSetupInteractionBridge({
logger: log,
});
+/**
+ * 代输入 (input handoff). Like Desktop-only confirmations these are Host-owned
+ * waits: they never block a later user turn and are not turn-idle zombies.
+ * Broadcasts carry step structure only; owner values never leave the
+ * trusted local channel or the signed v3 exchange.
+ */
+const inputHandoffImNotified = new Set<string>();
+/** Who is answering: this Desktop, or the server-verified controller device. */
+function inputHandoffActor(): InputHandoffHolder {
+ const context = getDeviceLinkInvokeContext();
+ if (!context) return { local: true };
+ return { deviceId: context.controllerDeviceId };
+}
+function describeInputHandoffDevice(deviceId: string): Omit<InputHandoffHolder, 'local' | 'deviceId'> {
+ const source = readDeviceLinkInvokeSourceDevice();
+ const name = (source?.deviceId === deviceId ? source.name : undefined) ?? readLastKnownDeviceNames()[deviceId];
+ return {
+ ...(name ? { name: name.slice(0, 60) } : {}),
+ ...(source?.deviceId === deviceId ? { platform: source.platform } : {}),
+ };
+}
+const inputHandoffImNotifier = createFeishuDesktopConfirmNotifier(buildInputHandoffNoticeText);
+/**
+ * Tell the owner a screen is waiting, wherever they are. The phone push is
+ * sent from main (not the renderer) so an unattended desktop with Cindy
+ * focused still alerts, and each new screen alerts again. The body is fixed
+ * copy: no screen contents, no purpose text, never a value.
+ */
+function notifyInputHandoffOwner(sessionId: string, snapshot: InputHandoffSnapshot): void {
+ const generation = getMobileNotifyGeneration();
+ void (async () => {
+ try {
+ const [title, preview] = await Promise.all([
+ readSessionTitle(sessionId),
+ readSessionNotificationPreview(sessionId, false).catch(() => undefined),
+ ]);
+ // An IM-driven task gets one text pointer per request, not one per screen.
+ if (!inputHandoffImNotified.has(snapshot.requestId)) {
+ inputHandoffImNotified.add(snapshot.requestId);
+ // Channel-driven tasks get it in their chat; a desktop task taken over from Feishu (/ctr) by its binding.
+ if (!sendInputHandoffChannelNotice(sessionId, buildInputHandoffNoticeText(title), log))
+ inputHandoffImNotifier(sessionId, title);
+ }
+ sendMobileSessionNotify({
+ sessionId,
+ title: preview?.teammateName ?? title,
+ kind: 'needs-reply',
+ fallbackBody: getInputHandoffNotificationBody(),
+ eventId: `input-handoff:${snapshot.requestId}:${snapshot.stepNumber}`,
+ generation,
+ ...(preview?.teammateBotId ? { teammateBotId: preview.teammateBotId } : {}),
+ ...(preview?.teammateAvatar ? { teammateAvatar: preview.teammateAvatar } : {}),
+ });
+ } catch (err) {
+ log.warn('[input-handoff] owner push failed (non-fatal)', err);
+ }
+ })();
+}
+let inputHandoffContinuation:
+ | ((sessionId: string, requestId: string, message: string) => Promise<void>)
+ | null = null;
+initInputHandoffService({
+ broadcast: (channel, payload) => {
+ broadcastToAllWindows(channel, payload);
+ const value = payload as { sessionId?: unknown; requestId?: unknown; request?: InputHandoffSnapshot };
+ if (typeof value.sessionId !== 'string') return;
+ if (channel === MAKER_PUSH.INTERACTION_REQUEST && value.request?.kind === 'input_handoff') {
+ if (!shouldNotifyAgentIslandForSession(value.sessionId)) return;
+ if (value.request.terminal === true) {
+ getAgentIslandService()?.handleInteractionDismissed(value.sessionId, value.request.requestId);
+ return;
+ }
+ getAgentIslandService()?.handlePluginSetupInteraction(
+ value.sessionId,
+ value.request.requestId,
+ value.request.purpose,
+ 'input_handoff',
+ );
+ return;
+ }
+ if (channel === MAKER_PUSH.INTERACTION_DISMISSED && typeof value.requestId === 'string') {
+ getAgentIslandService()?.handleInteractionDismissed(value.sessionId, value.requestId);
+ }
+ },
+ createDriver: () => (process.platform === 'darwin' ? createMacHandoffDriver() : null),
+ hostPid: process.pid,
+ remoteInputAvailable: supportsRemotePluginOauth,
+ // A live view of just the window rides remote desktop, so only where the owner allowed it.
+ liveViewAvailable: () => {
+ if (process.platform !== 'darwin') return false;
+ const settings = readDeviceLinkSettings();
+ return settings.remoteControlEnabled && settings.remoteDesktopEnabled;
+ },
+ notifyOwner: (sessionId, snapshot) => notifyInputHandoffOwner(sessionId, snapshot),
+ describeDevice: describeInputHandoffDevice,
+ onClosed: (_sessionId, requestId) => {
+ inputHandoffImNotified.delete(requestId);
+ },
+ continueAgent: async (sessionId, requestId, message) => {
+ if (!inputHandoffContinuation) throw new Error('INPUT_HANDOFF_CONTINUATION_UNAVAILABLE');
+ await inputHandoffContinuation(sessionId, requestId, message);
+ },
+ logger: log,
+});
+// sudo / ssh / git password prompts in the owner's local tasks become one-step 代输入 cards.
+initInputHandoffAskpass({
+ startTerminalPrompt: (request) => getInputHandoffService()?.startTerminalPrompt(request) ?? { ok: false },
+ isDisabledForSession: isInputHandoffDisabledForSession,
+ logger: log,
+});
+onQuit('input-handoff-askpass', closeInputHandoffAskpass, 'async');
+
initGhostSetupCoordinator({
getTargetToken: ghostInstallMutationTargetFor,
remoteConnection: true,
@@ -2994,6 +3117,7 @@ initializePluginOauthCards({
loadKey: loadOauthSigningKey,
bridge: ghostSetupInteractionBridge,
bots: getBotAuthorizationService,
+ inputHandoff: getInputHandoffService,
owner: () => currentOauthIdentityScope() ? activeOwnerScopeKey() : null,
available: peer => {
const settings = readDeviceLinkSettings();
@@ -3058,7 +3182,8 @@ type RecoverableInteractionSnapshot =
| GhostSetupInteractionSnapshot
| IssueConfirmInteractionSnapshot
| RenameSessionsConfirmInteractionSnapshot
- | GhostGrantConfirmInteractionSnapshot;
+ | GhostGrantConfirmInteractionSnapshot
+ | InputHandoffSnapshot;
type PendingInteractionSnapshotEntry = {
request: RecoverableInteractionSnapshot;
@@ -3085,6 +3210,7 @@ function getPendingInteractionsForSession(sessionId: string): PendingInteraction
.map(({ request }) => ({ request })),
...ghostGrantConfirmBridge.pendingSnapshots(sessionId).map(({ request }) => ({ request })),
...ghostSetupInteractionBridge.pendingSnapshots(sessionId).map(({ request }) => ({ request })),
+ ...(getInputHandoffService()?.pendingSnapshots(sessionId) ?? []).map(({ request }) => ({ request })),
);
return out;
}
@@ -3343,6 +3469,8 @@ function cleanupPendingInteractionsForSession(sessionId: string, reason: string)
sessionId,
reason === 'session_closed' ? 'session_closed' : 'session_aborted',
);
+ // 代输入 follows the same real close/abort boundary; silent, no continuation.
+ getInputHandoffService()?.cleanupForSession(sessionId);
// fs 槽 workdir 写确认的会话级记忆只在会话真正关闭时清(防 Set 无界增长)。
// 本函数在 session_aborted(用户点停止)等瞬态也会被调,那些场景确认卡该收、
// 但"同目录本会话免弹"的记忆要保住——否则用户每
@@ -11397,6 +11525,19 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
setBotInvitationWelcomeDispatch(dispatchBotSessionMessage);
+ // 代输入 ended: hidden metadata-only continuation, mirroring the bot
+ // authorization resume. A deterministic client id keeps delivery idempotent.
+ inputHandoffContinuation = async (sessionId, requestId, message) => {
+ await inputCoordinator.ensureQueueRestored(sessionId).catch(() => undefined);
+ const result = await dispatchBotSessionMessage({
+ targetSessionId: sessionId,
+ message,
+ persistedContent: `${UI_ACTION_TRIGGER_PREFIX}${message}`,
+ clientId: `input-handoff-result:${requestId}`,
+ });
+ if (!result.ok) throw new Error(`Input handoff continuation not accepted: ${result.errorCode}`);
+ };
+
initializeBotAuthorizationHost(async (card, validate, assertAuthorizationCurrent) => {
await inputCoordinator.ensureQueueRestored(card.sessionId);
const generation = inputCoordinator.getGeneration(card.sessionId);
@@ -19549,6 +19690,9 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
return { accepted: true };
}
if (await getBotAuthorizationService()?.resolve(requestId, decision, pluginSetupResponseTarget)) return { accepted: true };
+ // 代输入: value-less decisions only (hand back / cancel / stay / refresh).
+ // Values never use this generic channel; see INPUT_HANDOFF_LOCAL_CHANNEL.
+ if (!sharedTask && getInputHandoffService()?.resolve(requestId, decision, inputHandoffActor())) return { accepted: true };
log.warn('resolve-interaction: no pending resolver (likely already dismissed/timed out)', {
requestId,
});
@@ -19569,10 +19713,34 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
// 快照:打开/重连/刷新会话时,renderer 拉当前挂起交互重建面板(本机 + device-link 远程共用)。
ipcMain.handle(MAKER_INVOKE.GET_PENDING_INTERACTIONS, (_e, sessionId: unknown) => {
if (typeof sessionId !== 'string' || !sessionId) return [];
- const pending = getPendingInteractionsForSession(sessionId);
+ let pending = getPendingInteractionsForSession(sessionId);
+ // Shared-task guests never see the owner's input handoff.
+ if (getDeviceLinkInvokeContext()?.sharedTask)
+ pending = pending.filter(({ request }) => request.kind !== 'input_handoff');
return projectPendingInteractionsForRemote(pending, isDeviceLinkInvoke());
});
+ /**
+ * 代输入 values: Cindy's own trusted top-level renderer only. Never on the
+ * device-link allowlist; remote devices use the signed v3 exchange instead.
+ * The payload is never logged, persisted or echoed back.
+ */
+ ipcMain.handle(INPUT_HANDOFF_LOCAL_CHANNEL, async (event, requestId: unknown, submission: unknown) => {
+ if (isDeviceLinkInvoke()) throwIpcError('PERMISSION_DENIED', 'input handoff values must be entered on this Desktop');
+ assertTrustedAppRendererEvent(event);
+ if (typeof requestId !== 'string' || !requestId) throwIpcError('INVALID_PARAMS', 'requestId required');
+ return { accepted: (await getInputHandoffService()?.submit(requestId, submission)) ?? false };
+ });
+
+ /** 代输入 screenshot step on this computer: shown in Cindy's own window only, never pushed or stored. */
+ ipcMain.handle(INPUT_HANDOFF_LOCAL_PICTURE_CHANNEL, (event, requestId: unknown, revision: unknown) => {
+ if (isDeviceLinkInvoke()) throwIpcError('PERMISSION_DENIED', 'input handoff pictures stay on this Desktop');
+ assertTrustedAppRendererEvent(event);
+ if (typeof requestId !== 'string' || !requestId || !Number.isSafeInteger(revision))
+ throwIpcError('INVALID_PARAMS', 'requestId and revision required');
+ return getInputHandoffService()?.picture(requestId, revision as number) ?? null;
+ });
+
// ── 运行时切换 (Stage 2 B) ───────────────────────────────────────────────
// session 不存在(被 close / 还没 send 创建出来)就 no-op 不报错, 让 renderer
// 可以乐观调用 (UI 更新先行, IPC 失败也不会回滚 UI, 老 agentManager 同语义)。
diff --git a/apps/desktop/src/main/mcp-integrations/browser.ts b/apps/desktop/src/main/mcp-integrations/browser.ts
index 9b59f8da62..c18efcf24e 100644
--- a/apps/desktop/src/main/mcp-integrations/browser.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser.ts
@@ -63,6 +63,7 @@ import {
import { assertTrustedAppRendererEvent } from '../security/trustedAppRenderer.js';
import { createBrowserBackendIpcHandlers } from './browser-backend/settings-ipc.js';
import { raiseAgentBrowserWindow } from './raise-agent-browser-window.js';
+import { hasSecretPages, isSecretPage } from '../input-handoff/secretTaint.js';
import {
BrowserOpenForLoginError,
browserOpenForLoginErrorCodeFromData,
@@ -450,6 +451,7 @@ export function getBrowserMcpDeps(): {
logger: typeof logger;
getUserRecipes(): Promise<UserRecipesResult>;
saveUserRecipe(input: Parameters<typeof writeUserRecipe>[0]): Promise<WriteUserRecipeResult>;
+ pageReadsRestricted(target: { profile?: string; targetId?: string }): Promise<boolean>;
} {
return {
setBackend: async (kind) => {
@@ -467,6 +469,17 @@ export function getBrowserMcpDeps(): {
getRuntime: () => backendController,
supportsResourceDownloads: () => backendController.kind === 'rsb-webview',
supportsSemanticQueries: () => backendController.kind === 'rsb-webview',
+ // 代输入: pause page-state reads on a tab still showing a page where the owner typed a secret.
+ pageReadsRestricted: async ({ profile, targetId }) => {
+ if (!hasSecretPages()) return false;
+ const listed = await backendController.call({ action: 'tabs', ...(profile ? { profile } : {}) });
+ if (!listed.ok) return true;
+ const tabs = (listed.data as { tabs?: Array<{ targetId?: unknown; url?: unknown }> } | undefined)?.tabs ?? [];
+ // Without a target the runtime acts on its last tab; check every tab conservatively.
+ return tabs
+ .filter((tab) => !targetId || tab.targetId === targetId)
+ .some((tab) => typeof tab.url === 'string' && isSecretPage(tab.url));
+ },
logger,
};
}
diff --git a/apps/desktop/src/main/mcp-integrations/computer.ts b/apps/desktop/src/main/mcp-integrations/computer.ts
index fc3ca745f3..481003981f 100644
--- a/apps/desktop/src/main/mcp-integrations/computer.ts
+++ b/apps/desktop/src/main/mcp-integrations/computer.ts
@@ -3754,6 +3754,8 @@ export function getComputerMcpDeps(options: ComputerMcpDepsOptions = {}): Comput
await ensureRuntime();
return callComputerDriverTool(name, args, context);
},
+ // Loaded on use: the 代输入 driver brings the native input helpers with it.
+ isSecureTarget: async (target) => (await import('../input-handoff/macDriver.js')).isSecureInputTarget(target),
logger,
};
}
diff --git a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts b/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
index 58da98adc6..cf6e279302 100644
--- a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
+++ b/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
@@ -83,10 +83,13 @@ import {
} from '../maker-ipc/botWorkbenchTools.js';
import { createTaskToolCallAuthorizer } from '../maker-ipc/taskToolCallAuthorizer.js';
import {
+ getSessionRowSnapshot,
patchSessionMetaInDb,
renameSessionTitlesInDb,
setSessionsStatusInDb,
} from '../localDb/ipc/sessions.js';
+import { getInputHandoffService } from '../input-handoff/service.js';
+import { isInputHandoffDisabledForSession } from '../input-handoff/botPolicy.js';
import { isIpcError } from '../../shared/ipc-errors.js';
import type { PluginRegistry } from '../maker-host/plugins/plugin-registry.js';
import { getDesktopContactsManager } from '../maker-host/maker-contacts-host.js';
@@ -478,6 +481,34 @@ export function createDesktopMcpProviders(deps: DesktopMcpProvidersDeps): LiziMc
appUpdate: createAgentAppUpdateCallbacks((sessionId, sessionInstanceId) =>
deps.isCurrentLocalSessionInstance?.(sessionId, sessionInstanceId) === true),
logger: createLogger('mcp/cindy_helper'),
+ // 代输入: Host-owned card; values never return through this tool.
+ inputHandoff: {
+ start: async (context, request) => {
+ if (!context.sessionId || !deps.isCurrentLocalSessionInstance?.(context.sessionId, context.sessionInstanceId))
+ return { ok: false, errorCode: 'NO_SESSION_CONTEXT', message: 'This task is no longer current.' };
+ const service = getInputHandoffService();
+ if (!service) return { ok: false, errorCode: 'CAPABILITY_NOT_AVAILABLE', message: 'Input handoff is not ready yet.' };
+ // Unknown policy (store unreadable) fails closed; a teammate switch must hold.
+ if (await isInputHandoffDisabledForSession(context.sessionId).catch(() => true))
+ return {
+ ok: false,
+ errorCode: 'DISABLED_BY_OWNER',
+ message: 'The owner turned off input handoff for this teammate. Tell the owner what is still needed instead.',
+ };
+ const row = await getSessionRowSnapshot(context.sessionId).catch(() => null);
+ const requester = row?.title?.trim().slice(0, 120);
+ const result = service.start({
+ sessionId: context.sessionId,
+ purpose: request.purpose,
+ ...(request.note ? { note: request.note } : {}),
+ ...(requester ? { requester } : {}),
+ target: request.target,
+ ...(request.completeWhen ? { completeWhen: request.completeWhen } : {}),
+ ...(request.timeoutMinutes ? { timeoutMinutes: request.timeoutMinutes } : {}),
+ });
+ return result.ok ? { ok: true, requestId: result.requestId } : result;
+ },
+ },
grokLogin: {
start: async (context) => {
if (!context.sessionId || !context.sessionInstanceId
diff --git a/apps/desktop/src/main/plugin-oauth/__tests__/inputHandoffSubmission.test.ts b/apps/desktop/src/main/plugin-oauth/__tests__/inputHandoffSubmission.test.ts
new file mode 100644
index 0000000000..1c1e81b26d
--- /dev/null
+++ b/apps/desktop/src/main/plugin-oauth/__tests__/inputHandoffSubmission.test.ts
@@ -0,0 +1,210 @@
+import { testOauthSigningKey } from './fixtures.js';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import {
+ INPUT_HANDOFF_ACTION_ID,
+ INPUT_HANDOFF_GHOST_ID,
+ inputHandoffPresentation,
+ type InputHandoffSnapshot,
+} from '@cindy/device-link';
+import { GhostSetupInteractionBridge } from '../../cindy-brain/ghostSetupInteractionBridge.js';
+import { InputHandoffService } from '../../input-handoff/service.js';
+import { fakeDesktop } from '../../input-handoff/__tests__/fakeDesktop.js';
+import { initializePluginOauthCards } from '../cards.js';
+import {
+ handleAnswerInputHandoffPicture,
+ handleOpenInputHandoffPicture,
+ handleSubmitInputHandoff,
+ type LocalOauthDeps,
+} from '../localIpc.js';
+import {
+ invalidatePluginOauth,
+ publishedPluginOauthIdentity,
+ requestPluginOauth,
+} from '../runtime.js';
+
+const cleanups: Array<() => void> = [];
+afterEach(() => {
+ cleanups.splice(0).forEach((f) => f());
+ invalidatePluginOauth();
+ vi.restoreAllMocks();
+});
+
+async function harness(remoteInput = true, pictures = false) {
+ const desktop = fakeDesktop({ pictures });
+ const snapshots: InputHandoffSnapshot[] = [];
+ const continued: string[] = [];
+ let clock = 0;
+ const service = new InputHandoffService({
+ broadcast: (_channel, payload) => {
+ const request = (payload as { request?: InputHandoffSnapshot }).request;
+ if (request) snapshots.push(request);
+ },
+ createDriver: () => desktop.driver,
+ hostPid: 1,
+ remoteInputAvailable: () => remoteInput,
+ continueAgent: async (_session, _request, message) => {
+ continued.push(message);
+ },
+ terminalRetentionMs: 0,
+ sessionTiming: { now: () => clock, sleep: async (ms) => { clock += ms; }, finishingDelayMs: 5 },
+ });
+ cleanups.push(() => service.cleanupAll());
+ initializePluginOauthCards({
+ loadKey: testOauthSigningKey,
+ bridge: new GhostSetupInteractionBridge({ broadcast: () => {} }),
+ bots: () => null,
+ inputHandoff: () => service,
+ owner: () => 'membership',
+ available: () => true,
+ identity: () => ({ deviceId: 'cloud-device', realm: 'global' as const, membershipId: 'membership' }),
+ });
+ const wire: unknown[] = [];
+ const deps: LocalOauthDeps = {
+ owner: () => 'membership',
+ assertTarget: (device) => {
+ if (device !== 'cloud-device') throw new Error('target');
+ },
+ localDeviceId: () => 'desktop',
+ openExternal: async () => {
+ throw new Error('No browser for a step form');
+ },
+ trustIdentity: async () => {},
+ identity: async () => {
+ const identity = (await publishedPluginOauthIdentity())!;
+ const observedAtMs = Date.now();
+ return {
+ ...identity,
+ deviceId: 'cloud-device',
+ realm: 'global' as const,
+ membershipId: 'membership',
+ observedAtMs,
+ expiresAtMs: observedAtMs + 60_000,
+ };
+ },
+ invoke: async (_device, _channel, args) => {
+ const result = await requestPluginOauth('desktop', args[0]);
+ wire.push({ request: args[0], result });
+ return { ok: true, result };
+ },
+ };
+ const started = service.start({ sessionId: 'task', purpose: 'Sign in to Example', target: { app: 'Example' } });
+ expect(started.ok).toBe(true);
+ const latest = () => snapshots[snapshots.length - 1];
+ await vi.waitFor(() => expect(latest()?.phase).toBe('ready'));
+ const submit = (snapshot: InputHandoffSnapshot, values: Record<string, string>) =>
+ handleSubmitInputHandoff(deps, {
+ deviceId: 'cloud-device',
+ ghostId: INPUT_HANDOFF_GHOST_ID,
+ requestId: snapshot.requestId,
+ actionId: INPUT_HANDOFF_ACTION_ID,
+ expectedRevision: snapshot.revision,
+ submission: { expectedRevision: snapshot.revision, values, action: { kind: 'submit' } },
+ presentation: inputHandoffPresentation(snapshot),
+ });
+ return { desktop, service, deps, latest, submit, wire, continued };
+}
+
+describe('代输入 over the signed per-step exchange', () => {
+ it('applies each step the owner answers from another computer, sealed end to end', async () => {
+ const h = await harness();
+ let step = h.latest();
+ expect(step.remoteInput).toBe(true);
+ const email = step.controls.find((c) => c.kind === 'text')!;
+ await expect(h.submit(step, { [email.id]: '[email protected]' })).resolves.toEqual({ accepted: true });
+ await vi.waitFor(() => expect(h.latest().stepNumber).toBe(2));
+
+ step = h.latest();
+ expect(step.source.app).toBe('Google Chrome');
+ const password = step.controls.find((c) => c.kind === 'text')!;
+ await expect(h.submit(step, { [password.id]: 'synthetic-secret' })).resolves.toEqual({ accepted: true });
+ expect(h.desktop.acts.filter((act) => act.kind === 'text').map((act) => act.value)).toEqual(['[email protected]', 'synthetic-secret']);
+ // Only sealed boxes cross the wire; the values never appear in plain payloads.
+ expect(JSON.stringify(h.wire)).not.toMatch(/owner@example|synthetic-secret/);
+ await vi.waitFor(() => expect(h.desktop.stage()).toBe('consent'));
+ });
+
+ it('reports success for a terminal password that ended the handoff when it was typed', async () => {
+ const h = await harness();
+ const answers: Array<string | null> = [];
+ const asked = h.service.startTerminalPrompt({
+ sessionId: 'other-task',
+ prompt: '[sudo] password for someone:',
+ program: 'sudo',
+ command: 'sudo -A true',
+ answer: (value) => answers.push(value),
+ });
+ expect(asked.ok).toBe(true);
+ await vi.waitFor(() => expect(h.latest()).toMatchObject({ source: { app: 'sudo' }, phase: 'ready' }));
+ const prompt = h.latest();
+ await expect(h.submit(prompt, { answer: 'synthetic-pass' })).resolves.toEqual({ accepted: true });
+ expect(answers).toEqual(['synthetic-pass']);
+ expect(JSON.stringify(h.wire)).not.toContain('synthetic-pass');
+ });
+
+ it('refuses an answer for a screen that has already moved on', async () => {
+ const h = await harness();
+ const first = h.latest();
+ const email = first.controls.find((c) => c.kind === 'text')!;
+ await h.submit(first, { [email.id]: '[email protected]' });
+ await vi.waitFor(() => expect(h.latest().stepNumber).toBe(2));
+ await expect(h.submit(first, { [email.id]: '[email protected]' })).rejects.toThrow();
+ expect(h.desktop.stage()).toBe('password');
+ expect(h.desktop.acts.filter((act) => act.kind === 'text')).toHaveLength(1);
+ });
+});
+
+describe('代输入 screenshot step from another computer', () => {
+ const target = (snapshot: InputHandoffSnapshot) => ({
+ deviceId: 'cloud-device',
+ ghostId: INPUT_HANDOFF_GHOST_ID,
+ requestId: snapshot.requestId,
+ actionId: INPUT_HANDOFF_ACTION_ID,
+ expectedRevision: snapshot.revision,
+ presentation: inputHandoffPresentation(snapshot),
+ });
+
+ async function pictureStep() {
+ const h = await harness(true, true);
+ const form = h.latest();
+ expect(h.service.resolve(form.requestId, { kind: 'input_handoff', action: 'picture', expectedRevision: form.revision })).toBe(true);
+ await vi.waitFor(() => expect(h.latest().picture).toBe(true));
+ return h;
+ }
+
+ it('shows the picture to that window only, sealed on the wire, and applies the tap', async () => {
+ const h = await pictureStep();
+ const step = h.latest();
+ expect(JSON.stringify(step)).not.toContain('picture-of');
+ const opened = await handleOpenInputHandoffPicture(h.deps, target(step), 7);
+ expect(Buffer.from(opened.picture.data, 'base64').toString()).toBe('picture-of-account');
+ expect(JSON.stringify(h.wire)).not.toContain(opened.picture.data);
+
+ // Only the window that opened it can answer.
+ const tap = { expectedRevision: step.revision, values: {}, action: { kind: 'tap', x: 0.9, y: 0.9 } };
+ await expect(handleAnswerInputHandoffPicture({ token: opened.token, submission: tap }, 8)).resolves.toEqual({ accepted: false });
+ await expect(handleAnswerInputHandoffPicture({ token: opened.token, submission: tap }, 7)).resolves.toEqual({ accepted: true });
+ expect(h.desktop.pointers[0]).toMatchObject({ kind: 'tap', point: [720, 540] });
+ await vi.waitFor(() => expect(h.desktop.stage()).toBe('password'));
+ // A used exchange cannot be answered twice.
+ await expect(handleAnswerInputHandoffPicture({ token: opened.token, submission: tap }, 7)).resolves.toEqual({ accepted: false });
+ });
+
+ it('closes the exchange without touching the target when the owner leaves', async () => {
+ const h = await pictureStep();
+ const step = h.latest();
+ const opened = await handleOpenInputHandoffPicture(h.deps, target(step), 7);
+ await expect(handleAnswerInputHandoffPicture({ token: opened.token, submission: null }, 7)).resolves.toEqual({ accepted: false });
+ const stale = { expectedRevision: step.revision - 1, values: {}, action: { kind: 'tap', x: 0.5, y: 0.5 } };
+ const again = await handleOpenInputHandoffPicture(h.deps, target(step), 7);
+ await expect(handleAnswerInputHandoffPicture({ token: again.token, submission: stale }, 7)).resolves.toEqual({ accepted: false });
+ expect(h.desktop.pointers).toHaveLength(0);
+ });
+
+ it('refuses to open a picture for a form step or a step that moved on', async () => {
+ const h = await harness(true, true);
+ const form = h.latest();
+ await expect(handleOpenInputHandoffPicture(h.deps, target(form), 7)).rejects.toThrow();
+ const presentation = { ...inputHandoffPresentation(form), picture: true };
+ await expect(handleOpenInputHandoffPicture(h.deps, { ...target(form), presentation }, 7)).rejects.toThrow();
+ });
+});
diff --git a/apps/desktop/src/main/plugin-oauth/__tests__/pluginAuthorizationController.test.ts b/apps/desktop/src/main/plugin-oauth/__tests__/pluginAuthorizationController.test.ts
index 795c614ab3..a08c98607b 100644
--- a/apps/desktop/src/main/plugin-oauth/__tests__/pluginAuthorizationController.test.ts
+++ b/apps/desktop/src/main/plugin-oauth/__tests__/pluginAuthorizationController.test.ts
@@ -199,3 +199,95 @@ describe("native plugin configuration exchange", () => {
).toEqual([]);
});
});
+
+describe("代输入 screenshot step on the phone", () => {
+ // Distinctive base64 so a plaintext leak in the tunnel would be visible.
+ const picture = { mime: "image/jpeg" as const, width: 800, height: 600, data: "c3ludGhldGljLXBpY3R1cmUtYnl0ZXM=" };
+ const presentation = {
+ requestId: "card",
+ revision: 0,
+ purpose: "Sign in",
+ source: { app: "Game" },
+ command: null,
+ controls: [],
+ picture: true,
+ qr: false,
+ };
+ const inputAction = { requestId: "card", actionId: "step", expectedRevision: 0 };
+ function pictureHost() {
+ const answered = vi.fn(),
+ requests: unknown[] = [];
+ const host = new OauthTransactions({
+ owner: () => "account",
+ available: () => true,
+ bind: async () => ({ ghostId: "cindy-input-handoff", current: () => true }),
+ run: () => {
+ const remote = getRemoteOauthContext()!;
+ void (async () => {
+ try {
+ const state = randomBytes(32).toString("base64url");
+ answered(await remote.submitInput!({ kind: "input-entry", state, presentation, picture }));
+ remote.finish(true);
+ } catch {
+ remote.finish(false);
+ }
+ })();
+ return true;
+ },
+ });
+ return {
+ answered,
+ requests,
+ invoke: async (request: Parameters<OauthTransactions["request"]>[1]) => {
+ requests.push(request);
+ return host.request("phone", request);
+ },
+ };
+ }
+
+ it("shows the sealed picture and returns the owner's tap on the same exchange", async () => {
+ const h = pictureHost();
+ const shown = vi.fn();
+ const tap = { expectedRevision: 0, values: {}, action: { kind: "tap" as const, x: 0.5, y: 0.5 } };
+ await runMobilePluginAuthorization({
+ crypto,
+ action: inputAction,
+ kind: "input",
+ invoke: h.invoke,
+ assertCurrent: () => {},
+ pause: async () => {},
+ clearInput: () => {},
+ inputPresentation: presentation,
+ inputPicture: async (received) => {
+ shown(received);
+ return tap;
+ },
+ showAuthorization: async () => {
+ throw Error("No browser expected");
+ },
+ });
+ expect(shown).toHaveBeenCalledWith(picture);
+ expect(h.answered).toHaveBeenCalledWith(tap);
+ expect(JSON.stringify(h.requests)).not.toContain(picture.data);
+ });
+
+ it("never hands a picture to a prepared form answer", async () => {
+ const h = pictureHost();
+ await expect(
+ runMobilePluginAuthorization({
+ crypto,
+ action: inputAction,
+ kind: "input",
+ invoke: h.invoke,
+ assertCurrent: () => {},
+ pause: async () => {},
+ clearInput: () => {},
+ inputPresentation: presentation,
+ inputSubmission: { expectedRevision: 0, values: {}, action: { kind: "submit" } },
+ showAuthorization: async () => {},
+ }),
+ ).rejects.toThrow("OAUTH_BRIDGE_UNAVAILABLE");
+ expect(h.answered).not.toHaveBeenCalled();
+ expect(h.requests.at(-1)).toMatchObject({ op: "cancel" });
+ });
+});
diff --git a/apps/desktop/src/main/plugin-oauth/__tests__/pluginOauthCrypto.test.ts b/apps/desktop/src/main/plugin-oauth/__tests__/pluginOauthCrypto.test.ts
index 51b2c50dae..801dd435d0 100644
--- a/apps/desktop/src/main/plugin-oauth/__tests__/pluginOauthCrypto.test.ts
+++ b/apps/desktop/src/main/plugin-oauth/__tests__/pluginOauthCrypto.test.ts
@@ -12,7 +12,11 @@ import {
AuthenticatedOauthHost,
OauthHostIdentity,
} from "../authentication";
-import type { PluginOauthPeerIdentity } from "@cindy/device-link";
+import {
+ INPUT_HANDOFF_PICTURE_MAX_BYTES,
+ PLUGIN_OAUTH_SEALED_MAX_BYTES,
+ type PluginOauthPeerIdentity,
+} from "@cindy/device-link";
const crypto: PluginOauthCrypto = {
random: (n) => new Uint8Array(randomBytes(n)),
encrypt: async (key, iv, body, aad) => {
@@ -73,6 +77,24 @@ describe("mobile native plugin authorization cryptography", () => {
mobile.seal(desktop.publicKey, "transaction", "callback", {}),
).rejects.toThrow("OAUTH_BRIDGE_INVALID");
});
+ it("carries a full-size screenshot offer to the phone but keeps answers small", async () => {
+ const mobile = new MobileOauthBox(crypto),
+ desktop = new OauthBox();
+ const data = randomBytes(INPUT_HANDOFF_PICTURE_MAX_BYTES).toString("base64");
+ const offer = desktop.seal(mobile.publicKey, "transaction", "offer", { picture: data });
+ expect(
+ await mobile.open(desktop.publicKey, "transaction", "offer", offer),
+ ).toEqual({ picture: data });
+ // The answer direction keeps its small limit both ways.
+ await expect(
+ mobile.seal(desktop.publicKey, "transaction", "callback", {
+ value: "x".repeat(PLUGIN_OAUTH_SEALED_MAX_BYTES.callback),
+ }),
+ ).rejects.toThrow("OAUTH_BRIDGE_INVALID");
+ expect(() =>
+ desktop.open(mobile.publicKey, "transaction", "callback", offer),
+ ).toThrow();
+ });
it("verifies the actual signed Host handshake before transmitting authenticated requests", async () => {
const identity = new OauthHostIdentity(),
now = Date.now(),
diff --git a/apps/desktop/src/main/plugin-oauth/box.ts b/apps/desktop/src/main/plugin-oauth/box.ts
index 047a21dfd1..fb6753090a 100644
--- a/apps/desktop/src/main/plugin-oauth/box.ts
+++ b/apps/desktop/src/main/plugin-oauth/box.ts
@@ -8,6 +8,7 @@ import {
randomBytes,
type KeyObject,
} from 'node:crypto';
+import { PLUGIN_OAUTH_SEALED_MAX_BYTES, isPluginOauthBox } from '@cindy/device-link';
/** Ephemeral X25519 + HKDF/AES-GCM. Relay identity routing remains a trust root. */
export class OauthBox {
@@ -40,7 +41,7 @@ export class OauthBox {
const cipher = createCipheriv('aes-256-gcm', key, iv);
cipher.setAAD(Buffer.from(`cindy-plugin-oauth-v1:${id}:${direction}`));
const body = Buffer.from(JSON.stringify(value));
- if (body.length > 32_000) throw new Error('OAUTH_BRIDGE_INVALID');
+ if (body.length > PLUGIN_OAUTH_SEALED_MAX_BYTES[direction]) throw new Error('OAUTH_BRIDGE_INVALID');
return Buffer.concat([iv, cipher.update(body), cipher.final(), cipher.getAuthTag()]).toString(
'base64url',
);
@@ -50,7 +51,7 @@ export class OauthBox {
}
open(peer: string, id: string, direction: 'offer' | 'callback', box: string): unknown {
try {
- if (!/^[A-Za-z0-9_-]{40,48000}$/.test(box)) throw 0;
+ if (!isPluginOauthBox(direction, box)) throw 0;
const data = Buffer.from(box, 'base64url');
const key = this.key(peer, id, direction);
try {
diff --git a/apps/desktop/src/main/plugin-oauth/cards.ts b/apps/desktop/src/main/plugin-oauth/cards.ts
index 8731bc939f..b13b34698f 100644
--- a/apps/desktop/src/main/plugin-oauth/cards.ts
+++ b/apps/desktop/src/main/plugin-oauth/cards.ts
@@ -1,4 +1,12 @@
-import type { PluginOauthAction, PluginConnectionInput } from '@cindy/device-link';
+import {
+ INPUT_HANDOFF_ACTION_ID,
+ INPUT_HANDOFF_GHOST_ID,
+ inputHandoffPresentation,
+ type PluginOauthAction,
+ type PluginConnectionInput,
+ type InputHandoffSubmission,
+} from '@cindy/device-link';
+import type { InputHandoffService } from '../input-handoff/service.js';
import { randomBytes } from 'node:crypto';
import {
createPluginSecretPresentation,
@@ -15,6 +23,7 @@ import type { OauthCardBinding } from './transactions.js';
export function initializePluginOauthCards(deps: {
bridge: GhostSetupInteractionBridge;
bots(): BotAuthorizationService | null;
+ inputHandoff?(): InputHandoffService | null;
owner(): string | null;
available(peer: string): boolean;
identity: () => OauthIdentityScope | null;
@@ -51,13 +60,62 @@ export function initializePluginOauthCards(deps: {
};
return { snapshot: found.request, step, binding };
};
+ // 代输入: one signed exchange per step, bound to the exact pending revision.
+ const findHandoffStep = (action: PluginOauthAction) => {
+ const service = deps.inputHandoff?.();
+ if (!service || action.actionId !== INPUT_HANDOFF_ACTION_ID) return null;
+ const snapshot = service.actionable(action.requestId, action.expectedRevision);
+ if (!snapshot) return null;
+ const binding: OauthCardBinding = {
+ ghostId: INPUT_HANDOFF_GHOST_ID,
+ // A newer step is rejected by the revision check on submit. The exchange
+ // stays valid while the handoff runs, and after an answer that completed
+ // it (a terminal password, a last sign-in step) so it can report success;
+ // a cancelled, timed-out or failed handoff is no longer current.
+ current: () => service.isCurrent(action.requestId) || service.succeeded(action.requestId),
+ };
+ return { service, snapshot, binding };
+ };
+ const runHandoffStep = (action: PluginOauthAction): boolean => {
+ const step = findHandoffStep(action);
+ const remote = getRemoteOauthContext();
+ if (!step || !remote?.submitInput) return false;
+ const presentation = inputHandoffPresentation(step.snapshot);
+ // A screenshot step travels only inside this sealed offer, to the device that asked for it.
+ const picture = presentation.picture ? step.service.picture(action.requestId, action.expectedRevision) : null;
+ if (presentation.picture && !picture) return false;
+ void (async () => {
+ let submission: InputHandoffSubmission | undefined;
+ try {
+ submission = await remote.submitInput!({
+ kind: 'input-entry',
+ state: randomBytes(32).toString('base64url'),
+ presentation,
+ ...(picture ? { picture } : {}),
+ });
+ remote.assertCurrent();
+ if (submission.expectedRevision !== action.expectedRevision) throw new Error('INPUT_HANDOFF_STALE');
+ const accepted = await step.service.submit(action.requestId, submission, remote.peer ? { deviceId: remote.peer } : undefined);
+ remote.finish(accepted);
+ } catch {
+ remote.finish(false);
+ } finally {
+ submission = undefined;
+ }
+ })();
+ return true;
+ };
initializePluginOauthHost(
{
owner: deps.owner,
available: deps.available,
bind: async (action) =>
- findCardAction(action)?.binding ?? (await deps.bots()?.bindRemoteOauth(action)) ?? null,
+ findCardAction(action)?.binding ??
+ findHandoffStep(action)?.binding ??
+ (await deps.bots()?.bindRemoteOauth(action)) ??
+ null,
run: async (action) => {
+ if (findHandoffStep(action)) return runHandoffStep(action);
const card = findCardAction(action);
if (card) {
const { snapshot, step } = card;
diff --git a/apps/desktop/src/main/plugin-oauth/context.ts b/apps/desktop/src/main/plugin-oauth/context.ts
index 584008402b..593d654213 100644
--- a/apps/desktop/src/main/plugin-oauth/context.ts
+++ b/apps/desktop/src/main/plugin-oauth/context.ts
@@ -8,11 +8,15 @@ import type {
PluginDeviceOffer,
PluginAuthorizationOffer,
PluginDeviceOpened,
+ InputHandoffOffer,
+ InputHandoffSubmission,
} from '@cindy/device-link';
/** Captured by a validated card action, never from model/Renderer URL parameters. */
export interface RemoteOauthContext {
scope: string;
+ /** Device that opened this signed exchange (for value-free records only). */
+ peer?: string;
assertCurrent(): void;
authorize(offer: PluginOauthOffer, signal: AbortSignal): Promise<PluginOauthCallback>;
/** Optional additive capability; old loopback callers stay unchanged. */
@@ -23,6 +27,8 @@ export interface RemoteOauthContext {
): Promise<PluginOauthCallback | PluginDeviceOpened>;
submitSecret?(offer: PluginSecretOffer): Promise<string>;
submitConnection?(offer: PluginConnectionOffer): Promise<PluginConnectionInput>;
+ /** 代输入 step values; one signed exchange per step. */
+ submitInput?(offer: InputHandoffOffer): Promise<InputHandoffSubmission>;
cancelled?: AbortSignal;
finish(ok: boolean): void;
}
diff --git a/apps/desktop/src/main/plugin-oauth/controller.ts b/apps/desktop/src/main/plugin-oauth/controller.ts
index 9bc25e10a1..6bebb5bf0f 100644
--- a/apps/desktop/src/main/plugin-oauth/controller.ts
+++ b/apps/desktop/src/main/plugin-oauth/controller.ts
@@ -16,6 +16,12 @@ import {
type PluginDeviceOpened,
type PluginOauthOffer,
type PluginOauthRequest,
+ parseInputHandoffOffer,
+ parseInputHandoffPresentation,
+ parseInputHandoffValueReply,
+ type InputHandoffPicture,
+ type InputHandoffPresentation,
+ type InputHandoffSubmission,
} from '@cindy/device-link';
import { OauthBox } from './box.js';
import {
@@ -100,6 +106,11 @@ export interface OauthControllerDeps {
secretPresentation?: PluginSecretPresentation;
connectionValue?: PluginConnectionInput;
connectionPresentation?: PluginConnectionPresentation;
+ /** 代输入 step values; only from the dedicated local input IPC. */
+ inputSubmission?: InputHandoffSubmission;
+ inputPresentation?: InputHandoffPresentation;
+ /** 代输入 screenshot step: show the sealed picture, then return the owner's tap or typing. */
+ inputPicture?(picture: InputHandoffPicture): Promise<InputHandoffSubmission>;
invoke(request: PluginOauthRequest): Promise<unknown>;
openExternal(url: string): Promise<void>;
copyDeviceCode?(code: string): () => void;
@@ -126,6 +137,7 @@ export async function assistPluginOauth(
// Capability/handshake failures happen before a transaction exists too.
deps.secretValue = undefined;
deps.connectionValue = undefined;
+ deps.inputSubmission = undefined;
}
}
@@ -145,6 +157,11 @@ async function runAuthorization(
(caps.connectionSubmission !== true || deps.secretValue !== undefined)
)
throw fail();
+ if (
+ (deps.inputSubmission !== undefined || deps.inputPicture) &&
+ (caps.inputHandoff !== true || deps.secretValue !== undefined || deps.connectionValue !== undefined)
+ )
+ throw fail();
deps.assertCurrent();
const key = new OauthBox();
const deviceUserCode = caps.deviceUserCode === true && !!deps.copyDeviceCode;
@@ -157,6 +174,7 @@ async function runAuthorization(
...(caps.authorizationV1 === true ? { authorizationV1: true } : {}),
...(deps.secretValue !== undefined ? { secretSubmission: true } : {}),
...(deps.connectionValue !== undefined ? { connectionSubmission: true } : {}),
+ ...(deps.inputSubmission !== undefined || deps.inputPicture ? { inputHandoff: true } : {}),
}),
);
if (
@@ -198,6 +216,35 @@ async function runAuthorization(
if (status.phase === 'authorizing' && !opened) {
if (typeof status.offer !== 'string') throw fail();
const rawOffer = object(key.open(peerKey, id, 'offer', status.offer));
+ if (rawOffer.kind === 'input-entry') {
+ if ((deps.inputSubmission === undefined && !deps.inputPicture) || !deps.inputPresentation) throw fail();
+ const offer = parseInputHandoffOffer(rawOffer);
+ // The owner answered exactly this step; anything else is a newer step.
+ if (
+ JSON.stringify(offer.presentation) !==
+ JSON.stringify(parseInputHandoffPresentation(deps.inputPresentation))
+ )
+ throw fail();
+ if (offer.picture) {
+ // Only a caller that asked for this step's picture receives it; a prepared form answer never does.
+ if (!deps.inputPicture || deps.inputSubmission !== undefined) throw fail();
+ deps.inputSubmission = await deps.inputPicture(offer.picture);
+ deps.assertCurrent();
+ }
+ const payload = parseInputHandoffValueReply({
+ kind: 'input-value',
+ state: offer.state,
+ submission: deps.inputSubmission,
+ });
+ deps.assertCurrent();
+ const sealed = key.seal(peerKey, id, 'callback', payload);
+ deps.inputSubmission = undefined;
+ await deliverSealedCallback(sealed);
+ opened = true;
+ continue;
+ }
+ // A step form is never reinterpreted as another mode.
+ if (deps.inputSubmission !== undefined || deps.inputPicture) throw fail();
if (rawOffer.kind === 'connection-entry') {
if (caps.connectionSubmission !== true || deps.connectionValue === undefined)
throw fail();
@@ -306,6 +353,7 @@ async function runAuthorization(
} finally {
deps.secretValue = undefined;
deps.connectionValue = undefined;
+ deps.inputSubmission = undefined;
listener?.close();
adapter?.close(finished ? 'completed' : now() >= deadline ? 'expired' : 'ended');
clearDeviceCode?.();
diff --git a/apps/desktop/src/main/plugin-oauth/localIpc.ts b/apps/desktop/src/main/plugin-oauth/localIpc.ts
index c721ca5467..a2b10ebfad 100644
--- a/apps/desktop/src/main/plugin-oauth/localIpc.ts
+++ b/apps/desktop/src/main/plugin-oauth/localIpc.ts
@@ -7,9 +7,17 @@ import {
parsePluginSecretPresentation,
parsePluginConnectionInput,
parsePluginConnectionPresentation,
+ parseInputHandoffPresentation,
+ parseInputHandoffSubmission,
+ INPUT_HANDOFF_GHOST_ID,
+ PLUGIN_OAUTH_TTL_MS,
+ type InputHandoffPicture,
+ type InputHandoffPresentation,
+ type InputHandoffSubmission,
type InvokeResultPayload,
type PluginOauthPeerIdentity,
} from '@cindy/device-link';
+import { randomUUID } from 'node:crypto';
import { assistPluginOauth } from './controller.js';
import { capturePluginOauthPeer } from './runtime.js';
import { authenticateOauthController } from './authentication.js';
@@ -59,6 +67,11 @@ async function handleAuthorization(
raw: unknown,
secret?: Pick<LocalPluginSecretRequest, 'value' | 'presentation'>,
connection?: Pick<LocalPluginConnectionRequest, 'value' | 'presentation'>,
+ input?: {
+ presentation: InputHandoffPresentation;
+ submission?: InputHandoffSubmission;
+ picture?(picture: InputHandoffPicture): Promise<InputHandoffSubmission>;
+ },
): Promise<{ accepted: true }> {
const fail = () => new Error('OAUTH_BRIDGE_UNAVAILABLE');
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw fail();
@@ -103,6 +116,13 @@ async function handleAuthorization(
...(connection
? { connectionValue: connection.value, connectionPresentation: connection.presentation }
: {}),
+ ...(input
+ ? {
+ inputPresentation: input.presentation,
+ ...(input.submission ? { inputSubmission: input.submission } : {}),
+ ...(input.picture ? { inputPicture: input.picture } : {}),
+ }
+ : {}),
assertCurrent,
openExternal: deps.openExternal,
copyDeviceCode: deps.copyDeviceCode,
@@ -165,3 +185,126 @@ export async function handleSubmitPluginConnection(
presentation: parsePluginConnectionPresentation(presentation),
});
}
+
+/** 代输入 step for a task on another computer. The submission is never logged or echoed. */
+export async function handleSubmitInputHandoff(
+ deps: LocalOauthDeps,
+ raw: unknown,
+): Promise<{ accepted: true }> {
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
+ throw new Error('INPUT_HANDOFF_UNAVAILABLE');
+ const { submission, presentation, ...target } = raw as Record<string, unknown>;
+ if ((target as { ghostId?: unknown }).ghostId !== INPUT_HANDOFF_GHOST_ID)
+ throw new Error('INPUT_HANDOFF_UNAVAILABLE');
+ const parsedPresentation = parseInputHandoffPresentation(presentation);
+ const parsedSubmission = parseInputHandoffSubmission(submission);
+ if (
+ parsedPresentation.picture ||
+ parsedPresentation.requestId !== (target as { requestId?: unknown }).requestId ||
+ parsedPresentation.revision !== parsedSubmission.expectedRevision
+ )
+ throw new Error('INPUT_HANDOFF_UNAVAILABLE');
+ return handleAuthorization(deps, target, undefined, undefined, {
+ submission: parsedSubmission,
+ presentation: parsedPresentation,
+ });
+}
+
+interface PictureExchange {
+ owner: number;
+ revision: number;
+ answer(submission: InputHandoffSubmission | null): void;
+ done: Promise<{ accepted: true }>;
+}
+/** Open screenshot steps by token; each is one signed exchange waiting for the owner. */
+const pictureExchanges = new Map<string, PictureExchange>();
+
+/**
+ * 代输入 screenshot step for a task on another computer: runs the signed
+ * exchange up to the sealed offer and hands its picture to the requesting
+ * window. The exchange then waits for `handleAnswerInputHandoffPicture`.
+ * The picture is returned to that window only and never stored.
+ */
+export function handleOpenInputHandoffPicture(
+ deps: LocalOauthDeps,
+ raw: unknown,
+ owner: number,
+): Promise<{ token: string; picture: InputHandoffPicture }> {
+ const fail = () => new Error('INPUT_HANDOFF_UNAVAILABLE');
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return Promise.reject(fail());
+ const { presentation, ...target } = raw as Record<string, unknown>;
+ let parsed: InputHandoffPresentation;
+ try {
+ parsed = parseInputHandoffPresentation(presentation);
+ } catch {
+ return Promise.reject(fail());
+ }
+ if (
+ (target as { ghostId?: unknown }).ghostId !== INPUT_HANDOFF_GHOST_ID ||
+ !parsed.picture ||
+ parsed.requestId !== (target as { requestId?: unknown }).requestId ||
+ parsed.revision !== (target as { expectedRevision?: unknown }).expectedRevision ||
+ pictureExchanges.size >= 4
+ )
+ return Promise.reject(fail());
+ const token = randomUUID();
+ return new Promise((resolve, reject) => {
+ const done = handleAuthorization(deps, target, undefined, undefined, {
+ presentation: parsed,
+ picture: (picture) =>
+ new Promise<InputHandoffSubmission>((answered, declined) => {
+ const timer = setTimeout(() => entry.answer(null), PLUGIN_OAUTH_TTL_MS);
+ timer.unref?.();
+ const entry: PictureExchange = {
+ owner,
+ revision: parsed.revision,
+ answer: (submission) => {
+ clearTimeout(timer);
+ entry.answer = () => undefined;
+ if (submission) answered(submission);
+ else declined(fail());
+ },
+ done,
+ };
+ pictureExchanges.set(token, entry);
+ resolve({ token, picture });
+ }),
+ });
+ done.catch(reject).finally(() => {
+ pictureExchanges.get(token)?.answer(null);
+ pictureExchanges.delete(token);
+ });
+ });
+}
+
+/** The owner's tap or typing on an opened screenshot step; `null` closes it without acting. */
+export async function handleAnswerInputHandoffPicture(
+ raw: unknown,
+ owner: number,
+): Promise<{ accepted: boolean }> {
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw new Error('INPUT_HANDOFF_UNAVAILABLE');
+ const { token, submission } = raw as Record<string, unknown>;
+ const entry = typeof token === 'string' ? pictureExchanges.get(token) : undefined;
+ if (!entry || entry.owner !== owner) return { accepted: false };
+ // Closing waits for the exchange to wind down, so the same window can open the step again right away.
+ const close = async () => {
+ entry.answer(null);
+ await entry.done.catch(() => undefined);
+ return { accepted: false };
+ };
+ if (submission === null) return close();
+ let parsed: InputHandoffSubmission;
+ try {
+ parsed = parseInputHandoffSubmission(submission);
+ } catch {
+ return close();
+ }
+ if (parsed.expectedRevision !== entry.revision) return close();
+ entry.answer(parsed);
+ try {
+ await entry.done;
+ return { accepted: true };
+ } catch {
+ return { accepted: false };
+ }
+}
diff --git a/apps/desktop/src/main/plugin-oauth/transactions.ts b/apps/desktop/src/main/plugin-oauth/transactions.ts
index 45e7fd1645..6518e86f74 100644
--- a/apps/desktop/src/main/plugin-oauth/transactions.ts
+++ b/apps/desktop/src/main/plugin-oauth/transactions.ts
@@ -14,6 +14,9 @@ import {
type PluginDeviceOpened,
type PluginOauthCallback,
parsePluginOauthRequest,
+ parseInputHandoffOffer,
+ parseInputHandoffValueReply,
+ type InputHandoffValueReply,
type PluginOauthAction,
type PluginOauthPhase,
type PluginOauthRequest,
@@ -34,8 +37,19 @@ export interface OauthTransactionDeps {
now?: () => number;
}
type TransactionReply =
- PluginOauthCallback | PluginDeviceOpened | PluginSecretValue | PluginConnectionValue;
-type ReplyMode = 'loopback' | 'device' | 'secret' | 'connection';
+ | PluginOauthCallback
+ | PluginDeviceOpened
+ | PluginSecretValue
+ | PluginConnectionValue
+ | InputHandoffValueReply;
+type ReplyMode = 'loopback' | 'device' | 'secret' | 'connection' | 'input';
+const parseOrNull = <T>(parse: (raw: unknown) => T) => (raw: unknown): T | null => {
+ try {
+ return parse(raw);
+ } catch {
+ return null;
+ }
+};
interface OfferExchange<T> {
offer: { state: string };
mode: ReplyMode;
@@ -147,6 +161,7 @@ export class OauthTransactions {
): RemoteOauthContext {
return {
scope: t.id,
+ peer: t.peer,
cancelled: t.lifetime.signal,
assertCurrent: () => this.assertCurrent(t),
authorize: (offer, signal) =>
@@ -203,6 +218,15 @@ export class OauthTransactions {
parse: parsePluginConnectionValue,
}).then((reply) => reply.value);
},
+ submitInput: (rawOffer) => {
+ if (request.inputHandoff !== true) throw failure();
+ const offer = parseInputHandoffOffer(rawOffer);
+ return this.waitForReply(t, {
+ offer,
+ mode: 'input',
+ parse: parseOrNull(parseInputHandoffValueReply),
+ }).then((reply) => reply.submission);
+ },
finish: (ok) => {
if (!terminal(t.phase)) this.finish(t, ok && this.current(t) ? 'succeeded' : 'failed');
},
@@ -239,6 +263,7 @@ export class OauthTransactions {
authorizationV1: true,
secretSubmission: true,
connectionSubmission: true,
+ inputHandoff: true,
};
if (request.op === 'start') {
const owner = this.deps.owner()!;
@@ -311,7 +336,9 @@ export class OauthTransactions {
if (t.phase !== 'authorizing' || !t.key) throw failure();
const rawCallback = t.key.open(t.publicKey, t.id, 'callback', request.box);
const callback =
- t.mode === 'connection'
+ t.mode === 'input'
+ ? parseOrNull(parseInputHandoffValueReply)(rawCallback)
+ : t.mode === 'connection'
? parsePluginConnectionValue(rawCallback)
: t.mode === 'secret'
? parsePluginSecretValue(rawCallback)
diff --git a/apps/desktop/src/main/remote-desktop-viewer/__tests__/connection.test.ts b/apps/desktop/src/main/remote-desktop-viewer/__tests__/connection.test.ts
index ca67afd0c9..4d49294ba1 100644
--- a/apps/desktop/src/main/remote-desktop-viewer/__tests__/connection.test.ts
+++ b/apps/desktop/src/main/remote-desktop-viewer/__tests__/connection.test.ts
@@ -783,3 +783,55 @@ describe('control granted with the lease (autoControl)', () => {
});
});
});
+
+describe('代输入 window view', () => {
+ it('starts only the window view it was opened for, and keeps whole-desktop features off', async () => {
+ const request = vi.fn(async (_target: string, message: RemoteDesktopRequest) => {
+ if (message.op === 'capabilities')
+ return {
+ version: 1,
+ enabled: true,
+ canControl: true,
+ platform: 'darwin',
+ displays: [],
+ handoffWindow: true,
+ clipboardSync: true,
+ privacyScreen: true,
+ lockOnExit: true,
+ };
+ return { lease: 'lease-w', controlling: true, display: { id: '1', width: 800, height: 600 } };
+ });
+ const connection = new RemoteViewerConnection({
+ owner: () => 'account-a:1',
+ request,
+ readClipboard: () => '',
+ writeClipboard: () => {},
+ });
+ connection.bind({ deviceId: 'computer-a', name: 'Computer', handoff: 'req1' });
+ connection.setActive(true);
+ const { generation } = connection.snapshot();
+ const caps = await connection.request(generation, { op: 'capabilities' });
+ expect(caps.ok).toBe(true);
+ // The page cannot drop the window view or swap it for another request.
+ for (const start of [
+ { op: 'start', displayId: '1' },
+ { op: 'start', displayId: '1', handoff: 'req2' },
+ ])
+ expect(await connection.request(generation, start)).toEqual({
+ ok: false,
+ code: 'DESKTOP_UNAVAILABLE',
+ });
+ expect(
+ (await connection.request(generation, { op: 'start', displayId: '1', handoff: 'req1' })).ok,
+ ).toBe(true);
+ expect(request).toHaveBeenLastCalledWith(
+ 'computer-a',
+ expect.objectContaining({ op: 'start', handoff: 'req1' }),
+ expect.any(Function),
+ );
+ // Safety ticks use the window-view capabilities: no clipboard sync, masks or lock.
+ const safety = await connection.safety(generation);
+ expect(safety.privacyActive).toBe(false);
+ expect(request.mock.calls.map(([, message]) => message.op)).not.toContain('clipboardSync');
+ });
+});
diff --git a/apps/desktop/src/main/remote-desktop-viewer/connection.ts b/apps/desktop/src/main/remote-desktop-viewer/connection.ts
index 91a0c50f56..56c65fd362 100644
--- a/apps/desktop/src/main/remote-desktop-viewer/connection.ts
+++ b/apps/desktop/src/main/remote-desktop-viewer/connection.ts
@@ -1,4 +1,5 @@
import {
+ handoffWindowCapabilities,
isRemoteDesktopChannelRequest,
parseRemoteDesktopRequest,
REMOTE_DESKTOP_CHANNEL_TIMEOUT_MS,
@@ -78,7 +79,10 @@ export class RemoteViewerConnection {
) {}
bind(target: RemoteViewerTarget): void {
const owner = this.deps.owner();
- const sameScope = this.owner === owner && this.target?.deviceId === target.deviceId;
+ const sameScope =
+ this.owner === owner &&
+ this.target?.deviceId === target.deviceId &&
+ this.target.handoff === target.handoff;
this.deactivate();
if (!sameScope) this.lifecycle = null;
this.owner = owner;
@@ -191,6 +195,9 @@ export class RemoteViewerConnection {
if ('lease' in request && request.lease !== this.lease)
throw new Error('DESKTOP_LEASE_EXPIRED');
if (request.op === 'start' && this.starting) throw new Error('DESKTOP_BUSY');
+ // The window decides whether this is a 代输入 window view; the page cannot widen or swap it.
+ if (request.op === 'start' && request.handoff !== this.target?.handoff)
+ throw new Error('DESKTOP_UNAVAILABLE');
// Clipboard contents and credentials are handled only by dedicated Main adapters.
if (
request.op === 'clipboard' ||
@@ -238,7 +245,9 @@ export class RemoteViewerConnection {
const result = await this.send(outgoing, check);
if (request.op === 'capabilities') {
check();
- this.caps = result as RemoteDesktopCapabilities;
+ const caps = result as RemoteDesktopCapabilities;
+ // A window view never runs whole-desktop safety features (masks, mute, clipboard sync).
+ this.caps = target.handoff && caps?.handoffWindow ? handoffWindowCapabilities(caps) : caps;
}
if (isStart) {
const lease = result as RemoteDesktopLease;
diff --git a/apps/desktop/src/main/remote-desktop-viewer/windows.ts b/apps/desktop/src/main/remote-desktop-viewer/windows.ts
index 7d89ab12a8..3443bc661d 100644
--- a/apps/desktop/src/main/remote-desktop-viewer/windows.ts
+++ b/apps/desktop/src/main/remote-desktop-viewer/windows.ts
@@ -97,13 +97,24 @@ export class RemoteDesktopViewerWindows {
target.deviceId.length > 256 ||
target.deviceId === getSelfDeviceId() ||
typeof target.name !== 'string' ||
- target.name.length > 256
+ target.name.length > 256 ||
+ (target.handoff !== undefined &&
+ (typeof target.handoff !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(target.handoff)))
)
throwIpcError('INVALID_PARAMS', 'Invalid remote desktop target');
- let entry = [...this.entries].find((e) => e.connection.target?.deviceId === target.deviceId);
+ // A 代输入 window view is its own window, separate from a whole-desktop viewer.
+ let entry = [...this.entries].find(
+ (e) =>
+ e.connection.target?.deviceId === target.deviceId &&
+ e.connection.target.handoff === target.handoff,
+ );
if (!entry) entry = [...this.entries].find((e) => !e.connection.target) ?? this.create();
if (!entry.connection.active)
- entry.connection.bind({ deviceId: target.deviceId, name: target.name });
+ entry.connection.bind({
+ deviceId: target.deviceId,
+ name: target.name,
+ ...(target.handoff ? { handoff: target.handoff } : {}),
+ });
entry.controller.open(sender);
// The spare shell is created off the next click path, never connects to a peer.
this.prewarm();
diff --git a/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts
index 026d7001e4..8a8f724a35 100644
--- a/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts
+++ b/apps/desktop/src/main/remote-desktop/__tests__/captureBoundary.test.ts
@@ -42,6 +42,8 @@ const h = vi.hoisted(() => ({
inputFailure: null as null | (() => void),
nativeStop: vi.fn(),
nativeFrame: vi.fn(async () => 'frame'),
+ setWindow: vi.fn(),
+ handoff: null as null | { windowId: number; pid: number },
input: vi.fn(),
viewHeartbeat: vi.fn(),
controllerState: null as null | { peer: string; controlling: boolean },
@@ -173,6 +175,9 @@ vi.mock('../controller', () => ({
hasLease(value: string) {
return value === h.lease;
}
+ handoffWindow(value: string) {
+ return value === h.lease ? h.handoff : null;
+ }
isBackgroundViewing(value: string) {
return value === h.lease && h.background;
}
@@ -196,6 +201,7 @@ vi.mock('../nativeCapture', () => ({
NativeDesktopCapture: class {
stop = h.nativeStop;
frame = h.nativeFrame;
+ setWindow = h.setWindow;
},
}));
vi.mock('../inputHost', () => ({
@@ -280,6 +286,8 @@ beforeEach(() => {
h.releaseControl.mockClear();
h.nativeStop.mockClear();
h.nativeFrame.mockClear();
+ h.setWindow.mockClear();
+ h.handoff = null;
h.input.mockReset();
h.viewHeartbeat.mockClear();
// The host is constructed once at module load; keep its captured callback.
@@ -1291,3 +1299,27 @@ it('starts and retunes video for a background viewer without a new offer', async
});
expect(h.windows).toHaveLength(1);
});
+
+it('streams only the 代输入 window: native window capture, no screen source, no audio', async () => {
+ h.handoff = { windowId: 4242, pid: 77 };
+ await expect(
+ h.deps.offer({ lease: h.lease, display: { id: '1' } }, 'sdp', { audio: true }, false, 'a'),
+ ).rejects.toThrow('DESKTOP_AUDIO_UNAVAILABLE');
+ h.setWindow.mockClear();
+ const pending = offer();
+ h.handlers.get(DESKTOP_LOCAL.REGISTER)(event());
+ await flush();
+ const command = h.owner.send.mock.calls[0][1];
+ // The window stream is the native overlay capture of that one window.
+ expect(h.setWindow).toHaveBeenLastCalledWith(4242);
+ expect(command).toMatchObject({ op: 'offer', nativeCapture: true, cursorOverlay: true });
+ expect(command.sourceId).toBeUndefined();
+ h.handlers.get(DESKTOP_LOCAL.REPLY)(event(), command.id, 'answer');
+ await pending;
+ // Relay frames read the same window.
+ h.nativeFrame.mockClear();
+ await h.deps.frame('1', false, h.lease);
+ expect(h.nativeFrame).toHaveBeenLastCalledWith('1', true, undefined);
+ h.deps.stopVideo();
+ expect(h.setWindow).toHaveBeenLastCalledWith(null);
+});
diff --git a/apps/desktop/src/main/remote-desktop/__tests__/controllerHandoffWindow.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/controllerHandoffWindow.test.ts
new file mode 100644
index 0000000000..f595e3b75a
--- /dev/null
+++ b/apps/desktop/src/main/remote-desktop/__tests__/controllerHandoffWindow.test.ts
@@ -0,0 +1,144 @@
+import { describe, expect, it, vi } from 'vitest';
+import type { RemoteDesktopLease } from '@cindy/device-link';
+import {
+ RemoteDesktopController,
+ type DesktopControllerDeps,
+ type DesktopHandoffWindow,
+} from '../controller';
+
+const target: DesktopHandoffWindow = {
+ requestId: 'req1',
+ windowId: 4242,
+ pid: 77,
+ displayId: '2',
+ app: 'Game',
+ title: 'Sign in',
+ width: 800,
+ height: 600,
+};
+
+function harness(pending: DesktopHandoffWindow | null = target) {
+ const deps: DesktopControllerDeps = {
+ authorized: () => true,
+ capabilities: async () => ({
+ version: 1,
+ enabled: true,
+ canControl: true,
+ platform: 'darwin',
+ displays: [
+ { id: '1', name: 'Main', width: 1920, height: 1080 },
+ { id: '2', name: 'Side', width: 1440, height: 900 },
+ ],
+ }),
+ frame: vi.fn(async () => 'jpeg'),
+ startInput: vi.fn(async () => {}),
+ handoffWindow: vi.fn(async (requestId: string) =>
+ pending && pending.requestId === requestId ? pending : null,
+ ),
+ input: vi.fn(),
+ stopInput: vi.fn(),
+ stopVideo: vi.fn(),
+ offer: vi.fn(async () => 'answer'),
+ lockScreen: vi.fn(async () => {}),
+ clipboard: vi.fn(async () => 'host clipboard'),
+ displayModes: vi.fn(async () => []),
+ changed: vi.fn(),
+ };
+ const controller = new RemoteDesktopController(deps);
+ const open = (extra: Record<string, unknown> = {}) =>
+ controller.request('phone', {
+ op: 'start',
+ displayId: '1',
+ handoff: 'req1',
+ ...extra,
+ }) as Promise<RemoteDesktopLease>;
+ return { controller, deps, open };
+}
+
+describe('代输入 live view leases', () => {
+ it('advertises the window view and opens the window the host picks, at its shape', async () => {
+ const h = harness();
+ const caps = (await h.controller.request('phone', { op: 'capabilities' })) as {
+ handoffWindow?: boolean;
+ };
+ expect(caps.handoffWindow).toBe(true);
+ const lease = await h.open({ control: true });
+ expect(h.deps.handoffWindow).toHaveBeenCalledWith('req1', 'phone');
+ expect(lease.display).toMatchObject({ id: '2', width: 800, height: 600 });
+ expect(lease.window).toEqual({ app: 'Game', title: 'Sign in' });
+ expect(lease.controlling).toBe(true);
+ // Input is confined to the window from the first event.
+ expect(h.deps.startInput).toHaveBeenCalledWith('2', target);
+ expect(h.controller.handoffWindow(lease.lease)).toEqual(target);
+ });
+
+ it('refuses a request that is not waiting for the owner, and hosts without the view', async () => {
+ await expect(harness(null).open()).rejects.toThrow('DESKTOP_HANDOFF_ENDED');
+ const h = harness();
+ delete h.deps.handoffWindow;
+ const caps = (await h.controller.request('phone', { op: 'capabilities' })) as object;
+ expect(caps).not.toHaveProperty('handoffWindow');
+ await expect(h.open()).rejects.toThrow('DESKTOP_HANDOFF_UNAVAILABLE');
+ expect(h.controller.state).toBeNull();
+ });
+
+ it('allows only what stays inside the window', async () => {
+ const h = harness();
+ const { lease } = await h.open({ control: true });
+ for (const request of [
+ { op: 'clipboard', lease, action: 'copy' },
+ { op: 'displayModes', lease },
+ { op: 'privacyScreen', lease, enabled: true },
+ { op: 'windowAction', lease, action: 'desktop' },
+ { op: 'viewerDisplay', lease, width: 1280, height: 720 },
+ ])
+ await expect(h.controller.request('phone', request)).rejects.toThrow(
+ 'DESKTOP_HANDOFF_WINDOW_ONLY',
+ );
+ expect(h.deps.clipboard).not.toHaveBeenCalled();
+ expect(h.deps.displayModes).not.toHaveBeenCalled();
+ await h.controller.request('phone', { op: 'input', lease, sequence: 1, events: [{ kind: 'move', x: 0.5, y: 0.5 }] });
+ expect(h.deps.input).toHaveBeenCalledOnce();
+ expect(await h.controller.request('phone', { op: 'heartbeat', lease, lockOnExit: true })).toEqual({
+ controlling: true,
+ });
+ // Leaving a look at one window never locks the computer.
+ await h.controller.request('phone', { op: 'stop', lease, lockScreen: true });
+ expect(h.deps.lockScreen).not.toHaveBeenCalled();
+ expect(h.controller.state).toBeNull();
+ });
+
+ it('resumes only as the same request, and ends when the request ends', async () => {
+ const h = harness();
+ const first = await h.open();
+ const resumed = await h.open({ resume: true });
+ expect(resumed.lease).not.toBe(first.lease);
+ expect(h.controller.handoffWindow(resumed.lease)).toEqual(target);
+ await expect(
+ h.controller.request('phone', { op: 'start', displayId: '2', resume: true }),
+ ).rejects.toThrow('DESKTOP_BUSY');
+ h.controller.endHandoff('another');
+ expect(h.controller.state).not.toBeNull();
+ h.controller.endHandoff('req1');
+ expect(h.controller.state).toBeNull();
+ });
+
+ it('ends with the request, and tells the card when the view closes', async () => {
+ const h = harness();
+ let waiting = true;
+ const ended: string[] = [];
+ h.deps.handoffCurrent = () => waiting;
+ h.deps.handoffEnded = (requestId) => ended.push(requestId);
+ await h.open();
+ h.controller.tick();
+ expect(h.controller.state).not.toBeNull();
+ waiting = false;
+ h.controller.tick();
+ expect(h.controller.state).toBeNull();
+ expect(ended).toEqual(['req1']);
+ // A whole-display lease is not a 代输入 view and says nothing.
+ await h.controller.request('phone', { op: 'start', displayId: '1' });
+ await h.controller.stop();
+ expect(ended).toEqual(['req1']);
+ });
+});
diff --git a/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts
index cb7c720255..3174bc83a3 100644
--- a/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts
+++ b/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts
@@ -413,3 +413,46 @@ it('keeps Linux whole-desktop coordinates normalized and releases input before r
c.exit();
}
});
+
+describe('代输入 window input', () => {
+ it('starts the helper confined to one window and passes fractions through untouched', async () => {
+ const c = childProcess();
+ const spawn = vi.fn((_binary: string, _args?: string[]) => {
+ void Promise.resolve().then(() => c.child.stdout.emit('data', Buffer.from('ready\n')));
+ return c.typed;
+ });
+ const host = new DesktopInputHost(vi.fn(), {
+ platform: 'darwin',
+ resolveBinary: async () => '/test/helper',
+ spawn,
+ });
+ try {
+ // A display the screen does not know is fine: the window, not a display, is the target.
+ await host.start('9', { windowId: 4242, pid: 77 });
+ expect(spawn).toHaveBeenCalledWith('/test/helper', ['--window', '4242', '77']);
+ host.input([{ kind: 'button', button: 0, down: true, x: 0.25, y: 0.75 }]);
+ await flush();
+ expect(c.child.stdin.write).toHaveBeenCalledWith(
+ '[{"kind":"button","button":0,"down":true,"x":0.25,"y":0.75}]\n',
+ expect.any(Function),
+ );
+ } finally {
+ host.stop();
+ c.exit();
+ await flush();
+ }
+ });
+
+ it('refuses a window it cannot confine', async () => {
+ const spawn = vi.fn();
+ for (const [platform, window] of [
+ ['win32', { windowId: 1, pid: 2 }],
+ ['darwin', { windowId: 0, pid: 2 }],
+ ['darwin', { windowId: 1, pid: -1 }],
+ ] as const) {
+ const host = new DesktopInputHost(vi.fn(), { platform, resolveBinary: async () => '/x', spawn });
+ await expect(host.start('1', window)).rejects.toThrow('DESKTOP_INPUT_UNSUPPORTED');
+ }
+ expect(spawn).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/desktop/src/main/remote-desktop/__tests__/macNativeCapture.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/macNativeCapture.test.ts
index 081277ec3e..ac19595191 100644
--- a/apps/desktop/src/main/remote-desktop/__tests__/macNativeCapture.test.ts
+++ b/apps/desktop/src/main/remote-desktop/__tests__/macNativeCapture.test.ts
@@ -60,3 +60,19 @@ it('accepts frames up to the tier budget and stops capture beyond it', async ()
auto.owner.stop();
await expect(rejected).resolves.toBeNull();
});
+
+it('captures only the 代输入 window, never the display, and returns to the display after', async () => {
+ const { owner } = setup();
+ owner.setExcludedWindows([7, 8]);
+ owner.setWindow(4242);
+ // The window view exists only as the overlay stream.
+ await expect(owner.frame('1', false)).resolves.toBeNull();
+ expect(h.spawn).not.toHaveBeenCalled();
+ void owner.frame('1', true, { fps: 30, quality: 'auto', audio: false });
+ await vi.waitFor(() => expect(h.spawn).toHaveBeenCalledOnce());
+ expect(h.spawn.mock.calls[0][1].at(-1)).toBe('window:4242');
+ owner.setWindow(null);
+ void owner.frame('1', true, { fps: 30, quality: 'auto', audio: false });
+ await vi.waitFor(() => expect(h.spawn).toHaveBeenCalledTimes(2));
+ expect(h.spawn.mock.calls[1][1].at(-1)).toBe('7,8');
+});
diff --git a/apps/desktop/src/main/remote-desktop/__tests__/macosInput.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/macosInput.test.ts
index 38579aee3b..78b45a566a 100644
--- a/apps/desktop/src/main/remote-desktop/__tests__/macosInput.test.ts
+++ b/apps/desktop/src/main/remote-desktop/__tests__/macosInput.test.ts
@@ -24,7 +24,11 @@ it.skipIf(process.platform !== 'darwin')(
await writeFile(main, `${await readFile(callerPath, 'utf8')}\n${source}\n${tests}`);
await exec('swiftc', ['-D', 'DESKTOP_INPUT_TEST', main, '-o', binary], { timeout: 120_000 });
const { stdout } = await exec(binary, [], { timeout: 5000 });
- expect(stdout.trim()).toBe('native keyboard flags passed');
+ expect(stdout.trim().split('\n')).toEqual([
+ 'native keyboard flags passed',
+ 'native window confinement passed',
+ 'native qr detection passed',
+ ]);
} finally {
await rm(directory, { recursive: true, force: true });
}
diff --git a/apps/desktop/src/main/remote-desktop/controller.ts b/apps/desktop/src/main/remote-desktop/controller.ts
index cacbc2f3b2..8e0b81f4b7 100644
--- a/apps/desktop/src/main/remote-desktop/controller.ts
+++ b/apps/desktop/src/main/remote-desktop/controller.ts
@@ -23,6 +23,32 @@ import {
const log = createLogger('remote-desktop:controller');
+/** The one window a 代输入 live view shows; resolved by the host, never by a viewer. */
+export interface DesktopHandoffWindow {
+ requestId: string;
+ windowId: number;
+ pid: number;
+ displayId: string;
+ app: string;
+ title?: string;
+ /** Window size in points, so the viewer lays the picture out at its own shape. */
+ width: number;
+ height: number;
+}
+
+/** What a window lease may do; everything else reaches past the window. */
+const HANDOFF_WINDOW_OPS = new Set([
+ 'stop',
+ 'heartbeat',
+ 'control',
+ 'presentation',
+ 'input',
+ 'offer',
+ 'ice',
+ 'viewerHidden',
+ 'frame',
+]);
+
export interface DesktopControllerDeps {
/** Optional host setup before allocating the first lease or temporary output. */
prepare?(current: () => boolean): Promise<void>;
@@ -49,7 +75,18 @@ export interface DesktopControllerDeps {
cursorOverlay?: boolean,
lease?: string,
): Promise<string | RemoteDesktopCursorFrame | null>;
- startInput(displayId: string): Promise<void>;
+ /** With `window`, input reaches only that window (a 代输入 live view). */
+ startInput(displayId: string, window?: DesktopHandoffWindow): Promise<void>;
+ /**
+ * 代输入 live view: the window a pending request is about, raised so it can be
+ * shown, or null when the request is not waiting for the owner. Only the host
+ * picks the window; a viewer names nothing but the request.
+ */
+ handoffWindow?(requestId: string, peer: string): Promise<DesktopHandoffWindow | null>;
+ /** Whether the request a window lease shows is still waiting; its lease ends when not. */
+ handoffCurrent?(requestId: string): boolean;
+ /** A window lease ended; the request's card catches up with the window. */
+ handoffEnded?(requestId: string): void;
input(events: DesktopInput[]): void;
stopInput(): void;
releaseInput?(): Promise<void>;
@@ -132,6 +169,7 @@ export class RemoteDesktopController {
hostMute?: boolean;
lockOnExit?: boolean;
privacyLockOnExit?: boolean;
+ handoff?: DesktopHandoffWindow;
})
| null = null;
private starting = false;
@@ -211,6 +249,15 @@ export class RemoteDesktopController {
this.tick();
return this.active?.lease === lease;
}
+ /** The single window this lease shows, when it is a 代输入 live view. */
+ handoffWindow(lease: string): DesktopHandoffWindow | null {
+ return this.active?.lease === lease ? (this.active.handoff ?? null) : null;
+ }
+ /** The 代输入 request finished: its live view has nothing left to show. */
+ endHandoff(requestId: string): void {
+ const active = this.active;
+ if (active?.handoff?.requestId === requestId) void this.stop(active.peer, false);
+ }
isBackgroundViewing(lease: string): boolean {
return this.active?.lease === lease && this.active.backgroundViewing === true;
}
@@ -252,6 +299,9 @@ export class RemoteDesktopController {
) {
this.lockAbort?.abort();
void this.stop(undefined, false);
+ } else if (active.handoff && this.deps.handoffCurrent?.(active.handoff.requestId) === false) {
+ // The 代输入 request finished: nothing is left to show.
+ void this.stop(undefined, false);
} else if (!this.locking && active.expires <= this.now()) {
void this.stop();
}
@@ -320,6 +370,7 @@ export class RemoteDesktopController {
this.active = null;
this.deps.stopInput();
this.deps.stopVideo();
+ if (active?.handoff) this.deps.handoffEnded?.(active.handoff.requestId);
this.viewerDisplay?.dispose();
// Retain the handle until restoration completes (or can be retried after failure).
// EOF releases it asynchronously; a new lease must not bind stale geometry.
@@ -495,7 +546,9 @@ export class RemoteDesktopController {
if (!active.controlling) {
this.inputStarting = true;
try {
- await this.deps.startInput(active.display.id);
+ await (active.handoff
+ ? this.deps.startInput(active.display.id, active.handoff)
+ : this.deps.startInput(active.display.id));
if (
generation !== this.controlGeneration ||
this.active !== active ||
@@ -616,6 +669,7 @@ export class RemoteDesktopController {
resolutionRestore: Boolean(
caps.displayModes && this.deps.resolution && this.deps.displayModes,
),
+ ...(this.deps.handoffWindow ? { handoffWindow: true } : {}),
};
}
if (!this.deps.authorized(peer)) throw new Error('DESKTOP_DISABLED');
@@ -641,10 +695,15 @@ export class RemoteDesktopController {
): Promise<RemoteDesktopLease> {
const authenticationSession = this.authenticationSession(peer);
if (request.resume && this.userStopped.has(peer)) throw new Error('DESKTOP_STOPPED');
+ if (request.handoff !== undefined && !this.deps.handoffWindow)
+ throw new Error('DESKTOP_HANDOFF_UNAVAILABLE');
+ // A window view resumes only as the same request's view; a display view only as itself.
const resumesActive =
request.resume &&
this.active?.peer === peer &&
- this.active.sourceDisplayId === request.displayId;
+ (request.handoff !== undefined
+ ? this.active.handoff?.requestId === request.handoff
+ : !this.active.handoff && this.active.sourceDisplayId === request.displayId);
if (
this.locking ||
this.starting ||
@@ -671,7 +730,16 @@ export class RemoteDesktopController {
const caps = await this.deps.capabilities();
if (!this.authenticationCurrent(peer, authenticationSession))
throw new Error('DESKTOP_AUTHENTICATION_REQUIRED');
- let display = caps.displays.find((d) => d.id === request.displayId);
+ let handoff: DesktopHandoffWindow | undefined;
+ if (request.handoff !== undefined) {
+ handoff = (await this.deps.handoffWindow!(request.handoff, peer)) ?? undefined;
+ if (!handoff || handoff.requestId !== request.handoff)
+ throw new Error('DESKTOP_HANDOFF_ENDED');
+ if (!this.authenticationCurrent(peer, authenticationSession))
+ throw new Error('DESKTOP_AUTHENTICATION_REQUIRED');
+ }
+ const displayId = handoff?.displayId ?? request.displayId;
+ let display = caps.displays.find((d) => d.id === displayId);
if (!display) throw new Error('DESKTOP_DISPLAY_MISSING');
if (
this.startingPeer !== peer ||
@@ -700,11 +768,19 @@ export class RemoteDesktopController {
!this.authenticationCurrent(peer, authenticationSession)
)
throw new Error('DESKTOP_LEASE_EXPIRED');
- display = restored.displays.find((d) => d.id === request.displayId);
+ display = restored.displays.find((d) => d.id === displayId);
if (!display) throw new Error('DESKTOP_DISPLAY_MISSING');
}
if (!request.resume) this.userStopped.delete(peer);
- const lease: RemoteDesktopLease = { lease: randomUUID(), display, controlling: false };
+ const lease: RemoteDesktopLease = handoff
+ ? {
+ lease: randomUUID(),
+ // The picture is the window, so the viewer lays it out at the window's shape.
+ display: { ...display, width: handoff.width, height: handoff.height },
+ controlling: false,
+ window: { app: handoff.app, ...(handoff.title ? { title: handoff.title } : {}) },
+ }
+ : { lease: randomUUID(), display, controlling: false };
this.active = {
...lease,
peer,
@@ -712,7 +788,9 @@ export class RemoteDesktopController {
expires: this.now() + REMOTE_DESKTOP_LEASE_MS,
sequence: -1,
authenticationSession,
- lockOnExit: request.lockOnExit,
+ // Ending a look at one window never locks the whole computer.
+ lockOnExit: handoff ? undefined : request.lockOnExit,
+ ...(handoff ? { handoff } : {}),
};
this.deps.changed();
return lease;
@@ -729,6 +807,8 @@ export class RemoteDesktopController {
>,
): Promise<unknown> {
const active = this.require(peer, request.lease);
+ if (active.handoff && !HANDOFF_WINDOW_OPS.has(request.op))
+ throw new Error('DESKTOP_HANDOFF_WINDOW_ONLY');
if (
this.displayChanging &&
!['stop', 'heartbeat', 'frame', 'input', 'viewerHidden'].includes(request.op)
@@ -913,11 +993,11 @@ export class RemoteDesktopController {
throw new Error('DESKTOP_LOCK_UNAVAILABLE');
// Plain stop is also used for viewer recovery and display handoff.
// Explicit exit sends lockScreen; involuntary host stops use the policy.
- await this.stop(peer, request.lockScreen === true);
+ await this.stop(peer, request.lockScreen === true && !active.handoff);
return { ok: true };
}
case 'heartbeat':
- if (request.lockOnExit !== undefined) active.lockOnExit = request.lockOnExit;
+ if (request.lockOnExit !== undefined && !active.handoff) active.lockOnExit = request.lockOnExit;
active.expires = this.now() + REMOTE_DESKTOP_LEASE_MS;
return { controlling: active.controlling };
case 'presentation': {
diff --git a/apps/desktop/src/main/remote-desktop/index.ts b/apps/desktop/src/main/remote-desktop/index.ts
index e0e7a45a27..119d5f9fa5 100644
--- a/apps/desktop/src/main/remote-desktop/index.ts
+++ b/apps/desktop/src/main/remote-desktop/index.ts
@@ -40,7 +40,8 @@ import { DesktopCaptureWindow } from './captureWindow';
import { denyAppDesktopCapture } from './capturePermissions';
import { readDeviceLinkSettings, writeDeviceLinkSetting } from '../device-link/settings-store';
import { throwIpcError } from '../utils/ipcValidate';
-import { RemoteDesktopController } from './controller';
+import { RemoteDesktopController, type DesktopControllerDeps } from './controller';
+import { getInputHandoffService } from '../input-handoff/service';
import { ClipboardCounter } from './clipboardCounter';
import { onQuit } from '../lifecycle';
import {
@@ -325,6 +326,7 @@ function stopVideo(): void {
nativeOverlay = false;
nativeSettings = undefined;
nativeCapture.stop();
+ nativeCapture.setWindow(null);
hyprlandCapture.stop();
linuxAudio.stop();
nativeDisplay = null;
@@ -402,6 +404,11 @@ async function offer(
}
}
stopVideo();
+ // A 代输入 lease shows one window: only the macOS window stream, never a screen source or audio.
+ const handoff = remoteDesktop.handoffWindow(lease.lease);
+ if (handoff && process.platform !== 'darwin') throw new Error('DESKTOP_HANDOFF_UNAVAILABLE');
+ if (handoff && settings?.audio) throw new Error('DESKTOP_AUDIO_UNAVAILABLE');
+ nativeCapture.setWindow(handoff?.windowId ?? null);
preparingOffer = true;
const generation = offerGeneration;
const current = () => generation === offerGeneration && remoteDesktop.hasLease(lease.lease);
@@ -416,7 +423,7 @@ async function offer(
const hyprland = nativeWayland();
if (hyprland && lease.display.id !== WAYLAND_DISPLAY_ID) await linuxMonitor(lease.display.id);
let nativeAvailable = process.platform === 'darwin' || hyprland;
- if (!hyprland) {
+ if (!hyprland && !handoff) {
nativeAvailable ||=
process.platform === 'win32' && (await readWindowsDesktopSupport()) === 'ready';
try {
@@ -456,10 +463,11 @@ async function offer(
: null;
nativeDisplay = nativeAvailable ? lease.display.id : null;
nativeOverlay =
- cursorOverlay === true &&
+ Boolean(handoff) ||
+ (cursorOverlay === true &&
(process.platform === 'darwin' ||
(process.platform === 'win32' && nativeAvailable) ||
- (hyprland && (await readLinuxCursorSupport())));
+ (hyprland && (await readLinuxCursorSupport()))));
if (!current() || host !== currentHost || currentHost.isDestroyed())
throw new Error('DESKTOP_LEASE_EXPIRED');
nativeSettings = settings;
@@ -595,6 +603,41 @@ export async function requestRemoteDesktop(peer: string, value: unknown): Promis
: remoteDesktop.request(peer, value);
}
+/**
+ * 代输入 live view: the window a waiting request is about, chosen here from the
+ * request alone (never by the viewer), sized in points like a display.
+ */
+function handoffWindowDeps(): Pick<
+ DesktopControllerDeps,
+ 'handoffWindow' | 'handoffCurrent' | 'handoffEnded'
+> {
+ return {
+ handoffWindow: async (requestId) => {
+ const live = await getInputHandoffService()?.liveWindow(requestId);
+ if (!live) return null;
+ const [x, y, width, height] = live.frame as [number, number, number, number];
+ const display = screen.getDisplayMatching({
+ x: Math.round(x),
+ y: Math.round(y),
+ width: Math.max(1, Math.round(width)),
+ height: Math.max(1, Math.round(height)),
+ });
+ return {
+ requestId,
+ windowId: live.windowId,
+ pid: live.pid,
+ displayId: String(display.id),
+ app: live.app,
+ ...(live.title ? { title: live.title } : {}),
+ width: Math.max(1, Math.round(width)),
+ height: Math.max(1, Math.round(height)),
+ };
+ },
+ handoffCurrent: (requestId) => getInputHandoffService()?.isCurrent(requestId) ?? false,
+ handoffEnded: (requestId) => getInputHandoffService()?.liveViewEnded(requestId),
+ };
+}
+
async function setPrivacyScreen(enabled: boolean, current: () => boolean): Promise<void> {
if (enabled && process.platform === 'darwin' && videoLease && nativeDisplay) {
nativeOverlay = true;
@@ -747,8 +790,16 @@ export const remoteDesktop: RemoteDesktopController = new RemoteDesktopControlle
if (preparingOffer) return null;
// Compatibility viewers must also wake/capture without waiting for
// Chromium's thumbnail enumeration, which may hang on a sleeping display.
+ const handoff = lease ? remoteDesktop.handoffWindow(lease) : null;
+ if (handoff && process.platform !== 'darwin') throw new Error('DESKTOP_HANDOFF_UNAVAILABLE');
if (process.platform === 'darwin' || windowsAvailable) {
- const frame = await nativeCapture.frame(displayId, cursorOverlay === true, nativeSettings);
+ // A 代输入 lease reads only its window (the window stream needs the overlay mode).
+ if (!videoLease) nativeCapture.setWindow(handoff?.windowId ?? null);
+ const frame = await nativeCapture.frame(
+ displayId,
+ Boolean(handoff) || cursorOverlay === true,
+ nativeSettings,
+ );
return encodeNativeRelayFrame(frame, (jpeg) => nativeImage.createFromBuffer(jpeg));
}
const available = await sources(true).catch((error) => {
@@ -843,7 +894,8 @@ export const remoteDesktop: RemoteDesktopController = new RemoteDesktopControlle
else await waitForDisplayRestore(displayId, expected, beforeChange);
},
createViewerDisplay,
- startInput: async (displayId) => {
+ ...(process.platform === 'darwin' ? handoffWindowDeps() : {}),
+ startInput: async (displayId, window) => {
// A portal-selected window is not the whole compositor coordinate space.
// Never allow a forged control request to drive that view-only fallback.
if (
@@ -851,7 +903,8 @@ export const remoteDesktop: RemoteDesktopController = new RemoteDesktopControlle
(!nativeWayland() || !(await readLinuxDesktopInputSupport()))
)
throw new Error('DESKTOP_INPUT_UNSUPPORTED');
- await input.start(displayId);
+ if (window) await input.start(displayId, { windowId: window.windowId, pid: window.pid });
+ else await input.start(displayId);
},
input: (events) => {
try {
diff --git a/apps/desktop/src/main/remote-desktop/inputHost.ts b/apps/desktop/src/main/remote-desktop/inputHost.ts
index 8d3c9dcdc8..33b70b3201 100644
--- a/apps/desktop/src/main/remote-desktop/inputHost.ts
+++ b/apps/desktop/src/main/remote-desktop/inputHost.ts
@@ -214,22 +214,36 @@ export class DesktopInputHost {
private stopping: Promise<void> = Promise.resolve();
private privacyPaused = false;
private linuxPoint: ((x: number, y: number) => { x: number; y: number }) | null = null;
+ /** 代输入 live view: the helper confines input to this window and maps 0–1 fractions itself. */
+ private window: { windowId: number; pid: number } | null = null;
constructor(
private readonly onFailure: () => void,
private readonly runtime: {
platform?: NodeJS.Platform;
resolveBinary(): Promise<string>;
- spawn(binary: string): ChildProcessWithoutNullStreams;
+ spawn(binary: string, args?: string[]): ChildProcessWithoutNullStreams;
} = {
resolveBinary,
- spawn: (binary: string) => spawn(binary, [], { stdio: 'pipe', windowsHide: true }),
+ spawn: (binary: string, args: string[] = []) =>
+ spawn(binary, args, { stdio: 'pipe', windowsHide: true }),
},
) {}
- async start(displayId: string): Promise<void> {
+ async start(displayId: string, window?: { windowId: number; pid: number }): Promise<void> {
this.stop();
const platform = this.runtime.platform ?? process.platform;
if (platform !== 'darwin' && platform !== 'win32' && platform !== 'linux')
throw new Error('DESKTOP_INPUT_UNSUPPORTED');
+ // Only the macOS helper can keep input inside one window.
+ if (
+ window &&
+ (platform !== 'darwin' ||
+ !Number.isSafeInteger(window.windowId) ||
+ window.windowId <= 0 ||
+ window.windowId > 0xffff_ffff ||
+ !Number.isSafeInteger(window.pid) ||
+ window.pid <= 0)
+ )
+ throw new Error('DESKTOP_INPUT_UNSUPPORTED');
if (
platform === 'linux' &&
displayId !== WAYLAND_DISPLAY_ID &&
@@ -268,9 +282,12 @@ export class DesktopInputHost {
}
const binary = await this.runtime.resolveBinary();
if (generation !== this.generation) throw new Error('DESKTOP_LEASE_EXPIRED');
- const child = this.runtime.spawn(binary);
+ const child = window
+ ? this.runtime.spawn(binary, ['--window', String(window.windowId), String(window.pid)])
+ : this.runtime.spawn(binary);
this.child = child;
this.displayId = displayId;
+ this.window = window ? { windowId: window.windowId, pid: window.pid } : null;
child.stderr.resume(); // never log typed text or protocol payloads
child.stdin.on('error', () => {
if (this.child === child) this.onFailure();
@@ -352,6 +369,12 @@ export class DesktopInputHost {
flush();
return; // Wayland's virtual pointer maps normalized coordinates to the output layout.
}
+ if (this.window) {
+ // The helper places fractions on the window's live frame and drops what falls outside.
+ if (!this.child) throw new Error('DESKTOP_INPUT_UNAVAILABLE');
+ if (events.length) this.write(events, this.activity!.begin(events));
+ return;
+ }
const display = screen.getAllDisplays().find((item) => String(item.id) === this.displayId);
if (!display || (!this.child && !this.windows)) throw new Error('DESKTOP_INPUT_UNAVAILABLE');
if (events.length === 0) return;
@@ -427,6 +450,7 @@ export class DesktopInputHost {
async pauseForPrivacy(): Promise<() => Promise<void>> {
if (!this.child && !this.windows) throw new Error('DESKTOP_INPUT_UNAVAILABLE');
const displayId = this.displayId;
+ const window = this.window ?? undefined;
this.stop();
// The old activity stays owned until native exit. Hold a separate existing
// activity reservation for the local confirmation, released by stop/start.
@@ -438,7 +462,7 @@ export class DesktopInputHost {
return async () => {
if (generation !== this.generation) return;
try {
- await this.start(displayId);
+ await this.start(displayId, window);
} catch (error) {
if (!(error instanceof Error && error.message === 'DESKTOP_LEASE_EXPIRED'))
this.onFailure();
@@ -448,6 +472,7 @@ export class DesktopInputHost {
stop(): void {
this.generation++;
this.privacyPaused = false;
+ this.window = null;
this.acknowledge?.(new Error('DESKTOP_LEASE_EXPIRED'));
const windows = this.windows;
const writing = this.writing;
diff --git a/apps/desktop/src/main/remote-desktop/nativeCapture.ts b/apps/desktop/src/main/remote-desktop/nativeCapture.ts
index 15758b85ae..78e3a4ab5b 100644
--- a/apps/desktop/src/main/remote-desktop/nativeCapture.ts
+++ b/apps/desktop/src/main/remote-desktop/nativeCapture.ts
@@ -85,6 +85,53 @@ async function binary(): Promise<string> {
return building;
}
+/**
+ * 代输入 (macOS): one photo of just this window, from the same window-only
+ * stream as the live view. Its own pixels only, whatever covers it; never the
+ * display. Null when it cannot be taken. Nothing is written to disk.
+ */
+export async function photographMacWindow(displayId: string, windowId: number): Promise<Buffer | null> {
+ if (process.platform !== 'darwin' || !/^[0-9]{1,10}$/.test(displayId)) return null;
+ if (!Number.isSafeInteger(windowId) || windowId <= 0 || windowId > 0xffff_ffff) return null;
+ const executable = await binary();
+ return new Promise((resolve) => {
+ // Physical pixels up to 2800 on the long side and a 3 MB frame keep small text and QR codes sharp.
+ const child = spawn(
+ executable,
+ [displayId, 'cursor-overlay', '30', '0.9', '2800', '3000000', `window:${windowId}`],
+ { stdio: 'pipe' },
+ );
+ let text = '';
+ let done = false;
+ const finish = (jpeg: Buffer | null) => {
+ if (done) return;
+ done = true;
+ clearTimeout(timer);
+ child.kill();
+ resolve(jpeg);
+ };
+ const timer = setTimeout(() => finish(null), 5000);
+ child.stderr.resume();
+ child.stdin.on('error', () => undefined);
+ child.on('error', () => finish(null));
+ child.on('exit', () => finish(null));
+ child.stdout.on('data', (chunk: Buffer) => {
+ text += chunk.toString('ascii');
+ if (text.length > 4_200_000) return finish(null);
+ const end = text.indexOf('\n');
+ if (end < 0) return;
+ try {
+ const frame = JSON.parse(text.slice(0, end)) as { jpeg?: unknown };
+ const jpeg = typeof frame.jpeg === 'string' && /^[A-Za-z0-9+/]+={0,2}$/.test(frame.jpeg) ? frame.jpeg : '';
+ finish(jpeg ? Buffer.from(jpeg, 'base64') : null);
+ } catch {
+ finish(null);
+ }
+ });
+ child.stdin.write('f');
+ });
+}
+
/** One capture child for the current lease. No sockets, files, or frame history.
* macOS/Linux use user-session children; Windows uses the authorized SYSTEM broker.
* No adapter keeps frame history on disk.
@@ -98,6 +145,14 @@ export class NativeDesktopCapture {
this.stop();
this.excludedWindows = next;
}
+ private onlyWindow = '';
+ /** 代输入 live view (macOS): capture just this window; null returns to the whole display. */
+ setWindow(id: number | null): void {
+ const next = id && Number.isSafeInteger(id) && id > 0 && id <= 0xffff_ffff ? `window:${id}` : '';
+ if (next === this.onlyWindow) return;
+ this.stop();
+ this.onlyWindow = next;
+ }
get privacyReady(): boolean {
return !!this.excludedWindows && this.confirmedExclusion === this.excludedWindows;
}
@@ -178,6 +233,8 @@ export class NativeDesktopCapture {
)
return null;
if (this.busy) return null;
+ // A window view exists only as the macOS overlay stream; never widen it to the display.
+ if (this.onlyWindow && (linux || !overlay)) return null;
if (this.display && this.display !== display) this.stop();
this.busy = true;
const generation = this.generation;
@@ -204,7 +261,8 @@ export class NativeDesktopCapture {
String(profile.maxFrameBytes),
]
: [display];
- if (!linux && this.excludedWindows) args.push(this.excludedWindows);
+ if (!linux && this.onlyWindow) args.push(this.onlyWindow);
+ else if (!linux && this.excludedWindows) args.push(this.excludedWindows);
const child = spawn(executable, args, { stdio: 'pipe' });
this.child = child;
this.display = display;
diff --git a/apps/desktop/src/main/sessionNotificationCopy.ts b/apps/desktop/src/main/sessionNotificationCopy.ts
index 9af56db8ca..b8ce027725 100644
--- a/apps/desktop/src/main/sessionNotificationCopy.ts
+++ b/apps/desktop/src/main/sessionNotificationCopy.ts
@@ -35,6 +35,11 @@ export function getSessionExternalNotificationText(title: string, kind: SessionE
return t(EXTERNAL_KEY_BY_KIND[kind]).replaceAll('{{title}}', () => title);
}
+/** 代输入 push body: fixed copy, never the screen or the agent's purpose text. */
+export function getInputHandoffNotificationBody(): string {
+ return t('settings.notifications.sessionEvent.inputHandoff');
+}
+
export function getTeammateNotificationFallback(): string {
return t('settings.notifications.sessionEvent.newReply');
}
diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.ts
index cdb1a2a3c4..3a6f46946e 100644
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@ -4545,7 +4545,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
// ── Device Link (设备互联/跨设备远程控制) ─────────────────────────────
// 同账号设备经 server relay 互联;此处只暴露开关 + 设备列表管理面,
// 隧道(远程会话控制)在 M3 接入。
- openRemoteDesktop: (target: { deviceId: string; name: string }): Promise<void> =>
+ openRemoteDesktop: (target: { deviceId: string; name: string; handoff?: string }): Promise<void> =>
ipcRenderer.invoke(REMOTE_VIEWER.OPEN, target),
remoteDesktop: {
state: (checkWindowsSupport) => ipcRenderer.invoke(DESKTOP_LOCAL.STATE, checkWindowsSupport),
@@ -6935,6 +6935,31 @@ contextBridge.exposeInMainWorld('electronAPI', {
): Promise<import('../shared/pluginOauthDeviceCode').PluginOauthDeviceCodeView | null> =>
ipcRenderer.invoke('plugin-oauth:device-code', request),
+ /** 代输入 values for a task on this computer; trusted top-level frame only, never remote. */
+ submitInputHandoff: (requestId: string, submission: unknown): Promise<{ accepted: boolean }> =>
+ ipcRenderer.invoke('input-handoff:submit', requestId, submission),
+ /** 代输入 values for a task on another computer, over the signed v3 exchange. */
+ submitRemoteInputHandoff: (
+ request: import('../shared/pluginOauth').LocalInputHandoffRequest,
+ ): Promise<{ accepted: boolean }> => ipcRenderer.invoke('plugin-oauth:submit-input', request),
+ /** 代输入 screenshot step on this computer; trusted top-level frame only. */
+ getInputHandoffPicture: (
+ requestId: string,
+ revision: number,
+ ): Promise<import('@cindy/device-link').InputHandoffPicture | null> =>
+ ipcRenderer.invoke('input-handoff:picture', requestId, revision),
+ /** 代输入 screenshot step on another computer: the sealed picture for this window only. */
+ openRemoteInputHandoffPicture: (
+ request: import('../shared/pluginOauth').LocalInputHandoffPictureRequest,
+ ): Promise<{ token: string; picture: import('@cindy/device-link').InputHandoffPicture }> =>
+ ipcRenderer.invoke('plugin-oauth:open-input-picture', request),
+ /** The owner's tap or typing on an opened remote screenshot step; null closes it. */
+ answerRemoteInputHandoffPicture: (
+ token: string,
+ submission: unknown,
+ ): Promise<{ accepted: boolean }> =>
+ ipcRenderer.invoke('plugin-oauth:answer-input-picture', { token, submission }),
+
/** Local-only Secret handoff; Main verifies this is Cindy's trusted top-level frame. */
submitPluginSetupInline: (request: {
requestId: string;
diff --git a/apps/desktop/src/renderer/__tests__/makerQueueState.test.ts b/apps/desktop/src/renderer/__tests__/makerQueueState.test.ts
index f25d60386a..ef19a45d83 100644
--- a/apps/desktop/src/renderer/__tests__/makerQueueState.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerQueueState.test.ts
@@ -127,6 +127,7 @@ const state = (overrides: Partial<SessionChatState> = {}): SessionChatState => (
lastAgentMeta: null,
...overrides,
pendingRemoteDesktopConfirmation: overrides.pendingRemoteDesktopConfirmation ?? null,
+ pendingInputHandoff: overrides.pendingInputHandoff ?? null,
pendingRemoteDesktopConfirmationQueue:
overrides.pendingRemoteDesktopConfirmationQueue ?? [],
});
diff --git a/apps/desktop/src/renderer/components/chat/MessageStream.tsx b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
index 611d8d15d5..3027f3b1cd 100644
--- a/apps/desktop/src/renderer/components/chat/MessageStream.tsx
+++ b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
@@ -94,6 +94,7 @@ import type {
ContinuationInFlightProjectionCapability,
} from '@/hooks/useCCAgentChat';
import { findLastUserInputClientId, isAutoResumeRowInFlight } from '@/lib/autoResumePresentation';
+import { InputHandoffRecordRow, readInputHandoffRecordData } from '@/features/input-handoff/InputHandoffRecordRow';
export { findLastUserInputClientId, isAutoResumeRowInFlight } from '@/lib/autoResumePresentation';
import { Spinner } from '@/components/ui/spinner';
import { useMessageNavRailPreference } from '@/hooks/useMessageNavRailPreference';
@@ -6754,6 +6755,10 @@ const MessageItem = memo(function MessageItem({
}) {
// silent-stop 自动续跑行(isSyntheticTrigger + systemCardType):渲染成
// 「已自动继续」分隔线,必须在 synthetic early-return 之前检查,否则分隔线被吞。
+ if (message.role === 'user' && message.systemCardType === 'input-handoff') {
+ const record = readInputHandoffRecordData(message.systemCardData);
+ return record ? <InputHandoffRecordRow record={record} at={message.createdAt} /> : null;
+ }
if (message.role === 'user' && message.systemCardType) {
return (
<SystemCard
diff --git a/apps/desktop/src/renderer/components/chat/SystemCard.tsx b/apps/desktop/src/renderer/components/chat/SystemCard.tsx
index 766b30b6aa..0071b479f5 100644
--- a/apps/desktop/src/renderer/components/chat/SystemCard.tsx
+++ b/apps/desktop/src/renderer/components/chat/SystemCard.tsx
@@ -1,4 +1,5 @@
import { formatCompactionDuration, formatSessionDuration, formatShellDuration } from '@/lib/sessionDurationFormat';
+import { InputHandoffRecordRow, readInputHandoffRecordData } from '@/features/input-handoff/InputHandoffRecordRow';
import { Button } from '@/components/ui/button';
import { BotSessionTaskResultCard } from '@/features/bots/BotSessionTaskResultCard';
/**
@@ -56,6 +57,7 @@ import { getSessionDeviceId } from '@/features/device-link/remoteProjectsStore';
interface SystemCardProps {
cardType:
+ | 'input-handoff'
| 'cindy-make-doctor'
| 'cindy-make'
| 'help'
@@ -1462,6 +1464,10 @@ export function SystemCard({
return <BotAuthorizationCardView data={data} sessionId={sessionId} />;
case 'bot-direct-message':
return <BotDirectMessageCard data={data} sessionId={sessionId} />;
+ case 'input-handoff': {
+ const record = readInputHandoffRecordData(data);
+ return record ? <InputHandoffRecordRow record={record} at={typeof data?.at === 'string' ? data.at : undefined} /> : null;
+ }
default:
return null;
}
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupPendingInteraction.tsx b/apps/desktop/src/renderer/features/bots/BotGroupPendingInteraction.tsx
index dbc683c1a4..cc6b31498f 100644
--- a/apps/desktop/src/renderer/features/bots/BotGroupPendingInteraction.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotGroupPendingInteraction.tsx
@@ -3,7 +3,7 @@
*
* 群专线是一条普通 Cindy Session:权限请求 / 提问经 maker 事件进入 makerChatStore,
* 与任务页是同一份状态(按 sessionId 分片),这里只读它的轻量快照并复用任务页的
- * PermissionPrompt / AskUserQuestionPrompt,作答也走同一条 store 动作。其它交互(计划
+ * PermissionPrompt / AskUserQuestionPrompt / InputHandoffCard,作答也走同一条路径。其它交互(计划
* 审阅、插件配置等)在群里只提示「在等你确认」。
*
* 灵动岛活动镜像报告等待交互、store 里却没有卡片时(窗口刚重载、错过了实时推送),
@@ -16,6 +16,7 @@ import { useTranslation } from 'react-i18next';
import { AskUserQuestionPrompt } from '@/components/new-chat/AskUserQuestionPrompt';
import { PermissionPrompt } from '@/components/new-chat/PermissionPrompt';
+import { InputHandoffCard } from '@/features/input-handoff/InputHandoffCard';
import { makerChatStore } from '@/lib/makerChatStore';
import { useAgentIslandActivity } from '@/state/agentIslandActivity';
import type { BotChatIdentity } from './BotSessionContentHeader';
@@ -66,6 +67,15 @@ export function BotGroupPendingInteraction({
/>
);
}
+ if (light.pendingInputHandoff) {
+ return (
+ <InputHandoffCard
+ key={light.pendingInputHandoff.requestId}
+ sessionId={sessionId}
+ snapshot={light.pendingInputHandoff}
+ />
+ );
+ }
const waiting =
activity?.phase === 'needs-interaction' ||
light.pendingPlanReview !== null ||
diff --git a/apps/desktop/src/renderer/features/bots/BotsHomeView.tsx b/apps/desktop/src/renderer/features/bots/BotsHomeView.tsx
index 01296342c6..47da6aeec0 100644
--- a/apps/desktop/src/renderer/features/bots/BotsHomeView.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotsHomeView.tsx
@@ -1,4 +1,5 @@
import { Button } from '@/components/ui/button';
+import { Switch } from '@/components/ui/switch';
import { Textarea } from '@/components/ui/input';
import { shouldShowOpenPathError } from '../../../shared/openPathResult';
import { ConnectProviderCard } from '@/components/onboarding/ConnectProviderCard';
@@ -662,6 +663,18 @@ export function BotSettings({
autosave.onEdit('instant');
}}
/>
+ <div className="mt-5 flex items-start gap-3 border-t border-[var(--border-default)] pt-4">
+ <div className="min-w-0 flex-1">
+ <p className="text-13 font-medium text-[var(--text-primary)]">{t('bots.capabilities.inputHandoff.title')}</p>
+ <p className="mt-1 text-12 leading-5 text-[var(--text-secondary)]">{t('bots.capabilities.inputHandoff.description')}</p>
+ </div>
+ <Switch
+ aria-label={t('bots.capabilities.inputHandoff.title')}
+ className="mt-0.5 shrink-0"
+ checked={capabilities.inputHandoff !== false}
+ onCheckedChange={(value) => updateCapability('inputHandoff', value === true)}
+ />
+ </div>
</div>
)}
{page === 'history' ? (
diff --git a/apps/desktop/src/renderer/features/bots/botStore.ts b/apps/desktop/src/renderer/features/bots/botStore.ts
index 878e438a15..4134ca742f 100644
--- a/apps/desktop/src/renderer/features/bots/botStore.ts
+++ b/apps/desktop/src/renderer/features/bots/botStore.ts
@@ -55,6 +55,8 @@ export interface BotCapabilities {
mcpServers: string[];
memory: boolean;
permissions: 'ask' | 'auto' | 'trusted';
+ /** 代输入: may this companion ask the owner to finish an on-screen step. Missing = allowed. */
+ inputHandoff?: boolean;
}
export interface BotModelOverride {
@@ -467,6 +469,7 @@ function defaultCapabilities(
mcpMode: 'inherit',
mcpServers: [],
memory: true,
+ inputHandoff: true,
// 新建伙伴默认放手做(产品裁决 2026-08-18)。**只作用于「新建」**:读取既有
// profile 的两条路径都显式跑 normalizeBotPermissions,缺字段的历史数据仍落
// 'ask',与 main 侧投影一致,不会因为默认值变了就把老伙伴悄悄升成信任。
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
index a81fdbaf42..45e5023b51 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
@@ -93,6 +93,7 @@ import { PermissionPrompt } from '@/components/new-chat/PermissionPrompt';
import { IssueConfirmCard } from './IssueConfirmCard';
import { RenameSessionsConfirmCard } from './RenameSessionsConfirmCard';
import { GhostGrantConfirmCard } from './GhostGrantConfirmCard';
+import { InputHandoffCard } from '@/features/input-handoff/InputHandoffCard';
import { RemoteDesktopConfirmationNotice } from './RemoteDesktopConfirmationNotice';
import { AskUserQuestionPrompt } from '@/components/new-chat/AskUserQuestionPrompt';
import { PluginSetupPrompt } from '@/components/new-chat/PluginSetupPrompt';
@@ -1792,6 +1793,7 @@ function CCAgentSessionContent({
respondToRenameSessionsConfirm,
pendingGhostGrantConfirm,
pendingRemoteDesktopConfirmation,
+ pendingInputHandoff,
respondToGhostGrantConfirm,
lastExpandedPlanViewerState,
updatePlanContent,
@@ -5262,7 +5264,8 @@ function CCAgentSessionContent({
pendingIssueConfirm ||
pendingRenameSessionsConfirm ||
pendingGhostGrantConfirm ||
- pendingRemoteDesktopConfirmation
+ pendingRemoteDesktopConfirmation ||
+ pendingInputHandoff
)
}
className="mb-0"
@@ -5486,7 +5489,8 @@ function CCAgentSessionContent({
pendingIssueConfirm ||
pendingRenameSessionsConfirm ||
pendingGhostGrantConfirm ||
- pendingRemoteDesktopConfirmation
+ pendingRemoteDesktopConfirmation ||
+ pendingInputHandoff
)
}
placeholder={
@@ -5564,6 +5568,13 @@ function CCAgentSessionContent({
pending={pendingGhostGrantConfirm}
onRespond={respondToGhostGrantConfirm}
/>
+ ) : pendingInputHandoff && sessionId && !isSharedTaskPeer(remoteDeviceId ?? '') ? (
+ <InputHandoffCard
+ key={pendingInputHandoff.requestId}
+ sessionId={sessionId}
+ snapshot={pendingInputHandoff}
+ remote={!!remoteDeviceId}
+ />
) : pendingRemoteDesktopConfirmation ? (
<RemoteDesktopConfirmationNotice
key={pendingRemoteDesktopConfirmation.requestId}
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
index 232f3e7116..75bc875735 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
@@ -112,12 +112,13 @@ const CARD_TITLE_META_SLOT_CLASS =
*/
function getNeutralAwaitingKind(
sessionId: string,
-): 'permission' | 'plan_review' | 'ask_user' | 'plugin_setup' | '' {
+): 'permission' | 'plan_review' | 'ask_user' | 'plugin_setup' | 'input_handoff' | '' {
const info = makerChatStore.getRunningSnapshot().get(sessionId);
if (info?.hasPendingPermission) return 'permission';
if (info?.hasPendingPlanReview) return 'plan_review';
if (info?.hasPendingAskUser) return 'ask_user';
if (info?.hasPendingPluginSetup) return 'plugin_setup';
+ if (info?.hasPendingInputHandoff) return 'input_handoff';
return '';
}
@@ -257,7 +258,9 @@ export const SessionCard = withSidebarNavigation<SessionCardProps>(function Sess
? t('ccAgent.sidebar.card.awaitingPlan')
: awaitingKind === 'plugin_setup'
? t('ccAgent.sidebar.card.awaitingPluginSetup')
- : t('ccAgent.sidebar.card.awaitingQuestion');
+ : awaitingKind === 'input_handoff'
+ ? t('ccAgent.sidebar.card.awaitingInputHandoff')
+ : t('ccAgent.sidebar.card.awaitingQuestion');
const runningDetail =
islandActivity?.phase === 'running' && islandActivity.compactDetail
? islandActivity.compactDetail
diff --git a/apps/desktop/src/renderer/features/input-handoff/InputHandoffCard.tsx b/apps/desktop/src/renderer/features/input-handoff/InputHandoffCard.tsx
new file mode 100644
index 0000000000..cebe63fe10
--- /dev/null
+++ b/apps/desktop/src/renderer/features/input-handoff/InputHandoffCard.tsx
@@ -0,0 +1,497 @@
+/**
+ * InputHandoffCard (代输入)
+ * ---------------------------------------------------------------------------
+ * A strip above the composer says where the computer needs the owner; 填写
+ * (or 扫码) opens the dialog with just what the owner fills in. The Host reads
+ * one screen of the target UI and shows it as standard fields. Values the
+ * owner types stay in the form's local state and leave only through
+ * makerTransport.submitInputHandoff — never the store, the transcript or the
+ * model. Each new screen remounts the form, so a stale draft can never be
+ * applied to a different screen.
+ *
+ * Password fields are plain `type="password"` + `autocomplete` hints so the
+ * platform password manager (1Password, Passwords) can fill them.
+ */
+
+import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import type {
+ InputHandoffAction,
+ InputHandoffSnapshot,
+ InputHandoffValues,
+} from '@cindy/device-link';
+import {
+ inputHandoffHeldElsewhere,
+ inputHandoffPresentation,
+ inputHandoffStepKey,
+} from '@cindy/device-link';
+import { useOptionalAuthDeviceId } from '@/contexts/AuthContext';
+import { Button } from '@/components/ui/button';
+import { Spinner } from '@/components/ui/spinner';
+import { getStickySessionDeviceId } from '@/features/device-link/stickySessionOrigin';
+import { useDeviceLinkDeviceList } from '@/features/device-link/useDeviceLinkDeviceList';
+import { toast } from '@/lib/toast';
+import { makerApiForSticky, submitInputHandoff } from '@/lib/makerTransport';
+import { cn } from '@/lib/utils';
+import { InputHandoffDeviceCode } from './InputHandoffDeviceCode';
+import { InputHandoffDialog, InputHandoffPlace, inputHandoffIcon } from './InputHandoffDialog';
+import { InputHandoffPictureStep } from './InputHandoffPictureStep';
+import { InputHandoffQrStep } from './InputHandoffQrStep';
+import { CONTINUE_ATTR, InputHandoffStepForm } from './InputHandoffStepForm';
+import {
+ changedValues,
+ inputHandoffDialogHasContent,
+ inputHandoffDialogMode,
+ inputHandoffPlace,
+} from './inputHandoffModel';
+
+export interface InputHandoffCardProps {
+ sessionId: string;
+ snapshot: InputHandoffSnapshot;
+ /** The task runs on another computer (values go through the signed relay). */
+ remote?: boolean;
+}
+
+type Decision = 'done' | 'cancel' | 'stay' | 'refresh' | 'claim' | 'picture';
+
+interface StripAction {
+ label: string;
+ primary?: boolean;
+ onClick: () => void;
+}
+
+export function InputHandoffCard({ sessionId, snapshot, remote }: InputHandoffCardProps) {
+ const { t } = useTranslation();
+ const [busy, setBusy] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ // Stays wanted across steps: after Continue the dialog hides while the
+ // computer types and comes back by itself for the next screen to fill.
+ const [dialogWanted, setDialogWanted] = useState(false);
+
+ // A new screen clears any message about the previous one.
+ const stepKey = inputHandoffStepKey(snapshot);
+ useEffect(() => {
+ setError(null);
+ setBusy(false);
+ }, [stepKey]);
+ useEffect(() => {
+ if (snapshot.terminal) setDialogWanted(false);
+ }, [snapshot.terminal]);
+
+ const decide = useCallback(
+ async (action: Decision) => {
+ setBusy(true);
+ setError(null);
+ try {
+ const result = await makerApiForSticky(sessionId).resolveInteraction(snapshot.requestId, {
+ kind: 'input_handoff',
+ action,
+ expectedRevision: snapshot.revision,
+ });
+ if (!result.accepted) setError(t('inputHandoff.error.stale'));
+ } catch {
+ setError(t('inputHandoff.error.decision'));
+ } finally {
+ setBusy(false);
+ }
+ },
+ [sessionId, snapshot.requestId, snapshot.revision, t],
+ );
+
+ const submit = useCallback(
+ async (draft: InputHandoffValues, action: InputHandoffAction) => {
+ setBusy(true);
+ setError(null);
+ try {
+ const result = await submitInputHandoff(sessionId, {
+ submission: {
+ expectedRevision: snapshot.revision,
+ values: changedValues(snapshot, draft),
+ action,
+ },
+ presentation: inputHandoffPresentation(snapshot),
+ });
+ if (!result.accepted) setError(t('inputHandoff.error.stale'));
+ return result.accepted;
+ } catch {
+ setError(t('inputHandoff.error.submit'));
+ return false;
+ } finally {
+ setBusy(false);
+ }
+ },
+ [sessionId, snapshot, t],
+ );
+
+ // Starting to type on an unheld screen takes the handoff quietly, so other
+ // devices show "being handled on …". It never blocks the field being typed in.
+ const claimQuietly = useCallback(() => {
+ if (snapshot.holder) return;
+ void makerApiForSticky(sessionId)
+ .resolveInteraction(snapshot.requestId, {
+ kind: 'input_handoff',
+ action: 'claim',
+ expectedRevision: snapshot.revision,
+ })
+ .catch(() => undefined);
+ }, [sessionId, snapshot.holder, snapshot.requestId, snapshot.revision]);
+
+ const inputBlocked = remote === true && snapshot.remoteInput !== true;
+ const selfDeviceId = useOptionalAuthDeviceId();
+ const heldElsewhere = inputHandoffHeldElsewhere(
+ snapshot,
+ remote === true ? { deviceId: selfDeviceId } : { local: true },
+ );
+ const liveView = liveViewDevice(sessionId, snapshot);
+ const dialogContent = inputHandoffDialogHasContent(snapshot, heldElsewhere);
+ const qrScan = snapshot.qr === 'scan' && snapshot.picture === true;
+
+ const skip: StripAction = { label: t('inputHandoff.action.skip'), onClick: () => void decide('cancel') };
+ const handBack: StripAction = {
+ label: t('inputHandoff.action.done'),
+ primary: true,
+ onClick: () => void decide('done'),
+ };
+ let status: ReactNode = null;
+ let spinner = false;
+ let actions: StripAction[] = [];
+ if (snapshot.terminal) {
+ status = t(
+ (snapshot.phase === 'failed' || snapshot.failure === 'nothing_to_fill') && snapshot.failure
+ ? `inputHandoff.failure.${snapshot.failure}`
+ : `inputHandoff.terminal.${snapshot.phase}`,
+ );
+ } else if (snapshot.phase === 'ready' && heldElsewhere) {
+ status = t('inputHandoff.holder.elsewhere', { device: holderLabel(snapshot, t) });
+ actions = [
+ skip,
+ {
+ label: t('inputHandoff.action.claim'),
+ primary: true,
+ onClick: () => {
+ setDialogWanted(true);
+ void decide('claim');
+ },
+ },
+ ];
+ } else if (snapshot.phase === 'ready' && snapshot.qr === 'scanned') {
+ // The code was scanned; the sign-in finishes on the phone that scanned it.
+ spinner = true;
+ status = t('inputHandoff.qr.scanned');
+ actions = [skip, handBack];
+ } else if (snapshot.phase === 'ready' && dialogContent) {
+ actions = [
+ skip,
+ {
+ label: t(qrScan ? 'inputHandoff.action.scan' : 'inputHandoff.action.fill'),
+ primary: true,
+ onClick: () => setDialogWanted(true),
+ },
+ ];
+ } else if (snapshot.phase === 'ready') {
+ // Nothing left to type here (the owner stayed on, or an action did not take).
+ status = snapshot.failure ? t(`inputHandoff.failure.${snapshot.failure}`) : t('inputHandoff.nothingLeft');
+ actions = [skip, handBack];
+ } else if (snapshot.phase === 'finishing') {
+ status = <FinishingCountdown until={snapshot.finishingUntil} />;
+ actions = [{ label: t('inputHandoff.action.stay'), onClick: () => void decide('stay') }, handBack];
+ } else {
+ spinner = true;
+ status = t(snapshot.phase === 'working' ? 'inputHandoff.phase.working' : 'inputHandoff.phase.reading');
+ actions = [skip];
+ }
+
+ const place = inputHandoffPlace(snapshot.source);
+ const Icon = inputHandoffIcon(snapshot);
+ const dialogOpen = dialogWanted && dialogContent;
+ return (
+ <section
+ aria-label={snapshot.purpose}
+ data-testid="input-handoff-strip"
+ className={cn(
+ 'w-full max-w-[914px] rounded-[12px] border px-3 py-2.5',
+ 'border-[var(--border-default)] bg-[var(--surface-elevated)] text-[var(--text-primary)]',
+ )}
+ >
+ <div className="flex min-w-0 items-center gap-3">
+ <span className="flex size-9 shrink-0 items-center justify-center rounded-[8px] bg-[var(--surface-chip)] text-[var(--text-primary)]">
+ <Icon size={18} aria-hidden />
+ </span>
+ <div className="min-w-0 flex-1">
+ <p className="truncate text-14 font-medium leading-snug">{snapshot.purpose}</p>
+ <InputHandoffPlace label={place.label} secure={place.secure} />
+ </div>
+ {actions.length > 0 && (
+ <div className="flex shrink-0 items-center gap-2">
+ {actions.map((action) => (
+ <Button
+ key={action.label}
+ size="sm"
+ variant={action.primary ? 'primary' : 'secondary'}
+ tone={action.primary ? 'default' : 'quiet'}
+ disabled={busy}
+ onClick={action.onClick}
+ >
+ {action.label}
+ </Button>
+ ))}
+ </div>
+ )}
+ </div>
+ {status && (
+ <div className="mt-2 flex items-center gap-2 pl-12 text-13 text-[var(--text-secondary)]" role="status">
+ {spinner && <Spinner size={14} />}
+ <span className="min-w-0 [overflow-wrap:anywhere]">{status}</span>
+ </div>
+ )}
+ {error && !dialogOpen && (
+ <p role="alert" className="mt-2 pl-12 text-12 text-[var(--error-fg)]">
+ {error}
+ </p>
+ )}
+ {liveView && !dialogContent && (
+ <div className="mt-1 pl-12">
+ <LiveViewLink deviceId={liveView} requestId={snapshot.requestId} />
+ </div>
+ )}
+ {dialogContent && (
+ <InputHandoffStepDialog
+ open={dialogOpen}
+ sessionId={sessionId}
+ snapshot={snapshot}
+ busy={busy}
+ inputBlocked={inputBlocked}
+ error={error}
+ liveView={liveView}
+ onError={setError}
+ onDecide={(action) => void decide(action)}
+ onSubmit={submit}
+ onStart={claimQuietly}
+ onClose={() => setDialogWanted(false)}
+ />
+ )}
+ </section>
+ );
+}
+
+function InputHandoffStepDialog({
+ open,
+ sessionId,
+ snapshot,
+ busy,
+ inputBlocked,
+ error,
+ liveView,
+ onError,
+ onDecide,
+ onSubmit,
+ onStart,
+ onClose,
+}: {
+ open: boolean;
+ sessionId: string;
+ snapshot: InputHandoffSnapshot;
+ busy: boolean;
+ inputBlocked: boolean;
+ error: string | null;
+ /** The computer running the task, when it offers a live view of the window. */
+ liveView: string | null;
+ onError: (message: string | null) => void;
+ onDecide: (action: Decision) => void;
+ onSubmit: (draft: InputHandoffValues, action: InputHandoffAction) => Promise<boolean>;
+ onStart: () => void;
+ onClose: () => void;
+}) {
+ const { t } = useTranslation();
+ const mode = inputHandoffDialogMode(snapshot);
+ const formId = `input-handoff-${snapshot.requestId}`;
+ // One picture or code per revision: remount so it is fetched afresh, and never claim
+ // quietly there (that bumps the revision).
+ const revisionKey = `${snapshot.requestId}:${snapshot.revision}`;
+ let body: ReactNode;
+ let footer: ReactNode = null;
+ if (mode === 'qr') {
+ body = (
+ <InputHandoffQrStep
+ key={revisionKey}
+ sessionId={sessionId}
+ snapshot={snapshot}
+ busy={busy}
+ inputBlocked={inputBlocked}
+ onError={onError}
+ />
+ );
+ } else if (mode === 'picture') {
+ body = (
+ <InputHandoffPictureStep
+ key={revisionKey}
+ sessionId={sessionId}
+ snapshot={snapshot}
+ busy={busy}
+ inputBlocked={inputBlocked}
+ onDecide={onDecide}
+ onError={onError}
+ />
+ );
+ } else {
+ body = (
+ <>
+ <InputHandoffDeviceCode snapshot={snapshot} />
+ {mode === 'fields' && (
+ <InputHandoffStepForm
+ key={inputHandoffStepKey(snapshot)}
+ formId={formId}
+ snapshot={snapshot}
+ busy={busy}
+ inputBlocked={inputBlocked}
+ onSubmit={onSubmit}
+ onStart={onStart}
+ />
+ )}
+ </>
+ );
+ footer = (
+ <div className="flex flex-col gap-2">
+ <p className="text-center text-12 leading-relaxed text-[var(--text-tertiary)]">
+ {t('inputHandoff.dialogNote')}
+ </p>
+ {mode === 'code' ? (
+ <Button size="lg" variant="cta" palette="confirmation" disabled={busy} onClick={() => onDecide('done')}>
+ {t('inputHandoff.action.done')}
+ </Button>
+ ) : (
+ <Button
+ type="submit"
+ form={formId}
+ size="lg"
+ variant="cta"
+ palette="confirmation"
+ loading={busy}
+ disabled={busy || inputBlocked}
+ {...{ [CONTINUE_ATTR]: '' }}
+ >
+ {t('inputHandoff.action.continue')}
+ </Button>
+ )}
+ <Button size="lg" variant="secondary" palette="confirmation" onClick={onClose}>
+ {t('inputHandoff.action.close')}
+ </Button>
+ </div>
+ );
+ }
+ // A terminal prompt has no screen to look at; a picture step already is one, except a QR code cut out of it.
+ const canPicture = !snapshot.command && mode !== 'picture';
+ const links =
+ canPicture || liveView ? (
+ <>
+ {canPicture && (
+ <QuietLink disabled={busy} onClick={() => onDecide('picture')}>
+ {t('inputHandoff.action.picture')}
+ </QuietLink>
+ )}
+ {liveView && <LiveViewLink deviceId={liveView} requestId={snapshot.requestId} />}
+ </>
+ ) : null;
+ return (
+ <InputHandoffDialog
+ open={open}
+ snapshot={snapshot}
+ inputBlocked={inputBlocked}
+ error={error}
+ footer={footer}
+ links={links}
+ onClose={onClose}
+ >
+ {body}
+ </InputHandoffDialog>
+ );
+}
+
+function QuietLink({
+ children,
+ disabled,
+ onClick,
+}: {
+ children: ReactNode;
+ disabled?: boolean;
+ onClick: () => void;
+}) {
+ return (
+ <button
+ type="button"
+ disabled={disabled}
+ onClick={onClick}
+ className="min-h-8 text-12 text-[var(--text-tertiary)] transition-colors enabled:hover:text-[var(--text-secondary)] disabled:opacity-60"
+ >
+ {children}
+ </button>
+ );
+}
+
+/**
+ * The host offers a live view of just the target window (remote desktop is on
+ * there). Navigation only: the host picks the window from the request id and
+ * keeps input inside it; this device never names a window.
+ */
+function liveViewDevice(sessionId: string, snapshot: InputHandoffSnapshot): string | null {
+ const deviceId = getStickySessionDeviceId(sessionId);
+ return deviceId && snapshot.liveView && !snapshot.terminal ? deviceId : null;
+}
+
+function LiveViewLink({ deviceId, requestId }: { deviceId: string; requestId: string }) {
+ const { t } = useTranslation();
+ const devices = useDeviceLinkDeviceList();
+ const [opening, setOpening] = useState(false);
+ const mounted = useRef(true);
+ useEffect(
+ () => () => {
+ mounted.current = false;
+ },
+ [],
+ );
+ const name = devices?.find((device) => device.deviceId === deviceId)?.name || deviceId;
+ return (
+ <QuietLink
+ disabled={opening}
+ onClick={() => {
+ setOpening(true);
+ void window.electronAPI
+ .openRemoteDesktop({ deviceId, name, handoff: requestId })
+ .catch(() => toast.error(t('remoteDesktop.connectionError')))
+ .finally(() => {
+ if (mounted.current) setOpening(false);
+ });
+ }}
+ >
+ {t('inputHandoff.action.liveView')}
+ </QuietLink>
+ );
+}
+
+function holderLabel(snapshot: InputHandoffSnapshot, t: (key: string) => string): string {
+ const holder = snapshot.holder;
+ if (holder?.local) return t('inputHandoff.holder.host');
+ if (holder?.name) return holder.name;
+ return t(
+ holder?.platform === 'mobile' ? 'inputHandoff.holder.phone' : 'inputHandoff.holder.otherDevice',
+ );
+}
+
+function FinishingCountdown({ until }: { until?: number }) {
+ const { t } = useTranslation();
+ const [now, setNow] = useState(() => Date.now());
+ useEffect(() => {
+ if (!until) return;
+ const timer = window.setInterval(() => setNow(Date.now()), 250);
+ return () => window.clearInterval(timer);
+ }, [until]);
+ const seconds = until ? Math.max(0, Math.ceil((until - now) / 1000)) : 0;
+ return (
+ <>
+ {until
+ ? t('inputHandoff.phase.finishing', { count: seconds })
+ : t('inputHandoff.phase.finishingNow')}
+ </>
+ );
+}
diff --git a/apps/desktop/src/renderer/features/input-handoff/InputHandoffDeviceCode.tsx b/apps/desktop/src/renderer/features/input-handoff/InputHandoffDeviceCode.tsx
new file mode 100644
index 0000000000..654c925267
--- /dev/null
+++ b/apps/desktop/src/renderer/features/input-handoff/InputHandoffDeviceCode.tsx
@@ -0,0 +1,69 @@
+import { Copy, ExternalLink } from 'lucide-react';
+import { useTranslation } from 'react-i18next';
+
+import { isInputHandoffDeviceCode, type InputHandoffSnapshot } from '@cindy/device-link';
+import { Button } from '@/components/ui/button';
+import { toast } from '@/lib/toast';
+
+/**
+ * Device-code sign-in: the screen only shows a code and a link. The owner
+ * copies the code and opens the link here, where their browser is already
+ * signed in; nothing is typed into the window. The link is checked again
+ * (https, shown origin) before it is opened.
+ */
+export function InputHandoffDeviceCode({ snapshot }: { snapshot: InputHandoffSnapshot }) {
+ const { t } = useTranslation();
+ const deviceCode = snapshot.deviceCode;
+ if (!isInputHandoffDeviceCode(deviceCode)) return null;
+ return (
+ <div
+ aria-live="polite"
+ className="mb-4 flex flex-col gap-3 rounded-[10px] border border-[var(--border-default)] bg-[var(--surface-card-ivory)] p-3"
+ >
+ <span className="text-12 text-[var(--text-secondary)]">
+ {t('inputHandoff.deviceCode.prompt')}
+ </span>
+ <code className="select-all text-20 font-semibold tracking-[0.16em] text-[var(--text-primary)]">
+ {deviceCode.code}
+ </code>
+ <div className="flex flex-wrap items-center gap-2">
+ <Button
+ variant="secondary"
+ size="sm"
+ type="button"
+ onClick={() => {
+ void Promise.resolve()
+ .then(() => navigator.clipboard.writeText(deviceCode.code))
+ .then(() => toast.success(t('inputHandoff.deviceCode.copied')))
+ .catch(() => toast.error(t('inputHandoff.deviceCode.copyFailed')));
+ }}
+ >
+ <Copy size={13} aria-hidden />
+ {t('inputHandoff.deviceCode.copy')}
+ </Button>
+ <Button
+ variant="secondary"
+ size="sm"
+ type="button"
+ onClick={() => {
+ void window.electronAPI
+ .openExternal(deviceCode.url)
+ .then((result) => {
+ if (!result.success) toast.error(t('inputHandoff.deviceCode.openFailed'));
+ })
+ .catch(() => toast.error(t('inputHandoff.deviceCode.openFailed')));
+ }}
+ >
+ <ExternalLink size={13} aria-hidden />
+ {t('inputHandoff.deviceCode.open')}
+ <span className="font-mono font-normal text-[var(--text-tertiary)]">
+ · {deviceCode.origin}
+ </span>
+ </Button>
+ </div>
+ <span className="text-12 text-[var(--text-tertiary)]">
+ {t('inputHandoff.deviceCode.then')}
+ </span>
+ </div>
+ );
+}
diff --git a/apps/desktop/src/renderer/features/input-handoff/InputHandoffDialog.tsx b/apps/desktop/src/renderer/features/input-handoff/InputHandoffDialog.tsx
new file mode 100644
index 0000000000..37c82ec730
--- /dev/null
+++ b/apps/desktop/src/renderer/features/input-handoff/InputHandoffDialog.tsx
@@ -0,0 +1,137 @@
+/**
+ * The 代输入 dialog, opened from the strip above the composer. Same reading
+ * order as on the phone: what the agent needs, where it goes (lock + site, or
+ * the app), anything to check first, then only what the owner fills in. It
+ * closes without ending the handoff; the strip stays until it is done.
+ */
+
+import type { ReactNode } from 'react';
+import * as Dialog from '@radix-ui/react-dialog';
+import { AlertTriangle, AppWindow, Globe, Lock, QrCode, SquareTerminal } from 'lucide-react';
+import { useTranslation } from 'react-i18next';
+
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+import { inputHandoffPlace, inputHandoffPlaceKind } from './inputHandoffModel';
+
+export interface InputHandoffDialogProps {
+ open: boolean;
+ snapshot: InputHandoffSnapshot;
+ /** This device cannot send input to the computer running the task. */
+ inputBlocked: boolean;
+ error: string | null;
+ /** The step itself: fields, the QR code, a sign-in code or the picture. */
+ children: ReactNode;
+ /** Primary and Cancel; absent on steps whose own content holds the actions. */
+ footer?: ReactNode;
+ /** Quiet links under the footer (see the window, live view). */
+ links?: ReactNode;
+ onClose: () => void;
+}
+
+export function InputHandoffDialog({
+ open,
+ snapshot,
+ inputBlocked,
+ error,
+ children,
+ footer,
+ links,
+ onClose,
+}: InputHandoffDialogProps) {
+ const { t } = useTranslation();
+ return (
+ <Dialog.Root open={open} onOpenChange={(next) => !next && onClose()}>
+ <Dialog.Portal>
+ <Dialog.Overlay className="modal-scrim fixed inset-0 z-[70]" />
+ <Dialog.Content
+ aria-describedby={undefined}
+ onPointerDownOutside={(event) => event.preventDefault()}
+ onEscapeKeyDown={(event) => {
+ if (event.isComposing || event.keyCode === 229) event.preventDefault();
+ }}
+ className="modal-panel fixed inset-0 z-[71] m-auto flex h-fit max-h-[85vh] w-[min(440px,calc(100vw-32px))] flex-col gap-4 overflow-y-auto p-6 outline-none"
+ data-testid="input-handoff-dialog"
+ >
+ <InputHandoffDialogHeader snapshot={snapshot} inputBlocked={inputBlocked} />
+ {children}
+ {error && (
+ <p role="alert" className="text-center text-12 text-[var(--error-fg)]">
+ {error}
+ </p>
+ )}
+ {footer}
+ {links && <div className="-mt-1 flex flex-wrap justify-center gap-x-4">{links}</div>}
+ {!footer && (
+ <Dialog.Close className="mx-auto min-h-8 px-3 text-13 font-medium text-[var(--text-primary)] hover:text-[var(--text-secondary)]">
+ {t('inputHandoff.action.close')}
+ </Dialog.Close>
+ )}
+ </Dialog.Content>
+ </Dialog.Portal>
+ </Dialog.Root>
+ );
+}
+
+function InputHandoffDialogHeader({
+ snapshot,
+ inputBlocked,
+}: {
+ snapshot: InputHandoffSnapshot;
+ inputBlocked: boolean;
+}) {
+ const { t } = useTranslation();
+ const place = inputHandoffPlace(snapshot.source);
+ const Icon = inputHandoffIcon(snapshot);
+ const warnings = [
+ snapshot.source.warning ? t(`inputHandoff.originWarning.${snapshot.source.warning}`) : null,
+ snapshot.agentControlled ? t('inputHandoff.agentControlled') : null,
+ inputBlocked ? t('inputHandoff.remoteUnavailable') : null,
+ snapshot.failure && !snapshot.terminal ? t(`inputHandoff.failure.${snapshot.failure}`) : null,
+ ].filter((warning): warning is string => Boolean(warning));
+ return (
+ <div className="flex flex-col items-center gap-2 text-center">
+ <span className="flex size-12 items-center justify-center rounded-[12px] border border-[var(--border-default)] bg-[var(--surface-elevated)] text-[var(--text-primary)]">
+ <Icon size={22} aria-hidden />
+ </span>
+ <Dialog.Title className="mt-1 text-18 font-semibold leading-snug text-[var(--text-primary)] [overflow-wrap:anywhere]">
+ {snapshot.purpose}
+ </Dialog.Title>
+ <InputHandoffPlace label={place.label} secure={place.secure} />
+ {snapshot.note && (
+ <p className="text-12 leading-relaxed text-[var(--text-secondary)] [overflow-wrap:anywhere]">
+ {t('inputHandoff.agentNote', { note: snapshot.note })}
+ </p>
+ )}
+ {snapshot.command && (
+ <p className="max-w-full font-mono text-12 text-[var(--text-secondary)] [overflow-wrap:anywhere]">
+ {snapshot.command}
+ </p>
+ )}
+ {warnings.map((warning) => (
+ <p
+ key={warning}
+ className="flex w-full items-start gap-1.5 rounded-[8px] bg-[var(--warning-bg-soft)] px-2.5 py-1.5 text-left text-12 text-[var(--text-primary)]"
+ >
+ <AlertTriangle size={14} className="mt-px shrink-0 text-[var(--warning-fg)]" aria-hidden />
+ <span>{warning}</span>
+ </p>
+ ))}
+ </div>
+ );
+}
+
+/** Lock + host for a secure site; otherwise the origin or the app, as the owner checks it. */
+export function InputHandoffPlace({ label, secure }: { label: string; secure: boolean }) {
+ return (
+ <p className="flex min-w-0 items-center gap-1 text-12 text-[var(--text-secondary)]">
+ {secure && <Lock size={12} className="shrink-0" aria-hidden />}
+ <span className="truncate">{label}</span>
+ </p>
+ );
+}
+
+export function inputHandoffIcon(snapshot: InputHandoffSnapshot) {
+ if (snapshot.qr) return QrCode;
+ const kind = inputHandoffPlaceKind(snapshot);
+ return kind === 'web' ? Globe : kind === 'terminal' ? SquareTerminal : AppWindow;
+}
diff --git a/apps/desktop/src/renderer/features/input-handoff/InputHandoffPictureStep.tsx b/apps/desktop/src/renderer/features/input-handoff/InputHandoffPictureStep.tsx
new file mode 100644
index 0000000000..275f650fc1
--- /dev/null
+++ b/apps/desktop/src/renderer/features/input-handoff/InputHandoffPictureStep.tsx
@@ -0,0 +1,200 @@
+/**
+ * A 代输入 step answered on a screenshot of the target window: the owner taps
+ * a spot, and may type into the field that has focus there. It is mounted only
+ * while the owner has the dialog open, so the picture is fetched only when
+ * asked for. It lives only in this component's state for the current revision;
+ * it comes from Main on the executing computer or from the sealed offer for a
+ * task on another computer, and is dropped as soon as the step changes.
+ */
+
+import { useCallback, useEffect, useRef, useState, type FormEvent, type MouseEvent } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import {
+ INPUT_HANDOFF_PICTURE_TEXT_ID,
+ inputHandoffPresentation,
+ type InputHandoffAction,
+ type InputHandoffControl,
+ type InputHandoffSnapshot,
+} from '@cindy/device-link';
+import { Button } from '@/components/ui/button';
+import { Spinner } from '@/components/ui/spinner';
+import { openInputHandoffPicture, type InputHandoffPictureSession } from '@/lib/makerTransport';
+import { InputHandoffTextField } from './InputHandoffStepForm';
+
+type Decision = 'done' | 'refresh';
+
+export interface InputHandoffPictureStepProps {
+ sessionId: string;
+ snapshot: InputHandoffSnapshot;
+ busy: boolean;
+ inputBlocked: boolean;
+ onDecide: (action: Decision) => void;
+ onError: (message: string | null) => void;
+}
+
+export function InputHandoffPictureStep({
+ sessionId,
+ snapshot,
+ busy,
+ inputBlocked,
+ onDecide,
+ onError,
+}: InputHandoffPictureStepProps) {
+ const { t } = useTranslation();
+ const [state, setState] = useState<'idle' | 'loading' | 'shown' | 'failed'>('idle');
+ const [sending, setSending] = useState(false);
+ const [typed, setTyped] = useState('');
+ const opened = useRef<InputHandoffPictureSession | null>(null);
+ const alive = useRef(true);
+ const [src, setSrc] = useState<string | null>(null);
+ const image = useRef<HTMLImageElement>(null);
+ const field = snapshot.controls.find(
+ (control): control is Extract<InputHandoffControl, { kind: 'text' }> =>
+ control.kind === 'text' && control.id === INPUT_HANDOFF_PICTURE_TEXT_ID,
+ );
+ const disabled = busy || sending || inputBlocked || state !== 'shown';
+
+ const load = useCallback(async () => {
+ setState('loading');
+ onError(null);
+ try {
+ const session = await openInputHandoffPicture(sessionId, inputHandoffPresentation(snapshot));
+ // Closed while it loaded: end the exchange instead of leaving it open on the computer.
+ if (!alive.current) {
+ session.close();
+ return;
+ }
+ opened.current = session;
+ setSrc(`data:${session.picture.mime};base64,${session.picture.data}`);
+ setState('shown');
+ } catch {
+ setState('failed');
+ }
+ }, [onError, sessionId, snapshot]);
+
+ // Each revision is one picture: open it once, and close the exchange when the step changes.
+ useEffect(() => {
+ alive.current = true;
+ if (!inputBlocked) void load();
+ return () => {
+ alive.current = false;
+ opened.current?.close();
+ opened.current = null;
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- mounted once per revision by the card
+ }, []);
+
+ // Each exchange answers once: after a failed answer, open a fresh one so the picture works again.
+ const retry = (message: string) => {
+ if (!alive.current) return;
+ void load();
+ onError(message);
+ };
+
+ const answer = async (action: InputHandoffAction, values: Record<string, string> = {}) => {
+ const session = opened.current;
+ if (!session || disabled) return;
+ opened.current = null;
+ setSending(true);
+ onError(null);
+ try {
+ const result = await session.answer({ expectedRevision: snapshot.revision, values, action });
+ if (result.accepted) setTyped('');
+ else retry(t('inputHandoff.error.stale'));
+ } catch {
+ retry(t('inputHandoff.error.submit'));
+ } finally {
+ setSending(false);
+ }
+ };
+
+ const tap = (event: MouseEvent<HTMLButtonElement>) => {
+ const rect = image.current?.getBoundingClientRect();
+ if (!rect || rect.width <= 0 || rect.height <= 0) return;
+ const clamp = (n: number) => Math.min(1, Math.max(0, n));
+ void answer({
+ kind: 'tap',
+ x: clamp((event.clientX - rect.left) / rect.width),
+ y: clamp((event.clientY - rect.top) / rect.height),
+ });
+ };
+
+ const type = (submit: boolean) => {
+ if (!field) return;
+ if (!submit && !typed) return;
+ void answer({ kind: submit ? 'submit' : 'fill' }, typed ? { [field.id]: typed } : {});
+ };
+
+ const onFormSubmit = (event: FormEvent) => {
+ event.preventDefault();
+ type(true);
+ };
+
+ return (
+ <div>
+ {state === 'shown' && src ? (
+ <>
+ <p className="mb-2 text-12 text-[var(--text-tertiary)]">{t('inputHandoff.picture.hint')}</p>
+ <div className="max-h-[60vh] overflow-auto rounded-[8px] border border-[var(--border-default)] bg-[var(--surface-sunken)]">
+ <button
+ type="button"
+ className="block w-full cursor-crosshair disabled:cursor-default disabled:opacity-60"
+ disabled={disabled}
+ aria-label={t('inputHandoff.picture.alt')}
+ onClick={tap}
+ >
+ <img
+ ref={image}
+ src={src}
+ alt={t('inputHandoff.picture.alt')}
+ draggable={false}
+ className="block h-auto w-full select-none"
+ />
+ </button>
+ </div>
+ </>
+ ) : state === 'loading' ? (
+ <p className="flex items-center gap-2 text-13 text-[var(--text-secondary)]" role="status">
+ <Spinner size={14} />
+ {t('inputHandoff.picture.loading')}
+ </p>
+ ) : state === 'failed' ? (
+ <div className="flex flex-col items-start gap-2">
+ <p className="text-13 text-[var(--text-secondary)]">{t('inputHandoff.picture.error')}</p>
+ <Button type="button" size="sm" variant="secondary" disabled={busy || inputBlocked} onClick={() => void load()}>
+ {t('inputHandoff.picture.open')}
+ </Button>
+ </div>
+ ) : null}
+ {field && state === 'shown' && (
+ <form className="mt-3" onSubmit={onFormSubmit} autoComplete="on" noValidate>
+ <InputHandoffTextField
+ control={{ ...field, label: field.contentType === 'password' ? '' : t('inputHandoff.picture.field') }}
+ value={typed}
+ disabled={disabled}
+ onChange={setTyped}
+ />
+ <div className="mt-2 flex flex-wrap justify-end gap-2">
+ <Button type="button" size="sm" variant="secondary" disabled={disabled || !typed} onClick={() => type(false)}>
+ {t('inputHandoff.picture.type')}
+ </Button>
+ <Button type="submit" size="sm" variant="primary" disabled={disabled}>
+ {t('inputHandoff.picture.typeEnter')}
+ </Button>
+ </div>
+ </form>
+ )}
+ <div className="mt-4 flex flex-wrap items-center gap-2">
+ <Button type="button" size="sm" variant="secondary" tone="quiet" disabled={busy} onClick={() => onDecide('refresh')}>
+ {t('inputHandoff.action.backToForm')}
+ </Button>
+ <div className="ml-auto">
+ <Button type="button" size="sm" variant="secondary" disabled={busy} onClick={() => onDecide('done')}>
+ {t('inputHandoff.action.done')}
+ </Button>
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/desktop/src/renderer/features/input-handoff/InputHandoffQrStep.tsx b/apps/desktop/src/renderer/features/input-handoff/InputHandoffQrStep.tsx
new file mode 100644
index 0000000000..59754e226c
--- /dev/null
+++ b/apps/desktop/src/renderer/features/input-handoff/InputHandoffQrStep.tsx
@@ -0,0 +1,206 @@
+/**
+ * 代输入 scan-to-sign-in on a computer: the QR code on the target window,
+ * large enough to scan with a phone held up to this screen. The code arrives
+ * with the sealed picture of the current revision (never in the snapshot) and
+ * lives only in this component, which the dialog mounts once per revision; a
+ * refreshed code is a new revision. A click on the code clicks the same spot
+ * on the code in the window (for example "click to refresh" on an expired one).
+ */
+
+import { useCallback, useEffect, useRef, useState, type MouseEvent } from 'react';
+import { Copy, ExternalLink, ImageDown } from 'lucide-react';
+import { useTranslation } from 'react-i18next';
+
+import {
+ inputHandoffPresentation,
+ inputHandoffQrLink,
+ type InputHandoffPicture,
+ type InputHandoffSnapshot,
+} from '@cindy/device-link';
+import { Button } from '@/components/ui/button';
+import { Spinner } from '@/components/ui/spinner';
+import { openInputHandoffPicture, type InputHandoffPictureSession } from '@/lib/makerTransport';
+
+export interface InputHandoffQrStepProps {
+ sessionId: string;
+ snapshot: InputHandoffSnapshot;
+ busy: boolean;
+ inputBlocked: boolean;
+ onError: (message: string | null) => void;
+}
+
+/** The code's pixels as PNG for the clipboard (the clipboard takes PNG images only). */
+async function pngOf(img: HTMLImageElement): Promise<Blob> {
+ const canvas = document.createElement('canvas');
+ canvas.width = img.naturalWidth;
+ canvas.height = img.naturalHeight;
+ const context = canvas.getContext('2d');
+ if (!context) throw new Error('NO_CANVAS');
+ context.drawImage(img, 0, 0);
+ return new Promise((resolve, reject) =>
+ canvas.toBlob((blob) => (blob ? resolve(blob) : reject(new Error('NO_IMAGE'))), 'image/png'),
+ );
+}
+
+export function InputHandoffQrStep({ sessionId, snapshot, busy, inputBlocked, onError }: InputHandoffQrStepProps) {
+ const { t } = useTranslation();
+ const [state, setState] = useState<'loading' | 'shown' | 'sending' | 'failed'>('loading');
+ const [picture, setPicture] = useState<InputHandoffPicture | null>(null);
+ const [notice, setNotice] = useState<string | null>(null);
+ const opened = useRef<InputHandoffPictureSession | null>(null);
+ const alive = useRef(true);
+ const image = useRef<HTMLImageElement>(null);
+
+ const load = useCallback(async () => {
+ setState('loading');
+ onError(null);
+ try {
+ const session = await openInputHandoffPicture(sessionId, inputHandoffPresentation(snapshot));
+ // Closed while it loaded: end the exchange instead of leaving it open on the computer.
+ if (!alive.current || !session.picture.qr) {
+ session.close();
+ setState('failed');
+ return;
+ }
+ opened.current = session;
+ setPicture(session.picture);
+ setState('shown');
+ } catch {
+ setState('failed');
+ }
+ }, [onError, sessionId, snapshot]);
+
+ useEffect(() => {
+ alive.current = true;
+ if (!inputBlocked) void load();
+ return () => {
+ alive.current = false;
+ opened.current?.close();
+ opened.current = null;
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- mounted once per revision by the dialog
+ }, []);
+
+ const tap = async (event: MouseEvent<HTMLButtonElement>) => {
+ const session = opened.current;
+ const rect = image.current?.getBoundingClientRect();
+ if (!session || !rect || rect.width <= 0 || rect.height <= 0 || state !== 'shown') return;
+ opened.current = null;
+ setState('sending');
+ const clamp = (n: number) => Math.min(1, Math.max(0, n));
+ try {
+ const result = await session.answer({
+ expectedRevision: snapshot.revision,
+ values: {},
+ action: {
+ kind: 'tap',
+ x: clamp((event.clientX - rect.left) / rect.width),
+ y: clamp((event.clientY - rect.top) / rect.height),
+ },
+ });
+ if (!result.accepted) retry(t('inputHandoff.error.stale'));
+ } catch {
+ retry(t('inputHandoff.error.submit'));
+ }
+ };
+
+ // Each exchange answers once: after a failed tap, open a fresh one so the code works again.
+ function retry(message: string) {
+ if (!alive.current) return;
+ void load();
+ onError(message);
+ }
+
+ const qr = picture?.qr ?? null;
+ const link = qr ? inputHandoffQrLink(qr) : null;
+ // This computer opens web links only; an app link (weixin://…) is for the phone that scans the code.
+ const openable = link?.web ? link : null;
+ const copyText = () => {
+ if (!qr) return;
+ void Promise.resolve()
+ .then(() => navigator.clipboard.writeText(qr.text))
+ .then(() => setNotice(t('inputHandoff.qr.copied')))
+ .catch(() => setNotice(t('inputHandoff.qr.copyFailed')));
+ };
+ const copyImage = () => {
+ const img = image.current;
+ if (!img) return;
+ void pngOf(img)
+ .then((blob) => navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]))
+ .then(() => setNotice(t('inputHandoff.qr.imageCopied')))
+ .catch(() => setNotice(t('inputHandoff.qr.copyFailed')));
+ };
+ const open = () => {
+ if (!openable) return;
+ void window.electronAPI
+ .openExternal(openable.url)
+ .then((result) => setNotice(result.success ? null : t('inputHandoff.qr.openFailed')))
+ .catch(() => setNotice(t('inputHandoff.qr.openFailed')));
+ };
+
+ const src = picture ? `data:${picture.mime};base64,${picture.data}` : null;
+ const disabled = busy || inputBlocked || state !== 'shown';
+ return (
+ <div className="flex flex-col items-center gap-3">
+ <div className="flex size-[240px] items-center justify-center overflow-hidden rounded-[12px] border border-[var(--border-default)] bg-[var(--surface-elevated)]">
+ {src && (state === 'shown' || state === 'sending') ? (
+ <button
+ type="button"
+ className="block size-full disabled:opacity-60"
+ disabled={disabled}
+ aria-label={t('inputHandoff.qr.alt')}
+ data-testid="input-handoff-qr-code"
+ onClick={(event) => void tap(event)}
+ >
+ <img
+ ref={image}
+ src={src}
+ alt={t('inputHandoff.qr.alt')}
+ draggable={false}
+ className="block size-full select-none object-contain"
+ />
+ </button>
+ ) : state === 'failed' ? (
+ <button
+ type="button"
+ className="px-4 text-center text-13 text-[var(--text-secondary)]"
+ disabled={busy || inputBlocked}
+ onClick={() => void load()}
+ >
+ {t('inputHandoff.qr.failed')}
+ </button>
+ ) : (
+ <p className="flex flex-col items-center gap-2 text-12 text-[var(--text-tertiary)]" role="status">
+ <Spinner size={16} />
+ {t('inputHandoff.qr.loading')}
+ </p>
+ )}
+ </div>
+ <p className="max-w-[360px] text-center text-12 leading-relaxed text-[var(--text-secondary)]">
+ {t(openable ? 'inputHandoff.qr.hintLink' : 'inputHandoff.qr.hint')}
+ </p>
+ {/* Opening the link here comes first: many codes open an app straight from the browser. */}
+ {openable && (
+ <Button type="button" size="lg" variant="cta" palette="confirmation" className="w-full" disabled={disabled} onClick={open}>
+ <ExternalLink size={14} aria-hidden />
+ {t('inputHandoff.qr.open', { site: openable.site })}
+ </Button>
+ )}
+ <div className="flex flex-wrap justify-center gap-2">
+ <Button type="button" size="sm" variant="secondary" disabled={disabled} onClick={copyImage}>
+ <ImageDown size={13} aria-hidden />
+ {t('inputHandoff.qr.copyImage')}
+ </Button>
+ <Button type="button" size="sm" variant="secondary" disabled={disabled || !qr} onClick={copyText}>
+ <Copy size={13} aria-hidden />
+ {t(link ? 'inputHandoff.qr.copyLink' : 'inputHandoff.qr.copyText')}
+ </Button>
+ </div>
+ {notice && (
+ <p role="status" className="text-center text-12 text-[var(--text-secondary)]">
+ {notice}
+ </p>
+ )}
+ </div>
+ );
+}
diff --git a/apps/desktop/src/renderer/features/input-handoff/InputHandoffRecordRow.tsx b/apps/desktop/src/renderer/features/input-handoff/InputHandoffRecordRow.tsx
new file mode 100644
index 0000000000..be357f3273
--- /dev/null
+++ b/apps/desktop/src/renderer/features/input-handoff/InputHandoffRecordRow.tsx
@@ -0,0 +1,45 @@
+import { KeyRound } from 'lucide-react';
+import { useTranslation } from 'react-i18next';
+import {
+ inputHandoffRecordHost,
+ inputHandoffRecordMessage,
+ type InputHandoffEndRecord,
+} from '@cindy/maker-shared/synthetic-trigger';
+
+/**
+ * The one visible trace a 代输入 leaves in the task: who finished how many
+ * steps, where, and when. Never values, labels or screen text.
+ */
+export function InputHandoffRecordRow({ record, at }: { record: InputHandoffEndRecord; at?: string }) {
+ const { t, i18n } = useTranslation();
+ const message = inputHandoffRecordMessage(record);
+ const label = t(`inputHandoff.record.${message.key}`, message.params);
+ const host = inputHandoffRecordHost(record.origin);
+ const time = at ? formatTime(at, i18n.language) : undefined;
+ const text = [label, host, time].filter(Boolean).join(' · ');
+ return (
+ <div className="flex w-full items-center gap-3 py-2 select-none" role="separator" aria-label={text}>
+ <div className="h-px flex-1 bg-[var(--msg-tool-card-border)]" />
+ <div className="flex min-w-0 shrink items-center gap-1.5 rounded-full border border-[var(--msg-tool-card-border)] bg-background/50 px-2.5 py-1 text-11 text-muted-foreground tabular-nums">
+ <KeyRound size={12} className="shrink-0" aria-hidden />
+ <span className="truncate">{text}</span>
+ </div>
+ <div className="h-px flex-1 bg-[var(--msg-tool-card-border)]" />
+ </div>
+ );
+}
+
+function formatTime(iso: string, locale: string): string | undefined {
+ const date = new Date(iso);
+ if (Number.isNaN(date.getTime())) return undefined;
+ return date.toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' });
+}
+
+/** systemCardData was produced by parseInputHandoffEndRecord; re-check its shape before rendering. */
+export function readInputHandoffRecordData(data?: Record<string, unknown>): InputHandoffEndRecord | null {
+ if (!data) return null;
+ const { status, steps } = data;
+ if (!['succeeded', 'cancelled', 'failed', 'expired'].includes(String(status))) return null;
+ if (typeof steps !== 'number' || !Number.isSafeInteger(steps) || steps < 0) return null;
+ return data as unknown as InputHandoffEndRecord;
+}
diff --git a/apps/desktop/src/renderer/features/input-handoff/InputHandoffStepForm.tsx b/apps/desktop/src/renderer/features/input-handoff/InputHandoffStepForm.tsx
new file mode 100644
index 0000000000..b721332d99
--- /dev/null
+++ b/apps/desktop/src/renderer/features/input-handoff/InputHandoffStepForm.tsx
@@ -0,0 +1,212 @@
+/**
+ * One 代输入 step: only the fields the owner types into, in screen order, plus
+ * what the page says is wrong with them. Return moves to the next field and,
+ * on the last one, hands the answer over (the dialog's Continue does the
+ * same); Cindy then confirms on the page itself. The draft lives only here;
+ * the parent remounts this form for every new screen, and a successful submit
+ * clears it immediately.
+ */
+
+import { useRef, useState, type FormEvent } from 'react';
+import { Eye, EyeOff } from 'lucide-react';
+import { useTranslation } from 'react-i18next';
+
+import type {
+ InputHandoffAction,
+ InputHandoffControl,
+ InputHandoffSnapshot,
+ InputHandoffValues,
+} from '@cindy/device-link';
+import { FormField } from '@/components/ui/form-field';
+import { Input, Textarea } from '@/components/ui/input';
+import {
+ autoCompleteFor,
+ inputModeFor,
+ inputTypeFor,
+ textFields,
+ type InputHandoffTextControl,
+} from './inputHandoffModel';
+
+export interface InputHandoffStepFormProps {
+ /** The dialog's Continue button submits this form by id. */
+ formId: string;
+ snapshot: InputHandoffSnapshot;
+ busy: boolean;
+ inputBlocked: boolean;
+ onSubmit: (draft: InputHandoffValues, action: InputHandoffAction) => Promise<boolean>;
+ /** First edit on this screen: this device starts handling the handoff. */
+ onStart?: () => void;
+}
+
+const FIELD_ATTR = 'data-input-handoff-field';
+/** Marks the dialog's Continue button: it answers from any field, Return only from the last one. */
+export const CONTINUE_ATTR = 'data-input-handoff-continue';
+
+export function InputHandoffStepForm({
+ formId,
+ snapshot,
+ busy,
+ inputBlocked,
+ onSubmit,
+ onStart,
+}: InputHandoffStepFormProps) {
+ const [draft, setDraft] = useState<InputHandoffValues>({});
+ const started = useRef(false);
+ const set = (id: string, value: string) => {
+ if (!started.current) {
+ started.current = true;
+ onStart?.();
+ }
+ setDraft((d) => ({ ...d, [id]: value }));
+ };
+ const disabled = busy || inputBlocked;
+ const fields = textFields(snapshot);
+ const lastField = fields.at(-1)?.id;
+
+ const onFormSubmit = async (event: FormEvent<HTMLFormElement>) => {
+ event.preventDefault();
+ // Return in an earlier field moves on, like a sign-in form; only the last one (or Continue) answers.
+ const inputs = Array.from(event.currentTarget.querySelectorAll<HTMLElement>(`[${FIELD_ATTR}]`));
+ const at = inputs.indexOf(document.activeElement as HTMLElement);
+ const continued = (event.nativeEvent as SubmitEvent).submitter?.hasAttribute(CONTINUE_ATTR) === true;
+ if (!continued && at >= 0 && at < inputs.length - 1) {
+ inputs[at + 1].focus();
+ return;
+ }
+ if (disabled || fields.length === 0) return;
+ // Drop the typed values from memory as soon as the Host has them.
+ if (await onSubmit(draft, { kind: 'submit' })) setDraft({});
+ };
+
+ return (
+ <form id={formId} onSubmit={(event) => void onFormSubmit(event)} autoComplete="on" noValidate>
+ <div className="flex flex-col gap-3">
+ {snapshot.controls.map((control) =>
+ control.kind === 'note' ? (
+ <StepNote key={control.id} control={control} />
+ ) : (
+ <InputHandoffTextField
+ key={control.id}
+ control={control}
+ value={draft[control.id] ?? ''}
+ disabled={disabled}
+ last={control.id === lastField}
+ autoFocus={control.id === fields[0]?.id}
+ onChange={(v) => set(control.id, v)}
+ />
+ ),
+ )}
+ </div>
+ {/* Return submits the form; this button stays out of sight and out of the tab order. */}
+ <button type="submit" className="sr-only" tabIndex={-1} aria-hidden disabled={disabled} />
+ </form>
+ );
+}
+
+function StepNote({ control }: { control: Extract<InputHandoffControl, { kind: 'note' }> }) {
+ return (
+ <p role="alert" className="text-13 text-[var(--error-fg)] [overflow-wrap:anywhere]">
+ {control.text}
+ </p>
+ );
+}
+
+/** One standard platform text / password field; also used by the screenshot step. */
+export function InputHandoffTextField({
+ control,
+ value,
+ disabled,
+ last = true,
+ autoFocus,
+ onChange,
+}: {
+ control: InputHandoffTextControl;
+ value: string;
+ disabled: boolean;
+ /** Return on this field hands the answer over (otherwise it moves to the next field). */
+ last?: boolean;
+ autoFocus?: boolean;
+ onChange: (value: string) => void;
+}) {
+ const { t } = useTranslation();
+ // The eye only swaps the field kind; the autofill hint stays, so password managers still fill it.
+ const [revealed, setRevealed] = useState(false);
+ const password = control.contentType === 'password';
+ const label = control.label || t(
+ control.contentType === 'password' ? 'inputHandoff.passwordField'
+ : control.contentType === 'one-time-code' ? 'inputHandoff.codeField'
+ : 'inputHandoff.unnamedField',
+ );
+ const suggestions = control.suggestions ?? [];
+ const listId = suggestions.length > 0 ? `input-handoff-${control.id}-options` : undefined;
+ return (
+ <FormField label={label} hint={control.filled ? t('inputHandoff.filledHint') : undefined}>
+ {(field) =>
+ control.multiline ? (
+ <Textarea
+ id={field.id}
+ aria-describedby={field['aria-describedby']}
+ data-input-handoff-field=""
+ // Return moves on like in a one-line field; Shift + Return adds a line.
+ onKeyDown={(event) => {
+ if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing) {
+ event.preventDefault();
+ event.currentTarget.form?.requestSubmit();
+ }
+ }}
+ value={value}
+ placeholder={control.placeholder}
+ disabled={disabled}
+ rows={3}
+ onChange={onChange}
+ />
+ ) : (
+ <>
+ {/* Standard platform field with its autofill hints; the eye never turns them off. */}
+ <Input
+ id={field.id}
+ aria-describedby={field['aria-describedby']}
+ data-input-handoff-field=""
+ size="md"
+ type={password && revealed ? 'text' : inputTypeFor(control)}
+ autoFocus={autoFocus}
+ name={control.contentType === 'text' ? control.id : control.contentType}
+ autoComplete={autoCompleteFor(control)}
+ inputMode={inputModeFor(control)}
+ enterKeyHint={last ? 'go' : 'next'}
+ spellCheck={false}
+ autoCapitalize="off"
+ autoCorrect="off"
+ list={listId}
+ value={value}
+ placeholder={control.placeholder}
+ disabled={disabled}
+ onChange={onChange}
+ trailing={
+ password ? (
+ <button
+ type="button"
+ disabled={disabled}
+ aria-pressed={revealed}
+ aria-label={t(revealed ? 'inputHandoff.action.hidePassword' : 'inputHandoff.action.showPassword')}
+ onClick={() => setRevealed((v) => !v)}
+ className="absolute right-3 top-1/2 -translate-y-1/2 rounded-full text-[var(--text-tertiary)] transition-colors enabled:hover:text-[var(--text-secondary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)] disabled:opacity-60"
+ >
+ {revealed ? <EyeOff size={15} aria-hidden /> : <Eye size={15} aria-hidden />}
+ </button>
+ ) : undefined
+ }
+ />
+ {listId && (
+ <datalist id={listId}>
+ {suggestions.map((o) => (
+ <option key={o.id} value={o.label} />
+ ))}
+ </datalist>
+ )}
+ </>
+ )
+ }
+ </FormField>
+ );
+}
diff --git a/apps/desktop/src/renderer/features/input-handoff/__tests__/InputHandoffCard.test.tsx b/apps/desktop/src/renderer/features/input-handoff/__tests__/InputHandoffCard.test.tsx
new file mode 100644
index 0000000000..1aad56f0b0
--- /dev/null
+++ b/apps/desktop/src/renderer/features/input-handoff/__tests__/InputHandoffCard.test.tsx
@@ -0,0 +1,383 @@
+// @vitest-environment jsdom
+
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+
+import { InputHandoffCard } from '../InputHandoffCard';
+
+const mocks = vi.hoisted(() => ({
+ submit: vi.fn(async () => ({ accepted: true })),
+ resolve: vi.fn(async () => ({ accepted: true })),
+ deviceId: null as string | null,
+ hostDeviceId: undefined as string | undefined,
+ openRemoteDesktop: vi.fn(async () => {}),
+ openPicture: vi.fn(),
+ answer: vi.fn(async () => ({ accepted: true })),
+ close: vi.fn(),
+}));
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+vi.mock('@/contexts/AuthContext', () => ({
+ useOptionalAuthDeviceId: () => mocks.deviceId,
+}));
+vi.mock('@/features/device-link/stickySessionOrigin', () => ({
+ getStickySessionDeviceId: () => mocks.hostDeviceId,
+}));
+vi.mock('@/features/device-link/useDeviceLinkDeviceList', () => ({
+ useDeviceLinkDeviceList: () => [{ deviceId: 'mac', name: 'Studio' }],
+}));
+vi.mock('@/lib/toast', () => ({ toast: { error: vi.fn(), success: vi.fn() } }));
+vi.mock('@/lib/makerTransport', () => ({
+ submitInputHandoff: mocks.submit,
+ makerApiForSticky: () => ({ resolveInteraction: mocks.resolve }),
+ openInputHandoffPicture: mocks.openPicture,
+}));
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+ mocks.deviceId = null;
+ mocks.hostDeviceId = undefined;
+});
+
+const step = (overrides: Partial<InputHandoffSnapshot> = {}): InputHandoffSnapshot => ({
+ kind: 'input_handoff',
+ requestId: 'req1',
+ revision: 4,
+ phase: 'ready',
+ purpose: 'Sign in to Example',
+ source: { app: 'Example', window: 'Sign in' },
+ stepNumber: 1,
+ remoteInput: true,
+ controls: [
+ { id: 'c0', kind: 'text', label: 'Email', contentType: 'email' },
+ { id: 'c1', kind: 'text', label: 'Password', contentType: 'password' },
+ ],
+ ...overrides,
+});
+
+const fill = (name = 'inputHandoff.action.fill') => fireEvent.click(screen.getByRole('button', { name }));
+
+describe('InputHandoffCard', () => {
+ it('sits above the composer as one line, and opens the fields only when asked', () => {
+ render(<InputHandoffCard sessionId="s1" snapshot={step({ source: { app: 'Google Chrome', origin: 'https://login.example.com' } })} />);
+ expect(screen.getByText('Sign in to Example')).toBeTruthy();
+ expect(screen.getByText('login.example.com')).toBeTruthy();
+ expect(screen.queryByLabelText('Password')).toBeNull();
+ expect(screen.getAllByRole('button').map((b) => b.textContent)).toEqual([
+ 'inputHandoff.action.skip',
+ 'inputHandoff.action.fill',
+ ]);
+ fill();
+ expect(screen.getByTestId('input-handoff-dialog')).toBeTruthy();
+ expect(screen.getByLabelText('Password')).toBeTruthy();
+ });
+
+ it('skips with a value-less decision', async () => {
+ render(<InputHandoffCard sessionId="s1" snapshot={step()} />);
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.action.skip' }));
+ await waitFor(() =>
+ expect(mocks.resolve).toHaveBeenCalledWith('req1', { kind: 'input_handoff', action: 'cancel', expectedRevision: 4 }),
+ );
+ });
+
+ it('renders standard autofill fields so password managers can fill them', () => {
+ render(<InputHandoffCard sessionId="s1" snapshot={step()} />);
+ fill();
+ const password = screen.getByLabelText('Password') as HTMLInputElement;
+ expect(password.type).toBe('password');
+ expect(password.autocomplete).toBe('current-password');
+ const email = screen.getByLabelText('Email') as HTMLInputElement;
+ expect(email.type).toBe('email');
+ expect(email.autocomplete).toBe('email');
+ // The eye only shows the password; the autofill hint stays.
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.action.showPassword' }));
+ expect(password.type).toBe('text');
+ expect(password.autocomplete).toBe('current-password');
+ });
+
+ it('moves through the fields on Return and sends what was typed from the last one, then clears it', async () => {
+ render(<InputHandoffCard sessionId="s1" snapshot={step()} />);
+ fill();
+ const email = screen.getByLabelText('Email') as HTMLInputElement;
+ const password = screen.getByLabelText('Password') as HTMLInputElement;
+ fireEvent.change(email, { target: { value: '[email protected]' } });
+ email.focus();
+ fireEvent.submit(email.form!);
+ expect(document.activeElement).toBe(password);
+ expect(mocks.submit).not.toHaveBeenCalled();
+
+ fireEvent.change(password, { target: { value: 'synthetic-pass' } });
+ fireEvent.submit(password.form!);
+ await waitFor(() => expect(mocks.submit).toHaveBeenCalledTimes(1));
+ expect(mocks.submit).toHaveBeenCalledWith(
+ 's1',
+ expect.objectContaining({
+ submission: {
+ expectedRevision: 4,
+ values: { c0: '[email protected]', c1: 'synthetic-pass' },
+ action: { kind: 'submit' },
+ },
+ }),
+ );
+ await waitFor(() => expect(password.value).toBe(''));
+ });
+
+ it('shows only the fields to type and what the page says about them, and Continue sends them', async () => {
+ render(
+ <InputHandoffCard
+ sessionId="s1"
+ snapshot={step({ controls: [{ id: 'n0', kind: 'note', tone: 'error', text: 'Wrong password' }, ...step().controls] })}
+ />,
+ );
+ fill();
+ expect(screen.getByRole('alert').textContent).toBe('Wrong password');
+ const dialog = screen.getByTestId('input-handoff-dialog');
+ expect([...dialog.querySelectorAll('button:not([aria-hidden])')].map((b) => b.getAttribute('aria-label') ?? b.textContent)).toEqual([
+ 'inputHandoff.action.showPassword',
+ 'inputHandoff.action.continue',
+ 'inputHandoff.action.close',
+ 'inputHandoff.action.picture',
+ ]);
+ fireEvent.change(screen.getByLabelText('Email'), { target: { value: '[email protected]' } });
+ // Continue answers from any field, unlike Return in an earlier one.
+ screen.getByLabelText('Email').focus();
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.action.continue' }));
+ await waitFor(() => expect(mocks.submit).toHaveBeenCalledTimes(1));
+ // Cancel only closes the dialog; the handoff stays on the strip.
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.action.close' }));
+ expect(screen.queryByTestId('input-handoff-dialog')).toBeNull();
+ expect(mocks.resolve).not.toHaveBeenCalledWith('req1', expect.objectContaining({ action: 'cancel' }));
+ });
+
+ it('hands back with a value-less decision', async () => {
+ render(
+ <InputHandoffCard
+ sessionId="s1"
+ snapshot={step({ phase: 'finishing', finishingUntil: Date.now() + 3000 })}
+ />,
+ );
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.action.done' }));
+ await waitFor(() =>
+ expect(mocks.resolve).toHaveBeenCalledWith('req1', {
+ kind: 'input_handoff',
+ action: 'done',
+ expectedRevision: 4,
+ }),
+ );
+ expect(mocks.submit).not.toHaveBeenCalled();
+ });
+
+ it('starts a new screen from an empty draft, in the dialog that stays open', () => {
+ const { rerender } = render(<InputHandoffCard sessionId="s1" snapshot={step()} />);
+ fill();
+ fireEvent.change(screen.getByLabelText('Email'), { target: { value: '[email protected]' } });
+ rerender(<InputHandoffCard sessionId="s1" snapshot={step({ revision: 5, stepNumber: 2 })} />);
+ expect((screen.getByLabelText('Email') as HTMLInputElement).value).toBe('');
+ });
+
+ it('starts handling quietly on the first keystroke without blocking the form', async () => {
+ render(<InputHandoffCard sessionId="s1" snapshot={step()} />);
+ fill();
+ fireEvent.change(screen.getByLabelText('Email'), { target: { value: 's' } });
+ fireEvent.change(screen.getByLabelText('Email'), { target: { value: 'so' } });
+ await waitFor(() => expect(mocks.resolve).toHaveBeenCalledTimes(1));
+ expect(mocks.resolve).toHaveBeenCalledWith('req1', {
+ kind: 'input_handoff',
+ action: 'claim',
+ expectedRevision: 4,
+ });
+ expect((screen.getByLabelText('Email') as HTMLInputElement).disabled).toBe(false);
+ });
+
+ it('keeps what the owner is typing when another device was taken over', () => {
+ const { rerender } = render(<InputHandoffCard sessionId="s1" snapshot={step()} />);
+ fill();
+ fireEvent.change(screen.getByLabelText('Email'), { target: { value: '[email protected]' } });
+ rerender(
+ <InputHandoffCard sessionId="s1" snapshot={step({ revision: 5, holder: { local: true } })} />,
+ );
+ expect((screen.getByLabelText('Email') as HTMLInputElement).value).toBe('[email protected]');
+ });
+
+ it('shows who is handling it elsewhere and lets this device take over', async () => {
+ mocks.deviceId = 'desk-2';
+ render(
+ <InputHandoffCard
+ sessionId="s1"
+ snapshot={step({
+ holder: { deviceId: 'phone-1', name: 'Synthetic Phone', platform: 'mobile' },
+ })}
+ />,
+ );
+ expect(screen.getByText('inputHandoff.holder.elsewhere')).toBeTruthy();
+ expect(screen.queryByLabelText('Password')).toBeNull();
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.action.claim' }));
+ await waitFor(() =>
+ expect(mocks.resolve).toHaveBeenCalledWith('req1', {
+ kind: 'input_handoff',
+ action: 'claim',
+ expectedRevision: 4,
+ }),
+ );
+ });
+
+ it('shows a terminal password prompt as one answer to one program', async () => {
+ render(
+ <InputHandoffCard
+ sessionId="s1"
+ snapshot={step({
+ purpose: '[sudo] password for someone:',
+ source: { app: 'sudo' },
+ command: 'sudo -A true',
+ controls: [{ id: 'answer', kind: 'text', label: '', contentType: 'password' }],
+ })}
+ />,
+ );
+ fill();
+ expect(screen.getByText('sudo -A true')).toBeTruthy();
+ const field = screen.getByLabelText('inputHandoff.passwordField') as HTMLInputElement;
+ expect(field.type).toBe('password');
+ for (const hidden of ['picture', 'done']) {
+ expect(screen.queryByRole('button', { name: `inputHandoff.action.${hidden}` })).toBeNull();
+ }
+ fireEvent.change(field, { target: { value: 'synthetic-pass' } });
+ fireEvent.submit(field.form!);
+ await waitFor(() =>
+ expect(mocks.submit).toHaveBeenCalledWith(
+ 's1',
+ expect.objectContaining({
+ submission: {
+ expectedRevision: 4,
+ values: { answer: 'synthetic-pass' },
+ action: { kind: 'submit' },
+ },
+ }),
+ ),
+ );
+ });
+
+ it('opens a live view of just this window on the computer running the task', async () => {
+ (window as unknown as { electronAPI: object }).electronAPI = {
+ openRemoteDesktop: mocks.openRemoteDesktop,
+ };
+ const { rerender } = render(
+ <InputHandoffCard sessionId="s1" snapshot={step({ liveView: true })} />,
+ );
+ // A task on this computer: the window is right here.
+ expect(screen.queryByRole('button', { name: 'inputHandoff.action.liveView' })).toBeNull();
+ mocks.hostDeviceId = 'mac';
+ rerender(<InputHandoffCard sessionId="s1" snapshot={step()} />);
+ expect(screen.queryByRole('button', { name: 'inputHandoff.action.liveView' })).toBeNull();
+ rerender(<InputHandoffCard sessionId="s1" snapshot={step({ liveView: true })} />);
+ fill();
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.action.liveView' }));
+ await waitFor(() =>
+ expect(mocks.openRemoteDesktop).toHaveBeenCalledWith({
+ deviceId: 'mac',
+ name: 'Studio',
+ handoff: 'req1',
+ }),
+ );
+ });
+
+ it('offers a sign-in code to copy and its link to open on this device', async () => {
+ const openExternal = vi.fn(async () => ({ success: true }));
+ const writeText = vi.fn(async () => {});
+ (window as unknown as { electronAPI: object }).electronAPI = { openExternal };
+ Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });
+ const codeStep = step({
+ controls: [],
+ deviceCode: { code: 'WDJB-MJHT', url: 'https://github.com/login/device', origin: 'https://github.com' },
+ });
+ const { rerender } = render(<InputHandoffCard sessionId="s1" snapshot={codeStep} />);
+ fill();
+ expect(screen.getByText('WDJB-MJHT')).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.deviceCode.copy' }));
+ await waitFor(() => expect(writeText).toHaveBeenCalledWith('WDJB-MJHT'));
+ fireEvent.click(screen.getByRole('button', { name: /inputHandoff\.deviceCode\.open/ }));
+ await waitFor(() => expect(openExternal).toHaveBeenCalledWith('https://github.com/login/device'));
+ // A link whose shown origin does not match is never offered.
+ rerender(
+ <InputHandoffCard
+ sessionId="s1"
+ snapshot={{ ...codeStep, deviceCode: { ...codeStep.deviceCode!, origin: 'https://example.com' } }}
+ />,
+ );
+ expect(screen.queryByRole('button', { name: 'inputHandoff.deviceCode.copy' })).toBeNull();
+ });
+
+ describe('scan-to-sign-in', () => {
+ const qrStep = (overrides: Partial<InputHandoffSnapshot> = {}) =>
+ step({ controls: [], picture: true, qr: 'scan', source: { app: 'Google Chrome', origin: 'https://login.example.com' }, ...overrides });
+ const answerWith = (text: string, url?: string) =>
+ mocks.openPicture.mockImplementation(async () => ({
+ picture: { mime: 'image/jpeg', width: 360, height: 360, data: 'Y29kZQ==', qr: { text, ...(url ? { url } : {}) } },
+ answer: mocks.answer,
+ close: mocks.close,
+ }));
+
+ it('shows the code from the computer, opens its link here first, copies it, and clicks it there', async () => {
+ const link = 'https://login.example.com/qr?t=1';
+ answerWith(link, link);
+ const openExternal = vi.fn(async () => ({ success: true }));
+ const writeText = vi.fn(async () => {});
+ (window as unknown as { electronAPI: object }).electronAPI = { openExternal };
+ Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });
+ vi.spyOn(HTMLImageElement.prototype, 'getBoundingClientRect').mockReturnValue({
+ left: 0, top: 0, width: 240, height: 240, right: 240, bottom: 240, x: 0, y: 0, toJSON: () => ({}),
+ });
+ render(<InputHandoffCard sessionId="s1" snapshot={qrStep()} />);
+ // Nothing is fetched until the owner opens it.
+ expect(mocks.openPicture).not.toHaveBeenCalled();
+ fill('inputHandoff.action.scan');
+ const code = await screen.findByTestId('input-handoff-qr-code');
+ const actions = screen.getAllByRole('button').map((b) => b.textContent);
+ expect(actions.indexOf('inputHandoff.qr.open')).toBeLessThan(actions.indexOf('inputHandoff.qr.copyImage'));
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.qr.open' }));
+ await waitFor(() => expect(openExternal).toHaveBeenCalledWith(link));
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.qr.copyLink' }));
+ await waitFor(() => expect(writeText).toHaveBeenCalledWith(link));
+ fireEvent.click(code, { clientX: 120, clientY: 60 });
+ await waitFor(() =>
+ expect(mocks.answer).toHaveBeenCalledWith({ expectedRevision: 4, values: {}, action: { kind: 'tap', x: 0.5, y: 0.25 } }),
+ );
+ vi.restoreAllMocks();
+ });
+
+ it('leaves an app link to the phone that scans it, and content that is not a link to copy', async () => {
+ answerWith('weixin://dl/login?t=1', 'weixin://dl/login?t=1');
+ const { unmount } = render(<InputHandoffCard sessionId="s1" snapshot={qrStep()} />);
+ fill('inputHandoff.action.scan');
+ await screen.findByTestId('input-handoff-qr-code');
+ expect(screen.queryByRole('button', { name: 'inputHandoff.qr.open' })).toBeNull();
+ expect(screen.getByRole('button', { name: 'inputHandoff.qr.copyLink' })).toBeTruthy();
+ unmount();
+ answerWith('WIFI:S:home;;');
+ render(<InputHandoffCard sessionId="s1" snapshot={qrStep({ requestId: 'req2' })} />);
+ fill('inputHandoff.action.scan');
+ await screen.findByTestId('input-handoff-qr-code');
+ expect(screen.getByRole('button', { name: 'inputHandoff.qr.copyText' })).toBeTruthy();
+ });
+
+ it('waits on the strip once the code was scanned, and loads a refreshed code by itself', async () => {
+ answerWith('https://login.example.com/qr?t=1', 'https://login.example.com/qr?t=1');
+ const { rerender } = render(<InputHandoffCard sessionId="s1" snapshot={qrStep()} />);
+ fill('inputHandoff.action.scan');
+ await screen.findByTestId('input-handoff-qr-code');
+ rerender(<InputHandoffCard sessionId="s1" snapshot={qrStep({ revision: 5 })} />);
+ await waitFor(() => expect(mocks.openPicture).toHaveBeenCalledTimes(2));
+ expect(mocks.close).toHaveBeenCalledTimes(1);
+ rerender(<InputHandoffCard sessionId="s1" snapshot={qrStep({ revision: 6, qr: 'scanned', picture: undefined })} />);
+ expect(screen.queryByTestId('input-handoff-dialog')).toBeNull();
+ expect(screen.getByText('inputHandoff.qr.scanned')).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.action.done' }));
+ await waitFor(() =>
+ expect(mocks.resolve).toHaveBeenCalledWith('req1', { kind: 'input_handoff', action: 'done', expectedRevision: 6 }),
+ );
+ });
+ });
+});
diff --git a/apps/desktop/src/renderer/features/input-handoff/__tests__/InputHandoffPictureStep.test.tsx b/apps/desktop/src/renderer/features/input-handoff/__tests__/InputHandoffPictureStep.test.tsx
new file mode 100644
index 0000000000..697c9e7bdc
--- /dev/null
+++ b/apps/desktop/src/renderer/features/input-handoff/__tests__/InputHandoffPictureStep.test.tsx
@@ -0,0 +1,165 @@
+// @vitest-environment jsdom
+
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { InputHandoffSnapshot } from '@cindy/device-link';
+
+import { InputHandoffCard } from '../InputHandoffCard';
+
+const mocks = vi.hoisted(() => ({
+ answer: vi.fn(async () => ({ accepted: true })),
+ close: vi.fn(),
+ open: vi.fn(),
+ resolve: vi.fn(async () => ({ accepted: true })),
+}));
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+vi.mock('@/contexts/AuthContext', () => ({
+ useOptionalAuthDeviceId: () => 'this-device',
+}));
+vi.mock('@/lib/makerTransport', () => ({
+ submitInputHandoff: vi.fn(),
+ openInputHandoffPicture: mocks.open,
+ makerApiForSticky: () => ({ resolveInteraction: mocks.resolve }),
+}));
+
+beforeEach(() => {
+ mocks.open.mockImplementation(async () => ({
+ picture: { mime: 'image/jpeg', width: 800, height: 600, data: 'AAAA' },
+ answer: mocks.answer,
+ close: mocks.close,
+ }));
+ vi.spyOn(HTMLImageElement.prototype, 'getBoundingClientRect').mockReturnValue({
+ left: 10, top: 20, width: 400, height: 300, right: 410, bottom: 320, x: 10, y: 20, toJSON: () => ({}),
+ });
+});
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+ vi.restoreAllMocks();
+});
+
+let nextRequest = 0;
+const shot = (overrides: Partial<InputHandoffSnapshot> = {}): InputHandoffSnapshot => ({
+ kind: 'input_handoff',
+ requestId: `req${nextRequest}`,
+ revision: 4,
+ phase: 'ready',
+ purpose: 'Sign in to Game',
+ source: { app: 'Game', window: 'Game' },
+ stepNumber: 1,
+ remoteInput: true,
+ controls: [],
+ picture: true,
+ ...overrides,
+});
+
+const fill = () => fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.action.fill' }));
+
+describe('InputHandoffCard screenshot step', () => {
+ beforeEach(() => {
+ nextRequest++;
+ });
+
+ it('opens a fresh picture after a tap that did not go through, so the next tap works', async () => {
+ mocks.answer.mockResolvedValueOnce({ accepted: false });
+ render(<InputHandoffCard sessionId="s1" snapshot={shot()} />);
+ fill();
+ fireEvent.click(await screen.findByRole('button', { name: 'inputHandoff.picture.alt' }), { clientX: 110, clientY: 245 });
+ await waitFor(() => expect(mocks.open).toHaveBeenCalledTimes(2));
+ expect(await screen.findByText('inputHandoff.error.stale')).toBeTruthy();
+ fireEvent.click(await screen.findByRole('button', { name: 'inputHandoff.picture.alt' }), { clientX: 110, clientY: 245 });
+ await waitFor(() => expect(mocks.answer).toHaveBeenCalledTimes(2));
+ });
+
+ it('closes a picture that arrives after the dialog was closed', async () => {
+ let arrive: (value: unknown) => void = () => undefined;
+ mocks.open.mockImplementationOnce(() => new Promise((resolve) => { arrive = resolve; }));
+ const view = render(<InputHandoffCard sessionId="s1" snapshot={shot()} />);
+ fill();
+ await waitFor(() => expect(mocks.open).toHaveBeenCalledTimes(1));
+ view.unmount();
+ arrive({ picture: { mime: 'image/jpeg', width: 800, height: 600, data: 'AAAA' }, answer: mocks.answer, close: mocks.close });
+ await waitFor(() => expect(mocks.close).toHaveBeenCalledTimes(1));
+ });
+
+ it('shows the picture once the owner opens the step, and sends a tap as a fraction', async () => {
+ render(<InputHandoffCard sessionId="s1" snapshot={shot()} />);
+ expect(mocks.open).not.toHaveBeenCalled();
+ fill();
+ const image = await screen.findByRole('button', { name: 'inputHandoff.picture.alt' });
+ expect(mocks.open).toHaveBeenCalledWith('s1', expect.objectContaining({ picture: true, revision: 4 }));
+ fireEvent.click(image, { clientX: 110, clientY: 245 });
+ await waitFor(() => expect(mocks.answer).toHaveBeenCalledWith({
+ expectedRevision: 4,
+ values: {},
+ action: { kind: 'tap', x: 0.25, y: 0.75 },
+ }));
+ // No quiet take-over: that would move the revision under the picture.
+ expect(mocks.resolve).not.toHaveBeenCalled();
+ });
+
+ it('fetches nothing for a task on another computer until the owner opens the step', async () => {
+ render(<InputHandoffCard sessionId="s1" snapshot={shot()} remote />);
+ expect(mocks.open).not.toHaveBeenCalled();
+ fill();
+ await screen.findByRole('button', { name: 'inputHandoff.picture.alt' });
+ expect(mocks.open).toHaveBeenCalledTimes(1);
+ });
+
+ it('types into the focused field with the platform password field', async () => {
+ const snapshot = shot({ controls: [{ id: 'typed', kind: 'text', label: '', contentType: 'password' }] });
+ render(<InputHandoffCard sessionId="s1" snapshot={snapshot} />);
+ fill();
+ const field = (await screen.findByLabelText('inputHandoff.passwordField')) as HTMLInputElement;
+ expect(field.type).toBe('password');
+ fireEvent.change(field, { target: { value: 'synthetic-pass' } });
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.picture.typeEnter' }));
+ await waitFor(() => expect(mocks.answer).toHaveBeenCalledWith({
+ expectedRevision: 4,
+ values: { typed: 'synthetic-pass' },
+ action: { kind: 'submit' },
+ }));
+ await waitFor(() => expect(field.value).toBe(''));
+ });
+
+ it('closes the exchange when the step moves on and opens the next one by itself', async () => {
+ const { rerender } = render(<InputHandoffCard sessionId="s1" snapshot={shot()} remote />);
+ fill();
+ await screen.findByRole('button', { name: 'inputHandoff.picture.alt' });
+ rerender(<InputHandoffCard sessionId="s1" snapshot={shot({ revision: 6 })} remote />);
+ expect(mocks.close).toHaveBeenCalledTimes(1);
+ await waitFor(() => expect(mocks.open).toHaveBeenCalledTimes(2));
+ expect(mocks.open).toHaveBeenLastCalledWith('s1', expect.objectContaining({ revision: 6 }));
+ });
+
+ it('goes back to the form with a value-less decision', async () => {
+ render(<InputHandoffCard sessionId="s1" snapshot={shot()} />);
+ fill();
+ fireEvent.click(await screen.findByRole('button', { name: 'inputHandoff.action.backToForm' }));
+ await waitFor(() => expect(mocks.resolve).toHaveBeenCalledWith(expect.any(String), {
+ kind: 'input_handoff',
+ action: 'refresh',
+ expectedRevision: 4,
+ }));
+ });
+
+ it('offers the picture from a form step', async () => {
+ const form = shot({
+ picture: undefined,
+ controls: [{ id: 'c0', kind: 'text', label: 'Nickname', contentType: 'text' }],
+ });
+ render(<InputHandoffCard sessionId="s1" snapshot={form} />);
+ fill();
+ fireEvent.click(screen.getByRole('button', { name: 'inputHandoff.action.picture' }));
+ await waitFor(() => expect(mocks.resolve).toHaveBeenCalledWith(form.requestId, {
+ kind: 'input_handoff',
+ action: 'picture',
+ expectedRevision: 4,
+ }));
+ expect(mocks.open).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/desktop/src/renderer/features/input-handoff/inputHandoffModel.ts b/apps/desktop/src/renderer/features/input-handoff/inputHandoffModel.ts
new file mode 100644
index 0000000000..586c5d47c2
--- /dev/null
+++ b/apps/desktop/src/renderer/features/input-handoff/inputHandoffModel.ts
@@ -0,0 +1,149 @@
+import {
+ isInputHandoffDeviceCode,
+ type InputHandoffControl,
+ type InputHandoffSnapshot,
+ type InputHandoffValues,
+} from '@cindy/device-link';
+
+/**
+ * 代输入 card model. The snapshot carries step structure only; values the
+ * owner types live in the card's local state and leave only through
+ * makerTransport.submitInputHandoff.
+ */
+
+const PHASES = new Set([
+ 'reading',
+ 'ready',
+ 'working',
+ 'finishing',
+ 'succeeded',
+ 'cancelled',
+ 'failed',
+ 'expired',
+]);
+
+/** Light shape check for pushes; the Host is the authority for every field. */
+export function parsePendingInputHandoff(raw: unknown): InputHandoffSnapshot | null {
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
+ const v = raw as Record<string, unknown>;
+ const source = v.source as Record<string, unknown> | undefined;
+ if (
+ v.kind !== 'input_handoff' ||
+ typeof v.requestId !== 'string' ||
+ !v.requestId ||
+ !Number.isSafeInteger(v.revision) ||
+ !PHASES.has(String(v.phase)) ||
+ typeof v.purpose !== 'string' ||
+ !Array.isArray(v.controls) ||
+ !source ||
+ typeof source.app !== 'string'
+ )
+ return null;
+ return raw as InputHandoffSnapshot;
+}
+
+export function isInputHandoffAwaitingOwner(snapshot: InputHandoffSnapshot | null): boolean {
+ return !!snapshot && snapshot.terminal !== true;
+}
+
+export type InputHandoffTextControl = Extract<InputHandoffControl, { kind: 'text' }>;
+
+/** The fields the owner types into, in screen order. */
+export function textFields(snapshot: InputHandoffSnapshot): InputHandoffTextControl[] {
+ return snapshot.controls.filter((control): control is InputHandoffTextControl => control.kind === 'text');
+}
+
+/** Only fields the owner typed into are applied; text already on the screen stays. */
+export function changedValues(
+ snapshot: InputHandoffSnapshot,
+ draft: InputHandoffValues,
+): InputHandoffValues {
+ const out: InputHandoffValues = {};
+ for (const control of textFields(snapshot)) {
+ const value = draft[control.id];
+ if (value) out[control.id] = value;
+ }
+ return out;
+}
+
+/** Standard platform autofill hints so password managers recognize the field. */
+export function autoCompleteFor(control: InputHandoffTextControl): string {
+ switch (control.contentType) {
+ case 'password':
+ return 'current-password';
+ case 'one-time-code':
+ return 'one-time-code';
+ case 'username':
+ return 'username';
+ case 'email':
+ return 'email';
+ case 'tel':
+ return 'tel';
+ case 'url':
+ return 'url';
+ default:
+ return 'off';
+ }
+}
+
+export function inputTypeFor(control: InputHandoffTextControl): string {
+ switch (control.contentType) {
+ case 'password':
+ return 'password';
+ case 'email':
+ return 'email';
+ case 'tel':
+ return 'tel';
+ case 'url':
+ return 'url';
+ case 'search':
+ return 'search';
+ default:
+ return 'text';
+ }
+}
+
+export function inputModeFor(
+ control: InputHandoffTextControl,
+): 'numeric' | 'email' | 'tel' | 'url' | 'text' {
+ switch (control.contentType) {
+ case 'one-time-code':
+ case 'number':
+ return 'numeric';
+ case 'email':
+ return 'email';
+ case 'tel':
+ return 'tel';
+ case 'url':
+ return 'url';
+ default:
+ return 'text';
+ }
+}
+
+/** Where the value goes, as the owner checks it: a secure site's host (with a lock), otherwise the origin or app. */
+export function inputHandoffPlace(source: InputHandoffSnapshot['source']): { label: string; secure: boolean } {
+ const origin = source.origin;
+ if (!origin) return { label: source.app, secure: false };
+ if (origin.startsWith('https://') && !source.warning) return { label: origin.slice('https://'.length), secure: true };
+ return { label: origin, secure: false };
+}
+
+export type InputHandoffPlaceKind = 'web' | 'terminal' | 'app';
+
+export const inputHandoffPlaceKind = (snapshot: InputHandoffSnapshot): InputHandoffPlaceKind =>
+ snapshot.command ? 'terminal' : snapshot.source.origin ? 'web' : 'app';
+
+/** The dialog opens only on a screen with something for the owner: fields, a picture, a QR code or a sign-in code. */
+export function inputHandoffDialogHasContent(snapshot: InputHandoffSnapshot, heldElsewhere: boolean): boolean {
+ if (snapshot.terminal || snapshot.phase !== 'ready' || heldElsewhere) return false;
+ return Boolean(snapshot.picture) || isInputHandoffDeviceCode(snapshot.deviceCode) || textFields(snapshot).length > 0;
+}
+
+/** What the dialog asks for: typing, a QR code to scan, a sign-in code to use elsewhere, or a picture of the screen. */
+export function inputHandoffDialogMode(snapshot: InputHandoffSnapshot): 'qr' | 'picture' | 'code' | 'fields' {
+ if (snapshot.picture && snapshot.qr === 'scan') return 'qr';
+ if (snapshot.picture) return 'picture';
+ if (isInputHandoffDeviceCode(snapshot.deviceCode) && textFields(snapshot).length === 0) return 'code';
+ return 'fields';
+}
diff --git a/apps/desktop/src/renderer/features/remote-desktop/RemoteDesktopViewerWindow.tsx b/apps/desktop/src/renderer/features/remote-desktop/RemoteDesktopViewerWindow.tsx
index e4bb5bf375..3f6917e17f 100644
--- a/apps/desktop/src/renderer/features/remote-desktop/RemoteDesktopViewerWindow.tsx
+++ b/apps/desktop/src/renderer/features/remote-desktop/RemoteDesktopViewerWindow.tsx
@@ -357,6 +357,12 @@ export function RemoteDesktopViewerWindow() {
<div className="remote-viewer-heading">
<span className="remote-viewer-title">
{state?.target?.name ?? t('remoteDesktop.title')}
+ {state?.window && (
+ <>
+ <span aria-hidden="true"> · </span>
+ {t('remoteDesktop.handoffWindow', { app: state.window.app })}
+ </>
+ )}
</span>
<div className="remote-viewer-status">
<span>
@@ -386,68 +392,71 @@ export function RemoteDesktopViewerWindow() {
)}
</div>
</div>
- <div
- className="remote-viewer-toolgroup"
- role="group"
- aria-label={t('remoteDesktop.viewer.controlGroup')}
- >
- {state?.caps?.workspaceNavigation ? (
- <>
- <ViewerTool
- label={t('remoteDesktop.workspaceLeft')}
- disabled={!state.controlling || state.controlPending}
- onClick={() => workspaceAction('workspaceLeft')}
- >
- <WorkspaceLeftIcon size={16} />
- </ViewerTool>
+ {/* A 代输入 window view has no desktop to navigate. */}
+ {!state?.target?.handoff && (
+ <div
+ className="remote-viewer-toolgroup"
+ role="group"
+ aria-label={t('remoteDesktop.viewer.controlGroup')}
+ >
+ {state?.caps?.workspaceNavigation ? (
+ <>
+ <ViewerTool
+ label={t('remoteDesktop.workspaceLeft')}
+ disabled={!state.controlling || state.controlPending}
+ onClick={() => workspaceAction('workspaceLeft')}
+ >
+ <WorkspaceLeftIcon size={16} />
+ </ViewerTool>
+ <ViewerTool
+ label={t('remoteDesktop.workspaceRight')}
+ disabled={!state.controlling || state.controlPending}
+ onClick={() => workspaceAction('workspaceRight')}
+ >
+ <WorkspaceRightIcon size={16} />
+ </ViewerTool>
+ </>
+ ) : (
+ <>
+ <ViewerTool
+ label={t('remoteDesktop.allWindows')}
+ disabled={!state?.controlling || state.controlPending}
+ onClick={() =>
+ controller.current?.keys(
+ state?.caps?.platform === 'darwin'
+ ? ['ControlLeft', 'ArrowUp']
+ : ['MetaLeft', 'Tab'],
+ )
+ }
+ >
+ <AllWindowsIcon size={16} />
+ </ViewerTool>
+ <ViewerTool
+ label={t('remoteDesktop.showDesktop')}
+ disabled={!state?.controlling || state.controlPending}
+ onClick={() =>
+ // Cmd+F3 only works from the physical Mission Control key; a
+ // synthesized F3 keycode never triggers it. F11 is the default.
+ controller.current?.keys(
+ state?.caps?.platform === 'darwin' ? ['F11'] : ['MetaLeft', 'KeyD'],
+ )
+ }
+ >
+ <ShowDesktopIcon size={16} />
+ </ViewerTool>
+ </>
+ )}
+ {state?.caps?.omarchyMenu && (
<ViewerTool
- label={t('remoteDesktop.workspaceRight')}
+ label={t('remoteDesktop.omarchyMenu')}
disabled={!state.controlling || state.controlPending}
- onClick={() => workspaceAction('workspaceRight')}
- >
- <WorkspaceRightIcon size={16} />
- </ViewerTool>
- </>
- ) : (
- <>
- <ViewerTool
- label={t('remoteDesktop.allWindows')}
- disabled={!state?.controlling || state.controlPending}
- onClick={() =>
- controller.current?.keys(
- state?.caps?.platform === 'darwin'
- ? ['ControlLeft', 'ArrowUp']
- : ['MetaLeft', 'Tab'],
- )
- }
+ onClick={() => workspaceAction('omarchyMenu')}
>
- <AllWindowsIcon size={16} />
+ <OmarchyMenuIcon size={16} />
</ViewerTool>
- <ViewerTool
- label={t('remoteDesktop.showDesktop')}
- disabled={!state?.controlling || state.controlPending}
- onClick={() =>
- // Cmd+F3 only works from the physical Mission Control key; a
- // synthesized F3 keycode never triggers it. F11 is the default.
- controller.current?.keys(
- state?.caps?.platform === 'darwin' ? ['F11'] : ['MetaLeft', 'KeyD'],
- )
- }
- >
- <ShowDesktopIcon size={16} />
- </ViewerTool>
- </>
- )}
- {state?.caps?.omarchyMenu && (
- <ViewerTool
- label={t('remoteDesktop.omarchyMenu')}
- disabled={!state.controlling || state.controlPending}
- onClick={() => workspaceAction('omarchyMenu')}
- >
- <OmarchyMenuIcon size={16} />
- </ViewerTool>
- )}
- </div>
+ )}
+ </div>
+ )}
<div className="remote-viewer-zoom-group" role="group" aria-label={t('remoteDesktop.fit')}>
<ViewerTool
label={t('remoteDesktop.zoomOut')}
@@ -493,7 +502,7 @@ export function RemoteDesktopViewerWindow() {
restoreFocus={() => activePanel.current === null}
onOpenChange={(open) => openPanel('display', open)}
>
- {(state?.caps?.displays.length ?? 0) > 1 && (
+ {!state?.target?.handoff && (state?.caps?.displays.length ?? 0) > 1 && (
<Select
label={t('remoteDesktop.display')}
className="remote-viewer-display-select"
diff --git a/apps/desktop/src/renderer/features/remote-desktop/viewerController.ts b/apps/desktop/src/renderer/features/remote-desktop/viewerController.ts
index fb6dd5934a..a7b96b01c4 100644
--- a/apps/desktop/src/renderer/features/remote-desktop/viewerController.ts
+++ b/apps/desktop/src/renderer/features/remote-desktop/viewerController.ts
@@ -60,6 +60,8 @@ export interface ViewerSnapshot {
credentialNotice: string | null;
/** The picture was fitted to this window; restore and same-ratio sizes apply. */
fittedDisplay: Size | null;
+ /** 代输入 window view: the one window shown (only it can be clicked or typed into). */
+ window?: { app: string; title?: string } | null;
}
const sameAspect = (display: Size, width: number, height: number) =>
@@ -402,6 +404,7 @@ export class DesktopViewerController {
displayId: this.state.displayId || undefined,
resume,
takeover,
+ ...(this.scope.target?.handoff ? { handoff: this.scope.target.handoff } : {}),
// Desktop always operates; a host with `autoControl` grants it with the lease.
control: true,
isCurrent: () => this.epoch === epoch && !this.disposed && this.scope.active,
@@ -411,7 +414,12 @@ export class DesktopViewerController {
},
});
if (epoch !== this.epoch) return;
- this.publish({ caps, displayId: lease.display.id, status: 'connecting' });
+ this.publish({
+ caps,
+ displayId: lease.display.id,
+ status: 'connecting',
+ window: lease.window ?? null,
+ });
this.runtime.receive({
type: 'init',
epoch: lease.lease,
diff --git a/apps/desktop/src/renderer/hooks/useCCAgentChat.ts b/apps/desktop/src/renderer/hooks/useCCAgentChat.ts
index 26342e2e19..839936ad2f 100644
--- a/apps/desktop/src/renderer/hooks/useCCAgentChat.ts
+++ b/apps/desktop/src/renderer/hooks/useCCAgentChat.ts
@@ -15,6 +15,7 @@
* inside the store.
*/
+import type { InputHandoffSnapshot } from '@cindy/device-link';
import {
useCallback,
useEffect,
@@ -275,6 +276,8 @@ interface UseCCAgentChatReturn {
pendingGhostGrantConfirm: PendingGhostGrantConfirm | null;
/** Device Link Desktop controller: read-only host confirmation status. */
pendingRemoteDesktopConfirmation: PendingRemoteDesktopConfirmation | null;
+ /** 代输入: current step snapshot (structure only; values stay in the card). */
+ pendingInputHandoff: InputHandoffSnapshot | null;
/** ghost_grant_confirm: Respond to the pending ghost file-grant confirm card */
respondToGhostGrantConfirm: (
result: { confirmed: true; allowDirs?: boolean } | { confirmed: false },
@@ -923,6 +926,7 @@ export function useCCAgentChat(
respondToRenameSessionsConfirm,
pendingGhostGrantConfirm: lightState.pendingGhostGrantConfirm,
pendingRemoteDesktopConfirmation: lightState.pendingRemoteDesktopConfirmation,
+ pendingInputHandoff: lightState.pendingInputHandoff,
respondToGhostGrantConfirm,
planViewerState: lightState.planViewerState,
setPlanViewerState,
diff --git a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts
index db9eeaefb7..ea5a202263 100644
--- a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts
+++ b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts
@@ -20,6 +20,8 @@
* the active session (FP-3).
* - It has pending local plugin setup (`hasPendingPluginSetup`) while NOT
* being the active session.
+ * - It has a pending input handoff (`hasPendingInputHandoff`, 代输入) while
+ * NOT being the active session.
*
* Notifications are cleared when:
* - The user navigates to that session (clicks it) — done / awaiting only。
@@ -304,7 +306,8 @@ export function useSessionRunningStatus(
(cur.hasPendingAskUser ||
cur.hasPendingPermission ||
cur.hasPendingPlanReview ||
- cur.hasPendingPluginSetup);
+ cur.hasPendingPluginSetup ||
+ cur.hasPendingInputHandoff === true);
// silenced 可能在 debounce 窗口内才到:转换当时没静默、进了 debounce,落地必须再读。
if (!hasTerminalError && (isSessionDoneSilenced(sessionId)
|| makerChatStore.wasLastStopQuietCompletion(sessionId))) return;
@@ -335,7 +338,8 @@ export function useSessionRunningStatus(
info.hasPendingAskUser ||
info.hasPendingPermission ||
info.hasPendingPlanReview ||
- info.hasPendingPluginSetup
+ info.hasPendingPluginSetup ||
+ info.hasPendingInputHandoff === true
) {
currentPendingSet.add(id);
const isActive = id === activeSessionId;
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 71e3ac3c79..e939628204 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -757,7 +757,10 @@
"copy": "Copy to this computer",
"paste": "Paste to remote computer",
"clipboardSyncHint": "Sync text, images and rich text both ways while this window is in the foreground.",
- "credentialRequired": "Complete Mac password verification. If unavailable, update Cindy on both computers."
+ "credentialRequired": "Complete Mac password verification. If unavailable, update Cindy on both computers.",
+ "handoffEnded": "This input handoff has already finished, so there is no window to show.",
+ "handoffUnavailable": "This computer can't show just this window. Update Cindy on it, or turn on remote desktop there.",
+ "handoffWindow": "Input handoff · {{app}}"
},
"ipcError": {
"DEVICE_LINK_BUSY": "The remote computer is busy. Please try again shortly.",
@@ -1660,6 +1663,7 @@
"done": "Completed ✓",
"error": "Failed",
"needsReply": "Reply needed",
+ "inputHandoff": "Input handoff needed",
"externalDone": "Cindy · Session “{{title}}” completed ✓",
"externalError": "Cindy · Session “{{title}}” failed",
"externalNeedsReply": "Cindy · Session “{{title}}” needs your reply",
@@ -9301,7 +9305,11 @@
"configure": "Open configuration",
"empty_toolset": "No built-in tools are available on this execution target.",
"empty_mcp": "No custom MCP servers have been added.",
- "empty_skill": "No skills are available to select."
+ "empty_skill": "No skills are available to select.",
+ "inputHandoff": {
+ "title": "Input Handoff",
+ "description": "When this teammate reaches a sign-in, password or code it can't type itself, it may ask you to type it on any of your devices. Your values are never shared with it."
+ }
},
"guided": {
"title": "Create a teammate",
@@ -11631,7 +11639,8 @@
"awaitingPermission": "Awaiting permission",
"awaitingQuestion": "Awaiting your reply",
"awaitingPlan": "Awaiting plan review",
- "awaitingPluginSetup": "Awaiting plugin setup"
+ "awaitingPluginSetup": "Awaiting plugin setup",
+ "awaitingInputHandoff": "Awaiting input handoff"
},
"showAllSessions": "Show all {{count}}",
"allSessions": "All sessions",
@@ -13200,6 +13209,125 @@
"deny": "Deny"
}
},
+ "inputHandoff": {
+ "originWarning": {
+ "insecure": "This page doesn't use a secure connection. What you enter could be read by others.",
+ "ip-address": "This page uses an IP address instead of a domain. Make sure it's the site you expect.",
+ "local-host": "This page comes from a service on this computer. Make sure it's the app you expect.",
+ "local-file": "This page is a local file. Make sure it's what you expect.",
+ "punycode": "This address contains unusual characters and may imitate another site. Check it carefully.",
+ "embedded-frame": "These fields are inside another site embedded in the page. Make sure the source is trusted."
+ },
+ "agentControlled": "The agent opened this screen. Make sure it's really where you want to sign in before filling it.",
+ "error": {
+ "decision": "That didn't go through. Try again.",
+ "stale": "The screen has changed. Use the latest version.",
+ "submit": "Your input didn't go through. Try again."
+ },
+ "terminal": {
+ "succeeded": "Handed back to the agent.",
+ "cancelled": "Input handoff canceled.",
+ "failed": "Input handoff ended.",
+ "expired": "Input handoff ended after waiting too long."
+ },
+ "failure": {
+ "permission": "Cindy can't read this computer's screen. Allow Cindy under Accessibility in System Settings.",
+ "target_gone": "The target window was closed.",
+ "unreadable": "This screen can't be read. You can finish it on the host computer, then hand back to the agent.",
+ "action_failed": "That action didn't take effect. Check the screen and try again.",
+ "timeout": "Input handoff ended after waiting too long.",
+ "unsupported": "This computer doesn't support input handoff yet.",
+ "origin_changed": "The page changed before Cindy could fill it, so nothing was entered. Check the current page, then try again.",
+ "picture_unavailable": "Couldn't show this step as a picture. Allow Cindy to record the screen in System Settings, and make sure the window isn't minimized.",
+ "screen_locked": "This computer's screen is locked (a display going to sleep locks it too). Wake and unlock it, then ask the agent to try again.",
+ "nothing_to_fill": "Nothing on this screen needs typing, so the agent carries on by itself."
+ },
+ "phase": {
+ "reading": "Reading the screen…",
+ "working": "Filling in…",
+ "finishing": "Looks complete. Handing back to the agent in {{count}}s.",
+ "finishingNow": "Looks complete. Handing back to the agent…"
+ },
+ "action": {
+ "stay": "Not Done Yet",
+ "done": "Hand Back to Agent",
+ "claim": "Handle Here",
+ "picture": "Show screen",
+ "backToForm": "Back to form",
+ "liveView": "Live View",
+ "fill": "Fill In",
+ "skip": "Skip",
+ "continue": "Continue",
+ "close": "Cancel",
+ "showPassword": "Show Password",
+ "hidePassword": "Hide Password",
+ "scan": "Scan"
+ },
+ "remoteUnavailable": "This computer can't receive input remotely. Finish this step on the host computer, then hand back to the agent.",
+ "unnamedField": "Field",
+ "passwordField": "Password",
+ "codeField": "Verification code",
+ "filledHint": "Already has content. Leave empty to keep it.",
+ "record": {
+ "doneOn_one": "Owner finished {{count}} input step on {{device}}",
+ "doneOn_other": "Owner finished {{count}} input steps on {{device}}",
+ "doneHost_one": "Owner finished {{count}} input step on the host computer",
+ "doneHost_other": "Owner finished {{count}} input steps on the host computer",
+ "donePhone_one": "Owner finished {{count}} input step on a phone",
+ "donePhone_other": "Owner finished {{count}} input steps on a phone",
+ "doneElsewhere_one": "Owner finished {{count}} input step on another device",
+ "doneElsewhere_other": "Owner finished {{count}} input steps on another device",
+ "done": "Input handoff finished",
+ "nothingToFill": "Nothing to type; handed back to the agent",
+ "cancelled": "Input handoff cancelled",
+ "expired": "Input handoff timed out",
+ "failed": "Input handoff didn't finish"
+ },
+ "holder": {
+ "elsewhere": "Being handled on {{device}}. You can take it over here.",
+ "host": "the host computer",
+ "phone": "a phone",
+ "otherDevice": "another device"
+ },
+ "agentNote": "Note from the agent: {{note}}",
+ "picture": {
+ "hint": "Tap a spot in the picture and Cindy taps the same spot on the host computer.",
+ "open": "Show this step",
+ "alt": "Picture of the target window",
+ "loading": "Getting the picture…",
+ "error": "Couldn't get the picture. Try again.",
+ "field": "Focused field",
+ "type": "Type",
+ "typeEnter": "Type and press Return"
+ },
+ "deviceCode": {
+ "prompt": "Sign in with this code",
+ "copy": "Copy Code",
+ "copied": "Code copied",
+ "copyFailed": "Couldn't copy the code",
+ "open": "Open on This Device",
+ "openFailed": "Couldn't open the link",
+ "then": "Enter the code on that page and finish signing in, then choose Hand Back to Agent."
+ },
+ "nothingLeft": "Nothing here needs you to type.",
+ "dialogNote": "Typed only into this spot on the computer. Never given to the agent or saved.",
+ "qr": {
+ "open": "Open {{site}} Here",
+ "copyLink": "Copy Link",
+ "copyText": "Copy Text",
+ "copied": "Copied.",
+ "copyFailed": "Couldn't copy. Try again.",
+ "loading": "Getting the QR code…",
+ "scanned": "Scanned. Confirm on your phone; Cindy continues once you do.",
+ "hint": "Scan this code with your phone to sign in. Cindy continues once you're signed in.",
+ "hintLink": "Scan this code with your phone, or open the link here to sign in. Cindy continues once you're signed in.",
+ "copyImage": "Copy Image",
+ "imageCopied": "Image copied.",
+ "openFailed": "Couldn't open this link. You can scan the code with your phone.",
+ "alt": "The QR code on the computer. Clicking clicks this spot on the code there.",
+ "failed": "Couldn't get the QR code. Click to try again."
+ }
+ },
"commandPalette": {
"viewSkillDetails": "View skill details",
"projectSkillNotLoaded": "This Pi task hasn't loaded this project Skill. New tasks will automatically try to load it."
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 106f3c47d9..a792a77050 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -751,7 +751,10 @@
"copy": "このパソコンにコピー",
"paste": "リモートパソコンに貼り付け",
"clipboardSyncHint": "このウィンドウが最前面にある間、テキスト、画像、リッチテキストを双方向に同期します。",
- "credentialRequired": "Mac のパスワードを確認してください。確認できない場合は両方のパソコンで Cindy を更新してください。"
+ "credentialRequired": "Mac のパスワードを確認してください。確認できない場合は両方のパソコンで Cindy を更新してください。",
+ "handoffEnded": "この代理入力はすでに終了しているため、表示するウィンドウがありません。",
+ "handoffUnavailable": "このコンピュータではこのウィンドウだけを表示できません。そのコンピュータで Cindy を更新するか、リモートデスクトップをオンにしてください。",
+ "handoffWindow": "代理入力 · {{app}}"
},
"ipcError": {
"DEVICE_LINK_BUSY": "接続先のコンピュータが混み合っています。しばらくしてから再試行してください。",
@@ -1637,6 +1640,7 @@
"done": "完了しました ✓",
"error": "実行に失敗しました",
"needsReply": "返信が必要です",
+ "inputHandoff": "代理入力が必要です",
"externalDone": "Cindy · セッション「{{title}}」が完了しました ✓",
"externalError": "Cindy · セッション「{{title}}」の実行に失敗しました",
"externalNeedsReply": "Cindy · セッション「{{title}}」への返信が必要です",
@@ -9264,7 +9268,11 @@
"configure": "設定を開く",
"empty_toolset": "この実行環境には利用できる内蔵ツールがありません。",
"empty_mcp": "カスタム MCP サーバーはまだ追加されていません。",
- "empty_skill": "選択できるスキルはありません。"
+ "empty_skill": "選択できるスキルはありません。",
+ "inputHandoff": {
+ "title": "代理入力",
+ "description": "サインイン情報、パスワード、確認コードなど本人の入力が必要なとき、この仲間がいずれかのデバイスでの入力を依頼できます。入力した内容が仲間に渡ることはありません。"
+ }
},
"guided": {
"title": "パートナーを作成",
@@ -11581,7 +11589,8 @@
"awaitingPermission": "承認待ち",
"awaitingQuestion": "返信待ち",
"awaitingPlan": "プランの確認待ち",
- "awaitingPluginSetup": "プラグイン設定待ち"
+ "awaitingPluginSetup": "プラグイン設定待ち",
+ "awaitingInputHandoff": "代理入力待ち"
},
"showAllSessions": "すべて表示 {{count}} 件",
"allSessions": "すべてのセッション",
@@ -13149,6 +13158,125 @@
"deny": "拒否"
}
},
+ "inputHandoff": {
+ "originWarning": {
+ "insecure": "このページは安全な接続を使っていません。入力内容が他人に読まれる可能性があります。",
+ "ip-address": "このページはドメインではなく IP アドレスを使っています。想定したサイトか確認してください。",
+ "local-host": "このページはこのコンピュータ上のサービスから表示されています。想定したアプリか確認してください。",
+ "local-file": "このページはローカルファイルです。想定した内容か確認してください。",
+ "punycode": "このアドレスには特殊な文字が含まれ、別のサイトを装っている可能性があります。よく確認してください。",
+ "embedded-frame": "入力欄はページに埋め込まれた別サイトの中にあります。提供元が信頼できるか確認してください。"
+ },
+ "agentControlled": "この画面は Agent が開きました。入力する前に、本当にサインインしたい場所か確認してください。",
+ "error": {
+ "decision": "操作が届きませんでした。もう一度お試しください。",
+ "stale": "画面が変わりました。最新の内容で操作してください。",
+ "submit": "入力が届きませんでした。もう一度お試しください。"
+ },
+ "terminal": {
+ "succeeded": "Agent に戻しました。",
+ "cancelled": "代理入力をキャンセルしました。",
+ "failed": "代理入力は終了しました。",
+ "expired": "待ち時間が長すぎたため、代理入力は終了しました。"
+ },
+ "failure": {
+ "permission": "Cindy にこのコンピュータの画面を読む権限がありません。システム設定のアクセシビリティで Cindy を許可してください。",
+ "target_gone": "対象のウインドウが閉じられました。",
+ "unreadable": "この画面を読み取れません。ホストのコンピュータで直接完了してから Agent に戻してください。",
+ "action_failed": "直前の操作が反映されませんでした。画面を確認してもう一度お試しください。",
+ "timeout": "待ち時間が長すぎたため、代理入力は終了しました。",
+ "unsupported": "このコンピュータはまだ代理入力に対応していません。",
+ "origin_changed": "入力前にページが変わったため、何も入力していません。現在のページを確認してからもう一度入力してください。",
+ "picture_unavailable": "このステップの画面を表示できませんでした。システム設定で Cindy の画面収録を許可し、ウインドウが最小化されていないか確認してください。",
+ "screen_locked": "このコンピュータの画面はロックされています(ディスプレイのスリープでもロックされます)。スリープを解除してロックを外してから、Agent にもう一度試すよう伝えてください。",
+ "nothing_to_fill": "この画面には入力が必要な項目がないため、Agent がそのまま続けます。"
+ },
+ "phase": {
+ "reading": "画面を読み取っています…",
+ "working": "入力しています…",
+ "finishing": "完了したようです。{{count}} 秒後に Agent に戻します。",
+ "finishingNow": "完了したようです。Agent に戻しています…"
+ },
+ "action": {
+ "stay": "まだ終わっていない",
+ "done": "Agent に戻す",
+ "claim": "ここで対応",
+ "picture": "画面を見る",
+ "backToForm": "フォームに戻る",
+ "liveView": "ライブ表示",
+ "fill": "入力",
+ "skip": "スキップ",
+ "continue": "続ける",
+ "close": "キャンセル",
+ "showPassword": "パスワードを表示",
+ "hidePassword": "パスワードを隠す",
+ "scan": "スキャン"
+ },
+ "remoteUnavailable": "このコンピュータはリモートから入力を受け取れません。ホストのコンピュータでこのステップを完了してから Agent に戻してください。",
+ "unnamedField": "入力欄",
+ "passwordField": "パスワード",
+ "codeField": "確認コード",
+ "filledHint": "すでに入力済みです。空欄のままにすると変更しません。",
+ "record": {
+ "doneOn_one": "オーナーが {{device}} で {{count}} ステップの入力を完了しました",
+ "doneOn_other": "オーナーが {{device}} で {{count}} ステップの入力を完了しました",
+ "doneHost_one": "オーナーがホストのコンピュータで {{count}} ステップの入力を完了しました",
+ "doneHost_other": "オーナーがホストのコンピュータで {{count}} ステップの入力を完了しました",
+ "donePhone_one": "オーナーがスマートフォンで {{count}} ステップの入力を完了しました",
+ "donePhone_other": "オーナーがスマートフォンで {{count}} ステップの入力を完了しました",
+ "doneElsewhere_one": "オーナーが別のデバイスで {{count}} ステップの入力を完了しました",
+ "doneElsewhere_other": "オーナーが別のデバイスで {{count}} ステップの入力を完了しました",
+ "done": "代理入力が完了しました",
+ "nothingToFill": "入力不要のため Agent に戻しました",
+ "cancelled": "代理入力をキャンセルしました",
+ "expired": "代理入力がタイムアウトしました",
+ "failed": "代理入力は完了しませんでした"
+ },
+ "holder": {
+ "elsewhere": "{{device}} で対応中です。ここで引き継ぐこともできます。",
+ "host": "ホストのコンピュータ",
+ "phone": "スマートフォン",
+ "otherDevice": "別のデバイス"
+ },
+ "agentNote": "Agentからの補足:{{note}}",
+ "picture": {
+ "hint": "画面上の位置をタップすると、Cindy がホストのコンピュータで同じ位置をクリックします。",
+ "open": "このステップの画面を表示",
+ "alt": "対象ウインドウの画面",
+ "loading": "画面を取得しています…",
+ "error": "画面を取得できませんでした。もう一度お試しください。",
+ "field": "選択中の入力欄",
+ "type": "入力",
+ "typeEnter": "入力して Return"
+ },
+ "deviceCode": {
+ "prompt": "このコードでサインイン",
+ "copy": "コードをコピー",
+ "copied": "コードをコピーしました",
+ "copyFailed": "コピーできませんでした",
+ "open": "このデバイスで開く",
+ "openFailed": "リンクを開けませんでした",
+ "then": "開いたページでコードを入力してサインインを完了したら、「Agent に戻す」を選んでください。"
+ },
+ "nothingLeft": "ここで入力が必要な項目はありません。",
+ "dialogNote": "コンピュータ上のこの場所にだけ入力されます。Agent に渡したり保存したりすることはありません。",
+ "qr": {
+ "open": "この端末で {{site}} を開く",
+ "copyLink": "リンクをコピー",
+ "copyText": "内容をコピー",
+ "copied": "コピーしました。",
+ "copyFailed": "コピーできませんでした。もう一度お試しください。",
+ "loading": "QR コードを取得しています…",
+ "scanned": "スキャンしました。スマートフォンで確認してください。確認後は自動で続行します。",
+ "hint": "スマートフォンでこのコードを読み取ってログインしてください。ログイン後は自動で続行します。",
+ "hintLink": "スマートフォンでこのコードを読み取るか、この端末でリンクを開いてログインしてください。ログイン後は自動で続行します。",
+ "copyImage": "画像をコピー",
+ "imageCopied": "画像をコピーしました。",
+ "openFailed": "このリンクを開けませんでした。スマートフォンでコードを読み取ってください。",
+ "alt": "コンピュータ上の QR コード。クリックするとコンピュータ上の同じ位置をクリックします。",
+ "failed": "QR コードを取得できませんでした。クリックして再試行してください。"
+ }
+ },
"commandPalette": {
"viewSkillDetails": "スキルの詳細を見る",
"projectSkillNotLoaded": "現在の Pi タスクでは、このプロジェクト Skill はまだ読み込まれていません。新しいタスクでは自動的に読み込みを試みます。"
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index fd874858d5..4bb5e0680b 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -751,7 +751,10 @@
"copy": "이 컴퓨터로 복사",
"paste": "원격 컴퓨터에 붙여넣기",
"clipboardSyncHint": "이 창이 전면에 있을 때 텍스트, 이미지, 서식 있는 텍스트를 양방향으로 동기화합니다.",
- "credentialRequired": "Mac 암호를 확인하세요. 확인할 수 없으면 두 컴퓨터에서 Cindy를 업데이트하세요."
+ "credentialRequired": "Mac 암호를 확인하세요. 확인할 수 없으면 두 컴퓨터에서 Cindy를 업데이트하세요.",
+ "handoffEnded": "이 대리 입력은 이미 끝나서 표시할 창이 없습니다.",
+ "handoffUnavailable": "이 컴퓨터에서는 이 창만 표시할 수 없습니다. 해당 컴퓨터에서 Cindy를 업데이트하거나 원격 데스크톱을 켜세요.",
+ "handoffWindow": "대리 입력 · {{app}}"
},
"ipcError": {
"DEVICE_LINK_BUSY": "원격 컴퓨터가 사용 중입니다. 잠시 후 다시 시도해 주세요.",
@@ -1637,6 +1640,7 @@
"done": "완료됨 ✓",
"error": "실행 실패",
"needsReply": "답변이 필요합니다",
+ "inputHandoff": "대리 입력이 필요합니다",
"externalDone": "Cindy · 세션 “{{title}}” 완료됨 ✓",
"externalError": "Cindy · 세션 “{{title}}” 실행 실패",
"externalNeedsReply": "Cindy · 세션 “{{title}}”에 답변이 필요합니다",
@@ -9264,7 +9268,11 @@
"configure": "설정 열기",
"empty_toolset": "이 실행 환경에 사용 가능한 내장 도구가 없습니다.",
"empty_mcp": "사용자 지정 MCP 서버가 아직 추가되지 않았습니다.",
- "empty_skill": "선택할 수 있는 스킬이 없습니다."
+ "empty_skill": "선택할 수 있는 스킬이 없습니다.",
+ "inputHandoff": {
+ "title": "대리 입력",
+ "description": "로그인 정보, 비밀번호, 인증 코드처럼 본인 입력이 필요할 때 이 동료가 어느 기기에서든 입력을 요청할 수 있습니다. 입력한 내용은 동료에게 전달되지 않습니다."
+ }
},
"guided": {
"title": "파트너 만들기",
@@ -11581,7 +11589,8 @@
"awaitingPermission": "승인 대기 중",
"awaitingQuestion": "답장 대기 중",
"awaitingPlan": "계획 검토 대기 중",
- "awaitingPluginSetup": "플러그인 설정 대기 중"
+ "awaitingPluginSetup": "플러그인 설정 대기 중",
+ "awaitingInputHandoff": "대리 입력 대기 중"
},
"showAllSessions": "모두 표시 {{count}}개",
"allSessions": "모든 세션",
@@ -13149,6 +13158,125 @@
"deny": "거부"
}
},
+ "inputHandoff": {
+ "originWarning": {
+ "insecure": "이 페이지는 보안 연결을 사용하지 않습니다. 입력한 내용이 다른 사람에게 노출될 수 있습니다.",
+ "ip-address": "이 페이지는 도메인 대신 IP 주소를 사용합니다. 예상한 사이트인지 확인하세요.",
+ "local-host": "이 페이지는 이 컴퓨터의 서비스에서 제공됩니다. 예상한 앱인지 확인하세요.",
+ "local-file": "이 페이지는 로컬 파일입니다. 예상한 내용인지 확인하세요.",
+ "punycode": "이 주소에는 특수 문자가 포함되어 다른 사이트를 사칭할 수 있습니다. 자세히 확인하세요.",
+ "embedded-frame": "입력란이 페이지에 삽입된 다른 사이트 안에 있습니다. 출처를 신뢰할 수 있는지 확인하세요."
+ },
+ "agentControlled": "이 화면은 Agent가 열었습니다. 입력하기 전에 실제로 로그인하려는 곳인지 확인하세요.",
+ "error": {
+ "decision": "요청이 전달되지 않았습니다. 다시 시도하세요.",
+ "stale": "화면이 바뀌었습니다. 최신 내용으로 진행하세요.",
+ "submit": "입력이 전달되지 않았습니다. 다시 시도하세요."
+ },
+ "terminal": {
+ "succeeded": "Agent에게 넘겼습니다.",
+ "cancelled": "대리 입력을 취소했습니다.",
+ "failed": "대리 입력이 종료되었습니다.",
+ "expired": "대기 시간이 너무 길어 대리 입력이 종료되었습니다."
+ },
+ "failure": {
+ "permission": "Cindy에 이 컴퓨터 화면을 읽을 권한이 없습니다. 시스템 설정의 손쉬운 사용에서 Cindy를 허용하세요.",
+ "target_gone": "대상 창이 닫혔습니다.",
+ "unreadable": "이 화면을 읽을 수 없습니다. 호스트 컴퓨터에서 직접 완료한 뒤 Agent에게 넘기세요.",
+ "action_failed": "방금 작업이 적용되지 않았습니다. 화면을 확인하고 다시 시도하세요.",
+ "timeout": "대기 시간이 너무 길어 대리 입력이 종료되었습니다.",
+ "unsupported": "이 컴퓨터는 아직 대리 입력을 지원하지 않습니다.",
+ "origin_changed": "입력하기 전에 페이지가 바뀌어 아무것도 입력하지 않았습니다. 현재 페이지를 확인한 후 다시 입력하세요.",
+ "picture_unavailable": "이 단계의 화면을 표시하지 못했습니다. 시스템 설정에서 Cindy의 화면 기록을 허용하고 윈도우가 최소화되지 않았는지 확인하세요.",
+ "screen_locked": "이 컴퓨터의 화면이 잠겨 있습니다(디스플레이가 잠자기 상태가 되어도 잠깁니다). 화면을 깨우고 잠금을 해제한 후 Agent에게 다시 시도하도록 요청하세요.",
+ "nothing_to_fill": "이 화면에는 입력할 내용이 없어 Agent가 이어서 진행합니다."
+ },
+ "phase": {
+ "reading": "화면을 읽는 중…",
+ "working": "입력하는 중…",
+ "finishing": "완료된 것 같습니다. {{count}}초 후 Agent에게 넘깁니다.",
+ "finishingNow": "완료된 것 같습니다. Agent에게 넘기는 중…"
+ },
+ "action": {
+ "stay": "아직 안 끝났어요",
+ "done": "Agent에게 넘기기",
+ "claim": "여기서 처리",
+ "picture": "화면 보기",
+ "backToForm": "양식으로 돌아가기",
+ "liveView": "실시간 화면",
+ "fill": "입력",
+ "skip": "건너뛰기",
+ "continue": "계속",
+ "close": "취소",
+ "showPassword": "암호 표시",
+ "hidePassword": "암호 숨기기",
+ "scan": "스캔"
+ },
+ "remoteUnavailable": "이 컴퓨터는 원격으로 입력을 받을 수 없습니다. 호스트 컴퓨터에서 이 단계를 완료한 뒤 Agent에게 넘기세요.",
+ "unnamedField": "입력란",
+ "passwordField": "비밀번호",
+ "codeField": "인증 코드",
+ "filledHint": "이미 내용이 있습니다. 비워 두면 그대로 유지됩니다.",
+ "record": {
+ "doneOn_one": "소유자가 {{device}}에서 {{count}}단계 입력을 마쳤습니다",
+ "doneOn_other": "소유자가 {{device}}에서 {{count}}단계 입력을 마쳤습니다",
+ "doneHost_one": "소유자가 호스트 컴퓨터에서 {{count}}단계 입력을 마쳤습니다",
+ "doneHost_other": "소유자가 호스트 컴퓨터에서 {{count}}단계 입력을 마쳤습니다",
+ "donePhone_one": "소유자가 휴대폰에서 {{count}}단계 입력을 마쳤습니다",
+ "donePhone_other": "소유자가 휴대폰에서 {{count}}단계 입력을 마쳤습니다",
+ "doneElsewhere_one": "소유자가 다른 기기에서 {{count}}단계 입력을 마쳤습니다",
+ "doneElsewhere_other": "소유자가 다른 기기에서 {{count}}단계 입력을 마쳤습니다",
+ "done": "대리 입력을 마쳤습니다",
+ "nothingToFill": "입력할 내용이 없어 Agent에게 넘겼습니다",
+ "cancelled": "대리 입력을 취소했습니다",
+ "expired": "대리 입력 시간이 초과되었습니다",
+ "failed": "대리 입력을 마치지 못했습니다"
+ },
+ "holder": {
+ "elsewhere": "{{device}}에서 처리 중입니다. 여기서 이어받을 수도 있습니다.",
+ "host": "호스트 컴퓨터",
+ "phone": "휴대폰",
+ "otherDevice": "다른 기기"
+ },
+ "agentNote": "Agent 메모: {{note}}",
+ "picture": {
+ "hint": "화면에서 위치를 탭하면 Cindy가 호스트 컴퓨터의 같은 위치를 클릭합니다.",
+ "open": "이 단계 화면 보기",
+ "alt": "대상 윈도우의 화면",
+ "loading": "화면을 가져오는 중…",
+ "error": "화면을 가져오지 못했습니다. 다시 시도하세요.",
+ "field": "선택된 입력란",
+ "type": "입력",
+ "typeEnter": "입력 후 Return"
+ },
+ "deviceCode": {
+ "prompt": "이 코드로 로그인",
+ "copy": "코드 복사",
+ "copied": "코드를 복사했습니다",
+ "copyFailed": "복사하지 못했습니다",
+ "open": "이 기기에서 열기",
+ "openFailed": "링크를 열지 못했습니다",
+ "then": "열린 페이지에 코드를 입력해 로그인을 마친 뒤 「Agent에게 넘기기」를 선택하세요."
+ },
+ "nothingLeft": "여기에는 입력할 항목이 없습니다.",
+ "dialogNote": "컴퓨터의 이 위치에만 입력됩니다. Agent에게 전달하거나 저장하지 않습니다.",
+ "qr": {
+ "open": "이 기기에서 {{site}} 열기",
+ "copyLink": "링크 복사",
+ "copyText": "내용 복사",
+ "copied": "복사했습니다.",
+ "copyFailed": "복사하지 못했습니다. 다시 시도하세요.",
+ "loading": "QR 코드를 가져오는 중…",
+ "scanned": "스캔했습니다. 휴대폰에서 확인하세요. 확인하면 자동으로 계속합니다.",
+ "hint": "휴대폰으로 이 코드를 스캔해 로그인하세요. 로그인하면 자동으로 계속합니다.",
+ "hintLink": "휴대폰으로 이 코드를 스캔하거나 이 기기에서 링크를 열어 로그인하세요. 로그인하면 자동으로 계속합니다.",
+ "copyImage": "이미지 복사",
+ "imageCopied": "이미지를 복사했습니다.",
+ "openFailed": "이 링크를 열 수 없습니다. 휴대폰으로 코드를 스캔하세요.",
+ "alt": "컴퓨터의 QR 코드. 클릭하면 컴퓨터의 같은 위치를 클릭합니다.",
+ "failed": "QR 코드를 가져오지 못했습니다. 클릭해 다시 시도하세요."
+ }
+ },
"commandPalette": {
"viewSkillDetails": "스킬 상세 보기",
"projectSkillNotLoaded": "현재 Pi 작업에는 이 프로젝트 Skill이 아직 로드되지 않았습니다. 새 작업에서는 자동으로 로드를 시도합니다."
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index bd91ec0c56..2e035355b3 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -751,7 +751,10 @@
"copy": "复制到本机",
"paste": "粘贴到远程电脑",
"clipboardSyncHint": "此窗口在前台时,双向同步文字、图片和富文本。",
- "credentialRequired": "请完成 Mac 密码验证。如果无法验证,请更新两台电脑上的 Cindy。"
+ "credentialRequired": "请完成 Mac 密码验证。如果无法验证,请更新两台电脑上的 Cindy。",
+ "handoffEnded": "这次代输入已经结束,没有可显示的窗口。",
+ "handoffUnavailable": "这台电脑暂时不能只显示这个窗口。请在那台电脑上更新 Cindy,或开启远程桌面。",
+ "handoffWindow": "代输入 · {{app}}"
},
"ipcError": {
"DEVICE_LINK_BUSY": "远端繁忙,请稍后重试。",
@@ -1637,6 +1640,7 @@
"done": "已完成 ✓",
"error": "执行失败",
"needsReply": "需要你回复",
+ "inputHandoff": "需要你代为输入",
"externalDone": "Cindy · 任务「{{title}}」已完成 ✓",
"externalError": "Cindy · 任务「{{title}}」执行失败",
"externalNeedsReply": "Cindy · 任务「{{title}}」需要你回复",
@@ -9264,7 +9268,11 @@
"configure": "前往配置",
"empty_toolset": "当前执行环境没有可用的内置工具。",
"empty_mcp": "尚未添加自定义 MCP 服务。",
- "empty_skill": "暂无可选的技能。"
+ "empty_skill": "暂无可选的技能。",
+ "inputHandoff": {
+ "title": "代输入",
+ "description": "遇到需要你本人输入的登录信息、密码或验证码时,允许这位伙伴请你在任意设备上填写。你填写的内容不会交给它。"
+ }
},
"guided": {
"title": "创建伙伴",
@@ -11581,7 +11589,8 @@
"awaitingPermission": "等待授权",
"awaitingQuestion": "等待你的回复",
"awaitingPlan": "等待计划审阅",
- "awaitingPluginSetup": "等待插件设置"
+ "awaitingPluginSetup": "等待插件设置",
+ "awaitingInputHandoff": "等待代输入"
},
"showAllSessions": "显示全部 {{count}} 项",
"allSessions": "全部任务",
@@ -13149,6 +13158,125 @@
"deny": "拒绝"
}
},
+ "inputHandoff": {
+ "originWarning": {
+ "insecure": "这个页面没有使用安全连接,输入的内容可能被他人读取。",
+ "ip-address": "这个页面使用 IP 地址而不是域名,请确认它是你预期的网站。",
+ "local-host": "这个页面来自本机服务,请确认它是你预期的程序。",
+ "local-file": "这个页面是本地文件,请确认它是你预期的内容。",
+ "punycode": "这个网址包含特殊字符,可能在冒充其他网站,请仔细核对。",
+ "embedded-frame": "输入框位于嵌入的其他网站中,请确认来源可信。"
+ },
+ "agentControlled": "这个界面由 Agent 打开。填写前请确认它确实是你要登录的地方。",
+ "error": {
+ "decision": "操作没有送达,请重试。",
+ "stale": "界面已经变化,请按最新内容操作。",
+ "submit": "输入没有送达,请重试。"
+ },
+ "terminal": {
+ "succeeded": "已交还给 Agent。",
+ "cancelled": "已取消代输入。",
+ "failed": "代输入已结束。",
+ "expired": "等待时间过长,代输入已结束。"
+ },
+ "failure": {
+ "permission": "Cindy 没有读取这台电脑界面的权限。请在系统设置的辅助功能中允许 Cindy。",
+ "target_gone": "目标窗口已关闭。",
+ "unreadable": "无法读取这个界面。可以在宿主电脑上直接完成,然后交还给 Agent。",
+ "action_failed": "刚才的操作没有生效,请检查界面后重试。",
+ "timeout": "等待时间过长,代输入已结束。",
+ "unsupported": "这台电脑暂不支持代输入。",
+ "origin_changed": "填写前页面已变化,什么都没有填入。请确认现在的页面后再填写。",
+ "picture_unavailable": "没能显示这一步的画面。请在系统设置中允许 Cindy 录制屏幕,并确认窗口没有被最小化。",
+ "screen_locked": "这台电脑的屏幕已锁定(显示器休眠也会锁屏)。请先唤醒并解锁,再让 Agent 重试。",
+ "nothing_to_fill": "这个界面没有需要你输入的内容,已交还给 Agent 继续。"
+ },
+ "phase": {
+ "reading": "正在读取界面…",
+ "working": "正在填写…",
+ "finishing": "看起来已经完成,{{count}} 秒后交还给 Agent。",
+ "finishingNow": "看起来已经完成,正在交还给 Agent…"
+ },
+ "action": {
+ "stay": "还没完成",
+ "done": "交还给 Agent",
+ "claim": "改在这里处理",
+ "picture": "看画面",
+ "backToForm": "回到表单",
+ "liveView": "实时画面",
+ "fill": "填写",
+ "skip": "跳过",
+ "continue": "继续",
+ "close": "取消",
+ "showPassword": "显示密码",
+ "hidePassword": "隐藏密码",
+ "scan": "扫码"
+ },
+ "remoteUnavailable": "这台电脑不能从远程接收输入。请在宿主电脑上完成这一步,再交还给 Agent。",
+ "unnamedField": "输入框",
+ "passwordField": "密码",
+ "codeField": "验证码",
+ "filledHint": "已有内容;留空则保持不变。",
+ "record": {
+ "doneOn_one": "主人在 {{device}} 完成了 {{count}} 步输入",
+ "doneOn_other": "主人在 {{device}} 完成了 {{count}} 步输入",
+ "doneHost_one": "主人在宿主电脑上完成了 {{count}} 步输入",
+ "doneHost_other": "主人在宿主电脑上完成了 {{count}} 步输入",
+ "donePhone_one": "主人在手机上完成了 {{count}} 步输入",
+ "donePhone_other": "主人在手机上完成了 {{count}} 步输入",
+ "doneElsewhere_one": "主人在另一台设备上完成了 {{count}} 步输入",
+ "doneElsewhere_other": "主人在另一台设备上完成了 {{count}} 步输入",
+ "done": "代输入已完成",
+ "nothingToFill": "无需输入,已交还给 Agent",
+ "cancelled": "代输入已取消",
+ "expired": "代输入已超时",
+ "failed": "代输入未完成"
+ },
+ "holder": {
+ "elsewhere": "正在 {{device}} 上处理,也可以改在这里处理。",
+ "host": "宿主电脑",
+ "phone": "手机",
+ "otherDevice": "另一台设备"
+ },
+ "agentNote": "Agent 补充:{{note}}",
+ "picture": {
+ "hint": "点按画面里的位置,Cindy 会在宿主电脑上点按同一个位置。",
+ "open": "显示这一步的画面",
+ "alt": "目标窗口的画面",
+ "loading": "正在获取画面…",
+ "error": "没能取得画面,请重试。",
+ "field": "当前输入框",
+ "type": "输入",
+ "typeEnter": "输入并回车"
+ },
+ "deviceCode": {
+ "prompt": "用这个代码登录",
+ "copy": "复制代码",
+ "copied": "已复制代码",
+ "copyFailed": "复制失败",
+ "open": "在本设备打开",
+ "openFailed": "无法打开链接",
+ "then": "在打开的页面输入代码并完成登录,然后点「交还给 Agent」。"
+ },
+ "nothingLeft": "这里没有需要你填写的了。",
+ "dialogNote": "只会填进电脑上的这一处,不会交给 Agent,也不会保存。",
+ "qr": {
+ "open": "在本机打开 {{site}}",
+ "copyLink": "复制链接",
+ "copyText": "复制内容",
+ "copied": "已复制。",
+ "copyFailed": "没能复制,请重试。",
+ "loading": "正在获取二维码…",
+ "scanned": "已扫码,等你在手机上确认。确认后会自动继续。",
+ "hint": "用手机扫描这个码完成登录。登录后会自动继续。",
+ "hintLink": "用手机扫描这个码,或在本机打开链接完成登录。登录后会自动继续。",
+ "copyImage": "复制图片",
+ "imageCopied": "已复制图片。",
+ "openFailed": "没能打开这个链接。可以用手机扫描这个码。",
+ "alt": "电脑上的二维码。点击会点在电脑上的这个码上。",
+ "failed": "没能取得二维码,点击重试。"
+ }
+ },
"commandPalette": {
"viewSkillDetails": "查看技能详情",
"projectSkillNotLoaded": "当前 Pi 任务尚未加载此项目 Skill,新任务会自动尝试加载"
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 6104082d4f..b8f87b7da7 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -751,7 +751,10 @@
"copy": "複製到本機",
"paste": "貼上到遠端電腦",
"clipboardSyncHint": "此視窗在前景時,雙向同步文字、圖片和富文字。",
- "credentialRequired": "請完成 Mac 密碼驗證。如果無法驗證,請更新兩台電腦上的 Cindy。"
+ "credentialRequired": "請完成 Mac 密碼驗證。如果無法驗證,請更新兩台電腦上的 Cindy。",
+ "handoffEnded": "這次代輸入已經結束,沒有可顯示的視窗。",
+ "handoffUnavailable": "這台電腦暫時無法只顯示這個視窗。請在那台電腦上更新 Cindy,或開啟遠端桌面。",
+ "handoffWindow": "代輸入 · {{app}}"
},
"ipcError": {
"DEVICE_LINK_BUSY": "遠端忙碌中,請稍後再試。",
@@ -1637,6 +1640,7 @@
"done": "已完成 ✓",
"error": "執行失敗",
"needsReply": "需要你回覆",
+ "inputHandoff": "需要你代為輸入",
"externalDone": "Cindy · 任務「{{title}}」已完成 ✓",
"externalError": "Cindy · 任務「{{title}}」執行失敗",
"externalNeedsReply": "Cindy · 任務「{{title}}」需要你回覆",
@@ -9264,7 +9268,11 @@
"configure": "前往設定",
"empty_toolset": "目前執行環境沒有可用的內建工具。",
"empty_mcp": "尚未新增自訂 MCP 服務。",
- "empty_skill": "暫無可選的技能。"
+ "empty_skill": "暫無可選的技能。",
+ "inputHandoff": {
+ "title": "代輸入",
+ "description": "遇到需要你本人輸入的登入資訊、密碼或驗證碼時,允許這位夥伴請你在任意裝置上填寫。你填寫的內容不會交給它。"
+ }
},
"guided": {
"title": "建立夥伴",
@@ -11581,7 +11589,8 @@
"awaitingPermission": "等待授權",
"awaitingQuestion": "等待你的回覆",
"awaitingPlan": "等待計劃審閱",
- "awaitingPluginSetup": "等待插件設定"
+ "awaitingPluginSetup": "等待插件設定",
+ "awaitingInputHandoff": "等待代輸入"
},
"showAllSessions": "顯示全部 {{count}} 項",
"allSessions": "全部任務",
@@ -13149,6 +13158,125 @@
"deny": "拒絕"
}
},
+ "inputHandoff": {
+ "originWarning": {
+ "insecure": "這個頁面沒有使用安全連線,輸入的內容可能被他人讀取。",
+ "ip-address": "這個頁面使用 IP 位址而不是網域名稱,請確認它是你預期的網站。",
+ "local-host": "這個頁面來自本機服務,請確認它是你預期的程式。",
+ "local-file": "這個頁面是本機檔案,請確認它是你預期的內容。",
+ "punycode": "這個網址包含特殊字元,可能在冒充其他網站,請仔細核對。",
+ "embedded-frame": "輸入框位於嵌入的其他網站中,請確認來源可信。"
+ },
+ "agentControlled": "這個介面由 Agent 開啟。填寫前請確認它確實是你要登入的地方。",
+ "error": {
+ "decision": "操作沒有送達,請重試。",
+ "stale": "介面已經變化,請依最新內容操作。",
+ "submit": "輸入沒有送達,請重試。"
+ },
+ "terminal": {
+ "succeeded": "已交還給 Agent。",
+ "cancelled": "已取消代輸入。",
+ "failed": "代輸入已結束。",
+ "expired": "等待時間過長,代輸入已結束。"
+ },
+ "failure": {
+ "permission": "Cindy 沒有讀取這台電腦介面的權限。請在系統設定的輔助使用中允許 Cindy。",
+ "target_gone": "目標視窗已關閉。",
+ "unreadable": "無法讀取這個介面。可以在主機電腦上直接完成,然後交還給 Agent。",
+ "action_failed": "剛才的操作沒有生效,請檢查介面後重試。",
+ "timeout": "等待時間過長,代輸入已結束。",
+ "unsupported": "這台電腦暫不支援代輸入。",
+ "origin_changed": "填寫前頁面已變化,什麼都沒有填入。請確認現在的頁面後再填寫。",
+ "picture_unavailable": "無法顯示這一步的畫面。請在系統設定中允許 Cindy 錄製螢幕,並確認視窗沒有被縮到最小。",
+ "screen_locked": "這台電腦的螢幕已鎖定(顯示器休眠也會鎖定螢幕)。請先喚醒並解鎖,再讓 Agent 重試。",
+ "nothing_to_fill": "這個介面沒有需要你輸入的內容,已交還給 Agent 繼續。"
+ },
+ "phase": {
+ "reading": "正在讀取介面…",
+ "working": "正在填寫…",
+ "finishing": "看起來已經完成,{{count}} 秒後交還給 Agent。",
+ "finishingNow": "看起來已經完成,正在交還給 Agent…"
+ },
+ "action": {
+ "stay": "還沒完成",
+ "done": "交還給 Agent",
+ "claim": "改在這裡處理",
+ "picture": "看畫面",
+ "backToForm": "回到表單",
+ "liveView": "即時畫面",
+ "fill": "填寫",
+ "skip": "略過",
+ "continue": "繼續",
+ "close": "取消",
+ "showPassword": "顯示密碼",
+ "hidePassword": "隱藏密碼",
+ "scan": "掃碼"
+ },
+ "remoteUnavailable": "這台電腦無法從遠端接收輸入。請在主機電腦上完成這一步,再交還給 Agent。",
+ "unnamedField": "輸入框",
+ "passwordField": "密碼",
+ "codeField": "驗證碼",
+ "filledHint": "已有內容;留空則保持不變。",
+ "record": {
+ "doneOn_one": "主人在 {{device}} 完成了 {{count}} 步輸入",
+ "doneOn_other": "主人在 {{device}} 完成了 {{count}} 步輸入",
+ "doneHost_one": "主人在宿主電腦上完成了 {{count}} 步輸入",
+ "doneHost_other": "主人在宿主電腦上完成了 {{count}} 步輸入",
+ "donePhone_one": "主人在手機上完成了 {{count}} 步輸入",
+ "donePhone_other": "主人在手機上完成了 {{count}} 步輸入",
+ "doneElsewhere_one": "主人在另一台裝置上完成了 {{count}} 步輸入",
+ "doneElsewhere_other": "主人在另一台裝置上完成了 {{count}} 步輸入",
+ "done": "代輸入已完成",
+ "nothingToFill": "無需輸入,已交還給 Agent",
+ "cancelled": "代輸入已取消",
+ "expired": "代輸入已逾時",
+ "failed": "代輸入未完成"
+ },
+ "holder": {
+ "elsewhere": "正在 {{device}} 上處理,也可以改在這裡處理。",
+ "host": "宿主電腦",
+ "phone": "手機",
+ "otherDevice": "另一台裝置"
+ },
+ "agentNote": "Agent 補充:{{note}}",
+ "picture": {
+ "hint": "點按畫面中的位置,Cindy 會在主機電腦上點按同一個位置。",
+ "open": "顯示這一步的畫面",
+ "alt": "目標視窗的畫面",
+ "loading": "正在取得畫面…",
+ "error": "無法取得畫面,請重試。",
+ "field": "目前的輸入框",
+ "type": "輸入",
+ "typeEnter": "輸入並按 Return"
+ },
+ "deviceCode": {
+ "prompt": "用這個代碼登入",
+ "copy": "複製代碼",
+ "copied": "已複製代碼",
+ "copyFailed": "複製失敗",
+ "open": "在本裝置開啟",
+ "openFailed": "無法開啟連結",
+ "then": "在開啟的頁面輸入代碼並完成登入,然後點「交還給 Agent」。"
+ },
+ "nothingLeft": "這裡沒有需要你填寫的了。",
+ "dialogNote": "只會填進電腦上的這一處,不會交給 Agent,也不會儲存。",
+ "qr": {
+ "open": "在本機打開 {{site}}",
+ "copyLink": "複製連結",
+ "copyText": "複製內容",
+ "copied": "已複製。",
+ "copyFailed": "無法複製,請重試。",
+ "loading": "正在取得 QR 碼…",
+ "scanned": "已掃碼,等你在手機上確認。確認後會自動繼續。",
+ "hint": "用手機掃描這個碼完成登入。登入後會自動繼續。",
+ "hintLink": "用手機掃描這個碼,或在本機打開連結完成登入。登入後會自動繼續。",
+ "copyImage": "複製圖片",
+ "imageCopied": "已複製圖片。",
+ "openFailed": "沒能打開這個連結。可以用手機掃描這個碼。",
+ "alt": "電腦上的 QR 碼。點擊會點在電腦上的這個碼上。",
+ "failed": "沒能取得 QR 碼,點擊重試。"
+ }
+ },
"commandPalette": {
"viewSkillDetails": "查看技能詳情",
"projectSkillNotLoaded": "目前的 Pi 任務尚未載入此專案 Skill,新任務會自動嘗試載入"
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 5d9afd143b..4d331294e3 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -11,7 +11,7 @@ import { applyCindyMakeCardAttention } from './cindyMakeAttention';
import { confirmRemoteUsers, reserveRemoteUser } from './remoteUserHandoff';
import { readRemoteHistoryCache, remoteHistoryCacheWriter } from './remoteHistoryCache';
import { createPluginSecretPresentation, createPluginConnectionPresentation } from '../../shared/pluginOauth';
-import { parsePluginConnectionInput } from '@cindy/device-link';
+import { parsePluginConnectionInput, type InputHandoffSnapshot } from '@cindy/device-link';
/**
* makerChatStore — Module-level store for Maker chat (Claude / Codex), sharded by sessionId.
* ---------------------------------------------------------------------------
@@ -152,6 +152,7 @@ import {
requestRemoteReseed,
} from '@/features/device-link/remoteProjectsStore';
import { getStickySessionDeviceId } from '@/features/device-link/stickySessionOrigin';
+import { isInputHandoffAwaitingOwner, parsePendingInputHandoff } from '@/features/input-handoff/inputHandoffModel';
import { clearCachedMessages, readCachedMessages, persistListMessage, sessionCacheInvalidationToken } from '@/features/device-link/mirrorCacheClient';
import {
noteRemoteSessionSyncCompleted,
@@ -570,6 +571,8 @@ export interface ChatMessage {
*/
| 'bot-direct-message'
| 'bot-authorization'
+ /** 代输入结束留痕:由隐藏续接行派生,只有步数、设备与域名,没有任何输入值。 */
+ | 'input-handoff'
| 'context-rebuild';
systemCardData?: Record<string, unknown>;
/** FP-3: plan_review message fields */
@@ -2685,6 +2688,11 @@ export interface SessionChatState {
pendingPlanReview: PendingPlanReview | null;
/** issue_confirm: 提交 GitHub issue 前的确认卡片; null when none. */
pendingIssueConfirm: PendingIssueConfirm | null;
+ /**
+ * 代输入: Host-owned step card. Unlike turn-scoped prompts it survives the
+ * turn ending; only a Host dismissal or authoritative snapshot retires it.
+ */
+ pendingInputHandoff: InputHandoffSnapshot | null;
/** rename_sessions_confirm: 批量改名写入前的确认卡片; null when none. */
pendingRenameSessionsConfirm: PendingRenameSessionsConfirm | null;
/** ghost_grant_confirm: ghost_call 过户 workdir 外文件的确认卡片; null when none. */
@@ -2902,6 +2910,7 @@ export type SessionChatLightState = Pick<
| 'askUserDraft'
| 'pendingPlanReview'
| 'pendingIssueConfirm'
+ | 'pendingInputHandoff'
| 'pendingRenameSessionsConfirm'
| 'pendingGhostGrantConfirm'
| 'pendingRemoteDesktopConfirmation'
@@ -2975,6 +2984,7 @@ function createInitialState(): SessionChatState {
askUserDraft: null,
pendingPlanReview: null,
pendingIssueConfirm: null,
+ pendingInputHandoff: null,
pendingRenameSessionsConfirm: null,
pendingGhostGrantConfirm: null,
pendingRemoteDesktopConfirmation: null,
@@ -3060,6 +3070,7 @@ export const EMPTY_SESSION_STATE: SessionChatState = Object.freeze({
askUserDraft: null,
pendingPlanReview: null,
pendingIssueConfirm: null,
+ pendingInputHandoff: null,
pendingRenameSessionsConfirm: null,
pendingGhostGrantConfirm: null,
pendingRemoteDesktopConfirmation: null,
@@ -3679,6 +3690,7 @@ function _isSessionBusy(sessionId: string, s: SessionChatState): boolean {
hasPendingPluginSetupInteraction(s.pendingPluginSetup, s.pendingPluginSetupQueue) ||
s.pendingPlanReview ||
s.pendingIssueConfirm ||
+ s.pendingInputHandoff ||
s.pendingRenameSessionsConfirm ||
s.pendingGhostGrantConfirm ||
s.pendingRemoteDesktopConfirmation ||
@@ -6580,6 +6592,9 @@ export function handleStreamEvent(
if (state.pendingPermission?.requestId === data.requestId) {
return { ...state, pendingPermission: null };
}
+ if (state.pendingInputHandoff?.requestId === data.requestId) {
+ return { ...state, pendingInputHandoff: null };
+ }
if (state.pendingPluginSetup?.requestId === data.requestId) {
const [nextSetup = null, ...remainingSetups] = state.pendingPluginSetupQueue;
return {
@@ -7016,6 +7031,7 @@ function forceFinalizeOnSessionClosed(state: SessionChatState): SessionChatState
askUserDraft: null,
pendingPlanReview: null,
pendingIssueConfirm: null,
+ pendingInputHandoff: null,
pendingRenameSessionsConfirm: null,
pendingGhostGrantConfirm: null,
pendingRemoteDesktopConfirmation: null,
@@ -8359,7 +8375,8 @@ function initGlobalListeners(options: GlobalListenerOptions = {}): void {
kind !== 'plan_review' &&
kind !== 'issue_confirm' &&
kind !== 'rename_sessions_confirm' &&
- kind !== 'ghost_grant_confirm') ||
+ kind !== 'ghost_grant_confirm' &&
+ kind !== 'input_handoff') ||
typeof request.requestId !== 'string' ||
request.requestId.length === 0
) {
@@ -8414,6 +8431,17 @@ function initGlobalListeners(options: GlobalListenerOptions = {}): void {
return;
}
+ if (request.kind === 'input_handoff') {
+ const parsed = parsePendingInputHandoff(request);
+ if (!parsed) return;
+ setState(sessionId, (s) => {
+ const current = s.pendingInputHandoff;
+ if (current?.requestId === parsed.requestId && parsed.revision < current.revision) return s;
+ return { ...s, pendingInputHandoff: parsed };
+ });
+ return;
+ }
+
if (request.kind === 'permission') {
const metadata = request.metadata as Record<string, unknown> | undefined;
const data: CCAgentPermissionRequestPayload = {
@@ -9705,6 +9733,7 @@ function selectLightState(state: SessionChatState): SessionChatLightState {
askUserDraft: state.askUserDraft,
pendingPlanReview: state.pendingPlanReview,
pendingIssueConfirm: state.pendingIssueConfirm,
+ pendingInputHandoff: state.pendingInputHandoff,
pendingRenameSessionsConfirm: state.pendingRenameSessionsConfirm,
pendingGhostGrantConfirm: state.pendingGhostGrantConfirm,
pendingRemoteDesktopConfirmation: state.pendingRemoteDesktopConfirmation,
@@ -9755,6 +9784,7 @@ function lightStateEquals(a: SessionChatLightState, b: SessionChatLightState): b
a.askUserDraft === b.askUserDraft &&
a.pendingPlanReview === b.pendingPlanReview &&
a.pendingIssueConfirm === b.pendingIssueConfirm &&
+ a.pendingInputHandoff === b.pendingInputHandoff &&
a.pendingRenameSessionsConfirm === b.pendingRenameSessionsConfirm &&
a.pendingGhostGrantConfirm === b.pendingGhostGrantConfirm &&
a.pendingRemoteDesktopConfirmation === b.pendingRemoteDesktopConfirmation &&
@@ -9868,6 +9898,8 @@ export interface SessionStatusInfo {
hasPendingPermission: boolean;
hasPendingPlanReview: boolean;
hasPendingPluginSetup: boolean;
+ /** 代输入: owner input requested for an on-screen step (survives the turn). */
+ hasPendingInputHandoff?: boolean;
}
/**
@@ -9930,6 +9962,7 @@ function computeRunningSnapshot(): Map<string, SessionStatusInfo> {
state.pendingPluginSetup,
state.pendingPluginSetupQueue,
);
+ const hasPendingInputHandoff = isInputHandoffAwaitingOwner(state.pendingInputHandoff);
// 后台 subagent 折算:主 turn 已结束但 wake 型后台任务(local_agent /
// local_workflow)还在跑,或正处于「任务终态 → wake turn 启动」的桥接空窗
@@ -9951,12 +9984,14 @@ function computeRunningSnapshot(): Map<string, SessionStatusInfo> {
hasPendingPermission,
hasPendingPlanReview,
hasPendingPluginSetup,
+ hasPendingInputHandoff,
});
} else if (
hasPendingAskUser ||
hasPendingPermission ||
hasPendingPlanReview ||
- hasPendingPluginSetup
+ hasPendingPluginSetup ||
+ hasPendingInputHandoff
) {
// Session has a pending prompt for the user — include so the Sidebar
// can show the "needs attention" notification dot.
@@ -9967,6 +10002,7 @@ function computeRunningSnapshot(): Map<string, SessionStatusInfo> {
hasPendingPermission,
hasPendingPlanReview,
hasPendingPluginSetup,
+ hasPendingInputHandoff,
});
}
}
@@ -9990,6 +10026,7 @@ function computeRunningSnapshot(): Map<string, SessionStatusInfo> {
state.pendingPluginSetup,
state.pendingPluginSetupQueue,
),
+ hasPendingInputHandoff: isInputHandoffAwaitingOwner(state.pendingInputHandoff),
});
}
@@ -10027,7 +10064,8 @@ function getRunningSnapshot(): ReadonlyMap<string, SessionStatusInfo> {
prev.hasPendingAskUser !== info.hasPendingAskUser ||
prev.hasPendingPermission !== info.hasPendingPermission ||
prev.hasPendingPlanReview !== info.hasPendingPlanReview ||
- prev.hasPendingPluginSetup !== info.hasPendingPluginSetup
+ prev.hasPendingPluginSetup !== info.hasPendingPluginSetup ||
+ !!prev.hasPendingInputHandoff !== !!info.hasPendingInputHandoff
) {
same = false;
break;
@@ -10337,8 +10375,12 @@ function reconcilePendingInteractions(
const authoritativeQuestionIds = new Set<string>();
const authoritativePlanIds = new Set<string>();
const authoritativeRemoteDesktopConfirmationIds = new Set<string>();
+ const authoritativeInputHandoffIds = new Set<string>();
for (const item of list) {
const request = item?.request;
+ if (request?.kind === 'input_handoff' && typeof request.requestId === 'string') {
+ authoritativeInputHandoffIds.add(request.requestId);
+ }
if (request?.kind === 'permission' && typeof request.requestId === 'string') {
authoritativePermissionIds.add(request.requestId);
}
@@ -10392,6 +10434,12 @@ function reconcilePendingInteractions(
const nextPermission = state.pendingPermission &&
authoritativePermissionIds.has(state.pendingPermission.requestId)
? state.pendingPermission : null;
+ // Terminal snapshots are not listed by the Host; keep them for their
+ // short visual grace until the dismissal push arrives.
+ const nextInputHandoff = state.pendingInputHandoff &&
+ (state.pendingInputHandoff.terminal === true ||
+ authoritativeInputHandoffIds.has(state.pendingInputHandoff.requestId))
+ ? state.pendingInputHandoff : null;
const currentSurvives =
state.pendingPluginSetup !== null &&
authoritativePluginSetupIds.has(state.pendingPluginSetup.requestId);
@@ -10446,6 +10494,7 @@ function reconcilePendingInteractions(
nextAskUser === state.pendingAskUser &&
nextPlanReview === state.pendingPlanReview &&
nextPermission === state.pendingPermission &&
+ nextInputHandoff === state.pendingInputHandoff &&
nextCommand === state.pluginSetupCommandInFlight &&
promotedRemoteDesktopConfirmation === state.pendingRemoteDesktopConfirmation &&
!remoteQueueChanged
@@ -10462,6 +10511,7 @@ function reconcilePendingInteractions(
planViewerState: nextPlanReview ? state.planViewerState : 'expanded',
lastExpandedPlanViewerState: nextPlanReview ? state.lastExpandedPlanViewerState : 'expanded',
pendingPermission: nextPermission,
+ pendingInputHandoff: nextInputHandoff,
pendingPluginSetup: nextCurrent,
pendingPluginSetupQueue: survivingQueue,
pluginSetupViewerState: currentChanged ? 'expanded' : state.pluginSetupViewerState,
@@ -16164,6 +16214,7 @@ async function clearSessionAfterGuardImpl(sessionId: string, clearedAt: string):
askUserDraft: null,
pendingPlanReview: null,
pendingIssueConfirm: null,
+ pendingInputHandoff: null,
pendingRemoteDesktopConfirmation: null,
pendingRemoteDesktopConfirmationQueue: [],
pendingQueue: s.pendingQueue.filter((item) =>
@@ -17170,7 +17221,7 @@ import {
syntheticTriggerKind,
UI_ACTION_TRIGGER_PREFIX,
} from '../../shared/interruptedTurn.js';
-import { isContinuationMessage } from '@cindy/maker-shared/synthetic-trigger';
+import { isContinuationMessage, parseInputHandoffEndRecord } from '@cindy/maker-shared/synthetic-trigger';
export { UI_ACTION_TRIGGER_PREFIX };
/**
@@ -18349,6 +18400,12 @@ function mapServerCreatedAt(
* (模块级共享:mapServerMessages 打标用,loadOlderMessages 的可见锚点判定
* 也用它排除"渲染 null 的 user 行"。)
*/
+function readInputHandoffEndRecord(m: Message) {
+ const c = m.content;
+ const text = typeof c === 'string' ? c : c && typeof c === 'object' ? (c as { text?: unknown }).text : undefined;
+ return typeof text === 'string' ? parseInputHandoffEndRecord(text) : null;
+}
+
function isSyntheticTriggerRow(m: Message): boolean {
if (m.role !== 'user') return false;
const c = m.content;
@@ -18755,6 +18812,19 @@ function mapServerMessages(serverMsgs: Message[]): ChatMessage[] {
if (m.role === 'user') {
if (isSyntheticTriggerRow(m)) {
// 合成指令行:占位参与时序,不渲染、不外泄原文。
+ const handoffRecord = m.agentMeta?.autoResume === true ? null : readInputHandoffEndRecord(m);
+ if (handoffRecord) {
+ return {
+ clientId: m.clientId,
+ role: m.role,
+ content: '',
+ isStreaming: false,
+ isSyntheticTrigger: true,
+ isContinuationTrigger: isContinuationMessage(m),
+ systemCardType: 'input-handoff' as const,
+ systemCardData: { ...handoffRecord },
+ };
+ }
return {
clientId: m.clientId,
role: m.role,
diff --git a/apps/desktop/src/renderer/lib/makerTransport.ts b/apps/desktop/src/renderer/lib/makerTransport.ts
index 9338d65b91..611f639789 100644
--- a/apps/desktop/src/renderer/lib/makerTransport.ts
+++ b/apps/desktop/src/renderer/lib/makerTransport.ts
@@ -34,6 +34,13 @@ import * as sessionService from '@/lib/sessionService';
import { extractIpcError } from '@/utils/ipcError';
import type { TurnChangeSetUpdatedPayload } from '../../shared/turnChangeSet';
import type { LocalPluginOauthRequest, LocalPluginSecretRequest, LocalPluginConnectionRequest } from '../../shared/pluginOauth';
+import {
+ INPUT_HANDOFF_ACTION_ID,
+ INPUT_HANDOFF_GHOST_ID,
+ type InputHandoffPicture,
+ type InputHandoffPresentation,
+ type InputHandoffSubmission,
+} from '@cindy/device-link';
type FullMaker = typeof window.electronAPI.maker;
@@ -90,6 +97,77 @@ export function submitRemotePluginConnection(sessionId: string, request: Omit<Lo
return window.electronAPI.maker.submitRemotePluginConnection({ deviceId, ...request });
}
+/**
+ * 代输入 values. Local tasks use the trusted local channel; tasks on another
+ * computer go through Main's signed relay. Never makerApiFor/device-link invoke.
+ */
+export function submitInputHandoff(
+ sessionId: string,
+ request: { submission: InputHandoffSubmission; presentation: InputHandoffPresentation },
+): Promise<{ accepted: boolean }> {
+ const deviceId = getStickySessionDeviceId(sessionId);
+ if (!deviceId)
+ return window.electronAPI.maker.submitInputHandoff(request.presentation.requestId, request.submission);
+ return window.electronAPI.maker.submitRemoteInputHandoff({
+ deviceId,
+ ghostId: INPUT_HANDOFF_GHOST_ID,
+ requestId: request.presentation.requestId,
+ actionId: INPUT_HANDOFF_ACTION_ID,
+ expectedRevision: request.submission.expectedRevision,
+ submission: request.submission,
+ presentation: request.presentation,
+ });
+}
+
+/** One opened 代输入 screenshot step: its picture, and one answer (or close). */
+export interface InputHandoffPictureSession {
+ picture: InputHandoffPicture;
+ answer(submission: InputHandoffSubmission): Promise<{ accepted: boolean }>;
+ close(): void;
+}
+
+/**
+ * The current screenshot step. On this computer Main hands it over directly;
+ * for a task on another computer it arrives inside the sealed v3 offer, and
+ * the answer goes back on the same exchange.
+ */
+export async function openInputHandoffPicture(
+ sessionId: string,
+ presentation: InputHandoffPresentation,
+): Promise<InputHandoffPictureSession> {
+ const deviceId = getStickySessionDeviceId(sessionId);
+ if (!deviceId) {
+ const picture = await window.electronAPI.maker.getInputHandoffPicture(presentation.requestId, presentation.revision);
+ if (!picture) throw new Error('INPUT_HANDOFF_UNAVAILABLE');
+ return {
+ picture,
+ answer: (submission) => window.electronAPI.maker.submitInputHandoff(presentation.requestId, submission),
+ close: () => undefined,
+ };
+ }
+ const opened = await window.electronAPI.maker.openRemoteInputHandoffPicture({
+ deviceId,
+ ghostId: INPUT_HANDOFF_GHOST_ID,
+ requestId: presentation.requestId,
+ actionId: INPUT_HANDOFF_ACTION_ID,
+ expectedRevision: presentation.revision,
+ presentation,
+ });
+ let open = true;
+ return {
+ picture: opened.picture,
+ answer: (submission) => {
+ open = false;
+ return window.electronAPI.maker.answerRemoteInputHandoffPicture(opened.token, submission);
+ },
+ close: () => {
+ if (!open) return;
+ open = false;
+ void window.electronAPI.maker.answerRemoteInputHandoffPicture(opened.token, null).catch(() => undefined);
+ },
+ };
+}
+
/**
* makerChatStore / ChatInput 经传输层调用的会话操作子集。本地直接复用
* window.electronAPI.maker;远程转 deviceLink.invoke。所有 channel 均在
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index 4873c00e01..9f185b661a 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -3956,7 +3956,7 @@ interface ElectronAPI {
fetchReleaseNotesIndex: () => Promise<string[] | null>;
// ── Device Link (设备互联/跨设备远程控制) ─────────────────────────────
- openRemoteDesktop: (target: { deviceId: string; name: string }) => Promise<void>;
+ openRemoteDesktop: (target: { deviceId: string; name: string; handoff?: string }) => Promise<void>;
remoteDesktopViewer: import('../shared/remoteDesktopViewer').RemoteDesktopViewerApi;
remoteDesktop: import('../shared/remoteDesktop').RemoteDesktopApi;
sharedTask: {
@@ -6262,6 +6262,23 @@ interface ElectronAPI {
request: import('../shared/pluginOauthDeviceCode').PluginOauthDeviceCodeRequest,
) => Promise<import('../shared/pluginOauthDeviceCode').PluginOauthDeviceCodeView | null>;
+ /** 代输入 values for a local task (trusted frame only). */
+ submitInputHandoff: (requestId: string, submission: unknown) => Promise<{ accepted: boolean }>;
+ /** 代输入 values for a task on another computer (signed v3 exchange). */
+ submitRemoteInputHandoff: (
+ request: import('../shared/pluginOauth').LocalInputHandoffRequest,
+ ) => Promise<{ accepted: boolean }>;
+ /** 代输入 screenshot step on this computer (trusted frame only). */
+ getInputHandoffPicture: (
+ requestId: string,
+ revision: number,
+ ) => Promise<import('@cindy/device-link').InputHandoffPicture | null>;
+ /** 代输入 screenshot step on another computer (sealed offer, this window only). */
+ openRemoteInputHandoffPicture: (
+ request: import('../shared/pluginOauth').LocalInputHandoffPictureRequest,
+ ) => Promise<{ token: string; picture: import('@cindy/device-link').InputHandoffPicture }>;
+ answerRemoteInputHandoffPicture: (token: string, submission: unknown) => Promise<{ accepted: boolean }>;
+
/** Submit one inline plugin Secret through the local trusted-frame-only IPC. */
submitPluginSetupInline: (request: {
requestId: string;
diff --git a/apps/desktop/src/shared/agentIsland.ts b/apps/desktop/src/shared/agentIsland.ts
index ba291c46ed..16e33400d6 100644
--- a/apps/desktop/src/shared/agentIsland.ts
+++ b/apps/desktop/src/shared/agentIsland.ts
@@ -7,7 +7,8 @@ export type AgentIslandInteractionKind =
| 'permission'
| 'ask_user_question'
| 'plan_review'
- | 'plugin_setup';
+ | 'plugin_setup'
+ | 'input_handoff';
export type AgentIslandActivityLineKind = 'user' | 'assistant' | 'status' | 'tool';
/**
@@ -782,6 +783,7 @@ const AGENT_ISLAND_INTERACTION_KINDS: readonly AgentIslandInteractionKind[] = [
'ask_user_question',
'plan_review',
'plugin_setup',
+ 'input_handoff',
];
/** renderer payload 的运行时校验:整体形状非法返回 null,单条非法条目丢弃。 */
diff --git a/apps/desktop/src/shared/pluginOauth.ts b/apps/desktop/src/shared/pluginOauth.ts
index 7f28c2b611..111a7266c8 100644
--- a/apps/desktop/src/shared/pluginOauth.ts
+++ b/apps/desktop/src/shared/pluginOauth.ts
@@ -3,6 +3,8 @@ import type {
PluginSecretPresentation,
PluginConnectionPresentation,
PluginConnectionInput,
+ InputHandoffPresentation,
+ InputHandoffSubmission,
} from '@cindy/device-link';
import type { GhostSetupInlineSecretField } from './ghost.js';
@@ -22,6 +24,17 @@ export interface LocalPluginConnectionRequest extends LocalPluginOauthRequest {
presentation: PluginConnectionPresentation;
}
+/** 代输入 step for a task on another computer; `ghostId` is INPUT_HANDOFF_GHOST_ID. */
+export interface LocalInputHandoffRequest extends LocalPluginOauthRequest {
+ submission: InputHandoffSubmission;
+ presentation: InputHandoffPresentation;
+}
+
+/** 代输入 screenshot step on another computer: opens its sealed picture for this window. */
+export interface LocalInputHandoffPictureRequest extends LocalPluginOauthRequest {
+ presentation: InputHandoffPresentation;
+}
+
export function createPluginConnectionPresentation(
card: { ghost: { name: string }; intro?: string },
step: { title: string; description: string; action?: { id: string } },
diff --git a/apps/desktop/src/shared/remoteDesktopViewer.ts b/apps/desktop/src/shared/remoteDesktopViewer.ts
index c71e94e19a..196740ef94 100644
--- a/apps/desktop/src/shared/remoteDesktopViewer.ts
+++ b/apps/desktop/src/shared/remoteDesktopViewer.ts
@@ -27,6 +27,8 @@ export const REMOTE_VIEWER = {
export interface RemoteViewerTarget {
deviceId: string;
name: string;
+ /** 代输入 live view: only the window this waiting request is about (the host picks it). */
+ handoff?: string;
}
export interface RemoteViewerState {
target: RemoteViewerTarget | null;
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index a75f9fea54..29e72eef9b 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -2588,7 +2588,9 @@ function SessionScreenContent() {
const queueAvailabilityReason = cacheSeededReason
?? pendingCreationReason
?? (sessionOperationLayout.showQueue ? null : composerDisabledReason);
- const companionInlineInteraction = companionChat && pending.length > 0 && !pendingInteractionFullHeight;
+ // 代输入在伙伴对话里同样贴在输入框上方:它是一条入口,填写在原生表单里完成。
+ const companionInlineInteraction = companionChat && pending.length > 0 && !pendingInteractionFullHeight
+ && activePendingKind !== 'input_handoff';
const showMessageHistory = companionInlineInteraction || sessionOperationLayout.messageHistoryMode === 'visible'
|| (sessionOperationLayout.messageHistoryMode === 'collapsed' && pendingHistoryExpanded);
// 冷开即出壳:session 元信息还没回来,但不是真正不可用(离线/被撤销,看 remoteUnavailableReason)——
diff --git a/apps/mobile/src/__tests__/InputHandoffCardExtras.test.tsx b/apps/mobile/src/__tests__/InputHandoffCardExtras.test.tsx
new file mode 100644
index 0000000000..46ee4c8fb4
--- /dev/null
+++ b/apps/mobile/src/__tests__/InputHandoffCardExtras.test.tsx
@@ -0,0 +1,318 @@
+// @vitest-environment jsdom
+import { act, createElement, forwardRef, type ReactNode } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, expect, it, vi } from "vitest";
+import type { InputHandoffSnapshot } from "@cindy/device-link";
+
+const push = vi.fn();
+const openURL = vi.fn(async () => true);
+const setStringAsync = vi.fn(async () => true);
+const submit = vi.fn(async () => undefined);
+const shareAsync = vi.fn(async () => undefined);
+const writeAsStringAsync = vi.fn(async () => undefined);
+const answers: unknown[] = [];
+const openPicture = vi.fn(async (_snapshot: unknown, answer: (picture: unknown) => Promise<unknown>) => {
+ answers.push(await answer(qrPicture));
+});
+vi.mock("expo-clipboard", () => ({ setStringAsync }));
+vi.mock("expo-sharing", () => ({ shareAsync }));
+vi.mock("expo-file-system", () => {
+ class Directory {
+ uri = "file:///cache/input-handoff-qr";
+ exists = true;
+ create() {}
+ list() {
+ return [];
+ }
+ }
+ class File {
+ uri: string;
+ constructor(_dir: unknown, name: string) {
+ this.uri = `file:///cache/input-handoff-qr/${name}`;
+ }
+ }
+ return { Directory, File, Paths: { cache: "file:///cache" } };
+});
+vi.mock("expo-file-system/legacy", () => ({
+ writeAsStringAsync,
+ deleteAsync: vi.fn(async () => undefined),
+ EncodingType: { Base64: "base64" },
+}));
+vi.mock("react-native", async () => {
+ const { createElement } = await import("react");
+ const box = ({ children, testID }: { children?: ReactNode; testID?: string }) =>
+ createElement("div", { "data-testid": testID }, children);
+ return {
+ View: box,
+ Text: box,
+ Image: () => null,
+ useWindowDimensions: () => ({ width: 390, height: 844 }),
+ ScrollView: box,
+ KeyboardAvoidingView: box,
+ // The sheet exists in the tree only while presented.
+ Modal: ({ visible, children }: { visible: boolean; children?: ReactNode }) => (visible ? box({ children }) : null),
+ Pressable: ({ children, onPress, onLayout, testID, accessibilityLabel }: { children?: ReactNode; onPress(e: unknown): void; onLayout?(e: unknown): void; testID?: string; accessibilityLabel?: string }) => {
+ onLayout?.({ nativeEvent: { layout: { width: 200, height: 200 } } });
+ return createElement("button", { onClick: () => onPress({ nativeEvent: { locationX: 100, locationY: 50 } }), "data-testid": testID, "aria-label": accessibilityLabel }, children);
+ },
+ ActivityIndicator: () => null,
+ Linking: { openURL },
+ Platform: { OS: "android" },
+ StyleSheet: { create: (v: unknown) => v, hairlineWidth: 1 },
+ };
+});
+vi.mock("react-native-safe-area-context", () => ({ useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 }) }));
+vi.mock("lucide-react-native", () => ({ AppWindow: () => null, Globe: () => null, Lock: () => null, QrCode: () => null, SquareTerminal: () => null }));
+vi.mock("@/components/AppText", async () => {
+ const { createElement } = await import("react");
+ type Props = { accessibilityLabel: string; value: string; onChangeText(v: string): void; onSubmitEditing?(): void };
+ return {
+ Text: (await import("react-native")).Text,
+ TextInput: forwardRef<HTMLInputElement, Props>((props, ref) =>
+ createElement("input", {
+ ref,
+ "aria-label": props.accessibilityLabel,
+ value: props.value,
+ onChange: (e: { target: { value: string } }) => props.onChangeText(e.target.value),
+ onKeyDown: (e: { key: string }) => e.key === "Enter" && props.onSubmitEditing?.(),
+ }),
+ ),
+ };
+});
+vi.mock("@/components/MobilePrimitives", async () => {
+ const { createElement } = await import("react");
+ type Action = { label: string; disabled?: boolean; onPress(): void };
+ const button = (action: Action) =>
+ createElement("button", { key: action.label, disabled: action.disabled, onClick: action.onPress }, action.label);
+ return {
+ MainWindowActionButton: ({ action }: { action: Action }) => button(action),
+ MainWindowActionGroup: ({ primaryActions = [] }: { primaryActions?: Action[] }) =>
+ createElement("div", null, ...primaryActions.map(button)),
+ };
+});
+vi.mock("@/theme", () => ({
+ useTheme: () => ({ colors: {} }),
+ useThemedStyles: () => ({}),
+ iconSize: {},
+ iconStroke: {},
+ spacing: {},
+}));
+vi.mock("@/inputHandoff/inputHandoffStyles", () => ({ makeInputHandoffStyles: () => ({}) }));
+vi.mock("@/inputHandoff/InputHandoffPictureStep", () => ({
+ InputHandoffPictureStep: () => null,
+ rememberInputHandoffPictureOpened: () => {},
+}));
+vi.mock("@/inputHandoff/useInputHandoffSubmit", () => ({
+ useInputHandoffSubmit: () => ({ submit, openPicture }),
+}));
+vi.mock("@/auth/AuthContext", () => ({ useAuth: () => ({ deviceId: "phone" }) }));
+vi.mock("@/session/remoteSessionStore", () => ({
+ useRemoteDeviceIdentity: () => [{ deviceId: "mac", name: "Studio" }],
+}));
+vi.mock("@/utils/useGuardedPush", () => ({ useGuardedPush: () => push }));
+vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+
+(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+const { InputHandoffCard } = await import("@/inputHandoff/InputHandoffCard");
+
+let roots: Root[] = [];
+afterEach(() => {
+ act(() => roots.forEach((root) => root.unmount()));
+ roots = [];
+ for (const fn of [push, openURL, setStringAsync, submit, shareAsync, writeAsStringAsync, openPicture]) fn.mockClear();
+ answers.length = 0;
+});
+
+const qrLink = "https://login.example.com/qr?token=abc";
+const qrPicture = {
+ mime: "image/jpeg",
+ width: 360,
+ height: 360,
+ data: "Y29kZQ==",
+ qr: { text: qrLink, url: qrLink },
+};
+
+const step = (overrides: Partial<InputHandoffSnapshot> = {}): InputHandoffSnapshot => ({
+ kind: "input_handoff",
+ requestId: "req1",
+ revision: 2,
+ phase: "ready",
+ purpose: "Sign in",
+ source: { app: "Google Chrome", origin: "https://auth.example.com" },
+ stepNumber: 1,
+ remoteInput: true,
+ controls: [
+ { id: "c0", kind: "text", label: "Email", contentType: "email" },
+ { id: "c1", kind: "text", label: "Password", contentType: "password" },
+ ],
+ ...overrides,
+});
+
+function mount(snapshot: InputHandoffSnapshot) {
+ const container = document.createElement("div");
+ document.body.append(container);
+ const root = createRoot(container);
+ roots.push(root);
+ const onDecision = vi.fn();
+ const render = (next: InputHandoffSnapshot) =>
+ act(() => {
+ root.render(createElement(InputHandoffCard, { deviceId: "mac", snapshot: next, decisionBusy: false, onDecision }));
+ });
+ render(snapshot);
+ return { container, onDecision, render };
+}
+const buttons = (container: Element) => [...container.querySelectorAll("button")].map((b) => b.textContent);
+const press = async (container: Element, label: string) => {
+ const target = [...container.querySelectorAll("button")].find((b) => b.textContent === label);
+ if (!target) throw new Error(`no ${label} in ${buttons(container).join(", ")}`);
+ await act(async () => target.click());
+};
+const type = (input: HTMLInputElement, value: string) =>
+ act(() => {
+ const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!;
+ setter.call(input, value);
+ input.dispatchEvent(new Event("input", { bubbles: true }));
+ });
+const sheet = (container: Element) => container.querySelector('[data-testid="interaction.inputHandoff.sheet"]');
+
+it("shows a strip with where to fill and opens the form only when asked", async () => {
+ const { container, onDecision } = mount(step());
+ expect(container.textContent).toContain("Sign in");
+ expect(container.textContent).toContain("auth.example.com");
+ expect(container.querySelector("input")).toBeNull();
+ expect(buttons(container)).toEqual(["interaction.inputHandoff.action.skip", "interaction.inputHandoff.action.fill"]);
+
+ await press(container, "interaction.inputHandoff.action.fill");
+ expect(sheet(container)).not.toBeNull();
+ const [email, password] = [...container.querySelectorAll("input")];
+ type(email, "[email protected]");
+ type(password, "synthetic-secret");
+ await press(container, "interaction.inputHandoff.action.continue");
+ expect(submit).toHaveBeenCalledWith(expect.objectContaining({ requestId: "req1" }), {
+ expectedRevision: 2,
+ values: { c0: "[email protected]", c1: "synthetic-secret" },
+ action: { kind: "submit" },
+ });
+
+ // Skip on the strip cancels the handoff.
+ await press(container, "interaction.inputHandoff.action.skip");
+ expect(onDecision).toHaveBeenCalledWith({ kind: "input_handoff", action: "cancel", expectedRevision: 2 });
+});
+
+it("closes the sheet without cancelling, and comes back by itself for the next screen", async () => {
+ const { container, onDecision, render } = mount(step());
+ await press(container, "interaction.inputHandoff.action.fill");
+ await press(container, "interaction.inputHandoff.action.close");
+ expect(sheet(container)).toBeNull();
+ expect(onDecision).not.toHaveBeenCalled();
+
+ await press(container, "interaction.inputHandoff.action.fill");
+ render(step({ revision: 3, phase: "working", controls: [] }));
+ expect(sheet(container)).toBeNull();
+ expect(container.textContent).toContain("interaction.inputHandoff.phase.working");
+ render(step({ revision: 4, stepNumber: 2, controls: [{ id: "c2", kind: "text", label: "Code", contentType: "one-time-code" }] }));
+ expect(sheet(container)).not.toBeNull();
+ expect((container.querySelector("input") as HTMLInputElement).value).toBe("");
+});
+
+it("offers handing back when nothing is left to type, and a countdown when it looks done", async () => {
+ const { container, onDecision, render } = mount(step({ controls: [] }));
+ expect(container.textContent).toContain("interaction.inputHandoff.nothingLeft");
+ await press(container, "interaction.inputHandoff.action.done");
+ expect(onDecision).toHaveBeenLastCalledWith({ kind: "input_handoff", action: "done", expectedRevision: 2 });
+ render(step({ phase: "finishing", controls: [] }));
+ expect(buttons(container)).toEqual(["interaction.inputHandoff.action.stay", "interaction.inputHandoff.action.done"]);
+});
+
+it("opens a live view of just this window on the computer running the task", async () => {
+ const { container } = mount(step({ liveView: true }));
+ await press(container, "interaction.inputHandoff.action.fill");
+ await press(container, "interaction.inputHandoff.action.liveView");
+ expect(push).toHaveBeenCalledWith({
+ pathname: "/devices/desktop/[deviceId]",
+ params: { deviceId: "mac", deviceName: "Studio", handoff: "req1" },
+ });
+ expect(sheet(container)).toBeNull();
+ const ended = mount(step({ liveView: true, phase: "cancelled", terminal: true }));
+ expect(buttons(ended.container)).not.toContain("interaction.inputHandoff.action.liveView");
+});
+
+it("offers a sign-in code to copy and its link to open on this phone", async () => {
+ const deviceCode = {
+ code: "WDJB-MJHT",
+ url: "https://github.com/login/device",
+ origin: "https://github.com",
+ };
+ const { container, onDecision } = mount(step({ deviceCode, controls: [] }));
+ await press(container, "interaction.inputHandoff.action.fill");
+ expect(container.textContent).toContain("WDJB-MJHT");
+ await press(container, "interaction.inputHandoff.deviceCode.copy");
+ expect(setStringAsync).toHaveBeenCalledWith("WDJB-MJHT");
+ expect(container.textContent).toContain("interaction.inputHandoff.deviceCode.copied");
+ await press(container, "interaction.inputHandoff.deviceCode.open");
+ expect(openURL).toHaveBeenCalledWith("https://github.com/login/device");
+ // The sheet's main button hands back once the owner signed in there.
+ await press(container, "interaction.inputHandoff.action.done");
+ expect(onDecision).toHaveBeenCalledWith({ kind: "input_handoff", action: "done", expectedRevision: 2 });
+ // A link whose shown origin does not match is never offered.
+ const forged = mount(step({ deviceCode: { ...deviceCode, origin: "https://example.com" }, controls: [] }));
+ expect(buttons(forged.container)).not.toContain("interaction.inputHandoff.action.fill");
+});
+
+it("hands a QR code from the computer to this phone: open its link here, or save or share it", async () => {
+ const { container, render, onDecision } = mount(step({ controls: [], picture: true, qr: "scan" }));
+ expect(buttons(container)).toEqual(["interaction.inputHandoff.action.skip", "interaction.inputHandoff.action.scan"]);
+ // Nothing is fetched until the owner opens it.
+ expect(openPicture).not.toHaveBeenCalled();
+ await press(container, "interaction.inputHandoff.action.scan");
+ expect(openPicture).toHaveBeenCalledTimes(1);
+ expect(container.querySelector('[data-testid="interaction.inputHandoff.qr.code"]')).not.toBeNull();
+ await press(container, "interaction.inputHandoff.qr.open");
+ expect(openURL).toHaveBeenCalledWith(qrLink);
+ await press(container, "interaction.inputHandoff.qr.share");
+ expect(writeAsStringAsync).toHaveBeenCalledWith(expect.stringContaining("input-handoff-qr/qr-"), "Y29kZQ==", { encoding: "base64" });
+ expect(shareAsync).toHaveBeenCalledWith(expect.stringContaining("input-handoff-qr/qr-"), expect.objectContaining({ mimeType: "image/jpeg" }));
+ await press(container, "interaction.inputHandoff.qr.copyLink");
+ expect(setStringAsync).toHaveBeenCalledWith(qrLink);
+ // A tap on the code taps the same place on the code in the window.
+ const code = container.querySelector('[data-testid="interaction.inputHandoff.qr.code"]') as HTMLButtonElement;
+ await act(async () => code.click());
+ expect(answers).toEqual([{ expectedRevision: 2, values: {}, action: { kind: "tap", x: 0.5, y: 0.25 } }]);
+
+ // A refreshed code is a new revision and loads by itself while the sheet is open.
+ render(step({ revision: 3, controls: [], picture: true, qr: "scan" }));
+ expect(openPicture).toHaveBeenCalledTimes(2);
+
+ // Scanned: the sign-in finishes on the phone that scanned it; the owner can still hand back or skip.
+ render(step({ revision: 4, controls: [], qr: "scanned" }));
+ expect(container.textContent).toContain("interaction.inputHandoff.qr.scanned");
+ expect(sheet(container)).toBeNull();
+ await press(container, "interaction.inputHandoff.action.done");
+ expect(onDecision).toHaveBeenLastCalledWith({ kind: "input_handoff", action: "done", expectedRevision: 4 });
+});
+
+it("opens an app link here first, the way the phone camera would", async () => {
+ const appLink = "weixin://dl/login?t=1";
+ openPicture.mockImplementationOnce(async (_snapshot, answer) => {
+ answers.push(await answer({ ...qrPicture, qr: { text: appLink, url: appLink } }));
+ });
+ const { container } = mount(step({ controls: [], picture: true, qr: "scan" }));
+ await press(container, "interaction.inputHandoff.action.scan");
+ const labels = buttons(container);
+ expect(labels.indexOf("interaction.inputHandoff.qr.openApp")).toBeLessThan(labels.indexOf("interaction.inputHandoff.qr.share"));
+ await press(container, "interaction.inputHandoff.qr.openApp");
+ expect(openURL).toHaveBeenCalledWith(appLink);
+});
+
+it("offers content that is not a link only to save, share or copy", async () => {
+ openPicture.mockImplementationOnce(async (_snapshot, answer) => {
+ answers.push(await answer({ ...qrPicture, qr: { text: "WIFI:S:home;;" } }));
+ });
+ const { container } = mount(step({ controls: [], picture: true, qr: "scan" }));
+ await press(container, "interaction.inputHandoff.action.scan");
+ expect(buttons(container)).not.toContain("interaction.inputHandoff.qr.open");
+ expect(buttons(container)).toContain("interaction.inputHandoff.qr.copyText");
+ await press(container, "interaction.inputHandoff.qr.share");
+ expect(shareAsync).toHaveBeenCalled();
+ expect(openURL).not.toHaveBeenCalled();
+});
diff --git a/apps/mobile/src/__tests__/InputHandoffPictureStep.test.tsx b/apps/mobile/src/__tests__/InputHandoffPictureStep.test.tsx
new file mode 100644
index 0000000000..5b7339358a
--- /dev/null
+++ b/apps/mobile/src/__tests__/InputHandoffPictureStep.test.tsx
@@ -0,0 +1,221 @@
+// @vitest-environment jsdom
+import { act, createElement, type ReactNode } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, expect, it, vi } from "vitest";
+import type {
+ InputHandoffPicture,
+ InputHandoffSnapshot,
+ InputHandoffSubmission,
+} from "@cindy/device-link";
+
+vi.mock("react-native", async () => {
+ const { createElement, useEffect } = await import("react");
+ const box = ({ children }: { children?: ReactNode }) => createElement("div", null, children);
+ return {
+ View: box,
+ Text: box,
+ ActivityIndicator: () => null,
+ Image: ({ source }: { source: { uri: string } }) => createElement("img", { src: source.uri }),
+ // The picture is laid out at 400×300; a press lands at (100, 225) inside it.
+ Pressable: ({
+ children,
+ onPress,
+ onLayout,
+ accessibilityLabel,
+ disabled,
+ }: {
+ children?: ReactNode;
+ onPress?: (event: unknown) => void;
+ onLayout?: (event: unknown) => void;
+ accessibilityLabel?: string;
+ disabled?: boolean;
+ }) => {
+ useEffect(() => onLayout?.({ nativeEvent: { layout: { width: 400, height: 300 } } }), []);
+ return createElement(
+ "button",
+ {
+ "aria-label": accessibilityLabel,
+ disabled,
+ onClick: () => onPress?.({ nativeEvent: { locationX: 100, locationY: 225 } }),
+ },
+ children,
+ );
+ },
+ TextInput: ({
+ accessibilityLabel,
+ value,
+ onChangeText,
+ secureTextEntry,
+ }: {
+ accessibilityLabel?: string;
+ value?: string;
+ onChangeText?: (value: string) => void;
+ secureTextEntry?: boolean;
+ }) =>
+ createElement("input", {
+ "aria-label": accessibilityLabel,
+ type: secureTextEntry ? "password" : "text",
+ value,
+ onChange: (event: { target: { value: string } }) => onChangeText?.(event.target.value),
+ }),
+ StyleSheet: { create: (value: unknown) => value, hairlineWidth: 1 },
+ };
+});
+vi.mock("@/components/AppText", async () => {
+ const rn = await import("react-native");
+ return { Text: rn.Text, TextInput: rn.TextInput };
+});
+vi.mock("@/components/MobilePrimitives", async () => {
+ const { createElement } = await import("react");
+ type Action = { label: string; disabled?: boolean; onPress(): void };
+ const button = (action: Action) =>
+ createElement("button", { key: action.label, disabled: action.disabled, onClick: action.onPress }, action.label);
+ return {
+ MainWindowActionGroup: ({
+ cancelAction,
+ secondaryActions = [],
+ primaryActions = [],
+ }: {
+ cancelAction?: Action;
+ secondaryActions?: Action[];
+ primaryActions?: Action[];
+ }) =>
+ createElement(
+ "div",
+ null,
+ ...[cancelAction, ...secondaryActions, ...primaryActions].filter(Boolean).map((a) => button(a!)),
+ ),
+ };
+});
+vi.mock("@/theme", () => ({
+ useTheme: () => ({ colors: {} }),
+ useThemedStyles: () => ({}),
+}));
+vi.mock("@/inputHandoff/inputHandoffStyles", () => ({ makeInputHandoffStyles: () => ({}) }));
+vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+
+(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+const { InputHandoffPictureStep } = await import("@/inputHandoff/InputHandoffPictureStep");
+
+const picture: InputHandoffPicture = { mime: "image/jpeg", width: 800, height: 600, data: "AAAA" };
+let roots: Root[] = [];
+let nextRequest = 0;
+afterEach(() => {
+ act(() => roots.forEach((root) => root.unmount()));
+ roots = [];
+ document.body.innerHTML = "";
+});
+
+const shot = (overrides: Partial<InputHandoffSnapshot> = {}): InputHandoffSnapshot => ({
+ kind: "input_handoff",
+ requestId: `phone${++nextRequest}`,
+ revision: 3,
+ phase: "ready",
+ purpose: "Sign in",
+ source: { app: "Game" },
+ stepNumber: 1,
+ remoteInput: true,
+ controls: [],
+ picture: true,
+ ...overrides,
+});
+
+/** A Host exchange that shows the picture, then waits for the owner's answer. */
+function exchange() {
+ const answers: InputHandoffSubmission[] = [];
+ const errors: unknown[] = [];
+ const openPicture = vi.fn(
+ (_snapshot: InputHandoffSnapshot, answer: (p: InputHandoffPicture) => Promise<InputHandoffSubmission>) =>
+ answer(picture).then(
+ (submission) => {
+ answers.push(submission);
+ },
+ (error) => {
+ errors.push(error);
+ throw error;
+ },
+ ),
+ );
+ return { openPicture, answers, errors };
+}
+
+function mount(snapshot: InputHandoffSnapshot, openPicture: ReturnType<typeof exchange>["openPicture"]) {
+ const container = document.createElement("div");
+ document.body.appendChild(container);
+ const root = createRoot(container);
+ roots.push(root);
+ const onDecide = vi.fn();
+ act(() => {
+ root.render(
+ createElement(InputHandoffPictureStep, { snapshot, busy: false, openPicture, onDecide, onError: () => {} }),
+ );
+ });
+ return { container, root, onDecide };
+}
+
+const click = async (element: Element | null | undefined) => {
+ await act(async () => {
+ (element as HTMLElement).click();
+ });
+};
+const byText = (container: Element, text: string) =>
+ [...container.querySelectorAll("button")].find((b) => b.textContent === text);
+
+it("fetches the sealed picture only when the owner asks, then sends the tap as a fraction", async () => {
+ const host = exchange();
+ const { container } = mount(shot(), host.openPicture);
+ expect(host.openPicture).not.toHaveBeenCalled();
+ await click(byText(container, "interaction.inputHandoff.picture.open"));
+ const image = container.querySelector('button[aria-label="interaction.inputHandoff.picture.alt"]');
+ expect(container.querySelector("img")?.getAttribute("src")).toBe("data:image/jpeg;base64,AAAA");
+ await click(image);
+ expect(host.answers).toEqual([{ expectedRevision: 3, values: {}, action: { kind: "tap", x: 0.25, y: 0.75 } }]);
+});
+
+it("types into the focused field with the system secure field", async () => {
+ const host = exchange();
+ const snapshot = shot({ controls: [{ id: "typed", kind: "text", label: "", contentType: "password" }] });
+ const { container } = mount(snapshot, host.openPicture);
+ await click(byText(container, "interaction.inputHandoff.picture.open"));
+ const field = container.querySelector("input")!;
+ expect(field.type).toBe("password");
+ await act(async () => {
+ const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!;
+ setter.call(field, "synthetic-pass");
+ field.dispatchEvent(new Event("input", { bubbles: true }));
+ });
+ await click(byText(container, "interaction.inputHandoff.picture.typeEnter"));
+ expect(host.answers).toEqual([{ expectedRevision: 3, values: { typed: "synthetic-pass" }, action: { kind: "submit" } }]);
+});
+
+it("opens the next step by itself and closes an unanswered exchange when the step moves on", async () => {
+ const host = exchange();
+ const first = shot();
+ const { container, root } = mount(first, host.openPicture);
+ await click(byText(container, "interaction.inputHandoff.picture.open"));
+ await act(async () => {
+ root.render(
+ createElement(InputHandoffPictureStep, {
+ key: "next",
+ snapshot: { ...first, revision: 5 },
+ busy: false,
+ openPicture: host.openPicture,
+ onDecide: () => {},
+ onError: () => {},
+ }),
+ );
+ });
+ expect(host.errors).toHaveLength(1);
+ expect(host.openPicture).toHaveBeenCalledTimes(2);
+ expect(host.openPicture.mock.calls[1]![0]).toMatchObject({ revision: 5 });
+ expect(host.answers).toEqual([]);
+});
+
+it("goes back to the form without opening anything", async () => {
+ const host = exchange();
+ const { container, onDecide } = mount(shot(), host.openPicture);
+ await click(byText(container, "interaction.inputHandoff.action.backToForm"));
+ expect(onDecide).toHaveBeenCalledWith("refresh");
+ expect(host.openPicture).not.toHaveBeenCalled();
+});
+
diff --git a/apps/mobile/src/__tests__/InputHandoffStepFields.test.tsx b/apps/mobile/src/__tests__/InputHandoffStepFields.test.tsx
new file mode 100644
index 0000000000..828d3241de
--- /dev/null
+++ b/apps/mobile/src/__tests__/InputHandoffStepFields.test.tsx
@@ -0,0 +1,109 @@
+// @vitest-environment jsdom
+import { act, createElement, forwardRef, type ReactNode } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, expect, it, vi } from "vitest";
+import type { InputHandoffSnapshot } from "@cindy/device-link";
+
+vi.mock("react-native", async () => {
+ const { createElement } = await import("react");
+ const box = ({ children }: { children?: ReactNode }) => createElement("div", null, children);
+ return {
+ View: box,
+ Pressable: ({ children, onPress }: { children?: ReactNode; onPress(): void }) =>
+ createElement("button", { onClick: onPress }, children),
+ Platform: { OS: "ios" },
+ };
+});
+vi.mock("@/components/AppText", async () => {
+ const { createElement } = await import("react");
+ type Props = {
+ accessibilityLabel: string;
+ value: string;
+ returnKeyType?: string;
+ onChangeText(v: string): void;
+ onSubmitEditing?(): void;
+ };
+ return {
+ Text: ({ children }: { children?: ReactNode }) => createElement("span", null, children),
+ // Enter stands in for the keyboard's Return key.
+ TextInput: forwardRef<HTMLInputElement, Props>((props, ref) =>
+ createElement("input", {
+ ref,
+ "aria-label": props.accessibilityLabel,
+ "data-return": props.returnKeyType,
+ value: props.value,
+ onChange: (e: { target: { value: string } }) => props.onChangeText(e.target.value),
+ onKeyDown: (e: { key: string }) => e.key === "Enter" && props.onSubmitEditing?.(),
+ }),
+ ),
+ };
+});
+vi.mock("@/components/MobilePrimitives", async () => {
+ const { createElement } = await import("react");
+ type Action = { label: string; onPress(): void };
+ const button = (action: Action) => createElement("button", { key: action.label, onClick: action.onPress }, action.label);
+ return {
+ MainWindowActionButton: ({ action }: { action: Action }) => button(action),
+ MainWindowActionGroup: ({ cancelAction, primaryActions = [] }: { cancelAction?: Action; primaryActions?: Action[] }) =>
+ createElement("div", null, ...[cancelAction, ...primaryActions].filter(Boolean).map((a) => button(a!))),
+ };
+});
+vi.mock("@/theme", () => ({ useTheme: () => ({ colors: {} }), useThemedStyles: () => ({}) }));
+vi.mock("@/inputHandoff/inputHandoffStyles", () => ({ makeInputHandoffStyles: () => ({}) }));
+vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+
+(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+const { InputHandoffStepFields } = await import("@/inputHandoff/InputHandoffStepFields");
+
+let roots: Root[] = [];
+afterEach(() => {
+ act(() => roots.forEach((root) => root.unmount()));
+ roots = [];
+});
+
+const step: InputHandoffSnapshot = {
+ kind: "input_handoff",
+ requestId: "req1",
+ revision: 2,
+ phase: "ready",
+ purpose: "Sign in",
+ source: { app: "Google Chrome", origin: "https://auth.example.com" },
+ stepNumber: 1,
+ remoteInput: true,
+ controls: [
+ { id: "n0", kind: "note", tone: "error", text: "Wrong password" },
+ { id: "c0", kind: "text", label: "Email", contentType: "email" },
+ { id: "c1", kind: "text", label: "Password", contentType: "password" },
+ ],
+};
+
+function mount(snapshot: InputHandoffSnapshot) {
+ const onSubmit = vi.fn();
+ const host = document.createElement("div");
+ document.body.append(host);
+ const root = createRoot(host);
+ roots.push(root);
+ act(() =>
+ root.render(
+ createElement(InputHandoffStepFields, { snapshot, draft: {}, disabled: false, onChange: () => {}, onSubmit }),
+ ),
+ );
+ return { host, onSubmit };
+}
+
+const press = (el: Element) => act(() => el.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true })));
+
+it("shows only the fields and the page's error, with Next then Go on the keyboard", () => {
+ const { host, onSubmit } = mount(step);
+ expect(host.textContent).toContain("Wrong password");
+ const [email, password] = Array.from(host.querySelectorAll("input"));
+ expect([email.dataset.return, password.dataset.return]).toEqual(["next", "go"]);
+ // No page buttons: the sheet around the fields carries Continue and Cancel.
+ expect(host.querySelectorAll("button")).toHaveLength(0);
+
+ press(email);
+ expect(document.activeElement).toBe(password);
+ expect(onSubmit).not.toHaveBeenCalled();
+ press(password);
+ expect(onSubmit).toHaveBeenCalledTimes(1);
+});
diff --git a/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx b/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx
index 252d7e1934..af56c1378b 100644
--- a/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx
+++ b/apps/mobile/src/__tests__/InteractionPanelReceipt.test.tsx
@@ -23,6 +23,8 @@ vi.mock('@/device-link/DeviceLinkContext', () => ({ useDeviceLink: () => ({ invo
vi.mock('@/device-link/useMobileMakerTransport', () => ({
useMobileMakerTransport: () => ({ resolveInteraction }),
}));
+// 代输入 card has its own tests; its native modules (clipboard, secure store) are out of scope here.
+vi.mock('@/inputHandoff/InputHandoffCard', () => ({ InputHandoffCard: () => null }));
vi.mock('react-native-safe-area-context', () => ({ useSafeAreaInsets: () => ({ top: 0, right: 0, bottom: 0, left: 0 }) }));
vi.mock('react-native', async () => {
const { createElement } = await import('react');
diff --git a/apps/mobile/src/i18n/locales/en/interaction.json b/apps/mobile/src/i18n/locales/en/interaction.json
index 9d99807194..125db69256 100644
--- a/apps/mobile/src/i18n/locales/en/interaction.json
+++ b/apps/mobile/src/i18n/locales/en/interaction.json
@@ -129,6 +129,10 @@
"fallback": {
"title": "Remote Request Needs Attention",
"label": "Request"
+ },
+ "input_handoff": {
+ "title": "Input Handoff Needed",
+ "label": "Input Handoff"
}
},
"rewind": {
@@ -244,6 +248,129 @@
"inlineFormAction": "Enter {{label}} on your computer",
"inlineFormActionGeneric": "Enter one setting on your computer"
},
+ "inputHandoff": {
+ "originWarning": {
+ "insecure": "This page doesn't use a secure connection. What you enter could be read by others.",
+ "ip-address": "This page uses an IP address instead of a domain. Make sure it's the site you expect.",
+ "local-host": "This page comes from a service on this computer. Make sure it's the app you expect.",
+ "local-file": "This page is a local file. Make sure it's what you expect.",
+ "punycode": "This address contains unusual characters and may imitate another site. Check it carefully.",
+ "embedded-frame": "These fields are inside another site embedded in the page. Make sure the source is trusted."
+ },
+ "agentControlled": "The agent opened this screen. Make sure it's really where you want to sign in before filling it.",
+ "error": {
+ "decision": "That didn't go through. Try again.",
+ "stale": "The screen has changed. Use the latest version.",
+ "submit": "Your input didn't go through. Try again."
+ },
+ "terminal": {
+ "succeeded": "Handed back to the agent.",
+ "cancelled": "Input handoff canceled.",
+ "failed": "Input handoff ended.",
+ "expired": "Input handoff ended after waiting too long."
+ },
+ "failure": {
+ "permission": "Cindy can't read this computer's screen. Allow Cindy under Accessibility in System Settings.",
+ "target_gone": "The target window was closed.",
+ "unreadable": "This screen can't be read. You can finish it on the host computer, then hand back to the agent.",
+ "action_failed": "That action didn't take effect. Check the screen and try again.",
+ "timeout": "Input handoff ended after waiting too long.",
+ "unsupported": "This computer doesn't support input handoff yet.",
+ "origin_changed": "The page changed before Cindy could fill it, so nothing was entered. Check the current page, then try again.",
+ "picture_unavailable": "Couldn't show this step as a picture. Allow Cindy to record the screen in System Settings, and make sure the window isn't minimized.",
+ "screen_locked": "This computer's screen is locked (a display going to sleep locks it too). Wake and unlock it, then ask the agent to try again.",
+ "nothing_to_fill": "Nothing on this screen needs typing, so the agent carries on by itself."
+ },
+ "phase": {
+ "reading": "Reading the screen…",
+ "working": "Filling in…",
+ "finishing": "Looks complete. Handing back to the agent in {{count}}s.",
+ "finishingNow": "Looks complete. Handing back to the agent…"
+ },
+ "action": {
+ "stay": "Not Done Yet",
+ "done": "Hand Back to Agent",
+ "cancel": "Cancel Handoff",
+ "claim": "Handle Here",
+ "picture": "Show screen",
+ "backToForm": "Back to form",
+ "liveView": "Live View",
+ "fill": "Fill In",
+ "skip": "Skip",
+ "continue": "Continue",
+ "close": "Cancel",
+ "showPassword": "Show Password",
+ "hidePassword": "Hide Password",
+ "scan": "Scan"
+ },
+ "remoteUnavailable": "This computer can't receive input remotely. Finish this step on the host computer, then hand back to the agent.",
+ "unnamedField": "Field",
+ "passwordField": "Password",
+ "codeField": "Verification code",
+ "filledHint": "Already has content. Leave empty to keep it.",
+ "record": {
+ "doneOn_one": "Owner finished {{count}} input step on {{device}}",
+ "doneOn_other": "Owner finished {{count}} input steps on {{device}}",
+ "doneHost_one": "Owner finished {{count}} input step on the host computer",
+ "doneHost_other": "Owner finished {{count}} input steps on the host computer",
+ "donePhone_one": "Owner finished {{count}} input step on a phone",
+ "donePhone_other": "Owner finished {{count}} input steps on a phone",
+ "doneElsewhere_one": "Owner finished {{count}} input step on another device",
+ "doneElsewhere_other": "Owner finished {{count}} input steps on another device",
+ "done": "Input handoff finished",
+ "nothingToFill": "Nothing to type; handed back to the agent",
+ "cancelled": "Input handoff cancelled",
+ "expired": "Input handoff timed out",
+ "failed": "Input handoff didn't finish"
+ },
+ "holder": {
+ "elsewhere": "Being handled on {{device}}. You can take it over here.",
+ "host": "the host computer",
+ "phone": "a phone",
+ "otherDevice": "another device"
+ },
+ "agentNote": "Note from the agent: {{note}}",
+ "picture": {
+ "hint": "Tap a spot in the picture and Cindy taps the same spot on the host computer.",
+ "open": "Show this step",
+ "openHint": "This step can't be shown as a form. The picture is sent encrypted to this device only and isn't saved.",
+ "alt": "Picture of the target window",
+ "loading": "Getting the picture…",
+ "error": "Couldn't get the picture. Try again.",
+ "field": "Focused field",
+ "type": "Type",
+ "typeEnter": "Type and press Return"
+ },
+ "liveViewHint": "See just this window live from here. Clicks and typing stay inside it.",
+ "deviceCode": {
+ "prompt": "Sign in with this code",
+ "copy": "Copy Code",
+ "copied": "Code copied",
+ "copyFailed": "Couldn't copy the code",
+ "open": "Open on This Device",
+ "openFailed": "Couldn't open the link",
+ "then": "Enter the code on that page and finish signing in, then choose Hand Back to Agent."
+ },
+ "sheetNote": "Only entered here on the computer. Not shared with the agent, and not saved.",
+ "nothingLeft": "Nothing here needs you to type.",
+ "qr": {
+ "open": "Open {{site}} Here",
+ "openApp": "Open {{site}} Link Here",
+ "share": "Save or Share Image",
+ "copyLink": "Copy Link",
+ "copyText": "Copy Text",
+ "copied": "Copied.",
+ "copyFailed": "Couldn't copy. Try again.",
+ "openFailed": "This device can't open the link. Save the image and pick it from Photos in the app's scanner.",
+ "shareFailed": "Couldn't open sharing. Try again.",
+ "hintLink": "Opening it here hands the sign-in to the app that handles the link. Or save the image and pick it from Photos in the app's scanner. Cindy continues once you're signed in.",
+ "hint": "Save the image and pick it from Photos in the app's scanner, or scan this code from another device. Cindy continues once you're signed in.",
+ "alt": "QR code on the computer. Tapping it taps the code on the computer.",
+ "loading": "Getting the QR code…",
+ "failed": "Couldn't get the QR code. Tap to try again.",
+ "scanned": "Scanned. Confirm on your phone; Cindy continues once you do."
+ }
+ },
"presentation": {
"action": {
"submitting": "Submitting"
diff --git a/apps/mobile/src/i18n/locales/en/remoteDesktop.json b/apps/mobile/src/i18n/locales/en/remoteDesktop.json
index 7628b7f68c..6dbe3886bd 100644
--- a/apps/mobile/src/i18n/locales/en/remoteDesktop.json
+++ b/apps/mobile/src/i18n/locales/en/remoteDesktop.json
@@ -160,5 +160,8 @@
"lockOnExitFailed": "Could not confirm that the computer locked. Check the computer before leaving it unattended.",
"hostMute": "Mute remote computer",
"hostMuteHint": "Mute the remote computer while connected",
- "hostMuteFailed": "Couldn't change the remote computer's mute setting"
+ "hostMuteFailed": "Couldn't change the remote computer's mute setting",
+ "handoffEnded": "This input handoff has already finished, so there is no window to show.",
+ "handoffUnavailable": "This computer can't show just this window. Update Cindy on it, or turn on remote desktop there.",
+ "handoffWindow": "Input handoff · {{app}}"
}
diff --git a/apps/mobile/src/i18n/locales/ja/interaction.json b/apps/mobile/src/i18n/locales/ja/interaction.json
index b06904b907..c287f192b3 100644
--- a/apps/mobile/src/i18n/locales/ja/interaction.json
+++ b/apps/mobile/src/i18n/locales/ja/interaction.json
@@ -129,6 +129,10 @@
"fallback": {
"title": "リモートリクエストの対応が必要です",
"label": "リクエスト"
+ },
+ "input_handoff": {
+ "title": "代理入力が必要です",
+ "label": "代理入力"
}
},
"rewind": {
@@ -244,6 +248,129 @@
"inlineFormAction": "パソコンで{{label}}を入力",
"inlineFormActionGeneric": "パソコンで設定を入力"
},
+ "inputHandoff": {
+ "originWarning": {
+ "insecure": "このページは安全な接続を使っていません。入力内容が他人に読まれる可能性があります。",
+ "ip-address": "このページはドメインではなく IP アドレスを使っています。想定したサイトか確認してください。",
+ "local-host": "このページはこのコンピュータ上のサービスから表示されています。想定したアプリか確認してください。",
+ "local-file": "このページはローカルファイルです。想定した内容か確認してください。",
+ "punycode": "このアドレスには特殊な文字が含まれ、別のサイトを装っている可能性があります。よく確認してください。",
+ "embedded-frame": "入力欄はページに埋め込まれた別サイトの中にあります。提供元が信頼できるか確認してください。"
+ },
+ "agentControlled": "この画面は Agent が開きました。入力する前に、本当にサインインしたい場所か確認してください。",
+ "error": {
+ "decision": "操作が届きませんでした。もう一度お試しください。",
+ "stale": "画面が変わりました。最新の内容で操作してください。",
+ "submit": "入力が届きませんでした。もう一度お試しください。"
+ },
+ "terminal": {
+ "succeeded": "Agent に戻しました。",
+ "cancelled": "代理入力をキャンセルしました。",
+ "failed": "代理入力は終了しました。",
+ "expired": "待ち時間が長すぎたため、代理入力は終了しました。"
+ },
+ "failure": {
+ "permission": "Cindy にこのコンピュータの画面を読む権限がありません。システム設定のアクセシビリティで Cindy を許可してください。",
+ "target_gone": "対象のウインドウが閉じられました。",
+ "unreadable": "この画面を読み取れません。ホストのコンピュータで直接完了してから Agent に戻してください。",
+ "action_failed": "直前の操作が反映されませんでした。画面を確認してもう一度お試しください。",
+ "timeout": "待ち時間が長すぎたため、代理入力は終了しました。",
+ "unsupported": "このコンピュータはまだ代理入力に対応していません。",
+ "origin_changed": "入力前にページが変わったため、何も入力していません。現在のページを確認してからもう一度入力してください。",
+ "picture_unavailable": "このステップの画面を表示できませんでした。システム設定で Cindy の画面収録を許可し、ウインドウが最小化されていないか確認してください。",
+ "screen_locked": "このコンピュータの画面はロックされています(ディスプレイのスリープでもロックされます)。スリープを解除してロックを外してから、Agent にもう一度試すよう伝えてください。",
+ "nothing_to_fill": "この画面には入力が必要な項目がないため、Agent がそのまま続けます。"
+ },
+ "phase": {
+ "reading": "画面を読み取っています…",
+ "working": "入力しています…",
+ "finishing": "完了したようです。{{count}} 秒後に Agent に戻します。",
+ "finishingNow": "完了したようです。Agent に戻しています…"
+ },
+ "action": {
+ "stay": "まだ終わっていない",
+ "done": "Agent に戻す",
+ "cancel": "代理入力をキャンセル",
+ "claim": "ここで対応",
+ "picture": "画面を見る",
+ "backToForm": "フォームに戻る",
+ "liveView": "ライブ表示",
+ "fill": "入力",
+ "skip": "スキップ",
+ "continue": "続ける",
+ "close": "キャンセル",
+ "showPassword": "パスワードを表示",
+ "hidePassword": "パスワードを隠す",
+ "scan": "スキャン"
+ },
+ "remoteUnavailable": "このコンピュータはリモートから入力を受け取れません。ホストのコンピュータでこのステップを完了してから Agent に戻してください。",
+ "unnamedField": "入力欄",
+ "passwordField": "パスワード",
+ "codeField": "確認コード",
+ "filledHint": "すでに入力済みです。空欄のままにすると変更しません。",
+ "record": {
+ "doneOn_one": "オーナーが {{device}} で {{count}} ステップの入力を完了しました",
+ "doneOn_other": "オーナーが {{device}} で {{count}} ステップの入力を完了しました",
+ "doneHost_one": "オーナーがホストのコンピュータで {{count}} ステップの入力を完了しました",
+ "doneHost_other": "オーナーがホストのコンピュータで {{count}} ステップの入力を完了しました",
+ "donePhone_one": "オーナーがスマートフォンで {{count}} ステップの入力を完了しました",
+ "donePhone_other": "オーナーがスマートフォンで {{count}} ステップの入力を完了しました",
+ "doneElsewhere_one": "オーナーが別のデバイスで {{count}} ステップの入力を完了しました",
+ "doneElsewhere_other": "オーナーが別のデバイスで {{count}} ステップの入力を完了しました",
+ "done": "代理入力が完了しました",
+ "nothingToFill": "入力不要のため Agent に戻しました",
+ "cancelled": "代理入力をキャンセルしました",
+ "expired": "代理入力がタイムアウトしました",
+ "failed": "代理入力は完了しませんでした"
+ },
+ "holder": {
+ "elsewhere": "{{device}} で対応中です。ここで引き継ぐこともできます。",
+ "host": "ホストのコンピュータ",
+ "phone": "スマートフォン",
+ "otherDevice": "別のデバイス"
+ },
+ "agentNote": "Agentからの補足:{{note}}",
+ "picture": {
+ "hint": "画面上の位置をタップすると、Cindy がホストのコンピュータで同じ位置をクリックします。",
+ "open": "このステップの画面を表示",
+ "openHint": "このステップはフォームにできません。画面はこのデバイスにだけ暗号化して送られ、保存されません。",
+ "alt": "対象ウインドウの画面",
+ "loading": "画面を取得しています…",
+ "error": "画面を取得できませんでした。もう一度お試しください。",
+ "field": "選択中の入力欄",
+ "type": "入力",
+ "typeEnter": "入力して Return"
+ },
+ "liveViewHint": "このウィンドウだけをここでライブ表示します。クリックや入力はこのウィンドウ内にのみ届きます。",
+ "deviceCode": {
+ "prompt": "このコードでサインイン",
+ "copy": "コードをコピー",
+ "copied": "コードをコピーしました",
+ "copyFailed": "コピーできませんでした",
+ "open": "このデバイスで開く",
+ "openFailed": "リンクを開けませんでした",
+ "then": "開いたページでコードを入力してサインインを完了したら、「Agent に戻す」を選んでください。"
+ },
+ "sheetNote": "コンピュータのこの場所にのみ入力されます。エージェントには渡されず、保存もされません。",
+ "nothingLeft": "ここで入力が必要な項目はありません。",
+ "qr": {
+ "open": "この端末で {{site}} を開く",
+ "openApp": "この端末で {{site}} のリンクを開く",
+ "share": "画像を保存・共有",
+ "copyLink": "リンクをコピー",
+ "copyText": "内容をコピー",
+ "copied": "コピーしました。",
+ "copyFailed": "コピーできませんでした。もう一度お試しください。",
+ "openFailed": "この端末ではリンクを開けません。画像を保存して、アプリのスキャン画面で写真から読み取ってください。",
+ "shareFailed": "共有を開けませんでした。もう一度お試しください。",
+ "hintLink": "この端末で開くと、対応するアプリでログインを完了できます。画像を保存して、アプリのスキャン画面で写真から読み取ることもできます。ログイン後は自動で続行します。",
+ "hint": "画像を保存してアプリのスキャン画面で写真から読み取るか、別の端末でこのコードをスキャンしてください。ログイン後は自動で続行します。",
+ "alt": "コンピュータ上の QR コード。タップするとコンピュータ上のこのコードをタップします。",
+ "loading": "QR コードを取得しています…",
+ "failed": "QR コードを取得できませんでした。タップして再試行。",
+ "scanned": "スキャンしました。スマートフォンで確認してください。確認後は自動で続行します。"
+ }
+ },
"presentation": {
"action": {
"submitting": "送信中"
diff --git a/apps/mobile/src/i18n/locales/ja/remoteDesktop.json b/apps/mobile/src/i18n/locales/ja/remoteDesktop.json
index ea6d64c03e..727241448d 100644
--- a/apps/mobile/src/i18n/locales/ja/remoteDesktop.json
+++ b/apps/mobile/src/i18n/locales/ja/remoteDesktop.json
@@ -160,5 +160,8 @@
"lockOnExitFailed": "パソコンのロックを確認できませんでした。パソコンの状態を確認してください。",
"hostMute": "リモートのパソコンをミュート",
"hostMuteHint": "接続中はリモートのパソコンの音声をミュートします",
- "hostMuteFailed": "リモートのパソコンのミュート状態を変更できません"
+ "hostMuteFailed": "リモートのパソコンのミュート状態を変更できません",
+ "handoffEnded": "この代理入力はすでに終了しているため、表示するウィンドウがありません。",
+ "handoffUnavailable": "このコンピュータではこのウィンドウだけを表示できません。そのコンピュータで Cindy を更新するか、リモートデスクトップをオンにしてください。",
+ "handoffWindow": "代理入力 · {{app}}"
}
diff --git a/apps/mobile/src/i18n/locales/ko/interaction.json b/apps/mobile/src/i18n/locales/ko/interaction.json
index 3827a678b0..7f6a530cd7 100644
--- a/apps/mobile/src/i18n/locales/ko/interaction.json
+++ b/apps/mobile/src/i18n/locales/ko/interaction.json
@@ -129,6 +129,10 @@
"fallback": {
"title": "원격 요청을 처리해야 합니다",
"label": "요청"
+ },
+ "input_handoff": {
+ "title": "대리 입력이 필요합니다",
+ "label": "대리 입력"
}
},
"rewind": {
@@ -244,6 +248,129 @@
"inlineFormAction": "컴퓨터에서 {{label}} 입력",
"inlineFormActionGeneric": "컴퓨터에서 설정 입력"
},
+ "inputHandoff": {
+ "originWarning": {
+ "insecure": "이 페이지는 보안 연결을 사용하지 않습니다. 입력한 내용이 다른 사람에게 노출될 수 있습니다.",
+ "ip-address": "이 페이지는 도메인 대신 IP 주소를 사용합니다. 예상한 사이트인지 확인하세요.",
+ "local-host": "이 페이지는 이 컴퓨터의 서비스에서 제공됩니다. 예상한 앱인지 확인하세요.",
+ "local-file": "이 페이지는 로컬 파일입니다. 예상한 내용인지 확인하세요.",
+ "punycode": "이 주소에는 특수 문자가 포함되어 다른 사이트를 사칭할 수 있습니다. 자세히 확인하세요.",
+ "embedded-frame": "입력란이 페이지에 삽입된 다른 사이트 안에 있습니다. 출처를 신뢰할 수 있는지 확인하세요."
+ },
+ "agentControlled": "이 화면은 Agent가 열었습니다. 입력하기 전에 실제로 로그인하려는 곳인지 확인하세요.",
+ "error": {
+ "decision": "요청이 전달되지 않았습니다. 다시 시도하세요.",
+ "stale": "화면이 바뀌었습니다. 최신 내용으로 진행하세요.",
+ "submit": "입력이 전달되지 않았습니다. 다시 시도하세요."
+ },
+ "terminal": {
+ "succeeded": "Agent에게 넘겼습니다.",
+ "cancelled": "대리 입력을 취소했습니다.",
+ "failed": "대리 입력이 종료되었습니다.",
+ "expired": "대기 시간이 너무 길어 대리 입력이 종료되었습니다."
+ },
+ "failure": {
+ "permission": "Cindy에 이 컴퓨터 화면을 읽을 권한이 없습니다. 시스템 설정의 손쉬운 사용에서 Cindy를 허용하세요.",
+ "target_gone": "대상 창이 닫혔습니다.",
+ "unreadable": "이 화면을 읽을 수 없습니다. 호스트 컴퓨터에서 직접 완료한 뒤 Agent에게 넘기세요.",
+ "action_failed": "방금 작업이 적용되지 않았습니다. 화면을 확인하고 다시 시도하세요.",
+ "timeout": "대기 시간이 너무 길어 대리 입력이 종료되었습니다.",
+ "unsupported": "이 컴퓨터는 아직 대리 입력을 지원하지 않습니다.",
+ "origin_changed": "입력하기 전에 페이지가 바뀌어 아무것도 입력하지 않았습니다. 현재 페이지를 확인한 후 다시 입력하세요.",
+ "picture_unavailable": "이 단계의 화면을 표시하지 못했습니다. 시스템 설정에서 Cindy의 화면 기록을 허용하고 윈도우가 최소화되지 않았는지 확인하세요.",
+ "screen_locked": "이 컴퓨터의 화면이 잠겨 있습니다(디스플레이가 잠자기 상태가 되어도 잠깁니다). 화면을 깨우고 잠금을 해제한 후 Agent에게 다시 시도하도록 요청하세요.",
+ "nothing_to_fill": "이 화면에는 입력할 내용이 없어 Agent가 이어서 진행합니다."
+ },
+ "phase": {
+ "reading": "화면을 읽는 중…",
+ "working": "입력하는 중…",
+ "finishing": "완료된 것 같습니다. {{count}}초 후 Agent에게 넘깁니다.",
+ "finishingNow": "완료된 것 같습니다. Agent에게 넘기는 중…"
+ },
+ "action": {
+ "stay": "아직 안 끝났어요",
+ "done": "Agent에게 넘기기",
+ "cancel": "대리 입력 취소",
+ "claim": "여기서 처리",
+ "picture": "화면 보기",
+ "backToForm": "양식으로 돌아가기",
+ "liveView": "실시간 화면",
+ "fill": "입력",
+ "skip": "건너뛰기",
+ "continue": "계속",
+ "close": "취소",
+ "showPassword": "암호 표시",
+ "hidePassword": "암호 숨기기",
+ "scan": "스캔"
+ },
+ "remoteUnavailable": "이 컴퓨터는 원격으로 입력을 받을 수 없습니다. 호스트 컴퓨터에서 이 단계를 완료한 뒤 Agent에게 넘기세요.",
+ "unnamedField": "입력란",
+ "passwordField": "비밀번호",
+ "codeField": "인증 코드",
+ "filledHint": "이미 내용이 있습니다. 비워 두면 그대로 유지됩니다.",
+ "record": {
+ "doneOn_one": "소유자가 {{device}}에서 {{count}}단계 입력을 마쳤습니다",
+ "doneOn_other": "소유자가 {{device}}에서 {{count}}단계 입력을 마쳤습니다",
+ "doneHost_one": "소유자가 호스트 컴퓨터에서 {{count}}단계 입력을 마쳤습니다",
+ "doneHost_other": "소유자가 호스트 컴퓨터에서 {{count}}단계 입력을 마쳤습니다",
+ "donePhone_one": "소유자가 휴대폰에서 {{count}}단계 입력을 마쳤습니다",
+ "donePhone_other": "소유자가 휴대폰에서 {{count}}단계 입력을 마쳤습니다",
+ "doneElsewhere_one": "소유자가 다른 기기에서 {{count}}단계 입력을 마쳤습니다",
+ "doneElsewhere_other": "소유자가 다른 기기에서 {{count}}단계 입력을 마쳤습니다",
+ "done": "대리 입력을 마쳤습니다",
+ "nothingToFill": "입력할 내용이 없어 Agent에게 넘겼습니다",
+ "cancelled": "대리 입력을 취소했습니다",
+ "expired": "대리 입력 시간이 초과되었습니다",
+ "failed": "대리 입력을 마치지 못했습니다"
+ },
+ "holder": {
+ "elsewhere": "{{device}}에서 처리 중입니다. 여기서 이어받을 수도 있습니다.",
+ "host": "호스트 컴퓨터",
+ "phone": "휴대폰",
+ "otherDevice": "다른 기기"
+ },
+ "agentNote": "Agent 메모: {{note}}",
+ "picture": {
+ "hint": "화면에서 위치를 탭하면 Cindy가 호스트 컴퓨터의 같은 위치를 클릭합니다.",
+ "open": "이 단계 화면 보기",
+ "openHint": "이 단계는 양식으로 정리할 수 없습니다. 화면은 이 기기로만 암호화되어 전송되며 저장되지 않습니다.",
+ "alt": "대상 윈도우의 화면",
+ "loading": "화면을 가져오는 중…",
+ "error": "화면을 가져오지 못했습니다. 다시 시도하세요.",
+ "field": "선택된 입력란",
+ "type": "입력",
+ "typeEnter": "입력 후 Return"
+ },
+ "liveViewHint": "이 창 하나만 여기에서 실시간으로 봅니다. 클릭과 입력은 이 창 안에만 전달됩니다.",
+ "deviceCode": {
+ "prompt": "이 코드로 로그인",
+ "copy": "코드 복사",
+ "copied": "코드를 복사했습니다",
+ "copyFailed": "복사하지 못했습니다",
+ "open": "이 기기에서 열기",
+ "openFailed": "링크를 열지 못했습니다",
+ "then": "열린 페이지에 코드를 입력해 로그인을 마친 뒤 「Agent에게 넘기기」를 선택하세요."
+ },
+ "sheetNote": "컴퓨터의 이 위치에만 입력됩니다. 에이전트에게 전달되거나 저장되지 않습니다.",
+ "nothingLeft": "여기에는 입력할 항목이 없습니다.",
+ "qr": {
+ "open": "이 기기에서 {{site}} 열기",
+ "openApp": "이 기기에서 {{site}} 링크 열기",
+ "share": "이미지 저장 또는 공유",
+ "copyLink": "링크 복사",
+ "copyText": "내용 복사",
+ "copied": "복사했습니다.",
+ "copyFailed": "복사하지 못했습니다. 다시 시도하세요.",
+ "openFailed": "이 기기에서 링크를 열 수 없습니다. 이미지를 저장한 뒤 앱의 스캔 화면에서 사진으로 인식하세요.",
+ "shareFailed": "공유를 열지 못했습니다. 다시 시도하세요.",
+ "hintLink": "이 기기에서 열면 해당 앱에서 로그인을 마칠 수 있습니다. 이미지를 저장한 뒤 앱의 스캔 화면에서 사진으로 인식할 수도 있습니다. 로그인하면 자동으로 계속합니다.",
+ "hint": "이미지를 저장한 뒤 앱의 스캔 화면에서 사진으로 인식하거나, 다른 기기로 이 코드를 스캔하세요. 로그인하면 자동으로 계속합니다.",
+ "alt": "컴퓨터의 QR 코드. 탭하면 컴퓨터의 이 코드를 탭합니다.",
+ "loading": "QR 코드를 가져오는 중…",
+ "failed": "QR 코드를 가져오지 못했습니다. 탭해서 다시 시도하세요.",
+ "scanned": "스캔했습니다. 휴대폰에서 확인하세요. 확인하면 자동으로 계속합니다."
+ }
+ },
"presentation": {
"action": {
"submitting": "제출 중"
diff --git a/apps/mobile/src/i18n/locales/ko/remoteDesktop.json b/apps/mobile/src/i18n/locales/ko/remoteDesktop.json
index 8095d5b068..fd36e668b0 100644
--- a/apps/mobile/src/i18n/locales/ko/remoteDesktop.json
+++ b/apps/mobile/src/i18n/locales/ko/remoteDesktop.json
@@ -160,5 +160,8 @@
"lockOnExitFailed": "컴퓨터가 잠겼는지 확인하지 못했습니다. 컴퓨터 상태를 확인해 주세요.",
"hostMute": "원격 컴퓨터 음소거",
"hostMuteHint": "연결 중 원격 컴퓨터의 소리를 음소거합니다",
- "hostMuteFailed": "원격 컴퓨터의 음소거 상태를 변경할 수 없습니다"
+ "hostMuteFailed": "원격 컴퓨터의 음소거 상태를 변경할 수 없습니다",
+ "handoffEnded": "이 대리 입력은 이미 끝나서 표시할 창이 없습니다.",
+ "handoffUnavailable": "이 컴퓨터에서는 이 창만 표시할 수 없습니다. 해당 컴퓨터에서 Cindy를 업데이트하거나 원격 데스크톱을 켜세요.",
+ "handoffWindow": "대리 입력 · {{app}}"
}
diff --git a/apps/mobile/src/i18n/locales/zh-CN/interaction.json b/apps/mobile/src/i18n/locales/zh-CN/interaction.json
index 39b1d66118..abad5ec7a6 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/interaction.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/interaction.json
@@ -129,6 +129,10 @@
"fallback": {
"title": "需要处理远程请求",
"label": "请求"
+ },
+ "input_handoff": {
+ "title": "需要你代为输入",
+ "label": "代输入"
}
},
"rewind": {
@@ -244,6 +248,129 @@
"inlineFormAction": "在电脑端填写{{label}}",
"inlineFormActionGeneric": "在电脑端填写一项配置"
},
+ "inputHandoff": {
+ "originWarning": {
+ "insecure": "这个页面没有使用安全连接,输入的内容可能被他人读取。",
+ "ip-address": "这个页面使用 IP 地址而不是域名,请确认它是你预期的网站。",
+ "local-host": "这个页面来自本机服务,请确认它是你预期的程序。",
+ "local-file": "这个页面是本地文件,请确认它是你预期的内容。",
+ "punycode": "这个网址包含特殊字符,可能在冒充其他网站,请仔细核对。",
+ "embedded-frame": "输入框位于嵌入的其他网站中,请确认来源可信。"
+ },
+ "agentControlled": "这个界面由 Agent 打开。填写前请确认它确实是你要登录的地方。",
+ "error": {
+ "decision": "操作没有送达,请重试。",
+ "stale": "界面已经变化,请按最新内容操作。",
+ "submit": "输入没有送达,请重试。"
+ },
+ "terminal": {
+ "succeeded": "已交还给 Agent。",
+ "cancelled": "已取消代输入。",
+ "failed": "代输入已结束。",
+ "expired": "等待时间过长,代输入已结束。"
+ },
+ "failure": {
+ "permission": "Cindy 没有读取这台电脑界面的权限。请在系统设置的辅助功能中允许 Cindy。",
+ "target_gone": "目标窗口已关闭。",
+ "unreadable": "无法读取这个界面。可以在宿主电脑上直接完成,然后交还给 Agent。",
+ "action_failed": "刚才的操作没有生效,请检查界面后重试。",
+ "timeout": "等待时间过长,代输入已结束。",
+ "unsupported": "这台电脑暂不支持代输入。",
+ "origin_changed": "填写前页面已变化,什么都没有填入。请确认现在的页面后再填写。",
+ "picture_unavailable": "没能显示这一步的画面。请在系统设置中允许 Cindy 录制屏幕,并确认窗口没有被最小化。",
+ "screen_locked": "这台电脑的屏幕已锁定(显示器休眠也会锁屏)。请先唤醒并解锁,再让 Agent 重试。",
+ "nothing_to_fill": "这个界面没有需要你输入的内容,已交还给 Agent 继续。"
+ },
+ "phase": {
+ "reading": "正在读取界面…",
+ "working": "正在填写…",
+ "finishing": "看起来已经完成,{{count}} 秒后交还给 Agent。",
+ "finishingNow": "看起来已经完成,正在交还给 Agent…"
+ },
+ "action": {
+ "stay": "还没完成",
+ "done": "交还给 Agent",
+ "cancel": "取消代输入",
+ "claim": "改在这里处理",
+ "picture": "看画面",
+ "backToForm": "回到表单",
+ "liveView": "实时画面",
+ "fill": "填写",
+ "skip": "跳过",
+ "continue": "继续",
+ "close": "取消",
+ "showPassword": "显示密码",
+ "hidePassword": "隐藏密码",
+ "scan": "扫码"
+ },
+ "remoteUnavailable": "这台电脑不能从远程接收输入。请在宿主电脑上完成这一步,再交还给 Agent。",
+ "unnamedField": "输入框",
+ "passwordField": "密码",
+ "codeField": "验证码",
+ "filledHint": "已有内容;留空则保持不变。",
+ "record": {
+ "doneOn_one": "主人在 {{device}} 完成了 {{count}} 步输入",
+ "doneOn_other": "主人在 {{device}} 完成了 {{count}} 步输入",
+ "doneHost_one": "主人在宿主电脑上完成了 {{count}} 步输入",
+ "doneHost_other": "主人在宿主电脑上完成了 {{count}} 步输入",
+ "donePhone_one": "主人在手机上完成了 {{count}} 步输入",
+ "donePhone_other": "主人在手机上完成了 {{count}} 步输入",
+ "doneElsewhere_one": "主人在另一台设备上完成了 {{count}} 步输入",
+ "doneElsewhere_other": "主人在另一台设备上完成了 {{count}} 步输入",
+ "done": "代输入已完成",
+ "nothingToFill": "无需输入,已交还给 Agent",
+ "cancelled": "代输入已取消",
+ "expired": "代输入已超时",
+ "failed": "代输入未完成"
+ },
+ "holder": {
+ "elsewhere": "正在 {{device}} 上处理,也可以改在这里处理。",
+ "host": "宿主电脑",
+ "phone": "手机",
+ "otherDevice": "另一台设备"
+ },
+ "agentNote": "Agent 补充:{{note}}",
+ "picture": {
+ "hint": "点按画面里的位置,Cindy 会在宿主电脑上点按同一个位置。",
+ "open": "显示这一步的画面",
+ "openHint": "这一步无法整理成表单。画面只加密发送到这台设备,不会保存。",
+ "alt": "目标窗口的画面",
+ "loading": "正在获取画面…",
+ "error": "没能取得画面,请重试。",
+ "field": "当前输入框",
+ "type": "输入",
+ "typeEnter": "输入并回车"
+ },
+ "liveViewHint": "在这里实时查看这一个窗口,点按和输入只会进入这个窗口。",
+ "deviceCode": {
+ "prompt": "用这个代码登录",
+ "copy": "复制代码",
+ "copied": "已复制代码",
+ "copyFailed": "复制失败",
+ "open": "在本设备打开",
+ "openFailed": "无法打开链接",
+ "then": "在打开的页面输入代码并完成登录,然后点「交还给 Agent」。"
+ },
+ "sheetNote": "只会填进电脑上的这一处,不会交给 Agent,也不会保存。",
+ "nothingLeft": "这里没有需要你填写的了。",
+ "qr": {
+ "open": "在本机打开 {{site}}",
+ "openApp": "在本机打开 {{site}} 链接",
+ "share": "存图或分享",
+ "copyLink": "复制链接",
+ "copyText": "复制内容",
+ "copied": "已复制。",
+ "copyFailed": "没能复制,请重试。",
+ "openFailed": "这台设备打不开这个链接。可以存图后在 App 的「扫一扫」里从相册识别。",
+ "shareFailed": "没能打开分享,请重试。",
+ "hintLink": "在本机打开会唤起对应的 App 完成登录;也可以存图后在 App 的「扫一扫」里从相册识别。登录后会自动继续。",
+ "hint": "存图后在 App 的「扫一扫」里从相册识别,或用另一台设备扫这个码。登录后会自动继续。",
+ "alt": "电脑上的二维码。点按会点在电脑上的这个码上。",
+ "loading": "正在获取二维码…",
+ "failed": "没能取得二维码,点按重试。",
+ "scanned": "已扫码,等你在手机上确认。确认后会自动继续。"
+ }
+ },
"presentation": {
"action": {
"submitting": "提交中"
diff --git a/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.json b/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.json
index 1da705d125..e232d96600 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.json
@@ -160,5 +160,8 @@
"lockOnExitFailed": "未能确认电脑已锁屏,请检查电脑的锁屏状态。",
"hostMute": "远程电脑静音",
"hostMuteHint": "连接期间将远程电脑静音",
- "hostMuteFailed": "无法修改远程电脑的静音状态"
+ "hostMuteFailed": "无法修改远程电脑的静音状态",
+ "handoffEnded": "这次代输入已经结束,没有可显示的窗口。",
+ "handoffUnavailable": "这台电脑暂时不能只显示这个窗口。请在那台电脑上更新 Cindy,或开启远程桌面。",
+ "handoffWindow": "代输入 · {{app}}"
}
diff --git a/apps/mobile/src/i18n/locales/zh-TW/interaction.json b/apps/mobile/src/i18n/locales/zh-TW/interaction.json
index 1c082c73e9..088417aa1d 100644
--- a/apps/mobile/src/i18n/locales/zh-TW/interaction.json
+++ b/apps/mobile/src/i18n/locales/zh-TW/interaction.json
@@ -129,6 +129,10 @@
"fallback": {
"title": "需要處理遠端請求",
"label": "請求"
+ },
+ "input_handoff": {
+ "title": "需要你代為輸入",
+ "label": "代輸入"
}
},
"rewind": {
@@ -244,6 +248,129 @@
"inlineFormAction": "在電腦端填寫{{label}}",
"inlineFormActionGeneric": "在電腦端填寫一項配置"
},
+ "inputHandoff": {
+ "originWarning": {
+ "insecure": "這個頁面沒有使用安全連線,輸入的內容可能被他人讀取。",
+ "ip-address": "這個頁面使用 IP 位址而不是網域名稱,請確認它是你預期的網站。",
+ "local-host": "這個頁面來自本機服務,請確認它是你預期的程式。",
+ "local-file": "這個頁面是本機檔案,請確認它是你預期的內容。",
+ "punycode": "這個網址包含特殊字元,可能在冒充其他網站,請仔細核對。",
+ "embedded-frame": "輸入框位於嵌入的其他網站中,請確認來源可信。"
+ },
+ "agentControlled": "這個介面由 Agent 開啟。填寫前請確認它確實是你要登入的地方。",
+ "error": {
+ "decision": "操作沒有送達,請重試。",
+ "stale": "介面已經變化,請依最新內容操作。",
+ "submit": "輸入沒有送達,請重試。"
+ },
+ "terminal": {
+ "succeeded": "已交還給 Agent。",
+ "cancelled": "已取消代輸入。",
+ "failed": "代輸入已結束。",
+ "expired": "等待時間過長,代輸入已結束。"
+ },
+ "failure": {
+ "permission": "Cindy 沒有讀取這台電腦介面的權限。請在系統設定的輔助使用中允許 Cindy。",
+ "target_gone": "目標視窗已關閉。",
+ "unreadable": "無法讀取這個介面。可以在主機電腦上直接完成,然後交還給 Agent。",
+ "action_failed": "剛才的操作沒有生效,請檢查介面後重試。",
+ "timeout": "等待時間過長,代輸入已結束。",
+ "unsupported": "這台電腦暫不支援代輸入。",
+ "origin_changed": "填寫前頁面已變化,什麼都沒有填入。請確認現在的頁面後再填寫。",
+ "picture_unavailable": "無法顯示這一步的畫面。請在系統設定中允許 Cindy 錄製螢幕,並確認視窗沒有被縮到最小。",
+ "screen_locked": "這台電腦的螢幕已鎖定(顯示器休眠也會鎖定螢幕)。請先喚醒並解鎖,再讓 Agent 重試。",
+ "nothing_to_fill": "這個介面沒有需要你輸入的內容,已交還給 Agent 繼續。"
+ },
+ "phase": {
+ "reading": "正在讀取介面…",
+ "working": "正在填寫…",
+ "finishing": "看起來已經完成,{{count}} 秒後交還給 Agent。",
+ "finishingNow": "看起來已經完成,正在交還給 Agent…"
+ },
+ "action": {
+ "stay": "還沒完成",
+ "done": "交還給 Agent",
+ "cancel": "取消代輸入",
+ "claim": "改在這裡處理",
+ "picture": "看畫面",
+ "backToForm": "回到表單",
+ "liveView": "即時畫面",
+ "fill": "填寫",
+ "skip": "略過",
+ "continue": "繼續",
+ "close": "取消",
+ "showPassword": "顯示密碼",
+ "hidePassword": "隱藏密碼",
+ "scan": "掃碼"
+ },
+ "remoteUnavailable": "這台電腦無法從遠端接收輸入。請在主機電腦上完成這一步,再交還給 Agent。",
+ "unnamedField": "輸入框",
+ "passwordField": "密碼",
+ "codeField": "驗證碼",
+ "filledHint": "已有內容;留空則保持不變。",
+ "record": {
+ "doneOn_one": "主人在 {{device}} 完成了 {{count}} 步輸入",
+ "doneOn_other": "主人在 {{device}} 完成了 {{count}} 步輸入",
+ "doneHost_one": "主人在宿主電腦上完成了 {{count}} 步輸入",
+ "doneHost_other": "主人在宿主電腦上完成了 {{count}} 步輸入",
+ "donePhone_one": "主人在手機上完成了 {{count}} 步輸入",
+ "donePhone_other": "主人在手機上完成了 {{count}} 步輸入",
+ "doneElsewhere_one": "主人在另一台裝置上完成了 {{count}} 步輸入",
+ "doneElsewhere_other": "主人在另一台裝置上完成了 {{count}} 步輸入",
+ "done": "代輸入已完成",
+ "nothingToFill": "無需輸入,已交還給 Agent",
+ "cancelled": "代輸入已取消",
+ "expired": "代輸入已逾時",
+ "failed": "代輸入未完成"
+ },
+ "holder": {
+ "elsewhere": "正在 {{device}} 上處理,也可以改在這裡處理。",
+ "host": "宿主電腦",
+ "phone": "手機",
+ "otherDevice": "另一台裝置"
+ },
+ "agentNote": "Agent 補充:{{note}}",
+ "picture": {
+ "hint": "點按畫面中的位置,Cindy 會在主機電腦上點按同一個位置。",
+ "open": "顯示這一步的畫面",
+ "openHint": "這一步無法整理成表單。畫面只會加密傳送到這台裝置,不會保存。",
+ "alt": "目標視窗的畫面",
+ "loading": "正在取得畫面…",
+ "error": "無法取得畫面,請重試。",
+ "field": "目前的輸入框",
+ "type": "輸入",
+ "typeEnter": "輸入並按 Return"
+ },
+ "liveViewHint": "在這裡即時查看這一個視窗,點按和輸入只會進入這個視窗。",
+ "deviceCode": {
+ "prompt": "用這個代碼登入",
+ "copy": "複製代碼",
+ "copied": "已複製代碼",
+ "copyFailed": "複製失敗",
+ "open": "在本裝置開啟",
+ "openFailed": "無法開啟連結",
+ "then": "在開啟的頁面輸入代碼並完成登入,然後點「交還給 Agent」。"
+ },
+ "sheetNote": "只會填進電腦上的這一處,不會交給 Agent,也不會儲存。",
+ "nothingLeft": "這裡沒有需要你填寫的了。",
+ "qr": {
+ "open": "在本機打開 {{site}}",
+ "openApp": "在本機打開 {{site}} 連結",
+ "share": "存圖或分享",
+ "copyLink": "複製連結",
+ "copyText": "複製內容",
+ "copied": "已複製。",
+ "copyFailed": "無法複製,請重試。",
+ "openFailed": "這台裝置打不開這個連結。可以存圖後在 App 的「掃一掃」裡從相簿辨識。",
+ "shareFailed": "無法打開分享,請重試。",
+ "hintLink": "在本機打開會喚起對應的 App 完成登入;也可以存圖後在 App 的「掃一掃」裡從相簿辨識。登入後會自動繼續。",
+ "hint": "存圖後在 App 的「掃一掃」裡從相簿辨識,或用另一台裝置掃這個碼。登入後會自動繼續。",
+ "alt": "電腦上的 QR 碼。點按會點在電腦上的這個碼上。",
+ "loading": "正在取得 QR 碼…",
+ "failed": "無法取得 QR 碼,點按重試。",
+ "scanned": "已掃碼,等你在手機上確認。確認後會自動繼續。"
+ }
+ },
"presentation": {
"action": {
"submitting": "提交中"
diff --git a/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.json b/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.json
index f7f802d00d..6555f58ef9 100644
--- a/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.json
+++ b/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.json
@@ -160,5 +160,8 @@
"lockOnExitFailed": "無法確認電腦已鎖定螢幕,請檢查電腦狀態。",
"hostMute": "遠端電腦靜音",
"hostMuteHint": "連線期間將遠端電腦靜音",
- "hostMuteFailed": "無法修改遠端電腦的靜音狀態"
+ "hostMuteFailed": "無法修改遠端電腦的靜音狀態",
+ "handoffEnded": "這次代輸入已經結束,沒有可顯示的視窗。",
+ "handoffUnavailable": "這台電腦暫時無法只顯示這個視窗。請在那台電腦上更新 Cindy,或開啟遠端桌面。",
+ "handoffWindow": "代輸入 · {{app}}"
}
diff --git a/apps/mobile/src/inputHandoff/InputHandoffCard.tsx b/apps/mobile/src/inputHandoff/InputHandoffCard.tsx
new file mode 100644
index 0000000000..2790c3f212
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/InputHandoffCard.tsx
@@ -0,0 +1,434 @@
+/**
+ * 代输入 on the phone: a strip above the composer says where the computer
+ * needs the owner, and 填写 opens the native sheet with just the fields to
+ * type (system secure field + AutoFill hints so 1Password / Passwords can
+ * fill them). Typed values stay in this component and leave only through the
+ * sealed per-step channel.
+ */
+import { useEffect, useRef, useState } from "react";
+import { ActivityIndicator, Pressable, View, useWindowDimensions } from "react-native";
+import { AppWindow, Globe, Lock, QrCode, SquareTerminal } from "lucide-react-native";
+import { useTranslation } from "react-i18next";
+import type {
+ InputHandoffAction,
+ InputHandoffSnapshot,
+ InputHandoffValues,
+} from "@cindy/device-link";
+import {
+ inputHandoffHeldElsewhere,
+ inputHandoffStepKey,
+} from "@cindy/device-link";
+import { useAuth } from "@/auth/AuthContext";
+import { Text } from "@/components/AppText";
+import {
+ MainWindowActionButton,
+ MainWindowActionGroup,
+ type MainWindowAction,
+} from "@/components/MobilePrimitives";
+import { useRemoteDeviceIdentity } from "@/session/remoteSessionStore";
+import { iconSize, iconStroke, useTheme, useThemedStyles } from "@/theme";
+import { useGuardedPush } from "@/utils/useGuardedPush";
+import {
+ InputHandoffPictureStep,
+ rememberInputHandoffPictureOpened,
+} from "./InputHandoffPictureStep";
+import { InputHandoffDeviceCode } from "./InputHandoffDeviceCode";
+import { InputHandoffQrCode } from "./InputHandoffQrCode";
+import { InputHandoffSheet } from "./InputHandoffSheet";
+import { inputHandoffWarnings, type InputHandoffQrSheet } from "./inputHandoffSheetModel";
+import {
+ copyInputHandoffQr,
+ openInputHandoffQrLink,
+ shareInputHandoffQr,
+} from "./inputHandoffQrActions";
+import { useInputHandoffQr } from "./useInputHandoffQr";
+import { makeInputHandoffStyles } from "./inputHandoffStyles";
+import {
+ changedInputHandoffValues,
+ inputHandoffPlace,
+ inputHandoffPlaceKind,
+ inputHandoffSheetHasContent,
+} from "./inputHandoffNative";
+import { useInputHandoffSubmit } from "./useInputHandoffSubmit";
+
+type Decision = "done" | "cancel" | "stay" | "refresh" | "claim" | "picture";
+
+export function InputHandoffCard({
+ deviceId,
+ snapshot,
+ decisionBusy,
+ onDecision,
+ onQuietDecision,
+}: {
+ deviceId: string;
+ snapshot: InputHandoffSnapshot;
+ decisionBusy: boolean;
+ onDecision(decision: Record<string, unknown>): void;
+ /** Background decision that never marks the card busy (quiet claim). */
+ onQuietDecision?(decision: Record<string, unknown>): void;
+}) {
+ const { t } = useTranslation();
+ const styles = useThemedStyles(makeInputHandoffStyles);
+ const { colors } = useTheme();
+ const handoff = useInputHandoffSubmit(deviceId);
+ const selfDeviceId = useAuth().deviceId;
+ const heldElsewhere = inputHandoffHeldElsewhere(snapshot, {
+ deviceId: selfDeviceId,
+ });
+ const stepKey = inputHandoffStepKey(snapshot);
+ // Bumped when an answer clears the draft on the same screen, so native fields (which keep their own text) start empty too.
+ const [fieldEpoch, setFieldEpoch] = useState(0);
+ const started = useRef(false);
+ const [draft, setDraft] = useState<InputHandoffValues>({});
+ const [sending, setSending] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ // Stays wanted across steps: after Continue the sheet hides while the
+ // computer types and comes back by itself for the next screen to fill.
+ const [sheetWanted, setSheetWanted] = useState(false);
+ const push = useGuardedPush();
+ const devices = useRemoteDeviceIdentity();
+ // Every new screen starts from a clean draft; stale values are never reused.
+ // Holder changes on the same screen keep what the owner is typing.
+ useEffect(() => {
+ setDraft({});
+ setError(null);
+ started.current = false;
+ }, [stepKey]);
+ useEffect(() => {
+ if (snapshot.terminal) setSheetWanted(false);
+ }, [snapshot.terminal]);
+ const change = (id: string, value: string) => {
+ // Starting to type on an unheld screen takes the handoff quietly.
+ if (!started.current) {
+ started.current = true;
+ if (!snapshot.holder)
+ onQuietDecision?.({
+ kind: "input_handoff",
+ action: "claim",
+ expectedRevision: snapshot.revision,
+ });
+ }
+ setDraft((d) => ({ ...d, [id]: value }));
+ };
+
+ const busy = decisionBusy || sending;
+ const decide = (action: Decision) => {
+ if (action === "picture")
+ rememberInputHandoffPictureOpened(snapshot.requestId);
+ onDecision({
+ kind: "input_handoff",
+ action,
+ expectedRevision: snapshot.revision,
+ });
+ };
+ const submit = async (action: InputHandoffAction) => {
+ if (busy || snapshot.remoteInput !== true) return;
+ setSending(true);
+ setError(null);
+ const values = changedInputHandoffValues(snapshot, draft);
+ try {
+ await handoff.submit(snapshot, {
+ expectedRevision: snapshot.revision,
+ values,
+ action,
+ });
+ setDraft({});
+ setFieldEpoch((n) => n + 1);
+ } catch (e) {
+ setError(
+ e instanceof Error && e.message === "INPUT_HANDOFF_STALE"
+ ? t("interaction.inputHandoff.error.stale")
+ : t("interaction.inputHandoff.error.submit"),
+ );
+ } finally {
+ setSending(false);
+ }
+ };
+
+ const sheetContent = inputHandoffSheetHasContent(snapshot, heldElsewhere);
+ // Scan-to-sign-in: the code arrives sealed while the sheet is open, and follows refreshes by itself.
+ const qrScan = snapshot.qr === "scan" && snapshot.picture === true;
+ const [qrNotice, setQrNotice] = useState<string | null>(null);
+ const qrView = useInputHandoffQr({
+ snapshot,
+ active: sheetWanted && sheetContent && qrScan,
+ openPicture: handoff.openPicture,
+ onError: (kind) => setError(kind ? t(`interaction.inputHandoff.error.${kind}`) : null),
+ });
+ useEffect(() => setQrNotice(null), [snapshot.revision]);
+ // Large enough to scan from another screen, inside the sheet's margins.
+ const qrSide = Math.min(260, useWindowDimensions().width - 96);
+ const qrSheet: InputHandoffQrSheet | null = qrScan
+ ? {
+ view: qrView,
+ notice: qrNotice,
+ onOpen: () => {
+ const qr = qrView.picture?.qr;
+ if (qr)
+ void openInputHandoffQrLink(qr).then((ok) => {
+ if (!ok) setQrNotice(t("interaction.inputHandoff.qr.openFailed"));
+ });
+ },
+ onShare: () => {
+ const picture = qrView.picture;
+ if (picture)
+ void shareInputHandoffQr(picture).then((ok) => {
+ if (!ok) setQrNotice(t("interaction.inputHandoff.qr.shareFailed"));
+ });
+ },
+ onCopy: () => {
+ const qr = qrView.picture?.qr;
+ if (qr)
+ void copyInputHandoffQr(qr).then((ok) =>
+ setQrNotice(t(ok ? "interaction.inputHandoff.qr.copied" : "interaction.inputHandoff.qr.copyFailed")),
+ );
+ },
+ }
+ : null;
+ // A live view of just the target window on the computer running the task.
+ // Navigation only: the computer picks the window from the request id.
+ const openLiveView =
+ snapshot.liveView && !snapshot.terminal
+ ? () => {
+ setSheetWanted(false);
+ push({
+ pathname: "/devices/desktop/[deviceId]",
+ params: {
+ deviceId,
+ deviceName:
+ devices.find((device) => device.deviceId === deviceId)?.name ||
+ deviceId,
+ handoff: snapshot.requestId,
+ },
+ });
+ }
+ : undefined;
+ const skip: MainWindowAction = {
+ label: t("interaction.inputHandoff.action.skip"),
+ disabled: busy,
+ tone: "secondary",
+ testID: "interaction.inputHandoff.skip",
+ onPress: () => decide("cancel"),
+ };
+ const handBack: MainWindowAction = {
+ label: t("interaction.inputHandoff.action.done"),
+ disabled: busy,
+ tone: "primary",
+ onPress: () => decide("done"),
+ };
+
+ // Inline actions sit on the strip's row; a status line moves them below it.
+ let status: string | null = null;
+ let spinner = false;
+ let actions: MainWindowAction[] = [];
+ if (snapshot.terminal) {
+ status = t(
+ (snapshot.phase === "failed" ||
+ snapshot.failure === "nothing_to_fill") &&
+ snapshot.failure
+ ? `interaction.inputHandoff.failure.${snapshot.failure}`
+ : `interaction.inputHandoff.terminal.${snapshot.phase}`,
+ );
+ } else if (snapshot.phase === "ready" && heldElsewhere) {
+ status = t("interaction.inputHandoff.holder.elsewhere", {
+ device: holderLabel(snapshot, t),
+ });
+ actions = [
+ skip,
+ {
+ label: t("interaction.inputHandoff.action.claim"),
+ disabled: busy,
+ tone: "primary",
+ onPress: () => {
+ setSheetWanted(true);
+ decide("claim");
+ },
+ },
+ ];
+ } else if (snapshot.phase === "ready" && snapshot.qr === "scanned") {
+ // The code was scanned; the sign-in finishes on the phone that scanned it.
+ spinner = true;
+ status = t("interaction.inputHandoff.qr.scanned");
+ actions = [skip, handBack];
+ } else if (snapshot.phase === "ready" && sheetContent) {
+ actions = [
+ skip,
+ {
+ label: t(qrScan ? "interaction.inputHandoff.action.scan" : "interaction.inputHandoff.action.fill"),
+ disabled: busy,
+ tone: "primary",
+ testID: "interaction.inputHandoff.fill",
+ onPress: () => setSheetWanted(true),
+ },
+ ];
+ } else if (snapshot.phase === "ready") {
+ // Nothing left to type here (the owner stayed on, or an action did not take).
+ status =
+ inputHandoffWarnings(snapshot, t)[0] ??
+ t("interaction.inputHandoff.nothingLeft");
+ actions = [skip, handBack];
+ } else if (snapshot.phase === "finishing") {
+ actions = [
+ {
+ label: t("interaction.inputHandoff.action.stay"),
+ disabled: busy,
+ tone: "secondary",
+ onPress: () => decide("stay"),
+ },
+ handBack,
+ ];
+ } else {
+ spinner = true;
+ status = t(
+ snapshot.phase === "working"
+ ? "interaction.inputHandoff.phase.working"
+ : "interaction.inputHandoff.phase.reading",
+ );
+ actions = [skip];
+ }
+ const below = Boolean(status) || snapshot.phase === "finishing";
+
+ const place = inputHandoffPlace(snapshot.source);
+ const kind = inputHandoffPlaceKind(snapshot);
+ const Icon = snapshot.qr
+ ? QrCode
+ : kind === "web"
+ ? Globe
+ : kind === "terminal"
+ ? SquareTerminal
+ : AppWindow;
+ return (
+ <View style={styles.strip} testID="interaction.inputHandoff.strip">
+ <View style={styles.stripRow}>
+ <View style={styles.stripIcon}>
+ <Icon
+ color={colors.textPrimary}
+ size={iconSize.lg}
+ strokeWidth={iconStroke.regular}
+ />
+ </View>
+ <View style={styles.stripText}>
+ <Text numberOfLines={2} style={styles.label}>
+ {snapshot.purpose}
+ </Text>
+ <View style={styles.place}>
+ {place.secure ? (
+ <Lock
+ color={colors.textSecondary}
+ size={iconSize.xs}
+ strokeWidth={iconStroke.regular}
+ />
+ ) : null}
+ <Text numberOfLines={1} style={styles.placeText}>
+ {place.label}
+ </Text>
+ </View>
+ </View>
+ {actions.length > 0 && !below ? (
+ <View style={styles.stripActions}>
+ {actions.map((action) => (
+ <MainWindowActionButton
+ key={action.label}
+ density="compact"
+ action={action}
+ />
+ ))}
+ </View>
+ ) : null}
+ </View>
+ {snapshot.phase === "finishing" ? (
+ <FinishingText until={snapshot.finishingUntil} style={styles.body} />
+ ) : null}
+ {status ? (
+ <View style={styles.stripStatus}>
+ {spinner ? <ActivityIndicator color={colors.textSecondary} /> : null}
+ <Text style={[styles.body, styles.stripStatusText]}>{status}</Text>
+ </View>
+ ) : null}
+ {error && !sheetWanted ? <Text style={styles.error}>{error}</Text> : null}
+ {actions.length > 0 && below ? (
+ <MainWindowActionGroup density="compact" primaryActions={actions} />
+ ) : null}
+ {openLiveView && !sheetContent ? (
+ <Pressable
+ accessibilityRole="button"
+ onPress={openLiveView}
+ style={styles.quietLink}
+ testID="interaction.inputHandoff.liveView"
+ >
+ <Text style={styles.meta}>
+ {t("interaction.inputHandoff.action.liveView")}
+ </Text>
+ </Pressable>
+ ) : null}
+ <InputHandoffSheet
+ visible={sheetWanted && sheetContent}
+ snapshot={snapshot}
+ stepKey={`${stepKey}#${fieldEpoch}`}
+ draft={draft}
+ busy={busy}
+ error={error}
+ qr={qrSheet}
+ embedded={
+ // Mounted only while the sheet shows: a hidden SwiftUI sheet still renders its children.
+ !(sheetWanted && sheetContent) ? null : qrScan ? (
+ <InputHandoffQrCode view={qrView} side={qrSide} />
+ ) : snapshot.picture ? (
+ // One screenshot per revision; no quiet claim here (it would bump the revision).
+ <InputHandoffPictureStep
+ key={`${snapshot.requestId}:${snapshot.revision}`}
+ snapshot={snapshot}
+ busy={busy}
+ openPicture={handoff.openPicture}
+ onDecide={decide}
+ onError={setError}
+ />
+ ) : (
+ <InputHandoffDeviceCode snapshot={snapshot} />
+ )
+ }
+ onChange={change}
+ onSubmit={() => void submit({ kind: "submit" })}
+ onDone={() => {
+ setSheetWanted(false);
+ decide("done");
+ }}
+ onPicture={() => decide("picture")}
+ onLiveView={openLiveView}
+ onClose={() => setSheetWanted(false)}
+ />
+ </View>
+ );
+}
+
+function holderLabel(
+ snapshot: InputHandoffSnapshot,
+ t: (key: string) => string,
+): string {
+ const holder = snapshot.holder;
+ if (holder?.local) return t("interaction.inputHandoff.holder.host");
+ if (holder?.name) return holder.name;
+ return t(
+ holder?.platform === "mobile"
+ ? "interaction.inputHandoff.holder.phone"
+ : "interaction.inputHandoff.holder.otherDevice",
+ );
+}
+
+function FinishingText({ until, style }: { until?: number; style: object }) {
+ const { t } = useTranslation();
+ const [now, setNow] = useState(() => Date.now());
+ useEffect(() => {
+ if (!until) return;
+ const timer = setInterval(() => setNow(Date.now()), 250);
+ return () => clearInterval(timer);
+ }, [until]);
+ const seconds = until ? Math.max(0, Math.ceil((until - now) / 1000)) : 0;
+ return (
+ <Text style={style}>
+ {until
+ ? t("interaction.inputHandoff.phase.finishing", { count: seconds })
+ : t("interaction.inputHandoff.phase.finishingNow")}
+ </Text>
+ );
+}
diff --git a/apps/mobile/src/inputHandoff/InputHandoffDeviceCode.tsx b/apps/mobile/src/inputHandoff/InputHandoffDeviceCode.tsx
new file mode 100644
index 0000000000..bf71c3407b
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/InputHandoffDeviceCode.tsx
@@ -0,0 +1,75 @@
+/**
+ * Device-code sign-in on the phone: the screen only shows a code and a link.
+ * The owner copies the code and opens the link here, where their browser is
+ * already signed in; nothing is typed into the window. The link is checked
+ * again (https, shown origin) before it is opened.
+ */
+import { useState } from "react";
+import { Linking, View } from "react-native";
+import * as Clipboard from "expo-clipboard";
+import { useTranslation } from "react-i18next";
+import {
+ isInputHandoffDeviceCode,
+ type InputHandoffSnapshot,
+} from "@cindy/device-link";
+import { Text } from "@/components/AppText";
+import { MainWindowActionGroup } from "@/components/MobilePrimitives";
+import { useThemedStyles } from "@/theme";
+import { makeInputHandoffStyles } from "./inputHandoffStyles";
+
+type Status = "copied" | "copyFailed" | "openFailed" | null;
+
+export function InputHandoffDeviceCode({
+ snapshot,
+}: {
+ snapshot: InputHandoffSnapshot;
+}) {
+ const { t } = useTranslation();
+ const styles = useThemedStyles(makeInputHandoffStyles);
+ const [status, setStatus] = useState<Status>(null);
+ const deviceCode = snapshot.deviceCode;
+ if (!isInputHandoffDeviceCode(deviceCode)) return null;
+ return (
+ <View
+ style={styles.deviceCode}
+ testID="interaction.inputHandoff.deviceCode"
+ >
+ <Text style={styles.note}>
+ {t("interaction.inputHandoff.deviceCode.prompt")}
+ </Text>
+ <Text style={styles.deviceCodeText} selectable>
+ {deviceCode.code}
+ </Text>
+ <Text style={styles.mono}>{deviceCode.origin}</Text>
+ <MainWindowActionGroup
+ density="compact"
+ primaryActions={[
+ {
+ label: t("interaction.inputHandoff.deviceCode.copy"),
+ tone: "secondary",
+ testID: "interaction.inputHandoff.deviceCode.copy",
+ onPress: () =>
+ void Clipboard.setStringAsync(deviceCode.code)
+ .then(() => setStatus("copied"))
+ .catch(() => setStatus("copyFailed")),
+ },
+ {
+ label: t("interaction.inputHandoff.deviceCode.open"),
+ tone: "secondary",
+ testID: "interaction.inputHandoff.deviceCode.open",
+ onPress: () =>
+ void Linking.openURL(deviceCode.url).then(
+ () => setStatus(null),
+ () => setStatus("openFailed"),
+ ),
+ },
+ ]}
+ />
+ <Text style={styles.note}>
+ {status
+ ? t(`interaction.inputHandoff.deviceCode.${status}`)
+ : t("interaction.inputHandoff.deviceCode.then")}
+ </Text>
+ </View>
+ );
+}
diff --git a/apps/mobile/src/inputHandoff/InputHandoffPictureStep.tsx b/apps/mobile/src/inputHandoff/InputHandoffPictureStep.tsx
new file mode 100644
index 0000000000..03fbe62bc2
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/InputHandoffPictureStep.tsx
@@ -0,0 +1,244 @@
+/**
+ * 代输入 step answered on a screenshot of the target window. The picture
+ * arrives only inside the sealed per-step offer and lives in this component's
+ * state for one revision; the owner's tap (as a fraction of the picture) or
+ * typing goes back on the same exchange.
+ */
+import { useEffect, useRef, useState } from "react";
+import {
+ ActivityIndicator,
+ Image,
+ Pressable,
+ View,
+ type GestureResponderEvent,
+ type LayoutChangeEvent,
+} from "react-native";
+import { useTranslation } from "react-i18next";
+import {
+ INPUT_HANDOFF_PICTURE_TEXT_ID,
+ type InputHandoffAction,
+ type InputHandoffControl,
+ type InputHandoffPicture,
+ type InputHandoffSnapshot,
+ type InputHandoffSubmission,
+} from "@cindy/device-link";
+import { Text, TextInput } from "@/components/AppText";
+import { MainWindowActionGroup } from "@/components/MobilePrimitives";
+import { useTheme, useThemedStyles } from "@/theme";
+import { makeInputHandoffStyles } from "./inputHandoffStyles";
+import { nativeTextInputProps } from "./inputHandoffNative";
+
+/** Requests whose picture the owner opened on this phone; later steps open by themselves. Ids only. */
+const openedHere = new Set<string>();
+
+/** The owner asked for the picture on this phone: show it without another tap. */
+export function rememberInputHandoffPictureOpened(requestId: string): void {
+ if (openedHere.size > 64) openedHere.clear();
+ openedHere.add(requestId);
+}
+
+type Decision = "done" | "cancel" | "refresh";
+
+export function InputHandoffPictureStep({
+ snapshot,
+ busy,
+ openPicture,
+ onDecide,
+ onError,
+}: {
+ snapshot: InputHandoffSnapshot;
+ busy: boolean;
+ openPicture(
+ snapshot: InputHandoffSnapshot,
+ answer: (picture: InputHandoffPicture) => Promise<InputHandoffSubmission>,
+ ): Promise<void>;
+ onDecide(action: Decision): void;
+ onError(message: string | null): void;
+}) {
+ const { t } = useTranslation();
+ const styles = useThemedStyles(makeInputHandoffStyles);
+ const { colors } = useTheme();
+ const [state, setState] = useState<"idle" | "loading" | "shown" | "sending" | "failed">("idle");
+ const [picture, setPicture] = useState<InputHandoffPicture | null>(null);
+ const [typed, setTyped] = useState("");
+ const size = useRef({ width: 0, height: 0 });
+ const mounted = useRef(true);
+ const pending = useRef<{
+ resolve(submission: InputHandoffSubmission): void;
+ reject(error: Error): void;
+ } | null>(null);
+ const field = snapshot.controls.find(
+ (c): c is Extract<InputHandoffControl, { kind: "text" }> =>
+ c.kind === "text" && c.id === INPUT_HANDOFF_PICTURE_TEXT_ID,
+ );
+ const blocked = snapshot.remoteInput !== true;
+ const disabled = busy || blocked || state !== "shown";
+
+ const load = () => {
+ setState("loading");
+ onError(null);
+ let answered = false;
+ openPicture(snapshot, (p) =>
+ new Promise<InputHandoffSubmission>((resolve, reject) => {
+ pending.current = {
+ resolve: (submission) => {
+ answered = true;
+ resolve(submission);
+ },
+ reject,
+ };
+ setPicture(p);
+ setState("shown");
+ }),
+ )
+ .then(() => {
+ if (!mounted.current) return;
+ setTyped("");
+ setState("sending");
+ })
+ .catch((e: unknown) => {
+ if (!mounted.current) return;
+ pending.current = null;
+ setPicture(null);
+ if (answered)
+ onError(
+ e instanceof Error && e.message === "INPUT_HANDOFF_STALE"
+ ? t("interaction.inputHandoff.error.stale")
+ : t("interaction.inputHandoff.error.submit"),
+ );
+ setState(answered ? "idle" : "failed");
+ });
+ };
+
+ // One picture per revision: the card remounts this step for every new one.
+ useEffect(() => {
+ mounted.current = true;
+ if (!blocked && openedHere.has(snapshot.requestId)) load();
+ return () => {
+ mounted.current = false;
+ pending.current?.reject(new Error("INPUT_HANDOFF_CLOSED"));
+ pending.current = null;
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- mounted once per revision
+ }, []);
+
+ const answer = (action: InputHandoffAction, values: Record<string, string> = {}) => {
+ const reply = pending.current;
+ if (!reply || disabled) return;
+ pending.current = null;
+ setState("sending");
+ reply.resolve({ expectedRevision: snapshot.revision, values, action });
+ };
+
+ const tap = (event: GestureResponderEvent) => {
+ const { width, height } = size.current;
+ if (width <= 0 || height <= 0) return;
+ const clamp = (n: number) => Math.min(1, Math.max(0, n));
+ answer({
+ kind: "tap",
+ x: clamp(event.nativeEvent.locationX / width),
+ y: clamp(event.nativeEvent.locationY / height),
+ });
+ };
+
+ const type = (submit: boolean) => {
+ if (!field || (!submit && !typed)) return;
+ answer({ kind: submit ? "submit" : "fill" }, typed ? { [field.id]: typed } : {});
+ };
+
+ const fieldLabel =
+ field?.contentType === "password"
+ ? t("interaction.inputHandoff.passwordField")
+ : t("interaction.inputHandoff.picture.field");
+
+ return (
+ <View style={styles.stack}>
+ {blocked ? (
+ <Text style={styles.note}>{t("interaction.inputHandoff.remoteUnavailable")}</Text>
+ ) : null}
+ {picture && (state === "shown" || state === "sending") ? (
+ <>
+ <Text style={styles.note}>{t("interaction.inputHandoff.picture.hint")}</Text>
+ <Pressable
+ accessibilityRole="imagebutton"
+ accessibilityLabel={t("interaction.inputHandoff.picture.alt")}
+ accessibilityState={{ disabled }}
+ disabled={disabled}
+ onPress={tap}
+ onLayout={(e: LayoutChangeEvent) => {
+ size.current = e.nativeEvent.layout;
+ }}
+ style={[styles.picture, { aspectRatio: picture.width / picture.height }, disabled && styles.pictureDisabled]}
+ >
+ <Image
+ source={{ uri: `data:${picture.mime};base64,${picture.data}` }}
+ resizeMode="stretch"
+ style={styles.pictureImage}
+ accessibilityIgnoresInvertColors
+ />
+ </Pressable>
+ {field ? (
+ <View style={styles.field}>
+ <Text style={styles.label}>{fieldLabel}</Text>
+ <TextInput
+ accessibilityLabel={fieldLabel}
+ value={typed}
+ onChangeText={setTyped}
+ placeholderTextColor={colors.textPlaceholder}
+ autoCapitalize="none"
+ autoCorrect={false}
+ spellCheck={false}
+ editable={!disabled}
+ returnKeyType="done"
+ onSubmitEditing={() => type(true)}
+ style={styles.input}
+ {...nativeTextInputProps(field.contentType)}
+ />
+ </View>
+ ) : null}
+ </>
+ ) : state === "loading" || state === "sending" ? (
+ <View style={styles.row}>
+ <ActivityIndicator color={colors.textSecondary} />
+ <Text style={styles.body}>
+ {t(state === "loading" ? "interaction.inputHandoff.picture.loading" : "interaction.inputHandoff.phase.working")}
+ </Text>
+ </View>
+ ) : (
+ <Text style={styles.body}>
+ {t(state === "failed" ? "interaction.inputHandoff.picture.error" : "interaction.inputHandoff.picture.openHint")}
+ </Text>
+ )}
+ <MainWindowActionGroup
+ density="compact"
+ cancelAction={{ label: t("interaction.inputHandoff.action.cancel"), disabled: busy, onPress: () => onDecide("cancel") }}
+ secondaryActions={[
+ { label: t("interaction.inputHandoff.action.backToForm"), disabled: busy, tone: "secondary", onPress: () => onDecide("refresh") },
+ { label: t("interaction.inputHandoff.action.done"), disabled: busy, tone: "secondary", onPress: () => onDecide("done") },
+ ]}
+ primaryActions={
+ picture && state === "shown"
+ ? field
+ ? [
+ { label: t("interaction.inputHandoff.picture.type"), disabled: disabled || !typed, tone: "secondary", onPress: () => type(false) },
+ { label: t("interaction.inputHandoff.picture.typeEnter"), disabled, tone: "primary", onPress: () => type(true) },
+ ]
+ : []
+ : state === "idle" || state === "failed"
+ ? [
+ {
+ label: t("interaction.inputHandoff.picture.open"),
+ disabled: busy || blocked,
+ tone: "primary",
+ onPress: () => {
+ rememberInputHandoffPictureOpened(snapshot.requestId);
+ load();
+ },
+ },
+ ]
+ : []
+ }
+ />
+ </View>
+ );
+}
diff --git a/apps/mobile/src/inputHandoff/InputHandoffQrCode.tsx b/apps/mobile/src/inputHandoff/InputHandoffQrCode.tsx
new file mode 100644
index 0000000000..1b65dc76c8
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/InputHandoffQrCode.tsx
@@ -0,0 +1,64 @@
+/**
+ * The QR code from the computer, large and square on the 代输入 sheet. A tap
+ * taps the same place on the code in the window (for example "tap to
+ * refresh" on an expired code). The image is the computer's own pixels.
+ */
+import { useRef } from "react";
+import { ActivityIndicator, Image, Pressable, View, type LayoutChangeEvent } from "react-native";
+import { useTranslation } from "react-i18next";
+import { Text } from "@/components/AppText";
+import { useTheme, useThemedStyles } from "@/theme";
+import { makeInputHandoffStyles } from "./inputHandoffStyles";
+import type { InputHandoffQrView } from "./useInputHandoffQr";
+
+export function InputHandoffQrCode({ view, side }: { view: InputHandoffQrView; side: number }) {
+ const { t } = useTranslation();
+ const styles = useThemedStyles(makeInputHandoffStyles);
+ const { colors } = useTheme();
+ const layout = useRef({ width: 0, height: 0 });
+ const box = { width: side, height: side };
+ const { picture, state } = view;
+ if (picture && (state === "shown" || state === "sending")) {
+ return (
+ <View style={styles.qrWrap}>
+ <Pressable
+ accessibilityRole="imagebutton"
+ accessibilityLabel={t("interaction.inputHandoff.qr.alt")}
+ disabled={state !== "shown"}
+ testID="interaction.inputHandoff.qr.code"
+ onLayout={(e: LayoutChangeEvent) => {
+ layout.current = e.nativeEvent.layout;
+ }}
+ onPress={(event) => {
+ const { width, height } = layout.current;
+ if (width > 0 && height > 0) view.tap(event.nativeEvent.locationX / width, event.nativeEvent.locationY / height);
+ }}
+ style={[styles.qrCode, box, state !== "shown" && styles.pictureDisabled]}
+ >
+ <Image
+ source={{ uri: `data:${picture.mime};base64,${picture.data}` }}
+ resizeMode="contain"
+ style={styles.pictureImage}
+ accessibilityIgnoresInvertColors
+ />
+ </Pressable>
+ </View>
+ );
+ }
+ return (
+ <View style={styles.qrWrap}>
+ <View style={[styles.qrPlaceholder, box]}>
+ {state === "failed" ? (
+ <Pressable accessibilityRole="button" onPress={view.load} style={styles.quietLink} testID="interaction.inputHandoff.qr.retry">
+ <Text style={[styles.body, styles.centered]}>{t("interaction.inputHandoff.qr.failed")}</Text>
+ </Pressable>
+ ) : (
+ <>
+ <ActivityIndicator color={colors.textSecondary} />
+ <Text style={styles.meta}>{t("interaction.inputHandoff.qr.loading")}</Text>
+ </>
+ )}
+ </View>
+ </View>
+ );
+}
diff --git a/apps/mobile/src/inputHandoff/InputHandoffRecordRow.tsx b/apps/mobile/src/inputHandoff/InputHandoffRecordRow.tsx
new file mode 100644
index 0000000000..65e41cc421
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/InputHandoffRecordRow.tsx
@@ -0,0 +1,98 @@
+/**
+ * The one visible trace a 代输入 leaves in the task (matches Desktop): who
+ * finished how many steps, where, and when. Never values or screen text.
+ */
+import { StyleSheet, View } from "react-native";
+import { KeyRound } from "lucide-react-native";
+import { useTranslation } from "react-i18next";
+import {
+ inputHandoffRecordHost,
+ inputHandoffRecordMessage,
+ type InputHandoffEndRecord,
+} from "@cindy/maker-shared/synthetic-trigger";
+import { Text } from "@/components/AppText";
+import {
+ fontWeight,
+ iconSize,
+ iconStroke,
+ lineHeight,
+ radius,
+ spacing,
+ typeScale,
+ useTheme,
+ useThemedStyles,
+ type ThemeColors,
+} from "@/theme";
+
+export function InputHandoffRecordRow({ data }: { data?: Record<string, unknown> }) {
+ const { t, i18n } = useTranslation();
+ const styles = useThemedStyles(makeStyles);
+ const { colors } = useTheme();
+ const record = readRecord(data);
+ if (!record) return null;
+ const message = inputHandoffRecordMessage(record);
+ const at = typeof data?.at === "string" ? new Date(data.at) : null;
+ const time =
+ at && !Number.isNaN(at.getTime())
+ ? at.toLocaleTimeString(i18n.language, { hour: "2-digit", minute: "2-digit" })
+ : undefined;
+ const text = [
+ t(`interaction.inputHandoff.record.${message.key}`, message.params),
+ inputHandoffRecordHost(record.origin),
+ time,
+ ]
+ .filter(Boolean)
+ .join(" · ");
+ return (
+ <View style={styles.row} accessibilityLabel={text} testID="message.systemCard.input-handoff">
+ <View style={styles.divider} />
+ <View style={styles.pill}>
+ <KeyRound color={colors.textTertiary} size={iconSize.xs} strokeWidth={iconStroke.regular} />
+ <Text style={styles.text} numberOfLines={1}>
+ {text}
+ </Text>
+ </View>
+ <View style={styles.divider} />
+ </View>
+ );
+}
+
+function readRecord(data?: Record<string, unknown>): InputHandoffEndRecord | null {
+ if (!data) return null;
+ if (!["succeeded", "cancelled", "failed", "expired"].includes(String(data.status))) return null;
+ if (typeof data.steps !== "number" || !Number.isSafeInteger(data.steps) || data.steps < 0) return null;
+ return data as unknown as InputHandoffEndRecord;
+}
+
+const makeStyles = (colors: ThemeColors) =>
+ StyleSheet.create({
+ row: {
+ alignItems: "center",
+ flexDirection: "row",
+ gap: spacing.md,
+ paddingVertical: spacing.sm,
+ },
+ divider: {
+ backgroundColor: colors.border,
+ flex: 1,
+ height: StyleSheet.hairlineWidth,
+ },
+ pill: {
+ alignItems: "center",
+ borderColor: colors.border,
+ borderRadius: radius.pill,
+ borderWidth: StyleSheet.hairlineWidth,
+ flexDirection: "row",
+ flexShrink: 1,
+ gap: spacing.xs,
+ paddingHorizontal: spacing.sm,
+ paddingVertical: spacing.xs,
+ },
+ text: {
+ color: colors.textSecondary,
+ flexShrink: 1,
+ fontSize: typeScale.micro,
+ lineHeight: lineHeight.micro,
+ fontWeight: fontWeight.medium,
+ },
+ });
diff --git a/apps/mobile/src/inputHandoff/InputHandoffSheet.ios.tsx b/apps/mobile/src/inputHandoff/InputHandoffSheet.ios.tsx
new file mode 100644
index 0000000000..bd1c790ae6
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/InputHandoffSheet.ios.tsx
@@ -0,0 +1,445 @@
+/**
+ * The 代输入 form on iOS: a native SwiftUI sheet sized to its content, with
+ * system text and secure fields. Their content types let AutoFill, Passwords
+ * and 1Password offer the right item; the eye only swaps the field kind and
+ * keeps the typed text in native state. Values reach this component through
+ * change events and leave only through the card's sealed per-step channel.
+ */
+import { useRef, useState, type ReactNode } from "react";
+import { View, useWindowDimensions } from "react-native";
+import { useTranslation } from "react-i18next";
+import { Host } from "@expo/ui";
+import {
+ BottomSheet,
+ Button,
+ Group,
+ HStack,
+ Image,
+ RNHostView,
+ SecureField,
+ Spacer,
+ Text,
+ TextField,
+ VStack,
+ useNativeState,
+ type SecureFieldRef,
+ type TextFieldRef,
+} from "@expo/ui/swift-ui";
+import {
+ accessibilityLabel,
+ autocorrectionDisabled,
+ background,
+ buttonStyle,
+ contentShape,
+ disabled as disabledModifier,
+ fixedSize,
+ font,
+ foregroundStyle,
+ frame,
+ keyboardType,
+ lineLimit,
+ multilineTextAlignment,
+ onSubmit,
+ padding,
+ presentationDragIndicator,
+ shapes,
+ strokeBorder,
+ submitLabel,
+ textContentType,
+ textInputAutocapitalization,
+} from "@expo/ui/swift-ui/modifiers";
+import type { InputHandoffSnapshot } from "@cindy/device-link";
+import { iconSize, radius, spacing, useTheme } from "@/theme";
+import {
+ inputHandoffSheetMode,
+ inputHandoffWarnings,
+ type InputHandoffQrSheet,
+ type InputHandoffSheetProps,
+} from "./inputHandoffSheetModel";
+import { inputHandoffFieldLabel } from "./InputHandoffStepFields";
+import {
+ inputHandoffPlace,
+ inputHandoffPlaceKind,
+ inputHandoffTextFields,
+ swiftFieldTraits,
+ type InputHandoffTextControl,
+} from "./inputHandoffNative";
+
+const SIDE = 24;
+
+/** Fields, the icon tile and the command sit on the sheet like its action rows: filled and outlined in both modes. */
+const sheetRow = (colors: { sheetActionSurface: string; sheetActionBorder: string }, cornerRadius: number) => [
+ background(colors.sheetActionSurface, shapes.roundedRectangle({ cornerRadius, roundedCornerStyle: "continuous" })),
+ strokeBorder({ color: colors.sheetActionBorder, shape: "roundedRectangle", cornerRadius, style: { lineWidth: 1 } }),
+];
+const FIELD_HEIGHT = 50;
+const BUTTON_HEIGHT = 52;
+
+export function InputHandoffSheet(props: InputHandoffSheetProps) {
+ const { visible, snapshot, busy, error, embedded, onClose } = props;
+ const { t } = useTranslation();
+ const { mode: scheme, colors } = useTheme();
+ const mode = inputHandoffSheetMode(snapshot);
+ const remote = snapshot.remoteInput === true;
+ const fieldsDisabled = busy || !remote;
+ const fields = inputHandoffTextFields(snapshot);
+ const focusers = useRef(new Map<string, () => void>());
+ const focusAfter = (id: string) => {
+ const next = fields[fields.findIndex((f) => f.id === id) + 1];
+ if (next) focusers.current.get(next.id)?.();
+ else if (!fieldsDisabled) props.onSubmit();
+ };
+ const primary =
+ mode === "picture" || mode === "qr"
+ ? null
+ : {
+ label: t(mode === "code" ? "interaction.inputHandoff.action.done" : "interaction.inputHandoff.action.continue"),
+ disabled: busy || (mode === "fields" && !remote),
+ onPress: mode === "code" ? props.onDone : props.onSubmit,
+ };
+ // A QR step shows just the code; the whole window stays one tap away.
+ const quietPicture = !snapshot.command && (!snapshot.picture || mode === "qr");
+ return (
+ <Host colorScheme={scheme} seedColor={colors.textPrimary} pointerEvents="none" style={{ position: "absolute" }}>
+ <BottomSheet
+ isPresented={visible}
+ fitToContents
+ onIsPresentedChange={(open) => {
+ if (!open && visible) onClose();
+ }}
+ >
+ <Group modifiers={[presentationDragIndicator("visible")]}>
+ <VStack spacing={spacing.lg} modifiers={[padding({ top: 28, leading: SIDE, trailing: SIDE, bottom: spacing.md })]}>
+ <SheetHeader snapshot={snapshot} />
+ {mode !== "fields" ? (
+ <Embedded>{embedded}</Embedded>
+ ) : (
+ <>
+ {embedded ? <Embedded>{embedded}</Embedded> : null}
+ <VStack spacing={spacing.md} alignment="leading">
+ {snapshot.controls.map((control) =>
+ control.kind === "note" ? (
+ <HStack key={control.id} spacing={6} alignment="top">
+ <Image systemName="exclamationmark.circle.fill" size={iconSize.sm} color={colors.statusError} />
+ <Text modifiers={[font({ textStyle: "footnote" }), foregroundStyle(colors.errorText), frame({ maxWidth: Infinity, alignment: "leading" })]}>
+ {control.text}
+ </Text>
+ </HStack>
+ ) : (
+ <SheetField
+ key={`${props.stepKey}:${control.id}`}
+ control={control}
+ label={inputHandoffFieldLabel(control, t)}
+ last={fields[fields.length - 1]?.id === control.id}
+ disabled={fieldsDisabled}
+ onChange={(value) => props.onChange(control.id, value)}
+ onReturn={() => focusAfter(control.id)}
+ registerFocus={(focus) => {
+ if (focus) focusers.current.set(control.id, focus);
+ else focusers.current.delete(control.id);
+ }}
+ />
+ ),
+ )}
+ </VStack>
+ </>
+ )}
+ {error ? (
+ <Text modifiers={[font({ textStyle: "footnote" }), foregroundStyle(colors.errorText), multilineTextAlignment("center"), frame({ maxWidth: Infinity })]}>
+ {error}
+ </Text>
+ ) : null}
+ {mode === "qr" && props.qr ? <QrActions qr={props.qr} busy={busy} onClose={onClose} /> : null}
+ {primary ? (
+ <VStack spacing={spacing.xs}>
+ <Text modifiers={[font({ textStyle: "footnote" }), foregroundStyle(colors.textSecondary), multilineTextAlignment("center"), frame({ maxWidth: Infinity })]}>
+ {t("interaction.inputHandoff.sheetNote")}
+ </Text>
+ <Button
+ onPress={primary.onPress}
+ modifiers={[buttonStyle("plain"), disabledModifier(primary.disabled), padding({ top: spacing.sm }), accessibilityLabel(primary.label)]}
+ >
+ <Text
+ modifiers={[
+ font({ textStyle: "body", weight: "semibold" }),
+ foregroundStyle(colors.ctaText),
+ frame({ maxWidth: Infinity, minHeight: BUTTON_HEIGHT }),
+ background(primary.disabled ? colors.textTertiary : colors.cta, shapes.capsule()),
+ contentShape(shapes.capsule()),
+ ]}
+ >
+ {busy ? t("interaction.inputHandoff.phase.working") : primary.label}
+ </Text>
+ </Button>
+ <Button onPress={onClose} modifiers={[buttonStyle("plain")]}>
+ <Text
+ modifiers={[
+ font({ textStyle: "body", weight: "medium" }),
+ foregroundStyle(colors.textPrimary),
+ frame({ maxWidth: Infinity, minHeight: BUTTON_HEIGHT - 8 }),
+ contentShape(shapes.rectangle()),
+ ]}
+ >
+ {t("interaction.inputHandoff.action.close")}
+ </Text>
+ </Button>
+ </VStack>
+ ) : null}
+ {quietPicture || props.onLiveView ? (
+ <HStack spacing={spacing.xl}>
+ <Spacer />
+ {mode === "qr" && props.qr?.view.text ? (
+ <QuietLink
+ label={t(props.qr.view.link ? "interaction.inputHandoff.qr.copyLink" : "interaction.inputHandoff.qr.copyText")}
+ onPress={props.qr.onCopy}
+ />
+ ) : null}
+ {quietPicture ? <QuietLink label={t("interaction.inputHandoff.action.picture")} disabled={busy} onPress={props.onPicture} /> : null}
+ {props.onLiveView ? <QuietLink label={t("interaction.inputHandoff.action.liveView")} onPress={props.onLiveView} /> : null}
+ <Spacer />
+ </HStack>
+ ) : null}
+ </VStack>
+ </Group>
+ </BottomSheet>
+ </Host>
+ );
+}
+
+function SheetHeader({ snapshot }: { snapshot: InputHandoffSnapshot }) {
+ const { t } = useTranslation();
+ const { colors } = useTheme();
+ const place = inputHandoffPlace(snapshot.source);
+ const kind = inputHandoffPlaceKind(snapshot);
+ return (
+ <VStack spacing={spacing.sm}>
+ <Image
+ systemName={snapshot.qr === "scan" ? "qrcode" : kind === "web" ? "globe" : kind === "terminal" ? "terminal" : "macwindow"}
+ size={iconSize.xl}
+ color={colors.textPrimary}
+ modifiers={[frame({ width: 60, height: 60 }), ...sheetRow(colors, radius.container)]}
+ />
+ <Text modifiers={[font({ textStyle: "title3", weight: "semibold" }), multilineTextAlignment("center"), padding({ top: spacing.xs })]}>
+ {snapshot.purpose}
+ </Text>
+ <HStack spacing={4}>
+ {place.secure ? <Image systemName="lock.fill" size={iconSize.xs} color={colors.textSecondary} /> : null}
+ <Text modifiers={[font({ textStyle: "subheadline" }), foregroundStyle(colors.textSecondary), lineLimit(1)]}>{place.label}</Text>
+ </HStack>
+ {snapshot.note ? (
+ <Text modifiers={[font({ textStyle: "footnote" }), foregroundStyle(colors.textSecondary), multilineTextAlignment("center")]}>
+ {t("interaction.inputHandoff.agentNote", { note: snapshot.note })}
+ </Text>
+ ) : null}
+ {snapshot.command ? (
+ <Text
+ modifiers={[
+ font({ textStyle: "footnote", design: "monospaced" }),
+ foregroundStyle(colors.textSecondary),
+ frame({ maxWidth: Infinity }),
+ padding({ all: spacing.sm }),
+ ...sheetRow(colors, radius.control),
+ ]}
+ >
+ {snapshot.command}
+ </Text>
+ ) : null}
+ {inputHandoffWarnings(snapshot, t).map((warning) => (
+ <HStack key={warning} spacing={6} alignment="top">
+ <Image systemName="exclamationmark.triangle.fill" size={iconSize.sm} color={colors.warningFg} />
+ <Text modifiers={[font({ textStyle: "footnote" }), foregroundStyle(colors.textPrimary), frame({ maxWidth: Infinity, alignment: "leading" })]}>{warning}</Text>
+ </HStack>
+ ))}
+ </VStack>
+ );
+}
+
+function SheetField({
+ control,
+ label,
+ last,
+ disabled,
+ onChange,
+ onReturn,
+ registerFocus,
+}: {
+ control: InputHandoffTextControl;
+ label: string;
+ last: boolean;
+ disabled: boolean;
+ onChange(value: string): void;
+ onReturn(): void;
+ registerFocus(focus: (() => void) | null): void;
+}) {
+ const { t } = useTranslation();
+ const { colors } = useTheme();
+ // Shared by both field kinds, so revealing a password keeps what was typed.
+ const text = useNativeState("");
+ const [revealed, setRevealed] = useState(false);
+ const secure = control.contentType === "password";
+ const traits = swiftFieldTraits(control.contentType);
+ const ref = (field: TextFieldRef | SecureFieldRef | null) => registerFocus(field ? () => void field.focus() : null);
+ const modifiers = [
+ ...(traits.textContentType ? [textContentType(traits.textContentType)] : []),
+ keyboardType(traits.keyboardType),
+ textInputAutocapitalization("never"),
+ autocorrectionDisabled(true),
+ submitLabel(last ? "go" : "next"),
+ onSubmit(onReturn),
+ disabledModifier(disabled),
+ font({ textStyle: "body" }),
+ frame({ maxWidth: Infinity, minHeight: FIELD_HEIGHT }),
+ accessibilityLabel(label),
+ ];
+ const placeholder = control.placeholder ?? "";
+ return (
+ <VStack spacing={6} alignment="leading">
+ <Text modifiers={[font({ textStyle: "subheadline", weight: "medium" }), foregroundStyle(colors.textSecondary)]}>{label}</Text>
+ <HStack
+ spacing={spacing.sm}
+ modifiers={[
+ padding({ horizontal: 14 }),
+ frame({ minHeight: FIELD_HEIGHT }),
+ ...sheetRow(colors, radius.container),
+ ]}
+ >
+ {secure && !revealed ? (
+ <SecureField ref={ref} text={text} placeholder={placeholder} onTextChange={onChange} modifiers={modifiers} />
+ ) : (
+ <TextField
+ ref={ref}
+ text={text}
+ placeholder={placeholder}
+ axis={control.multiline ? "vertical" : "horizontal"}
+ onTextChange={onChange}
+ modifiers={control.multiline ? [...modifiers, lineLimit(4)] : modifiers}
+ />
+ )}
+ {secure ? (
+ <Button
+ onPress={() => setRevealed((shown) => !shown)}
+ modifiers={[
+ buttonStyle("plain"),
+ accessibilityLabel(t(revealed ? "interaction.inputHandoff.action.hidePassword" : "interaction.inputHandoff.action.showPassword")),
+ ]}
+ >
+ <Image
+ systemName={revealed ? "eye.slash" : "eye"}
+ size={iconSize.lg}
+ color={colors.textSecondary}
+ modifiers={[frame({ width: 32, height: 44 }), contentShape(shapes.rectangle())]}
+ />
+ </Button>
+ ) : null}
+ </HStack>
+ {control.filled ? (
+ <Text modifiers={[font({ textStyle: "footnote" }), foregroundStyle(colors.textSecondary)]}>{t("interaction.inputHandoff.filledHint")}</Text>
+ ) : null}
+ {control.suggestions?.length ? (
+ <HStack spacing={spacing.sm}>
+ {control.suggestions.slice(0, 4).map((option) => (
+ <Button
+ key={option.id}
+ label={option.label}
+ onPress={() => {
+ text.set(option.label);
+ onChange(option.label);
+ }}
+ modifiers={[buttonStyle("bordered"), disabledModifier(disabled)]}
+ />
+ ))}
+ </HStack>
+ ) : null}
+ </VStack>
+ );
+}
+
+/** Scan-to-sign-in: open the link here (the app that handles it takes over), or save or share the code. */
+function QrActions({ qr, busy, onClose }: { qr: InputHandoffQrSheet; busy: boolean; onClose(): void }) {
+ const { t } = useTranslation();
+ const { colors } = useTheme();
+ const shown = qr.view.state === "shown";
+ const link = qr.view.link;
+ const primary = link
+ ? { label: t(link.web ? "interaction.inputHandoff.qr.open" : "interaction.inputHandoff.qr.openApp", { site: link.site }), onPress: qr.onOpen }
+ : { label: t("interaction.inputHandoff.qr.share"), onPress: qr.onShare };
+ const disabled = busy || !shown;
+ return (
+ <VStack spacing={spacing.xs}>
+ <Text modifiers={[font({ textStyle: "footnote" }), foregroundStyle(colors.textSecondary), multilineTextAlignment("center"), frame({ maxWidth: Infinity }), fixedSize({ horizontal: false, vertical: true })]}>
+ {t(link ? "interaction.inputHandoff.qr.hintLink" : "interaction.inputHandoff.qr.hint")}
+ </Text>
+ <Button
+ onPress={primary.onPress}
+ modifiers={[buttonStyle("plain"), disabledModifier(disabled), padding({ top: spacing.sm }), accessibilityLabel(primary.label)]}
+ >
+ <Text
+ modifiers={[
+ font({ textStyle: "body", weight: "semibold" }),
+ foregroundStyle(colors.ctaText),
+ lineLimit(1),
+ padding({ horizontal: spacing.lg }),
+ frame({ maxWidth: Infinity, minHeight: BUTTON_HEIGHT }),
+ background(disabled ? colors.textTertiary : colors.cta, shapes.capsule()),
+ contentShape(shapes.capsule()),
+ ]}
+ >
+ {primary.label}
+ </Text>
+ </Button>
+ {link ? (
+ <Button onPress={qr.onShare} modifiers={[buttonStyle("plain"), disabledModifier(disabled), padding({ top: spacing.xs })]}>
+ <Text
+ modifiers={[
+ font({ textStyle: "body", weight: "medium" }),
+ foregroundStyle(colors.textPrimary),
+ frame({ maxWidth: Infinity, minHeight: BUTTON_HEIGHT }),
+ background(colors.sheetActionSurface, shapes.capsule()),
+ strokeBorder({ color: colors.sheetActionBorder, shape: "capsule", style: { lineWidth: 1 } }),
+ contentShape(shapes.capsule()),
+ ]}
+ >
+ {t("interaction.inputHandoff.qr.share")}
+ </Text>
+ </Button>
+ ) : null}
+ {qr.notice ? (
+ <Text modifiers={[font({ textStyle: "footnote" }), foregroundStyle(colors.textSecondary), multilineTextAlignment("center"), frame({ maxWidth: Infinity }), fixedSize({ horizontal: false, vertical: true })]}>
+ {qr.notice}
+ </Text>
+ ) : null}
+ <Button onPress={onClose} modifiers={[buttonStyle("plain")]}>
+ <Text
+ modifiers={[
+ font({ textStyle: "body", weight: "medium" }),
+ foregroundStyle(colors.textPrimary),
+ frame({ maxWidth: Infinity, minHeight: BUTTON_HEIGHT - 8 }),
+ contentShape(shapes.rectangle()),
+ ]}
+ >
+ {t("interaction.inputHandoff.action.close")}
+ </Text>
+ </Button>
+ </VStack>
+ );
+}
+
+function QuietLink({ label, disabled = false, onPress }: { label: string; disabled?: boolean; onPress(): void }) {
+ const { colors } = useTheme();
+ return (
+ <Button onPress={onPress} modifiers={[buttonStyle("plain"), disabledModifier(disabled)]}>
+ <Text modifiers={[font({ textStyle: "footnote" }), foregroundStyle(colors.textSecondary), frame({ minHeight: 44 })]}>{label}</Text>
+ </Button>
+ );
+}
+
+/** React Native content (screenshot step, sign-in code) inside the native sheet. */
+function Embedded({ children }: { children: ReactNode }) {
+ // The hosted view sizes to its content, so the width is given outright.
+ const { width } = useWindowDimensions();
+ return (
+ <RNHostView matchContents>
+ <View style={{ width: width - SIDE * 2 }}>{children}</View>
+ </RNHostView>
+ );
+}
diff --git a/apps/mobile/src/inputHandoff/InputHandoffSheet.tsx b/apps/mobile/src/inputHandoff/InputHandoffSheet.tsx
new file mode 100644
index 0000000000..11b5151d37
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/InputHandoffSheet.tsx
@@ -0,0 +1,192 @@
+/**
+ * The 代输入 form, opened from the strip above the composer. iOS uses the
+ * native SwiftUI sheet (InputHandoffSheet.ios.tsx); elsewhere a bottom panel
+ * with the platform's own text fields. Both read the same props.
+ */
+import {
+ KeyboardAvoidingView,
+ Modal,
+ Platform,
+ Pressable,
+ ScrollView,
+ View,
+} from "react-native";
+import { useSafeAreaInsets } from "react-native-safe-area-context";
+import { useTranslation } from "react-i18next";
+import { AppWindow, Globe, Lock, QrCode, SquareTerminal } from "lucide-react-native";
+import type { InputHandoffSnapshot } from "@cindy/device-link";
+import { Text } from "@/components/AppText";
+import { MainWindowActionButton } from "@/components/MobilePrimitives";
+import { iconSize, iconStroke, spacing, useTheme, useThemedStyles } from "@/theme";
+import { InputHandoffStepFields } from "./InputHandoffStepFields";
+import { makeInputHandoffStyles } from "./inputHandoffStyles";
+import { inputHandoffPlace, inputHandoffPlaceKind } from "./inputHandoffNative";
+import {
+ inputHandoffSheetMode,
+ inputHandoffWarnings,
+ type InputHandoffQrSheet,
+ type InputHandoffSheetProps,
+} from "./inputHandoffSheetModel";
+
+export function InputHandoffSheet(props: InputHandoffSheetProps) {
+ const { visible, snapshot, busy, error, embedded, onClose } = props;
+ const { t } = useTranslation();
+ const styles = useThemedStyles(makeInputHandoffStyles);
+ const insets = useSafeAreaInsets();
+ const mode = inputHandoffSheetMode(snapshot);
+ const remote = snapshot.remoteInput === true;
+ return (
+ <Modal visible={visible} transparent animationType="slide" onRequestClose={onClose}>
+ <KeyboardAvoidingView
+ behavior={Platform.OS === "ios" ? "padding" : undefined}
+ style={styles.sheetBackdrop}
+ >
+ <Pressable accessibilityRole="button" accessibilityLabel={t("interaction.inputHandoff.action.close")} style={{ flex: 1 }} onPress={onClose} />
+ <View style={[styles.sheetPanel, { paddingBottom: Math.max(insets.bottom, spacing.lg) }]} testID="interaction.inputHandoff.sheet">
+ <ScrollView keyboardShouldPersistTaps="handled" contentContainerStyle={{ gap: spacing.lg }}>
+ <InputHandoffSheetHeader snapshot={snapshot} />
+ {mode === "fields" ? (
+ <>
+ {embedded}
+ <InputHandoffStepFields
+ key={props.stepKey}
+ snapshot={snapshot}
+ draft={props.draft}
+ disabled={busy || !remote}
+ onChange={props.onChange}
+ onSubmit={props.onSubmit}
+ />
+ </>
+ ) : (
+ embedded
+ )}
+ {error ? <Text style={styles.error}>{error}</Text> : null}
+ {mode === "qr" && props.qr ? (
+ <InputHandoffQrActions {...props} qr={props.qr} />
+ ) : mode === "picture" || mode === "qr" ? null : (
+ <>
+ <Text style={styles.sheetNote}>{t("interaction.inputHandoff.sheetNote")}</Text>
+ <View style={styles.sheetButtons}>
+ <MainWindowActionButton
+ grow
+ action={{
+ label: t(mode === "code" ? "interaction.inputHandoff.action.done" : "interaction.inputHandoff.action.continue"),
+ tone: "primary",
+ busy,
+ disabled: mode === "fields" && !remote,
+ testID: "interaction.inputHandoff.continue",
+ onPress: mode === "code" ? props.onDone : props.onSubmit,
+ }}
+ />
+ <MainWindowActionButton
+ grow
+ action={{ label: t("interaction.inputHandoff.action.close"), tone: "secondary", onPress: onClose }}
+ />
+ </View>
+ </>
+ )}
+ <InputHandoffQuietLinks {...props} />
+ </ScrollView>
+ </View>
+ </KeyboardAvoidingView>
+ </Modal>
+ );
+}
+
+function InputHandoffSheetHeader({ snapshot }: { snapshot: InputHandoffSnapshot }) {
+ const { t } = useTranslation();
+ const styles = useThemedStyles(makeInputHandoffStyles);
+ const { colors } = useTheme();
+ const place = inputHandoffPlace(snapshot.source);
+ const kind = inputHandoffPlaceKind(snapshot);
+ const Icon = snapshot.qr === "scan" ? QrCode : kind === "web" ? Globe : kind === "terminal" ? SquareTerminal : AppWindow;
+ return (
+ <View style={styles.sheetHeader}>
+ <View style={styles.sheetIcon}>
+ <Icon color={colors.textPrimary} size={iconSize.xl} strokeWidth={iconStroke.regular} />
+ </View>
+ <Text style={styles.sheetTitle}>{snapshot.purpose}</Text>
+ <View style={styles.place}>
+ {place.secure ? <Lock color={colors.textSecondary} size={iconSize.xs} strokeWidth={iconStroke.regular} /> : null}
+ <Text numberOfLines={1} style={styles.placeText}>{place.label}</Text>
+ </View>
+ {snapshot.note ? (
+ <Text style={styles.sheetNote}>{t("interaction.inputHandoff.agentNote", { note: snapshot.note })}</Text>
+ ) : null}
+ {snapshot.command ? <Text style={styles.mono}>{snapshot.command}</Text> : null}
+ {inputHandoffWarnings(snapshot, t).map((warning) => (
+ <Text key={warning} style={styles.warning}>{warning}</Text>
+ ))}
+ </View>
+ );
+}
+
+/** Scan-to-sign-in: open the link here (the app that handles it takes over), or save or share the code. */
+function InputHandoffQrActions({ qr, busy, onClose }: InputHandoffSheetProps & { qr: InputHandoffQrSheet }) {
+ const { t } = useTranslation();
+ const styles = useThemedStyles(makeInputHandoffStyles);
+ const link = qr.view.link;
+ const disabled = busy || qr.view.state !== "shown";
+ const share = { label: t("interaction.inputHandoff.qr.share"), disabled, onPress: qr.onShare };
+ return (
+ <>
+ <Text style={styles.sheetNote}>
+ {t(link ? "interaction.inputHandoff.qr.hintLink" : "interaction.inputHandoff.qr.hint")}
+ </Text>
+ <View style={styles.sheetButtons}>
+ <MainWindowActionButton
+ grow
+ action={
+ link
+ ? {
+ label: t(link.web ? "interaction.inputHandoff.qr.open" : "interaction.inputHandoff.qr.openApp", { site: link.site }),
+ tone: "primary",
+ disabled,
+ testID: "interaction.inputHandoff.qr.open",
+ onPress: qr.onOpen,
+ }
+ : { ...share, tone: "primary", testID: "interaction.inputHandoff.qr.share" }
+ }
+ />
+ {link ? (
+ <MainWindowActionButton grow action={{ ...share, tone: "secondary", testID: "interaction.inputHandoff.qr.share" }} />
+ ) : null}
+ {qr.notice ? <Text style={[styles.sheetNote]}>{qr.notice}</Text> : null}
+ <MainWindowActionButton
+ grow
+ action={{ label: t("interaction.inputHandoff.action.close"), tone: "secondary", onPress: onClose }}
+ />
+ </View>
+ </>
+ );
+}
+
+function InputHandoffQuietLinks({ snapshot, busy, onPicture, onLiveView, qr }: InputHandoffSheetProps) {
+ const { t } = useTranslation();
+ const styles = useThemedStyles(makeInputHandoffStyles);
+ // A terminal prompt has no screen to look at; a picture step is already one, except a QR code cut out of it.
+ const picture = !snapshot.command && (!snapshot.picture || snapshot.qr === "scan");
+ const copy = snapshot.qr === "scan" && qr?.view.text ? qr : null;
+ if (!picture && !onLiveView && !copy) return null;
+ return (
+ <View style={styles.quietRow}>
+ {copy ? (
+ <Pressable accessibilityRole="button" onPress={copy.onCopy} style={styles.quietLink} testID="interaction.inputHandoff.qr.copy">
+ <Text style={styles.meta}>
+ {t(copy.view.link ? "interaction.inputHandoff.qr.copyLink" : "interaction.inputHandoff.qr.copyText")}
+ </Text>
+ </Pressable>
+ ) : null}
+ {picture ? (
+ <Pressable accessibilityRole="button" disabled={busy} onPress={onPicture} style={styles.quietLink}>
+ <Text style={styles.meta}>{t("interaction.inputHandoff.action.picture")}</Text>
+ </Pressable>
+ ) : null}
+ {onLiveView ? (
+ <Pressable accessibilityRole="button" onPress={onLiveView} style={styles.quietLink} testID="interaction.inputHandoff.liveView">
+ <Text style={styles.meta}>{t("interaction.inputHandoff.action.liveView")}</Text>
+ </Pressable>
+ ) : null}
+ </View>
+ );
+}
diff --git a/apps/mobile/src/inputHandoff/InputHandoffStepFields.tsx b/apps/mobile/src/inputHandoff/InputHandoffStepFields.tsx
new file mode 100644
index 0000000000..b5cf5c151e
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/InputHandoffStepFields.tsx
@@ -0,0 +1,99 @@
+import { useRef } from "react";
+import { View, type TextInput as NativeTextInput } from "react-native";
+import { useTranslation } from "react-i18next";
+import type { InputHandoffSnapshot, InputHandoffValues } from "@cindy/device-link";
+import { Text, TextInput } from "@/components/AppText";
+import { MainWindowActionButton } from "@/components/MobilePrimitives";
+import { useTheme, useThemedStyles } from "@/theme";
+import { makeInputHandoffStyles } from "./inputHandoffStyles";
+import { inputHandoffTextFields, nativeTextInputProps } from "./inputHandoffNative";
+
+/**
+ * Only the fields the owner types into, in screen order, plus what the page
+ * says is wrong with them. The keyboard's Next moves on; Go on the last field
+ * answers like the sheet's Continue, and the computer confirms on the page.
+ */
+export function InputHandoffStepFields({
+ snapshot,
+ draft,
+ disabled,
+ onChange,
+ onSubmit,
+}: {
+ snapshot: InputHandoffSnapshot;
+ draft: InputHandoffValues;
+ disabled: boolean;
+ onChange(id: string, value: string): void;
+ onSubmit(): void;
+}) {
+ const { t } = useTranslation();
+ const styles = useThemedStyles(makeInputHandoffStyles);
+ const { colors } = useTheme();
+ const inputs = useRef(new Map<string, NativeTextInput>());
+ const fields = inputHandoffTextFields(snapshot);
+ const nextField = (id: string) => fields[fields.findIndex((f) => f.id === id) + 1];
+
+ return (
+ <View style={styles.stack}>
+ {snapshot.controls.map((control) => {
+ if (control.kind === "note")
+ return (
+ <Text key={control.id} style={styles.error}>
+ {control.text}
+ </Text>
+ );
+ const label = inputHandoffFieldLabel(control, t);
+ const next = nextField(control.id);
+ return (
+ <View key={control.id} style={styles.field}>
+ <Text style={styles.fieldLabel}>{label}</Text>
+ <TextInput
+ ref={(input) => {
+ if (input) inputs.current.set(control.id, input);
+ else inputs.current.delete(control.id);
+ }}
+ accessibilityLabel={label}
+ value={draft[control.id] ?? ""}
+ onChangeText={(v) => onChange(control.id, v)}
+ placeholder={control.placeholder}
+ placeholderTextColor={colors.textPlaceholder}
+ autoCapitalize="none"
+ autoCorrect={false}
+ spellCheck={false}
+ editable={!disabled}
+ multiline={control.multiline === true}
+ // Return always moves on, even in a multi-line field (pasted lines are kept).
+ returnKeyType={next ? "next" : "go"}
+ submitBehavior={next ? "submit" : "blurAndSubmit"}
+ onSubmitEditing={() => (next ? inputs.current.get(next.id)?.focus() : !disabled && onSubmit())}
+ style={styles.input}
+ {...nativeTextInputProps(control.contentType)}
+ />
+ {control.filled ? <Text style={styles.note}>{t("interaction.inputHandoff.filledHint")}</Text> : null}
+ {control.suggestions?.length ? (
+ <View style={styles.wrap}>
+ {control.suggestions.slice(0, 12).map((o) => (
+ <MainWindowActionButton
+ key={o.id}
+ density="compact"
+ action={{ label: o.label, disabled, tone: "secondary", onPress: () => onChange(control.id, o.label) }}
+ />
+ ))}
+ </View>
+ ) : null}
+ </View>
+ );
+ })}
+ </View>
+ );
+}
+
+export function inputHandoffFieldLabel(
+ control: { label?: string; contentType: string },
+ t: (key: string) => string,
+): string {
+ if (control.label) return control.label;
+ if (control.contentType === "password") return t("interaction.inputHandoff.passwordField");
+ if (control.contentType === "one-time-code") return t("interaction.inputHandoff.codeField");
+ return t("interaction.inputHandoff.unnamedField");
+}
diff --git a/apps/mobile/src/inputHandoff/inputHandoffNative.ts b/apps/mobile/src/inputHandoff/inputHandoffNative.ts
new file mode 100644
index 0000000000..7a22e27365
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/inputHandoffNative.ts
@@ -0,0 +1,154 @@
+import type {
+ InputHandoffContentType,
+ InputHandoffControl,
+ InputHandoffSnapshot,
+ InputHandoffValues,
+} from "@cindy/device-link";
+import { isInputHandoffDeviceCode } from "@cindy/device-link";
+import { Platform, type TextInputProps } from "react-native";
+
+/**
+ * Return moves field to field and answers on the last one. The iOS number
+ * and phone pads have no Return key, so iOS uses the numeric keyboard that
+ * keeps one.
+ */
+const numericKeyboard = (pad: "number-pad" | "phone-pad"): TextInputProps["keyboardType"] =>
+ Platform.OS === "ios" ? "numbers-and-punctuation" : pad;
+
+/**
+ * Standard platform hints per field so iOS AutoFill / Android Autofill and
+ * password managers (1Password) offer the right item. Password fields are
+ * the plain system secure field — no custom reveal.
+ */
+export function nativeTextInputProps(
+ contentType: InputHandoffContentType,
+): Pick<
+ TextInputProps,
+ "secureTextEntry" | "textContentType" | "autoComplete" | "keyboardType"
+> {
+ switch (contentType) {
+ case "password":
+ return {
+ secureTextEntry: true,
+ textContentType: "password",
+ autoComplete: "password",
+ };
+ case "one-time-code":
+ return {
+ textContentType: "oneTimeCode",
+ autoComplete: "sms-otp",
+ keyboardType: numericKeyboard("number-pad"),
+ };
+ case "username":
+ return { textContentType: "username", autoComplete: "username" };
+ case "email":
+ return {
+ textContentType: "emailAddress",
+ autoComplete: "email",
+ keyboardType: "email-address",
+ };
+ case "tel":
+ return {
+ textContentType: "telephoneNumber",
+ autoComplete: "tel",
+ keyboardType: numericKeyboard("phone-pad"),
+ };
+ case "url":
+ return { textContentType: "URL", autoComplete: "url", keyboardType: "url" };
+ case "number":
+ return { textContentType: "none", autoComplete: "off", keyboardType: numericKeyboard("number-pad") };
+ default:
+ return { textContentType: "none", autoComplete: "off" };
+ }
+}
+
+export type InputHandoffTextControl = Extract<InputHandoffControl, { kind: "text" }>;
+
+/** The fields the owner types into, in screen order. */
+export const inputHandoffTextFields = (snapshot: InputHandoffSnapshot): InputHandoffTextControl[] =>
+ snapshot.controls.filter((c): c is InputHandoffTextControl => c.kind === "text");
+
+/**
+ * The same hints for the SwiftUI fields of the iOS sheet (system AutoFill,
+ * Passwords and 1Password read the content type).
+ */
+export function swiftFieldTraits(contentType: InputHandoffContentType): {
+ textContentType?: "username" | "password" | "oneTimeCode" | "emailAddress" | "telephoneNumber" | "URL";
+ keyboardType: "default" | "email-address" | "numbers-and-punctuation" | "url";
+} {
+ switch (contentType) {
+ case "password":
+ return { textContentType: "password", keyboardType: "default" };
+ case "one-time-code":
+ return { textContentType: "oneTimeCode", keyboardType: "numbers-and-punctuation" };
+ case "username":
+ return { textContentType: "username", keyboardType: "default" };
+ case "email":
+ return { textContentType: "emailAddress", keyboardType: "email-address" };
+ case "tel":
+ return { textContentType: "telephoneNumber", keyboardType: "numbers-and-punctuation" };
+ case "url":
+ return { textContentType: "URL", keyboardType: "url" };
+ case "number":
+ return { keyboardType: "numbers-and-punctuation" };
+ default:
+ return { keyboardType: "default" };
+ }
+}
+
+/**
+ * Where the fields are, as the owner reads it: just the site for a plain
+ * https page (with a lock), the full origin when something about it needs a
+ * second look, otherwise the app.
+ */
+export function inputHandoffPlace(source: InputHandoffSnapshot["source"]): { label: string; secure: boolean } {
+ const origin = source.origin;
+ if (!origin) return { label: source.app, secure: false };
+ if (origin.startsWith("https://") && !source.warning) return { label: origin.slice("https://".length), secure: true };
+ return { label: origin, secure: false };
+}
+
+export type InputHandoffPlaceKind = "web" | "terminal" | "app";
+
+export const inputHandoffPlaceKind = (snapshot: InputHandoffSnapshot): InputHandoffPlaceKind =>
+ snapshot.command ? "terminal" : snapshot.source.origin ? "web" : "app";
+
+/** The sheet opens only on a screen with something for the owner: fields, a picture or a sign-in code. */
+export function inputHandoffSheetHasContent(snapshot: InputHandoffSnapshot, heldElsewhere: boolean): boolean {
+ if (snapshot.terminal || snapshot.phase !== "ready" || heldElsewhere) return false;
+ return (
+ Boolean(snapshot.picture) ||
+ isInputHandoffDeviceCode(snapshot.deviceCode) ||
+ inputHandoffTextFields(snapshot).length > 0
+ );
+}
+
+/** Only fields the owner typed into are applied; text already on the screen stays. */
+export function changedInputHandoffValues(
+ snapshot: InputHandoffSnapshot,
+ draft: InputHandoffValues,
+): InputHandoffValues {
+ const out: InputHandoffValues = {};
+ for (const control of inputHandoffTextFields(snapshot)) {
+ const value = draft[control.id];
+ if (value) out[control.id] = value;
+ }
+ return out;
+}
+
+export function parseInputHandoffSnapshotLike(
+ raw: Record<string, unknown>,
+): InputHandoffSnapshot | null {
+ const source = raw.source as Record<string, unknown> | undefined;
+ if (
+ raw.kind !== "input_handoff" ||
+ typeof raw.requestId !== "string" ||
+ !Number.isSafeInteger(raw.revision) ||
+ typeof raw.purpose !== "string" ||
+ !Array.isArray(raw.controls) ||
+ !source ||
+ typeof source.app !== "string"
+ )
+ return null;
+ return raw as unknown as InputHandoffSnapshot;
+}
diff --git a/apps/mobile/src/inputHandoff/inputHandoffQrActions.ts b/apps/mobile/src/inputHandoff/inputHandoffQrActions.ts
new file mode 100644
index 0000000000..c467f39ca9
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/inputHandoffQrActions.ts
@@ -0,0 +1,70 @@
+/**
+ * What the owner can do with a QR code from the computer, on this phone:
+ * open its link here (an app that handles the link takes over, for example to
+ * confirm a sign-in), hand the image to the share sheet (save it, then pick it
+ * from the album in an app's scanner, or send it on), or copy what it says.
+ */
+import { Linking } from "react-native";
+import * as Clipboard from "expo-clipboard";
+import { Directory, File, Paths } from "expo-file-system";
+import { inputHandoffQrLink, type InputHandoffPicture, type InputHandoffQr } from "@cindy/device-link";
+
+const SHARE_DIR = "input-handoff-qr";
+/** The share sheet may still read the file after it returns; the code is removed soon after. */
+const SHARE_KEEP_MS = 120_000;
+
+/** Opens the code's link here, as a phone camera would: a web link, or an app link the phone hands to its app. */
+export async function openInputHandoffQrLink(qr: InputHandoffQr): Promise<boolean> {
+ const link = inputHandoffQrLink(qr);
+ if (!link) return false;
+ try {
+ await Linking.openURL(link.url);
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+export async function copyInputHandoffQr(qr: InputHandoffQr): Promise<boolean> {
+ try {
+ await Clipboard.setStringAsync(qr.text);
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+async function removeShared(): Promise<void> {
+ try {
+ const directory = new Directory(Paths.cache, SHARE_DIR);
+ if (!directory.exists) return;
+ const FileSystem = await import("expo-file-system/legacy");
+ await Promise.all(
+ directory.list().map((entry) => FileSystem.deleteAsync(entry.uri, { idempotent: true }).catch(() => undefined)),
+ );
+ } catch {
+ // Best effort: the cache directory is the operating system's to clear too.
+ }
+}
+
+/** Hands the code's image to the system share sheet (Save Image, or another app). */
+export async function shareInputHandoffQr(picture: InputHandoffPicture): Promise<boolean> {
+ // Only the latest shared code is ever kept, and only briefly.
+ await removeShared();
+ let uri: string | null = null;
+ try {
+ const directory = new Directory(Paths.cache, SHARE_DIR);
+ directory.create({ intermediates: true, idempotent: true });
+ const file = new File(directory, `qr-${Date.now().toString(36)}.jpg`);
+ uri = file.uri;
+ const FileSystem = await import("expo-file-system/legacy");
+ await FileSystem.writeAsStringAsync(file.uri, picture.data, { encoding: FileSystem.EncodingType.Base64 });
+ const sharing = await import("expo-sharing");
+ await sharing.shareAsync(file.uri, { mimeType: "image/jpeg", UTI: "public.jpeg" });
+ setTimeout(() => void removeShared(), SHARE_KEEP_MS);
+ return true;
+ } catch {
+ if (uri) await removeShared();
+ return false;
+ }
+}
diff --git a/apps/mobile/src/inputHandoff/inputHandoffSheetModel.ts b/apps/mobile/src/inputHandoff/inputHandoffSheetModel.ts
new file mode 100644
index 0000000000..09900f8eda
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/inputHandoffSheetModel.ts
@@ -0,0 +1,60 @@
+/** What the 代输入 sheet shows, shared by the iOS sheet and the bottom panel used elsewhere. */
+import type { ReactNode } from "react";
+import {
+ isInputHandoffDeviceCode,
+ type InputHandoffSnapshot,
+ type InputHandoffValues,
+} from "@cindy/device-link";
+import { inputHandoffTextFields } from "./inputHandoffNative";
+import type { InputHandoffQrView } from "./useInputHandoffQr";
+
+/** Scan-to-sign-in on the sheet: the code, and what can be done with it on this phone. */
+export interface InputHandoffQrSheet {
+ view: InputHandoffQrView;
+ onOpen(): void;
+ onShare(): void;
+ onCopy(): void;
+ /** Result of the last open, share or copy. */
+ notice: string | null;
+}
+
+export interface InputHandoffSheetProps {
+ visible: boolean;
+ snapshot: InputHandoffSnapshot;
+ /** Changes with every new screen: fields start empty on each. */
+ stepKey: string;
+ draft: InputHandoffValues;
+ busy: boolean;
+ error: string | null;
+ /** The screenshot step or the device-code panel, shown as they are. */
+ embedded: ReactNode;
+ onChange(id: string, value: string): void;
+ /** Hands the typed values to the computer, which confirms on the page. */
+ onSubmit(): void;
+ /** Sign-in code steps: the owner finished elsewhere and hands back. */
+ onDone(): void;
+ onPicture(): void;
+ onLiveView?(): void;
+ /** Scan-to-sign-in steps only. */
+ qr: InputHandoffQrSheet | null;
+ /** Closes the sheet only; the handoff stays open in the strip. */
+ onClose(): void;
+}
+
+/** What the sheet asks for: typing, a QR code to scan, a sign-in code to use elsewhere, or a picture of the screen. */
+export function inputHandoffSheetMode(snapshot: InputHandoffSnapshot): "qr" | "picture" | "code" | "fields" {
+ if (snapshot.picture && snapshot.qr === "scan") return "qr";
+ if (snapshot.picture) return "picture";
+ if (isInputHandoffDeviceCode(snapshot.deviceCode) && inputHandoffTextFields(snapshot).length === 0) return "code";
+ return "fields";
+}
+
+/** What the owner should check before typing: the page's origin, an agent-opened browser, a computer that can't take input. */
+export function inputHandoffWarnings(snapshot: InputHandoffSnapshot, t: (key: string) => string): string[] {
+ const out: string[] = [];
+ if (snapshot.source.warning) out.push(t(`interaction.inputHandoff.originWarning.${snapshot.source.warning}`));
+ if (snapshot.agentControlled) out.push(t("interaction.inputHandoff.agentControlled"));
+ if (snapshot.remoteInput !== true) out.push(t("interaction.inputHandoff.remoteUnavailable"));
+ if (snapshot.failure && !snapshot.terminal) out.push(t(`interaction.inputHandoff.failure.${snapshot.failure}`));
+ return out;
+}
diff --git a/apps/mobile/src/inputHandoff/inputHandoffStyles.ts b/apps/mobile/src/inputHandoff/inputHandoffStyles.ts
new file mode 100644
index 0000000000..f1034729a2
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/inputHandoffStyles.ts
@@ -0,0 +1,246 @@
+import { StyleSheet } from "react-native";
+import {
+ fontWeight,
+ lineHeight,
+ monoFont,
+ radius,
+ spacing,
+ typeScale,
+ type ThemeColors,
+} from "@/theme";
+
+export const makeInputHandoffStyles = (colors: ThemeColors) =>
+ StyleSheet.create({
+ card: {
+ gap: spacing.sm,
+ padding: spacing.lg,
+ borderRadius: radius.container,
+ borderWidth: StyleSheet.hairlineWidth,
+ borderColor: colors.border,
+ backgroundColor: colors.surfaceElevated,
+ },
+ // 代输入: optional live view of the window, below the step.
+ liveView: {
+ gap: spacing.sm,
+ paddingTop: spacing.sm,
+ borderTopWidth: StyleSheet.hairlineWidth,
+ borderTopColor: colors.border,
+ },
+ // 代输入:设备码登录,代码与在本设备打开
+ deviceCode: {
+ gap: spacing.sm,
+ padding: spacing.md,
+ borderRadius: radius.control,
+ borderWidth: StyleSheet.hairlineWidth,
+ borderColor: colors.border,
+ backgroundColor: colors.surfaceChip,
+ },
+ // 大数字:设备码本身
+ deviceCodeText: {
+ fontFamily: monoFont,
+ fontSize: typeScale.headline,
+ lineHeight: lineHeight.headline,
+ fontWeight: fontWeight.semibold,
+ letterSpacing: 2,
+ color: colors.textPrimary,
+ },
+ row: {
+ minHeight: 44,
+ flexDirection: "row",
+ alignItems: "center",
+ gap: spacing.sm,
+ },
+ // 列表 / 卡片标题
+ title: {
+ fontSize: typeScale.subtitle,
+ lineHeight: lineHeight.subtitle,
+ fontWeight: fontWeight.medium,
+ color: colors.textPrimary,
+ },
+ // 行标题、选项
+ label: {
+ fontSize: typeScale.body,
+ lineHeight: lineHeight.body,
+ fontWeight: fontWeight.medium,
+ color: colors.textPrimary,
+ },
+ // 次级正文
+ body: {
+ fontSize: typeScale.bodySmall,
+ lineHeight: lineHeight.bodySmall,
+ fontWeight: fontWeight.regular,
+ color: colors.textSecondary,
+ },
+ // 时间、计数、状态词
+ meta: {
+ fontSize: typeScale.caption,
+ lineHeight: lineHeight.caption,
+ fontWeight: fontWeight.regular,
+ color: colors.textTertiary,
+ },
+ // 说明、提示、报错
+ note: {
+ fontSize: typeScale.footnote,
+ lineHeight: lineHeight.caption,
+ fontWeight: fontWeight.regular,
+ color: colors.textSecondary,
+ },
+ warning: {
+ fontSize: typeScale.footnote,
+ lineHeight: lineHeight.caption,
+ fontWeight: fontWeight.regular,
+ color: colors.textPrimary,
+ borderLeftWidth: 2,
+ borderLeftColor: colors.warningFg,
+ paddingLeft: spacing.sm,
+ },
+ mono: {
+ fontFamily: monoFont,
+ fontSize: typeScale.footnote,
+ lineHeight: lineHeight.caption,
+ fontWeight: fontWeight.regular,
+ color: colors.textSecondary,
+ },
+ input: {
+ fontSize: typeScale.bodySmall,
+ fontWeight: fontWeight.regular,
+ color: colors.textPrimary,
+ borderWidth: StyleSheet.hairlineWidth,
+ borderColor: colors.border,
+ borderRadius: radius.control,
+ paddingHorizontal: spacing.md,
+ minHeight: 44,
+ },
+ option: {
+ minHeight: 44,
+ flexDirection: "row",
+ alignItems: "center",
+ justifyContent: "space-between",
+ gap: spacing.sm,
+ paddingHorizontal: spacing.md,
+ borderWidth: StyleSheet.hairlineWidth,
+ borderColor: colors.border,
+ borderRadius: radius.control,
+ },
+ optionSelected: {
+ borderColor: colors.borderStrong,
+ backgroundColor: colors.surfaceChip,
+ },
+ // 低调的文字入口(看画面),保留 44pt 点击高度
+ quietLink: { alignSelf: "center", minHeight: 44, justifyContent: "center", paddingHorizontal: spacing.md },
+ quietRow: { flexDirection: "row", justifyContent: "center", flexWrap: "wrap" },
+ // 代输入条:贴在输入框上方的一行(图标 + 用途 + 位置,右侧「填写」「跳过」)
+ strip: {
+ gap: spacing.sm,
+ paddingVertical: spacing.md,
+ paddingHorizontal: spacing.md,
+ borderRadius: radius.container,
+ borderWidth: StyleSheet.hairlineWidth,
+ borderColor: colors.border,
+ backgroundColor: colors.surfaceElevated,
+ },
+ stripRow: { flexDirection: "row", alignItems: "center", gap: spacing.md },
+ stripIcon: {
+ width: 36,
+ height: 36,
+ borderRadius: radius.control,
+ alignItems: "center",
+ justifyContent: "center",
+ backgroundColor: colors.surfaceChip,
+ },
+ stripText: { flex: 1, minWidth: 0, gap: 2 },
+ stripActions: { flexDirection: "row", alignItems: "center", gap: spacing.sm },
+ stripStatus: { flexDirection: "row", alignItems: "center", gap: spacing.sm },
+ stripStatusText: { flexShrink: 1 },
+ // 位置行:锁 + 站点(或应用名)
+ place: { flexDirection: "row", alignItems: "center", gap: spacing.xs, minWidth: 0 },
+ placeText: {
+ flexShrink: 1,
+ fontSize: typeScale.caption,
+ lineHeight: lineHeight.caption,
+ fontWeight: fontWeight.regular,
+ color: colors.textSecondary,
+ },
+ // 代输入表单(非 iOS 的底部面板)
+ sheetBackdrop: { flex: 1, justifyContent: "flex-end", backgroundColor: colors.overlay },
+ sheetPanel: {
+ gap: spacing.lg,
+ paddingTop: spacing.xl,
+ paddingHorizontal: spacing.xl,
+ borderTopLeftRadius: radius.container,
+ borderTopRightRadius: radius.container,
+ backgroundColor: colors.surfaceElevated,
+ },
+ sheetHeader: { alignItems: "center", gap: spacing.sm },
+ sheetIcon: {
+ width: 56,
+ height: 56,
+ borderRadius: radius.container,
+ alignItems: "center",
+ justifyContent: "center",
+ backgroundColor: colors.surfaceChip,
+ },
+ sheetTitle: {
+ fontSize: typeScale.title,
+ lineHeight: lineHeight.title,
+ fontWeight: fontWeight.semibold,
+ color: colors.textPrimary,
+ textAlign: "center",
+ },
+ sheetNote: {
+ fontSize: typeScale.footnote,
+ lineHeight: lineHeight.caption,
+ fontWeight: fontWeight.regular,
+ color: colors.textSecondary,
+ textAlign: "center",
+ },
+ sheetButtons: { gap: spacing.xs },
+ // 页面上的报错(黑白系文字,语义由文案承担)
+ error: {
+ fontSize: typeScale.footnote,
+ lineHeight: lineHeight.caption,
+ fontWeight: fontWeight.regular,
+ color: colors.errorText,
+ },
+ fieldLabel: {
+ fontSize: typeScale.footnote,
+ lineHeight: lineHeight.caption,
+ fontWeight: fontWeight.medium,
+ color: colors.textSecondary,
+ },
+ field: { gap: spacing.xs },
+ stack: { gap: spacing.md },
+ wrap: { flexDirection: "row", flexWrap: "wrap", gap: spacing.sm },
+ options: { maxHeight: 264 },
+ // 代输入画面:整宽、按截图比例,点按位置按比例换算
+ picture: {
+ width: "100%",
+ overflow: "hidden",
+ borderRadius: radius.control,
+ borderWidth: StyleSheet.hairlineWidth,
+ borderColor: colors.border,
+ backgroundColor: colors.surfaceChip,
+ },
+ pictureDisabled: { opacity: 0.6 },
+ // 扫码登录:电脑上的二维码,居中、正方形
+ qrWrap: { alignItems: "center" },
+ qrCode: {
+ overflow: "hidden",
+ borderRadius: radius.container,
+ borderWidth: StyleSheet.hairlineWidth,
+ borderColor: colors.sheetActionBorder,
+ backgroundColor: colors.sheetActionSurface,
+ },
+ qrPlaceholder: {
+ alignItems: "center",
+ justifyContent: "center",
+ gap: spacing.sm,
+ padding: spacing.lg,
+ borderRadius: radius.container,
+ borderWidth: StyleSheet.hairlineWidth,
+ borderColor: colors.sheetActionBorder,
+ backgroundColor: colors.sheetActionSurface,
+ },
+ centered: { textAlign: "center" },
+ pictureImage: { width: "100%", height: "100%" },
+ });
diff --git a/apps/mobile/src/inputHandoff/useInputHandoffQr.ts b/apps/mobile/src/inputHandoff/useInputHandoffQr.ts
new file mode 100644
index 0000000000..047c765d53
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/useInputHandoffQr.ts
@@ -0,0 +1,128 @@
+/**
+ * 代输入 scan-to-sign-in on the phone: the QR code on the computer arrives
+ * inside the sealed per-step offer (like a screenshot step), and lives only in
+ * this hook's state for one revision. A tap on it goes back on the same
+ * exchange and taps the code in the window (for example to refresh an expired one).
+ */
+import { useEffect, useRef, useState } from "react";
+import {
+ inputHandoffQrLink,
+ type InputHandoffPicture,
+ type InputHandoffQrLink,
+ type InputHandoffSnapshot,
+ type InputHandoffSubmission,
+} from "@cindy/device-link";
+
+export type InputHandoffQrState = "idle" | "loading" | "shown" | "sending" | "failed";
+
+export interface InputHandoffQrView {
+ state: InputHandoffQrState;
+ picture: InputHandoffPicture | null;
+ /** The code's content as a link to open here (web or app link); null when it is not one. */
+ link: InputHandoffQrLink | null;
+ /** The code's content, for copying. */
+ text: string | null;
+ load(): void;
+ /** Taps the code in the window, at fractions of the picture. */
+ tap(x: number, y: number): void;
+}
+
+type OpenPicture = (
+ snapshot: InputHandoffSnapshot,
+ answer: (picture: InputHandoffPicture) => Promise<InputHandoffSubmission>,
+) => Promise<void>;
+
+export function useInputHandoffQr({
+ snapshot,
+ active,
+ openPicture,
+ onError,
+}: {
+ snapshot: InputHandoffSnapshot;
+ /** The sheet is open on a code that is on screen. */
+ active: boolean;
+ openPicture: OpenPicture;
+ onError(message: "stale" | "submit" | null): void;
+}): InputHandoffQrView {
+ const [state, setState] = useState<InputHandoffQrState>("idle");
+ const [picture, setPicture] = useState<InputHandoffPicture | null>(null);
+ const pending = useRef<{ resolve(submission: InputHandoffSubmission): void; reject(error: Error): void } | null>(null);
+ const generation = useRef(0);
+ const scan = snapshot.qr === "scan" && snapshot.picture === true && !snapshot.terminal;
+ const key = `${snapshot.requestId}:${snapshot.revision}`;
+ const revision = useRef(snapshot.revision);
+ revision.current = snapshot.revision;
+
+ const drop = () => {
+ generation.current++;
+ pending.current?.reject(new Error("INPUT_HANDOFF_CLOSED"));
+ pending.current = null;
+ setPicture(null);
+ };
+
+ const load = () => {
+ if (!scan || snapshot.remoteInput !== true) return;
+ drop();
+ const mine = generation.current;
+ let answered = false;
+ setState("loading");
+ onError(null);
+ openPicture(snapshot, (next) =>
+ new Promise<InputHandoffSubmission>((resolve, reject) => {
+ if (generation.current !== mine) {
+ reject(new Error("INPUT_HANDOFF_CLOSED"));
+ return;
+ }
+ pending.current = {
+ resolve: (submission) => {
+ answered = true;
+ resolve(submission);
+ },
+ reject,
+ };
+ setPicture(next.qr ? next : null);
+ setState(next.qr ? "shown" : "failed");
+ }),
+ )
+ .then(() => {
+ if (generation.current === mine) setState("sending");
+ })
+ .catch((e: unknown) => {
+ if (generation.current !== mine) return;
+ pending.current = null;
+ setPicture(null);
+ if (answered) onError(e instanceof Error && e.message === "INPUT_HANDOFF_STALE" ? "stale" : "submit");
+ setState(answered ? "idle" : "failed");
+ });
+ };
+
+ // One code per revision: a refreshed code is a new revision and loads by itself while the sheet is open.
+ useEffect(() => {
+ if (active && scan) load();
+ else {
+ drop();
+ setState("idle");
+ }
+ return drop;
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- reloads per revision and when the sheet opens
+ }, [key, active, scan]);
+
+ const tap = (x: number, y: number) => {
+ const reply = pending.current;
+ if (!reply || state !== "shown") return;
+ pending.current = null;
+ setState("sending");
+ const clamp = (n: number) => Math.min(1, Math.max(0, n));
+ reply.resolve({ expectedRevision: revision.current, values: {}, action: { kind: "tap", x: clamp(x), y: clamp(y) } });
+ };
+
+ const qr = picture?.qr ?? null;
+ return {
+ state,
+ picture,
+ link: qr ? inputHandoffQrLink(qr) : null,
+ text: qr?.text ?? null,
+ load,
+ tap,
+ };
+}
diff --git a/apps/mobile/src/inputHandoff/useInputHandoffSubmit.ts b/apps/mobile/src/inputHandoff/useInputHandoffSubmit.ts
new file mode 100644
index 0000000000..d79ea66a9c
--- /dev/null
+++ b/apps/mobile/src/inputHandoff/useInputHandoffSubmit.ts
@@ -0,0 +1,135 @@
+import { useEffect, useRef } from "react";
+import { AppState } from "react-native";
+import { useIsFocused } from "expo-router";
+import {
+ INPUT_HANDOFF_ACTION_ID,
+ INPUT_HANDOFF_GHOST_ID,
+ PLUGIN_OAUTH_CHANNEL,
+ inputHandoffPresentation,
+ type InputHandoffPicture,
+ type InputHandoffSnapshot,
+ type InputHandoffSubmission,
+} from "@cindy/device-link";
+import { useAuth } from "@/auth/AuthContext";
+import {
+ getMobileAuthOwner,
+ isMobileAuthOwnerCurrent,
+} from "@/auth/authOwnerGeneration";
+import { useDeviceLink } from "@/device-link/DeviceLinkContext";
+import { runMobilePluginAuthorization } from "@/plugins/pluginAuthorizationController";
+import { openMobilePluginOauthSession } from "@/plugins/pluginOauthSession";
+import { pluginOauthPlatformCrypto } from "@/plugins/pluginOauthPlatformCrypto";
+
+/**
+ * Sends one 代输入 step answer to the execution computer through the signed,
+ * end-to-end sealed v3 channel. The values never use the generic interaction
+ * resolve path, so they never enter the relay's plain payloads or any store.
+ *
+ * `submit` sends a prepared form answer. `openPicture` asks for the step's
+ * screenshot: it arrives inside the sealed offer, `answer` gets it, and the
+ * tap or typing it resolves with goes back on the same exchange.
+ */
+export function useInputHandoffSubmit(deviceId: string) {
+ const auth = useAuth(),
+ link = useDeviceLink(),
+ focused = useIsFocused();
+ const owner = useRef(getMobileAuthOwner()).current,
+ alive = useRef(true),
+ operation = useRef(0);
+ const live = useRef({ focused, epoch: link.connectionEpoch });
+ live.current = { focused, epoch: link.connectionEpoch };
+ useEffect(
+ () => () => {
+ alive.current = false;
+ operation.current++;
+ },
+ [],
+ );
+
+ const run = async (
+ snapshot: InputHandoffSnapshot,
+ answer:
+ | { submission: InputHandoffSubmission }
+ | { picture(picture: InputHandoffPicture): Promise<InputHandoffSubmission> },
+ ): Promise<void> => {
+ const peer = auth.deviceId;
+ if (!peer || !live.current.focused || AppState.currentState !== "active")
+ throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
+ const generation = ++operation.current,
+ epoch = link.connectionEpoch;
+ const assertCurrent = () => {
+ if (
+ !alive.current ||
+ generation !== operation.current ||
+ !isMobileAuthOwnerCurrent(owner) ||
+ !live.current.focused ||
+ live.current.epoch !== epoch
+ )
+ throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
+ };
+ const invoke = (raw: unknown, cleanup = false) =>
+ link.invoke(deviceId, PLUGIN_OAUTH_CHANNEL, [raw], {
+ preSend: () => {
+ if (cleanup) {
+ if (!isMobileAuthOwnerCurrent(owner) || live.current.epoch !== epoch)
+ throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
+ } else assertCurrent();
+ if (!cleanup && AppState.currentState !== "active")
+ throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
+ },
+ });
+ const action = {
+ requestId: snapshot.requestId,
+ actionId: INPUT_HANDOFF_ACTION_ID,
+ expectedRevision: snapshot.revision,
+ };
+ let pending: InputHandoffSubmission | undefined =
+ "submission" in answer ? answer.submission : undefined;
+ const client = await openMobilePluginOauthSession({
+ deviceId,
+ peer,
+ owner,
+ ghostId: INPUT_HANDOFF_GHOST_ID,
+ action,
+ invoke,
+ assertCurrent,
+ });
+ try {
+ await runMobilePluginAuthorization({
+ crypto: pluginOauthPlatformCrypto,
+ action,
+ kind: "input",
+ invoke: client.request,
+ assertCurrent,
+ inputPresentation: inputHandoffPresentation(snapshot),
+ inputSubmission: pending,
+ ...("picture" in answer ? { inputPicture: answer.picture } : {}),
+ clearInput: () => {
+ pending = undefined;
+ },
+ pause: async () => {
+ await new Promise((resolve) => setTimeout(resolve, 400));
+ while (AppState.currentState !== "active") {
+ assertCurrent();
+ await new Promise((resolve) => setTimeout(resolve, 600));
+ }
+ },
+ showAuthorization: async () => {
+ throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
+ },
+ });
+ } finally {
+ pending = undefined;
+ client.dispose();
+ }
+ };
+
+ return {
+ submit: (snapshot: InputHandoffSnapshot, submission: InputHandoffSubmission) =>
+ run(snapshot, { submission }),
+ openPicture: (
+ snapshot: InputHandoffSnapshot,
+ answer: (picture: InputHandoffPicture) => Promise<InputHandoffSubmission>,
+ ) => run(snapshot, { picture: answer }),
+ };
+}
diff --git a/apps/mobile/src/plugins/PluginSetupNativeForm.tsx b/apps/mobile/src/plugins/PluginSetupNativeForm.tsx
index 5ed3ad04e1..d5e1ce6def 100644
--- a/apps/mobile/src/plugins/PluginSetupNativeForm.tsx
+++ b/apps/mobile/src/plugins/PluginSetupNativeForm.tsx
@@ -11,13 +11,7 @@ import {
import { useIsFocused } from "expo-router";
import * as WebBrowser from "expo-web-browser";
import * as Clipboard from "expo-clipboard";
-import * as SecureStore from "expo-secure-store";
-import { pinMobilePluginIdentity } from "./pluginOauthPins";
-import { accountVaultKey } from "@cindy/auth-client";
-import {
- PLUGIN_OAUTH_CHANNEL,
- parsePluginOauthPeerIdentity,
-} from "@cindy/device-link";
+import { PLUGIN_OAUTH_CHANNEL } from "@cindy/device-link";
import { useTranslation } from "react-i18next";
import { Text, TextInput } from "@/components/AppText";
import { useAuth } from "@/auth/AuthContext";
@@ -38,7 +32,8 @@ import {
type ThemeColors,
} from "@/theme";
import { type MobilePluginSetupAction } from "./pluginSetupActions";
-import { authenticateMobilePluginOauth } from "./pluginOauthClient";
+import type { authenticateMobilePluginOauth } from "./pluginOauthClient";
+import { openMobilePluginOauthSession } from "./pluginOauthSession";
import { pluginOauthPlatformCrypto } from "./pluginOauthPlatformCrypto";
import { runMobilePluginAuthorization } from "./pluginAuthorizationController";
@@ -152,38 +147,14 @@ export default function PluginSetupNativeForm({
let client:
Awaited<ReturnType<typeof authenticateMobilePluginOauth>> | undefined;
try {
- const target = parsePluginOauthPeerIdentity(
- await invoke({ op: "identity", version: 3 }),
- );
- assertCurrent();
- if (
- target.deviceId !== deviceId ||
- target.membershipId !== owner.accountId ||
- accountVaultKey(target.realm, target.membershipId) !== owner.accountKey
- )
- throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
- client = await authenticateMobilePluginOauth({
- crypto: pluginOauthPlatformCrypto,
- target,
+ client = await openMobilePluginOauthSession({
+ deviceId,
peer: auth.deviceId,
+ owner,
ghostId: action.ghostId,
action: action.action,
- assertCurrent,
invoke,
- trustIdentity: (identity, check) =>
- pinMobilePluginIdentity(
- {
- get: (key) => SecureStore.getItemAsync(key),
- set: (key, value) =>
- SecureStore.setItemAsync(key, value, {
- keychainAccessible:
- SecureStore.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
- }),
- },
- identity,
- auth.deviceId!,
- check,
- ),
+ assertCurrent,
});
await runMobilePluginAuthorization({
crypto: pluginOauthPlatformCrypto,
diff --git a/apps/mobile/src/plugins/pluginAuthorizationController.ts b/apps/mobile/src/plugins/pluginAuthorizationController.ts
index 3fc132cb25..cd4d2a51ea 100644
--- a/apps/mobile/src/plugins/pluginAuthorizationController.ts
+++ b/apps/mobile/src/plugins/pluginAuthorizationController.ts
@@ -9,6 +9,12 @@ import {
parsePluginConnectionInput,
parsePluginAuthorizationOffer,
parsePluginDeviceOffer,
+ parseInputHandoffOffer,
+ parseInputHandoffPresentation,
+ parseInputHandoffValueReply,
+ type InputHandoffPicture,
+ type InputHandoffPresentation,
+ type InputHandoffSubmission,
type PluginOauthRequest,
type PluginOauthAction,
type PluginSecretPresentation,
@@ -25,8 +31,13 @@ export async function runMobilePluginAuthorization(deps: {
crypto: PluginOauthCrypto;
invoke(request: PluginOauthRequest): Promise<unknown>;
action: PluginOauthAction;
- kind: "oauth" | "secret" | "connection";
+ kind: "oauth" | "secret" | "connection" | "input";
secretPresentation?: PluginSecretPresentation;
+ /** 代输入: the exact step the owner answered, and the answer. */
+ inputPresentation?: InputHandoffPresentation;
+ inputSubmission?: InputHandoffSubmission;
+ /** 代输入 screenshot step: show the sealed picture, then return the owner's tap or typing. */
+ inputPicture?(picture: InputHandoffPicture): Promise<InputHandoffSubmission>;
connectionPresentation?: PluginConnectionPresentation;
inputSecret?: string;
inputConnection?: { host: string; token: string };
@@ -53,7 +64,8 @@ export async function runMobilePluginAuthorization(deps: {
caps.encrypted !== true ||
caps.callback !== "desktop-loopback" ||
(deps.kind === "secret" && caps.secretSubmission !== true) ||
- (deps.kind === "connection" && caps.connectionSubmission !== true)
+ (deps.kind === "connection" && caps.connectionSubmission !== true) ||
+ (deps.kind === "input" && caps.inputHandoff !== true)
)
throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
deps.assertCurrent();
@@ -72,6 +84,7 @@ export async function runMobilePluginAuthorization(deps: {
...(deps.kind === "connection"
? { connectionSubmission: true as const }
: {}),
+ ...(deps.kind === "input" ? { inputHandoff: true as const } : {}),
}),
);
if (!oauthId(start.id) || !oauthPublicKey(start.publicKey))
@@ -85,6 +98,7 @@ export async function runMobilePluginAuthorization(deps: {
deps.clearInput();
deps.inputSecret = undefined;
deps.inputConnection = undefined;
+ deps.inputSubmission = undefined;
deps.assertCurrent();
const result = object(
await deps.invoke({ op: "callback", id: id!, box }),
@@ -110,7 +124,35 @@ export async function runMobilePluginAuthorization(deps: {
if (typeof status.offer !== "string")
throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
const raw = object(await key.open(peerKey, id, "offer", status.offer));
- if (deps.kind === "secret") {
+ if (deps.kind === "input") {
+ if (
+ raw.kind !== "input-entry" ||
+ !deps.inputPresentation ||
+ (!deps.inputSubmission && !deps.inputPicture)
+ )
+ throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
+ const offer = parseInputHandoffOffer(raw);
+ // The owner answered exactly this step; anything else is a newer screen.
+ if (
+ JSON.stringify(offer.presentation) !==
+ JSON.stringify(parseInputHandoffPresentation(deps.inputPresentation))
+ )
+ throw new Error("INPUT_HANDOFF_STALE");
+ if (offer.picture) {
+ // Only a caller that asked for this step's picture receives it; a prepared form answer never does.
+ if (!deps.inputPicture || deps.inputSubmission)
+ throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
+ deps.inputSubmission = await deps.inputPicture(offer.picture);
+ deps.assertCurrent();
+ }
+ await deliver(
+ parseInputHandoffValueReply({
+ kind: "input-value",
+ state: offer.state,
+ submission: deps.inputSubmission,
+ }),
+ );
+ } else if (deps.kind === "secret") {
const offer = parsePluginSecretOffer(raw);
if (
JSON.stringify(offer.presentation) !==
@@ -174,6 +216,7 @@ export async function runMobilePluginAuthorization(deps: {
deps.clearInput();
deps.inputSecret = undefined;
deps.inputConnection = undefined;
+ deps.inputSubmission = undefined;
if (!finished && id)
await deps.invoke({ op: "cancel", id }).catch(() => {});
key.dispose();
diff --git a/apps/mobile/src/plugins/pluginOauthCrypto.ts b/apps/mobile/src/plugins/pluginOauthCrypto.ts
index c47228840e..f7ba649477 100644
--- a/apps/mobile/src/plugins/pluginOauthCrypto.ts
+++ b/apps/mobile/src/plugins/pluginOauthCrypto.ts
@@ -1,6 +1,7 @@
import { ed25519, x25519 } from "@noble/curves/ed25519";
import { hkdf } from "@noble/hashes/hkdf";
import { sha256 } from "@noble/hashes/sha256";
+import { PLUGIN_OAUTH_SEALED_MAX_BYTES, isPluginOauthBox } from "@cindy/device-link";
/** Bounded UTF-8 helpers work without TextEncoder/TextDecoder on Hermes. */
export function oauthUtf8Bytes(value: string): Uint8Array {
const encoded = encodeURIComponent(value),
@@ -14,6 +15,13 @@ export function oauthUtf8Bytes(value: string): Uint8Array {
return Uint8Array.from(bytes);
}
function oauthUtf8Text(bytes: Uint8Array): string {
+ // Sealed offers can carry a screenshot; plain ASCII skips the escape round trip.
+ if (bytes.every((byte) => byte < 0x80)) {
+ const parts: string[] = [];
+ for (let i = 0; i < bytes.length; i += 8192)
+ parts.push(String.fromCharCode(...bytes.subarray(i, i + 8192)));
+ return parts.join("");
+ }
return decodeURIComponent(
Array.from(bytes, (byte) => "%" + byte.toString(16).padStart(2, "0")).join(
"",
@@ -37,7 +45,10 @@ export interface PluginOauthCrypto {
}
const alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+const alphabetIndex = new Int16Array(128).fill(-1);
+for (let i = 0; i < alphabet.length; i++) alphabetIndex[alphabet.charCodeAt(i)] = i;
export function encodeOauthBytes(bytes: Uint8Array): string {
+ const parts: string[] = [];
let result = "";
for (let i = 0; i < bytes.length; i += 3) {
const a = bytes[i],
@@ -46,8 +57,13 @@ export function encodeOauthBytes(bytes: Uint8Array): string {
result += alphabet[a >> 2] + alphabet[((a & 3) << 4) | ((b ?? 0) >> 4)];
if (b !== undefined) result += alphabet[((b & 15) << 2) | ((c ?? 0) >> 6)];
if (c !== undefined) result += alphabet[c & 63];
+ if (result.length >= 8192) {
+ parts.push(result);
+ result = "";
+ }
}
- return result;
+ parts.push(result);
+ return parts.join("");
}
export function decodeOauthBytes(value: string): Uint8Array {
if (!/^[A-Za-z0-9_-]+$/.test(value) || value.length % 4 === 1)
@@ -56,8 +72,8 @@ export function decodeOauthBytes(value: string): Uint8Array {
let bits = 0,
accumulated = 0,
at = 0;
- for (const c of value) {
- accumulated = (accumulated << 6) | alphabet.indexOf(c);
+ for (let i = 0; i < value.length; i++) {
+ accumulated = ((accumulated << 6) | alphabetIndex[value.charCodeAt(i)]) & 0xffffff;
bits += 6;
if (bits >= 8) {
bits -= 8;
@@ -134,7 +150,8 @@ export class MobileOauthBox {
const key = this.key(peer, id, direction),
body = oauthUtf8Bytes(JSON.stringify(value));
try {
- if (body.length > 32000) throw new Error("OAUTH_BRIDGE_INVALID");
+ if (body.length > PLUGIN_OAUTH_SEALED_MAX_BYTES[direction])
+ throw new Error("OAUTH_BRIDGE_INVALID");
return encodeOauthBytes(
await this.crypto.encrypt(
key,
@@ -156,14 +173,14 @@ export class MobileOauthBox {
): Promise<unknown> {
let key: Uint8Array | undefined, body: Uint8Array | undefined;
try {
- if (!/^[A-Za-z0-9_-]{40,48000}$/.test(box)) throw 0;
+ if (!isPluginOauthBox(direction, box)) throw 0;
key = this.key(peer, id, direction);
body = await this.crypto.decrypt(
key,
decodeOauthBytes(box),
oauthUtf8Bytes(`cindy-plugin-oauth-v1:${id}:${direction}`),
);
- if (body.length > 32000) throw 0;
+ if (body.length > PLUGIN_OAUTH_SEALED_MAX_BYTES[direction]) throw 0;
return JSON.parse(oauthUtf8Text(body));
} catch {
throw new Error("OAUTH_BRIDGE_INVALID");
diff --git a/apps/mobile/src/plugins/pluginOauthSession.ts b/apps/mobile/src/plugins/pluginOauthSession.ts
new file mode 100644
index 0000000000..c9d2a6bea9
--- /dev/null
+++ b/apps/mobile/src/plugins/pluginOauthSession.ts
@@ -0,0 +1,59 @@
+import * as SecureStore from "expo-secure-store";
+import { accountVaultKey } from "@cindy/auth-client";
+import {
+ parsePluginOauthPeerIdentity,
+ type PluginOauthAction,
+} from "@cindy/device-link";
+import type { MobileAuthOwnerGeneration } from "@/auth/authOwnerGeneration";
+import { authenticateMobilePluginOauth } from "./pluginOauthClient";
+import { pinMobilePluginIdentity } from "./pluginOauthPins";
+import { pluginOauthPlatformCrypto } from "./pluginOauthPlatformCrypto";
+
+/**
+ * Verifies the execution computer belongs to this account, pins its identity,
+ * and opens the signed v3 channel for one action. Shared by plugin setup and
+ * 代输入 so both use the exact same trust path.
+ */
+export async function openMobilePluginOauthSession(input: {
+ deviceId: string;
+ peer: string;
+ owner: MobileAuthOwnerGeneration;
+ ghostId: string;
+ action: PluginOauthAction;
+ invoke(raw: unknown, cleanup?: boolean): Promise<unknown>;
+ assertCurrent(): void;
+}) {
+ const target = parsePluginOauthPeerIdentity(
+ await input.invoke({ op: "identity", version: 3 }),
+ );
+ input.assertCurrent();
+ if (
+ target.deviceId !== input.deviceId ||
+ target.membershipId !== input.owner.accountId ||
+ accountVaultKey(target.realm, target.membershipId) !==
+ input.owner.accountKey
+ )
+ throw new Error("OAUTH_BRIDGE_UNAVAILABLE");
+ return authenticateMobilePluginOauth({
+ crypto: pluginOauthPlatformCrypto,
+ target,
+ peer: input.peer,
+ ghostId: input.ghostId,
+ action: input.action,
+ assertCurrent: input.assertCurrent,
+ invoke: input.invoke,
+ trustIdentity: (identity, check) =>
+ pinMobilePluginIdentity(
+ {
+ get: (key) => SecureStore.getItemAsync(key),
+ set: (key, value) =>
+ SecureStore.setItemAsync(key, value, {
+ keychainAccessible: SecureStore.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
+ }),
+ },
+ identity,
+ input.peer,
+ check,
+ ),
+ });
+}
diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx
index d514b432d4..7280257550 100644
--- a/apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx
+++ b/apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx
@@ -65,7 +65,7 @@ export function RemoteDesktopToolbar(props: ComponentProps<typeof Toolbar>) {
const { t } = useTranslation();
const groupStyle = useNativeGlassGroupStyle("clear");
const glass = useLiquidGlassAvailable();
- const actions = [
+ const allActions = [
{
key: props.onWorkspaceLeft ? "workspaceLeft" : "allWindows",
Icon: props.onWorkspaceLeft ? WorkspaceLeftIcon : AllWindowsIcon,
@@ -106,6 +106,10 @@ export function RemoteDesktopToolbar(props: ComponentProps<typeof Toolbar>) {
selected: props.operations,
},
];
+ // 代输入 window view: no desktop to navigate, so only keyboard and settings.
+ const actions = props.windowOnly
+ ? allActions.filter(({ key }) => key === "keyboard" || key === "operations")
+ : allActions;
const length = target * actions.length + inset * 2;
const Stack = props.landscape ? VStack : HStack;
return (
diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx
index 9abeb7f58c..b0c7327fc7 100644
--- a/apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx
+++ b/apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx
@@ -41,6 +41,7 @@ export function RemoteDesktopToolbar({
onWorkspaceLeft,
onWorkspaceRight,
onOmarchyMenu,
+ windowOnly,
}: {
landscape: boolean;
canControl: boolean;
@@ -53,6 +54,8 @@ export function RemoteDesktopToolbar({
onWorkspaceLeft?: () => void;
onWorkspaceRight?: () => void;
onOmarchyMenu?: () => void;
+ /** 代输入 window view: no desktop to navigate, so only keyboard and settings. */
+ windowOnly?: boolean;
}) {
const { t } = useTranslation();
const { colors } = useTheme();
@@ -100,12 +103,16 @@ export function RemoteDesktopToolbar({
selected: operations,
},
];
+ // 代输入 window view: no desktop to navigate, so only keyboard and settings.
+ const shown = windowOnly
+ ? actions.filter(({ key }) => key === "keyboard" || key === "operations")
+ : actions;
return (
<View
style={[styles.toolbar, landscape && styles.rail]}
testID="remoteDesktop.toolbar"
>
- {(landscape ? [...actions].reverse() : actions).map(
+ {(landscape ? [...shown].reverse() : shown).map(
({ key, icon: Icon, press, selected, disabled }) => (
<RemoteDesktopActionButton
key={key}
diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx
index 0456bf1dfe..03a9ca2841 100644
--- a/apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx
+++ b/apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx
@@ -12,7 +12,13 @@ import { NativeRemoteDesktopView } from "./NativeRemoteDesktopView";
import { RemoteDesktopSession } from "./RemoteDesktopScreen";
import { logDesktopNavigation } from "./remoteDesktopNavigationDebug";
-type Session = { account: string; deviceId: string; deviceName: string };
+type Session = {
+ account: string;
+ deviceId: string;
+ deviceName: string;
+ /** 代输入 live view of one window; a different request is a different viewer. */
+ handoff?: string;
+};
/** One connected viewer survives its route, but never its signed-in owner. */
export function RemoteDesktopHost({ children }: { children: ReactNode }) {
@@ -22,7 +28,7 @@ export function RemoteDesktopHost({ children }: { children: ReactNode }) {
const rootState = useNavigationState((state) => state);
const route = activeDesktopRoute(rootState);
const params = route?.params as
- { deviceId?: string; deviceName?: string } | undefined;
+ { deviceId?: string; deviceName?: string; handoff?: string } | undefined;
const account =
auth.isAuthenticated && auth.user?.id
? `${auth.user.id}:${auth.accountGeneration}`
@@ -32,6 +38,10 @@ export function RemoteDesktopHost({ children }: { children: ReactNode }) {
inDesktop && typeof params?.deviceId === "string" ? params.deviceId : "";
const routeName =
typeof params?.deviceName === "string" ? params.deviceName : routeDevice;
+ const routeHandoff =
+ inDesktop && typeof params?.handoff === "string" && params.handoff
+ ? params.handoff
+ : undefined;
const [session, setSession] = useState<Session | null>(null);
const [visible, setVisible] = useState(true);
const restorePending = useRef<Session | null>(null);
@@ -42,14 +52,21 @@ export function RemoteDesktopHost({ children }: { children: ReactNode }) {
}
if (routeDevice) {
setSession((current) =>
- current?.account === account && current.deviceId === routeDevice
+ current?.account === account &&
+ current.deviceId === routeDevice &&
+ current.handoff === routeHandoff
? current
- : { account, deviceId: routeDevice, deviceName: routeName },
+ : {
+ account,
+ deviceId: routeDevice,
+ deviceName: routeName,
+ ...(routeHandoff ? { handoff: routeHandoff } : {}),
+ },
);
setVisible(true);
} else
setSession((current) => (current?.account === account ? current : null));
- }, [account, routeDevice, routeName]);
+ }, [account, routeDevice, routeName, routeHandoff]);
const current = session?.account === account ? session : null;
const owner = useRef(current);
owner.current = current;
@@ -101,9 +118,10 @@ export function RemoteDesktopHost({ children }: { children: ReactNode }) {
collapsable={false}
>
<RemoteDesktopSession
- key={`${current.account}:${current.deviceId}`}
+ key={`${current.account}:${current.deviceId}:${current.handoff ?? ""}`}
deviceId={current.deviceId}
deviceName={current.deviceName}
+ handoff={current.handoff}
focused={routeDevice === current.deviceId}
onBack={() => {
logDesktopNavigation("back callback", navigation.getRootState(), {
@@ -167,6 +185,7 @@ export function RemoteDesktopHost({ children }: { children: ReactNode }) {
params: {
deviceId: current.deviceId,
deviceName: current.deviceName,
+ ...(current.handoff ? { handoff: current.handoff } : {}),
},
});
}}
diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx
index 5e1c618809..a9133d8848 100644
--- a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx
+++ b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx
@@ -198,12 +198,14 @@ const LABELS: Record<string, string> = {
};
export default function RemoteDesktopScreen() {
- const { deviceId: rawId, deviceName: rawName } = useLocalSearchParams<{
+ const { deviceId: rawId, deviceName: rawName, handoff: rawHandoff } = useLocalSearchParams<{
deviceId: string;
deviceName?: string;
+ handoff?: string;
}>();
const deviceId = typeof rawId === "string" ? rawId : "";
const deviceName = typeof rawName === "string" ? rawName : deviceId;
+ const handoff = typeof rawHandoff === "string" && rawHandoff ? rawHandoff : undefined;
const router = useRouter();
const focused = useIsFocused();
return (
@@ -218,6 +220,7 @@ export default function RemoteDesktopScreen() {
<RemoteDesktopSession
deviceId={deviceId}
deviceName={deviceName}
+ handoff={handoff}
focused={focused}
onBack={() => goBackGuarded(router)}
/>
@@ -228,6 +231,7 @@ export default function RemoteDesktopScreen() {
export function RemoteDesktopSession({
deviceId,
deviceName,
+ handoff,
focused,
onBack,
onRestore,
@@ -236,6 +240,8 @@ export function RemoteDesktopSession({
}: {
deviceId: string;
deviceName: string;
+ /** 代输入 live view: only the window this waiting request is about (the host picks it). */
+ handoff?: string;
focused: boolean;
onBack(): void;
onRestore?(): void;
@@ -1122,6 +1128,7 @@ export function RemoteDesktopSession({
displayId: displayId ?? recovery.current.displayId,
resume: resuming,
takeover,
+ ...(handoff ? { handoff } : {}),
// Hosts with `autoControl` grant control with the lease.
control: wantsControl.current,
onStart: () => {
@@ -1132,7 +1139,8 @@ export function RemoteDesktopSession({
mark("capabilities");
capsRef.current = { deviceId, value: result };
setHostCaps({ deviceId, value: result });
- if (supportsAutoUnlock(result.platform)) {
+ // A window view never unlocks the computer: it shows a window on an unlocked desktop.
+ if (!handoff && supportsAutoUnlock(result.platform)) {
// Linux capture may be unavailable until its locker releases the session.
if (result.platform === "linux") {
return securityRef.current.maybeUnlock(async () => {
@@ -1247,6 +1255,7 @@ export function RemoteDesktopSession({
[
deviceId,
fail,
+ handoff,
landscape,
mode,
request,
@@ -3310,10 +3319,10 @@ export function RemoteDesktopSession({
<RemoteDesktopPanel
railAnchor={systemSideRail ? {
right: (sideRailWidth - navigationChrome.target) / 2,
- top: (sideRailTop + navigationChrome.target + spacing.lg + windowSize.height - insets.bottom - navigationChrome.target * (caps?.omarchyMenu ? 5 : 4)) / 2,
+ top: (sideRailTop + navigationChrome.target + spacing.lg + windowSize.height - insets.bottom - navigationChrome.target * (handoff ? 2 : caps?.omarchyMenu ? 5 : 4)) / 2,
} : undefined}
toolbarOnLeft={toolbarOnLeft}
- toolbarActionCount={caps?.omarchyMenu ? 5 : 4}
+ toolbarActionCount={handoff ? 2 : caps?.omarchyMenu ? 5 : 4}
visible={operations && focused}
landscape={landscape}
topInset={edgePadding.paddingTop}
@@ -3326,7 +3335,7 @@ export function RemoteDesktopSession({
? undefined
: () => setControlPage("controls")
}
- caption={`${deviceName} · ${showConnectionStatus ? connectionLabel : t(`remoteDesktop.${status}`)}`}
+ caption={`${lease?.window ? t("remoteDesktop.handoffWindow", { app: lease.window.app }) : deviceName} · ${showConnectionStatus ? connectionLabel : t(`remoteDesktop.${status}`)}`}
onClose={() => setOperations(false)}
footer={
<RemoteDesktopDisconnect onPress={() => void leave()} />
@@ -3395,7 +3404,7 @@ export function RemoteDesktopSession({
onResolution: changeResolution,
}}
inputMode={inputMode}
- displays={caps?.displays ?? []}
+ displays={handoff ? [] : (caps?.displays ?? [])}
displayId={recovery.current.displayId ?? lease?.display.id}
onViewOnly={() => void toggleControl()}
onInputMode={(value) => {
@@ -3493,6 +3502,7 @@ export function RemoteDesktopSession({
>
<RemoteDesktopToolbar
landscape={landscape || systemSideRail}
+ windowOnly={Boolean(handoff)}
onWorkspaceLeft={
caps?.workspaceNavigation
? () => workspaceAction("workspaceLeft")
diff --git a/apps/mobile/src/remote-desktop/__tests__/host.test.tsx b/apps/mobile/src/remote-desktop/__tests__/host.test.tsx
index 5143e24a0d..72b7194e25 100644
--- a/apps/mobile/src/remote-desktop/__tests__/host.test.tsx
+++ b/apps/mobile/src/remote-desktop/__tests__/host.test.tsx
@@ -130,6 +130,27 @@ describe.each([false, true])(
expect(host.querySelector('[data-pointer-events="auto"]')).not.toBeNull();
expect(fixture.resetRoot).not.toHaveBeenCalled();
});
+ it("opens a 代输入 window view as its own viewer and restores it as the same view", () => {
+ const windowView = {
+ key: "desktop-w",
+ name: REMOTE_DESKTOP_ROUTE,
+ params: { deviceId: "computer", deviceName: "Computer", handoff: "req1" },
+ };
+ fixture.state = stack(home, windowView);
+ render();
+ expect(fixture.props.handoff).toBe("req1");
+ // The whole-desktop viewer of the same computer is replaced, not reused.
+ expect(fixture.stopped).toHaveBeenCalledOnce();
+ expect(fixture.mounted).toHaveBeenCalledTimes(2);
+ act(() => fixture.props.onBack());
+ render();
+ fixture.props.onRestore();
+ expect(fixture.push).toHaveBeenCalledWith(
+ expect.objectContaining({
+ params: { deviceId: "computer", deviceName: "Computer", handoff: "req1" },
+ }),
+ );
+ });
it("retains one mounted viewer across back and fullscreen restoration", () => {
act(() => fixture.props.onBack());
render();
diff --git a/apps/mobile/src/session/InteractionPanel.tsx b/apps/mobile/src/session/InteractionPanel.tsx
index 129719f8d7..4dae68e125 100644
--- a/apps/mobile/src/session/InteractionPanel.tsx
+++ b/apps/mobile/src/session/InteractionPanel.tsx
@@ -1,4 +1,6 @@
import { PluginSetupNativeActions } from '@/plugins/PluginSetupNativeActions';
+import { InputHandoffCard } from '@/inputHandoff/InputHandoffCard';
+import { parseInputHandoffSnapshotLike } from '@/inputHandoff/inputHandoffNative';
import { mobilePluginSetupActions } from '@/plugins/pluginSetupActions';
import { usePaneViewport } from '@/platform/AdaptiveWindowContext';
import { createContext, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
@@ -107,6 +109,7 @@ const LOCALIZED_INTERACTION_KINDS = new Set([
'rename_sessions_confirm',
'ghost_grant_confirm',
'plugin_setup',
+ 'input_handoff',
]);
function localizedInteractionKindKey(kind: string): string {
@@ -348,12 +351,15 @@ function InteractionPanelContent({
}
return (
<View style={[styles.root, fillAvailableHeight && styles.rootFill, rootLayoutStyle]} testID="interaction.panel">
- <PendingTaskHeader
- onCollapse={canToggleCollapsed ? toggleCollapsed : undefined}
- onSelectRequest={setActiveRequestId}
- presentation={activeQueuePresentation}
- touchLayout={touchLayout}
- />
+ {/* 代输入条自带用途与位置,单独一条时不再叠一层队列头。 */}
+ {kind === 'input_handoff' && activeQueuePresentation.totalCount <= 1 ? null : (
+ <PendingTaskHeader
+ onCollapse={canToggleCollapsed ? toggleCollapsed : undefined}
+ onSelectRequest={setActiveRequestId}
+ presentation={activeQueuePresentation}
+ touchLayout={touchLayout}
+ />
+ )}
<InteractionItem
key={readRequestId(activeInteraction) ?? `${interactionKind(activeInteraction)}-${JSON.stringify(activeInteraction.request)}`}
deviceId={deviceId}
@@ -634,6 +640,34 @@ function InteractionItem({
/>
);
}
+ // 代输入: values go through the sealed per-step channel inside the card;
+ // value-less decisions use resolve and wait for the Host's next snapshot.
+ if (kind === 'input_handoff') {
+ const snapshot = parseInputHandoffSnapshotLike(item.request);
+ if (!snapshot || !deviceId || isSharedTaskPeer(deviceId)) {
+ return (
+ <UnsupportedCard
+ message={t('interaction.panel.unsupportedType')}
+ request={item.request}
+ touchLayout={touchLayout}
+ />
+ );
+ }
+ return (
+ <InputHandoffCard
+ key={snapshot.requestId}
+ deviceId={deviceId}
+ snapshot={snapshot}
+ decisionBusy={busy}
+ onDecision={(decision) => void submitDecision(decision, { optimisticDismiss: false })}
+ // Claiming on first keystroke must not mark the card busy (that would
+ // disable the field being typed in); a failed claim is harmless.
+ onQuietDecision={(decision) => {
+ if (requestId) void resolveInteractionResilient(maker, sessionId, requestId, decision).catch(() => undefined);
+ }}
+ />
+ );
+ }
// 配置通过独立加密 v3 原生入口;通用交互 resolve 仍只允许取消。
// 旧 Host、共享访客及电脑本地回调保留电脑入口。
if (kind === 'plugin_setup') {
diff --git a/apps/mobile/src/session/MessageRenderer.tsx b/apps/mobile/src/session/MessageRenderer.tsx
index 1946686750..278e676ce8 100644
--- a/apps/mobile/src/session/MessageRenderer.tsx
+++ b/apps/mobile/src/session/MessageRenderer.tsx
@@ -27,6 +27,7 @@ import { errorText, resolvedUrlKind } from '@/debug/fileDiagnostics';
import { createContext, Fragment, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, type ComponentProps, type Dispatch, type ReactNode, type SetStateAction } from 'react';
import { useTranslation } from 'react-i18next';
import { MessageLoadingImage, MessageImagePlaceholder } from './MessageLoadingImage';
+import { InputHandoffRecordRow } from '@/inputHandoff/InputHandoffRecordRow';
import {
ArrowLeftRight,
Bot,
@@ -5384,6 +5385,7 @@ function MobileSystemCard({
}
// agent-switch 走专用「分隔线 + 药丸」渲染(对齐桌面),不落通用盒子卡片。
if (type === 'agent-switch') return <MobileAgentSwitchCard data={data} />;
+ if (type === 'input-handoff') return <InputHandoffRecordRow data={data} />;
// auto-resume 复用桌面 AgentActionRow 的单行状态布局:默认只显示当前状态和压缩后的
// 中断原因,完整诊断按需展开,避免底层错误全文把手机消息流撑成一张大卡片。
if (type === 'auto-resume') {
diff --git a/apps/mobile/src/session/messageNormalize.ts b/apps/mobile/src/session/messageNormalize.ts
index 71a7a1dd38..bd3dec8b64 100644
--- a/apps/mobile/src/session/messageNormalize.ts
+++ b/apps/mobile/src/session/messageNormalize.ts
@@ -21,7 +21,7 @@ import {
normalizeAgentTaskTerminalStatus,
type AgentTaskTerminalStatus,
} from '@cindy/maker-shared/agent-task';
-import { isSyntheticTriggerText } from '@cindy/maker-shared/synthetic-trigger';
+import { isSyntheticTriggerText, parseInputHandoffEndRecord } from '@cindy/maker-shared/synthetic-trigger';
import {
isHookSchedulerOrigin,
readMessageSourceDevice,
@@ -530,6 +530,24 @@ export function normalizeRemoteMessages(
const userContent = message.role === 'user' ? parseUserContent(message.content) : null;
// 合成 UI 指令行(隐藏续跑 prompt 等):打标 + body 置空,不渲染但保留 turn 边界。
if (userContent && isSyntheticTriggerText(userContent.text)) {
+ const handoffRecord = parseInputHandoffEndRecord(userContent.text);
+ if (handoffRecord) {
+ // 代输入结束:只留一条无值的记录行(对齐桌面),turn 边界照旧。
+ result.push({
+ key: messageNormalizeKey(message),
+ source: message,
+ kind: 'user',
+ role: message.role,
+ label: 'user',
+ body: '',
+ systemCardType: 'input-handoff',
+ isSyntheticTrigger: true,
+ systemCardData: { ...handoffRecord, at: message.createdAt },
+ align: 'agent',
+ createdAt: message.createdAt,
+ });
+ continue;
+ }
result.push({
key: messageNormalizeKey(message),
source: message,
diff --git a/apps/mobile/src/session/systemCard.ts b/apps/mobile/src/session/systemCard.ts
index c2708bb340..199039f8bd 100644
--- a/apps/mobile/src/session/systemCard.ts
+++ b/apps/mobile/src/session/systemCard.ts
@@ -34,7 +34,9 @@ export type MobileSystemCardType =
| 'auto-resume'
| 'learn'
// session-agent-switch 边界卡(desktop 落库 role='agent_switch',读侧派生)。
- | 'agent-switch';
+ | 'agent-switch'
+ // 代输入结束留痕(隐藏续接行派生)。
+ | 'input-handoff';
export type MobileSystemCardPresentation = SystemCardPresentation;
/** goal 达成记录文案(对齐桌面 GoalCompleteCard 的 goal.complete.record)。 */
@@ -102,7 +104,7 @@ export function buildMobileSystemCardData(
): Record<string, unknown> {
// goal / auto-resume / agent-switch 卡的数据由桌面落库行派生,learn 卡的数据由
// 发送侧 buildLearnCardData 直接组装,都不走本地 slash 命令的数据组装。
- if (type === 'goal-complete' || type === 'goal-resumed' || type === 'context-rebuild' || type === 'auto-resume' || type === 'learn' || type === 'agent-switch') return {};
+ if (type === 'goal-complete' || type === 'goal-resumed' || type === 'context-rebuild' || type === 'auto-resume' || type === 'learn' || type === 'agent-switch' || type === 'input-handoff') return {};
return buildSystemCardData(type, {
...options,
localCommands: MOBILE_LOCAL_SYSTEM_COMMANDS,
@@ -132,6 +134,8 @@ export function formatMobileSystemCard(
if (type === 'auto-resume') return formatAutoResumeCard(data);
if (type === 'agent-switch') return formatAgentSwitchCard(data);
if (type === 'learn') return formatLearnCard(data);
+ // 代输入留痕由 InputHandoffRecordRow 渲染,不走通用卡片。
+ if (type === 'input-handoff') return { title: '', rows: [] };
return formatSystemCard(type, data);
}
diff --git a/apps/mobile/src/session/types.ts b/apps/mobile/src/session/types.ts
index 0fea7529f2..0325fc2f93 100644
--- a/apps/mobile/src/session/types.ts
+++ b/apps/mobile/src/session/types.ts
@@ -146,7 +146,9 @@ export interface RemoteMessage {
mobileToolInputProjection?: MobileToolInputProjection;
systemCardData?: Record<string, unknown>;
systemCardType?:
- | 'help' | 'context' | 'cost' | 'pwd' | 'status' | 'compact' | 'cmd' | 'goal-complete' | 'goal-resumed' | 'context-rebuild' | 'auto-resume' | 'learn' | 'agent-switch';
+ | 'help' | 'context' | 'cost' | 'pwd' | 'status' | 'compact' | 'cmd' | 'goal-complete' | 'goal-resumed' | 'context-rebuild' | 'auto-resume' | 'learn' | 'agent-switch'
+ /** 代输入结束留痕(由隐藏续接行派生,无输入值)。 */
+ | 'input-handoff';
}
export type RemoteAttachmentCategory = 'image' | 'pdf' | 'text' | 'office' | 'file';
diff --git a/docs/design-rules/design-inventory.md b/docs/design-rules/design-inventory.md
index 1a61db6441..8401a4cd86 100644
--- a/docs/design-rules/design-inventory.md
+++ b/docs/design-rules/design-inventory.md
@@ -54,10 +54,10 @@
| `mobile.account-deletion` | mobile | 账号注销 | app/account-deletion.tsx | AdaptiveWindow, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ClipboardSharedTaskPrompt, CompanionNativeContent.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceLinkContext, FoldTouchpad, HomeEntryProvider, HomeHeaderGlassButton, HomeHeaderGlassButton.ios, HomeNativeStackHeader, HomeStackHeader, IncomingShareBridge, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileOutboxBridge, MobilePrimitives, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, OutsideTap, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PushNotificationsBridge, QuietSyncIndicator, RecentMessageHistories, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, ResidentHomeList, SharedTaskAdmissionDialog, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, ThemeProvider, _layout, account-deletion, gestureHandler, nativeToolbarMenuItems, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/account-deletion.tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/HomeStackHeader.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/nativeToolbarMenuItems.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeHeaderGlassButton.ios.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 214 | 62 |
| `mobile.auth` | mobile | 登录与添加账号 | app/(auth)/login.tsx / app/add-account.tsx | AccountSwitcherSheet, AdaptiveWindow, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ClipboardSharedTaskPrompt, CompanionNativeContent.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceLinkContext, FoldTouchpad, HomeEntryProvider, HomeHeaderGlassButton, HomeHeaderGlassButton.ios, IncomingShareBridge, LoginCaptchaWebView, LoginNativeButton, LoginNativeButton.ios, LoginSkinControls, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileOutboxBridge, MobilePrimitives, MobileUserAvatar, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, OutsideTap, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PushNotificationsBridge, QuietSyncIndicator, RecentMessageHistories, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, ResidentHomeList, SharedTaskAdmissionDialog, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, SystemNavigationBack, ThemeProvider, _layout, add-account, gestureHandler, login, peerFileTransport, useLocale | apps/mobile/app/(auth)/login.tsx, apps/mobile/app/_layout.tsx, apps/mobile/app/add-account.tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/LoginCaptchaWebView.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/LoginNativeButton.ios.tsx, apps/mobile/src/components/LoginNativeButton.tsx, apps/mobile/src/components/LoginSkinControls.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/MobileUserAvatar.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/SystemNavigationBack.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/AccountSwitcherSheet.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeHeaderGlassButton.ios.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 221 | 84 |
| `mobile.chat.new` | mobile | 新建任务 | app/sessions/new.tsx | AdaptiveWindow, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AnnotationBurnInWebView, AppText, AuthContext, BlurBackdrop, CenteredScreen, ClipboardSharedTaskPrompt, CompanionNativeContent.ios, ComposerActivityPill, ComposerAttachmentTray, ComposerDockKeyboardFollow, ComposerFrame, ComposerFrame.ios, ComposerKeyboardAvoidingView, ComposerNativeRow, ComposerNativeRow.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, ContextSheetCollabView, ContextSheetGoalView, ContextSheetGoalView.ios, ContextSheetMediaViews, ContextSheetPlugins, DeviceLinkContext, FileTypeIcon, FoldTouchpad, HomeEntryProvider, HomeHeaderGlassButton, HomeHeaderGlassButton.ios, HomeNativeStackHeader, HomeStackHeader, ImageLightbox, IncomingShareBridge, MobileAgentMark, MobileAgentSwitcher, MobileChoicePickerList, MobileComposerInputRow, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileModelPickerList, MobileModelPickerList.ios, MobileOutboxBridge, MobilePermissionPickerList, MobilePermissionPickerList.ios, MobilePrimitives, MobileProviderMark, MobileVendorIcon, ModelOptionsSheetView, ModelOptionsSheetView.ios, ModelPickerNativeHeader, ModelPickerNativeHeader.ios, ModelPickerSheet, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePermissionSheet, NativePermissionSheet.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, NativeVideoPlayer, NewTaskSelectionRow, NewTaskSelectionSheet, NewTaskSelectionSheet.android, NewTaskSelectionSheet.ios, OrcaWorkerDirectoryPicker, OutsideTap, PaperPlaneIcon, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PlanModeChip, PushNotificationsBridge, QuietSyncIndicator, RecentMessageHistories, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, RemoteSourceMark, ResidentHomeList, SharedTaskAdmissionDialog, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, SlowSendNotice, StartupSplashOverlay, ThemeProvider, UnifiedModelPickerSheet, UnifiedModelPickerView, UnifiedModelPickerView.ios, VoiceRecordingPill, _layout, gestureHandler, mediaPlayerWebView, nativeToolbarMenuItems, new, peerFileTransport, useLocale, voicePillWidthMotion | apps/mobile/app/_layout.tsx, apps/mobile/app/sessions/new.tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/FileTypeIcon.tsx, apps/mobile/src/components/MobileAgentMark.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/MobileVendorIcon.tsx, apps/mobile/src/components/PaperPlaneIcon.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/HomeStackHeader.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/nativeToolbarMenuItems.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/AnnotationBurnInWebView.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/ComposerActivityPill.tsx, apps/mobile/src/session/ComposerAttachmentTray.tsx, apps/mobile/src/session/ComposerDockKeyboardFollow.tsx, apps/mobile/src/session/ComposerFrame.ios.tsx, apps/mobile/src/session/ComposerFrame.tsx, apps/mobile/src/session/ComposerKeyboardAvoidingView.tsx, apps/mobile/src/session/ComposerNativeRow.ios.tsx, apps/mobile/src/session/ComposerNativeRow.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/ContextSheetCollabView.tsx, apps/mobile/src/session/ContextSheetGoalView.ios.tsx, apps/mobile/src/session/ContextSheetGoalView.tsx, apps/mobile/src/session/ContextSheetMediaViews.tsx, apps/mobile/src/session/ContextSheetPlugins.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeHeaderGlassButton.ios.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/ImageLightbox.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/MobileAgentSwitcher.tsx, apps/mobile/src/session/MobileChoicePickerList.tsx, apps/mobile/src/session/MobileComposerInputRow.tsx, apps/mobile/src/session/MobileModelPickerList.ios.tsx, apps/mobile/src/session/MobileModelPickerList.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/MobilePermissionPickerList.ios.tsx, apps/mobile/src/session/MobilePermissionPickerList.tsx, apps/mobile/src/session/MobileProviderMark.tsx, apps/mobile/src/session/ModelOptionsSheetView.ios.tsx, apps/mobile/src/session/ModelOptionsSheetView.tsx, apps/mobile/src/session/ModelPickerNativeHeader.ios.tsx, apps/mobile/src/session/ModelPickerNativeHeader.tsx, apps/mobile/src/session/ModelPickerSheet.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativePermissionSheet.ios.tsx, apps/mobile/src/session/NativePermissionSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/NativeVideoPlayer.tsx, apps/mobile/src/session/NewTaskSelectionRow.tsx, apps/mobile/src/session/NewTaskSelectionSheet.android.tsx, apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx, apps/mobile/src/session/NewTaskSelectionSheet.tsx, apps/mobile/src/session/OrcaWorkerDirectoryPicker.tsx, apps/mobile/src/session/PlanModeChip.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/RemoteSourceMark.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/SlowSendNotice.tsx, apps/mobile/src/session/UnifiedModelPickerSheet.tsx, apps/mobile/src/session/UnifiedModelPickerView.ios.tsx, apps/mobile/src/session/UnifiedModelPickerView.tsx, apps/mobile/src/session/VoiceRecordingPill.tsx, apps/mobile/src/session/mediaPlayerWebView.tsx, apps/mobile/src/session/mediaPlayerWebViewHtml.ts, apps/mobile/src/session/voicePillWidthMotion.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 251 | 114 |
-| `mobile.chat.session` | mobile | 任务内容与输入 | app/sessions/[sessionId].tsx | AccountSwitcherSheet, AdaptiveWindow, AgentErrorDetails, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AnnotationBurnInWebView, AppText, AuthContext, AuthorizationMessageCard, AutomationTimerIcon, BlurBackdrop, CenteredScreen, ChatFileChipMenuSheet, ChatIdentityHeader, CindyMakeSessionGate, ClipboardSharedTaskPrompt, CompanionChoice, CompanionCreateNativeView, CompanionCreateNativeView.ios, CompanionEntering, CompanionHeader, CompanionImportSheet, CompanionLearningFooter, CompanionMemoryPage, CompanionMemoryPage.ios, CompanionMessageActions, CompanionMessageCard, CompanionModelChain, CompanionNativeContent.ios, CompanionPortraitPicker, CompanionPresenceRing, CompanionProfileArtifacts, CompanionProfileNativeView, CompanionProfileNativeView.ios, CompanionProfileSheet, CompanionSettingsRow, CompanionSettingsRow.ios, CompanionSheet, CompanionSheet.ios, CompanionTaskResultCard, CompanionTodoRow, CompanionTodos, CompanionWorkingStatus, ComposerActivityPill, ComposerAttachmentTray, ComposerDockKeyboardFollow, ComposerExpandButton, ComposerExpandButton.ios, ComposerFrame, ComposerFrame.ios, ComposerKeyboardAvoidingView, ComposerMorphSource, ComposerMorphSource.ios, ComposerNativeInput, ComposerNativeInput.ios, ComposerNativeRow, ComposerNativeRow.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerRichInput, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, ContextSheetCollabView, ContextSheetGoalView, ContextSheetGoalView.ios, ContextSheetMediaViews, ContextSheetPlugins, ConversationSearchFilterSheet, ConversationShareSvg, ConversationShareWebView, DeviceLinkContext, FailedScheduleNotice, FileTypeIcon, FoldTouchpad, HomeChromeDrawer, HomeChromeFrost, HomeEntryProvider, HomeGlassMenuPanel, HomeHeaderGlassButton, HomeHeaderGlassButton.ios, HomeListVisuals, HomeModeSwitch, HomeNativeStackHeader, HomeNewTaskButton, HomeProjectMachineLabel, HomeSearchBar, HomeSessionInfoMeta, HomeStackHeader, HomeSurface, HomeUnreadContext, ImageLightbox, IncomingShareBridge, InlineQueueSection, InlineQuoteChip, InlineReferenceChip, InteractionPanel, MarkdownBlockContent, MessageActionSheet, MessageLoadingImage, MessageRenderer, MobileAgentMark, MobileAgentSwitcher, MobileBoundaryNotice, MobileComposerInputRow, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileModelPickerList, MobileModelPickerList.ios, MobileOutboxBridge, MobilePermissionPickerList, MobilePermissionPickerList.ios, MobilePrimitives, MobileProviderMark, MobileUserAvatar, MobileVendorIcon, ModalContentArea, ModelOptionsSheetView, ModelOptionsSheetView.ios, ModelPickerNativeHeader, ModelPickerNativeHeader.ios, ModelPickerSheet, MountOnFirstOpen, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePermissionSheet, NativePermissionSheet.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, NativeVideoPlayer, NewTaskSelectionRow, NewTaskSelectionSheet, NewTaskSelectionSheet.android, NewTaskSelectionSheet.ios, OrcaWorkerDirectoryPicker, OutsideTap, PaperPlaneIcon, PendingSendBubble, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PlanModeChip, PluginCardActions, PluginInvocationHeader, PluginMenuUnreadDot, PluginSetupNativeActions, PluginSetupNativeForm, PromptRecommendation, PushNotificationsBridge, QuietSyncIndicator, QuoteCapsule, ReadableHistoryRecovery, RecentMessageHistories, RemoteAccessGuide, RemoteCompanionAvatar, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, RemoteSourceMark, RemoteTaskSuggestions, RenameSessionModal, ResidentHomeList, RewindPreviewPanel, RunningTokenRatePopover, SentInlineAtomBody, SessionActionSheet, SessionActionSheetFrame, SessionActionSheetFrame.android, SessionDetailsNative, SessionDetailsNative.ios, SessionHeaderNativeControls, SessionHeaderNativeControls.ios, SessionListDrawer, SessionMenuSheet, SessionOptionsExpoSheet, SessionResourceCards, SessionRightSpinner, SessionSearchNative, SessionSearchNative.ios, SessionTailBanner, SessionTransientNotice, SessionUsageSummary, ShareImageNativeButton, ShareImageNativeButton.ios, ShareMessageCheckbox, ShareSelectAllButton, ShareSelectionBar, SharedTaskAdmissionDialog, SharedTaskEndedState, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, SlowSendNotice, StartupSplashOverlay, SwipeableSessionRow, SwipeableSessionRow.ios, SystemNavigationBack, TaskTags, TaskTagsSheet, ThemeProvider, ThinkingDots, TodoDateInput, TodoDateInput.android, TodoDateInput.ios, UnifiedModelPickerSheet, UnifiedModelPickerView, UnifiedModelPickerView.ios, VoiceRecordingPill, WorkingStatusText, [sessionId], _layout, gestureHandler, listDisclosureTransition, mathWebView, mediaPlayerWebView, mermaidWebView, nativeToolbarMenuItems, peerFileTransport, useLocale, useSharedTaskConfirmation, voicePillWidthMotion | apps/mobile/app/_layout.tsx, apps/mobile/app/sessions/[sessionId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/FileTypeIcon.tsx, apps/mobile/src/components/MobileAgentMark.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/MobileUserAvatar.tsx, apps/mobile/src/components/MobileVendorIcon.tsx, apps/mobile/src/components/PaperPlaneIcon.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/RemoteAccessGuide.tsx, apps/mobile/src/components/RemoteCompanionAvatar.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/ModalContentArea.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/HomeStackHeader.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/SystemNavigationBack.tsx, apps/mobile/src/platform/chrome/nativeToolbarMenuItems.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/plugins/PluginCardActions.tsx, apps/mobile/src/plugins/PluginMenuUnreadDot.tsx, apps/mobile/src/plugins/PluginSetupNativeActions.tsx, apps/mobile/src/plugins/PluginSetupNativeForm.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/AccountSwitcherSheet.tsx, apps/mobile/src/session/AgentErrorDetails.tsx, apps/mobile/src/session/AnnotationBurnInWebView.tsx, apps/mobile/src/session/AuthorizationMessageCard.tsx, apps/mobile/src/session/AutomationTimerIcon.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ChatFileChipMenuSheet.tsx, apps/mobile/src/session/ChatIdentityHeader.tsx, apps/mobile/src/session/CindyMakeSessionGate.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionChoice.tsx, apps/mobile/src/session/CompanionCreateNativeView.ios.tsx, apps/mobile/src/session/CompanionCreateNativeView.tsx, apps/mobile/src/session/CompanionEntering.tsx, apps/mobile/src/session/CompanionHeader.tsx, apps/mobile/src/session/CompanionImportSheet.tsx, apps/mobile/src/session/CompanionLearningFooter.tsx, apps/mobile/src/session/CompanionMemoryPage.ios.tsx, apps/mobile/src/session/CompanionMemoryPage.tsx, apps/mobile/src/session/CompanionMessageActions.tsx, apps/mobile/src/session/CompanionMessageCard.tsx, apps/mobile/src/session/CompanionModelChain.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/CompanionPortraitPicker.tsx, apps/mobile/src/session/CompanionPresenceRing.tsx, apps/mobile/src/session/CompanionProfileArtifacts.tsx, apps/mobile/src/session/CompanionProfileNativeView.ios.tsx, apps/mobile/src/session/CompanionProfileNativeView.tsx, apps/mobile/src/session/CompanionProfileSheet.tsx, apps/mobile/src/session/CompanionSettingsRow.ios.tsx, apps/mobile/src/session/CompanionSettingsRow.tsx, apps/mobile/src/session/CompanionSheet.ios.tsx, apps/mobile/src/session/CompanionSheet.tsx, apps/mobile/src/session/CompanionTaskResultCard.tsx, apps/mobile/src/session/CompanionTodoRow.tsx, apps/mobile/src/session/CompanionTodos.tsx, apps/mobile/src/session/CompanionWorkingStatus.tsx, apps/mobile/src/session/ComposerActivityPill.tsx, apps/mobile/src/session/ComposerAttachmentTray.tsx, apps/mobile/src/session/ComposerDockKeyboardFollow.tsx, apps/mobile/src/session/ComposerExpandButton.ios.tsx, apps/mobile/src/session/ComposerExpandButton.tsx, apps/mobile/src/session/ComposerFrame.ios.tsx, apps/mobile/src/session/ComposerFrame.tsx, apps/mobile/src/session/ComposerKeyboardAvoidingView.tsx, apps/mobile/src/session/ComposerMorphSource.ios.tsx, apps/mobile/src/session/ComposerMorphSource.tsx, apps/mobile/src/session/ComposerNativeInput.ios.tsx, apps/mobile/src/session/ComposerNativeInput.tsx, apps/mobile/src/session/ComposerNativeRow.ios.tsx, apps/mobile/src/session/ComposerNativeRow.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerRichInput.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/ContextSheetCollabView.tsx, apps/mobile/src/session/ContextSheetGoalView.ios.tsx, apps/mobile/src/session/ContextSheetGoalView.tsx, apps/mobile/src/session/ContextSheetMediaViews.tsx, apps/mobile/src/session/ContextSheetPlugins.tsx, apps/mobile/src/session/ConversationSearchFilterSheet.tsx, apps/mobile/src/session/ConversationShareSvg.tsx, apps/mobile/src/session/ConversationShareWebView.tsx, apps/mobile/src/session/FailedScheduleNotice.tsx, apps/mobile/src/session/HomeChromeDrawer.tsx, apps/mobile/src/session/HomeChromeFrost.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeGlassMenuPanel.tsx, apps/mobile/src/session/HomeHeaderGlassButton.ios.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/HomeListVisuals.tsx, apps/mobile/src/session/HomeModeSwitch.tsx, apps/mobile/src/session/HomeNewTaskButton.tsx, apps/mobile/src/session/HomeProjectMachineLabel.tsx, apps/mobile/src/session/HomeSearchBar.tsx, apps/mobile/src/session/HomeSessionInfoMeta.tsx, apps/mobile/src/session/HomeSurface.tsx, apps/mobile/src/session/HomeUnreadContext.tsx, apps/mobile/src/session/ImageLightbox.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/InlineQueueSection.tsx, apps/mobile/src/session/InlineQuoteChip.tsx, apps/mobile/src/session/InlineReferenceChip.tsx, apps/mobile/src/session/InteractionPanel.tsx, apps/mobile/src/session/MarkdownBlockContent.tsx, apps/mobile/src/session/MessageActionSheet.tsx, apps/mobile/src/session/MessageLoadingImage.tsx, apps/mobile/src/session/MessageRenderer.tsx, apps/mobile/src/session/MobileAgentSwitcher.tsx, apps/mobile/src/session/MobileBoundaryNotice.tsx, apps/mobile/src/session/MobileComposerInputRow.tsx, apps/mobile/src/session/MobileModelPickerList.ios.tsx, apps/mobile/src/session/MobileModelPickerList.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/MobilePermissionPickerList.ios.tsx, apps/mobile/src/session/MobilePermissionPickerList.tsx, apps/mobile/src/session/MobileProviderMark.tsx, apps/mobile/src/session/ModelOptionsSheetView.ios.tsx, apps/mobile/src/session/ModelOptionsSheetView.tsx, apps/mobile/src/session/ModelPickerNativeHeader.ios.tsx, apps/mobile/src/session/ModelPickerNativeHeader.tsx, apps/mobile/src/session/ModelPickerSheet.tsx, apps/mobile/src/session/MountOnFirstOpen.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativePermissionSheet.ios.tsx, apps/mobile/src/session/NativePermissionSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/NativeVideoPlayer.tsx, apps/mobile/src/session/NewTaskSelectionRow.tsx, apps/mobile/src/session/NewTaskSelectionSheet.android.tsx, apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx, apps/mobile/src/session/NewTaskSelectionSheet.tsx, apps/mobile/src/session/OrcaWorkerDirectoryPicker.tsx, apps/mobile/src/session/PendingSendBubble.tsx, apps/mobile/src/session/PlanModeChip.tsx, apps/mobile/src/session/PluginInvocationHeader.tsx, apps/mobile/src/session/PromptRecommendation.tsx, apps/mobile/src/session/QuoteCapsule.tsx, apps/mobile/src/session/ReadableHistoryRecovery.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/RemoteSourceMark.tsx, apps/mobile/src/session/RemoteTaskSuggestions.tsx, apps/mobile/src/session/RenameSessionModal.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/RewindPreviewPanel.tsx, apps/mobile/src/session/RunningTokenRatePopover.tsx, apps/mobile/src/session/SentInlineAtomBody.tsx, apps/mobile/src/session/SessionActionSheet.tsx, apps/mobile/src/session/SessionActionSheetFrame.android.tsx, apps/mobile/src/session/SessionActionSheetFrame.tsx, apps/mobile/src/session/SessionDetailsNative.ios.tsx, apps/mobile/src/session/SessionDetailsNative.tsx, apps/mobile/src/session/SessionHeaderNativeControls.ios.tsx, apps/mobile/src/session/SessionHeaderNativeControls.tsx, apps/mobile/src/session/SessionListDrawer.tsx, apps/mobile/src/session/SessionMenuSheet.tsx, apps/mobile/src/session/SessionOptionsExpoSheet.tsx, apps/mobile/src/session/SessionResourceCards.tsx, apps/mobile/src/session/SessionRightSpinner.tsx, apps/mobile/src/session/SessionSearchNative.ios.tsx, apps/mobile/src/session/SessionSearchNative.tsx, apps/mobile/src/session/SessionTailBanner.tsx, apps/mobile/src/session/SessionTransientNotice.tsx, apps/mobile/src/session/SessionUsageSummary.tsx, apps/mobile/src/session/ShareImageNativeButton.ios.tsx, apps/mobile/src/session/ShareImageNativeButton.tsx, apps/mobile/src/session/ShareMessageCheckbox.tsx, apps/mobile/src/session/ShareSelectAllButton.tsx, apps/mobile/src/session/ShareSelectionBar.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskEndedState.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/SlowSendNotice.tsx, apps/mobile/src/session/SwipeableSessionRow.ios.tsx, apps/mobile/src/session/SwipeableSessionRow.tsx, apps/mobile/src/session/TaskTags.tsx, apps/mobile/src/session/TaskTagsSheet.tsx, apps/mobile/src/session/ThinkingDots.tsx, apps/mobile/src/session/TodoDateInput.android.tsx, apps/mobile/src/session/TodoDateInput.ios.tsx, apps/mobile/src/session/TodoDateInput.tsx, apps/mobile/src/session/UnifiedModelPickerSheet.tsx, apps/mobile/src/session/UnifiedModelPickerView.ios.tsx, apps/mobile/src/session/UnifiedModelPickerView.tsx, apps/mobile/src/session/VoiceRecordingPill.tsx, apps/mobile/src/session/WorkingStatusText.tsx, apps/mobile/src/session/composerRichInputHtml.ts, apps/mobile/src/session/conversationShareWebViewHtml.ts, apps/mobile/src/session/listDisclosureTransition.tsx, apps/mobile/src/session/mathWebView.tsx, apps/mobile/src/session/mathWebViewHtml.ts, apps/mobile/src/session/mediaPlayerWebView.tsx, apps/mobile/src/session/mediaPlayerWebViewHtml.ts, apps/mobile/src/session/mermaidWebView.tsx, apps/mobile/src/session/mermaidWebViewHtml.ts, apps/mobile/src/session/selectableMarkdownHtml.ts, apps/mobile/src/session/useSharedTaskConfirmation.tsx, apps/mobile/src/session/voicePillWidthMotion.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 7 | 252 | 312 |
+| `mobile.chat.session` | mobile | 任务内容与输入 | app/sessions/[sessionId].tsx | AccountSwitcherSheet, AdaptiveWindow, AgentErrorDetails, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AnnotationBurnInWebView, AppText, AuthContext, AuthorizationMessageCard, AutomationTimerIcon, BlurBackdrop, CenteredScreen, ChatFileChipMenuSheet, ChatIdentityHeader, CindyMakeSessionGate, ClipboardSharedTaskPrompt, CompanionChoice, CompanionCreateNativeView, CompanionCreateNativeView.ios, CompanionEntering, CompanionHeader, CompanionImportSheet, CompanionLearningFooter, CompanionMemoryPage, CompanionMemoryPage.ios, CompanionMessageActions, CompanionMessageCard, CompanionModelChain, CompanionNativeContent.ios, CompanionPortraitPicker, CompanionPresenceRing, CompanionProfileArtifacts, CompanionProfileNativeView, CompanionProfileNativeView.ios, CompanionProfileSheet, CompanionSettingsRow, CompanionSettingsRow.ios, CompanionSheet, CompanionSheet.ios, CompanionTaskResultCard, CompanionTodoRow, CompanionTodos, CompanionWorkingStatus, ComposerActivityPill, ComposerAttachmentTray, ComposerDockKeyboardFollow, ComposerExpandButton, ComposerExpandButton.ios, ComposerFrame, ComposerFrame.ios, ComposerKeyboardAvoidingView, ComposerMorphSource, ComposerMorphSource.ios, ComposerNativeInput, ComposerNativeInput.ios, ComposerNativeRow, ComposerNativeRow.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerRichInput, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, ContextSheetCollabView, ContextSheetGoalView, ContextSheetGoalView.ios, ContextSheetMediaViews, ContextSheetPlugins, ConversationSearchFilterSheet, ConversationShareSvg, ConversationShareWebView, DeviceLinkContext, FailedScheduleNotice, FileTypeIcon, FoldTouchpad, HomeChromeDrawer, HomeChromeFrost, HomeEntryProvider, HomeGlassMenuPanel, HomeHeaderGlassButton, HomeHeaderGlassButton.ios, HomeListVisuals, HomeModeSwitch, HomeNativeStackHeader, HomeNewTaskButton, HomeProjectMachineLabel, HomeSearchBar, HomeSessionInfoMeta, HomeStackHeader, HomeSurface, HomeUnreadContext, ImageLightbox, IncomingShareBridge, InlineQueueSection, InlineQuoteChip, InlineReferenceChip, InputHandoffCard, InputHandoffDeviceCode, InputHandoffPictureStep, InputHandoffQrCode, InputHandoffRecordRow, InputHandoffSheet, InputHandoffSheet.ios, InputHandoffStepFields, InteractionPanel, MarkdownBlockContent, MessageActionSheet, MessageLoadingImage, MessageRenderer, MobileAgentMark, MobileAgentSwitcher, MobileBoundaryNotice, MobileComposerInputRow, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileModelPickerList, MobileModelPickerList.ios, MobileOutboxBridge, MobilePermissionPickerList, MobilePermissionPickerList.ios, MobilePrimitives, MobileProviderMark, MobileUserAvatar, MobileVendorIcon, ModalContentArea, ModelOptionsSheetView, ModelOptionsSheetView.ios, ModelPickerNativeHeader, ModelPickerNativeHeader.ios, ModelPickerSheet, MountOnFirstOpen, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePermissionSheet, NativePermissionSheet.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, NativeVideoPlayer, NewTaskSelectionRow, NewTaskSelectionSheet, NewTaskSelectionSheet.android, NewTaskSelectionSheet.ios, OrcaWorkerDirectoryPicker, OutsideTap, PaperPlaneIcon, PendingSendBubble, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PlanModeChip, PluginCardActions, PluginInvocationHeader, PluginMenuUnreadDot, PluginSetupNativeActions, PluginSetupNativeForm, PromptRecommendation, PushNotificationsBridge, QuietSyncIndicator, QuoteCapsule, ReadableHistoryRecovery, RecentMessageHistories, RemoteAccessGuide, RemoteCompanionAvatar, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, RemoteSourceMark, RemoteTaskSuggestions, RenameSessionModal, ResidentHomeList, RewindPreviewPanel, RunningTokenRatePopover, SentInlineAtomBody, SessionActionSheet, SessionActionSheetFrame, SessionActionSheetFrame.android, SessionDetailsNative, SessionDetailsNative.ios, SessionHeaderNativeControls, SessionHeaderNativeControls.ios, SessionListDrawer, SessionMenuSheet, SessionOptionsExpoSheet, SessionResourceCards, SessionRightSpinner, SessionSearchNative, SessionSearchNative.ios, SessionTailBanner, SessionTransientNotice, SessionUsageSummary, ShareImageNativeButton, ShareImageNativeButton.ios, ShareMessageCheckbox, ShareSelectAllButton, ShareSelectionBar, SharedTaskAdmissionDialog, SharedTaskEndedState, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, SlowSendNotice, StartupSplashOverlay, SwipeableSessionRow, SwipeableSessionRow.ios, SystemNavigationBack, TaskTags, TaskTagsSheet, ThemeProvider, ThinkingDots, TodoDateInput, TodoDateInput.android, TodoDateInput.ios, UnifiedModelPickerSheet, UnifiedModelPickerView, UnifiedModelPickerView.ios, VoiceRecordingPill, WorkingStatusText, [sessionId], _layout, gestureHandler, listDisclosureTransition, mathWebView, mediaPlayerWebView, mermaidWebView, nativeToolbarMenuItems, peerFileTransport, useLocale, useSharedTaskConfirmation, voicePillWidthMotion | apps/mobile/app/_layout.tsx, apps/mobile/app/sessions/[sessionId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/FileTypeIcon.tsx, apps/mobile/src/components/MobileAgentMark.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/MobileUserAvatar.tsx, apps/mobile/src/components/MobileVendorIcon.tsx, apps/mobile/src/components/PaperPlaneIcon.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/RemoteAccessGuide.tsx, apps/mobile/src/components/RemoteCompanionAvatar.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/inputHandoff/InputHandoffCard.tsx, apps/mobile/src/inputHandoff/InputHandoffDeviceCode.tsx, apps/mobile/src/inputHandoff/InputHandoffPictureStep.tsx, apps/mobile/src/inputHandoff/InputHandoffQrCode.tsx, apps/mobile/src/inputHandoff/InputHandoffRecordRow.tsx, apps/mobile/src/inputHandoff/InputHandoffSheet.ios.tsx, apps/mobile/src/inputHandoff/InputHandoffSheet.tsx, apps/mobile/src/inputHandoff/InputHandoffStepFields.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/ModalContentArea.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/HomeStackHeader.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/SystemNavigationBack.tsx, apps/mobile/src/platform/chrome/nativeToolbarMenuItems.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/plugins/PluginCardActions.tsx, apps/mobile/src/plugins/PluginMenuUnreadDot.tsx, apps/mobile/src/plugins/PluginSetupNativeActions.tsx, apps/mobile/src/plugins/PluginSetupNativeForm.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/AccountSwitcherSheet.tsx, apps/mobile/src/session/AgentErrorDetails.tsx, apps/mobile/src/session/AnnotationBurnInWebView.tsx, apps/mobile/src/session/AuthorizationMessageCard.tsx, apps/mobile/src/session/AutomationTimerIcon.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ChatFileChipMenuSheet.tsx, apps/mobile/src/session/ChatIdentityHeader.tsx, apps/mobile/src/session/CindyMakeSessionGate.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionChoice.tsx, apps/mobile/src/session/CompanionCreateNativeView.ios.tsx, apps/mobile/src/session/CompanionCreateNativeView.tsx, apps/mobile/src/session/CompanionEntering.tsx, apps/mobile/src/session/CompanionHeader.tsx, apps/mobile/src/session/CompanionImportSheet.tsx, apps/mobile/src/session/CompanionLearningFooter.tsx, apps/mobile/src/session/CompanionMemoryPage.ios.tsx, apps/mobile/src/session/CompanionMemoryPage.tsx, apps/mobile/src/session/CompanionMessageActions.tsx, apps/mobile/src/session/CompanionMessageCard.tsx, apps/mobile/src/session/CompanionModelChain.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/CompanionPortraitPicker.tsx, apps/mobile/src/session/CompanionPresenceRing.tsx, apps/mobile/src/session/CompanionProfileArtifacts.tsx, apps/mobile/src/session/CompanionProfileNativeView.ios.tsx, apps/mobile/src/session/CompanionProfileNativeView.tsx, apps/mobile/src/session/CompanionProfileSheet.tsx, apps/mobile/src/session/CompanionSettingsRow.ios.tsx, apps/mobile/src/session/CompanionSettingsRow.tsx, apps/mobile/src/session/CompanionSheet.ios.tsx, apps/mobile/src/session/CompanionSheet.tsx, apps/mobile/src/session/CompanionTaskResultCard.tsx, apps/mobile/src/session/CompanionTodoRow.tsx, apps/mobile/src/session/CompanionTodos.tsx, apps/mobile/src/session/CompanionWorkingStatus.tsx, apps/mobile/src/session/ComposerActivityPill.tsx, apps/mobile/src/session/ComposerAttachmentTray.tsx, apps/mobile/src/session/ComposerDockKeyboardFollow.tsx, apps/mobile/src/session/ComposerExpandButton.ios.tsx, apps/mobile/src/session/ComposerExpandButton.tsx, apps/mobile/src/session/ComposerFrame.ios.tsx, apps/mobile/src/session/ComposerFrame.tsx, apps/mobile/src/session/ComposerKeyboardAvoidingView.tsx, apps/mobile/src/session/ComposerMorphSource.ios.tsx, apps/mobile/src/session/ComposerMorphSource.tsx, apps/mobile/src/session/ComposerNativeInput.ios.tsx, apps/mobile/src/session/ComposerNativeInput.tsx, apps/mobile/src/session/ComposerNativeRow.ios.tsx, apps/mobile/src/session/ComposerNativeRow.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerRichInput.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/ContextSheetCollabView.tsx, apps/mobile/src/session/ContextSheetGoalView.ios.tsx, apps/mobile/src/session/ContextSheetGoalView.tsx, apps/mobile/src/session/ContextSheetMediaViews.tsx, apps/mobile/src/session/ContextSheetPlugins.tsx, apps/mobile/src/session/ConversationSearchFilterSheet.tsx, apps/mobile/src/session/ConversationShareSvg.tsx, apps/mobile/src/session/ConversationShareWebView.tsx, apps/mobile/src/session/FailedScheduleNotice.tsx, apps/mobile/src/session/HomeChromeDrawer.tsx, apps/mobile/src/session/HomeChromeFrost.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeGlassMenuPanel.tsx, apps/mobile/src/session/HomeHeaderGlassButton.ios.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/HomeListVisuals.tsx, apps/mobile/src/session/HomeModeSwitch.tsx, apps/mobile/src/session/HomeNewTaskButton.tsx, apps/mobile/src/session/HomeProjectMachineLabel.tsx, apps/mobile/src/session/HomeSearchBar.tsx, apps/mobile/src/session/HomeSessionInfoMeta.tsx, apps/mobile/src/session/HomeSurface.tsx, apps/mobile/src/session/HomeUnreadContext.tsx, apps/mobile/src/session/ImageLightbox.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/InlineQueueSection.tsx, apps/mobile/src/session/InlineQuoteChip.tsx, apps/mobile/src/session/InlineReferenceChip.tsx, apps/mobile/src/session/InteractionPanel.tsx, apps/mobile/src/session/MarkdownBlockContent.tsx, apps/mobile/src/session/MessageActionSheet.tsx, apps/mobile/src/session/MessageLoadingImage.tsx, apps/mobile/src/session/MessageRenderer.tsx, apps/mobile/src/session/MobileAgentSwitcher.tsx, apps/mobile/src/session/MobileBoundaryNotice.tsx, apps/mobile/src/session/MobileComposerInputRow.tsx, apps/mobile/src/session/MobileModelPickerList.ios.tsx, apps/mobile/src/session/MobileModelPickerList.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/MobilePermissionPickerList.ios.tsx, apps/mobile/src/session/MobilePermissionPickerList.tsx, apps/mobile/src/session/MobileProviderMark.tsx, apps/mobile/src/session/ModelOptionsSheetView.ios.tsx, apps/mobile/src/session/ModelOptionsSheetView.tsx, apps/mobile/src/session/ModelPickerNativeHeader.ios.tsx, apps/mobile/src/session/ModelPickerNativeHeader.tsx, apps/mobile/src/session/ModelPickerSheet.tsx, apps/mobile/src/session/MountOnFirstOpen.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativePermissionSheet.ios.tsx, apps/mobile/src/session/NativePermissionSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/NativeVideoPlayer.tsx, apps/mobile/src/session/NewTaskSelectionRow.tsx, apps/mobile/src/session/NewTaskSelectionSheet.android.tsx, apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx, apps/mobile/src/session/NewTaskSelectionSheet.tsx, apps/mobile/src/session/OrcaWorkerDirectoryPicker.tsx, apps/mobile/src/session/PendingSendBubble.tsx, apps/mobile/src/session/PlanModeChip.tsx, apps/mobile/src/session/PluginInvocationHeader.tsx, apps/mobile/src/session/PromptRecommendation.tsx, apps/mobile/src/session/QuoteCapsule.tsx, apps/mobile/src/session/ReadableHistoryRecovery.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/RemoteSourceMark.tsx, apps/mobile/src/session/RemoteTaskSuggestions.tsx, apps/mobile/src/session/RenameSessionModal.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/RewindPreviewPanel.tsx, apps/mobile/src/session/RunningTokenRatePopover.tsx, apps/mobile/src/session/SentInlineAtomBody.tsx, apps/mobile/src/session/SessionActionSheet.tsx, apps/mobile/src/session/SessionActionSheetFrame.android.tsx, apps/mobile/src/session/SessionActionSheetFrame.tsx, apps/mobile/src/session/SessionDetailsNative.ios.tsx, apps/mobile/src/session/SessionDetailsNative.tsx, apps/mobile/src/session/SessionHeaderNativeControls.ios.tsx, apps/mobile/src/session/SessionHeaderNativeControls.tsx, apps/mobile/src/session/SessionListDrawer.tsx, apps/mobile/src/session/SessionMenuSheet.tsx, apps/mobile/src/session/SessionOptionsExpoSheet.tsx, apps/mobile/src/session/SessionResourceCards.tsx, apps/mobile/src/session/SessionRightSpinner.tsx, apps/mobile/src/session/SessionSearchNative.ios.tsx, apps/mobile/src/session/SessionSearchNative.tsx, apps/mobile/src/session/SessionTailBanner.tsx, apps/mobile/src/session/SessionTransientNotice.tsx, apps/mobile/src/session/SessionUsageSummary.tsx, apps/mobile/src/session/ShareImageNativeButton.ios.tsx, apps/mobile/src/session/ShareImageNativeButton.tsx, apps/mobile/src/session/ShareMessageCheckbox.tsx, apps/mobile/src/session/ShareSelectAllButton.tsx, apps/mobile/src/session/ShareSelectionBar.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskEndedState.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/SlowSendNotice.tsx, apps/mobile/src/session/SwipeableSessionRow.ios.tsx, apps/mobile/src/session/SwipeableSessionRow.tsx, apps/mobile/src/session/TaskTags.tsx, apps/mobile/src/session/TaskTagsSheet.tsx, apps/mobile/src/session/ThinkingDots.tsx, apps/mobile/src/session/TodoDateInput.android.tsx, apps/mobile/src/session/TodoDateInput.ios.tsx, apps/mobile/src/session/TodoDateInput.tsx, apps/mobile/src/session/UnifiedModelPickerSheet.tsx, apps/mobile/src/session/UnifiedModelPickerView.ios.tsx, apps/mobile/src/session/UnifiedModelPickerView.tsx, apps/mobile/src/session/VoiceRecordingPill.tsx, apps/mobile/src/session/WorkingStatusText.tsx, apps/mobile/src/session/composerRichInputHtml.ts, apps/mobile/src/session/conversationShareWebViewHtml.ts, apps/mobile/src/session/listDisclosureTransition.tsx, apps/mobile/src/session/mathWebView.tsx, apps/mobile/src/session/mathWebViewHtml.ts, apps/mobile/src/session/mediaPlayerWebView.tsx, apps/mobile/src/session/mediaPlayerWebViewHtml.ts, apps/mobile/src/session/mermaidWebView.tsx, apps/mobile/src/session/mermaidWebViewHtml.ts, apps/mobile/src/session/selectableMarkdownHtml.ts, apps/mobile/src/session/useSharedTaskConfirmation.tsx, apps/mobile/src/session/voicePillWidthMotion.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 7 | 252 | 316 |
| `mobile.chat.sharing` | mobile | 共享任务邀请与成员;供应商分享链接提示 | app/shared-session.tsx / app/provider-share.tsx | AdaptiveWindow, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ClipboardSharedTaskPrompt, CompanionNativeContent.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceLinkContext, FoldTouchpad, HomeEntryProvider, IncomingShareBridge, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileOutboxBridge, MobilePrimitives, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, OutsideTap, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PushNotificationsBridge, QuietSyncIndicator, RecentMessageHistories, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, ResidentHomeList, SharedTaskAdmissionDialog, SharedTaskEndedState, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, ThemeProvider, _layout, gestureHandler, peerFileTransport, provider-share, shared-session, useLocale, useSharedTaskConfirmation | apps/mobile/app/_layout.tsx, apps/mobile/app/provider-share.tsx, apps/mobile/app/shared-session.tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskEndedState.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/useSharedTaskConfirmation.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 214 | 69 |
| `mobile.companions.direct` | mobile | 伙伴私聊回看 | app/companions/direct/[threadId].tsx | AdaptiveWindow, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ClipboardSharedTaskPrompt, CompanionNativeContent.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceLinkContext, FoldTouchpad, HomeEntryProvider, HomeHeaderGlassButton, HomeHeaderGlassButton.ios, HomeNativeStackHeader, HomeStackHeader, IncomingShareBridge, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileOutboxBridge, MobilePrimitives, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, OutsideTap, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PushNotificationsBridge, QuietSyncIndicator, RecentMessageHistories, RemoteCompanionAvatar, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, ResidentHomeList, SharedTaskAdmissionDialog, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, ThemeProvider, [threadId], _layout, gestureHandler, nativeToolbarMenuItems, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/companions/direct/[threadId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/RemoteCompanionAvatar.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/HomeStackHeader.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/nativeToolbarMenuItems.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeHeaderGlassButton.ios.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 214 | 60 |
-| `mobile.companions.groups` | mobile | 伙伴群聊与分工 | app/companions/groups/[groupId].tsx | AdaptiveWindow, AgentErrorDetails, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AppText, AuthContext, AuthorizationMessageCard, BlurBackdrop, BotGroupAvatars, BotGroupChatScreen, BotGroupComposer, BotGroupMenu, BotGroupMessageAttachments, BotGroupMessageText, BotGroupPlan, BotGroupQuote, BotGroupSettingsSheet, BotGroupSpeakerRow, CenteredScreen, ChatIdentityHeader, ClipboardSharedTaskPrompt, CompanionCardButton, CompanionEntering, CompanionLearningFooter, CompanionMessageActions, CompanionMessageCard, CompanionNativeContent.ios, CompanionPresenceRing, CompanionSheet, CompanionSheet.ios, CompanionTaskResultCard, ComposerAttachmentTray, ComposerFrame, ComposerFrame.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, ContextSheetMediaViews, DeviceLinkContext, FileTypeIcon, FoldTouchpad, HomeEntryProvider, HomeHeaderGlassButton, HomeHeaderGlassButton.ios, HomeNativeStackHeader, HomeStackHeader, ImageLightbox, IncomingShareBridge, InlineQuoteChip, InlineReferenceChip, InteractionPanel, MarkdownBlockContent, MessageActionSheet, MessageLoadingImage, MessageRenderer, MobileBoundaryNotice, MobileComposerInputRow, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileOutboxBridge, MobilePrimitives, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, NativeVideoPlayer, OutsideTap, PaperPlaneIcon, PendingSendBubble, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PluginCardActions, PluginInvocationHeader, PluginSetupNativeActions, PluginSetupNativeForm, PushNotificationsBridge, QuietSyncIndicator, QuoteCapsule, RecentMessageHistories, RemoteCompanionAvatar, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, ResidentHomeList, SentInlineAtomBody, SessionHeaderNativeControls, SessionHeaderNativeControls.ios, ShareMessageCheckbox, SharedTaskAdmissionDialog, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, TaskTags, ThemeProvider, ThinkingDots, WorkingStatusText, [groupId], _layout, gestureHandler, mathWebView, mediaPlayerWebView, mermaidWebView, nativeToolbarMenuItems, peerFileTransport, useLocale, voicePillWidthMotion | apps/mobile/app/_layout.tsx, apps/mobile/app/companions/groups/[groupId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/FileTypeIcon.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/PaperPlaneIcon.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/RemoteCompanionAvatar.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/HomeStackHeader.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/nativeToolbarMenuItems.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/plugins/PluginCardActions.tsx, apps/mobile/src/plugins/PluginSetupNativeActions.tsx, apps/mobile/src/plugins/PluginSetupNativeForm.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/AgentErrorDetails.tsx, apps/mobile/src/session/AuthorizationMessageCard.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/BotGroupAvatars.tsx, apps/mobile/src/session/BotGroupChatScreen.tsx, apps/mobile/src/session/BotGroupComposer.tsx, apps/mobile/src/session/BotGroupMenu.tsx, apps/mobile/src/session/BotGroupMessageAttachments.tsx, apps/mobile/src/session/BotGroupMessageText.tsx, apps/mobile/src/session/BotGroupPlan.tsx, apps/mobile/src/session/BotGroupQuote.tsx, apps/mobile/src/session/BotGroupSettingsSheet.tsx, apps/mobile/src/session/BotGroupSpeakerRow.tsx, apps/mobile/src/session/ChatIdentityHeader.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionCardButton.tsx, apps/mobile/src/session/CompanionEntering.tsx, apps/mobile/src/session/CompanionLearningFooter.tsx, apps/mobile/src/session/CompanionMessageActions.tsx, apps/mobile/src/session/CompanionMessageCard.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/CompanionPresenceRing.tsx, apps/mobile/src/session/CompanionSheet.ios.tsx, apps/mobile/src/session/CompanionSheet.tsx, apps/mobile/src/session/CompanionTaskResultCard.tsx, apps/mobile/src/session/ComposerAttachmentTray.tsx, apps/mobile/src/session/ComposerFrame.ios.tsx, apps/mobile/src/session/ComposerFrame.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/ContextSheetMediaViews.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeHeaderGlassButton.ios.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/ImageLightbox.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/InlineQuoteChip.tsx, apps/mobile/src/session/InlineReferenceChip.tsx, apps/mobile/src/session/InteractionPanel.tsx, apps/mobile/src/session/MarkdownBlockContent.tsx, apps/mobile/src/session/MessageActionSheet.tsx, apps/mobile/src/session/MessageLoadingImage.tsx, apps/mobile/src/session/MessageRenderer.tsx, apps/mobile/src/session/MobileBoundaryNotice.tsx, apps/mobile/src/session/MobileComposerInputRow.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/NativeVideoPlayer.tsx, apps/mobile/src/session/PendingSendBubble.tsx, apps/mobile/src/session/PluginInvocationHeader.tsx, apps/mobile/src/session/QuoteCapsule.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/SentInlineAtomBody.tsx, apps/mobile/src/session/SessionHeaderNativeControls.ios.tsx, apps/mobile/src/session/SessionHeaderNativeControls.tsx, apps/mobile/src/session/ShareMessageCheckbox.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/TaskTags.tsx, apps/mobile/src/session/ThinkingDots.tsx, apps/mobile/src/session/WorkingStatusText.tsx, apps/mobile/src/session/mathWebView.tsx, apps/mobile/src/session/mathWebViewHtml.ts, apps/mobile/src/session/mediaPlayerWebView.tsx, apps/mobile/src/session/mediaPlayerWebViewHtml.ts, apps/mobile/src/session/mermaidWebView.tsx, apps/mobile/src/session/mermaidWebViewHtml.ts, apps/mobile/src/session/voicePillWidthMotion.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 251 | 205 |
+| `mobile.companions.groups` | mobile | 伙伴群聊与分工 | app/companions/groups/[groupId].tsx | AdaptiveWindow, AgentErrorDetails, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AppText, AuthContext, AuthorizationMessageCard, BlurBackdrop, BotGroupAvatars, BotGroupChatScreen, BotGroupComposer, BotGroupMenu, BotGroupMessageAttachments, BotGroupMessageText, BotGroupPlan, BotGroupQuote, BotGroupSettingsSheet, BotGroupSpeakerRow, CenteredScreen, ChatIdentityHeader, ClipboardSharedTaskPrompt, CompanionCardButton, CompanionEntering, CompanionLearningFooter, CompanionMessageActions, CompanionMessageCard, CompanionNativeContent.ios, CompanionPresenceRing, CompanionSheet, CompanionSheet.ios, CompanionTaskResultCard, ComposerAttachmentTray, ComposerFrame, ComposerFrame.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, ContextSheetMediaViews, DeviceLinkContext, FileTypeIcon, FoldTouchpad, HomeEntryProvider, HomeHeaderGlassButton, HomeHeaderGlassButton.ios, HomeNativeStackHeader, HomeStackHeader, ImageLightbox, IncomingShareBridge, InlineQuoteChip, InlineReferenceChip, InputHandoffCard, InputHandoffDeviceCode, InputHandoffPictureStep, InputHandoffQrCode, InputHandoffRecordRow, InputHandoffSheet, InputHandoffSheet.ios, InputHandoffStepFields, InteractionPanel, MarkdownBlockContent, MessageActionSheet, MessageLoadingImage, MessageRenderer, MobileBoundaryNotice, MobileComposerInputRow, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileOutboxBridge, MobilePrimitives, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, NativeVideoPlayer, OutsideTap, PaperPlaneIcon, PendingSendBubble, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PluginCardActions, PluginInvocationHeader, PluginSetupNativeActions, PluginSetupNativeForm, PushNotificationsBridge, QuietSyncIndicator, QuoteCapsule, RecentMessageHistories, RemoteCompanionAvatar, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, ResidentHomeList, SentInlineAtomBody, SessionHeaderNativeControls, SessionHeaderNativeControls.ios, ShareMessageCheckbox, SharedTaskAdmissionDialog, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, TaskTags, ThemeProvider, ThinkingDots, WorkingStatusText, [groupId], _layout, gestureHandler, mathWebView, mediaPlayerWebView, mermaidWebView, nativeToolbarMenuItems, peerFileTransport, useLocale, voicePillWidthMotion | apps/mobile/app/_layout.tsx, apps/mobile/app/companions/groups/[groupId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/FileTypeIcon.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/PaperPlaneIcon.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/RemoteCompanionAvatar.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/inputHandoff/InputHandoffCard.tsx, apps/mobile/src/inputHandoff/InputHandoffDeviceCode.tsx, apps/mobile/src/inputHandoff/InputHandoffPictureStep.tsx, apps/mobile/src/inputHandoff/InputHandoffQrCode.tsx, apps/mobile/src/inputHandoff/InputHandoffRecordRow.tsx, apps/mobile/src/inputHandoff/InputHandoffSheet.ios.tsx, apps/mobile/src/inputHandoff/InputHandoffSheet.tsx, apps/mobile/src/inputHandoff/InputHandoffStepFields.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/HomeStackHeader.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/nativeToolbarMenuItems.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/plugins/PluginCardActions.tsx, apps/mobile/src/plugins/PluginSetupNativeActions.tsx, apps/mobile/src/plugins/PluginSetupNativeForm.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/AgentErrorDetails.tsx, apps/mobile/src/session/AuthorizationMessageCard.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/BotGroupAvatars.tsx, apps/mobile/src/session/BotGroupChatScreen.tsx, apps/mobile/src/session/BotGroupComposer.tsx, apps/mobile/src/session/BotGroupMenu.tsx, apps/mobile/src/session/BotGroupMessageAttachments.tsx, apps/mobile/src/session/BotGroupMessageText.tsx, apps/mobile/src/session/BotGroupPlan.tsx, apps/mobile/src/session/BotGroupQuote.tsx, apps/mobile/src/session/BotGroupSettingsSheet.tsx, apps/mobile/src/session/BotGroupSpeakerRow.tsx, apps/mobile/src/session/ChatIdentityHeader.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionCardButton.tsx, apps/mobile/src/session/CompanionEntering.tsx, apps/mobile/src/session/CompanionLearningFooter.tsx, apps/mobile/src/session/CompanionMessageActions.tsx, apps/mobile/src/session/CompanionMessageCard.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/CompanionPresenceRing.tsx, apps/mobile/src/session/CompanionSheet.ios.tsx, apps/mobile/src/session/CompanionSheet.tsx, apps/mobile/src/session/CompanionTaskResultCard.tsx, apps/mobile/src/session/ComposerAttachmentTray.tsx, apps/mobile/src/session/ComposerFrame.ios.tsx, apps/mobile/src/session/ComposerFrame.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/ContextSheetMediaViews.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeHeaderGlassButton.ios.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/ImageLightbox.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/InlineQuoteChip.tsx, apps/mobile/src/session/InlineReferenceChip.tsx, apps/mobile/src/session/InteractionPanel.tsx, apps/mobile/src/session/MarkdownBlockContent.tsx, apps/mobile/src/session/MessageActionSheet.tsx, apps/mobile/src/session/MessageLoadingImage.tsx, apps/mobile/src/session/MessageRenderer.tsx, apps/mobile/src/session/MobileBoundaryNotice.tsx, apps/mobile/src/session/MobileComposerInputRow.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/NativeVideoPlayer.tsx, apps/mobile/src/session/PendingSendBubble.tsx, apps/mobile/src/session/PluginInvocationHeader.tsx, apps/mobile/src/session/QuoteCapsule.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/SentInlineAtomBody.tsx, apps/mobile/src/session/SessionHeaderNativeControls.ios.tsx, apps/mobile/src/session/SessionHeaderNativeControls.tsx, apps/mobile/src/session/ShareMessageCheckbox.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/TaskTags.tsx, apps/mobile/src/session/ThinkingDots.tsx, apps/mobile/src/session/WorkingStatusText.tsx, apps/mobile/src/session/mathWebView.tsx, apps/mobile/src/session/mathWebViewHtml.ts, apps/mobile/src/session/mediaPlayerWebView.tsx, apps/mobile/src/session/mediaPlayerWebViewHtml.ts, apps/mobile/src/session/mermaidWebView.tsx, apps/mobile/src/session/mermaidWebViewHtml.ts, apps/mobile/src/session/voicePillWidthMotion.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 251 | 209 |
| `mobile.device-management` | mobile | 设备管理 | app/devices/manage.tsx / app/devices/manage/[deviceId].tsx | AdaptiveWindow, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, ClipboardSharedTaskPrompt, CompanionNativeContent.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceInformationFields, DeviceInformationFields.ios, DeviceLinkContext, DeviceManagementDialogs, DeviceManagementList, DeviceManagementList.ios, FoldTouchpad, HomeEntryProvider, HomeHeaderGlassButton, HomeHeaderGlassButton.ios, HomeNativeStackHeader, HomeStackHeader, IncomingShareBridge, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileOutboxBridge, MobilePrimitives, ModalContentArea, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, OutsideTap, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PushNotificationsBridge, QuietSyncIndicator, RecentMessageHistories, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, RenameDeviceModal, ResidentHomeList, SettingsGroupRows, SharedTaskAdmissionDialog, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, ThemeProvider, [deviceId], _layout, gestureHandler, listDisclosureTransition, manage, nativeToolbarMenuItems, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/devices/manage.tsx, apps/mobile/app/devices/manage/[deviceId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceInformationFields.ios.tsx, apps/mobile/src/device-link/DeviceInformationFields.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/DeviceManagementDialogs.tsx, apps/mobile/src/device-link/DeviceManagementList.ios.tsx, apps/mobile/src/device-link/DeviceManagementList.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/ModalContentArea.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/HomeStackHeader.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/nativeToolbarMenuItems.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeHeaderGlassButton.ios.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/RenameDeviceModal.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/SettingsGroupRows.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/listDisclosureTransition.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 214 | 60 |
| `mobile.devices` | mobile | 主机详情 | app/devices/[deviceId].tsx | AccountSwitcherSheet, AdaptiveWindow, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AppText, AuthContext, AutomationTimerIcon, BlurBackdrop, CenteredScreen, ClipboardSharedTaskPrompt, CompanionNativeContent.ios, ComposerMorphSource, ComposerMorphSource.ios, ComposerNativeRow, ComposerNativeRow.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, ConversationSearchFilterSheet, DeviceLinkContext, FoldTouchpad, HomeChromeDrawer, HomeChromeFrost, HomeEntryProvider, HomeGlassMenuPanel, HomeHeaderGlassButton, HomeHeaderGlassButton.ios, HomeListVisuals, HomeModeSwitch, HomeNativeStackHeader, HomeNewTaskButton, HomeProjectMachineLabel, HomeSearchBar, HomeSessionInfoMeta, HomeStackHeader, HomeSurface, HomeUnreadContext, IncomingShareBridge, MobileAgentMark, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileOutboxBridge, MobilePrimitives, MobileUserAvatar, MobileVendorIcon, ModalContentArea, MountOnFirstOpen, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, OutsideTap, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PluginMenuUnreadDot, PushNotificationsBridge, QuietSyncIndicator, RecentMessageHistories, RemoteAccessGuide, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, RemoteSourceMark, RemoteTaskSuggestions, RenameSessionModal, ResidentHomeList, SessionActionSheet, SessionActionSheetFrame, SessionActionSheetFrame.android, SessionDetailsNative, SessionDetailsNative.ios, SessionOptionsExpoSheet, SessionRightSpinner, SharedTaskAdmissionDialog, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, SwipeableSessionRow, SwipeableSessionRow.ios, TaskTags, ThemeProvider, [deviceId], _layout, gestureHandler, listDisclosureTransition, nativeToolbarMenuItems, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/devices/[deviceId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/MobileAgentMark.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/MobileUserAvatar.tsx, apps/mobile/src/components/MobileVendorIcon.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/RemoteAccessGuide.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/ModalContentArea.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx, apps/mobile/src/platform/chrome/HomeStackHeader.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/nativeToolbarMenuItems.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/plugins/PluginMenuUnreadDot.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/AccountSwitcherSheet.tsx, apps/mobile/src/session/AutomationTimerIcon.tsx, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/ComposerMorphSource.ios.tsx, apps/mobile/src/session/ComposerMorphSource.tsx, apps/mobile/src/session/ComposerNativeRow.ios.tsx, apps/mobile/src/session/ComposerNativeRow.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/ConversationSearchFilterSheet.tsx, apps/mobile/src/session/HomeChromeDrawer.tsx, apps/mobile/src/session/HomeChromeFrost.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HomeGlassMenuPanel.tsx, apps/mobile/src/session/HomeHeaderGlassButton.ios.tsx, apps/mobile/src/session/HomeHeaderGlassButton.tsx, apps/mobile/src/session/HomeListVisuals.tsx, apps/mobile/src/session/HomeModeSwitch.tsx, apps/mobile/src/session/HomeNewTaskButton.tsx, apps/mobile/src/session/HomeProjectMachineLabel.tsx, apps/mobile/src/session/HomeSearchBar.tsx, apps/mobile/src/session/HomeSessionInfoMeta.tsx, apps/mobile/src/session/HomeSurface.tsx, apps/mobile/src/session/HomeUnreadContext.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/MountOnFirstOpen.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/RemoteSourceMark.tsx, apps/mobile/src/session/RemoteTaskSuggestions.tsx, apps/mobile/src/session/RenameSessionModal.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/SessionActionSheet.tsx, apps/mobile/src/session/SessionActionSheetFrame.android.tsx, apps/mobile/src/session/SessionActionSheetFrame.tsx, apps/mobile/src/session/SessionDetailsNative.ios.tsx, apps/mobile/src/session/SessionDetailsNative.tsx, apps/mobile/src/session/SessionOptionsExpoSheet.tsx, apps/mobile/src/session/SessionRightSpinner.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/SwipeableSessionRow.ios.tsx, apps/mobile/src/session/SwipeableSessionRow.tsx, apps/mobile/src/session/TaskTags.tsx, apps/mobile/src/session/listDisclosureTransition.tsx, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 214 | 113 |
| `mobile.files` | mobile | 任务文件与预览 | app/files/[sessionId].tsx / app/files/preview/[sessionId].tsx | AdaptiveWindow, AnchoredPullDownMenu, AnchoredPullDownMenu.android, AndroidUpdateSheet, AppText, AuthContext, BlurBackdrop, CenteredScreen, CindyMakeSessionGate, ClipboardSharedTaskPrompt, CompanionNativeContent.ios, ComposerNativeSection, ComposerNativeSection.ios, ComposerSheet, ComposerSheet.ios, ConnectionBanner, ConnectionNoticeOverlay, ContextSheet, ContextSheet.ios, DeviceLinkContext, FileBrowserSegmentedControl, FileTypeIcon, FileTypeTile, FoldTouchpad, HomeEntryProvider, HtmlBrowserChrome, HtmlBrowserChrome.ios, HtmlFileReader, HtmlWebsiteBrowser, ImageLightbox, IncomingShareBridge, MarkdownFileReader, MobileLoginHandoffContext, MobileLoginHandoffStage, MobileOutboxBridge, MobilePrimitives, ModalContentArea, NativeBottomSheet, NativeBottomSheet.android, NativeChromeBackButton.ios, NativeChromeButton.ios, NativePullDownMenu, NativeRemoteDesktopView, NativeResidentHistory, NativeSwitch, NativeVideoPlayer, OutsideTap, PermissionGuide, PermissionGuideView, PermissionGuideView.ios, PushNotificationsBridge, QuietSyncIndicator, RecentMessageHistories, RemoteDesktopActionButton, RemoteDesktopActionButton.ios, RemoteDesktopBackButton, RemoteDesktopBackButton.ios, RemoteDesktopChrome, RemoteDesktopChrome.ios, RemoteDesktopClipboardButton, RemoteDesktopControls, RemoteDesktopDisplaySettings, RemoteDesktopHost, RemoteDesktopIcons, RemoteDesktopMouseControls, RemoteDesktopMouseControls.ios, RemoteDesktopNetworkStatus, RemoteDesktopPanelButton, RemoteDesktopPanelButton.ios, RemoteDesktopScreen, RemoteDesktopSecuritySettings, RemoteDesktopWindows, RemoteHistoryPrefetchBridge, ResidentHomeList, SharedTaskAdmissionDialog, SharedTaskScreen, SheetModal, SheetSurface, SimpleStackHeader, StartupSplashOverlay, SystemNavigationBack, ThemeProvider, [sessionId], _layout, gestureHandler, mediaPlayerWebView, peerFileTransport, useLocale | apps/mobile/app/_layout.tsx, apps/mobile/app/files/[sessionId].tsx, apps/mobile/app/files/preview/[sessionId].tsx, apps/mobile/src/auth/AuthContext.tsx, apps/mobile/src/auth/MobileLoginHandoffContext.tsx, apps/mobile/src/components/AppText.tsx, apps/mobile/src/components/CenteredScreen.tsx, apps/mobile/src/components/ConnectionBanner.tsx, apps/mobile/src/components/ConnectionNoticeOverlay.tsx, apps/mobile/src/components/FileTypeIcon.tsx, apps/mobile/src/components/FileTypeTile.tsx, apps/mobile/src/components/MobileLoginHandoffStage.tsx, apps/mobile/src/components/MobilePrimitives.tsx, apps/mobile/src/components/QuietSyncIndicator.tsx, apps/mobile/src/components/StartupSplashOverlay.tsx, apps/mobile/src/device-link/DeviceLinkContext.tsx, apps/mobile/src/device-link/peerFileTransport.tsx, apps/mobile/src/i18n/useLocale.tsx, apps/mobile/src/notifications/PushNotificationsBridge.tsx, apps/mobile/src/platform/AdaptiveWindow.tsx, apps/mobile/src/platform/ModalContentArea.tsx, apps/mobile/src/platform/OutsideTap.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.android.tsx, apps/mobile/src/platform/chrome/AnchoredPullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeChromeBackButton.ios.tsx, apps/mobile/src/platform/chrome/NativeChromeButton.ios.tsx, apps/mobile/src/platform/chrome/NativePullDownMenu.tsx, apps/mobile/src/platform/chrome/NativeSwitch.tsx, apps/mobile/src/platform/chrome/SimpleStackHeader.tsx, apps/mobile/src/platform/chrome/SystemNavigationBack.tsx, apps/mobile/src/platform/gestureHandler.tsx, apps/mobile/src/remote-desktop/FoldTouchpad.tsx, apps/mobile/src/remote-desktop/NativeRemoteDesktopView.tsx, apps/mobile/src/remote-desktop/PermissionGuide.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx, apps/mobile/src/remote-desktop/PermissionGuideView.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopActionButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopBackButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopChrome.tsx, apps/mobile/src/remote-desktop/RemoteDesktopClipboardButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopDisplaySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopHost.tsx, apps/mobile/src/remote-desktop/RemoteDesktopIcons.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopMouseControls.tsx, apps/mobile/src/remote-desktop/RemoteDesktopNetworkStatus.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.ios.tsx, apps/mobile/src/remote-desktop/RemoteDesktopPanelButton.tsx, apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx, apps/mobile/src/remote-desktop/RemoteDesktopSecuritySettings.tsx, apps/mobile/src/remote-desktop/RemoteDesktopWindows.tsx, apps/mobile/src/remote-desktop/viewerHtml.ts, apps/mobile/src/session/BlurBackdrop.tsx, apps/mobile/src/session/CindyMakeSessionGate.tsx, apps/mobile/src/session/ClipboardSharedTaskPrompt.tsx, apps/mobile/src/session/CompanionNativeContent.ios.tsx, apps/mobile/src/session/ComposerNativeSection.ios.tsx, apps/mobile/src/session/ComposerNativeSection.tsx, apps/mobile/src/session/ComposerSheet.ios.tsx, apps/mobile/src/session/ComposerSheet.tsx, apps/mobile/src/session/ContextSheet.ios.tsx, apps/mobile/src/session/ContextSheet.tsx, apps/mobile/src/session/FileBrowserSegmentedControl.tsx, apps/mobile/src/session/HomeEntryProvider.tsx, apps/mobile/src/session/HtmlBrowserChrome.ios.tsx, apps/mobile/src/session/HtmlBrowserChrome.tsx, apps/mobile/src/session/HtmlFileReader.tsx, apps/mobile/src/session/HtmlWebsiteBrowser.tsx, apps/mobile/src/session/ImageLightbox.tsx, apps/mobile/src/session/IncomingShareBridge.tsx, apps/mobile/src/session/MarkdownFileReader.tsx, apps/mobile/src/session/MobileOutboxBridge.tsx, apps/mobile/src/session/NativeBottomSheet.android.tsx, apps/mobile/src/session/NativeBottomSheet.tsx, apps/mobile/src/session/NativeResidentHistory.tsx, apps/mobile/src/session/NativeVideoPlayer.tsx, apps/mobile/src/session/RecentMessageHistories.tsx, apps/mobile/src/session/RemoteHistoryPrefetchBridge.tsx, apps/mobile/src/session/ResidentHomeList.tsx, apps/mobile/src/session/SharedTaskAdmissionDialog.tsx, apps/mobile/src/session/SharedTaskScreen.tsx, apps/mobile/src/session/SheetModal.tsx, apps/mobile/src/session/SheetSurface.tsx, apps/mobile/src/session/mathWebViewHtml.ts, apps/mobile/src/session/mediaPlayerWebView.tsx, apps/mobile/src/session/mediaPlayerWebViewHtml.ts, apps/mobile/src/session/selectableMarkdownHtml.ts, apps/mobile/src/theme/ThemeProvider.tsx, apps/mobile/src/theme/navigationTheme.ts, apps/mobile/src/theme/tokens.ts, apps/mobile/src/update/AndroidUpdateSheet.tsx | 0 | 251 | 84 |
diff --git a/docs/dev-rules/credentials-and-local-storage.md b/docs/dev-rules/credentials-and-local-storage.md
index 871c1f05ad..be3279ab16 100644
--- a/docs/dev-rules/credentials-and-local-storage.md
+++ b/docs/dev-rules/credentials-and-local-storage.md
@@ -37,6 +37,13 @@
只写已声明的单个 user Secret,不读回、不批量同步、不开放账号 vault。值只短暂存在于
输入组件/Main 调用中,不进入 Renderer store、Agent、普通远控、日志或历史。CLI PKCE
的私有回调也只交给发起的可信 Node RPC,不能返回沙箱 main.js 或业务 stdout。
+- 代输入([产品规则](../product-rules/input-handoff.md))复用同一签名输入桥:每一步按
+ (requestId, revision) 绑定,主人填写的**所有**值(不只密码)只在 Main 执行输入那一下存在,
+ 提交对象用后逐键删除;不进 Renderer store、续接消息、任务记录、数据库、日志、IM 或推送。
+ 卡片快照只含界面结构与界面上显示的文字;截图像素只走本地受信 IPC 或加密 offer。
+ 宿主注入任务 shell 的 askpass(`SUDO_ASKPASS` / `SSH_ASKPASS` / `GIT_ASKPASS`,经
+ `taskShellEnv`)只携带本机一次性路由,不携带秘密;口令只写回发起的那个进程。
+ 设备码「复制代码」写入的是界面上本就显示的短期代码,不属于主人填写的值。
- access token 等只需短期使用的秘密优先保留在内存中。日志、错误、遥测和调试输出不得
包含凭证明文、完整鉴权头或可直接复用的授权材料。
- 测试只使用明显无效的假凭证,不读取或复制开发者真实的 `HOME`、Agent home、
diff --git a/docs/dev-rules/maker-core-and-agent-behavior.md b/docs/dev-rules/maker-core-and-agent-behavior.md
index 7db897937f..4764976f88 100644
--- a/docs/dev-rules/maker-core-and-agent-behavior.md
+++ b/docs/dev-rules/maker-core-and-agent-behavior.md
@@ -308,6 +308,19 @@ sessionRunningRetry 就停。每次因 replacement 关闭而重新入队都计
事件、上下文和结果,不在中间造成无意损失(见
[`../product-rules/core-product-principles.md`](../product-rules/core-product-principles.md))。
+### 代输入:任务 shell 环境与工具说明(2026-10-13)
+
+- `runtimeConfig.taskShellEnv({ sessionId })` 给本任务 Agent 运行的命令注入代输入 askpass
+ (`SUDO_ASKPASS` / `SSH_ASKPASS` / `GIT_ASKPASS` 等,只含本机一次性路由,不含秘密)。三个 Harness
+ 只对**本账号的本机任务**调用:SSH 远程、Review、设备托管访客任务一律不注入。Claude Code 与 Pi 写进
+ Agent 进程 env;Codex 的 app-server 共享,按线程经 `shell_environment_policy.set.<名>` 设置。
+ 返回值必须按 sessionId 确定,重启进程得到字节相同的 env(否则破坏缓存与重建一致性)。
+- `request_input_handoff`(`packages/lizi-mcps/src/xdt-helper/input_handoff.ts`)的使用时机只写在工具
+ 说明里,**不改 system prompt**;子 Agent(`mcpCallerKind === 'descendant'`)与远程工作区任务直接拒绝。
+ 何时该发起靠工具返回提示(如 `cindy_computer` 拒绝直接操作保密输入框),不靠提示词。
+- 续接是隐藏的 `[Input handoff ended]` 合成消息,只有事实;产品规则见
+ [`../product-rules/input-handoff.md`](../product-rules/input-handoff.md)。
+
## 2. 优先用代码保证确定性,而非依赖 prompt
能用代码保证的行为都写在代码里,让结果可预测、可测试、可调试;prompt 只承担真正需要
diff --git a/docs/dev-rules/pi-harness.md b/docs/dev-rules/pi-harness.md
index febcb2a408..dd0e952178 100644
--- a/docs/dev-rules/pi-harness.md
+++ b/docs/dev-rules/pi-harness.md
@@ -360,6 +360,12 @@ Pi CLI 管理入口、内核自更新与旧工具兼容的执行边界见
- SDK 成功与正文入库/交付分开取证。只见 JSONL 成功但 SQLite 缺正文时,不能自动重跑
已成功的工作;应沿 RPC → translator → Session → persistence 查丢失边界。
+- 代输入 askpass(2026-10-13):Pi 本机任务的 Agent 进程 env 合入 `runtimeConfig.taskShellEnv`,
+ 只在 `!remote && !hosted && !reviewMode` 时合入,且按 sessionId 确定(respawn 字节一致)。这只是给
+ sudo/ssh/git 提供口令来源,不改 Pi 原生命令、扩展或权限行为;Pi 自身的 bash 工具照常执行,口令由宿主
+ 核验进程链后写回发起进程。见 [`maker-core-and-agent-behavior.md`](maker-core-and-agent-behavior.md)
+ 「代输入:任务 shell 环境与工具说明」。
+
## 5. 已交付(2026-07 里程碑)
- redacted thinking 不再显示为空卡片;PI 会话图标(π);Auto-review 核心 + pi adapter + auto 档;
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 384bed2ecc..6bf3f2e95d 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -193,6 +193,31 @@ Claude Code 终态 error 事件可带 `usageResetAt`(unix ms)。服务端无
增加 alias fallback。Desktop 与 Mobile 复用同一握手 parser;长企业键要求控制端也具备
该校验能力,旧端的短键行为保持不变。
+## 代输入(2026-10-13)
+
+产品规则见 [`../product-rules/input-handoff.md`](../product-rules/input-handoff.md),共享类型与 parser 在
+`packages/device-link/src/inputHandoff.ts`。
+
+- **卡片快照** `InputHandoffSnapshot`(`kind: "input_handoff"`)随既有交互推送下发,控制端按字段透传、
+ 不做结构化拒收。新能力一律加**可选**字段:`picture`(本步按截图作答,像素不在快照里)、`liveView`
+ (可打开单窗口实时画面)、`deviceCode`(`{ code, url, origin }`,设备码登录)、`holder`、`remoteInput` 等。
+ 旧控制端忽略不认识的字段,仍能看到本步的说明文字并交还/取消;新控制端只在字段存在时展示对应入口。
+ `deviceCode` 在打开前必须经 `isInputHandoffDeviceCode` 复核(https、无账号密码、origin 与显示一致)。
+- **带值提交**只走插件授权 v3:`capabilities` 声明 `inputHandoff: true`,`start` 带 `inputHandoff: true`;
+ 每步按 (requestId, revision) 绑定,`validateInputHandoffSubmissionForStep` 复核控件与值上限。
+ 加密 offer 上限放宽到 480,000 字节以容纳一张截图(`PLUGIN_OAUTH_SEALED_MAX_BYTES.offer`),
+ 控制端回传的 callback 仍为 32,000 字节。对端未声明 `inputHandoff` 时返回「请更新」,**不降级到明文**。
+ 不带值的决定(交还、取消、停留、刷新、接手、看画面)沿用既有 `resolveInteraction`。
+- **单窗口实时画面**沿用远程桌面业务通道,不改 relay、IPC allowlist 或协议版本:
+ - 被控端以可选能力 `handoffWindow` 声明支持;控制端只在 `start` 里附 `handoff: <requestId>`
+ (`^[A-Za-z0-9_-]{1,128}$`),**不能**指定窗口——窗口由被控端按请求选择。
+ - 响应的 lease 附 `window: { app, title? }`。控制端收到不带 `window` 的整屏 lease 时立即 `stop` 并报错;
+ 被控端未声明能力时控制端报 `CHANNEL_NOT_ALLOWED`、不展示入口。
+ - 该 lease 只允许窗口内输入:控制端剔除整桌面能力(剪贴板、显示模式、隐私屏、系统音频、接管),
+ 被控端拒绝越界操作(`DESKTOP_HANDOFF_WINDOW_ONLY`),代输入结束即结束(`DESKTOP_HANDOFF_ENDED`),
+ 非 macOS 或要求音频时拒绝(`DESKTOP_HANDOFF_UNAVAILABLE` / `DESKTOP_AUDIO_UNAVAILABLE`)。
+ - 先发被控端:卡片上的 `liveView` 由执行代输入的那台电脑给出,它本身就是新版。
+
## Agent 跨设备历史发现与搜索
`cindy_helper` 的 `list_history_devices` 使用现有同账号设备目录;`list_sessions` 和
diff --git a/docs/dev-rules/remote-and-mobile-adaptation.md b/docs/dev-rules/remote-and-mobile-adaptation.md
index 420d416afd..bc0e600207 100644
--- a/docs/dev-rules/remote-and-mobile-adaptation.md
+++ b/docs/dev-rules/remote-and-mobile-adaptation.md
@@ -40,6 +40,23 @@ Cindy 的产品形态不止本地桌面单机。同一个功能可能运行在
同步 topic 路由;不登记,手机/远程控制端就永远调不通。
3. 手机版需不需要对应的入口/UI/交互?
+## 代输入的多端适配(2026-10-13)
+
+产品规则见 [`../product-rules/input-handoff.md`](../product-rules/input-handoff.md)。三种形态的落点:
+
+- **SSH 远程工作区**:不支持。目标窗口必须在执行代输入的这台电脑上;`request_input_handoff`
+ 在带 `remoteHostId` 的任务里返回 `CAPABILITY_NOT_AVAILABLE`,由 Agent 改为直接告诉主人需要什么。
+- **设备互联远程控制**:卡片快照随既有交互推送(`kind: "input_handoff"`)到所有控制端;交还、取消、
+ 停留、刷新、接手、看画面等**不带值**的决定走既有 `resolveInteraction`;**带值**的提交与截图只走插件
+ 授权 v3 加密交换(`plugin-oauth:submit-input` / `plugin-oauth:open-input-picture` /
+ `plugin-oauth:answer-input-picture`),不新增明文 invoke。对端不支持 v3 时卡片显示「请更新」,不降级。
+- **手机版**:同一张卡(`src/inputHandoff/`),系统保密输入与 AutoFill 类型、截图点按、设备码
+ (`expo-clipboard` + `Linking`,无新原生依赖)与单窗口实时画面(远程桌面路由带 `handoff` 参数)。
+ 推送深链回到所属任务。
+- 单窗口实时画面复用远程桌面通道:控制端只在 `start` 里带 `handoff: requestId`,由被控端按请求选窗口;
+ 被控端以 `handoffWindow` 能力位声明支持,旧被控端不声明时控制端不展示入口。协议细节见
+ [`protocol-compatibility.md`](protocol-compatibility.md)「代输入」。
+
## 恢复动作先回答故障半径(device-link 共享链路)
设备互联是 1:N 拓扑:被控端与 relay 之间只有一条连接,同账号的全部控制端共用它。
diff --git a/docs/product-rules/README.md b/docs/product-rules/README.md
index c1cdf76aba..69e2ce607d 100644
--- a/docs/product-rules/README.md
+++ b/docs/product-rules/README.md
@@ -30,5 +30,7 @@
叫「任务」,任务 / 对话 / 消息的分层定义与判定规则,以及「任务」与 `task` 的歧义处理。
- [`document-workshop-quality.md`](document-workshop-quality.md):无插件文档基础能力的
HTML-first 工序、四格式统一视觉语言、Session 作品卡和插件增强层边界。
+- [`input-handoff.md`](input-handoff.md):代输入——Agent 把需要主人的一步(登录、密码、验证码、
+ 授权、未知选项)交给主人逐步完成,值不留痕;兜底、提醒、结束判定与已知边界。
- [`session-runtime-control.md`](session-runtime-control.md):Agent 调整任务模型、来源、
推理强度与 Fast 的统一控制面,baseline/effective/pending 状态和自动降级边界。
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index 15f8c645b8..8049200acc 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -660,6 +660,9 @@ Todo 是伙伴维护的事务清单:既包含用户交办,也允许从已授
- 不隐瞒能力缺口:未安装、未连接、全局停用或当前引擎/远端不支持时明确返回状态。目录读取失败
必须报告,不能用空列表启动并宣称已全配。Cindy 安装更新只能经 `install_app_update`
由宿主向主人弹确认卡后执行(见 [`agent-app-update.md`](agent-app-update.md)),`check_app_update` 只检查更新。
+- 代输入(2026-10-13,[产品规则](input-handoff.md)):伙伴与普通任务共用 `request_input_handoff` 与
+ 终端 askpass,卡片同样只交给主人。伙伴设置能力页有独立开关(`capabilities.inputHandoff`,缺省为开);
+ 关闭后按伙伴**当前** Profile 即时对它所有运行中任务生效,工具调用与终端口令都直接拒绝,不影响普通任务。
- 本改动不引入跨设备控制协议、新的 `control_session` 大工具或新的幂等数据库表。
通用工具保留原名和发现路径。伙伴的身份、个人记忆和 Skill 学习与工具权限分开维护。
diff --git a/docs/product-rules/input-handoff.md b/docs/product-rules/input-handoff.md
new file mode 100644
index 0000000000..e8b5dd6fe9
--- /dev/null
+++ b/docs/product-rules/input-handoff.md
@@ -0,0 +1,152 @@
+# 代输入:Agent 把需要主人的输入交给主人
+
+> 适用:普通任务(Claude Code / Codex / Pi)与伙伴任务。实现入口:
+> `apps/desktop/src/main/input-handoff/`(宿主)、`packages/device-link/src/inputHandoff.ts`
+> (卡片快照与提交协议)、Desktop `renderer/features/input-handoff/`、Mobile `src/inputHandoff/`。
+> 术语「代输入」在 `i18n/glossary.json` 为 proposed,定稿前文案沿用。
+
+## 1. 用户应该得到什么
+
+Agent 在任何界面遇到只有主人才能填的输入框——账号、密码、验证码、它不知道的个人信息——调用
+`request_input_handoff`,本轮结束。宿主读取目标窗口**当前这一步**,在主人的设备上、**输入框上方**出现一条
+代输入条:图标、Agent 说的用途、宿主核实的位置(安全网站显示锁 + 站点,否则显示来源或应用名),右侧「跳过」
+「填写」。点「填写」打开表单(iPhone 是系统原生底部面板,电脑与其它平台是同样版式的对话框),**表单上只有这一步
+要主人填的输入框**(普通文本框变标准输入框、密码框变系统保密输入框,带显示密码的眼睛),以及页面对这些输入框的
+报错。主人在最后一项按回车(手机键盘的「前往」)或点「继续」,宿主把值填进真实界面,再按页面自己的主按钮(没有
+就在最后一个输入框按回车)。界面稳定后若又出现要主人填的输入框,就把**下一步**刷到同一个表单上(主人没关表单时
+它自己回来);没有了就交还给 Agent。
+
+- **只在有输入框要主人填时才弹**:按钮、选项、开关、勾选、授权同意页都由 Agent 自己处理,卡片上不出现。
+ 界面上没有要主人填的输入框时,请求立即结束(`nothing_to_fill`),不弹卡、不推送,Agent 继续。
+- 表单不显示页面的按钮、标题、链接、步数;「继续」与回车等价。「取消」只关表单,代输入条还在;「跳过」才结束本次代输入。
+- **Agent 不需要知道有几步**,也不预先描述每一步;界面出现什么输入框,卡片显示什么。
+- **通用,不做站点或业务适配**:同一套逻辑覆盖桌面上的任何程序——网页、Electron 应用、原生 App(含微信等扫码登录的桌面客户端)与终端口令,不只网页登录。
+- **不以远程控制为主路径**:主人看到的是卡片;截图点按与单窗口实时画面只是个别步骤的兜底。
+
+## 2. 产品不变量
+
+### 2.1 主人的值不留痕
+
+- 主人填写的**所有**值(不只密码)只交给宿主执行那一下,随即清零;不进模型上下文、工具结果、续接消息、
+ 任务记录、数据库、日志、上传日志、IM、推送。续接消息只有事实:状态、结束方式、步数、最终应用/窗口/
+ origin(`buildInputHandoffContinuation`)。
+- 本机 Desktop 经受信本地 IPC 提交;手机与其它电脑经插件授权 v3 的签名握手 + 端到端加密,按
+ (requestId, revision) 逐步绑定;旧版本对端返回「请更新」,**不降级到明文**。
+- 卡片快照(经 device-link 推送,不加密)只含界面本身显示的结构与文字,从不含输入框里的值;截图像素只走
+ 本地受信通道或加密 offer,快照里只有 `picture: true`。
+- Agent 之后自己读界面时能看到界面显示的非密码内容——那是界面状态,不是 Cindy 转交的。
+- 任务记录只留一行「主人完成了 N 步输入」类的事实(`inputHandoffRecord`)。
+
+### 2.2 防钓鱼与执行边界
+
+- 卡片顶部是**宿主核实**的来源:应用名、窗口、网页 origin;Agent 写的 `purpose` / `note` 单独标为 Agent 说明。
+- origin 是 IP、`localhost`、`file:` / `data:`、punycode、http 明文、跨域 iframe 里的密码框 → 警示(`originPolicy.ts`),
+ 只加提醒不拦截;提交时 origin 已变 → 本步作废不填(`origin_changed`)。
+- 主人在 Agent 驱动的浏览器页面填过密码后,该页面(同 scheme/host/port/path)在离开前暂停 Agent 的读页工具
+ (脚本执行、网络请求与响应体、console),15 分钟过期(`secretTaint.ts`)。
+- Agent 直接操作保密输入框会被拒绝并提示改用代输入(`cindy_computer` 的 `isSecureTarget`)。
+- Electron 应用等 Agent 在目标进程里能跑脚本的界面,卡片明示「此界面由 Agent 控制」。威胁模型边界:保证 Cindy
+ 不记录、不转发、不交给模型并挡住网页钓鱼;不是针对「Agent 本身恶意且在目标进程里有任意代码」的沙箱。
+
+### 2.3 谁能答、在哪里答
+
+- 只有主人:共享任务访客、群成员、IM 非主人都不能提交(宿主判定)。
+- 本机 Desktop、手机、主人其它电脑同时出现卡片;**先开始处理的设备持有本次会话**,其它设备显示「正在 iPhone
+ 上处理」,可「接手」。接手会推进 revision,旧设备在途的提交按过期拒绝。无人持有时首个按键的静默认领同样推进
+ revision,但认领设备按认领前 revision 发出的提交仍有效(密码管理器「填充并提交」比认领回执更快),其它设备不享有此例外。
+- 每任务同时只有一个待处理代输入;一小时内最多 6 次(防循环骚扰);
+ 伙伴设置可关闭该伙伴的代输入(`capabilities.inputHandoff === false`,即时对所有运行中任务生效)。
+
+### 2.4 提醒
+
+- 手机推送正文固定(`settings.notifications.sessionEvent.inputHandoff`),不含界面文字和 Agent 写的目的;
+ 只在卡片真正有东西要主人填时提醒(读取中、无需输入就结束的请求不提醒,也不出现在任何设备上),
+ 每出现新的一步再提醒一次。
+- 由 IM 渠道驱动的任务(个人 bot 与官方 Telegram bot),在该聊天里发**一行固定指引**
+ 「🔐 需要你帮忙输入:<任务名> · 在 Cindy 中打开」,每个请求一次(`im/shared/inputHandoffChannelNotice.ts`);
+ 飞书 `/ctr` 接管的桌面任务沿用桌面确认提示的飞书通道。IM 里不显示界面内容、不收输入。
+- Agent Island 显示待处理卡片,结束即撤下。
+
+### 2.5 结束与交还
+
+- 宿主判定:主人至少答过一步之后,当前界面已没有要主人填的输入框(只剩按钮、选项或授权同意页也算)→ 卡片进入约 3 秒可取消的倒计时,
+ 到点自动交还;主人可点「还没完」停留在本步。Agent 给的 `complete_when`(窗口关闭 / 出现文字 / URL 包含)同样可触发。
+- 主人随时可取消;超时(默认 15 分钟,最长 60)、目标窗口消失也会结束。
+- **交还不等于成功**:Agent 拿到续接后自己检查结果,未完成可再次发起。
+
+## 3. 一步读不出来时(只限这一步)
+
+| 情形 | 卡片 |
+| --- | --- |
+| 结构读不出(画布、自绘界面、图形验证码) | **截图点按**:宿主无法判断有没有输入框,所以显示该窗口截图,主人点哪里就在真实窗口点哪里;有焦点输入框时附一个输入框(「填入」只打字、「填入并回车」再按回车)。主人也可在任一步从卡片底部的「看画面」切过来。读不出结构又截不到图时请求失败(`unreadable`)。执行电脑锁屏时(显示器休眠也会锁屏)不读取也不输入,直接以 `screen_locked` 结束,提示主人先唤醒并解锁;Agent 等主人说已解锁后再发起。 |
+| 截图点按也不够(拖动滑块等) | **单窗口实时画面**:主人主动打开,只含该窗口;输入限制在窗口内,不能切显示器、不能锁屏或解锁、没有声音与剪贴板。随代输入结束而结束。需要执行电脑开启远程桌面(仅 macOS)。 |
+| 设备码登录(界面只给一个代码 + 一个链接) | 卡片显示代码、「复制代码」与「在本设备打开」(显示目标 origin);主人在自己设备已登录的浏览器里完成,再点「交还给 Agent」。此步不会自动倒计时交还。 |
+
+- 设备码识别是通用形状判断:本步没有文本输入,且恰好一个代码形状的文本(带连字符分组且含字母,或单独成行的
+ 6–10 位大小写字母数字混合)与恰好一个公网 https 链接;有歧义就按普通步骤显示。客户端打开前再校验一次
+ (https、无账号密码、origin 与显示一致)。
+- 下一步能读出结构时自动回到卡片。
+
+## 4. 扫码登录
+
+国内大量网站与桌面客户端(淘宝、微信电脑版等)只给一个登录二维码。宿主在本步没有要主人填的输入框时,用系统
+自带的识别(macOS Vision,图片经标准输入交给本机原生助手,不落盘)在目标窗口里找二维码;找到就把这一步变成
+**扫码**:代输入条的主按钮是「扫码」,打开后显示从窗口裁出的二维码大图。
+
+- **码的内容只走加密通道**:二维码图片与它写的内容随本步的截图一起,只走本地受信通道或加密 offer
+ (`picture.qr`),快照里只有 `qr: "scan"`;不进模型、记录、日志、推送。
+- **主人这边**(手机):码是可打开的链接时,第一个按钮是「在本机打开 <站点>」——网页链接(https 或 http,
+ 有的码就是借浏览器网址唤起 App)与 App 链接(`weixin://`、`alipays://` 这类)都按手机相机扫到后的方式打开;
+ 其次「存图或分享」(系统分享面板,可存到相册后在 App 的「扫一扫」里从相册识别;临时文件在分享后约 2 分钟删除,
+ 不新增相册权限,避免冷更),以及「复制链接 / 复制内容」。只有 `javascript:`、`data:`、`file:` 这类手机相机也
+ 不会打开的内容不给打开,只能复制或存图;`WIFI:`、`tel:`、名片等按内容处理。
+- **主人这边**(另一台电脑):拿手机对着屏幕扫;码是网页链接时可「在本机打开」(电脑只打开网页链接,App 链接
+ 留给扫码的手机),还可「复制图片」「复制链接」。
+- 点按二维码等于点在电脑上的这个码上(例如过期后的「点击刷新」)。电脑上换了新码会自动跟上(每 2 秒看一次,
+ 只在目标窗口在最前且聚焦时看,不抢焦点)。
+- **登录成功自动继续**:码消失后,若窗口出现了要填的输入框(例如扫完还要验证码)→ 直接显示这一步;若窗口换了
+ 标题、网址或位置、命中 `complete_when`,或登录窗口关闭 → 判定完成,约 3 秒倒计时后交还;否则代输入条显示
+ 「已扫码,等你在手机上确认」,主人也可直接交还或跳过。别的程序挡在前面时不下结论。
+
+## 5. 终端口令
+
+本任务 shell 里的 `sudo -A`、`ssh`、HTTPS 上的 `git` 要口令时,宿主注入的 askpass 核对请求方进程链(系统路径的
+sudo/ssh/git,属于本任务),合格则开启一步代输入,卡片显示完整命令;Agent 的命令直接继续,无需调用工具。
+Windows 暂不支持 askpass。
+
+## 6. 已知边界(如实标注,不算缺陷)
+
+- 读取与执行依赖 macOS 辅助功能;其它平台返回 `UNSUPPORTED`。
+- 按键只发给最前面的程序:打字前确认目标程序在最前。系统不许后台辅助程序切换前台时,点一下目标窗口自己的
+ 空白标题栏把它带到前面;仍带不到前面(例如标题栏被挡住)就不打字,这一步报填写失败。
+- 单窗口实时画面:窗口外的弹层(独立窗口的菜单、系统对话框)点不到;窗口缩放后画面比例可能短暂不一致;
+ 「窗口在最前」检查与投递事件之间存在竞争窗口。
+- 读页暂停按 URL 路径匹配;跨域 iframe 内的结构可能读不到;覆盖检测可能误报(误报只会转为截图点按);
+ 截图点按的读页暂停取最后一次能读出的页面地址。
+- 做不到:Touch ID / 通行密钥要主人在电脑旁;Claude 订阅登录按仓库规则不收集;开机前 FileVault 不支持。
+- 扫码识别依赖 macOS Vision;窗口里有多个码时取最大的一个;码被遮挡或太小时识别不到,按截图点按处理。
+
+## 7. 已裁决
+
+| 日期 | 事项 | 裁决 |
+| --- | --- | --- |
+| 2026-10-13 | 结束判定 | 宿主自动判定 + 约 3 秒可取消倒计时 |
+| 2026-10-13 | 非密码值是否也对 Agent 保密 | 全部不经 Cindy 转交 |
+| 2026-10-13 | 交付形态 | 本地完整可用后一次提 PR |
+| 2026-10-13 | 手机提交前 Face ID | 本次不加:需要新原生能力会触发冷更;手机端依赖密码管理器自身的面容验证 |
+| 2026-10-13 | 卡片内容 | 只放主人该填的输入框和页面对它们的报错;按钮、选项、开关、授权页归 Agent;没有输入框不弹卡;回车即提交,宿主按页面主按钮确认;不设「拒绝,本任务不再询问」 |
+| 2026-10-14 | 呈现形态 | 输入框上方一条代输入条 +「填写」打开的原生表单(iPhone 系统底部面板,电脑同版式对话框) |
+| 2026-10-14 | 适用范围 | 桌面上的任何程序,不只网页登录 |
+| 2026-10-14 | 扫码登录 | 读出远端窗口的二维码交给主人扫或在本机打开,远端自动判定登录成功 |
+| 2026-10-14 | 扫码后的打开顺序 | 「在本机打开」优先于存图分享;http 与 App 链接都可打开,只挡相机也不会打开的内容 |
+
+## 8. 验收
+
+- 多步流程(应用里的账号 → 跳浏览器的密码 → 授权同意页)在本机、手机、另一台电脑上都能逐步完成:卡片只出现
+ 账号、密码两步,到授权页自动交还;只有按钮的界面发起代输入时不弹卡、不推送,Agent 收到 `nothing_to_fill`;
+ 续接消息、任务记录、日志里搜不到主人填写的任何值。
+- 1Password / 系统密码能在卡片的密码框里自动填充(Desktop `autocomplete`、iOS `textContentType`)。
+- 截图点按、单窗口实时画面、设备码、终端 sudo/ssh/git 各走通一次;第二台设备接手后旧设备提交被拒。
+- 扫码登录:网页与桌面客户端的登录码各走通一次——手机上能在本机打开、存图、复制;码刷新后手机跟上;扫完自动交还,
+ 扫完还要填的输入框直接出现。
+- 推送与 IM 指引里没有界面内容;Light / Dark 两种模式下卡片可读。
diff --git a/docs/product-rules/message-source.md b/docs/product-rules/message-source.md
index 52c9e9f7aa..81757efddf 100644
--- a/docs/product-rules/message-source.md
+++ b/docs/product-rules/message-source.md
@@ -35,6 +35,14 @@
- 切换引擎、上下文滚动、重建式分叉从落库数据重建交接摘要时,按 `agentMeta` 重新生成
来源标记;`[UI_ACTION_TRIGGER]` 合成行仍不进交接。
+### 代输入续接(2026-10-13)
+
+- 代输入结束时宿主给 Agent 发一条隐藏续接,首句 `[Input handoff ended]` 声明这是宿主事实、
+ 不是用户消息;只含状态、结束方式、步数、最终应用 / origin 与作答设备类别,**不含主人填写的任何值**
+ (`packages/maker-shared/src/syntheticTrigger.ts`)。
+- 界面不显示续接原文,桌面与手机从同一行派生一条可见留痕「主人在 iPhone 完成了 3 步输入 ·
+ <域名>」;IM 渠道只收固定指引,不收续接。产品规则见 [代输入](input-handoff.md)。
+
## 界面
- 桌面与手机同一文案;Android 跟随 iOS。
diff --git a/docs/product-rules/telegram-bot-parity.md b/docs/product-rules/telegram-bot-parity.md
index 9e24f8d048..cfccd360a2 100644
--- a/docs/product-rules/telegram-bot-parity.md
+++ b/docs/product-rules/telegram-bot-parity.md
@@ -75,6 +75,7 @@ App 完成未读与提醒统一由 `renderer/hooks/useSessionRunningStatus.ts`
|---|---|---|
| 子代理输出隔离 | `im/shared/agentEventScope.ts` + `maker-core/agents/claude-code/translator.ts` | 官方 `hook-control/turnObserver` 与个人 `im/shared/turnRunner` 在消费实时事件前过滤带 `agentMeta.parentUuid` 的子代理事件。内部正文、工具/思考、媒体旁路和终态不进入主任务的 IM 回帖,也不影响主任务收口;个人侧自动任务转播同样适用。Claude translator 为子代理工具结果保留归属,主代理流式事件不继承子代理元数据;主任务正文统计和最后消息的实质内容判定只消费主代理,子代理完整消息与流式增量都不阻断主任务 result 截断补发,也不覆盖 silent-stop 判定。整轮失败即使由子代理 API 错误引起,仍按主任务失败收口。主代理主动引用的成果正常发送,桌面完整记录不变。 |
| 普通工具权限的多处确认 | `maker-ipc/interactionRouter.ts` + `sharedPermission.ts` | IM 与 Cindy 共用一个决定,首次有效回答生效,桌面/手机与渠道同步收口。来源正文由 `im/shared/interactionSource.ts` 构造;个人富卡与官方 Hook 分别负责各自载体更新。供应商分享的本机凭证确认卡共用 `interactionCardModel.ts` 回传当前任务的凭证授权标记;个人卡片点击从 pending 保存的原请求恢复作用域,不转换成通用工具允许规则。未来渠道复用同一注册接口,详见 [共享合同](im-permission-confirmation.md)。 |
+| 代输入指引(2026-10-13) | `im/shared/inputHandoffChannelNotice.ts` | 任务开出代输入卡时,在驱动该任务的聊天里发**一行固定文字**「🔐 需要你帮忙输入:<任务名> · 在 Cindy 中打开」,每个请求一次。个人 bot 由 `turnRunner` 在 `beforeProviderStart` 绑定 `im.sendText`;官方 bot 由 `session-runner` 绑定与运行时回收提示同一条独立发送(`onRuntimeRecovery`,需协商 `msg-op-v1`,未协商时不发)。卡片、界面内容与主人填写的值**两侧都不进 Telegram**——这是有意的产品边界(值只走 Cindy 加密通道),不是缺口。详见 [代输入](input-handoff.md)。 |
| 模型列表的开关就绪 | `maker-host/model-visibility-mirror.ts` | 个人 `/model` 与官方 `listAgentModels` 均等待当前账号配置同步;超时返回错误,不把未同步当成全部关闭或回退出厂开关。 |
| 过程区与正文的**文本合成** | `im/shared/turnPresenter.ts` + `turnActivity.ts` | 过程区怎么排(工具步骤、思考步骤、耗时行)、过程区与正文怎么拼(`composeProgressView`)。耗时行末尾的当前 `N tok/s` 同源:两侧(含个人侧自动任务转播)都只经 `applyStatusTokenRate` 读 `status` 事件的 `tokenSpeed`(与桌面运行状态栏同一份读数)——无读数不显示、占位帧与 0 读数保留上一个值、`generationReliable === false` 隐藏、只随 ticker 带出不单独刷帧;凡把过程区冻结进终稿的收口(个人侧终止错误、转播收口)都经 `clearRunningIndicators` 与重试说明一起清掉。**正文累积不算**——见第三节:`createTurnPresenter` 按 `mode` 实例化两个独立引擎,累积、消息投影、`finalText()` 判据都不同,改一个引擎不影响另一个 |
| 运行中**过程消息**的生命周期、渲染与出站失败判据(官方需双方协商 `telegram-progress-ops-v1`) | `packages/lizi-im/src/telegram/streamingText.ts`(`startTelegramProgressCarrier` 与个人 `startTelegramStreaming` 是同一个 handle 类)+ `progressFrame.ts` + `outboundPolicy.ts` + `markdown.ts` 的 `markdownToTelegramHtml` | 惰性占位、1.5s 尾沿节流、首帧 send 后续 edit、单帧上限 `TELEGRAM_PROGRESS_FRAME_MAX_CHARS = 3800`(源 markdown 字符数;官方 presenter 的 `PresenterPolicy.intermediateMaxRenderedChars` 默认值也取它)、NO_REPLY 及其前缀不落地、HTML 被拒(400)回落纯文本、`message is not modified` 视为成功、429 按 `retry_after` 全长退避后重试一次——两侧跑同一份代码。**传输不同**:个人走 Bot API(`index.ts` 的 `callSend` / `sendRenderedChunk` / `editHtml`),官方走 msg.op(`hook-control/telegramTurnCarrier.ts` 只实现 `TelegramStreamingDeps` 的 msg.op 版,并经 `telegramMsgOp.ts` 把 `msg.op.result` 的 `channelErrorCode` / `error` / `retryAfterMs` 映射成同形错误);服务端只执行,不做转换与回落。未协商时官方仍由服务端渲染 `turn.progress`,本行对官方不成立 |
diff --git a/i18n/GLOSSARY.md b/i18n/GLOSSARY.md
index 535dc0e656..00c3be1d0d 100644
--- a/i18n/GLOSSARY.md
+++ b/i18n/GLOSSARY.md
@@ -323,6 +323,10 @@ Chat Server 的群角色,可由人或伙伴担任;不要与伙伴主人或
模型显示品牌采用官方中文名称,版本号和变体原样保留;仅用于展示与搜索,不改模型 ID 或用户保存的名称。
+### Input Handoff
+
+Agent 遇到需要主人填写的界面(选择、文本、密码、验证码、授权)时,由宿主读出当前一步,主人在本机或远程设备上填写,值只交给宿主、不进模型与记录。不是远程控制。
+
### Invitation Code
共享任务加入表单中由房主提供、访客输入的代码;用户要求明确称为邀请码,避免被理解为任意邀请文本。
diff --git a/i18n/glossary.json b/i18n/glossary.json
index 6aa9363c1e..a1e6ad2d79 100644
--- a/i18n/glossary.json
+++ b/i18n/glossary.json
@@ -5,6 +5,7 @@
"sourceLocale": "en",
"punctuationExempt": ["desktop:settings.help.qnaFeedbackBodyTemplate"],
"terms": [
+ {"id": "input-handoff", "status": "proposed", "en": "Input Handoff", "translations": {"zh-CN": "代输入", "zh-TW": "代輸入", "ja": "代理入力", "ko": "대리 입력"}, "checkCase": false, "note": "Agent 遇到需要主人填写的界面(选择、文本、密码、验证码、授权)时,由宿主读出当前一步,主人在本机或远程设备上填写,值只交给宿主、不进模型与记录。不是远程控制。"},
{"id": "wallpaper-blur", "status": "proposed", "en": "Wallpaper Blur", "translations": {"zh-CN": "壁纸模糊", "zh-TW": "桌布模糊", "ja": "壁紙のぼかし", "ko": "배경화면 흐림"}, "note": "仅使应用壁纸柔化,不模糊文字或控件;0 为关闭,按用户选择应用于静态图片和视频。"},
{"id": "group-owner", "status": "proposed", "en": "Group Owner", "translations": {"zh-CN": "群主", "zh-TW": "群主", "ja": "グループオーナー", "ko": "그룹 소유자"}, "checkCase": false, "note": "Chat Server 的群角色,可由人或伙伴担任;不要与伙伴主人或分工负责人混同。群设置成员行英文可简写 Owner。"},
{"id": "group-admin", "status": "proposed", "en": "Group Admin", "translations": {"zh-CN": "群管理员", "zh-TW": "群管理員", "ja": "グループ管理者", "ko": "그룹 관리자"}, "checkCase": false, "note": "可管理群资料和成员,但不能替伙伴主人授权工具或私人资料。群设置内可简称管理员 / Admin。"},
diff --git a/packages/device-link/src/__tests__/inputHandoff.test.ts b/packages/device-link/src/__tests__/inputHandoff.test.ts
new file mode 100644
index 0000000000..50fbdbd512
--- /dev/null
+++ b/packages/device-link/src/__tests__/inputHandoff.test.ts
@@ -0,0 +1,245 @@
+import { describe, expect, it } from 'vitest';
+import type { InputHandoffSnapshot } from '../inputHandoff.js';
+import {
+ INPUT_HANDOFF_PICTURE_MAX_BYTES,
+ INPUT_HANDOFF_PICTURE_MAX_SIDE,
+ inputHandoffHeldElsewhere,
+ inputHandoffPresentation,
+ inputHandoffStepKey,
+ parseInputHandoffDecision,
+ parseInputHandoffOffer,
+ parseInputHandoffPicture,
+ parseInputHandoffPresentation,
+ parseInputHandoffQr,
+ parseInputHandoffSubmission,
+ inputHandoffQrContent,
+ inputHandoffQrLink,
+ validateInputHandoffSubmissionForStep,
+} from '../inputHandoff.js';
+
+const controls: InputHandoffSnapshot['controls'] = [
+ { id: 'c0', kind: 'text', label: 'Email', contentType: 'email' },
+ { id: 'c1', kind: 'note', tone: 'error', text: 'Enter a valid email' },
+];
+
+describe('代输入 holder', () => {
+ it('is free for everyone until a device starts handling it', () => {
+ expect(inputHandoffHeldElsewhere({}, { local: true })).toBe(false);
+ expect(inputHandoffHeldElsewhere({}, { deviceId: 'phone-1' })).toBe(false);
+ });
+
+ it('tells each device whether someone else is handling it', () => {
+ const onPhone = { holder: { deviceId: 'phone-1' } };
+ expect(inputHandoffHeldElsewhere(onPhone, { deviceId: 'phone-1' })).toBe(false);
+ expect(inputHandoffHeldElsewhere(onPhone, { deviceId: 'desk-2' })).toBe(true);
+ expect(inputHandoffHeldElsewhere(onPhone, { local: true })).toBe(true);
+ // A device without a known id can never be mistaken for the holder.
+ expect(inputHandoffHeldElsewhere(onPhone, { deviceId: null })).toBe(true);
+
+ const onHost = { holder: { local: true as const } };
+ expect(inputHandoffHeldElsewhere(onHost, { local: true })).toBe(false);
+ expect(inputHandoffHeldElsewhere(onHost, { deviceId: 'phone-1' })).toBe(true);
+ });
+
+ it('accepts take-over as a value-less decision', () => {
+ expect(parseInputHandoffDecision({ kind: 'input_handoff', action: 'claim', expectedRevision: 3 })).toEqual({
+ kind: 'input_handoff',
+ action: 'claim',
+ expectedRevision: 3,
+ });
+ expect(parseInputHandoffDecision({ kind: 'input_handoff', action: 'steal', expectedRevision: 3 })).toBeNull();
+ expect(parseInputHandoffDecision({ kind: 'input_handoff', action: 'decline', expectedRevision: 3 })).toBeNull();
+ });
+});
+
+describe('代输入 step key', () => {
+ const base = { requestId: 'req1', stepNumber: 1, controls };
+
+ it('stays the same when only the revision moves, so a take-over keeps the draft', () => {
+ expect(inputHandoffStepKey(base)).toBe(inputHandoffStepKey({ ...base, controls: controls.map((c) => ({ ...c })) }));
+ });
+
+ it('changes for a new step or a different screen', () => {
+ expect(inputHandoffStepKey({ ...base, stepNumber: 2 })).not.toBe(inputHandoffStepKey(base));
+ const password: InputHandoffSnapshot['controls'] = [
+ { id: 'c0', kind: 'text', label: 'Password', contentType: 'password' },
+ controls[1]!,
+ ];
+ expect(inputHandoffStepKey({ ...base, controls: password })).not.toBe(inputHandoffStepKey(base));
+ });
+
+ it('gives a screenshot step its own key, so a form draft never carries over', () => {
+ expect(inputHandoffStepKey({ ...base, picture: true })).not.toBe(inputHandoffStepKey(base));
+ });
+});
+
+describe('代输入 screenshot step', () => {
+ const picture = { mime: 'image/jpeg', width: 640, height: 400, data: 'AAAA' };
+ const presentation = {
+ requestId: 'req1',
+ revision: 4,
+ purpose: 'Sign in',
+ source: { app: 'Chrome' },
+ command: null,
+ controls: [{ id: 'typed', kind: 'text', label: '' }],
+ picture: true,
+ qr: false,
+ };
+ const state = 'a'.repeat(43);
+
+ it('accepts a bounded JPEG and nothing else', () => {
+ expect(parseInputHandoffPicture(picture)).toEqual(picture);
+ for (const bad of [
+ { ...picture, mime: 'image/png' },
+ { ...picture, width: 0 },
+ { ...picture, height: INPUT_HANDOFF_PICTURE_MAX_SIDE + 1 },
+ { ...picture, data: '' },
+ { ...picture, data: 'not base64!' },
+ { ...picture, data: 'A'.repeat(Math.ceil(INPUT_HANDOFF_PICTURE_MAX_BYTES / 3) * 4 + 4) },
+ { ...picture, extra: 1 },
+ ])
+ expect(() => parseInputHandoffPicture(bad)).toThrow();
+ });
+
+ it('carries the picture exactly when the presentation says it is a screenshot step', () => {
+ expect(parseInputHandoffOffer({ kind: 'input-entry', state, presentation, picture }).picture).toEqual(picture);
+ expect(() => parseInputHandoffOffer({ kind: 'input-entry', state, presentation })).toThrow();
+ const form = { ...presentation, picture: false };
+ expect(() => parseInputHandoffOffer({ kind: 'input-entry', state, presentation: form, picture })).toThrow();
+ expect(parseInputHandoffOffer({ kind: 'input-entry', state, presentation: form }).picture).toBeUndefined();
+ });
+
+ it('requires the picture flag in every presentation', () => {
+ const { picture: _flag, ...withoutFlag } = presentation;
+ expect(() => parseInputHandoffPresentation(withoutFlag)).toThrow();
+ });
+
+ it('marks the presentation as a screenshot step without carrying pixels', () => {
+ const snapshot = {
+ requestId: 'req1',
+ revision: 4,
+ purpose: 'Sign in',
+ source: { app: 'Chrome' },
+ controls: [{ id: 'typed', kind: 'text', label: '', contentType: 'password' }],
+ picture: true,
+ } as unknown as InputHandoffSnapshot;
+ expect(inputHandoffPresentation(snapshot)).toEqual(presentation);
+ });
+
+ it('parses a tap as fractions of the picture', () => {
+ const tap = (action: unknown) => parseInputHandoffSubmission({ expectedRevision: 4, values: {}, action });
+ expect(tap({ kind: 'tap', x: 0.25, y: 1 }).action).toEqual({ kind: 'tap', x: 0.25, y: 1 });
+ for (const action of [
+ { kind: 'tap', x: -0.1, y: 0.5 },
+ { kind: 'tap', x: 0.5, y: 1.2 },
+ { kind: 'tap', x: '0.5', y: 0.5 },
+ { kind: 'tap', x: 0.5 },
+ { kind: 'tap', x: 0.5, y: 0.5, button: 'right' },
+ ])
+ expect(() => tap(action)).toThrow();
+ });
+
+ it('allows a tap only on a screenshot step, and only without values', () => {
+ const form = { revision: 4, controls: [{ id: 'typed', kind: 'text' as const, label: '', contentType: 'text' as const }] };
+ const shot = { ...form, picture: true as const };
+ const tap = { kind: 'tap', x: 0.5, y: 0.5 } as const;
+ expect(validateInputHandoffSubmissionForStep(shot, { expectedRevision: 4, values: {}, action: tap })).toBe(true);
+ expect(validateInputHandoffSubmissionForStep(form, { expectedRevision: 4, values: {}, action: tap })).toBe(false);
+ expect(validateInputHandoffSubmissionForStep(shot, { expectedRevision: 4, values: { typed: 'x' }, action: tap })).toBe(false);
+ expect(validateInputHandoffSubmissionForStep(shot, { expectedRevision: 3, values: {}, action: tap })).toBe(false);
+ expect(
+ validateInputHandoffSubmissionForStep(shot, { expectedRevision: 4, values: { typed: 'hello' }, action: { kind: 'submit' } }),
+ ).toBe(true);
+ });
+
+ it('carries only typed text, confirmed by the page itself', () => {
+ const form = { revision: 4, controls };
+ const submit = { kind: 'submit' } as const;
+ expect(validateInputHandoffSubmissionForStep(form, { expectedRevision: 4, values: { c0: '[email protected]' }, action: submit })).toBe(true);
+ // The error note is not a field.
+ expect(validateInputHandoffSubmissionForStep(form, { expectedRevision: 4, values: { c1: 'x' }, action: submit })).toBe(false);
+ // Typing without confirming is for screenshot steps only.
+ expect(validateInputHandoffSubmissionForStep(form, { expectedRevision: 4, values: { c0: 'x' }, action: { kind: 'fill' } })).toBe(false);
+ for (const bad of [
+ { expectedRevision: 4, values: { c0: true }, action: submit },
+ { expectedRevision: 4, values: {}, action: { kind: 'press', controlId: 'c1' } },
+ ])
+ expect(() => parseInputHandoffSubmission(bad)).toThrow();
+ // Page buttons and options never reach another device.
+ expect(() => parseInputHandoffPresentation({
+ requestId: 'req1', revision: 4, purpose: 'Sign in', source: { app: 'Chrome' }, command: null, picture: false, qr: false,
+ controls: [{ id: 'b0', kind: 'button', label: 'Next' }],
+ })).toThrow();
+ });
+
+ it('accepts asking for the picture as a value-less decision', () => {
+ expect(parseInputHandoffDecision({ kind: 'input_handoff', action: 'picture', expectedRevision: 2 })?.action).toBe('picture');
+ });
+});
+
+describe('代输入 QR step', () => {
+ const state = 'a'.repeat(43);
+ const snapshot = {
+ kind: 'input_handoff',
+ requestId: 'req1',
+ revision: 5,
+ phase: 'ready',
+ purpose: 'Sign in',
+ source: { app: 'WeChat' },
+ stepNumber: 1,
+ controls: [],
+ picture: true,
+ qr: 'scan',
+ } as InputHandoffSnapshot;
+ const link = 'https://login.example.com/qr?token=abc';
+ const picture = {
+ mime: 'image/jpeg', width: 400, height: 400, data: 'AAAA',
+ qr: { text: link, url: link },
+ };
+
+ it('says in the presentation that the picture is a code, and only for a code on screen', () => {
+ expect(inputHandoffPresentation(snapshot).qr).toBe(true);
+ expect(inputHandoffPresentation({ ...snapshot, qr: 'scanned', picture: undefined }).qr).toBe(false);
+ expect(() => parseInputHandoffPresentation({ ...inputHandoffPresentation(snapshot), picture: false })).toThrow();
+ });
+
+ it('carries what the code says inside the sealed picture, and nowhere else', () => {
+ const presentation = inputHandoffPresentation(snapshot);
+ expect(parseInputHandoffOffer({ kind: 'input-entry', state, presentation, picture }).picture?.qr).toEqual(picture.qr);
+ // A code step without its content, or a plain screenshot that claims one, is refused.
+ const { qr: _qr, ...plain } = picture;
+ expect(() => parseInputHandoffOffer({ kind: 'input-entry', state, presentation, picture: plain })).toThrow();
+ expect(() => parseInputHandoffOffer({
+ kind: 'input-entry', state, presentation: { ...presentation, qr: false }, picture,
+ })).toThrow();
+ });
+
+ it('opens what a phone camera would open: web links and app links, nothing that runs or reads locally', () => {
+ expect(inputHandoffQrLink(picture.qr)).toEqual({ url: link, site: 'login.example.com', web: true });
+ // Some codes are a plain http page that hands over to an app; app links open the app directly.
+ expect(inputHandoffQrContent(' http://192.168.1.2:8080/pair?t=1 ')).toEqual({ text: 'http://192.168.1.2:8080/pair?t=1', url: 'http://192.168.1.2:8080/pair?t=1' });
+ expect(inputHandoffQrLink({ text: 'weixin://dl/login?t=1', url: 'weixin://dl/login?t=1' })).toEqual({ url: 'weixin://dl/login?t=1', site: 'weixin', web: false });
+ expect(inputHandoffQrContent('alipays://platformapi/startapp?appId=1')?.url).toBe('alipays://platformapi/startapp?appId=1');
+ for (const text of ['WIFI:S:home;T:WPA;P:secret;;', 'tel:10086', 'javascript://x%0Aalert(1)', 'data://text/html,x', 'file:///etc/hosts', 'https://u:[email protected]/', 'just words'])
+ expect(inputHandoffQrContent(text)).toEqual({ text });
+ expect(inputHandoffQrContent('')).toBeNull();
+ expect(inputHandoffQrContent('a\u0007b')).toBeNull();
+ expect(inputHandoffQrContent('x'.repeat(2049))).toBeNull();
+ expect(parseInputHandoffQr({ text: 'WIFI:S:home;T:WPA;P:secret;;' })).toEqual({ text: 'WIFI:S:home;T:WPA;P:secret;;' });
+ for (const bad of [
+ { text: 'shown text', url: link },
+ { text: 'javascript://x%0Aalert(1)', url: 'javascript://x%0Aalert(1)' },
+ { text: 'https://u:[email protected]/', url: 'https://u:[email protected]/' },
+ { text: link, url: link, origin: 'https://login.example.com' },
+ { text: '' },
+ { text: 'a\u0000b' },
+ { text: 'x'.repeat(2049) },
+ { text: link, extra: 1 },
+ ])
+ expect(() => parseInputHandoffQr(bad)).toThrow();
+ });
+
+ it('gives a new key when the code was scanned, so the scanned state is a new screen', () => {
+ expect(inputHandoffStepKey(snapshot)).not.toBe(inputHandoffStepKey({ ...snapshot, qr: 'scanned', picture: undefined }));
+ });
+});
diff --git a/packages/device-link/src/__tests__/remoteDesktop.test.ts b/packages/device-link/src/__tests__/remoteDesktop.test.ts
index 97820d7959..141b5a0eda 100644
--- a/packages/device-link/src/__tests__/remoteDesktop.test.ts
+++ b/packages/device-link/src/__tests__/remoteDesktop.test.ts
@@ -52,6 +52,15 @@ describe("remote desktop wire boundary", () => {
parseRemoteDesktopRequest({ op: "start", displayId: "1", resume }),
).toThrow("INVALID_REQUEST");
});
+ it("carries a 代输入 request id on start, never a window of the viewer's choosing", () => {
+ expect(parseRemoteDesktopRequest({ op: "start", displayId: "1", handoff: "req_1-a" })).toEqual({
+ op: "start",
+ displayId: "1",
+ handoff: "req_1-a",
+ });
+ for (const handoff of ["", "a b", "x".repeat(129), 42, null, { window: 7 }])
+ expect(() => parseRemoteDesktopRequest({ op: "start", displayId: "1", handoff })).toThrow("INVALID_REQUEST");
+ });
it("limits permission actions to status and the dedicated guide", () => {
expect(
parseRemoteDesktopRequest({ op: "permissions", action: "guide" }),
diff --git a/packages/device-link/src/__tests__/remoteDesktopViewerSession.test.ts b/packages/device-link/src/__tests__/remoteDesktopViewerSession.test.ts
index 3021e4a97c..dabd12ae7f 100644
--- a/packages/device-link/src/__tests__/remoteDesktopViewerSession.test.ts
+++ b/packages/device-link/src/__tests__/remoteDesktopViewerSession.test.ts
@@ -270,3 +270,37 @@ it("keeps confirmed control when an older heartbeat omits its projection", async
f.request.mockResolvedValueOnce({});
expect(await f.session.heartbeat()).toEqual({ controlling: true });
});
+
+it("a 代输入 window view names only the request, hides controls past the window and refuses a whole display", async () => {
+ const f = fixture();
+ const full = { ...caps, handoffWindow: true, clipboardText: true, displayModes: true, privacyScreen: true, systemAudio: true, autoControl: true };
+ f.request.mockResolvedValueOnce(full).mockResolvedValueOnce({
+ lease: "lease",
+ display: { id: "screen" },
+ controlling: true,
+ window: { app: "Game", title: "Sign in" },
+ });
+ const seen = vi.fn();
+ const { caps: shown, lease } = await f.session.connect({
+ isCurrent: () => true,
+ handoff: "req1",
+ control: true,
+ onCapabilities: seen,
+ });
+ expect(f.request.mock.calls[1][0]).toEqual({ op: "start", displayId: "screen", control: true, handoff: "req1" });
+ expect(shown).toMatchObject({ handoffWindow: true, autoControl: true, canControl: true });
+ for (const key of ["clipboardText", "displayModes", "privacyScreen", "systemAudio", "connectionTakeover"])
+ expect(shown).not.toHaveProperty(key);
+ expect(seen).toHaveBeenCalledWith(shown);
+ expect(lease.window).toEqual({ app: "Game", title: "Sign in" });
+ await f.session.stop();
+
+ // An older host cannot show a single window.
+ f.request.mockResolvedValueOnce(caps);
+ await expect(f.session.connect({ isCurrent: () => true, handoff: "req1" })).rejects.toThrow("CHANNEL_NOT_ALLOWED");
+ // A host that answers with the whole display is released at once.
+ f.request.mockResolvedValueOnce(full).mockResolvedValueOnce({ lease: "whole", display: { id: "screen" } });
+ await expect(f.session.connect({ isCurrent: () => true, handoff: "req1" })).rejects.toThrow("INVALID_RESPONSE");
+ expect(f.request.mock.calls.at(-1)?.[0]).toEqual({ op: "stop", lease: "whole" });
+ expect(f.session.lease).toBeNull();
+});
diff --git a/packages/device-link/src/index.ts b/packages/device-link/src/index.ts
index 3dbdf7e64a..a418335e31 100644
--- a/packages/device-link/src/index.ts
+++ b/packages/device-link/src/index.ts
@@ -59,6 +59,7 @@ export * from "./pluginSecretSubmission.js";
export * from "./pluginConnectionSubmission.js";
export * from "./pluginDeviceAuthorization.js";
export * from "./pluginOauthAuthentication.js";
+export * from "./inputHandoff.js";
export * from "./inputDelivery.js";
export * from "./taskMigration.js";
export * from "./remoteAgent.js";
diff --git a/packages/device-link/src/inputHandoff.ts b/packages/device-link/src/inputHandoff.ts
new file mode 100644
index 0000000000..664d0afefb
--- /dev/null
+++ b/packages/device-link/src/inputHandoff.ts
@@ -0,0 +1,633 @@
+/**
+ * Input handoff (代输入): the Host reads one screen of a target UI, the owner
+ * completes it on any of their devices, and the Host performs it locally.
+ *
+ * Snapshots carry structure only (labels, options, roles). Values the owner
+ * enters travel exclusively through the trusted local Desktop channel or the
+ * signed plugin-oauth v3 exchange; they never appear in snapshots, plain
+ * interaction decisions, transcripts, logs or IM.
+ */
+
+/** Reserved binding id for the v3 signed handshake. Not an installable plugin id. */
+export const INPUT_HANDOFF_GHOST_ID = "cindy-input-handoff";
+/** Trusted Desktop Renderer → Main only; never add this channel to the remote allowlist. */
+export const INPUT_HANDOFF_LOCAL_CHANNEL = "input-handoff:submit";
+/** Trusted Desktop IPC that relays one step to another computer over the signed v3 exchange. */
+export const INPUT_HANDOFF_REMOTE_LOCAL_CHANNEL = "plugin-oauth:submit-input";
+/** Trusted Desktop Renderer → Main only: the current step's screenshot on the executing computer. */
+export const INPUT_HANDOFF_LOCAL_PICTURE_CHANNEL = "input-handoff:picture";
+/**
+ * Trusted Desktop IPC pair for a screenshot step of a task on another computer:
+ * open receives the sealed picture, answer returns the owner's tap or typing
+ * on the same signed exchange. Host-only, like the submit channel.
+ */
+export const INPUT_HANDOFF_REMOTE_PICTURE_CHANNEL = "plugin-oauth:open-input-picture";
+export const INPUT_HANDOFF_REMOTE_PICTURE_ANSWER_CHANNEL = "plugin-oauth:answer-input-picture";
+export const INPUT_HANDOFF_VALUE_MAX_CHARS = 4096;
+export const INPUT_HANDOFF_MAX_CONTROLS = 40;
+export const INPUT_HANDOFF_MAX_OPTIONS = 200;
+export const INPUT_HANDOFF_LABEL_MAX_CHARS = 300;
+/** Whole-step budget so one signed reply always fits the v3 sealed box. */
+export const INPUT_HANDOFF_TOTAL_VALUE_MAX_CHARS = 8192;
+/** Presentation labels are shortened so a sealed offer stays small. */
+export const INPUT_HANDOFF_PRESENTATION_LABEL_CHARS = 80;
+/** Fixed v3 action id: each step is one signed exchange bound to (requestId, revision). */
+export const INPUT_HANDOFF_ACTION_ID = "step";
+/** Screenshot of one step, JPEG bytes. Sized so one sealed offer carries it with the presentation. */
+export const INPUT_HANDOFF_PICTURE_MAX_BYTES = 330_000;
+export const INPUT_HANDOFF_PICTURE_MAX_SIDE = 4096;
+/** Control id of the text box shown under a screenshot when the window has a focused text field. */
+export const INPUT_HANDOFF_PICTURE_TEXT_ID = "typed";
+/** Longest QR content carried to an owner device. */
+export const INPUT_HANDOFF_QR_TEXT_MAX_CHARS = 2048;
+
+export type InputHandoffContentType =
+ | "text"
+ | "username"
+ | "email"
+ | "tel"
+ | "url"
+ | "number"
+ | "password"
+ | "one-time-code"
+ | "search";
+
+export interface InputHandoffOption {
+ id: string;
+ label: string;
+}
+
+/**
+ * What the owner is asked for: only the fields they type into, plus what the
+ * page says is wrong with them. Buttons, pick lists and boxes stay with the
+ * agent, so they never reach an owner device.
+ */
+export type InputHandoffControl =
+ | {
+ id: string;
+ kind: "text";
+ label: string;
+ contentType: InputHandoffContentType;
+ placeholder?: string;
+ multiline?: true;
+ /** The field already contains text. The text itself never leaves the Host. */
+ filled?: true;
+ /** Combo boxes: options the owner may pick instead of typing. */
+ suggestions?: InputHandoffOption[];
+ }
+ | { id: string; kind: "note"; text: string; tone: "error" };
+
+export type InputHandoffPhase =
+ | "reading"
+ | "ready"
+ | "working"
+ | "finishing"
+ | "succeeded"
+ | "cancelled"
+ | "failed"
+ | "expired";
+
+export type InputHandoffOriginWarning =
+ | "insecure"
+ | "ip-address"
+ | "local-host"
+ | "local-file"
+ | "punycode"
+ | "embedded-frame";
+
+export type InputHandoffFailure =
+ | "permission"
+ | "target_gone"
+ | "unreadable"
+ | "action_failed"
+ | "timeout"
+ | "unsupported"
+ /** The page or window changed between the owner answering and the secret being typed; nothing was filled. */
+ | "origin_changed"
+ /** This step could not be shown as a screenshot (no screen-recording permission, or the window is hidden). */
+ | "picture_unavailable"
+ /** The screen has only buttons or options: nothing for the owner to type, so the agent handles it. */
+ | "nothing_to_fill"
+ /** The computer's screen is locked: nothing is read or typed until the owner unlocks it. */
+ | "screen_locked";
+
+export interface InputHandoffSource {
+ /** Application name as reported by the operating system. */
+ app: string;
+ window?: string;
+ /** scheme://host[:port] of the web content, when the step is a web page. */
+ origin?: string;
+ warning?: InputHandoffOriginWarning;
+}
+
+/**
+ * The owner device currently answering. Host-verified (server-stamped device id
+ * or the executing Desktop itself); the name is a display snapshot only.
+ */
+export interface InputHandoffHolder {
+ /** The executing Desktop answered on its own screen. */
+ local?: true;
+ deviceId?: string;
+ name?: string;
+ platform?: "mobile" | "desktop";
+}
+
+export interface InputHandoffSnapshot {
+ kind: "input_handoff";
+ requestId: string;
+ revision: number;
+ phase: InputHandoffPhase;
+ /** Agent-supplied purpose, shown as untrusted text. */
+ purpose: string;
+ /** Optional agent note to the owner, shown labelled as from the agent. */
+ note?: string;
+ /** Device holding this handoff; other devices may take it over. */
+ holder?: InputHandoffHolder;
+ /** Who asked: a task title or a teammate name, resolved by the Host. */
+ requester?: string;
+ /** Terminal prompts (sudo / ssh / git) show the full command instead of a window. */
+ command?: string;
+ source: InputHandoffSource;
+ stepNumber: number;
+ controls: InputHandoffControl[];
+ /** Epoch ms when the Host hands control back unless the owner says to stay. */
+ finishingUntil?: number;
+ failure?: InputHandoffFailure;
+ /** The target is driven by the agent (for example a CDP-controlled browser). */
+ agentControlled?: true;
+ /** Remote controllers may submit values through the signed v3 exchange. */
+ remoteInput?: true;
+ /** The request has settled; kept briefly for terminal feedback only. */
+ terminal?: true;
+ /**
+ * This step is shown as a screenshot of the window instead of a form: the
+ * owner taps on it, and may type into the focused field (the optional text
+ * control). The pixels never travel in a snapshot; the executing Desktop
+ * reads them locally and other devices receive them inside the sealed offer.
+ */
+ picture?: true;
+ /**
+ * Another device may open a live view of just this window (remote desktop is
+ * allowed on this computer); input there stays inside the window.
+ */
+ liveView?: true;
+ /**
+ * The step only shows a sign-in code and a link to open (device-code
+ * sign-in). The owner copies the code and opens the link on their own
+ * device; nothing is typed into the window.
+ */
+ deviceCode?: InputHandoffDeviceCode;
+ /**
+ * The step is a QR code to scan (scan-to-sign-in). `scan`: the code is on
+ * screen; it is also a picture step, and its picture is the code itself,
+ * with what the code says. `scanned`: the code went away and the Host is
+ * waiting for the sign-in to finish (for example a confirmation on the
+ * owner's phone). The code's content never travels in a snapshot.
+ */
+ qr?: "scan" | "scanned";
+}
+
+/**
+ * What a QR code on the target says. `url` is present when the content is a
+ * link the owner may open on their device; clients re-check with
+ * {@link inputHandoffQrLink} before offering to open it.
+ */
+export interface InputHandoffQr {
+ text: string;
+ url?: string;
+}
+
+/** A QR code's content as a link to open on an owner device. */
+export interface InputHandoffQrLink {
+ url: string;
+ /** Web links: the host. App links (`weixin://…`): the scheme. Shown so the owner sees where it goes. */
+ site: string;
+ web: boolean;
+}
+
+export interface InputHandoffDeviceCode {
+ code: string;
+ /** Always https; clients re-check with {@link isInputHandoffDeviceCode} before opening. */
+ url: string;
+ /** `https://host[:port]` of `url`, shown so the owner sees where the link goes. */
+ origin: string;
+}
+
+/** One step's screenshot. Delivered only through the trusted local channel or a sealed offer. */
+export interface InputHandoffPicture {
+ mime: "image/jpeg";
+ width: number;
+ height: number;
+ /** Base64 JPEG. */
+ data: string;
+ /** QR steps: the picture is the code, and this is what it says. */
+ qr?: InputHandoffQr;
+}
+
+export type InputHandoffValues = Record<string, string>;
+
+export type InputHandoffAction =
+ /** Type the values, then confirm the step as the owner would: the page's main button, else Return. */
+ | { kind: "submit" }
+ /** Screenshot steps: type into the focused field without pressing Return. */
+ | { kind: "fill" }
+ /** Screenshot steps: click at this point, as fractions (0–1) of the picture's width and height. */
+ | { kind: "tap"; x: number; y: number };
+
+export interface InputHandoffSubmission {
+ expectedRevision: number;
+ values: InputHandoffValues;
+ action: InputHandoffAction;
+}
+
+/** Value-less decisions; the only ones accepted through the plain interaction channel. */
+export type InputHandoffDecision = {
+ kind: "input_handoff";
+ /**
+ * claim: answer on this device (take over from another one).
+ * picture: show this step as a screenshot instead of a form; refresh goes back to the form.
+ */
+ action: "done" | "cancel" | "stay" | "refresh" | "claim" | "picture";
+ expectedRevision: number;
+};
+
+/** What the owner saw. Both ends derive it with the same function and compare. */
+export interface InputHandoffPresentation {
+ requestId: string;
+ revision: number;
+ purpose: string;
+ source: InputHandoffSource;
+ command: string | null;
+ controls: Array<{ id: string; kind: string; label: string }>;
+ /** The owner answers on a screenshot of this step. */
+ picture: boolean;
+ /** The screenshot is a QR code to scan; its content travels with the sealed picture. */
+ qr: boolean;
+}
+
+export interface InputHandoffOffer {
+ kind: "input-entry";
+ state: string;
+ presentation: InputHandoffPresentation;
+ /** Present exactly when the presentation is a screenshot step. */
+ picture?: InputHandoffPicture;
+}
+
+export interface InputHandoffValueReply {
+ kind: "input-value";
+ state: string;
+ submission: InputHandoffSubmission;
+}
+
+const fail = () => new Error("INPUT_HANDOFF_UNAVAILABLE");
+
+function object(raw: unknown): Record<string, unknown> {
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw fail();
+ return raw as Record<string, unknown>;
+}
+
+function keysWithin(value: Record<string, unknown>, required: string[], optional: string[] = []) {
+ const allowed = new Set([...required, ...optional]);
+ return required.every((key) => Object.hasOwn(value, key)) &&
+ Object.keys(value).every((key) => allowed.has(key));
+}
+
+const fraction = (value: unknown): value is number =>
+ typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
+
+const controlId = (value: unknown): value is string =>
+ typeof value === "string" && /^[a-z0-9_-]{1,64}$/i.test(value);
+
+const label = (value: unknown, allowEmpty = false): value is string =>
+ typeof value === "string" &&
+ value.length <= INPUT_HANDOFF_LABEL_MAX_CHARS &&
+ (allowEmpty || value.length > 0) &&
+ !/[\x00-\x08\x0b\x0c\x0e-\x1f]/.test(value);
+
+/** Rejects control characters other than tab and line breaks; passwords may contain anything printable. */
+export function parseInputHandoffValue(value: unknown): string {
+ if (
+ typeof value !== "string" ||
+ value.length > INPUT_HANDOFF_VALUE_MAX_CHARS ||
+ /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(value)
+ )
+ throw fail();
+ return value;
+}
+
+/**
+ * A device code is safe to show and open: a short code of letters, digits and
+ * hyphens, and a plain https link (no credentials) whose origin is the one shown.
+ */
+export function isInputHandoffDeviceCode(raw: unknown): raw is InputHandoffDeviceCode {
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return false;
+ const v = raw as Record<string, unknown>;
+ if (!keysWithin(v, ["code", "url", "origin"])) return false;
+ if (typeof v.code !== "string" || !/^[A-Z0-9](?:[A-Z0-9-]{1,22}[A-Z0-9])$/.test(v.code)) return false;
+ if (typeof v.url !== "string" || v.url.length > 2048 || typeof v.origin !== "string") return false;
+ let url: URL;
+ try {
+ url = new URL(v.url);
+ } catch {
+ return false;
+ }
+ return url.protocol === "https:" && !url.username && !url.password && url.origin === v.origin;
+}
+
+const qrText = (value: unknown): value is string =>
+ typeof value === "string" &&
+ value.length > 0 &&
+ value.length <= INPUT_HANDOFF_QR_TEXT_MAX_CHARS &&
+ !/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(value);
+
+/**
+ * Content a phone camera would never open: script, inline data, local files
+ * and browser internals. Everything else that is a link (http, https, an app
+ * link such as `weixin://`) opens like a scanned code would.
+ */
+const QR_BLOCKED_SCHEMES = new Set(["javascript", "vbscript", "data", "file", "blob", "about", "filesystem"]);
+
+function qrLinkOf(text: string): InputHandoffQrLink | null {
+ const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(text)?.[1]?.toLowerCase();
+ if (!scheme || QR_BLOCKED_SCHEMES.has(scheme)) return null;
+ let url: URL;
+ try {
+ url = new URL(text);
+ } catch {
+ return null;
+ }
+ if (url.username || url.password) return null;
+ if (scheme === "http" || scheme === "https") return url.host ? { url: text, site: url.host, web: true } : null;
+ // App links are `scheme://…`; `WIFI:…`, `tel:…` or a vCard are content, not something to open.
+ return /^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? { url: text, site: scheme, web: false } : null;
+}
+
+/** What a QR code says, as handed to the owner; null when it cannot be shown. */
+export function inputHandoffQrContent(text: string): InputHandoffQr | null {
+ const clean = text.trim();
+ if (!qrText(clean)) return null;
+ return qrLinkOf(clean) ? { text: clean, url: clean } : { text: clean };
+}
+
+/** The link a QR code may be opened as on an owner device: its own content, when that is an openable link. */
+export function inputHandoffQrLink(qr: InputHandoffQr): InputHandoffQrLink | null {
+ if (qr.url === undefined || qr.url !== qr.text) return null;
+ return qrLinkOf(qr.url);
+}
+
+export function parseInputHandoffQr(raw: unknown): InputHandoffQr {
+ const v = object(raw);
+ if (!keysWithin(v, ["text"], ["url"]) || !qrText(v.text)) throw fail();
+ if (v.url === undefined) return { text: v.text };
+ if (typeof v.url !== "string" || !inputHandoffQrLink({ text: v.text, url: v.url })) throw fail();
+ return { text: v.text, url: v.url };
+}
+
+export function inputHandoffPresentation(snapshot: InputHandoffSnapshot): InputHandoffPresentation {
+ return {
+ requestId: snapshot.requestId,
+ revision: snapshot.revision,
+ purpose: snapshot.purpose,
+ source: {
+ app: snapshot.source.app,
+ ...(snapshot.source.window !== undefined
+ ? { window: snapshot.source.window.slice(0, INPUT_HANDOFF_PRESENTATION_LABEL_CHARS) }
+ : {}),
+ ...(snapshot.source.origin !== undefined ? { origin: snapshot.source.origin } : {}),
+ ...(snapshot.source.warning !== undefined ? { warning: snapshot.source.warning } : {}),
+ },
+ command: snapshot.command ?? null,
+ controls: snapshot.controls
+ .filter((control) => control.kind !== "note")
+ .map((control) => ({
+ id: control.id,
+ kind: control.kind,
+ label: control.label.slice(
+ 0,
+ INPUT_HANDOFF_PRESENTATION_LABEL_CHARS,
+ ),
+ })),
+ picture: snapshot.picture === true,
+ qr: snapshot.picture === true && snapshot.qr === "scan",
+ };
+}
+
+export function parseInputHandoffPicture(raw: unknown): InputHandoffPicture {
+ const v = object(raw);
+ const side = (n: unknown) =>
+ Number.isSafeInteger(n) && (n as number) > 0 && (n as number) <= INPUT_HANDOFF_PICTURE_MAX_SIDE;
+ if (
+ !keysWithin(v, ["mime", "width", "height", "data"], ["qr"]) ||
+ v.mime !== "image/jpeg" ||
+ !side(v.width) ||
+ !side(v.height) ||
+ typeof v.data !== "string" ||
+ v.data.length === 0 ||
+ v.data.length > Math.ceil(INPUT_HANDOFF_PICTURE_MAX_BYTES / 3) * 4 ||
+ !/^[A-Za-z0-9+/]+={0,2}$/.test(v.data)
+ )
+ throw fail();
+ return {
+ mime: "image/jpeg",
+ width: v.width as number,
+ height: v.height as number,
+ data: v.data,
+ ...(v.qr !== undefined ? { qr: parseInputHandoffQr(v.qr) } : {}),
+ };
+}
+
+function parseSource(raw: unknown): InputHandoffSource {
+ const v = object(raw);
+ if (
+ !keysWithin(v, ["app"], ["window", "origin", "warning"]) ||
+ !label(v.app) ||
+ (v.window !== undefined && !label(v.window, true)) ||
+ (v.origin !== undefined && (typeof v.origin !== "string" || v.origin.length > 512)) ||
+ (v.warning !== undefined &&
+ !["insecure", "ip-address", "local-host", "local-file", "punycode", "embedded-frame"].includes(
+ String(v.warning),
+ ))
+ )
+ throw fail();
+ return {
+ app: v.app as string,
+ ...(v.window !== undefined ? { window: v.window as string } : {}),
+ ...(v.origin !== undefined ? { origin: v.origin as string } : {}),
+ ...(v.warning !== undefined ? { warning: v.warning as InputHandoffOriginWarning } : {}),
+ };
+}
+
+export function parseInputHandoffPresentation(raw: unknown): InputHandoffPresentation {
+ const v = object(raw);
+ if (
+ !keysWithin(v, ["requestId", "revision", "purpose", "source", "command", "controls", "picture", "qr"]) ||
+ typeof v.picture !== "boolean" ||
+ typeof v.qr !== "boolean" ||
+ (v.qr && !v.picture) ||
+ typeof v.requestId !== "string" ||
+ !/^[A-Za-z0-9_-]{1,128}$/.test(v.requestId) ||
+ !Number.isSafeInteger(v.revision) ||
+ (v.revision as number) < 0 ||
+ typeof v.purpose !== "string" ||
+ v.purpose.length > 1000 ||
+ (v.command !== null && (typeof v.command !== "string" || v.command.length > 2000)) ||
+ !Array.isArray(v.controls) ||
+ v.controls.length > INPUT_HANDOFF_MAX_CONTROLS
+ )
+ throw fail();
+ const controls = v.controls.map((entry) => {
+ const control = object(entry);
+ if (
+ !keysWithin(control, ["id", "kind", "label"]) ||
+ !controlId(control.id) ||
+ control.kind !== "text" ||
+ !label(control.label, true)
+ )
+ throw fail();
+ return { id: control.id as string, kind: control.kind as string, label: control.label as string };
+ });
+ return {
+ requestId: v.requestId,
+ revision: v.revision as number,
+ purpose: v.purpose,
+ source: parseSource(v.source),
+ command: v.command as string | null,
+ controls,
+ picture: v.picture as boolean,
+ qr: v.qr as boolean,
+ };
+}
+
+export function parseInputHandoffOffer(raw: unknown): InputHandoffOffer {
+ const v = object(raw);
+ if (
+ !keysWithin(v, ["kind", "state", "presentation"], ["picture"]) ||
+ v.kind !== "input-entry" ||
+ typeof v.state !== "string" ||
+ !/^[A-Za-z0-9_-]{43}$/.test(v.state)
+ )
+ throw fail();
+ const presentation = parseInputHandoffPresentation(v.presentation);
+ if (presentation.picture !== (v.picture !== undefined)) throw fail();
+ const picture = v.picture !== undefined ? parseInputHandoffPicture(v.picture) : undefined;
+ // A QR step's picture always says what the code is; any other picture never does.
+ if (picture && presentation.qr !== (picture.qr !== undefined)) throw fail();
+ return {
+ kind: "input-entry",
+ state: v.state,
+ presentation,
+ ...(picture ? { picture } : {}),
+ };
+}
+
+/**
+ * Structural validation only. The Host additionally checks every id against
+ * the exact step the owner answered before touching the target.
+ */
+export function parseInputHandoffSubmission(raw: unknown): InputHandoffSubmission {
+ const v = object(raw);
+ if (
+ !keysWithin(v, ["expectedRevision", "values", "action"]) ||
+ !Number.isSafeInteger(v.expectedRevision) ||
+ (v.expectedRevision as number) < 0
+ )
+ throw fail();
+ const rawValues = object(v.values);
+ const entries = Object.entries(rawValues);
+ if (entries.length > INPUT_HANDOFF_MAX_CONTROLS) throw fail();
+ const values: InputHandoffValues = {};
+ let total = 0;
+ for (const [id, value] of entries) {
+ if (!controlId(id)) throw fail();
+ values[id] = parseInputHandoffValue(value);
+ if ((total += values[id].length) > INPUT_HANDOFF_TOTAL_VALUE_MAX_CHARS) throw fail();
+ }
+ const action = object(v.action);
+ let parsed: InputHandoffAction;
+ if ((action.kind === "submit" || action.kind === "fill") && keysWithin(action, ["kind"]))
+ parsed = { kind: action.kind };
+ else if (action.kind === "tap" && keysWithin(action, ["kind", "x", "y"]) && fraction(action.x) && fraction(action.y))
+ parsed = { kind: "tap", x: action.x, y: action.y };
+ else throw fail();
+ return { expectedRevision: v.expectedRevision as number, values, action: parsed };
+}
+
+export function parseInputHandoffValueReply(raw: unknown): InputHandoffValueReply {
+ const v = object(raw);
+ if (
+ !keysWithin(v, ["kind", "state", "submission"]) ||
+ v.kind !== "input-value" ||
+ typeof v.state !== "string" ||
+ !/^[A-Za-z0-9_-]{43}$/.test(v.state)
+ )
+ throw fail();
+ return { kind: "input-value", state: v.state, submission: parseInputHandoffSubmission(v.submission) };
+}
+
+export function parseInputHandoffDecision(raw: unknown): InputHandoffDecision | null {
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
+ const v = raw as Record<string, unknown>;
+ if (
+ !keysWithin(v, ["kind", "action", "expectedRevision"]) ||
+ v.kind !== "input_handoff" ||
+ !["done", "cancel", "stay", "refresh", "claim", "picture"].includes(String(v.action)) ||
+ !Number.isSafeInteger(v.expectedRevision) ||
+ (v.expectedRevision as number) < 0
+ )
+ return null;
+ return {
+ kind: "input_handoff",
+ action: v.action as InputHandoffDecision["action"],
+ expectedRevision: v.expectedRevision as number,
+ };
+}
+
+/** Owner-side check that a submission only references controls of the step it answers. */
+export function validateInputHandoffSubmissionForStep(
+ snapshot: Pick<InputHandoffSnapshot, "revision" | "controls" | "picture">,
+ submission: InputHandoffSubmission,
+): boolean {
+ if (submission.expectedRevision !== snapshot.revision) return false;
+ // A tap is only meaningful on a screenshot, and carries nothing else.
+ if (submission.action.kind === "tap")
+ return snapshot.picture === true && Object.keys(submission.values).length === 0;
+ if (submission.action.kind === "fill" && snapshot.picture !== true) return false;
+ const fields = new Set(snapshot.controls.filter((control) => control.kind === "text").map((control) => control.id));
+ return Object.entries(submission.values).every(([id, value]) => fields.has(id) && typeof value === "string");
+}
+
+/** True when a remote client must not run this snapshot's actions. */
+export function isInputHandoffActionable(snapshot: InputHandoffSnapshot): boolean {
+ return !snapshot.terminal && snapshot.phase === "ready";
+}
+
+/**
+ * Whether another owner device holds this handoff. The executing Desktop is
+ * `{ local: true }`; a remote viewer passes its own device id. Value-less
+ * decisions (hand back, cancel, stay) stay available everywhere.
+ */
+export function inputHandoffHeldElsewhere(
+ snapshot: Pick<InputHandoffSnapshot, "holder">,
+ viewer: { local: true } | { deviceId: string | null },
+): boolean {
+ const holder = snapshot.holder;
+ if (!holder) return false;
+ if ("local" in viewer) return holder.local !== true;
+ return holder.local === true || !viewer.deviceId || holder.deviceId !== viewer.deviceId;
+}
+
+/**
+ * Identity of the screen a draft belongs to. Holder changes and re-reads of the
+ * same screen keep the key (so typing is not wiped when this device claims the
+ * handoff); any different screen gets a new key and a clean draft.
+ */
+export function inputHandoffStepKey(
+ snapshot: Pick<InputHandoffSnapshot, "requestId" | "stepNumber" | "controls" | "picture" | "qr">,
+): string {
+ const shape = (snapshot.picture ? "p|" : "") + (snapshot.qr ? `q:${snapshot.qr}|` : "") + snapshot.controls
+ .map((c) => (c.kind === "note" ? `n:${c.id}` : `t:${c.id}:${c.label}:${c.contentType}`))
+ .join("|");
+ let hash = 5381;
+ for (let i = 0; i < shape.length; i++) hash = ((hash << 5) + hash + shape.charCodeAt(i)) | 0;
+ return `${snapshot.requestId}:${snapshot.stepNumber}:${(hash >>> 0).toString(36)}`;
+}
diff --git a/packages/device-link/src/pluginOauth.ts b/packages/device-link/src/pluginOauth.ts
index 10eb06c592..c081befa7b 100644
--- a/packages/device-link/src/pluginOauth.ts
+++ b/packages/device-link/src/pluginOauth.ts
@@ -2,6 +2,20 @@
export const PLUGIN_OAUTH_CHANNEL = "device-link:plugin-oauth:v3";
export const PLUGIN_OAUTH_LOCAL_CHANNEL = "plugin-oauth:assist";
export const PLUGIN_OAUTH_TTL_MS = 5 * 60_000;
+/**
+ * Sealed JSON body limits. A Host offer may carry one 代输入 step screenshot;
+ * what the owner device sends back stays as small as before.
+ */
+export const PLUGIN_OAUTH_SEALED_MAX_BYTES = { offer: 480_000, callback: 32_000 } as const;
+/** A well-formed base64url box for a direction: IV (12) + body + tag (16). */
+export function isPluginOauthBox(direction: "offer" | "callback", box: unknown): box is string {
+ return (
+ typeof box === "string" &&
+ box.length >= 40 &&
+ box.length <= Math.ceil(((PLUGIN_OAUTH_SEALED_MAX_BYTES[direction] + 28) * 4) / 3) &&
+ /^[A-Za-z0-9_-]+$/.test(box)
+ );
+}
export interface PluginOauthAction {
requestId: string;
@@ -18,6 +32,8 @@ export type PluginOauthRequest =
authorizationV1?: true;
secretSubmission?: true;
connectionSubmission?: true;
+ /** Input handoff step submission (代输入); bound to a Host-owned card. */
+ inputHandoff?: true;
} & PluginOauthAction)
| { op: "status"; id: string }
| { op: "cancel"; id: string }
@@ -96,6 +112,7 @@ export function parsePluginOauthRequest(
...(value.authorizationV1 === true ? ["authorizationV1"] : []),
...(value.secretSubmission === true ? ["secretSubmission"] : []),
...(value.connectionSubmission === true ? ["connectionSubmission"] : []),
+ ...(value.inputHandoff === true ? ["inputHandoff"] : []),
])
) {
const action = parsePluginOauthAction({
@@ -118,6 +135,7 @@ export function parsePluginOauthRequest(
...(value.connectionSubmission === true
? { connectionSubmission: true }
: {}),
+ ...(value.inputHandoff === true ? { inputHandoff: true } : {}),
};
}
if (
diff --git a/packages/device-link/src/remoteDesktop.ts b/packages/device-link/src/remoteDesktop.ts
index 23032c8c33..efa35c94b3 100644
--- a/packages/device-link/src/remoteDesktop.ts
+++ b/packages/device-link/src/remoteDesktop.ts
@@ -196,6 +196,12 @@ export interface RemoteDesktopCapabilities {
windowActions?: boolean;
workspaceNavigation?: boolean;
omarchyMenu?: boolean;
+ /**
+ * Accepts `start` with `handoff`: a live view of only the window a pending
+ * 代输入 step is about, with input confined to that window. The host picks the
+ * window; a viewer can never name one.
+ */
+ handoffWindow?: boolean;
}
export type DesktopPermission = "screenRecording" | "accessibility";
export type DesktopPermissionStatus =
@@ -222,6 +228,13 @@ export interface RemoteDesktopLease {
viewerDisplayRequest?: { width: number; height: number };
/** The display change kept the existing video stream; no new offer is needed. */
videoKept?: boolean;
+ /** A 代输入 live view: the video is this one window, and input stays inside it. */
+ window?: RemoteDesktopLeaseWindow;
+}
+/** Host-verified description of the single window a 代输入 live view shows. */
+export interface RemoteDesktopLeaseWindow {
+ app: string;
+ title?: string;
}
export type RemoteDesktopRequest =
| { op: "windowAction"; lease: string; action: "list" | "desktop" }
@@ -252,6 +265,8 @@ export type RemoteDesktopRequest =
takeover?: boolean;
control?: boolean;
lockOnExit?: boolean;
+ /** 代输入 request id; only to hosts advertising `handoffWindow`. */
+ handoff?: string;
}
| { op: "heartbeat"; lease: string; lockOnExit?: boolean }
| { op: "stop"; lease: string; lockScreen?: boolean }
@@ -324,9 +339,15 @@ export function parseRemoteDesktopRequest(
throw new Error("INVALID_REQUEST");
if (v.takeover === true && v.resume === true)
throw new Error("INVALID_REQUEST");
+ if (
+ v.handoff !== undefined &&
+ (typeof v.handoff !== "string" || !/^[A-Za-z0-9_-]{1,128}$/.test(v.handoff))
+ )
+ throw new Error("INVALID_REQUEST");
return {
op: v.op,
displayId: v.displayId,
+ ...(typeof v.handoff === "string" ? { handoff: v.handoff } : {}),
...(v.takeover === true ? { takeover: true } : {}),
...(typeof v.resume === "boolean" ? { resume: v.resume } : {}),
...control(),
diff --git a/packages/device-link/src/remoteDesktopViewerSession.ts b/packages/device-link/src/remoteDesktopViewerSession.ts
index ec8dc1dc88..c83e31256d 100644
--- a/packages/device-link/src/remoteDesktopViewerSession.ts
+++ b/packages/device-link/src/remoteDesktopViewerSession.ts
@@ -21,6 +21,12 @@ interface ViewerConnectOptions {
isCurrent: () => boolean;
/** Ask a host advertising `autoControl` to grant control with the lease. */
control?: boolean;
+ /**
+ * Open a 代输入 live view of the window this pending request is about. Needs a
+ * host advertising `handoffWindow`; the reported caps keep only what applies
+ * to a single window.
+ */
+ handoff?: string;
onCapabilities?: (caps: RemoteDesktopCapabilities) => void | Promise<void>;
onStart?: () => void;
}
@@ -74,7 +80,7 @@ export class RemoteDesktopViewerSession {
throw new Error("DESKTOP_VIDEO_STOPPED");
};
check();
- const caps = await this.request<RemoteDesktopCapabilities>(
+ let caps = await this.request<RemoteDesktopCapabilities>(
{ op: "capabilities" },
check,
);
@@ -83,6 +89,10 @@ export class RemoteDesktopViewerSession {
if (!caps.enabled) throw new Error("DESKTOP_DISABLED");
if (options.resume && !caps.automaticReconnect)
throw new Error("CHANNEL_NOT_ALLOWED");
+ if (options.handoff !== undefined) {
+ if (!caps.handoffWindow) throw new Error("CHANNEL_NOT_ALLOWED");
+ caps = handoffWindowCapabilities(caps);
+ }
await options.onCapabilities?.(caps);
check();
const display =
@@ -101,6 +111,7 @@ export class RemoteDesktopViewerSession {
...(options.control && caps.autoControl && caps.canControl
? { control: true }
: {}),
+ ...(options.handoff !== undefined ? { handoff: options.handoff } : {}),
},
check,
);
@@ -108,6 +119,11 @@ export class RemoteDesktopViewerSession {
await this.request({ op: "stop", lease: lease.lease }).catch(() => {});
throw new Error("DESKTOP_VIDEO_STOPPED");
}
+ // A window view that came back as a whole display is not what was asked for.
+ if (options.handoff !== undefined && typeof lease.window?.app !== "string") {
+ await this.request({ op: "stop", lease: lease.lease }).catch(() => {});
+ throw new Error("INVALID_RESPONSE");
+ }
// Only a confirmed grant counts; older hosts always start view only.
lease.controlling = lease.controlling === true;
this.active = lease;
@@ -282,6 +298,34 @@ export class RemoteDesktopViewerSession {
}
}
+/**
+ * What a 代输入 window view may use. Everything that reaches past the one window —
+ * display modes, whole-system audio, the clipboard, privacy screen, window and
+ * workspace actions, locking — is left out, so the viewer hides those controls;
+ * the host refuses them for a window lease either way.
+ */
+export function handoffWindowCapabilities(
+ caps: RemoteDesktopCapabilities,
+): RemoteDesktopCapabilities {
+ return {
+ version: caps.version,
+ enabled: caps.enabled,
+ canControl: caps.canControl,
+ platform: caps.platform,
+ displays: caps.displays,
+ ...(caps.permissions ? { permissions: caps.permissions } : {}),
+ ...(caps.automaticReconnect ? { automaticReconnect: true } : {}),
+ ...(caps.videoSettings ? { videoSettings: true } : {}),
+ ...(caps.trickleIce ? { trickleIce: true } : {}),
+ ...(caps.channelRequests ? { channelRequests: true } : {}),
+ ...(caps.autoControl ? { autoControl: true } : {}),
+ ...(caps.backgroundViewing ? { backgroundViewing: true } : {}),
+ ...(caps.cursorOverlay ? { cursorOverlay: true } : {}),
+ ...(caps.viewerHidden ? { viewerHidden: true } : {}),
+ handoffWindow: true,
+ };
+}
+
/** Layout points determine the ratio; cap the long edge instead of sending phone DPR pixels. */
export function viewerDisplaySize(
width: number,
@@ -355,6 +399,8 @@ export function remoteDesktopFailureKey(code: string): string | null {
if (/ACCESS_REVOKED/.test(code)) return "accessRevoked";
if (/REMOTE_DISABLED/.test(code)) return "remoteDisabled";
if (/DESKTOP_BUSY/.test(code)) return "connectionBusy";
+ if (/DESKTOP_HANDOFF_ENDED/.test(code)) return "handoffEnded";
+ if (/DESKTOP_HANDOFF_(UNAVAILABLE|WINDOW_ONLY)/.test(code)) return "handoffUnavailable";
if (/CHANNEL_NOT_ALLOWED/.test(code)) return "upgrade";
if (/DESKTOP_DISABLED/.test(code)) return "disabled";
if (/PERMISSION|ACCESSIBILITY/.test(code)) return "permissionHint";
diff --git a/packages/lizi-mcps/src/browser/browserMcpServer.test.ts b/packages/lizi-mcps/src/browser/browserMcpServer.test.ts
index 0f75695160..a5e299fcb7 100644
--- a/packages/lizi-mcps/src/browser/browserMcpServer.test.ts
+++ b/packages/lizi-mcps/src/browser/browserMcpServer.test.ts
@@ -814,4 +814,55 @@ describe('createBrowserMcpServer', () => {
expect(parsed.truncated).toBe(true);
await h.cleanup();
});
+
+ it.each([true, false])('points the agent at 代输入 when a snapshot shows a password field (%s)', async (password) => {
+ const h = await makeHarness({}, (request) => request.action === 'act'
+ ? { result: { password, code: false } }
+ : { targetId: 't9', snapshot: '- textbox "Password" [ref=e3]' });
+ const result = await h.client.callTool({
+ name: 'call_tool',
+ arguments: { name: 'browser', args: { action: 'snapshot' } },
+ });
+ const text = (result.content as Array<{ text: string }>)[0].text;
+ const parsed = JSON.parse(text) as { loginWall?: { fields: string[]; hint: string }; ok: boolean };
+ expect(parsed.ok).toBe(true);
+ if (password) {
+ expect(text.startsWith('{"loginWall"')).toBe(true);
+ expect(parsed.loginWall).toMatchObject({ fields: ['password'], hint: expect.stringContaining('request_input_handoff') });
+ } else {
+ expect(parsed.loginWall).toBeUndefined();
+ }
+ // The check runs on the tab the snapshot came from.
+ expect(h.calls[1]).toMatchObject({ action: 'act', targetId: 't9', request: { kind: 'evaluate' } });
+ await h.cleanup();
+ });
+
+ it('pauses page-state reads on a page where the owner just typed a secret', async () => {
+ let restricted = true;
+ const asked: unknown[] = [];
+ const h = await makeHarness({
+ pageReadsRestricted: async (target) => { asked.push(target); return restricted; },
+ });
+ const call = async (args: Record<string, unknown>) => JSON.parse(((await h.client.callTool({
+ name: 'call_tool', arguments: { name: 'browser', args },
+ })).content as Array<{ text: string }>)[0].text) as { ok: boolean; data?: { reason?: string } };
+ try {
+ for (const args of [
+ { action: 'act', targetId: 't1', request: { kind: 'evaluate', fn: '() => 1' } },
+ { action: 'requests', targetId: 't1' },
+ { action: 'console', targetId: 't1' },
+ ]) {
+ expect(await call(args)).toMatchObject({ ok: false, data: { reason: 'secret_entered' } });
+ }
+ expect(asked[0]).toEqual({ targetId: 't1' });
+ expect(h.calls).toEqual([]);
+ // Reading the page's structure and clicking stay available.
+ expect(await call({ action: 'act', targetId: 't1', request: { kind: 'click', ref: 'e1' } })).toMatchObject({ ok: true });
+ restricted = false;
+ expect(await call({ action: 'console', targetId: 't1' })).toMatchObject({ ok: true });
+ } finally {
+ await h.cleanup();
+ }
+ });
});
+
diff --git a/packages/lizi-mcps/src/browser/tools.ts b/packages/lizi-mcps/src/browser/tools.ts
index 35f0bcf9f4..b568711035 100644
--- a/packages/lizi-mcps/src/browser/tools.ts
+++ b/packages/lizi-mcps/src/browser/tools.ts
@@ -108,8 +108,36 @@ const ACT_KINDS = [
'close',
] as const;
+/** Tools that read page script state, network traffic or console output. */
+function readsPageState(request: BrowserControlRequest): boolean {
+ if (request.action === 'console' || request.action === 'requests' || request.action === 'responseBody') return true;
+ const act = request.request as { kind?: unknown; fn?: unknown } | undefined;
+ return request.action === 'act' && (act?.kind === 'evaluate' || (act?.kind === 'wait' && act.fn !== undefined));
+}
+
function getRuntime(deps: BrowserMcpDeps): BrowserControlRuntime {
- return deps.getRuntime();
+ const runtime = deps.getRuntime();
+ const restricted = deps.pageReadsRestricted;
+ if (!restricted) return runtime;
+ // Every path (tool actions, extract, recipes, hints) goes through this check.
+ return {
+ call: async (request) => {
+ if (readsPageState(request)
+ && await restricted({
+ ...(request.profile ? { profile: request.profile } : {}),
+ ...(request.targetId ? { targetId: request.targetId } : {}),
+ }).catch(() => true)) {
+ return {
+ ok: false,
+ action: request.action,
+ errorCode: 'BROWSER_RUNTIME_INVALID_REQUEST',
+ message: 'The owner just entered a password on this page through Cindy. Script evaluation, network and console reads are paused here until the tab leaves this page. Use snapshot or screenshot, or navigate on.',
+ data: { reason: 'secret_entered' },
+ };
+ }
+ return runtime.call(request);
+ },
+ };
}
function actKindSchema(deps: BrowserMcpDeps) {
@@ -166,6 +194,47 @@ function elementQuerySchema(deps: BrowserMcpDeps) {
// `extract.limit` are optional + agent-controlled, so this is the backstop.
const MAX_RESULT_BYTES = 200_000;
+/**
+ * 代输入 hint on a page that asks for a password or a one-time code: the
+ * owner should fill it from their own device. A cheap DOM check after a
+ * snapshot; any failure means no hint.
+ */
+const LOGIN_WALL_FN = `() => {
+ const docs = [document];
+ for (const frame of document.querySelectorAll('iframe')) {
+ try { if (frame.contentDocument) docs.push(frame.contentDocument); } catch {}
+ }
+ const has = (selector) => docs.some((doc) => doc.querySelector(selector));
+ return {
+ password: !!has('input[type=password]'),
+ code: !!has('input[autocomplete="one-time-code"]'),
+ };
+}`;
+
+async function detectLoginWall(runtime: BrowserControlRuntime, profile: unknown, targetId: unknown) {
+ try {
+ const checked = await runtime.call({
+ action: 'act',
+ ...(typeof profile === 'string' ? { profile } : {}),
+ ...(typeof targetId === 'string' ? { targetId } : {}),
+ request: { kind: 'evaluate', fn: LOGIN_WALL_FN, timeoutMs: 2000 },
+ } as BrowserControlRequest);
+ const found = (checked.data as { result?: { password?: unknown; code?: unknown } } | undefined)?.result;
+ if (!checked.ok || (found?.password !== true && found?.code !== true)) return null;
+ return {
+ fields: [found.password === true ? 'password' : null, found.code === true ? 'one-time-code' : null].filter(Boolean),
+ hint: 'This page asks for a password or verification code. Do not type it yourself: call request_input_handoff with this browser window so the owner completes the sign-in from their phone or another computer, then continue when it ends.',
+ };
+ } catch {
+ return null;
+ }
+}
+
+function readTargetId(result: { data?: unknown }): string | undefined {
+ const id = (result.data as { targetId?: unknown } | undefined)?.targetId;
+ return typeof id === 'string' && id ? id : undefined;
+}
+
function resultText(value: unknown): string {
const json = JSON.stringify(value);
// JSON.stringify returns undefined only for undefined/function inputs; callers
@@ -669,6 +738,11 @@ export function registerBrowserTools(registry: BrowserToolRegistry, deps: Browse
} else {
result = await runtime.call(toRuntimeRequest(args));
}
+ if (args.action === 'snapshot' && result.ok) {
+ const loginWall = await detectLoginWall(runtime, args.profile, readTargetId(result) ?? args.targetId);
+ // First key, so it survives truncation of a large snapshot.
+ if (loginWall) result = { loginWall, ...result } as typeof result;
+ }
// For extract, the runtime call may succeed (evaluate ran) while the
// in-page extract reports ok:false (invalid selector); surface that as an
// error so the agent sees + acts on the embedded hint.
diff --git a/packages/lizi-mcps/src/computer/server.ts b/packages/lizi-mcps/src/computer/server.ts
index 15b11cc806..503f1cb84c 100644
--- a/packages/lizi-mcps/src/computer/server.ts
+++ b/packages/lizi-mcps/src/computer/server.ts
@@ -492,6 +492,8 @@ export function createComputerMcpServer(
sessionId,
);
if (staleResult) return staleResult;
+ const secureFieldResult = await checkSecureField(name as ComputerMcpToolName, parsedData, sessionId);
+ if (secureFieldResult) return secureFieldResult;
const postcondition = parsedData.postcondition;
delete parsedData.postcondition; // Cindy-owned verification, never part of driver action args.
if (postcondition && typeof parsedData.window_id !== "number") {
@@ -1509,6 +1511,48 @@ export function createComputerMcpServer(
);
}
+ /**
+ * 代输入 hint: a password field is the owner's to fill. Typing into one from
+ * the agent would put the secret in the model's context, so refuse and point
+ * at request_input_handoff. Runs after the freshness check resolved the target.
+ */
+ async function checkSecureField(
+ name: ComputerMcpToolName,
+ parsedData: Record<string, unknown>,
+ sessionId: string | undefined,
+ ) {
+ if ((name !== 'type_text' && name !== 'set_value') || !deps.isSecureTarget) return null;
+ const pid = parsedData.pid as number;
+ let snapshotId = typeof parsedData.snapshot_id === 'string' ? parsedData.snapshot_id : undefined;
+ let index = typeof parsedData.element_index === 'number' ? parsedData.element_index : undefined;
+ if (typeof parsedData.element_token === 'string') {
+ const ref = snapshotTracker.elementReference(sessionId, parsedData.element_token, snapshotId);
+ if (ref) {
+ snapshotId = ref.snapshotId;
+ index = ref.index;
+ }
+ }
+ const windowId = typeof parsedData.window_id === 'number' ? parsedData.window_id : undefined;
+ const frame = index === undefined ? undefined : snapshotTracker.elementFrame(sessionId, pid, windowId, index, snapshotId);
+ // An element we cannot place is not guessed at; plain typing goes to the focused element.
+ if (index !== undefined && !frame) return null;
+ const point = frame ? { x: frame.x + frame.w / 2, y: frame.y + frame.h / 2 } : undefined;
+ const secure = await deps.isSecureTarget({ pid, ...(point ? { point } : {}) }).catch(() => false);
+ if (!secure) return null;
+ return textResult(
+ {
+ ok: false,
+ errorCode: 'SECURE_FIELD',
+ data: {
+ tool: name,
+ message: 'This element is a password field. Cindy does not let the agent type into password fields.',
+ hint: 'Call request_input_handoff with this pid and window so the owner fills it from their phone or another computer; leave the window as it is until it ends.',
+ },
+ },
+ true,
+ );
+ }
+
/** get_window_state 成功观察后登记新一代快照;其余工具或观察失败时返回 null。 */
function recordWindowSnapshot(
name: ComputerMcpToolName,
diff --git a/packages/lizi-mcps/src/computer/snapshot-tracker.ts b/packages/lizi-mcps/src/computer/snapshot-tracker.ts
index ae01edf0b4..7aea1e4d52 100644
--- a/packages/lizi-mcps/src/computer/snapshot-tracker.ts
+++ b/packages/lizi-mcps/src/computer/snapshot-tracker.ts
@@ -40,6 +40,8 @@ interface SnapshotMeta {
windowId: number;
driverSnapshotId?: string;
elements?: Map<string, number>;
+ /** Screen frames by element_index, to ask the OS what an action would land on. */
+ frames?: Map<number, ElementFrame>;
}
/** 保留的窗口数与历史快照数上限(FIFO 淘汰)。 */
@@ -138,13 +140,31 @@ export class WindowSnapshotTracker {
const meta = this.metaById.get(snapshotId);
if (!meta || !Array.isArray(elements)) return;
meta.elements = new Map();
+ meta.frames = new Map();
for (const element of elements.slice(0, 2000)) {
- if (typeof element?.element_token === 'string' && typeof element?.element_index === 'number') {
- meta.elements.set(element.element_token, element.element_index);
- }
+ if (typeof element?.element_index !== 'number') continue;
+ if (typeof element.element_token === 'string') meta.elements.set(element.element_token, element.element_index);
+ const frame = readFrame(element.frame);
+ if (frame) meta.frames.set(element.element_index, frame);
}
}
+ /** Screen frame of an element in the observation it came from (given, or the window's latest). */
+ elementFrame(
+ sessionId: string | undefined,
+ pid: number,
+ windowId: number | undefined,
+ index: number,
+ snapshotId?: string,
+ ): ElementFrame | undefined {
+ const key = sessionId ?? '';
+ const id = snapshotId !== undefined
+ ? this.aliasToId.get(this.aliasKey(key, snapshotId)) ?? snapshotId
+ : windowId !== undefined ? this.latestByWindow.get(this.windowKey(key, pid, windowId)) : undefined;
+ const meta = id === undefined ? undefined : this.metaById.get(id);
+ return meta?.sessionKey === key && meta.pid === pid ? meta.frames?.get(index) : undefined;
+ }
+
elementReference(sessionId: string | undefined, token: string, observationId?: string) {
// A repeated token is ambiguous without an explicit observation. Never silently
// promote an old reference to the newest generation just because its text matches.
@@ -190,3 +210,18 @@ export class WindowSnapshotTracker {
return { ok: true };
}
}
+
+export interface ElementFrame {
+ x: number;
+ y: number;
+ w: number;
+ h: number;
+}
+
+function readFrame(raw: unknown): ElementFrame | undefined {
+ if (!raw || typeof raw !== 'object') return undefined;
+ const { x, y, w, h } = raw as Record<string, unknown>;
+ return [x, y, w, h].every((value) => typeof value === 'number' && Number.isFinite(value))
+ ? { x: x as number, y: y as number, w: w as number, h: h as number }
+ : undefined;
+}
diff --git a/packages/lizi-mcps/src/computer/snapshotGuard.test.ts b/packages/lizi-mcps/src/computer/snapshotGuard.test.ts
index b8f5b74d34..8405106112 100644
--- a/packages/lizi-mcps/src/computer/snapshotGuard.test.ts
+++ b/packages/lizi-mcps/src/computer/snapshotGuard.test.ts
@@ -718,3 +718,43 @@ describe('computer snapshot guard', () => {
},
);
});
+
+describe('password fields', () => {
+ it('refuses agent typing into a password field and points at 代输入', async () => {
+ const dispatch = vi.fn(async (name: string) => name === 'get_window_state'
+ ? {
+ elements: [
+ { element_index: 0, element_token: 'w:0', role: 'AXTextField', frame: { x: 10, y: 20, w: 100, h: 20 } },
+ // cua-driver reports password fields as plain AXTextField; only the OS knows.
+ { element_index: 1, element_token: 'w:1', role: 'AXTextField', frame: { x: 10, y: 60, w: 100, h: 20 } },
+ ],
+ }
+ : { effect: 'confirmed' });
+ let focusedSecure = false;
+ const isSecureTarget = vi.fn(async ({ point }: { pid: number; point?: { x: number; y: number } }) =>
+ point ? point.y === 70 : focusedSecure);
+ const h = await makeHarness({ getStatus: vi.fn(), callTool: dispatch, isSecureTarget }, { sessionId: 'secure' });
+ try {
+ const state = await h.call('get_window_state', { pid: 1, window_id: 2 });
+ for (const [tool, extra] of [['type_text', { text: 'synthetic' }], ['set_value', { value: 'synthetic' }]] as const) {
+ expect(await h.call(tool, { pid: 1, window_id: 2, element_token: 'w:1', ...extra })).toMatchObject({
+ ok: false,
+ errorCode: 'SECURE_FIELD',
+ data: { hint: expect.stringContaining('request_input_handoff') },
+ });
+ expect(await h.call(tool, { pid: 1, window_id: 2, element_index: 1, snapshot_id: state.snapshot_id, ...extra }))
+ .toMatchObject({ errorCode: 'SECURE_FIELD' });
+ }
+ expect(isSecureTarget).toHaveBeenCalledWith({ pid: 1, point: { x: 60, y: 70 } });
+ expect(dispatch).toHaveBeenCalledTimes(1);
+ expect(await h.call('type_text', { pid: 1, window_id: 2, element_token: 'w:0', text: '[email protected]' }))
+ .toMatchObject({ ok: true });
+ // Plain typing lands in the focused element.
+ focusedSecure = true;
+ expect(await h.call('type_text', { pid: 1, text: 'synthetic' })).toMatchObject({ errorCode: 'SECURE_FIELD' });
+ expect(isSecureTarget).toHaveBeenLastCalledWith({ pid: 1 });
+ } finally {
+ await h.cleanup();
+ }
+ });
+});
diff --git a/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts b/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts
index 4f5343c013..41a1961112 100644
--- a/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts
+++ b/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts
@@ -9,7 +9,7 @@ import { registerSessionTagTools, type SessionTagsCallback } from './xdt-helper/
* - 通用工具走 `list_tools` / `call_tool` 两个入口,渐进式发现:
* 异步提问使用独立的 ask_user_question_async 入口,以便 harness 验证根代理身份。
* - 'cindy' : 只读自省 (get_capabilities / get_current_session_id)
- * - 'auth' : 由 Host 保存凭证的供应商授权
+ * - 'auth' : 由 Host 保存凭证的供应商授权;代输入(request_input_handoff)
* - 'history' : 只读查询本地数据库聊天历史与输入队列 (list_workdirs /
* list_sessions / list_session_queue / get_chat_history /
* search_chat_history)
@@ -35,6 +35,7 @@ import { ListToolsRequestSchema, type Tool } from '@modelcontextprotocol/sdk/typ
import { z } from 'zod';
import { registerBotRoutineTools, type BotRoutineCallbacks } from './xdt-helper/botRoutineTools.js';
import { registerGrokLoginTools, type GrokLoginCallbacks } from './xdt-helper/grok_login.js';
+import { registerInputHandoffTool, type InputHandoffCallbacks } from './xdt-helper/input_handoff.js';
import { jsonObjectArg } from './json-object-arg.js';
import { registerAsyncQuestionTool, supportsAsyncQuestionTool, type AskUserQuestionAsyncCallback } from './xdt-helper/ask_user_question_async.js';
@@ -730,6 +731,8 @@ export interface XdtHelperMcpDeps {
logger?: LiziMcpLogger;
appUpdate?: AppUpdateCallbacks;
grokLogin?: GrokLoginCallbacks;
+ /** 代输入: hand an on-screen step to the owner; values stay on the host. */
+ inputHandoff?: InputHandoffCallbacks;
/**
* Host-owned runtime classification. `bot-main` is a local Bot's main task: it sees
* the ordinary task surface plus Bot tools, and every call is judged by `authorizeCall`.
@@ -875,6 +878,8 @@ export function createXdtHelperMcpServer(
}
if (deps.grokLogin)
registerGrokLoginTools(registry, () => resolveLiziMcpSessionContext(sessionCtx), deps.grokLogin);
+ if (deps.inputHandoff)
+ registerInputHandoffTool(registry, () => resolveLiziMcpSessionContext(sessionCtx), deps.inputHandoff);
registerGetCurrentSessionIdTool(registry, {
getSessionContext: () => resolveLiziMcpSessionContext(sessionCtx),
});
diff --git a/packages/lizi-mcps/src/types.ts b/packages/lizi-mcps/src/types.ts
index 1108de8028..b32b16661c 100644
--- a/packages/lizi-mcps/src/types.ts
+++ b/packages/lizi-mcps/src/types.ts
@@ -553,6 +553,12 @@ export interface BrowserMcpDeps {
supportsResourceDownloads?(): boolean;
/** Whether the active backend accepts semantic element queries. */
supportsSemanticQueries?(): boolean;
+ /**
+ * 代输入: true while the target tab still shows a page where the owner just
+ * typed a secret. Page-state reads (evaluate, requests, response bodies,
+ * console) are then refused.
+ */
+ pageReadsRestricted?(target: { profile?: string; targetId?: string }): Promise<boolean>;
logger?: LiziMcpLogger;
/**
* Optional L2 (user-local) recipe layer. The host scans userData, parses with
@@ -653,6 +659,11 @@ export interface ComputerMcpDeps {
args: Record<string, unknown>,
context?: ComputerMcpCallContext,
): Promise<unknown>;
+ /**
+ * 代输入: whether typing would land in a password field — the element at a
+ * screen point of this app, or its focused element. Roles only, never values.
+ */
+ isSecureTarget?(target: { pid: number; point?: { x: number; y: number } }): Promise<boolean>;
logger?: LiziMcpLogger;
}
diff --git a/packages/lizi-mcps/src/xdt-helper/index.ts b/packages/lizi-mcps/src/xdt-helper/index.ts
index fe2bab1656..56c065b522 100644
--- a/packages/lizi-mcps/src/xdt-helper/index.ts
+++ b/packages/lizi-mcps/src/xdt-helper/index.ts
@@ -11,6 +11,7 @@
export { registerGetCapabilitiesTool } from './get_capabilities.js';
export { registerAppUpdateTools, type AppUpdateCallbacks } from './app_update.js';
export { registerGrokLoginTools, type GrokLoginCallbacks, type GrokLoginState } from './grok_login.js';
+export { registerInputHandoffTool, type InputHandoffCallbacks, type InputHandoffToolRequest, type InputHandoffToolResult } from './input_handoff.js';
export { registerSkillhubTools, type SkillhubAgentCallback, type SkillhubAgentRequest } from './skillhub.js';
export {
registerGetCurrentSessionIdTool,
diff --git a/packages/lizi-mcps/src/xdt-helper/input_handoff.ts b/packages/lizi-mcps/src/xdt-helper/input_handoff.ts
new file mode 100644
index 0000000000..851865e55c
--- /dev/null
+++ b/packages/lizi-mcps/src/xdt-helper/input_handoff.ts
@@ -0,0 +1,108 @@
+import { z } from 'zod';
+import type { XdtHelperToolRegistry } from '../lizi_xdtHelperToolRegistry.js';
+import type { LiziMcpSessionContext } from '../types.js';
+import { errorPayload, okPayload } from './_payload.js';
+
+/**
+ * 代输入 (input handoff): the agent hands the fields on screen that only the
+ * owner can type (sign-in name, password, verification code, text it cannot
+ * know) to the owner. The owner types them from any of their devices; values
+ * go straight to the host and are never returned here. A sign-in QR code is
+ * handed to the owner to scan. Buttons and options stay with the agent.
+ */
+
+export interface InputHandoffToolRequest {
+ purpose: string;
+ note?: string;
+ target: { app?: string; pid?: number; windowTitle?: string };
+ completeWhen?: { windowClosed?: boolean; textAppears?: string; urlContains?: string };
+ timeoutMinutes?: number;
+}
+
+export type InputHandoffToolResult =
+ | { ok: true; requestId: string }
+ | { ok: false; errorCode: string; message: string };
+
+export interface InputHandoffCallbacks {
+ start(context: LiziMcpSessionContext, request: InputHandoffToolRequest): Promise<InputHandoffToolResult>;
+}
+
+const DESCRIPTION =
+ 'Ask the owner to type what only they can into fields on this computer\'s screen: '
+ + 'a sign-in name, password, verification code, or other text you cannot know. '
+ + 'Cindy shows the owner just those fields on their phone or another computer, types the answer in and confirms with the page\'s own main button; '
+ + 'it follows the flow across windows and browsers while fields keep appearing. '
+ + 'A sign-in QR code on screen is handed to the owner to scan, and the task continues once they are signed in. '
+ + 'Buttons, options and consent pages are yours to handle: a screen with neither a field to type nor a sign-in QR code ends at once with failure nothing_to_fill. '
+ + 'Do not type, click or read secrets in that window yourself while it is pending. '
+ + 'Returns a pending receipt; a hidden "[Input handoff ended]" message continues this task later. '
+ + 'Values the owner enters are never shared with you. One pending handoff per task. '
+ + 'Not needed for terminal password prompts on macOS and Linux: in this task\'s shell, sudo (run it as `sudo -A`), '
+ + 'ssh and git over HTTPS ask the owner automatically and your command simply continues.';
+
+const STRING = (max: number) => z.string().trim().min(1).max(max);
+
+export function registerInputHandoffTool(
+ registry: XdtHelperToolRegistry,
+ getContext: () => LiziMcpSessionContext,
+ callbacks: InputHandoffCallbacks,
+): void {
+ registry.register({
+ name: 'request_input_handoff',
+ category: 'auth',
+ description: DESCRIPTION,
+ inputShape: {
+ purpose: STRING(200).describe('One short sentence for the owner, e.g. "Sign in to Example to continue setup".'),
+ note: STRING(500).optional().describe('Optional extra context for the owner, e.g. "I do not know which sign-in option your organization uses". Shown labelled as from you.'),
+ target: z.object({
+ app: STRING(200).optional().describe('Application name or bundle id showing the step, e.g. "Google Chrome".'),
+ pid: z.number().int().positive().optional(),
+ window_title: STRING(300).optional().describe('Window title, when the app has several windows.'),
+ }).strict().describe('The window that shows the step. Omit everything to use the frontmost app.'),
+ complete_when: z.object({
+ window_closed: z.boolean().optional(),
+ text_appears: STRING(200).optional(),
+ url_contains: STRING(500).optional(),
+ }).strict().optional().describe('Optional signs that the step is done. Cindy also detects completion itself.'),
+ timeout_minutes: z.number().int().min(1).max(60).optional(),
+ },
+ handler: async ({ purpose, note, target, complete_when, timeout_minutes }) => {
+ const context = getContext();
+ if (!context.sessionId || !context.sessionInstanceId)
+ return errorPayload('NO_SESSION_CONTEXT', 'No current Cindy task for this handoff.');
+ if (context.remoteHostId)
+ return errorPayload('CAPABILITY_NOT_AVAILABLE', 'Input handoff only works for windows on this computer.');
+ if (context.mcpCallerKind === 'descendant')
+ return errorPayload('ROOT_REQUIRED', 'Ask the parent agent to request the input handoff.');
+ const request: InputHandoffToolRequest = {
+ purpose,
+ ...(note ? { note } : {}),
+ target: {
+ ...(target.app ? { app: target.app } : {}),
+ ...(target.pid ? { pid: target.pid } : {}),
+ ...(target.window_title ? { windowTitle: target.window_title } : {}),
+ },
+ ...(complete_when ? {
+ completeWhen: {
+ ...(complete_when.window_closed !== undefined ? { windowClosed: complete_when.window_closed } : {}),
+ ...(complete_when.text_appears ? { textAppears: complete_when.text_appears } : {}),
+ ...(complete_when.url_contains ? { urlContains: complete_when.url_contains } : {}),
+ },
+ } : {}),
+ ...(timeout_minutes ? { timeoutMinutes: timeout_minutes } : {}),
+ };
+ let result: InputHandoffToolResult;
+ try {
+ result = await callbacks.start(context, request);
+ } catch {
+ return errorPayload('HANDOFF_UNAVAILABLE', 'Cindy could not start the input handoff. Tell the owner what is needed instead.');
+ }
+ if (!result.ok) return errorPayload(result.errorCode, result.message);
+ return okPayload({
+ request_id: result.requestId,
+ status: 'pending',
+ next: 'End your turn or do unrelated work. Do not touch that window until "[Input handoff ended]" arrives.',
+ });
+ },
+ });
+}
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/device-hosted-guest.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/device-hosted-guest.test.ts
index 725611d9d7..810dc9d6e2 100644
--- a/packages/maker-core/src/agents/claude-code/__tests__/device-hosted-guest.test.ts
+++ b/packages/maker-core/src/agents/claude-code/__tests__/device-hosted-guest.test.ts
@@ -134,7 +134,7 @@ const HOST_MODELS = ['shared/model-a', 'shared/model-b', 'other/model-c'].map((i
async function startHostedSession(
guest: boolean,
- overrides: { guestProvider?: DeviceHostedGuestProvider | null; providerId?: string } = {},
+ overrides: { guestProvider?: DeviceHostedGuestProvider | null; providerId?: string; local?: boolean } = {},
): Promise<{ options: CapturedOptions; sessionRoot: string }> {
const configDir = await makeTempDir();
process.env.CLAUDE_CONFIG_DIR = configDir;
@@ -160,7 +160,11 @@ async function startHostedSession(
};
const deps: AgentDeps = {
auth,
- runtimeConfig: { systemPrompt: 'GLOBAL CINDY HOST PROMPT', subagentModel: 'other/model-c' },
+ runtimeConfig: {
+ systemPrompt: 'GLOBAL CINDY HOST PROMPT',
+ subagentModel: 'other/model-c',
+ taskShellEnv: ({ sessionId }) => ({ CINDY_INPUT_HANDOFF_ROUTE: `route-${sessionId}` }),
+ },
capabilityAdditions: { availableModels: HOST_MODELS },
binaryPath: process.execPath,
logger: createNoopLogger(),
@@ -195,7 +199,7 @@ async function startHostedSession(
providerId: overrides.providerId ?? 'shared-provider',
workingDir,
permissionMode: 'acceptEdits',
- deviceHosted,
+ ...(overrides.local ? {} : { deviceHosted }),
});
liveHandles.push(handle);
const options = sdkMock.query.mock.calls.at(-1)?.[0]?.options as CapturedOptions | undefined;
@@ -286,4 +290,11 @@ describe('Claude Code device-hosted guest sessions', () => {
expect(options.settings?.availableModels).toEqual(['shared/model-a', 'shared/model-b', 'other/model-c']);
expect(options.env?.CLAUDE_CODE_SUBAGENT_MODEL).toBe('other/model-c');
});
+
+ it('gives terminal password prompts to the owner only for tasks running on this computer', async () => {
+ expect((await startHostedSession(false)).options.env?.CINDY_INPUT_HANDOFF_ROUTE).toBeUndefined();
+ expect((await startHostedSession(true)).options.env?.CINDY_INPUT_HANDOFF_ROUTE).toBeUndefined();
+ const { options } = await startHostedSession(false, { local: true });
+ expect(options.env?.CINDY_INPUT_HANDOFF_ROUTE).toBe('route-hosted-session');
+ });
});
diff --git a/packages/maker-core/src/agents/claude-code/index.ts b/packages/maker-core/src/agents/claude-code/index.ts
index 90c2ac4b25..4576f0a8d7 100644
--- a/packages/maker-core/src/agents/claude-code/index.ts
+++ b/packages/maker-core/src/agents/claude-code/index.ts
@@ -1659,6 +1659,10 @@ export class ClaudeCodeAgent extends BaseAgent {
? `${DEVICE_HOSTED_GUEST_ROUTE_HEADER}: ${guestProvider.routeToken}`
: undefined;
if (guestProvider) env.ANTHROPIC_SMALL_FAST_MODEL = sdkModel;
+ // Input handoff askpass for this owner's own local tasks only.
+ if (!opts.remoteHostId && !hosted && !reviewMode && opts.sessionId) {
+ Object.assign(env, this.deps.runtimeConfig.taskShellEnv?.({ sessionId: opts.sessionId }));
+ }
if (guestRouteHeader) {
env.ANTHROPIC_CUSTOM_HEADERS = env.ANTHROPIC_CUSTOM_HEADERS
? `${env.ANTHROPIC_CUSTOM_HEADERS}\n${guestRouteHeader}`
diff --git a/packages/maker-core/src/agents/codex/__tests__/device-hosted-guest.test.ts b/packages/maker-core/src/agents/codex/__tests__/device-hosted-guest.test.ts
index 310ca44cda..5b50468920 100644
--- a/packages/maker-core/src/agents/codex/__tests__/device-hosted-guest.test.ts
+++ b/packages/maker-core/src/agents/codex/__tests__/device-hosted-guest.test.ts
@@ -185,7 +185,10 @@ async function startHosted(fixture: Fixture) {
async logout() {},
async getAuthEnv() { return {}; },
},
- runtimeConfig: { systemPrompt: 'GLOBAL CINDY HOST PROMPT' },
+ runtimeConfig: {
+ systemPrompt: 'GLOBAL CINDY HOST PROMPT',
+ taskShellEnv: () => ({ CINDY_INPUT_HANDOFF_ROUTE: 'host-route' }),
+ },
binaryPath: process.execPath,
logger: noopLogger(),
getGhostRosterPrompt,
@@ -437,6 +440,8 @@ describe('Codex device-hosted guest sessions', () => {
expect(fixture.request.mock.calls.some(([method]) => method === Method.McpServerStatusList)).toBe(false);
expect(fixture.request.mock.calls.some(([method]) => method === Method.ExperimentalFeatureList)).toBe(false);
expect(config['features.image_generation']).toBeUndefined();
+ // Terminal password prompts would reach this computer's owner, not the account running the task.
+ expect(config['shell_environment_policy.set.CINDY_INPUT_HANDOFF_ROUTE']).toBeUndefined();
await handle.close();
});
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index d99aba22bf..6344207a03 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -1836,6 +1836,29 @@ describe('CodexAgent permissions', () => {
}
});
+ it.each([false, true])('gives this task\'s shell the 代输入 askpass variables per thread (resume=%s)', async (resume) => {
+ const agent = new CodexAgent(createDeps({
+ taskShellEnv: ({ sessionId }) => ({ CINDY_INPUT_HANDOFF_ROUTE: `route-${sessionId}`, SUDO_ASKPASS: '/tmp/x/askpass' }),
+ }));
+ const host = installFakeHost(agent);
+ const handle = await agent.startSession({
+ sessionId: 'askpass-task',
+ model: 'gpt-6-astra',
+ workingDir: '/repo',
+ ...(resume ? { resumeSessionId: '11111111-1111-1111-1111-111111111111' } : {}),
+ });
+ try {
+ const params = host.request.mock.calls.find(
+ ([method]) => method === (resume ? Method.ThreadResume : Method.ThreadStart),
+ )?.[1] as { config: Record<string, unknown> };
+ // The app-server is shared by tasks, so the variables travel with the thread, not the process.
+ expect(params.config['shell_environment_policy.set.CINDY_INPUT_HANDOFF_ROUTE']).toBe('route-askpass-task');
+ expect(params.config['shell_environment_policy.set.SUDO_ASKPASS']).toBe('/tmp/x/askpass');
+ } finally {
+ await handle.close();
+ }
+ });
+
it.each([
{ transport: 'absent', memoryConfig: undefined },
{ transport: 'stdio', memoryConfig: { command: 'memory-server', enabled: true } },
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index d74bf83e62..7225b5113a 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -3624,6 +3624,13 @@ assertRouteCurrent();
// 受邀者只能用分享给它的那一个供应商(启动来源就是它):app-server 不升格、不开智能子代理调配,
// 自定义供应商路由与按模型分流也只留它(见 prepareCodexExtraSpawnConfig 的 deviceHostedGuestProviderId)。
const guestProviderId = hostedGuest ? hosted?.guestProvider?.providerId : undefined;
+ // Input handoff askpass for this owner's own local tasks. The app-server is
+ // shared, so the variables reach this thread's commands through its config.
+ const taskShellEnvConfig = Object.fromEntries(Object.entries(
+ !opts.remoteHostId && !hosted && !reviewMode && sid
+ ? this.deps.runtimeConfig.taskShellEnv?.({ sessionId: sid }) ?? {}
+ : {},
+ ).map(([name, value]) => [`shell_environment_policy.set.${name}`, value]));
if (hostedGuest && (!guestProviderId || guestProviderId !== opts.providerId)) {
throw new Error('[REMOTE_AGENT_PROVIDER_NOT_ALLOWED] this provider is not allowed for remote use on this computer');
}
@@ -6464,6 +6471,7 @@ assertRouteCurrent();
// starts a second continuation loop whose turns bypass Session.send
// and lose the Host origin after the first terminal event.
'features.goals': false,
+ ...taskShellEnvConfig,
// Keep companion memory in its own Home. Native delegation uses the
// same feature settings and permissions as an ordinary task.
...(opts.botRuntimeProfile ? {
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
index aec52f5bd3..4969cee325 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
@@ -691,6 +691,23 @@ describe('pi auto-review dispatch & spawn config (mocked pi process)', () => {
await handle.close();
});
+ it.each(['local', 'remote'] as const)('gives only a local task\'s shell the 代输入 askpass variables (%s)', async (mode) => {
+ const deps = buildDeps();
+ const remoteTransport = deps.getRemotePiTransport!;
+ deps.getRemotePiTransport = async (host, options) => {
+ captured.env = options.env;
+ return remoteTransport(host, options);
+ };
+ deps.runtimeConfig.taskShellEnv = ({ sessionId }) => ({ CINDY_INPUT_HANDOFF_ROUTE: `route-${sessionId}` });
+ const agent = new PiAgent(deps);
+ const handle = await agent.startSession({ sessionId: 'askpass', workingDir: cwd, model: 'm',
+ ...(mode === 'remote' ? { remoteHostId: 'remote-1' } : {}),
+ });
+ // A remote computer's prompts must not reach this computer's owner.
+ expect(captured.env.CINDY_INPUT_HANDOFF_ROUTE).toBe(mode === 'local' ? 'route-askpass' : undefined);
+ await handle.close();
+ });
+
it('lets Pi discover user-installed packages natively instead of gating them on Cindy metadata', async () => {
const packageRoot = path.join(agentHome, 'future-pi-package-shape');
mkdirSync(packageRoot, { recursive: true });
diff --git a/packages/maker-core/src/agents/pi/index.ts b/packages/maker-core/src/agents/pi/index.ts
index dcee87c9c0..9e5671f11f 100644
--- a/packages/maker-core/src/agents/pi/index.ts
+++ b/packages/maker-core/src/agents/pi/index.ts
@@ -5465,6 +5465,10 @@ export class PiAgent extends BaseAgent {
...mcpEnv,
// 视觉桥后端 env(层 C):键含 API key 已纳入 piSecretEnvNames 剥离面。
...(visionBridgeEnv ? visionBridgeEnv : {}),
+ // Input handoff askpass, owner's own local tasks only (deterministic per session).
+ ...(!remote && !hosted && !reviewMode && opts.sessionId
+ ? this.deps.runtimeConfig.taskShellEnv?.({ sessionId: opts.sessionId })
+ : {}),
[PI_SESSION_ID_ENV]: opts.sessionId ?? '',
...(proxySessionToken !== undefined ? { [PI_SESSION_TOKEN_ENV]: proxySessionToken } : {}),
[PI_SECRET_ENV_NAMES_ENV]: JSON.stringify(piSecretEnvNames),
diff --git a/packages/maker-core/src/interfaces/runtime-config.ts b/packages/maker-core/src/interfaces/runtime-config.ts
index 191c8543f6..cd3e81b38c 100644
--- a/packages/maker-core/src/interfaces/runtime-config.ts
+++ b/packages/maker-core/src/interfaces/runtime-config.ts
@@ -59,6 +59,16 @@ export interface AgentRuntimeConfig {
*/
behaviorFlags?: Record<string, string> | ((ctx: BehaviorFlagsContext) => Record<string, string>);
+ /**
+ * Variables for the commands the agent runs in one task (Cindy input handoff
+ * askpass). Harnesses call it only for local tasks of this account: never for
+ * SSH, Review or device-hosted guest tasks. Claude Code and Pi add it to the
+ * agent process env; Codex, whose app-server is shared, sets it per thread via
+ * `shell_environment_policy.set`. Must be deterministic per sessionId so a
+ * respawned process gets byte-identical env.
+ */
+ taskShellEnv?: (ctx: { sessionId: string }) => Record<string, string>;
+
/**
* Host-managed default model for native subagents.
*
diff --git a/packages/maker-shared/src/__tests__/inputHandoffRecord.test.ts b/packages/maker-shared/src/__tests__/inputHandoffRecord.test.ts
new file mode 100644
index 0000000000..51d091b8a8
--- /dev/null
+++ b/packages/maker-shared/src/__tests__/inputHandoffRecord.test.ts
@@ -0,0 +1,45 @@
+import { describe, expect, it } from 'vitest';
+import {
+ INPUT_HANDOFF_ENDED_PREFIX,
+ UI_ACTION_TRIGGER_PREFIX,
+ inputHandoffRecordHost,
+ inputHandoffRecordMessage,
+ parseInputHandoffEndRecord,
+} from '../syntheticTrigger.js';
+
+const line = (facts: string) => `${UI_ACTION_TRIGGER_PREFIX}${INPUT_HANDOFF_ENDED_PREFIX} ${facts}. Continue.`;
+
+describe('代输入 record line', () => {
+ it('reads the facts the Host wrote and nothing else', () => {
+ const record = parseInputHandoffEndRecord(
+ line('status=succeeded steps=2 origin=https://login.example.test/sso app="Example App" answered_on="Chris \\"Phone\\""'),
+ );
+ expect(record).toEqual({
+ status: 'succeeded',
+ nothingToFill: false,
+ steps: 2,
+ origin: 'https://login.example.test/sso',
+ app: 'Example App',
+ answeredOn: { kind: 'named', name: 'Chris "Phone"' },
+ });
+ expect(inputHandoffRecordHost(record!.origin)).toBe('login.example.test');
+ });
+
+ it('labels where it was finished', () => {
+ const msg = (facts: string) => inputHandoffRecordMessage(parseInputHandoffEndRecord(line(facts))!);
+ expect(msg('status=succeeded steps=1 answered_on=this_computer')).toEqual({ key: 'doneHost', params: { count: 1 } });
+ expect(msg('status=succeeded steps=3 answered_on=phone')).toEqual({ key: 'donePhone', params: { count: 3 } });
+ expect(msg('status=succeeded steps=1 answered_on=another_device')).toEqual({ key: 'doneElsewhere', params: { count: 1 } });
+ expect(msg('status=succeeded steps=0').key).toBe('done');
+ expect(msg('status=cancelled steps=0 ended_by=detected failure=nothing_to_fill').key).toBe('nothingToFill');
+ expect(msg('status=cancelled steps=1').key).toBe('cancelled');
+ expect(msg('status=expired steps=0').key).toBe('expired');
+ expect(msg('status=failed steps=0').key).toBe('failed');
+ });
+
+ it('ignores other hidden triggers and malformed lines', () => {
+ expect(parseInputHandoffEndRecord(`${UI_ACTION_TRIGGER_PREFIX}Something else`)).toBeNull();
+ expect(parseInputHandoffEndRecord(line('status=weird steps=1'))).toBeNull();
+ expect(inputHandoffRecordHost('not a url')).toBeUndefined();
+ });
+});
diff --git a/packages/maker-shared/src/__tests__/interaction.test.ts b/packages/maker-shared/src/__tests__/interaction.test.ts
index f54f40fd7e..e02ccebe09 100644
--- a/packages/maker-shared/src/__tests__/interaction.test.ts
+++ b/packages/maker-shared/src/__tests__/interaction.test.ts
@@ -638,6 +638,21 @@ describe('interaction shared model', () => {
expect(interactionBlocksRemoteComposer(null)).toBe(false);
});
+ it('lets the controller answer 代输入 without taking over its composer', () => {
+ const live = { request: { kind: 'input_handoff', requestId: 'h1', revision: 3 } };
+ const ended = { request: { kind: 'input_handoff', requestId: 'h1', revision: 4, terminal: true } };
+ expect(remoteInteractionHandling(live)).toBe('resolvable');
+ expect(remoteInteractionHandling(ended)).toBe('desktop-only');
+ // A Host-owned wait outlives the turn; the owner must still be able to chat.
+ expect(interactionBlocksRemoteComposer(live)).toBe(false);
+ expect(pendingInteractionsBlockRemoteComposer([live])).toBe(false);
+ // A question the turn is blocked on still comes first.
+ expect(sortPendingInteractions([
+ live,
+ { request: { kind: 'permission', requestId: 'p1' } },
+ ]).map((item) => item.request.requestId)).toEqual(['p1', 'h1']);
+ });
+
it('keys composer blocking off the whole pending set, not the card being viewed', () => {
// 混合队列:切到 plugin_setup 只是换了查看对象,那张权限卡仍在等回答 —— 输入框
// 不能因此放开,否则用户绕过了仍待处理的阻塞交互。
diff --git a/packages/maker-shared/src/interaction.ts b/packages/maker-shared/src/interaction.ts
index f9cc30d7f6..490e326e3f 100644
--- a/packages/maker-shared/src/interaction.ts
+++ b/packages/maker-shared/src/interaction.ts
@@ -390,7 +390,7 @@ export function interactionKind(item: PendingInteractionLike): string {
}
export function interactionDisplayTitle(kind: string, localizer?: PresentationLocalizer): string {
- const known = ['plan_review', 'permission', 'ask_user_question', 'issue_confirm', 'plugin_setup'];
+ const known = ['plan_review', 'permission', 'ask_user_question', 'issue_confirm', 'plugin_setup', 'input_handoff'];
const key = known.includes(kind) ? kind : 'fallback';
const fallback: Record<string, string> = {
plan_review: '需要确认执行计划',
@@ -398,6 +398,7 @@ export function interactionDisplayTitle(kind: string, localizer?: PresentationLo
ask_user_question: '需要回答 Agent 问题',
issue_confirm: '需要确认 Issue 内容',
plugin_setup: '需要在电脑端配置插件',
+ input_handoff: '需要你代为输入',
fallback: '需要处理远程请求',
};
return presentationText(localizer, `interaction.kinds.${key}.title`, fallback[key]);
@@ -424,7 +425,7 @@ export function interactionDisplayHint(
}
export function interactionKindLabel(kind: string, localizer?: PresentationLocalizer): string {
- const known = ['plan_review', 'permission', 'ask_user_question', 'issue_confirm', 'plugin_setup'];
+ const known = ['plan_review', 'permission', 'ask_user_question', 'issue_confirm', 'plugin_setup', 'input_handoff'];
const key = known.includes(kind) ? kind : 'fallback';
const fallback: Record<string, string> = {
plan_review: '计划',
@@ -432,6 +433,7 @@ export function interactionKindLabel(kind: string, localizer?: PresentationLocal
ask_user_question: '问题',
issue_confirm: 'Issue',
plugin_setup: '插件',
+ input_handoff: '代输入',
fallback: '请求',
};
return presentationText(localizer, `interaction.kinds.${key}.label`, fallback[key]);
@@ -456,6 +458,9 @@ const REMOTE_RESOLVABLE_KINDS = new Set(['permission', 'ask_user_question', 'pla
export function remoteInteractionHandling(item: PendingInteractionLike): RemoteInteractionHandling {
const kind = interactionKind(item);
if (REMOTE_RESOLVABLE_KINDS.has(kind)) return 'resolvable';
+ // 代输入: the controller fills each step through the signed per-step channel
+ // and sends value-less decisions (done / cancel / stay / refresh) through resolve.
+ if (kind === 'input_handoff') return item.request.terminal === true ? 'desktop-only' : 'resolvable';
// `cancel-only` 必须与 buildPluginSetupCancelDecision 判定一致,否则调用方只看
// handling 就以为「能取消」,而实际拿不到 decision(#530 review):
// - terminal 快照是被控端收尾展示用的最后一帧,已经不 actionable;
@@ -475,6 +480,8 @@ export function remoteInteractionHandling(item: PendingInteractionLike): RemoteI
* 死锁:任何被控端新增的 interaction kind 默认都落进「不阻塞」这一侧。
*/
export function interactionBlocksRemoteComposer(item: PendingInteractionLike | null | undefined): boolean {
+ // 代输入 is a Host-owned wait that outlives the turn; the owner keeps the composer.
+ if (item && interactionKind(item) === 'input_handoff') return false;
return !!item && remoteInteractionHandling(item) === 'resolvable';
}
@@ -785,6 +792,8 @@ const INTERACTION_PRIORITY: Record<string, number> = {
// 只能回电脑端处理的卡上(手机侧另有不阻塞输入框的兜底,见
// interactionBlocksRemoteComposer)。
plugin_setup: 4,
+ // Answerable on the controller, but never ahead of a question the turn is blocked on.
+ input_handoff: 3,
};
export function interactionPriority(item: PendingInteractionLike): number {
diff --git a/packages/maker-shared/src/syntheticTrigger.ts b/packages/maker-shared/src/syntheticTrigger.ts
index 453e272544..d59298f11c 100644
--- a/packages/maker-shared/src/syntheticTrigger.ts
+++ b/packages/maker-shared/src/syntheticTrigger.ts
@@ -87,3 +87,92 @@ export function isContinuationMessage(message: {
: (content as { text?: unknown } | null)?.text;
return typeof text === 'string' && syntheticTriggerKind(text) === 'continue';
}
+
+/**
+ * 代输入结束时给 Agent 的隐藏续接(桌面 input-handoff/service.ts 产出)。它只有
+ * 事实没有主人输入的值;两端从同一行派生任务记录里那条可见留痕
+ * 「主人在 iPhone 完成了 3 步输入 · <域名> · 时间」。
+ */
+export const INPUT_HANDOFF_ENDED_PREFIX = '[Input handoff ended]';
+
+export interface InputHandoffEndRecord {
+ status: 'succeeded' | 'cancelled' | 'failed' | 'expired';
+ /** The screen had nothing for the owner to type; the agent carried on by itself. */
+ nothingToFill: boolean;
+ steps: number;
+ origin?: string;
+ app?: string;
+ /** Answering device: a display name, or this computer / an unnamed phone or device. */
+ answeredOn?: { kind: 'this_computer' | 'phone' | 'another_device' } | { kind: 'named'; name: string };
+}
+
+const END_STATUSES = new Set(['succeeded', 'cancelled', 'failed', 'expired']);
+const QUOTED = '"(?:[^"\\\\]|\\\\.)*"';
+
+function readQuoted(text: string, key: string): string | undefined {
+ const match = new RegExp(`(?:^| )${key}=(${QUOTED})`).exec(text);
+ if (!match) return undefined;
+ try {
+ const value = JSON.parse(match[1]) as unknown;
+ return typeof value === 'string' && value.trim() ? value.trim().slice(0, 200) : undefined;
+ } catch {
+ return undefined;
+ }
+}
+
+/** Parse the persisted continuation row (with or without the UI trigger prefix). */
+export function parseInputHandoffEndRecord(content: string): InputHandoffEndRecord | null {
+ const text = content.startsWith(UI_ACTION_TRIGGER_PREFIX) ? content.slice(UI_ACTION_TRIGGER_PREFIX.length) : content;
+ if (!text.startsWith(INPUT_HANDOFF_ENDED_PREFIX)) return null;
+ const facts = text.slice(INPUT_HANDOFF_ENDED_PREFIX.length);
+ const status = / status=(\w+)/.exec(facts)?.[1];
+ const steps = Number(/ steps=(\d+)/.exec(facts)?.[1]);
+ if (!status || !END_STATUSES.has(status) || !Number.isSafeInteger(steps)) return null;
+ // The facts end with ". " before the instruction sentence; drop that period.
+ const origin = / origin=([^\s"]+)/.exec(facts)?.[1]?.replace(/\.$/, '');
+ const app = readQuoted(facts, 'app');
+ const answered = / answered_on=(this_computer|phone|another_device)\b/.exec(facts)?.[1];
+ const answeredName = answered ? undefined : readQuoted(facts, 'answered_on');
+ return {
+ status: status as InputHandoffEndRecord['status'],
+ nothingToFill: / failure=nothing_to_fill\b/.test(facts),
+ steps,
+ ...(origin ? { origin: origin.slice(0, 300) } : {}),
+ ...(app ? { app } : {}),
+ ...(answered
+ ? { answeredOn: { kind: answered as 'this_computer' | 'phone' | 'another_device' } }
+ : answeredName
+ ? { answeredOn: { kind: 'named' as const, name: answeredName } }
+ : {}),
+ };
+}
+
+export type InputHandoffRecordKey =
+ | 'nothingToFill' | 'cancelled' | 'expired' | 'failed' | 'done'
+ | 'doneOn' | 'doneHost' | 'donePhone' | 'doneElsewhere';
+
+/** Locale key + params for the record line; both clients translate under their own `…record.<key>`. */
+export function inputHandoffRecordMessage(record: InputHandoffEndRecord): {
+ key: InputHandoffRecordKey;
+ params?: { count: number; device?: string };
+} {
+ if (record.nothingToFill) return { key: 'nothingToFill' };
+ if (record.status !== 'succeeded') return { key: record.status };
+ const count = record.steps;
+ const on = record.answeredOn;
+ if (count < 1 || !on) return { key: 'done' };
+ if (on.kind === 'named') return { key: 'doneOn', params: { count, device: on.name } };
+ if (on.kind === 'this_computer') return { key: 'doneHost', params: { count } };
+ if (on.kind === 'phone') return { key: 'donePhone', params: { count } };
+ return { key: 'doneElsewhere', params: { count } };
+}
+
+/** Host part of the final origin for display; never the path or query. */
+export function inputHandoffRecordHost(origin?: string): string | undefined {
+ if (!origin) return undefined;
+ try {
+ return new URL(origin).host || undefined;
+ } catch {
+ return undefined;
+ }
+}