Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677import Foundationimport RealityDriverSupport
struct RealityRecoveryLedger { static func load(directory: URL, repository: URL) throws -> [OwnedWindow] { let expectedRoot = repository.resolvingSymlinksInPath().appendingPathComponent( "build/reality", isDirectory: true) let root = expectedRoot.resolvingSymlinksInPath() let directory = directory.resolvingSymlinksInPath() guard root.path == expectedRoot.path, directory.path.hasPrefix(root.path + "/") else { throw RealityError("Recovery must use an ownership ledger inside this worktree's build/reality") } let windows = try JSONDecoder().decode( [OwnedWindow].self, from: Data(contentsOf: directory.appendingPathComponent("owned-windows.json"))) guard windows.count == 1, let window = windows.first, window.app == .finder, window.pid > 0, window.id > 0 else { throw RealityError("Recovery accepts exactly one active, ledger-owned Finder window; it never quits Finder") } return windows }}
@MainActorfunc recoverOwnedFinder(directory: URL, driver: RealityDriver) async throws { let windows = try RealityRecoveryLedger.load( directory: directory, repository: URL(fileURLWithPath: FileManager.default.currentDirectoryPath)) var warnings: [String] = [] for window in windows { guard try FrameOracle.read().contains(where: { $0.id == window.id && $0.pid == window.pid }) else { throw RealityError("The recovery window is absent or no longer owned by the recorded PID") } warnings += try await driver.register(window) _ = try await driver.send(.close(pid: window.pid, windowID: window.id)) var samples: [Observation] = [] _ = try await pollRealFrames(samples: &samples) { !$0.contains { $0.id == window.id } } } struct Receipt: Encodable { let closed: [OwnedWindow] let identificationWarnings: [String] } try encodeJSON( Receipt(closed: windows, identificationWarnings: warnings), to: directory.appendingPathComponent("recovery.json")) try encodeJSON([OwnedWindow](), to: directory.appendingPathComponent("owned-windows.json"))}
@MainActorfunc recoverHeldKey(_ key: UInt16, driver: RealityDriver) async throws { try RealityScreenPrecondition.requireAvailableConsole() try DriverCommand.recoverKey(pid: 1, windowID: 1, virtualKey: key).validate() let directory = URL(fileURLWithPath: FileManager.default.currentDirectoryPath) .appendingPathComponent("build/reality/key-recovery-\(UUID().uuidString)") try FileManager.default.createDirectory( at: directory, withIntermediateDirectories: true, attributes: [.posixPermissions: 0o700]) let apps = RealApps(directory: directory, token: "ParcelReality-Recovery-\(UUID().uuidString)", driver: driver) var operationError: (any Error)? do { let window = try await apps.open(.fixture) try await apps.focus(window) let before = try await driver.inputState() let response = try await driver.send(.recoverKey(pid: window.pid, windowID: window.id, virtualKey: key)) guard let after = response.inputState else { throw RealityError("Safety stop: recovery omitted combined state") } try after.requireNeutralBaseline() try encodeJSON([before, after], to: directory.appendingPathComponent("key-recovery.json")) } catch { operationError = error } do { try await apps.cleanup() } catch { throw RealityError( "Safety stop: recovery cleanup failed: \(error); operation: \(String(describing: operationError))") } if let operationError { throw operationError } try DriverInputState.capture().requireNeutralBaseline() print("Released key \(key) through an owned fixture; combined state is neutral. Evidence: \(directory.path)")}