Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123import AppKitimport CoreGraphicsimport Foundationimport ParcelCoreimport ParcelPlatformimport RealityDriverSupport
@MainActorfunc desktopStandardWindows( _ session: RealitySession, rows: [DesktopWindow], fixturePIDs: Set<Int32>?, directory: URL) async throws -> [DesktopWindow] { let active = Set(try await NativeSpaceReader().snapshot().map(\.currentSpace)) let regular = Set( NSWorkspace.shared.runningApplications.filter { $0.activationPolicy == .regular }.map(\.processIdentifier)) let candidates = rows.filter { $0.pid != session.parcel?.processIdentifier && RealDesktopOracle.candidate($0, activeSpaces: active, regularPIDs: regular) && (fixturePIDs == nil || fixturePIDs?.contains($0.pid) == true) } var standard: Set<UInt32> = [] for pid in Set(candidates.map(\.pid)).sorted() { let response = try await session.driver.send( .standardWindows(pid: pid, candidates: candidates.filter { $0.pid == pid }.map(\.id))) try encodeJSON(response, to: directory.appendingPathComponent("standard-windows-\(pid).json")) guard let ids = response.windowIDs, let identified = response.identifiedWindowIDs else { throw RealityError("Missing independent standard-window probe for pid \(pid)") } standard.formUnion( RealDesktopOracle.probeCandidates( candidates: candidates.filter { $0.pid == pid }.map(\.id), standard: ids, identified: identified)) } return candidates.filter { standard.contains($0.id) }}
@MainActorfunc desktopAudit( _ session: RealitySession, windows: [DesktopWindow], workspaces: [DesktopWorkspace], skipped: [DesktopSkippedApplication], directory: URL) async throws -> (audits: [DesktopWindowAudit], inspections: [DesktopInspection]) { let tiled = Set( workspaces.filter(\.active).flatMap { $0.tiles?.stacks ?? [] }.flatMap { $0.windows.map(\.rawValue) }) var audits: [DesktopWindowAudit] = [] var inspections: [DesktopInspection] = [] for window in windows { let result = try await session.cli(["why", "--json", String(window.id)]) try encodeJSON(result, to: directory.appendingPathComponent("why-\(window.id).json")) let inspection: DesktopInspection? let why: String if result.status == 0 { let value = try JSONDecoder().decode(DesktopInspection.self, from: Data(result.output.utf8)) guard value.id == window.id else { throw RealityError("Window \(window.id) returned a different diagnostic identity") } inspection = value inspections.append(value) why = value.reason ?? "No classification explanation" } else if RealDesktopOracle.unknownWindow(result) { inspection = nil why = "unmanaged: Parcel has not observed this window (window_not_found)" } else { throw RealityError("Window \(window.id) diagnostic failed: \(result.errors)") } audits.append( RealDesktopOracle.audit(window: window, tiledIDs: tiled, inspection: inspection, skipped: skipped, why: why) ) } return (audits, inspections)}
@MainActorfunc desktopTourEvidence(_ session: RealitySession, stage: String, directory: URL) async throws -> DesktopTourEvidence { let result = try await session.cli(["run", "--json", "e2e-tour", "status"]) try encodeJSON(result, to: directory.appendingPathComponent("tour-\(stage).json")) guard result.status == 0 else { throw RealityError("Desktop tour evidence failed: \(result.errors)") } return try JSONDecoder().decode(DesktopTourEvidence.self, from: Data(result.output.utf8))}
@MainActorfunc desktopScreenshot(directory: URL) async throws -> [String] { // Preflight never requests access; capture remains the terminal harness's responsibility. guard CGPreflightScreenCaptureAccess() else { throw RealityError( "Desktop screenshots need an existing Screen Recording grant for the terminal harness, not Parcel") } let count = NSScreen.screens.count guard count > 0 else { throw RealityError("No displays available for desktop screenshots") } var paths: [String] = [] for display in 1...count { let file = "display-\(display).png" let target = directory.appendingPathComponent(file) let result = try await RealityProcess.run( "/usr/sbin/screencapture", ["-x", "-D", String(display), target.path], directory: directory) try encodeJSON(result, to: directory.appendingPathComponent("receipt-\(display).json")) guard result.status == 0 else { throw RealityError("Harness screenshot failed: \(result.errors)") } let data = try Data(contentsOf: target) guard data.count > 8, Array(data.prefix(8)) == [137, 80, 78, 71, 13, 10, 26, 10] else { throw RealityError("Harness screenshot did not produce a PNG for display \(display)") } paths.append(file) } return paths}
@MainActorfunc desktopManagerEvidence(environment: [String: String], notes: URL, report: inout RealDesktopReport) throws { report.runningBundleIDs = Array(Set(NSWorkspace.shared.runningApplications.compactMap(\.bundleIdentifier))).sorted() let path = environment["PARCEL_REAL_DESKTOP_MANAGER_BUNDLE_IDS"] guard path == nil || path?.hasPrefix("/") == true else { throw RealityError("Private window-manager watch list requires an absolute path") } let file = path.map { URL(fileURLWithPath: $0) } ?? notes.appendingPathComponent("qa/real-desktop/window-manager-bundle-ids.json") if path == nil && !FileManager.default.fileExists(atPath: file.path) { return } guard file.path.hasPrefix("/"), file.standardizedFileURL == file.resolvingSymlinksInPath().standardizedFileURL else { throw RealityError("Private window-manager watch list must be an unredirected absolute path") } let watched = try RealDesktopOracle.managerBundleIDs(Data(contentsOf: file)) report.competingManagers = report.runningBundleIDs.filter { watched.contains($0) } report.managerDetection = "Matched a private bundle-ID watch list; running utilities may fight Parcel"}