Cotton code
797 lines · 34.8 KB · SwiftRaw
// SETTINGS, ONE SHAPE IN EVERY APP (owner, 21 Nov 2026;// assets/design/shared/DECISIONS.md "Settings", WORDS-PROGRESS-STORAGE.md §3),// as Android's `SettingsParts.kt`: each app draws Account its own way, then// Your Claude while signed in, then Storage, Help and feedback and About under// it, every word the core's (`shell.settings`, `shell.report`,// `shell.freeUp`, `assistant.screen`). The app's look comes in through// `SettingsLook` (its ink, quiet colour, faces, heading and acts), as// Android's CardLook; these parts decide nothing.//// THE ONE PROGRESS LINE (§2, DECISIONS.md "Loading"): while a signed-in// phone's first pull runs, `shell.home`'s `bringing` says "Loading your// data… 42%" with how far it is. `LoadingLine` draws it the same way in every// app, quietly, in that app's ink: the words, a thin bar under them, then gone.#if os(iOS)import CottonKitimport SwiftUIimport UIKit// MARK: - The answers/// `shell.settings`' answer: the three parts drawn under Account.struct SettingsAnswer: Decodable, Equatable, Sendable {    struct Part: Decodable, Equatable, Sendable {        let id: String        let label: String        var line: String?        let bytes: Int64?        let said: String    }    struct FreeUp: Decodable, Equatable, Sendable {        let label: String        let bytes: Int64        var line: String?        var ask: String?        var askBody: String?        var confirm: String?        enum CodingKeys: String, CodingKey {            case label, bytes, line, ask, confirm            case askBody = "ask_body"        }    }    struct Storage: Decodable, Equatable, Sendable {        let title: String        var line: String?        /// The whole kept on this phone, in words ("1.4 GB").        var said: String?        let parts: [Part]        var freeUp: FreeUp?        enum CodingKeys: String, CodingKey {            case title, line, said, parts            case freeUp = "free_up"        }    }    struct Share: Decodable, Equatable, Sendable {        let label: String        var line: String?        var previewTitle: String?        var previewShare: String?        var previewClose: String?        enum CodingKeys: String, CodingKey {            case label, line            case previewTitle = "preview_title"            case previewShare = "preview_share"            case previewClose = "preview_close"        }    }    struct Help: Decodable, Equatable, Sendable {        let title: String        var share: Share?        /// The privacy policy and Help and contact, each opening its page on cottondb.com (store pass, 24 Nov 2026).        var links: [Link]?    }    struct Link: Decodable, Equatable, Sendable, Identifiable {        let id: String        let label: String        let url: String    }    struct Fact: Decodable, Equatable, Sendable {        var id: String?        let label: String        let said: String    }    struct About: Decodable, Equatable, Sendable {        let title: String        var version: Fact?        var facts: [Fact]?    }    var storage: Storage?    var help: Help?    var about: About?}/// `shell.report`'s answer: what Share a report shows, then shares.struct SettingsReport: Decodable, Equatable, Identifiable, Sendable {    let title: String?    let fileName: String?    let text: String    var id: String { text }    enum CodingKeys: String, CodingKey {        case title, text        case fileName = "file_name"    }}private struct SettingsAsk: Encodable, Sendable { let commit: String }private struct FreeUpAsk: Encodable, Sendable { let expected: Int64 }extension SettingsAnswer {    /// The build's commit, as every Account ask sends it.    static var commit: String { (Bundle.main.object(forInfoDictionaryKey: "CottonBuildCommit") as? String) ?? "" }    static func read(_ core: any CottonCalling) async -> SettingsAnswer? {        try? await asked(core)    }    /// The answer, or why it did not come.    static func asked(_ core: any CottonCalling) async throws -> SettingsAnswer {        try await core.call(CottonMethod.shellSettings, SettingsAsk(commit: commit), as: SettingsAnswer.self)    }    /// Free up space, once the person agreed to `bytes`: what the core said    /// ("Freed 80 MB.", or why it refused).    static func freeUp(_ core: any CottonCalling, bytes: Int64) async -> String? {        do {            return try await core.callJSON(CottonMethod.shellFreeUp, FreeUpAsk(expected: bytes)).text("said")        } catch {            return (error as? CottonCallError)?.message ?? ActionRefused.words(for: error)        }    }}extension SettingsReport {    /// The report Share a report shows whole before anything goes.    static func read(_ core: any CottonCalling) async throws -> SettingsReport {        try await core.call(CottonMethod.shellReport, SettingsAsk(commit: SettingsAnswer.commit), as: SettingsReport.self)    }    /// The share sheet, once the preview has gone: the report as a small    /// text file named as the core names it, and the text itself.    @MainActor    func share() {        let name = fileName ?? "report.txt"        let file = FileManager.default.temporaryDirectory.appendingPathComponent("report", isDirectory: true)        try? FileManager.default.removeItem(at: file)        try? FileManager.default.createDirectory(at: file, withIntermediateDirectories: true)        let url = file.appendingPathComponent(name)        if (try? text.write(to: url, atomically: true, encoding: .utf8)) != nil {            ShareSheet.present(file: url, words: text)        } else {            ShareSheet.present(words: text)        }    }}// MARK: - The look/// How an app draws the shared parts, in its own look (Android's CardLook).struct SettingsLook {    var ink: Color    var quiet: Color    /// The rule between rows; clear where the app draws none.    var rule: Color    /// The report sheet's ground.    var ground: Color    var body: Font    var small: Font    /// The app's own group heading (Days' dotted heading, Chat's WarmHeading…).    var heading: (String) -> AnyView    /// One act in the app's own button: its words, its identifier, whether it can be pressed, the tap.    var act: (_ words: String, _ id: String, _ enabled: Bool, _ tap: @escaping () -> Void) -> AnyView    /// One choice of several (Your Claude's On, Ask each time, Off): words, chosen, identifier, enabled, tap.    var choice: (_ words: String, _ on: Bool, _ id: String, _ enabled: Bool, _ tap: @escaping () -> Void) -> AnyView    /// The app's danger ink (Delete account's row and its warning): Days' and Story's ink, Words' accent.    var danger: Color? = nil    /// A page's own heading face (Delete account's page).    var title: Font? = nil}// MARK: - Settings parts/// Storage, Help and feedback and About as one block under an app's Account,/// read from the core and read again on each change; `help` is the app's own/// ways to help, under Share a report (Story's Write to us).struct SettingsParts<More: View>: View {    let core: (any CottonCalling)?    let look: SettingsLook    /// What an act said ("Freed 80 MB.", a refusal), in the app's own place for it.    let said: (String) -> Void    /// One part alone, as its own page of the grouped Settings (`SettingsGrouped.swift`): `storage`, `help` or    /// `about`, drawn without its heading (the app's header names the page), with what Comms' page adds.    var only: String? = nil    /// Storage's page: how much this app keeps, in its name (`shell.settings` `pages.storage_kept`).    var kept: String? = nil    @ViewBuilder var more: () -> More    @Environment(\.cottonSync) private var sync    @Environment(\.openURL) private var openURL    @State private var answer: SettingsAnswer?    /// Why the first answer did not come, in the core's words (DATA iPhone 3: Storage stood with its title alone).    @State private var failed: String?    @State private var reads = ReadInTurn()    @State private var asked = 0    @State private var asking = false    @State private var report: SettingsReport?    /// The report Share was pressed on, shared once its preview has gone.    @State private var sharing: SettingsReport?    var body: some View {        VStack(alignment: .leading, spacing: 0) {            if let answer {                if let storage = answer.storage, shows("storage") { storagePart(storage) }                if let help = answer.help, let share = help.share, shows("help") { helpPart(help, share) }                if let about = answer.about, shows("about") { aboutPart(about) }            } else if only != nil {                // A part on its own page is never its title alone: Loading… at once, else why it did not come.                if let failed {                    quietLine(failed).accessibilityIdentifier("settings-part-failed")                    look.act(ShellLines.line("settings", "storage.again"), "settings-part-again", true) { asked += 1 }                        .padding(.top, 12)                } else {                    HStack(spacing: 10) {                        ProgressView().controlSize(.small).tint(look.quiet)                        quietLine(ShellLines.line("settings", "storage.loading"))                    }                    .accessibilityElement(children: .combine)                    .accessibilityIdentifier("settings-part-loading")                }            }        }        // A read that is refused leaves what stands: the parts never blink away during a sync. One read at a time:        // a sync moves every quarter second while it runs, and a read that moves with it never lands.        .task(id: "\(sync?.revision ?? 0)-\(asked)") {            guard let core else { return }            reads.ask {                do {                    answer = try await SettingsAnswer.asked(core)                    failed = nil                } catch {                    if answer == nil { failed = (error as? CottonCallError)?.message ?? ShellLines.line("settings", "storage.failed") }                }            }        }        .confirmDecision(            isPresented: $asking,            title: answer?.storage?.freeUp?.ask ?? "",            message: answer?.storage?.freeUp?.askBody ?? "",            confirmLabel: answer?.storage?.freeUp?.confirm ?? "",            identifier: "settings-free-up-confirm"        ) {            guard let bytes = answer?.storage?.freeUp?.bytes, bytes > 0 else { return }            Task { await freeUp(bytes) }        }        // A card, never a sheet (NoBottomSheetsTests): raised at the window, over the app, in its look.        .cottonCard(item: $report, detents: [.tall], onDismiss: shareAfterPreview) { shown in            if let share = answer?.help?.share {                SettingsReportSheet(share: share, text: shown.text, look: look, close: { report = nil }) {                    sharing = shown                    report = nil                }            }        }    }    private func shows(_ part: String) -> Bool { only == nil || only == part }    /// The part's heading in the list; on its own page the header names it.    @ViewBuilder private func heading(_ title: String) -> some View {        if only == nil { look.heading(title) }    }    private func storagePart(_ storage: SettingsAnswer.Storage) -> some View {        VStack(alignment: .leading, spacing: 0) {            heading(storage.title)            if only != nil {                if let whole = storage.said {                    Text(verbatim: whole).font(look.title ?? look.body).foregroundStyle(look.ink)                        .accessibilityIdentifier("settings-storage-whole")                }                if let kept { quietLine(kept).padding(.top, 4) }            } else if let line = storage.line {                quietLine(line).padding(.top, 8)            }            ForEach(storage.parts, id: \.id) { part in                SettingsPartRow(label: part.label, said: part.said, line: part.line, look: look, id: "settings-storage-\(part.id)")            }            if only != nil {                quietLine(SettingsWords.line("storage_measured")).padding(.top, 8)                // The account-full line, where the core adds one after what is kept here.                if let line = storage.line, let end = line.range(of: ". ") {                    quietLine(String(line[end.upperBound...])).padding(.top, 8).accessibilityIdentifier("settings-storage-room")                }            }            if let free = storage.freeUp {                if let line = free.line { quietLine(line).padding(.top, 8) }                look.act(free.label, "settings-free-up", free.bytes > 0) { asking = true }                    .padding(.top, 10)            }        }        .accessibilityElement(children: .contain)        .accessibilityIdentifier("settings-storage")    }    private func helpPart(_ help: SettingsAnswer.Help, _ share: SettingsAnswer.Share) -> some View {        VStack(alignment: .leading, spacing: 0) {            heading(help.title)            if only != nil { look.heading(SettingsWords.line("help_wrong")) }            if let line = share.line { quietLine(line).padding(.top, 8) }            look.act(share.label, "settings-share-report", true) { Task { await readReport() } }                .padding(.top, 10)            more()            // The privacy policy and the way to reach us, in every app (both stores ask; shared/DECISIONS "Settings").            if let links = help.links, !links.isEmpty {                VStack(spacing: 0) {                    ForEach(links) { link in                        SettingsGoRow(label: link.label, line: nil, look: look, id: "settings-link-\(link.id)") {                            if let url = URL(string: link.url) { openURL(url) }                        }                    }                }                .padding(.top, 16)            }        }        .accessibilityElement(children: .contain)        .accessibilityIdentifier("settings-help")    }    private func aboutPart(_ about: SettingsAnswer.About) -> some View {        VStack(alignment: .leading, spacing: 0) {            heading(about.title)            // On its own page, as Comms': the app's name large, as the phone names it under its icon.            if only != nil, let name = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String {                Text(verbatim: name).font(look.title ?? look.body).foregroundStyle(look.ink)                    .accessibilityIdentifier("settings-about-name")            }            if let version = about.version {                SettingsPartRow(label: version.label, said: version.said, line: nil, look: look, id: "settings-about-version")            }            if only != nil { look.heading(SettingsWords.line("about_curious")) }            // On its own page the version stands above, so the app's own fact is not said twice (as Comms' About).            ForEach(Array((about.facts ?? []).filter { only == nil || $0.id != "app" }.enumerated()), id: \.offset) { _, fact in                SettingsPartRow(label: fact.label, said: fact.said, line: nil, look: look, id: "settings-about-\(fact.id ?? fact.label)")            }            // On its own page, as Comms': the facts as text, for support or an assistant.            if only != nil {                look.act(SettingsWords.line("about_copy"), "settings-about-copy", true) {                    let lines = ([about.version].compactMap { $0 } + (about.facts ?? [])).map { "\($0.label): \($0.said)" }                    UIPasteboard.general.string = lines.joined(separator: "\n")                    said(SettingsWords.line("about_copied"))                }                .padding(.top, 14)            }        }        .accessibilityElement(children: .contain)        .accessibilityIdentifier("settings-about")    }    private func quietLine(_ words: String) -> some View {        Text(verbatim: words)            .font(look.small)            .foregroundStyle(look.quiet)            .fixedSize(horizontal: false, vertical: true)    }    private func freeUp(_ bytes: Int64) async {        guard let core else { return }        if let words = await SettingsAnswer.freeUp(core, bytes: bytes) { said(words) }        asked += 1    }    private func readReport() async {        guard let core else { return }        do {            report = try await SettingsReport.read(core)        } catch {            said((error as? CottonCallError)?.message ?? ActionRefused.words(for: error))        }    }    /// Share opens the share sheet once the preview has gone.    private func shareAfterPreview() {        guard let shown = sharing else { return }        sharing = nil        shown.share()    }}extension SettingsParts where More == EmptyView {    init(core: (any CottonCalling)?, look: SettingsLook, said: @escaping (String) -> Void, only: String? = nil, kept: String? = nil) {        self.init(core: core, look: look, said: said, only: only, kept: kept) { EmptyView() }    }}/// A label and what it says, sharing the row: a long said (About's Database)/// wraps in its half, never squeezing the label, what is said at the right.struct SettingsPartRow: View {    let label: String    let said: String    let line: String?    let look: SettingsLook    let id: String    var body: some View {        VStack(spacing: 0) {            HStack(alignment: .firstTextBaseline, spacing: 12) {                VStack(alignment: .leading, spacing: 2) {                    Text(verbatim: label).font(look.body).foregroundStyle(look.ink)                    if let line { Text(verbatim: line).font(look.small).foregroundStyle(look.quiet) }                }                .frame(maxWidth: .infinity, alignment: .leading)                Text(verbatim: said)                    .font(look.body)                    .foregroundStyle(look.quiet)                    .multilineTextAlignment(.trailing)                    .frame(maxWidth: .infinity, alignment: .trailing)            }            .frame(minHeight: 44)            .padding(.vertical, 4)            Rectangle().fill(look.rule).frame(height: 0.5)        }        .accessibilityElement(children: .combine)        .accessibilityIdentifier(id)    }}/// The report shown whole before it goes: its title, the text in the look's/// small words on a breath of its ink, Close and Share always in the window/// with the text scrolling in the room left.struct SettingsReportSheet: View {    let share: SettingsAnswer.Share    let text: String    let look: SettingsLook    let close: () -> Void    let onShare: () -> Void    @ViewBuilder private var acts: some View {        look.act(share.previewClose ?? "", "settings-report-close", true, close)        look.act(share.previewShare ?? "", "settings-report-share", true, onShare)    }    var body: some View {        VStack(alignment: .leading, spacing: 16) {            Text(verbatim: share.previewTitle ?? "")                .font(look.body.weight(.semibold))                .foregroundStyle(look.ink)                .accessibilityAddTraits(.isHeader)            ScrollView {                Text(verbatim: text)                    .font(look.small)                    .foregroundStyle(look.ink)                    .frame(maxWidth: .infinity, alignment: .leading)                    .textSelection(.enabled)                    .padding(10)                    .accessibilityIdentifier("settings-report-text")            }            .background(look.ink.opacity(0.06))            .accessibilityIdentifier("settings-report-box")            // Side by side while they fit; at the largest text one over the other.            ViewThatFits(in: .horizontal) {                HStack(spacing: 12) {                    Spacer()                    acts                }                VStack(alignment: .trailing, spacing: 8) {                    acts                }                .frame(maxWidth: .infinity, alignment: .trailing)            }        }        .padding(20)        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)        // The card's paper scrolls (CottonSheetChrome): the report is as tall        // as the room it shows, less the paper's foot, so the text scrolls in        // its box and Close and Share stand in the window at every text size.        .containerRelativeFrame(.vertical, alignment: .top) { room, _ in max(0, room - 12) }        .background(look.ground.ignoresSafeArea())        .accessibilityElement(children: .contain)        .accessibilityIdentifier("settings-report-preview")    }}// MARK: - The loading line/// The loading line in `ink` over its faint `track`, `font` for its words;/// nothing at all once `bringing` is nil. While it stands the home is asked/// again each second, so its figure follows the pages of the first pull.struct LoadingLine: View {    let bringing: HomeAnswer.Bringing?    let ink: Color    var track: Color?    var font: Font = .system(size: 13)    @Environment(BootModel.self) private var boot: BootModel?    /// How often the home is asked again while the line stands (Android's `Loading.TICK_MS`).    static let tick: Duration = .seconds(1)    var body: some View {        if let bringing, !bringing.words.isEmpty {            VStack(alignment: .leading, spacing: 6) {                Text(verbatim: bringing.words)                    .font(font)                    .foregroundStyle(ink)                    .fixedSize(horizontal: false, vertical: true)                    .accessibilityIdentifier("loading-words")                LoadingBar(percent: bringing.percent, ink: ink, track: track ?? ink.opacity(0.2))                    .frame(height: 2)                    .accessibilityIdentifier("loading-bar")            }            .frame(maxWidth: .infinity, alignment: .leading)            .accessibilityElement(children: .ignore)            .accessibilityLabel(bringing.words)            .accessibilityIdentifier("loading-line")            .task {                while !Task.isCancelled {                    try? await Task.sleep(for: Self.tick)                    await boot?.ask()                }            }        }    }}/// The thin bar: `percent` filled, or, while it is nil, a quarter moving on its own.private struct LoadingBar: View {    let percent: Int?    let ink: Color    let track: Color    var body: some View {        GeometryReader { box in            let width = box.size.width            ZStack(alignment: .leading) {                Rectangle().fill(track)                if let percent {                    Rectangle().fill(ink).frame(width: width * CGFloat(min(max(percent, 0), 100)) / 100)                } else {                    TimelineView(.animation) { time in                        let at = time.date.timeIntervalSinceReferenceDate.truncatingRemainder(dividingBy: 1.4) / 1.4                        let w = width * 0.25                        Rectangle().fill(ink).frame(width: w).offset(x: (width + w) * at - w)                    }                }            }            .clipped()        }    }}// MARK: - Your Claude/// YOUR CLAUDE, under Account while signed in (owner, 20/// Nov 2026: connecting Claude is the grant), as Android's `AssistantsPart`:/// the promise, each connection, Connect Claude and Remove with what they/// said, then What it may read (every sealed table On, Ask each time or Off),/// what a table's choice said under that table. Connect Claude and turning on/// a table left off on the card go behind the phone's lock; the rest do not.struct YourClaudePart: View {    let core: (any CottonCalling)?    let look: SettingsLook    /// Under its own heading in a list; on its own page the header names it.    var headed = true    @Environment(\.cottonSync) private var sync    @State private var screen: JSONValue?    @State private var asked = 0    @State private var busy = false    /// What an act said: under the acts, or under the table it was said of.    @State private var note: (words: String, table: String?)?    var body: some View {        VStack(alignment: .leading, spacing: 10) {            if let mine = YourClaude(screen) {                if headed {                    look.heading(mine.heading)                        .accessibilityIdentifier("account-your-claude-heading")                }                Text(verbatim: mine.promise).font(look.small).foregroundStyle(look.quiet)                    .fixedSize(horizontal: false, vertical: true)                    .accessibilityIdentifier("account-your-claude-promise")                ForEach(Array(mine.connections.enumerated()), id: \.offset) { _, said in                    Text(verbatim: said).font(look.body).foregroundStyle(look.ink)                        .accessibilityIdentifier("account-your-claude-connection")                }                if let none = mine.none {                    Text(verbatim: none).font(look.small).foregroundStyle(look.quiet)                        .accessibilityIdentifier("account-your-claude-none")                }                SettingsFlow(spacing: 10) {                    if let offer = mine.connect {                        look.act(offer, "account-your-claude-connect", !busy) { Task { await connect() } }                    }                    if let remove = mine.remove {                        look.act(remove, "account-your-claude-remove", !busy) { Task { await call(CottonMethod.assistantRemove, table: nil) } }                    }                }                if let note, note.table == nil { said(note.words) }                // How it reads now and its act (Ask each time instead, Stop now), then what it may read as groups a                // person knows, each On, Ask each time or Off (shared/DECISIONS.md "Your Claude asks"). An app the                // core answers no groups for keeps the tables.                if let reading = mine.reading, let title = reading.title {                    VStack(alignment: .leading, spacing: 4) {                        Text(verbatim: title).font(look.body).foregroundStyle(look.ink)                            .fixedSize(horizontal: false, vertical: true)                            .accessibilityIdentifier("account-your-claude-state-title")                        if let line = reading.line {                            Text(verbatim: line).font(look.small).foregroundStyle(look.quiet)                                .fixedSize(horizontal: false, vertical: true)                        }                        if let act = reading.act {                            look.act(act.label, "account-your-claude-act-\(act.id)", !busy) {                                Task { await call(act.id == "stop" ? CottonMethod.assistantStop : CottonMethod.assistantAskEachTime, table: nil) }                            }                        }                    }                    .padding(.top, 6)                    .accessibilityElement(children: .contain)                    .accessibilityIdentifier("account-your-claude-state")                }                if !mine.groups.isEmpty {                    Text(verbatim: mine.mayRead).font(look.body).foregroundStyle(look.ink)                        .padding(.top, 6)                        .accessibilityIdentifier("account-your-claude-may-read")                    ForEach(mine.groups, id: \.id) { group in                        VStack(alignment: .leading, spacing: 4) {                            Text(verbatim: group.label).font(look.body).foregroundStyle(look.ink)                            Text(verbatim: group.line).font(look.small).foregroundStyle(look.quiet)                                .fixedSize(horizontal: false, vertical: true)                            SettingsFlow(spacing: 6) {                                ForEach(group.choices, id: \.access) { choice in                                    look.choice(choice.label, choice.on, "account-your-claude-\(group.id)-\(choice.access)", !busy && !choice.on) {                                        Task { await scope(group, to: choice.access) }                                    }                                }                            }                            if let note, note.table == group.id { said(note.words) }                        }                        .accessibilityElement(children: .contain)                        .accessibilityIdentifier("account-your-claude-group-\(group.id)")                    }                    if let note = mine.reading?.note {                        Text(verbatim: note).font(look.small).foregroundStyle(look.quiet)                            .fixedSize(horizontal: false, vertical: true)                            .accessibilityIdentifier("account-your-claude-groups-note")                    }                } else if !mine.tables.isEmpty {                    Text(verbatim: mine.mayRead).font(look.body).foregroundStyle(look.ink)                        .padding(.top, 6)                        .accessibilityIdentifier("account-your-claude-may-read")                    ForEach(mine.tables, id: \.table) { table in                        VStack(alignment: .leading, spacing: 4) {                            Text(verbatim: table.label).font(look.body).foregroundStyle(look.ink)                            SettingsFlow(spacing: 6) {                                ForEach(table.choices, id: \.access) { choice in                                    look.choice(choice.label, choice.on, "account-your-claude-\(table.table)-\(choice.access)", !busy && !choice.on) {                                        Task { await scope(table, to: choice.access) }                                    }                                }                            }                            if let note, note.table == table.table { said(note.words) }                        }                        .accessibilityElement(children: .contain)                        .accessibilityIdentifier("account-your-claude-table-\(table.table)")                    }                }            }        }        .frame(maxWidth: .infinity, alignment: .leading)        .accessibilityElement(children: .contain)        .accessibilityIdentifier("account-your-claude")        .task(id: "\(sync?.revision ?? 0)-\(asked)") {            guard let core else { return }            if let read = try? await core.callJSON(CottonMethod.assistantScreen) { screen = read }        }    }    private func said(_ words: String) -> some View {        Text(verbatim: words).font(look.small).foregroundStyle(look.quiet)            .fixedSize(horizontal: false, vertical: true)            .accessibilityIdentifier("account-your-claude-note")    }    /// One table's setting: Off and Ask each time at once; On for a table    /// left off on the card behind the phone's lock.    private func scope(_ table: YourClaude.Table, to access: String) async {        guard let core else { return }        if access == "on", table.needsLock {            busy = true            let name = table.table            let handed = await VaultAccess().handing(CottonMethod.assistantScope, through: core) { key in                YourClaude.SignedScope(table: name, access: access, privateKey: key)            }            take(handed, table: name, sayDone: false)            busy = false            asked += 1        } else {            await call(CottonMethod.assistantScope, YourClaude.Scope(table: table.table, access: access), table: table.table, sayDone: false)        }    }    /// A group's choice: On (where it widens) behind the phone's lock; Ask each time and Off at once.    private func scope(_ group: YourClaude.Group, to access: String) async {        guard let core else { return }        if access == "on", group.needsLock {            busy = true            let id = group.id            let handed = await VaultAccess().handing(CottonMethod.assistantScope, through: core) { key in                YourClaude.SignedGroupScope(group: id, access: access, privateKey: key)            }            take(handed, table: id, sayDone: false)            busy = false            asked += 1        } else {            await call(CottonMethod.assistantScope, YourClaude.GroupScope(group: group.id, access: access), table: group.id, sayDone: false)        }    }    /// Connect Claude: behind the phone's lock; the core says where to add it.    private func connect() async {        guard let core else { return }        busy = true        let handed = await VaultAccess().handing(CottonMethod.assistantConnect, through: core) { key in YourClaude.Signed(privateKey: key) }        take(handed, table: nil, sayDone: true)        busy = false        asked += 1    }    private func take(_ handed: VaultHanding, table: String?, sayDone: Bool) {        switch handed {        case .answered(let answered):            note = sayDone ? answered.text("said").map { (words: $0, table: table) } : nil        case .cancelled:            return        case .noPresence:            note = (words: ShellLines.line("unlock", "no_presence"), table: table)        case .refused(let words):            note = (words: words, table: table)        }    }    private func call(_ method: String, _ request: some Encodable & Sendable = EmptyRequest(), table: String?, sayDone: Bool = true) async {        guard let core else { return }        busy = true        do {            let answered = try await core.callJSON(method, request)            note = sayDone ? answered.text("said").map { (words: $0, table: table) } : nil        } catch {            note = (words: (error as? CottonCallError)?.message ?? ActionRefused.words(for: error), table: table)        }        busy = false        asked += 1    }}/// Acts and choices laid out in a row that wraps, at any text size.struct SettingsFlow: Layout {    var spacing: CGFloat    func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {        let width = proposal.width ?? .infinity        var x: CGFloat = 0, y: CGFloat = 0, line: CGFloat = 0, widest: CGFloat = 0        for view in subviews {            let size = view.sizeThatFits(.unspecified)            let w = min(size.width, width)            if x > 0, x + w > width { y += line + spacing; x = 0; line = 0 }            x += w + spacing            line = max(line, size.height)            widest = max(widest, x - spacing)        }        return CGSize(width: proposal.width ?? widest, height: y + line)    }    func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {        var x = bounds.minX, y = bounds.minY, line: CGFloat = 0        for view in subviews {            let size = view.sizeThatFits(.unspecified)            let w = min(size.width, bounds.width)            if x > bounds.minX, x + w > bounds.maxX { y += line + spacing; x = bounds.minX; line = 0 }            view.place(at: CGPoint(x: x, y: y), proposal: ProposedViewSize(width: w, height: size.height))            x += w + spacing            line = max(line, size.height)        }    }}#endif