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.
Import Dia 1.55's sidebar from its encrypted tabs.db (#79)
Victor Kildahlf8e486159157
diff --git a/Sources/Cra/Services/Import/ChromiumImporter.swift b/Sources/Cra/Services/Import/ChromiumImporter.swiftindex cf73ae9..6478bf5 100644--- a/Sources/Cra/Services/Import/ChromiumImporter.swift+++ b/Sources/Cra/Services/Import/ChromiumImporter.swift@@ -210,6 +210,12 @@ enum ChromiumImporter {guard let secret = ChromiumCrypto.keychainSecret(service: keychainService, account: keychainAccount) else {throw CredentialImportError.keychainDenied(browser)}+ return try credentials(browser: browser, profiles: profiles, secret: secret, cookies: cookies, passwords: passwords)+ }++ /// The same with a secret already read (Dia's sidebar needs it too: one prompt for both).+ static func credentials(browser: String, profiles: [ChromiumProfile], secret: String,+ cookies: Bool, passwords: Bool) throws -> ImportedCredentials {let key = ChromiumCrypto.key(fromSecret: secret)var out = ImportedCredentials()var readAny = falsediff --git a/Sources/Cra/Services/Import/DiaSidebar.swift b/Sources/Cra/Services/Import/DiaSidebar.swiftnew file mode 100644index 0000000..4c018ec--- /dev/null+++ b/Sources/Cra/Services/Import/DiaSidebar.swift@@ -0,0 +1,179 @@+import CommonCrypto+import CryptoKit+import Foundation++// Dia 1.55 keeps its sidebar (spaces, per-space favorites, pinned tabs and folders, open tabs)+// in User Data/<profile>/tabs.db, a SQLCipher 4 database with a raw key derived from the+// "Dia Safe Storage" secret (see docs/arc-reverse-engineering.md, "Dia 1.55 sidebar store").+// StorableProfileContainers.json and the bookmarks bar stopped following the sidebar then.++enum DiaSidebar {+ /// The HMAC key of Dia's DatabaseEncryptionKeyDerivationFunction, from its binary.+ private static let saltKey = Data(base64Encoded: "iOe1Ue/XtonbieE/5m1nAgewvWQlePHRcKnoU10EyOM=")!+ /// SQLCipher 4 defaults: 4096-byte pages ending in a 16-byte IV and a 64-byte HMAC-SHA512.+ private static let pageSize = 4096, reserve = 80++ /// The profiles' tabs.db files, in profile folder order.+ static func databases(userData: URL) -> [(profile: String, url: URL)] {+ let names = (try? FileManager.default.contentsOfDirectory(atPath: userData.path)) ?? []+ return names.filter { $0 == "Default" || $0.hasPrefix("Profile ") }.sorted().compactMap { name in+ let url = userData.appendingPathComponent(name).appendingPathComponent("tabs.db")+ return FileManager.default.fileExists(atPath: url.path) ? (name, url) : nil+ }+ }++ /// HKDF-SHA256 of Chromium's Safe Storage key, salted with HMAC-SHA256(saltKey, label);+ /// the label is "profile/<profile folder>/<database name>" (Dia's DatabaseController).+ static func key(rootKey: Data, label: String) -> Data {+ let info = Data(label.utf8)+ let salt = Data(HMAC<SHA256>.authenticationCode(for: info, using: SymmetricKey(data: saltKey)))+ let key = HKDF<SHA256>.deriveKey(inputKeyMaterial: SymmetricKey(data: rootKey), salt: salt, info: info, outputByteCount: 32)+ return key.withUnsafeBytes { Data($0) }+ }++ /// The database as plain SQLite, with the committed frames of its -wal folded in (Dia+ /// keeps the file open, so recent edits are often only there). Nil for a wrong key.+ static func decrypt(_ url: URL, key: Data) -> Data? {+ guard let file = try? Data(contentsOf: url), file.count >= pageSize, file.count % pageSize == 0 else { return nil }+ var pages: [Int: Data] = [:]+ var count = file.count / pageSize+ for i in 0..<count { pages[i + 1] = file.subdata(in: i * pageSize..<(i + 1) * pageSize) }+ if let wal = try? Data(contentsOf: URL(fileURLWithPath: url.path + "-wal")), wal.count > 32, be32(wal, 8) == pageSize {+ // Frames from an older generation of the log carry another salt; frames after+ // the last commit belong to an unfinished transaction.+ let salt = wal.subdata(in: 16..<24)+ var pending: [Int: Data] = [:]+ var off = 32+ while off + 24 + pageSize <= wal.count, wal.subdata(in: off + 8..<off + 16) == salt {+ pending[be32(wal, off)] = wal.subdata(in: off + 24..<off + 24 + pageSize)+ let commit = be32(wal, off + 4)+ if commit > 0 { pages.merge(pending) { $1 }; pending = [:]; count = commit }+ off += 24 + pageSize+ }+ }+ // A damaged log can claim more pages than exist.+ guard count >= 1, count <= pages.count else { return nil }+ var out = Data(capacity: count * pageSize)+ for n in 1...count {+ guard let page = pages[n], let plain = decryptPage(page, first: n == 1, key: key) else { return nil }+ out.append(plain)+ }+ // A right key turns page 1 into SQLite's header: page size 4096, payload fractions 64/32/32.+ guard out[16] == 0x10, out[17] == 0, out[21] == 64, out[22] == 32, out[23] == 32 else { return nil }+ return out+ }++ private static func decryptPage(_ page: Data, first: Bool, key: Data) -> Data? {+ let start = first ? 16 : 0 // page 1 begins with the KDF salt instead of "SQLite format 3"+ let body = page.subdata(in: start..<pageSize - reserve), iv = page.subdata(in: pageSize - reserve..<pageSize - reserve + 16)+ var plain = Data(count: body.count)+ var moved = 0+ let status = plain.withUnsafeMutableBytes { out in body.withUnsafeBytes { inp in key.withUnsafeBytes { k in iv.withUnsafeBytes { v in+ CCCrypt(CCOperation(kCCDecrypt), CCAlgorithm(kCCAlgorithmAES), 0, k.baseAddress, key.count, v.baseAddress,+ inp.baseAddress, body.count, out.baseAddress, body.count, &moved)+ } } } }+ guard status == kCCSuccess, moved == body.count else { return nil }+ return (first ? Data("SQLite format 3\0".utf8) : Data()) + plain + Data(count: reserve)+ }++ private static func be32(_ d: Data, _ i: Int) -> Int {+ d.subdata(in: i..<i + 4).reduce(0) { $0 << 8 | Int($1) }+ }++ // MARK: Reading the sidebar++ /// Every profile's spaces; empty when no database opens with the key.+ static func spaces(userData: URL, rootKey: Data) -> [ImportedSpace] {+ databases(userData: userData).flatMap { db -> [ImportedSpace] in+ guard let plain = decrypt(db.url, key: key(rootKey: rootKey, label: "profile/\(db.profile)/tabs")) else {+ CraLog.note("Dia import: \(db.profile)/tabs.db did not decrypt")+ return []+ }+ let tmp = FileManager.default.temporaryDirectory.appendingPathComponent("cra-dia-\(UUID().uuidString).db")+ defer { try? FileManager.default.removeItem(at: tmp) }+ // Readable by the user only while it exists: it holds the decrypted tab list.+ guard FileManager.default.createFile(atPath: tmp.path, contents: plain, attributes: [.posixPermissions: 0o600]),+ let snapshot = SQLiteSnapshot(copying: tmp) else {+ CraLog.note("Dia import: \(db.profile)/tabs.db could not be opened")+ return []+ }+ let found = spaces(in: snapshot)+ CraLog.note("Dia import: \(db.profile)/tabs.db has \(found.count) spaces")+ return found+ }+ }++ /// `nodes` is the tree: per space a `favorites` and a `pinned_container` node and one+ /// `window` node per window (its open tabs). A `tab` holds one `content_pane` (two or+ /// more in a split), a `group` is a folder.+ static func spaces(in db: SQLiteSnapshot) -> [ImportedSpace] {+ let nodes = db.rows("SELECT id, kind, entity_id, parent_id, space_id FROM nodes WHERE deleted_at IS NULL ORDER BY \"order\"")+ var children: [Int64: [[String: Any]]] = [:]+ for n in nodes { if let p = n["parent_id"] as? Int64 { children[p, default: []].append(n) } }+ func byID(_ sql: String) -> [String: [String: Any]] {+ Dictionary(db.rows(sql).compactMap { r in (r["id"] as? String).map { ($0, r) } }) { a, _ in a }+ }+ let groups = byID("SELECT id, title FROM tab_groups")+ let tabs = byID("SELECT id, creation_date FROM tabs")+ let panes = byID("SELECT p.id, p.custom_title, w.url, w.title FROM content_panes p JOIN web_contents w ON w.content_pane_id = p.id")++ func items(_ node: [String: Any], created: Date) -> [ImportedItem] {+ let id = node["entity_id"] as? String ?? ""+ let kids = (node["id"] as? Int64).flatMap { children[$0] } ?? []+ switch node["kind"] as? String {+ case "tab":+ let created = date(tabs[id]?["creation_date"]) ?? created+ return kids.flatMap { items($0, created: created) }+ case "content_pane":+ guard let p = panes[id], let url = p["url"] as? String, !url.isEmpty else { return [] }+ let custom = (p["custom_title"] as? String).flatMap { $0.isEmpty ? nil : $0 }+ return [ImportedItem(customTitle: custom, pageTitle: p["title"] as? String ?? "", url: url, createdAt: created)]+ case "group":+ let title = groups[id]?["title"] as? String ?? "Folder"+ return [ImportedItem(customTitle: title, pageTitle: title, url: nil, isFolder: true,+ children: kids.flatMap { items($0, created: created) }, createdAt: created)]+ default:+ return []+ }+ }+ func contents(of kind: String, in space: String) -> [ImportedItem] {+ nodes.filter { $0["kind"] as? String == kind && $0["space_id"] as? String == space }.flatMap { container in+ ((container["id"] as? Int64).flatMap { children[$0] } ?? []).flatMap { items($0, created: Date()) }+ }+ }++ return db.rows("SELECT id, title, theme FROM spaces ORDER BY creation_date").map { row in+ let id = row["id"] as? String ?? ""+ var space = ImportedSpace(title: row["title"] as? String ?? "Space", emoji: "🗂️", theme: theme(row["theme"] as? String))+ space.favorites = contents(of: "favorites", in: id)+ space.pinned = contents(of: "pinned_container", in: id)+ space.today = contents(of: "window", in: id)+ return space+ }+ }++ /// GRDB's text dates: "2026-10-14 07:32:24.443", UTC.+ private static func date(_ value: Any?) -> Date? {+ guard let s = value as? String else { return nil }+ let f = DateFormatter()+ f.locale = Locale(identifier: "en_US_POSIX")+ f.timeZone = TimeZone(identifier: "UTC")+ for format in ["yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss"] {+ f.dateFormat = format+ if let d = f.date(from: s) { return d }+ }+ return nil+ }++ /// Dia's space colours are names (neutral, red, orange, yellow, green, blue, pink, purple);+ /// neutral is Cra's default theme.+ static func theme(_ name: String?) -> SpaceTheme? {+ let colors: [String: [String]] = [+ "red": ["#F25C54", "#F7A399"], "orange": ["#F5913E", "#F9C48F"], "yellow": ["#F8D558", "#FBE79E"],+ "green": ["#5DBB63", "#A8DCA0"], "blue": ["#4A90E2", "#9CC3F0"], "pink": ["#F27BAA", "#F8B8D0"],+ "purple": ["#9B6FE0", "#C9B0F0"],+ ]+ guard let name, let pair = colors[name] else { return nil }+ return SpaceTheme(colors: pair, intensity: 0.5, noise: 0.15, appearance: "light", accent: pair[0])+ }+}diff --git a/Sources/Cra/Services/Import/Importers.swift b/Sources/Cra/Services/Import/Importers.swiftindex a564d6a..cc1d7ba 100644--- a/Sources/Cra/Services/Import/Importers.swift+++ b/Sources/Cra/Services/Import/Importers.swift@@ -265,15 +265,36 @@ enum ArcImporter {// MARK: - Diaenum DiaImporter {- static let supportDir = FileManager.default.homeDirectoryForCurrentUser- .appendingPathComponent("Library/Application Support/Dia", isDirectory: true)+ /// CRA_DIA_DIR points a test instance at a made-up profile (Tests/Fixtures/Dia).+ static let supportDir = ProcessInfo.processInfo.environment["CRA_DIA_DIR"].map { URL(fileURLWithPath: $0, isDirectory: true) }+ ?? FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Library/Application Support/Dia", isDirectory: true)+ static var userData: URL { supportDir.appendingPathComponent("User Data", isDirectory: true) }- static var isAvailable: Bool { FileManager.default.fileExists(atPath: supportDir.appendingPathComponent("StorableProfileContainers.json").path) }+ static var isAvailable: Bool {+ FileManager.default.fileExists(atPath: supportDir.appendingPathComponent("StorableProfileContainers.json").path) || hasEncryptedSidebar+ }- static func plan() throws -> ImportPlan {+ /// Dia 1.55 and later: the sidebar is in encrypted tabs.db files, read with the Keychain secret.+ static var hasEncryptedSidebar: Bool { !DiaSidebar.databases(userData: userData).isEmpty }++ /// With the "Dia Safe Storage" secret the spaces come from Dia's sidebar database; without+ /// it (or from an older Dia) from the files Dia kept before 1.55, which no longer follow+ /// the sidebar: the open tabs as of then and the bookmarks bar. A secret that opens no+ /// sidebar database throws rather than fall back to those stale files.+ static func plan(secret: String? = nil) throws -> ImportPlan {guard isAvailable else { throw ImportError.notFound("Dia") }var plan = ImportPlan(source: "Dia")+ if let secret, hasEncryptedSidebar {+ plan.spaces = DiaSidebar.spaces(userData: userData, rootKey: ChromiumCrypto.key(fromSecret: secret))+ if plan.spaces.isEmpty { throw ImportError.unreadable("Dia's spaces and tabs") }+ } else {+ addLegacySidebar(to: &plan)+ }+ addArchive(to: &plan)+ return plan+ }+ private static func addLegacySidebar(to plan: inout ImportPlan) {// Open tabs and the favorites container.if let data = try? Data(contentsOf: supportDir.appendingPathComponent("StorableProfileContainers.json")),let root = try? JSONSerialization.jsonObject(with: data) as? [String: Any],@@ -297,7 +318,7 @@ enum DiaImporter {}// Bookmarks: Dia keeps imported Arc spaces as folders on the bookmarks bar.- let profiles = (try? FileManager.default.contentsOfDirectory(atPath: supportDir.appendingPathComponent("User Data").path)) ?? []+ let profiles = (try? FileManager.default.contentsOfDirectory(atPath: userData.path)) ?? []for prof in profiles where prof == "Default" || prof.hasPrefix("Profile ") {let bm = supportDir.appendingPathComponent("User Data/\(prof)/Bookmarks")guard let data = try? Data(contentsOf: bm), let root = try? JSONSerialization.jsonObject(with: data) as? [String: Any],@@ -329,7 +350,9 @@ enum DiaImporter {plan.spaces.append(ImportedSpace(title: "Other Bookmarks", emoji: "🔖", theme: nil, pinned: kids))}}+ }+ private static func addArchive(to plan: inout ImportPlan) {// Auto-archive store (best effort; shape varies between Dia versions).if let data = try? Data(contentsOf: supportDir.appendingPathComponent("StorableAutoArchive.json")),let root = try? JSONSerialization.jsonObject(with: data) as? [String: Any],@@ -343,7 +366,6 @@ enum DiaImporter {}}}- return plan}private static func firstURL(in obj: Any) -> (String, String)? {@@ -409,7 +431,9 @@ extension SidebarStore {var tab = SidebarItem.tab(url, title: it.pageTitle, parent: parent)tab.title = it.customTitletab.createdAt = it.createdAt- if var t = tab.tab { t.timeLastActiveAt = it.createdAt; tab.data = .tab(t) }+ // An open tab was alive in the other browser: auto-archive counts from the import,+ // not from when the tab was made (Dia keeps tabs for weeks with auto-clean off).+ if var t = tab.tab { t.timeLastActiveAt = pinned ? it.createdAt : clock.now; tab.data = .tab(t) }insertItem(tab, into: parent, at: nil)result.tabs += 1}diff --git a/Sources/Cra/UI/Onboarding/ImportFlow.swift b/Sources/Cra/UI/Onboarding/ImportFlow.swiftindex 756310a..08bef1a 100644--- a/Sources/Cra/UI/Onboarding/ImportFlow.swift+++ b/Sources/Cra/UI/Onboarding/ImportFlow.swift@@ -106,6 +106,8 @@ final class ImportFlowModel {/// Read and decrypted, staged for the next launch once the import runs.private(set) var credentials = ImportedCredentials()private(set) var credentialError: String?+ /// Dia's sidebar could not be unlocked or read; the unlock step says so and offers a retry.+ private(set) var unlockError: String?private(set) var credentialsAttempted = falseprivate(set) var credentialsStaged = false@@ -216,6 +218,7 @@ final class ImportFlowModel {loadError = nilcredentials = ImportedCredentials()credentialError = nil+ unlockError = nilcredentialsAttempted = falseexportFileName = nilexportError = nil@@ -282,20 +285,45 @@ final class ImportFlowModel {if selectedProfiles.contains(id) { selectedProfiles.remove(id) } else { selectedProfiles.insert(id) }}+ /// Dia 1.55 encrypts its sidebar with the same Keychain secret as passwords and cookies.+ var unlockReadsSidebar: Bool { source?.kind == .dia && DiaImporter.hasEncryptedSidebar }+/// Reads the Keychain secret (macOS asks for the login password) and/// decrypts the picked profiles' passwords and cookies, then moves on.- func unlock() {+ func unlock() { unlock(profiles: credentialProfiles.filter { selectedProfiles.contains($0.id) }) }++ private func unlock(profiles: [ChromiumProfile]) {guard let source, let service = source.keychainService, let account = source.keychainAccount, !unlocking else { return }- let profiles = credentialProfiles.filter { selectedProfiles.contains($0.id) }- guard !profiles.isEmpty else { goToSpaces(); return }+ let readsSidebar = unlockReadsSidebar+ guard !profiles.isEmpty || readsSidebar else { goToSpaces(); return }unlocking = truecredentialError = nil+ unlockError = nilTask { @MainActor in- let result = await Task.detached(priority: .userInitiated) { () -> Result<ImportedCredentials, Error> in- Result { try ChromiumImporter.credentials(browser: source.name, profiles: profiles, keychainService: service,- keychainAccount: account, cookies: true, passwords: true) }+ let (result, sidebar) = await Task.detached(priority: .userInitiated) { () -> (Result<ImportedCredentials, Error>, Result<ImportPlan, Error>?) in+ guard let secret = ChromiumCrypto.keychainSecret(service: service, account: account) else {+ CraLog.note("import: no Keychain secret for \(service)")+ let denied = CredentialImportError.keychainDenied(source.name)+ return (.failure(denied), readsSidebar ? .failure(denied) : nil)+ }+ CraLog.note("import: unlocked \(service)\(readsSidebar ? ", reading the sidebar" : "")")+ let credentials = profiles.isEmpty ? .success(ImportedCredentials()) : Result {+ try ChromiumImporter.credentials(browser: source.name, profiles: profiles, secret: secret, cookies: true, passwords: true)+ }+ return (credentials, readsSidebar ? Result { try DiaImporter.plan(secret: secret) } : nil)}.valueunlocking = false+ switch sidebar {+ case .success(let plan)?: setPlan(plan)+ case .failure(let error)?:+ // Dia's older files no longer match its sidebar: stay here rather than import them.+ unlockError = error is CredentialImportError+ ? "macOS didn't unlock Dia's data. Dia encrypts your spaces and tabs, so Cra needs your computer password to bring them over."+ : "Cra couldn't read your Dia spaces and tabs. This version of Dia may store them differently."+ return+ case nil: break+ }+ guard !profiles.isEmpty else { goToSpaces(); return }credentialsAttempted = trueswitch result {case .success(let c): credentials = c@@ -308,7 +336,7 @@ final class ImportFlowModel {func skipCredentials() {credentials = ImportedCredentials()credentialsAttempted = false- goToSpaces()+ if unlockReadsSidebar { unlock(profiles: []) } else { goToSpaces() }}/// Safari's exported .zip or folder (bookmarks, history, passwords) ordiff --git a/Sources/Cra/UI/Onboarding/OnboardingSteps.swift b/Sources/Cra/UI/Onboarding/OnboardingSteps.swiftindex b3ed419..99bf205 100644--- a/Sources/Cra/UI/Onboarding/OnboardingSteps.swift+++ b/Sources/Cra/UI/Onboarding/OnboardingSteps.swift@@ -93,8 +93,10 @@ struct UnlockStep: View {ZStack(alignment: .topLeading) {BackLink(c: c) { model.go(.source) }StepHeader(title: "Unlock your data for import",- subtitle: many ? "Some data is encrypted, so macOS will ask for your computer password once for each selected profile."- : "Some data is encrypted, so macOS will ask for your computer password to bring it securely into Cra.", c: c)+ subtitle: model.unlockReadsSidebar+ ? "Dia encrypts your spaces, tabs and passwords, so macOS will ask for your computer password."+ : many ? "Some data is encrypted, so macOS will ask for your computer password once for each selected profile."+ : "Some data is encrypted, so macOS will ask for your computer password to bring it securely into Cra.", c: c)if many {ScrollView {VStack(alignment: .leading, spacing: 8) {@@ -123,9 +125,14 @@ struct UnlockStep: View {.overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder(c.rowBorder, lineWidth: 0.5)).offset(y: ImportMetrics.listTop)}+ if let err = model.unlockError {+ Text(err).font(.system(size: 12)).foregroundStyle(.red.opacity(0.85))+ .frame(width: ImportMetrics.columnWidth, alignment: .leading)+ .offset(y: ImportMetrics.buttonTop - 44)+ }HStack(spacing: 6) {SecondaryButton(title: "Skip", c: c) { model.skipCredentials() }.frame(width: 146)- PrimaryButton(title: model.unlocking ? "Waiting for password" : "Continue",+ PrimaryButton(title: model.unlocking ? "Waiting for password" : model.unlockError == nil ? "Continue" : "Try Again",c: c, enabled: !model.unlocking, width: 290) { model.unlock() }}.frame(width: ImportMetrics.columnWidth + 2)diff --git a/Tests/Fixtures/Dia/User Data/Profile 1/tabs.db b/Tests/Fixtures/Dia/User Data/Profile 1/tabs.dbnew file mode 100644index 0000000..02a033bBinary files /dev/null and b/Tests/Fixtures/Dia/User Data/Profile 1/tabs.db differdiff --git a/Tests/Fixtures/Dia/User Data/Profile 1/tabs.db-wal b/Tests/Fixtures/Dia/User Data/Profile 1/tabs.db-walnew file mode 100644index 0000000..96e539cBinary files /dev/null and b/Tests/Fixtures/Dia/User Data/Profile 1/tabs.db-wal differdiff --git a/Tests/Fixtures/Dia/make-fixture.py b/Tests/Fixtures/Dia/make-fixture.pynew file mode 100644index 0000000..e2e05f4--- /dev/null+++ b/Tests/Fixtures/Dia/make-fixture.py@@ -0,0 +1,109 @@+#!/usr/bin/env python3 -I+"""Rebuilds User Data/Profile 1/tabs.db(-wal): a made-up Dia 1.55 sidebar encrypted the way Dia+does it (SQLCipher 4, raw key from the Safe Storage secret "cra-test-secret"). The Work space's+folder is only in the -wal, as Dia's recent edits often are. Needs the sqlite3 and openssl CLIs."""+import base64, hashlib, hmac, os, shutil, sqlite3, subprocess, tempfile++HERE = os.path.dirname(os.path.abspath(__file__))+OUT = os.path.join(HERE, "User Data", "Profile 1")+SECRET, LABEL = b"cra-test-secret", b"profile/Profile 1/tabs"+SALT_KEY = base64.b64decode("iOe1Ue/XtonbieE/5m1nAgewvWQlePHRcKnoU10EyOM=")+PAGE, RESERVE = 4096, 80++SCHEMA = """+CREATE TABLE spaces (id TEXT PRIMARY KEY, title TEXT NOT NULL, creation_date DATE NOT NULL, last_updated_at DATE NOT NULL, theme TEXT NOT NULL DEFAULT 'neutral');+CREATE TABLE nodes (id INTEGER PRIMARY KEY AUTOINCREMENT, kind TEXT NOT NULL, entity_id TEXT NOT NULL, parent_id INTEGER, "order" INTEGER NOT NULL, deleted_at DATETIME, space_id TEXT NOT NULL DEFAULT '');+CREATE TABLE tabs (id TEXT PRIMARY KEY, node_id INTEGER NOT NULL, creation_date DATE NOT NULL);+CREATE TABLE tab_groups (id TEXT PRIMARY KEY, node_id INTEGER NOT NULL, creation_date DATE NOT NULL, title TEXT, theme TEXT NOT NULL DEFAULT 'neutral');+CREATE TABLE content_panes (id TEXT PRIMARY KEY, node_id INTEGER NOT NULL, creation_date DATE NOT NULL, custom_title TEXT, variant TEXT);+CREATE TABLE web_contents (id INTEGER PRIMARY KEY AUTOINCREMENT, content_pane_id TEXT NOT NULL, url TEXT NOT NULL, title TEXT);+"""++class Tree:+ def __init__(self, db): self.db, self.n = db, 0+ def node(self, kind, parent, order, space, deleted=None):+ self.n += 1+ ent = "%s-%d" % (kind, self.n)+ self.db.execute('INSERT INTO nodes (id, kind, entity_id, parent_id, "order", deleted_at, space_id) VALUES (?,?,?,?,?,?,?)',+ (self.n, kind, ent, parent, order, deleted, space))+ return self.n, ent+ def tab(self, parent, order, space, *pages, deleted=None):+ nid, ent = self.node("tab", parent, order, space, deleted)+ self.db.execute("INSERT INTO tabs VALUES (?,?,?)", (ent, nid, "2026-10-14 07:32:25.072"))+ for i, (url, title, custom) in enumerate(pages):+ pid, pent = self.node("content_pane", nid, i, space)+ self.db.execute("INSERT INTO content_panes VALUES (?,?,?,?,?)", (pent, pid, "2026-10-14 07:32:25.072", custom,+ "web_content" if url else "new_tab_page"))+ if url: self.db.execute("INSERT INTO web_contents (content_pane_id, url, title) VALUES (?,?,?)", (pent, url, title))+ def group(self, parent, order, space, title):+ nid, ent = self.node("group", parent, order, space)+ self.db.execute("INSERT INTO tab_groups VALUES (?,?,?,?,?)", (ent, nid, "2026-10-14 07:32:25.072", title, "neutral"))+ return nid++def build(path, wal_path):+ subprocess.run(["sqlite3", path, ".filectrl reserve_bytes %d" % RESERVE, SCHEMA], check=True)+ db = sqlite3.connect(path)+ db.execute("INSERT INTO spaces VALUES ('home','Home','2026-10-01 08:00:00.000','2026-10-01 08:00:00.000','yellow')")+ db.execute("INSERT INTO spaces VALUES ('work','Work','2026-10-02 08:00:00.000','2026-10-02 08:00:00.000','neutral')")+ t = Tree(db)+ for space, offset in (("home", 0), ("work", 10)):+ t.node("pinned_container", None, offset, space)+ t.n = 2+ fav, _ = t.node("favorites", None, 20, "home")+ t.tab(fav, 0, "home", ("https://example.com/mail", "Mail", None))+ t.tab(fav, 1, "home", ("https://example.com/calendar", "Calendar", None))+ t.tab(1, 0, "home", ("https://example.com/docs", "Docs page", "Docs"))+ reading = t.group(1, 1, "home", "Reading")+ t.tab(reading, 0, "home", ("https://example.com/read/1", "Read one", None))+ deep = t.group(reading, 1, "home", "Deep")+ t.tab(deep, 0, "home", ("https://example.com/read/deep", "Deep read", None))+ t.tab(1, 2, "home", ("https://example.com/gone", "Deleted", None), deleted="2026-10-20 10:00:00.000")+ win, _ = t.node("window", None, 30, "home")+ t.tab(win, 0, "home", ("https://example.com/open", "Open", None))+ t.tab(win, 1, "home", ("https://example.com/left", "Left", None), ("https://example.com/right", "Right", None))+ t.tab(win, 2, "home", (None, None, None))+ wfav, _ = t.node("favorites", None, 40, "work")+ t.tab(wfav, 0, "work", ("https://example.com/jira", "Jira", None))+ db.commit(); db.close()++ db = sqlite3.connect(path)+ db.execute("PRAGMA journal_mode=WAL"); db.execute("PRAGMA wal_autocheckpoint=0")+ t = Tree(db); t.n = db.execute("SELECT max(id) FROM nodes").fetchone()[0]+ tools = t.group(2, 0, "work", "Tools")+ t.tab(tools, 0, "work", ("https://example.com/ci", "CI", None))+ db.commit()+ shutil.copy(path, path + ".snap"); shutil.copy(path + "-wal", wal_path)+ db.close()+ shutil.move(path + ".snap", path)++def key():+ root = hashlib.pbkdf2_hmac("sha1", SECRET, b"saltysalt", 1003, 16)+ prk = hmac.new(hmac.new(SALT_KEY, LABEL, hashlib.sha256).digest(), root, hashlib.sha256).digest()+ return hmac.new(prk, LABEL + b"\x01", hashlib.sha256).digest()++def encrypt_page(page, first, k):+ iv = os.urandom(16)+ start = 16 if first else 0+ ct = subprocess.run(["openssl", "enc", "-e", "-aes-256-cbc", "-nopad", "-K", k.hex(), "-iv", iv.hex()],+ input=page[start:PAGE - RESERVE], capture_output=True, check=True).stdout+ return (os.urandom(16) if first else b"") + ct + iv + os.urandom(RESERVE - 16)++def main():+ k = key()+ with tempfile.TemporaryDirectory() as tmp:+ plain, wal = os.path.join(tmp, "tabs.db"), os.path.join(tmp, "wal")+ build(plain, wal)+ raw = open(plain, "rb").read()+ with open(os.path.join(OUT, "tabs.db"), "wb") as f:+ for i in range(len(raw) // PAGE): f.write(encrypt_page(raw[i * PAGE:(i + 1) * PAGE], i == 0, k))+ w = open(wal, "rb").read()+ with open(os.path.join(OUT, "tabs.db-wal"), "wb") as f:+ f.write(w[:32])+ off = 32+ while off + 24 + PAGE <= len(w):+ pno = int.from_bytes(w[off:off + 4], "big")+ f.write(w[off:off + 24] + encrypt_page(w[off + 24:off + 24 + PAGE], pno == 1, k))+ off += 24 + PAGE++if __name__ == "__main__":+ main()diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swiftindex 4afdbd0..735989c 100644--- a/Tests/StoreTests.swift+++ b/Tests/StoreTests.swift@@ -14,8 +14,10 @@ enum StoreTests {// Before AppPaths and ArcImporter read them: they are fixed for the process.setenv("CRA_DATA_DIR", data.path, 1)setenv("CRA_ARC_DIR", URL(fileURLWithPath: #filePath).deletingLastPathComponent().appendingPathComponent("Fixtures/Arc").path, 1)+ setenv("CRA_DIA_DIR", URL(fileURLWithPath: #filePath).deletingLastPathComponent().appendingPathComponent("Fixtures/Dia").path, 1)try arcImport()+ try diaImport()chromiumProfile()autoArchive()tabSleepCadence()@@ -55,6 +57,42 @@ enum StoreTests {expect(composition.store.integrityProblems().isEmpty, "the imported sidebar is sound")}+ /// Dia 1.55's encrypted sidebar (Tests/Fixtures/Dia, rebuilt by its make-fixture.py with the+ /// Safe Storage secret "cra-test-secret").+ @MainActor+ private static func diaImport() throws {+ expect(DiaImporter.isAvailable && DiaImporter.hasEncryptedSidebar, "a profile with tabs.db counts as Dia data")+ let plan = try DiaImporter.plan(secret: "cra-test-secret")+ expect(plan.spaces.map(\.title) == ["Home", "Work"], "Dia's spaces come over oldest first")+ let home = plan.spaces[0], work = plan.spaces[1]+ expect(home.theme?.colors.first == "#F8D558" && work.theme == nil, "a named Dia colour becomes a theme, neutral the default")+ expect(home.favorites.compactMap(\.url) == ["https://example.com/mail", "https://example.com/calendar"]+ && work.favorites.compactMap(\.url) == ["https://example.com/jira"], "each space keeps its own favorites")+ expect(home.pinned.map { $0.customTitle ?? $0.pageTitle } == ["Docs", "Reading"], "pinned tabs and folders in order, deleted ones left out")+ expect(home.pinned[0].pageTitle == "Docs page", "a renamed pinned tab keeps both titles")+ let reading = home.pinned[1]+ expect(reading.isFolder && reading.children.count == 2 && reading.children[1].isFolder+ && reading.children[1].children.compactMap(\.url) == ["https://example.com/read/deep"], "folders nest")+ expect(home.today.compactMap(\.url) == ["https://example.com/open", "https://example.com/left", "https://example.com/right"],+ "open tabs come over, a split as its tabs, a new tab page left out")+ expect(work.pinned.count == 1 && work.pinned[0].customTitle == "Tools" && work.pinned[0].children.compactMap(\.url) == ["https://example.com/ci"],+ "edits still in the -wal come over")++ expect((try? DiaImporter.plan(secret: "wrong")) == nil,+ "a secret that opens no sidebar database fails instead of importing Dia's stale older files")+ expect((try? DiaImporter.plan())?.spaces.contains { $0.title == "Home" } == false, "without the secret nothing comes from the database")++ let clock = ManualScheduler()+ let composition = AppComposition(clock: clock)+ let result = composition.store.apply(plan, includeArchive: false, includeSettings: false)+ expect(result.spaces == 2 && result.folders == 3, "applying adds both spaces and their folders")+ let homeSpace = composition.store.orderedSpaces.first { $0.title == "Home" }+ let open = homeSpace.map { composition.store.tabs(under: $0.todayContainerID) } ?? []+ expect(open.count == 3 && open.allSatisfy { $0.tab?.timeLastActiveAt == clock.now },+ "open tabs count as active at the import, so auto-archive doesn't take weeks-old Dia tabs at once")+ expect(composition.store.integrityProblems().isEmpty, "the imported sidebar is sound")+ }+/// Chrome-family profiles (Tests/Fixtures/Chromium/Default): the last session's open tabs,/// bookmarks and which extensions are turned off.private static func chromiumProfile() {diff --git a/Tests/lint-baseline.txt b/Tests/lint-baseline.txtindex 0940d0c..2d8359b 100644--- a/Tests/lint-baseline.txt+++ b/Tests/lint-baseline.txt@@ -1,6 +1,5 @@# scripts/lint.py findings in code older than the rule. Only ever lower these.importer-without-fixture Services/Import/FirefoxImporter.swift:Firefox 1-importer-without-fixture Services/Import/Importers.swift:Dia 1importer-without-fixture Services/Import/SafariImporter.swift:Safari 1importer-without-fixture Services/Import/ZenImporter.swift:Zen 1raw-observation-tracking UI/CommandBar/CommandBarView.swift 1diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex 1f59bde..66da3b9 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -137,6 +137,25 @@ Legend: [O] observed in shipped artifact or data file, [I] inference, [U] unknowcontainers[].archivedTabs (empty here). Chromium profile at User Data/Profile 7 with Bookmarks whose bookmark-barfolders mirror Arc spaces ("Favorites", "Victor", "JYSK").+## Dia 1.55 sidebar store (1 Nov 2026)+- [O] StorableProfileContainers.json stopped being written (last Feb 2026, still names "Profile 1") and the bookmarks+ bar keeps the Arc import from 14 Oct; neither follows the sidebar. Bookmarks also moved to EncryptedBookmarks2+ (OSCrypt v10 of the same JSON, same checksum).+- [O] The sidebar is User Data/<profile>/tabs.db (GRDB with SQLCipher 4 defaults: 4096-byte pages, 80 reserved bytes =+ IV + HMAC-SHA512, raw 32-byte key). Its siblings key_value_store.db, live_data_database.db, assistant.db … are the same.+- [O] Key (BoostBrowser Persistence/DatabaseEncryptionKeyDerivationFunction.swift, read from the arm64 code at+ 0x100faf20c and its caller 0x100fc31ec in 1.55.1): `HKDF<SHA256>(ikm: rootKey, salt: HMAC<SHA256>(key:+ base64 "iOe1Ue/XtonbieE/5m1nAgewvWQlePHRcKnoU10EyOM=", label), info: label, 32 bytes)`, label+ `profile/<profile folder>/<name>` ("profile/Profile 7/tabs") or `global/<name>`. rootKey = Chromium's OSCrypt key,+ PBKDF2-SHA1("Dia Safe Storage" secret, "saltysalt", 1003, 16 bytes).+- [O] Tables: `spaces(id, title, creation_date, theme)` with theme a name (neutral, red, orange, yellow, green, blue,+ pink, purple; no icon); `nodes(id, kind, entity_id, parent_id, order, deleted_at, space_id)`, kind tab | group |+ favorites | window | content_pane | pinned_container. Per space one `favorites` and one `pinned_container` node and a+ `window` node per window (open tabs; closed windows have deleted_at). `tabs`, `tab_groups(title, icon JSON, behavior)`,+ `content_panes(custom_title, variant web_content | new_tab_page)`, `web_contents(content_pane_id, url, title)`; a split+ is a tab with several content panes. Dates are GRDB text in UTC. Recent edits often sit only in tabs.db-wal.+ Cra reads it in Services/Import/DiaSidebar.swift.+## Other observed features (not in Cra's first scope)- Little Arc (LittleBrowser), Peek, Easels, Boosts, split view, hover cards, site control center, sidebar banners,sync via CloudKit + Firebase, Chromium extensions, "Tidy", Ask Arc.