importCottonKitimportCottonValuesimportSwiftUI/// The build line ([`BuildLine`]) as it is drawn: faint, one line, at the/// bottom of the Databases sheet and of This phone / This Mac; red while the/// two schemas differ. A tap copies it. Debug information the owner allowed/// in the app until the 1 Nov packaging (12 Oct 2026).structBuildLineView: View { @Environment(\.cottonCore) privatevar core @Environment(\.theme) privatevar theme @State privatevar schema: Int? @State privatevar peer: BuildLine.Peer? @State privatevar copied = falseprivatelet build = BuildFacts.fromBundle()/// The databases the sheet lists / the databases the Mac answered, said/// for the device's reported state where the line stands on the sheet.var databasesListed: String? = nilprivatestructFacts: Decodable { let schemaVersion: Int }privatevar line: BuildLine {BuildLine(version: build.version, build: build.build, commit: build.commit, schema: schema, peer: peer) }var body: someView {let line = lineText(copied ? ShellLines.line("diagnostics", "copied") : line.text) .font(.system(size: 10, design: .monospaced)) .foregroundStyle(line.mismatched ? theme.colors.error.color : theme.colors.inkTertiary.color)// Wraps whole, never cut by an ellipsis: the commit at its end is// the part a report needs (walker 291). .multilineTextAlignment(.center) .fixedSize(horizontal: false, vertical: true) .frame(maxWidth: .infinity) .padding(.vertical, 6) .contentShape(Rectangle()) .onTapGesture { UIPasteboard.general.string = line.text copied = true } .accessibilityIdentifier("build-line") .task { await listen() } .task(id: databasesListed) {iflet databasesListed { Diagnostics.say(core, ["databasesListed": databasesListed]) } } .task(id: copied) {guard copied else { return }try? awaitTask.sleep(for: .seconds(1)) copied = false } }/// The serving Mac as this device's own copy names it (the `copy` row/// whose role is serving): a phone that holds a copy but has not heard/// the Mac this run names that Mac, never "no Mac heard yet" (walker's/// offline pass). Version and schema stay unsaid until the loop hears it.privatefunc servingCopy() async -> BuildLine.Peer? {guardlet core else { returnnil }let request: [String: RecordValue] = ["table": .text(HomeSync.table)]guardlet rows = try? await core.call(CottonMethod.recordsList, request, as: Rows.self) else { returnnil }let serving = rows.records.map(\.record).first { $0["role"].text == "serving" }guardlet name = serving?["name"].text else { returnnil }returnBuildLine.Peer(name: name) }privatestructRows: Decodable { let records: [CoreRecords.WireRecord] }/// The constants once, then what the loop last heard every few seconds/// while the line is on screen.privatefunc listen() async {guardlet core else { return } schema = (try? await core.call("build.facts", as: Facts.self))?.schemaVersionwhile !Task.isCancelled {let status = try? await core.callJSON(CottonMethod.readSyncStatus) peer = BuildLine.Peer.of(syncStatus: status) ?? peerif peer == nil { peer = await servingCopy() }try? awaitTask.sleep(for: .seconds(5)) } }}