import DocsKit import Foundation import RastrilloApple import SwiftUI // This entry point is exclusively the review target. The production target // compiles Sources/DocsApp and has no fixture/environment authentication path. @main struct DocsReviewPhone: App { private struct Configuration: Decodable { let origin: String; let credential: NativeSession } private var client: NativeHTTP? { let input = URL.documentsDirectory.appendingPathComponent("review.json") guard let data = try? Data(contentsOf: input), let config = try? JSONDecoder().decode(Configuration.self, from: data), let origin = try? NativeHTTP.origin(config.origin), origin.scheme == "http", ["localhost", "127.0.0.1", "::1", "[::1]"].contains(origin.host ?? "") else { return nil } return NativeHTTP(origin: origin, credential: config.credential) } var body: some Scene { WindowGroup { if let client { DocsWorkspace(client: client, signOut: {}) .overlay(alignment: .bottom) { if ProcessInfo.processInfo.environment["DOCS_REVIEW_COMMAND_PROBE"] == "1" { ReviewCommandProbe() } } } else { Text("Review fixture unavailable").accessibilityIdentifier("fixture.missing") } } } } // Fixed-command review probe only. It inspects and dispatches the editor's real // registered Command-K action through the first-responder chain, without HID. import UIKit private struct ReviewCommandProbe: View { @State private var status = "Waiting for native editor focus" var body: some View { Text(status).font(.caption).accessibilityIdentifier("review.command.probe") .task { for _ in 0..<200 { guard !Task.isCancelled else { return } let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene } let windows: [UIWindow] = scenes.flatMap { $0.windows } var focused: UITextView? for window in windows { if let editor = focusedEditor(in: window) { focused = editor; break } } if let editor = focused { let registered: [UIKeyCommand] = editor.keyCommands ?? [] var found: UIKeyCommand? for candidate in registered { if candidate.input == "k" && candidate.modifierFlags == UIKeyModifierFlags.command { found = candidate; break } } guard let command = found, let selector = command.action, command.wantsPriorityOverSystemBehavior else { status = "Missing native Command-K registration"; return } status = UIApplication.shared.sendAction(selector, to: nil, from: command, for: nil) ? "Native Command-K dispatched" : "Native Command-K dispatch failed" return } try? await Task.sleep(for: .milliseconds(100)) } status = "Native editor never became first responder" } } private func focusedEditor(in view: UIView) -> UITextView? { if let editor = view as? UITextView, editor.accessibilityIdentifier == "docs.editor", editor.isFirstResponder { return editor } return view.subviews.lazy.compactMap { focusedEditor(in: $0) }.first } }