The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.
Tidy Downloads as Arc's, on Apple Intelligence
Victor3435f27599b1
diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swiftindex 32ac97c..ae9833a 100644--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift@@ -524,6 +524,9 @@ public struct AppSettings: Codable, Equatable {/// Arc Max's Tidy Tab Titles (renamePinnedTabsEnabled): a tab you pin gets a shorter name from the/// Mac's Apple Intelligence model. Off by default: it renames, where Tidy waits for a click.public var tidyTabTitles: Bool = false+ /// Arc Max's Tidy Downloads (renameDownloadsEnabled): a finished download gets a readable name from+ /// the Mac's Apple Intelligence model. Off by default, like Arc Max.+ public var tidyDownloads: Bool = falsepublic init() {}@@ -688,6 +691,7 @@ extension AppSettings {perfHidesSiteNames = try c.decodeIfPresent(Bool.self, forKey: .perfHidesSiteNames) ?? falsetidyTabs = try c.decodeIfPresent(Bool.self, forKey: .tidyTabs) ?? truetidyTabTitles = try c.decodeIfPresent(Bool.self, forKey: .tidyTabTitles) ?? false+ tidyDownloads = try c.decodeIfPresent(Bool.self, forKey: .tidyDownloads) ?? false}}diff --git a/Packages/CraCore/Sources/CraCore/TidyDownloads.swift b/Packages/CraCore/Sources/CraCore/TidyDownloads.swiftnew file mode 100644index 0000000..f6c347e--- /dev/null+++ b/Packages/CraCore/Sources/CraCore/TidyDownloads.swift@@ -0,0 +1,75 @@+import Foundation++/// Arc Max's Tidy Downloads (renameDownloads), on the Mac's own Apple Intelligence model: a finished+/// download gets a short, readable name from its file name, the tab's title and the site (Arc 1.171's+/// beginRename(…defaultFilename:sourceUrl:webContentsTitle:referrerTitle:)). This decides what the+/// model is asked and which answers may become a file's name; renaming the file is the app's.+public enum TidyDownloads {+ static let maximumLength = 80++ public static let instructions = """+ You rename files as they finish downloading, so they are helpful, concise and readable: two to four \+ words. Keep names that already say what the file is mostly as they are. For names that say nothing \+ (image.png, download.pdf, IDs), use what the tab's title or the website says. Remove machine-made \+ cruft such as IDs, (1), (copy), stock-photo prefixes and seconds in times; write dates short and human \+ ("Aug 14"); fix casing and spacing. Answer with the new name only, keeping the file's extension.+ """++ /// Pairs showing the style (made up for Cra, in the spirit of Arc's).+ public static let examples: [(file: String, title: String, site: String, name: String)] = [+ ("Cra-0.1.30.dmg", "Cra · A browser like Arc", "crabrowser.app", "Cra 0.1.30.dmg"),+ ("invoice_884213_2026-10-02.pdf", "Your invoice from Acme Hosting - Gmail", "mail.google.com", "Acme Hosting Invoice Oct 2.pdf"),+ ("IMG_20260912_141533.jpg", "Photos from the beach trip - Google Drive", "drive.google.com", "Beach Trip Sep 12.jpg"),+ ("image.png", "Logo feedback - Slack", "app.slack.com", "Logo Feedback.png"),+ ("Screenshot 2026-09-26 at 11.12.18 PM.png", "DM with Sara - X", "x.com", "Sep 26 Screenshot from Sara.png"),+ ("annual-report-final(1).pdf", "Annual report 2025 | Nordic Rail", "nordicrail.com", "Nordic Rail Annual Report 2025.pdf"),+ ]++ /// The request: the file's name, the tab it came from and the site.+ public static func prompt(file: String, tabTitle: String, url: String) -> String {+ var lines = ["Examples, as 'file', 'tab title', 'site' → new name:"]+ for e in examples { lines.append("'\(e.file)', '\(e.title)', '\(e.site)' → \(e.name)") }+ lines.append("")+ lines.append("Rename: '\(file)', '\(clip(tabTitle, 160))', '\(host(url))'")+ return lines.joined(separator: "\n")+ }++ /// The model's answer as a file name in the same folder, or nil when it isn't usable: empty,+ /// hidden (".…"), the same name, or with path characters. The original extension stays.+ public static func clean(_ answer: String, original: String) -> String? {+ var s = answer.split(whereSeparator: \.isNewline).first.map(String.init) ?? ""+ s = s.trimmingCharacters(in: .whitespaces.union(CharacterSet(charactersIn: "\"'“”‘’`")))+ s = s.replacingOccurrences(of: "/", with: "-").replacingOccurrences(of: ":", with: "-")+ s = s.split(whereSeparator: \.isWhitespace).joined(separator: " ")+ guard !s.isEmpty, !s.hasPrefix(".") else { return nil }+ let ext = (original as NSString).pathExtension+ if !ext.isEmpty {+ // A name that lost or changed the extension gets the original's back.+ if (s as NSString).pathExtension.lowercased() != ext.lowercased() { s += "." + ext }+ let stem = (s as NSString).deletingPathExtension.trimmingCharacters(in: .whitespaces.union(.punctuationCharacters))+ guard !stem.isEmpty else { return nil }+ s = stem + "." + ext+ }+ guard !s.isEmpty, !s.hasPrefix("."), s.count <= maximumLength, s != original else { return nil }+ return s+ }++ /// A free name in `existing` for `name`: "Report.pdf", then "Report 2.pdf", "Report 3.pdf"…+ public static func unique(_ name: String, existing: (String) -> Bool) -> String {+ guard existing(name) else { return name }+ let ext = (name as NSString).pathExtension+ let stem = (name as NSString).deletingPathExtension+ for n in 2...999 {+ let candidate = ext.isEmpty ? "\(stem) \(n)" : "\(stem) \(n).\(ext)"+ if !existing(candidate) { return candidate }+ }+ return name+ }++ static func host(_ url: String) -> String {+ guard let h = URL(string: url)?.host?.lowercased() else { return "" }+ return h.hasPrefix("www.") ? String(h.dropFirst(4)) : h+ }++ static func clip(_ s: String, _ n: Int) -> String { s.count <= n ? s : String(s.prefix(n)) }+}diff --git a/Packages/CraCore/Tests/CraCoreTests/TidyDownloadsTests.swift b/Packages/CraCore/Tests/CraCoreTests/TidyDownloadsTests.swiftnew file mode 100644index 0000000..61bf8cb--- /dev/null+++ b/Packages/CraCore/Tests/CraCoreTests/TidyDownloadsTests.swift@@ -0,0 +1,37 @@+import CraCore+import Testing++/// Tidy Downloads: what the model is asked about a finished download and which answers rename it.+struct TidyDownloadsTests {+ @Test func promptGivesFileTabAndSite() {+ let p = TidyDownloads.prompt(file: "folio_6691488.PDF", tabTitle: "Your Guest Stay Folio", url: "https://mail.google.com/mail/u/0/#inbox")+ #expect(p.hasPrefix("Examples, as 'file', 'tab title', 'site' → new name:\n'Cra-0.1.30.dmg'"))+ #expect(p.hasSuffix("Rename: 'folio_6691488.PDF', 'Your Guest Stay Folio', 'mail.google.com'"))+ }++ @Test func cleanKeepsTheExtension() {+ #expect(TidyDownloads.clean("Hello World Master", original: "Hello-World-master.zip") == "Hello World Master.zip")+ #expect(TidyDownloads.clean("\"Guest Stay Folio Aug 14.pdf\"", original: "folio_6691488.PDF") == "Guest Stay Folio Aug 14.PDF")+ #expect(TidyDownloads.clean("Ladybug.png", original: "AdobeStock_1.jpeg") == "Ladybug.png.jpeg")+ #expect(TidyDownloads.clean("Notes", original: "notes_v2") == "Notes")+ }++ @Test func cleanRefusesUnusableNames() {+ #expect(TidyDownloads.clean("", original: "a.pdf") == nil)+ #expect(TidyDownloads.clean(".pdf", original: "a.pdf") == nil)+ #expect(TidyDownloads.clean(".hidden", original: "notes") == nil)+ #expect(TidyDownloads.clean("a.pdf", original: "a.pdf") == nil)+ #expect(TidyDownloads.clean(String(repeating: "x", count: 90), original: "a.pdf") == nil)+ // Path characters can't move the file elsewhere.+ #expect(TidyDownloads.clean("../../etc/Report", original: "r.pdf") == nil)+ #expect(TidyDownloads.clean("Q3/Q4 Report", original: "r.pdf") == "Q3-Q4 Report.pdf")+ #expect(TidyDownloads.clean("Q3: Plan", original: "plan.key") == "Q3- Plan.key")+ }++ @Test func uniqueNamesDontOverwrite() {+ let taken: Set = ["Report.pdf", "Report 2.pdf", "Notes"]+ #expect(TidyDownloads.unique("Report.pdf", existing: taken.contains) == "Report 3.pdf")+ #expect(TidyDownloads.unique("Notes", existing: taken.contains) == "Notes 2")+ #expect(TidyDownloads.unique("New.pdf", existing: taken.contains) == "New.pdf")+ }+}diff --git a/Sources/Cra/Services/BrowserManager.swift b/Sources/Cra/Services/BrowserManager.swiftindex 746d509..704195d 100644--- a/Sources/Cra/Services/BrowserManager.swift+++ b/Sources/Cra/Services/BrowserManager.swift@@ -117,6 +117,8 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {}func runtime(for tabID: UUID) -> TabRuntime? { runtimes[tabID] }+ /// The tab whose page the download being reported came from (set only during that report).+ private(set) var downloadSourceTab: UUID?var visibleRuntime: TabRuntime? { visibleTabID.flatMap { runtimes[$0] } }@discardableResult@@ -1135,7 +1137,10 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {}func browser(_ browser: CraBrowser, didUpdateDownload download: CraDownloadInfo) {+ // The delegate reads it during the call: Tidy Downloads names the file from that tab.+ downloadSourceTab = tabID(of: browser)delegate?.browserManager(download: download)+ downloadSourceTab = nil}func browser(_ browser: CraBrowser, requestsPermissionForOrigin origin: String, kinds: UInt, completion: @escaping (Bool) -> Void) {diff --git a/Sources/Cra/Services/TidyDownloadsService.swift b/Sources/Cra/Services/TidyDownloadsService.swiftnew file mode 100644index 0000000..c2c0af2--- /dev/null+++ b/Sources/Cra/Services/TidyDownloadsService.swift@@ -0,0 +1,126 @@+import AppKit+import Foundation+import Observation+#if canImport(FoundationModels)+import FoundationModels+#endif++/// Tidy Downloads on the Mac's Apple Intelligence model (Arc Max's renameDownloads): a finished+/// download gets a readable name from its file name, the tab it came from and the site, and the+/// file on disk is renamed. The sidebar's card above the download bin says so ("Download renamed+/// to:", Arc's SidebarBanner) with a way back; reverting says "Download name reverted!" in Cra's toast.+@MainActor @Observable+final class TidyDownloadsService {+ static let shared = TidyDownloadsService()++ /// A rename the card shows: the file's path before and after, and the window it downloaded in.+ struct Rename: Equatable, Identifiable {+ let id = UUID()+ var download: UInt32+ var window: UUID+ var oldPath: String+ var newPath: String+ var oldName: String { (oldPath as NSString).lastPathComponent }+ var newName: String { (newPath as NSString).lastPathComponent }+ }++ /// The card on screen, if any.+ private(set) var card: Rename?++ /// Arc 1.171 (27 Oct 2026): the card leaves 8 s after it comes in.+ static let cardShown: TimeInterval = 8++ /// The tab a download started from: its title and address, for the prompt.+ @ObservationIgnored private var sources: [UInt32: (title: String, url: String)] = [:]+ @ObservationIgnored private var asked: Set<UInt32> = []++ private init() {}++ func noteSource(_ id: UInt32, title: String, url: String) {+ if sources[id] == nil { sources[id] = (title, url) }+ }++ /// A download finished at `path`. Rename it if the setting is on and the model can run; `moved`+ /// tells the window the file's new path.+ func finished(_ id: UInt32, path: String, downloadURL: String, window: UUID, store: SidebarStore,+ moved: @escaping (String) -> Void) {+ guard store.settings.tidyDownloads, TidyTabsService.shared.modelAvailable, !asked.contains(id), !path.isEmpty else { return }+ asked.insert(id)+ let source = sources.removeValue(forKey: id)+ let original = (path as NSString).lastPathComponent+ let prompt = TidyDownloads.prompt(file: original, tabTitle: source?.title ?? "", url: source?.url ?? downloadURL)+ Task { @MainActor in+ guard let answer = await Self.ask(prompt), let name = TidyDownloads.clean(answer, original: original) else { return }+ let folder = (path as NSString).deletingLastPathComponent+ let fm = FileManager.default+ let free = TidyDownloads.unique(name) { fm.fileExists(atPath: (folder as NSString).appendingPathComponent($0)) }+ let newPath = (folder as NSString).appendingPathComponent(free)+ guard fm.fileExists(atPath: path), (try? fm.moveItem(atPath: path, toPath: newPath)) != nil else {+ CraLog.note("Tidy Downloads: the file couldn't be renamed")+ return+ }+ DownloadHistory.shared.move(from: path, to: newPath)+ moved(newPath)+ CraLog.note("Tidy Downloads: renamed a download (\(original.count) → \(free.count) characters)")+ show(Rename(download: id, window: window, oldPath: path, newPath: newPath))+ }+ }++ private func show(_ r: Rename) {+ card = r+ DispatchQueue.main.asyncAfter(deadline: .now() + Self.cardShown) { [weak self] in+ if self?.card?.id == r.id { self?.card = nil }+ }+ }++ func dismiss() { card = nil }++ /// Arc's "Revert to original name": the file takes its old name back (or the next free one).+ func revert(_ r: Rename, moved: (String, String) -> Void) -> Bool {+ card = nil+ let fm = FileManager.default+ guard fm.fileExists(atPath: r.newPath) else { return false }+ let folder = (r.oldPath as NSString).deletingLastPathComponent+ let free = TidyDownloads.unique(r.oldName) { fm.fileExists(atPath: (folder as NSString).appendingPathComponent($0)) }+ let back = (folder as NSString).appendingPathComponent(free)+ guard (try? fm.moveItem(atPath: r.newPath, toPath: back)) != nil else { return false }+ DownloadHistory.shared.move(from: r.newPath, to: back)+ moved(r.newPath, back)+ return true+ }++ private static func ask(_ prompt: String) async -> String? {+ if TidyTabsService.fakeModel {+ // Test copies without Apple Intelligence: the file's name tidied by hand.+ guard let line = prompt.split(separator: "\n").last, let q = line.range(of: "Rename: '") else { return nil }+ let file = line[q.upperBound...].prefix { $0 != "'" }+ let ext = (String(file) as NSString).pathExtension+ let stem = (String(file) as NSString).deletingPathExtension+ .replacingOccurrences(of: "_", with: " ").replacingOccurrences(of: "-", with: " ")+ .filter { !$0.isNumber }.split(separator: " ").joined(separator: " ").capitalized+ return ext.isEmpty ? stem : "\(stem).\(ext)"+ }+ #if canImport(FoundationModels)+ if #available(macOS 26.0, *) {+ do {+ let session = LanguageModelSession(instructions: TidyDownloads.instructions)+ let r = try await session.respond(to: prompt, generating: TidyDownloadAnswer.self, options: GenerationOptions(sampling: .greedy))+ return r.content.name+ } catch {+ CraLog.note("Tidy Downloads: the model failed: \(error)")+ return nil+ }+ }+ #endif+ return nil+ }+}++#if canImport(FoundationModels)+@available(macOS 26.0, *)+@Generable+struct TidyDownloadAnswer {+ @Guide(description: "The file's new name, with its extension")+ var name: String+}+#endifdiff --git a/Sources/Cra/UI/Settings/MaxPane.swift b/Sources/Cra/UI/Settings/MaxPane.swiftindex c08d2dd..f751c6e 100644--- a/Sources/Cra/UI/Settings/MaxPane.swift+++ b/Sources/Cra/UI/Settings/MaxPane.swift@@ -25,6 +25,12 @@ struct MaxPane: View {} description: {Text("Have your tabs automatically renamed with tidier, shorter titles when you Pin them.")}+ SettingsCardDivider()+ MaxFeatureRow(title: "Tidy Downloads", isOn: $store.settings.tidyDownloads, enabled: available) {+ TidyDownloadsPicture()+ } description: {+ Text("Keep your many files more organized with smartly renamed downloads — and make them a little easier to find later.")+ }}MaxFooter(status: service.status) { service.openSystemSettings() }.padding(.top, 14)@@ -117,6 +123,29 @@ private struct MaxFooter: View {}}+/// Arc's Tidy Downloads picture: the "Download renamed to:" card on blue.+private struct TidyDownloadsPicture: View {+ private let grey = Color(white: 0.55)+ var body: some View {+ ZStack {+ Color(red: 0.16, green: 0.20, blue: 0.93)+ VStack(alignment: .leading, spacing: 1) {+ HStack(spacing: 3) {+ Text("Download renamed to:").font(.system(size: 4)).foregroundStyle(grey).lineLimit(1).fixedSize()+ Spacer(minLength: 0)+ Image(systemName: "arrow.uturn.backward").font(.system(size: 4.5, weight: .semibold)).foregroundStyle(grey)+ Image(systemName: "xmark").font(.system(size: 4.5, weight: .semibold)).foregroundStyle(grey)+ }+ Text("Navan Itinerary.pdf").font(.system(size: 6, weight: .medium)).foregroundStyle(.black).lineLimit(1).fixedSize()+ Text("387494875.pdf").font(.system(size: 4.5)).strikethrough().foregroundStyle(grey).lineLimit(1).fixedSize()+ }+ .padding(.horizontal, 5).padding(.vertical, 4)+ .frame(width: 70)+ .background(RoundedRectangle(cornerRadius: 4, style: .continuous).fill(Color.white))+ }+ }+}+/// Arc's Tidy Tab Titles picture: a renamed tab, "Double-click to rename" under it, sparkles round/// it, on mauve.private struct TidyTabTitlesPicture: View {diff --git a/Sources/Cra/UI/Sidebar/DownloadRenameCard.swift b/Sources/Cra/UI/Sidebar/DownloadRenameCard.swiftnew file mode 100644index 0000000..a9c4a30--- /dev/null+++ b/Sources/Cra/UI/Sidebar/DownloadRenameCard.swift@@ -0,0 +1,223 @@+import AppKit++/// Arc's Tidy Downloads card (SidebarBanner, "Download renamed to:"), over the sidebar's foot with+/// its tail on the download bin. Measured on Arc 1.171, 4 Nov 2026 (60 fps, a dark space, 347 pt+/// sidebar): 8 pt from either side, 65 pt tall plus a 9 pt tail; "Download renamed to:" 12 pt in+/// blue, the new name 14 pt semibold, the old name 12 pt in blue, struck through; revert ↶ and close+/// ✕ at the top right; four-point sparkles twinkling round it. It springs out of the bin (0.55× to+/// 1.05× at 0.29 s, settled by 0.55 s), the strike draws in 0.5 s later over 0.15 s, and it shrinks+/// back into the bin in 0.12 s after 8 s.+final class DownloadRenameCard: NSView {+ static let bodyHeight: CGFloat = 65+ static let tail: CGFloat = 9+ static var height: CGFloat { bodyHeight + tail }++ let rename: TidyDownloadsService.Rename+ var onRevert: () -> Void = {}+ var onClose: () -> Void = {}+ var onOpen: () -> Void = {}+ /// Where the tail points, in the card's coordinates (the bin's top centre).+ var tailX: CGFloat = 33 { didSet { needsLayout = true } }++ private let shape = CAShapeLayer()+ private let label = NSTextField.sidebarLabel(size: 12)+ private let newName = NSTextField.sidebarLabel(size: 14, weight: .semibold)+ private let oldName = NSTextField.sidebarLabel(size: 12)+ private let strike = CAShapeLayer()+ private let sparkles = CALayer()+ private var revert: SidebarGlyphButton!+ private var close: SidebarGlyphButton!+ private var dark: Bool++ init(rename: TidyDownloadsService.Rename, colors: SidebarColors) {+ self.rename = rename+ dark = colors.isDark+ super.init(frame: .zero)+ wantsLayer = true+ layer?.addSublayer(shape)+ label.stringValue = "Download renamed to:"+ newName.stringValue = rename.newName+ oldName.stringValue = rename.oldName+ for l in [label, newName, oldName] { addSubview(l) }+ oldName.wantsLayer = true+ strike.fillColor = nil+ strike.lineWidth = 1+ strike.strokeEnd = 0+ strike.actions = ["strokeEnd": NSNull(), "path": NSNull()]+ layer?.addSublayer(strike)+ layer?.addSublayer(sparkles)+ revert = SidebarGlyphButton(symbol: "arrow.uturn.backward", size: 26, iconSize: 13, weight: .medium,+ help: "Revert to original name", colors: colors) { [weak self] in self?.onRevert() }+ close = SidebarGlyphButton(symbol: "xmark", size: 26, iconSize: 13, help: "", colors: colors) { [weak self] in self?.onClose() }+ close.setCloseMark(minus: false, help: "Close")+ addSubview(revert)+ addSubview(close)+ setAccessibilityElement(true)+ setAccessibilityRole(.button)+ setAccessibilityLabel("Download renamed to:, \(rename.newName), \(rename.oldName)")+ style()+ }++ required init?(coder: NSCoder) { fatalError() }++ override var isFlipped: Bool { true }++ /// Arc drew it navy on a dark space; a light space's card is white (Arc's Max picture), not measured.+ private func style() {+ let blue = NSColor(srgbRed: 0x34 / 255, green: 0x3B / 255, blue: 0xD1 / 255, alpha: 1)+ shape.fillColor = (dark ? NSColor(srgbRed: 0x03 / 255, green: 0x06 / 255, blue: 0x1F / 255, alpha: 1) : .white).cgColor+ shape.shadowColor = NSColor.black.cgColor+ shape.shadowOpacity = dark ? 0 : 0.12+ shape.shadowRadius = 6+ shape.shadowOffset = CGSize(width: 0, height: -1)+ label.textColor = blue+ oldName.textColor = blue+ strike.strokeColor = blue.cgColor+ newName.textColor = dark ? NSColor(white: 0.94, alpha: 1) : .black+ for b in [revert, close] { b?.tint = NSColor(white: dark ? 0.55 : 0.5, alpha: 1) }+ }++ override func layout() {+ super.layout()+ let w = bounds.width, body = Self.bodyHeight+ let p = CGMutablePath()+ p.addRoundedRect(in: CGRect(x: 0, y: 0, width: w, height: body), cornerWidth: 12, cornerHeight: 12)+ let tx = min(max(tailX, 16), w - 16)+ p.move(to: CGPoint(x: tx - 7, y: body - 0.5))+ p.addLine(to: CGPoint(x: tx, y: body + Self.tail))+ p.addLine(to: CGPoint(x: tx + 7, y: body - 0.5))+ p.closeSubpath()+ shape.path = p+ shape.frame = bounds+ // Text 13 pt in; cap tops 12.5, 31 and 50 pt down (Arc).+ // The label stops short of ↶; the names may run to the card's right padding.+ func place(_ l: NSTextField, capTop: CGFloat, right: CGFloat) {+ let f = l.font ?? .systemFont(ofSize: 12)+ let top = capTop - (f.ascender - f.capHeight) - 1+ l.frame = NSRect(x: 13 - SidebarText.inset, y: top, width: max(0, w - 13 - right) + 2 * SidebarText.inset,+ height: l.intrinsicContentSize.height)+ }+ place(label, capTop: 12.5, right: 64)+ place(newName, capTop: 31, right: 13)+ place(oldName, capTop: 50, right: 13)+ // ↶ and ✕ centred 47 and 21 pt in from the right, 17 pt down.+ close.frame = NSRect(x: w - 21 - 13, y: 17 - 13, width: 26, height: 26)+ revert.frame = NSRect(x: w - 47 - 13, y: 17 - 13, width: 26, height: 26)+ // The strike runs through the old name's lower-case middle.+ let f = oldName.font ?? .systemFont(ofSize: 12)+ let ink = (oldName.stringValue as NSString).size(withAttributes: [.font: f]).width+ let midY = 50 + f.capHeight - f.xHeight / 2+ let line = CGMutablePath()+ line.move(to: CGPoint(x: 13, y: midY))+ line.addLine(to: CGPoint(x: 13 + ink, y: midY))+ strike.path = line+ strike.frame = bounds+ sparkles.frame = bounds+ if sparkles.sublayers == nil { addSparkles() }+ }++ /// Four-point stars where Arc had them: by the label, after the new name, at the old name's end,+ /// at the bottom left, each breathing on its own beat.+ private func addSparkles() {+ let w = bounds.width+ let spots: [(CGPoint, CGFloat, Float)] = [+ (CGPoint(x: 92, y: 9), 5, 0.6), (CGPoint(x: min(w - 70, 205), y: 30), 4, 0.5),+ (CGPoint(x: 168, y: 57), 10, 0.8), (CGPoint(x: 13, y: 60), 8, 0.6), (CGPoint(x: 68, y: 44), 4, 0.45),+ ]+ for (i, (c, size, peak)) in spots.enumerated() {+ let star = CAShapeLayer()+ star.path = Self.star(size: size)+ star.bounds = CGRect(x: 0, y: 0, width: size, height: size)+ star.position = c+ star.fillColor = NSColor(white: dark ? 0.85 : 0.6, alpha: 1).cgColor+ star.opacity = 0+ let twinkle = CAKeyframeAnimation(keyPath: "opacity")+ twinkle.values = [0, peak, peak * 0.35, peak]+ twinkle.keyTimes = [0, 0.3, 0.65, 1]+ twinkle.duration = 1.4 + Double(i) * 0.23+ twinkle.autoreverses = true+ twinkle.repeatCount = .infinity+ twinkle.beginTime = CACurrentMediaTime() + 0.1 * Double(i)+ twinkle.fillMode = .both+ star.add(twinkle, forKey: "twinkle")+ sparkles.addSublayer(star)+ }+ }++ private static func star(size s: CGFloat) -> CGPath {+ let p = CGMutablePath(), c = s / 2, k = s * 0.12+ p.move(to: CGPoint(x: c, y: 0))+ p.addQuadCurve(to: CGPoint(x: s, y: c), control: CGPoint(x: c + k, y: c - k))+ p.addQuadCurve(to: CGPoint(x: c, y: s), control: CGPoint(x: c + k, y: c + k))+ p.addQuadCurve(to: CGPoint(x: 0, y: c), control: CGPoint(x: c - k, y: c + k))+ p.addQuadCurve(to: CGPoint(x: c, y: 0), control: CGPoint(x: c - k, y: c - k))+ return p+ }++ /// The tail's tip, where the card grows from and goes back to. The sidebar's layers run top+ /// down (flipped superview), so the tip is the layer's bottom edge at y 1.+ private func anchorOnTail() {+ guard let layer else { return }+ let f = frame+ let ax = tailX / max(1, f.width)+ layer.anchorPoint = CGPoint(x: ax, y: 1)+ layer.position = CGPoint(x: f.minX + ax * f.width, y: f.maxY)+ }++ func appear() {+ layoutSubtreeIfNeeded()+ anchorOnTail()+ let spring = CASpringAnimation(keyPath: "transform.scale")+ spring.fromValue = 0.55+ spring.toValue = 1+ spring.mass = 1+ spring.stiffness = 162+ spring.damping = 14.4+ spring.duration = spring.settlingDuration+ layer?.add(spring, forKey: "in")+ let fade = CABasicAnimation(keyPath: "opacity")+ fade.fromValue = 0+ fade.toValue = 1+ fade.duration = 0.1+ layer?.add(fade, forKey: "fadeIn")+ let draw = CABasicAnimation(keyPath: "strokeEnd")+ draw.fromValue = 0+ draw.toValue = 1+ draw.beginTime = CACurrentMediaTime() + 0.5+ draw.duration = 0.15+ draw.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)+ draw.fillMode = .backwards+ strike.strokeEnd = 1+ strike.add(draw, forKey: "draw")+ }++ func disappear(then done: @escaping () -> Void) {+ anchorOnTail()+ CATransaction.begin()+ CATransaction.setCompletionBlock(done)+ let shrink = CABasicAnimation(keyPath: "transform.scale")+ shrink.toValue = 0.55+ let fade = CABasicAnimation(keyPath: "opacity")+ fade.toValue = 0+ let g = CAAnimationGroup()+ g.animations = [shrink, fade]+ g.duration = 0.12+ g.timingFunction = CAMediaTimingFunction(name: .easeIn)+ g.fillMode = .forwards+ g.isRemovedOnCompletion = false+ layer?.add(g, forKey: "out")+ CATransaction.commit()+ }++ override var mouseDownCanMoveWindow: Bool { false }+ override func mouseDown(with event: NSEvent) {}+ override func mouseUp(with event: NSEvent) {+ let p = convert(event.locationInWindow, from: nil)+ if p.y <= Self.bodyHeight, bounds.contains(p) { onOpen() }+ }+ override func hitTest(_ point: NSPoint) -> NSView? {+ let p = convert(point, from: superview)+ guard p.y >= 0, p.y <= Self.bodyHeight, p.x >= 0, p.x <= bounds.width else { return nil }+ return super.hitTest(point) ?? self+ }+}diff --git a/Sources/Cra/UI/Sidebar/List/SidebarView.swift b/Sources/Cra/UI/Sidebar/List/SidebarView.swiftindex 71db5e5..c5da62c 100644--- a/Sources/Cra/UI/Sidebar/List/SidebarView.swift+++ b/Sources/Cra/UI/Sidebar/List/SidebarView.swift@@ -44,6 +44,56 @@ final class SidebarView: NSView {player.onCountChange = { [weak self] in self?.needsLayout = true }ui.observeLibraryReveal { [weak self] in self?.applyLibraryReveal() }observe()+ observeRenameCard()+ }++ // MARK: Tidy Downloads' card++ private var renameCard: DownloadRenameCard?++ /// The card for a download this window renamed: in over the bin, out after 8 s or a click.+ private func observeRenameCard() {+ let window = ui.windowID+ observeChanges(of: { TidyDownloadsService.shared.card.flatMap { $0.window == window ? $0 : nil } }) { [weak self] card in+ self?.showRenameCard(card)+ }+ }++ private func showRenameCard(_ mine: TidyDownloadsService.Rename?) {+ guard mine?.id != renameCard?.rename.id else { return }+ if let old = renameCard {+ renameCard = nil+ old.disappear { old.removeFromSuperview() }+ }+ guard let r = mine else { return }+ let v = DownloadRenameCard(rename: r, colors: SidebarColors(palette))+ let service = TidyDownloadsService.shared+ let toast = actions.showToast+ let ui = self.ui+ v.onClose = { service.dismiss() }+ v.onOpen = { NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: r.newPath)]) }+ v.onRevert = {+ let ok = service.revert(r) { _, back in+ if var recent = ui.recentDownload, recent.id == r.download {+ recent.path = back+ ui.recentDownload = recent+ }+ }+ if ok { toast("Download name reverted!") }+ }+ tabs.addSubview(v)+ renameCard = v+ layoutRenameCard()+ v.appear()+ }++ private func layoutRenameCard() {+ guard let v = renameCard, let anchor = ui.libraryAnchor as? LibraryButtonView else { return }+ let bin = anchor.convert(anchor.binFrame, to: tabs)+ // Arc: the tail's tip ends 1 pt above the bin's 38 pt box, ~4 pt above its 32 pt thumbnail.+ let w = tabs.bounds.width - 16+ v.frame = NSRect(x: 8, y: bin.minY - 4 - DownloadRenameCard.height, width: w, height: DownloadRenameCard.height)+ v.tailX = bin.midX - 8}required init?(coder: NSCoder) { fatalError() }@@ -218,6 +268,7 @@ final class SidebarView: NSView {let trayH = DownloadsTrayMetrics.listHeight(rows: rows) + 4trayHost.frame = NSRect(x: 0, y: pager.frame.maxY - trayH, width: b.width, height: trayH)updateTrayMask(open: ui.downloadsListOpen, rows: rows)+ if renameCard?.layer?.animationKeys()?.isEmpty ?? true { layoutRenameCard() }}}@@ -980,6 +1031,8 @@ final class LibraryButtonView: NSView {private var hovering = false { didSet { if hovering != oldValue { refresh() } } }var colors = SidebarColors() { didSet { if colors != oldValue { glyph.image = LibraryGlyph.image(dark: colors.isDark); refresh() } } }static let binOffset = CGSize(width: 9, height: -12)+ /// The download bin's frame, for Tidy Downloads' card to point at.+ var binFrame: NSRect { bin.frame }init(ui: SidebarUIState, actions: SidebarActions) {self.ui = uidiff --git a/Sources/Cra/UI/SidebarUIState.swift b/Sources/Cra/UI/SidebarUIState.swiftindex 9e155f0..fe5afd0 100644--- a/Sources/Cra/UI/SidebarUIState.swift+++ b/Sources/Cra/UI/SidebarUIState.swift@@ -207,6 +207,8 @@ final class SidebarActions {var separatePinnedTab: (UUID) -> Void = { _ in }var editPinnedURL: (UUID) -> Void = { _ in }var openURL: (String) -> Void = { _ in }+ /// Cra's one toast (ShinyToast) in this window.+ var showToast: (String) -> Void = { _ in }var performAction: (String) -> Void = { _ in }/// Double-click on an empty part of the header strip (sidebar title row or toolbar).var titleBarDoubleClick: () -> Void = {}diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex 73b5581..ddacd31 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -269,6 +269,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMsidebarActions.resetPinnedTab = { [weak self] id in self?.resetPinnedTab(id) }sidebarActions.separatePinnedTab = { [weak self] id in self?.separatePinnedTab(id) }sidebarActions.editPinnedURL = { [weak self] id in self?.editPinnedURL(id) }+ sidebarActions.showToast = { [weak self] text in self?.showToast(text) }sidebarActions.openURL = { [weak self] url inguard let self else { return }self.store.createTab(url: url, window: self.windowID)@@ -595,6 +596,9 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMfunc browserManager(download: CraDownloadInfo) {let name = (download.fullPath as NSString).lastPathComponent.isEmpty ? download.suggestedName : (download.fullPath as NSString).lastPathComponent+ if let tab = browsers.downloadSourceTab, let item = store.item(tab), let t = item.tab {+ TidyDownloadsService.shared.noteSource(download.identifier, title: item.displayTitle, url: t.url)+ }if windowDownloads.insert(download.identifier).inserted {ChromeDownloadAnimation.suppress()showDownloadInSidebar(download, name: name)@@ -606,6 +610,12 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMupdateRecentDownload(download)if download.state == .complete, !download.fullPath.isEmpty, finishedDownloads.insert(download.identifier).inserted {DownloadHistory.shared.add(path: download.fullPath)+ let id = download.identifier+ TidyDownloadsService.shared.finished(id, path: download.fullPath, downloadURL: download.url, window: windowID, store: store) { [weak self] path in+ guard let self, var recent = self.sidebarUI.recentDownload, recent.id == id else { return }+ recent.path = path+ self.sidebarUI.recentDownload = recent+ }}if download.state == .inProgress, downloadWatchdog == nil {downloadWatchdog = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { [weak self] _ indiff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex 2b7cd7b..2e52923 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -1849,13 +1849,10 @@ iconOffsetXAnimator, iconBounceAnimator, lazy g / vx0 / vy0 / projectileMotionDu6 pt high, drops to 12 pt low at ~0.15 s, back to −2 pt, settled by ~0.4 s. Faint grey while Arc's window is inthe background, white when it is key. It leaves 30 s after the glyph lands (appeared 8.47 s, faded 39.37-39.53 sin a 60 fps capture), fading over 0.15 s, the same with Arc in front or behind.-- With Tidy Downloads on, Arc also shows a "Download renamed to:" card above the bin; Cra has no Tidy Downloads.+- With Tidy Downloads on, Arc also shows a "Download renamed to:" card above the bin (see "Tidy Downloads").- Cra: DownloadFlight (overlay panel, Core Animation keyframes sampled from the same projectile) and DownloadBin inSpaceDock. Verified side by side with fixed-source test builds.-- Tidy Downloads card (only with Arc Max's renaming): in over ~0.2 s once the rename is ready, gone after 8.0 s in- under 0.1 s. Prompt and inputs (filename, tab title, domain; JSON `newName`) are in the binary next to- beginRename(browserContextID:downloadID:defaultFilename:sourceUrl:webContentsTitle:referrerTitle:). Not built in- Cra: Victor doesn't want AI features for now (27 Oct 2026).+- Tidy Downloads card (only with Arc Max's renaming): see "Tidy Downloads" below (built 4 Nov 2026).### Arc's downloads list on hovering the Library button (live, 60 fps, 1728×1084 window)@@ -3095,3 +3092,29 @@ Titles (`renamePinnedTabsEnabled`, AI endpoint `renamePinnedTabs`) gives a tab aopt-in).- [?] Not seen: whether a drag into Pinned renames (Cra does, every pin counts), a rename whose new name isn't aprefix of the old (Cra crossfades in the soft edge), undo.++## Tidy Downloads (Arc 1.171, 4 Nov 2026, strings + Victor's Arc, 60 fps recordings)++Arc Max's renameDownloads: a finished download is renamed on disk and a card above the download bin says so.+- [O static] beginRename(browserContextID:downloadID:defaultFilename:sourceUrl:webContentsTitle:referrerTitle:) sends+ the file name, the source tab's title and domain with a prompt ("Rewrite its filename to be helpful, concise and+ readable. 2-4 words." plus rules and nine examples) and reads JSON `newName`; it refuses an empty name or one+ starting with ".". The card is SidebarBanner's ("Download renamed to:", "Revert to original name"); the toasts+ "Download renamed!" / "Download name reverted!" are DownloadRenamedToastContentView in Arc's toast.+- [O] Live, three GitHub zips from their repo pages: Hello-World-master.zip → "Hello World Repository.zip",+ Spoon-Knife-main.zip → "Spoon Knife main.zip", git-consortium-master.zip → "Git Consortium Master.zip" (renamed+ on disk). A second download from the same tab didn't start (Chrome's multiple-download block).+- [O] Card (dark space, 347 pt sidebar, AX + 2x frames): a button 331 × 74 pt at x 8 (the sidebar less 8 pt a side),+ body 65 pt with 12 pt corners plus a 9 pt tail at bottom left whose tip ends 1 pt above the bin. Fill #03061F;+ "Download renamed to:" 12 pt regular #343BD1, 13 pt in, cap top 12.5 pt down; the new name 14 pt semibold white,+ cap top 31; the old name 12 pt #343BD1, cap top 50, struck through; ↶ and ✕ grey glyphs centred 47 and 21 pt from+ the right, 17 pt down; four-point sparkles (5–10 pt) twinkling by the label, the names and the bottom left.+- [O] Timeline: the card comes ~2.6 s after the download starts (with a small zip), springing from the tail's tip:+ 0.55× → 1.0 in 0.18 s, 1.05× at 0.29 s, settled by ~0.55 s, fading in over ~0.1 s; the strike draws left to right+ 0.5 s in, over ~0.15 s. It leaves 7.96 s after it came, shrinking back to the tip and fading in ~0.12 s.+ ↶ renamed the file back at once (git-consortium-master.zip). Not captured: the reverted toast (Cra shows+ "Download name reverted!" in its one toast), the card in a light space (Cra: white, from Arc's Max picture), and+ whether hovering holds it.+- Cra: TidyDownloads (CraCore: prompt with Cra's own examples, the name's checks, a free name), TidyDownloadsService+ (FoundationModels, renames the file, DownloadHistory.move, revert), DownloadRenameCard (SidebarView, over the bin).+ Settings ▸ Max ▸ Tidy Downloads, off by default.diff --git a/docs/development.md b/docs/development.mdindex 1f417db..a5ce160 100644--- a/docs/development.md+++ b/docs/development.md@@ -157,7 +157,8 @@ Measure them with `sample <pid> 6 1` and compare the main thread's busy time betTidy Tabs needs Apple Intelligence. `CRA_TIDY_FAKE_MODEL=1` stands in a model that groups bysite (after a 1.6 s pause), so a test instance on any Mac shows the button, the squiggle and the-groups, and Tidy Tab Titles names a pinned tab after its title's first part; `CRA_TIDY_FAKE_MODEL=off` (or `preparing`, `ineligible`) shows Settings ▸ Max as a Mac+groups, Tidy Tab Titles names a pinned tab after its title's first part and Tidy Downloads tidies a+download's file name by hand; `CRA_TIDY_FAKE_MODEL=off` (or `preparing`, `ineligible`) shows Settings ▸ Max as a Macwithout Apple Intelligence would. `cra://debug?tidy=1` runs Tidy on the window's space withouthovering the divider, `cra://debug?undoTidy=1` is ⌘Z's undo and `cra://debug?settingsPane=max`opens Settings on a pane.