// Home's one sync line, the board's `sync` part (lane syncface, 21 Oct 2026):// where this device's copy of the shown database stands, in ONE line the core// chose from typed states (`rules::sync_status`) and said in the shell's// words (`kits/shell/lines/sync.json`) — "Up to date with Studio Mac · 3 min// ago", "Receiving 40 changes from Studio Mac", "Studio Mac not reached since// 2 h ago". Swift composes no word of it: it picks the ink by the state —// quiet grey at rest, print ink while working, red only when the Mac was not// reached. No spinner, no badge. A tap opens this device's own record page.//// Read from the core's one answer for Home (`shell.home`'s `sync`: the line// and its typed state), off the phone's own copy, so it answers offline; again// on every pass the window's sync model sees, and on a slow tick for the ages.// With nothing read it keeps its room.importCottonKitimportCottonValuesimportSwiftUI/// The core's resolved line: its typed state and its words.structSyncLineRead: Decodable, Equatable, Sendable {let state: Stringlet words: String/// The quiet states: nothing is moving.var atRest: Bool { state == "up_to_date" || state == "reader_only" || state == "alone" }var notReached: Bool { state == "not_reached" }}structHomeSync: View { @Environment(\.cottonCore) privatevar core @Environment(\.cottonSync) privatevar sync @Environment(\.theme) privatevar theme @Environment(Navigator.self) privatevar navigator: Navigator? @Environment(DatabaseScene.self) privatevar scene: DatabaseScene? @State privatevar line: SyncLineRead?var body: someView {iflet line = line ?? HomeSyncLines.last[scene?.shownId ?? ""], !line.words.isEmpty {Button { navigator?.open(.device) } label: {Text(line.words) .font(theme.type.body(HomeSyncKnobs.size)) .foregroundStyle(ink(line)) .frame(maxWidth: .infinity, alignment: .leading) .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityIdentifier("home-sync") .accessibilityValue(line.state) .background { reader } } else {// Its room before its first read: Today stands where it will// stay, never stepping down as the line arrives (294 row 3,// walker293).Text(verbatim: " ").font(theme.type.body(HomeSyncKnobs.size)) .hidden() .accessibilityHidden(true) .background { reader } } }privatefunc ink(_ line: SyncLineRead) -> Color {if line.notReached { return theme.print(.red) }return line.atRest ? theme.colors.inkSecondary.color : theme.print(.ink) }/// What moves the line: the shown database, and each pass the window's/// sync model sees (a pull landing, an outbox draining, a media move).privatestructMoves: Equatable {let shown: String?let pulled: String?let pending: Int }privatevar reader: someView {Color.clear .task(id: Moves(shown: scene?.shownId, pulled: sync?.lastPullAt, pending: sync?.pendingOps ?? 0)) {while !Task.isCancelled {await read()try? awaitTask.sleep(for: .seconds(HomeSyncKnobs.every)) } } }privatefunc read() async {guardlet core, let own = awaitSelf.line(core), !Task.isCancelled else { return } line = ownHomeSyncLines.last[scene?.shownId ?? ""] = own }/// This device's line for the database `core` is aimed at; nil when it/// could not be read or the answer carries none.staticfunc line(_ core: any CottonCalling) async -> SyncLineRead? {guardlet sync = try? await core.call(CottonMethod.shellHome, as: HomeAnswer.self).sync,let state = sync.line_stateelse { returnnil }returnSyncLineRead(state: state, words: sync.line) }/// Read `database`'s line now, through `core` — aimed at it — and keep it/// (`HomeSyncLines`): a switch reads it before it turns (`HomeModel.prepare`),/// so the page it rebuilds draws the line in its first frame, never its/// empty room (295 A, walker294).staticfunc prepare(_ core: any CottonCalling, database: String) async {guardlet own = await line(core) else { return }HomeSyncLines.last[database] = own }/// This device's copy of `database` in copy.json's words — what it is/// doing and when it last synced — or nil-nil when it holds no row; nil/// when the rows could not be read. A read still out (`StillReading`)/// says it.staticfunc thisDevice(_ core: any CottonCalling, database: String?) async -> (state: String?, when: String?)? {guardlet rows = awaitCopyRows.read(core, database: database) else { returnnil }guardlet own = rows.first(where: { $0["role"].text == HomeSync.thisDevice }) else { return (nil, nil) }return (own["@slip_subtitle"].text, own["@slip_caption"].text) }staticlet table = "copy"staticlet thisDevice = "this_device"}/// A database's `copy` rows as this device's own file holds them, read/// SINGLE-FLIGHT (architect's ruling 21:00 IST 16 Oct 2026): while a read for/// a database is out, every other asker — the next tick, Me's line on the/// same page, a remount after a switch — waits for its/// answer and never starts a second. A Swift task cancelled mid-read does not/// stop the core's call, so a read restarted beside it stacked one more call/// on the read pool every 20 s on a starved file (realfan, 16 Oct 2026).@MainActorenumCopyRows {privatestaticvar flights: [String: Task<[TableRecord]?, Never>] = [:]/// Nil when the rows could not be read.staticfunc read(_ core: any CottonCalling, database: String?) async -> [TableRecord]? {let key = database ?? ""iflet flight = flights[key] { returnawait flight.value }let flight = Task { () -> [TableRecord]? invar request: [String: RecordValue] = ["table": .text(HomeSync.table)]iflet database { request["where"] = .object(["database": .text(database)]) }let rows = try? await core.call(CottonMethod.recordsList, request, as: Page.self)// The flight clears itself, before any asker resumes, so the// next ask after it lands starts one fresh read. flights[key] = nilreturn rows?.records.map(\.record) } flights[key] = flightreturnawait flight.value }privatestructPage: Decodable {let records: [CoreRecords.WireRecord] }}/// The record Home's board names on its `device` part, in a box Home's page/// reads (`HomeToday`) and the board fills each time it is read/// (`BoardSurface`). A box, as Me's print is (`HomeRead`), and never a value/// handed down: Home is drawn inside the fan's live page, which draws again/// only when its tile or database moves (`FanLivePage`), so the board read/// that lands after a database turned — the fresh one an Erase starts — must/// reach the deck by observation.@MainActor @ObservablefinalclassHomeDevicePart {var id: String?init(id: String? = nil) {self.id = id }/// The card the answer's `device` part names; nil when it names none/// (no such part, or no identity yet).staticfunc named(in parts: [BoardEntry]) -> String? { parts.first { $0.kind == "device" }?.card }}enumHomeSyncKnobs {staticlet size: CGFloat = 16/// Seconds between reads while Me is shown.staticlet every: Double = 20}/// Each database's last sync line, over a switch: the switch rebuilds Me's/// page and its line arrived last, pushing Today down under a page already/// drawn (293 row 2, walker292). A database's line is drawn as it last read/// — or as the switch read it before turning (`HomeSync.prepare`) — until its/// read answers again.@MainActorenumHomeSyncLines {staticvar last: [String: SyncLineRead] = [:]}