// 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)importCottonKitimportSwiftUIimport UIKit// MARK: - The answers/// `shell.settings`' answer: the three parts drawn under Account.structSettingsAnswer: Decodable, Equatable, Sendable {structPart: Decodable, Equatable, Sendable {let id: Stringlet label: Stringvar line: String?let bytes: Int64?let said: String }structFreeUp: Decodable, Equatable, Sendable {let label: Stringlet bytes: Int64var line: String?var ask: String?var askBody: String?var confirm: String?enumCodingKeys: String, CodingKey {case label, bytes, line, ask, confirmcase askBody = "ask_body" } }structStorage: Decodable, Equatable, Sendable {let title: Stringvar line: String?/// The whole kept on this phone, in words ("1.4 GB").var said: String?let parts: [Part]var freeUp: FreeUp?enumCodingKeys: String, CodingKey {case title, line, said, partscase freeUp = "free_up" } }structShare: Decodable, Equatable, Sendable {let label: Stringvar line: String?var previewTitle: String?var previewShare: String?var previewClose: String?enumCodingKeys: String, CodingKey {case label, linecase previewTitle = "preview_title"case previewShare = "preview_share"case previewClose = "preview_close" } }structHelp: Decodable, Equatable, Sendable {let title: Stringvar share: Share?/// The privacy policy and Help and contact, each opening its page on cottondb.com (store pass, 24 Nov 2026).var links: [Link]? }structLink: Decodable, Equatable, Sendable, Identifiable {let id: Stringlet label: Stringlet url: String }structFact: Decodable, Equatable, Sendable {var id: String?let label: Stringlet said: String }structAbout: Decodable, Equatable, Sendable {let title: Stringvar 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.structSettingsReport: Decodable, Equatable, Identifiable, Sendable {let title: String?let fileName: String?let text: Stringvar id: String { text }enumCodingKeys: String, CodingKey {case title, textcase fileName = "file_name" }}privatestructSettingsAsk: Encodable, Sendable { let commit: String }privatestructFreeUpAsk: Encodable, Sendable { let expected: Int64 }extensionSettingsAnswer {/// The build's commit, as every Account ask sends it.staticvar commit: String { (Bundle.main.object(forInfoDictionaryKey: "CottonBuildCommit") as? String) ?? "" }staticfunc read(_ core: any CottonCalling) async -> SettingsAnswer? {try? await asked(core) }/// The answer, or why it did not come.staticfunc asked(_ core: any CottonCalling) asyncthrows -> SettingsAnswer {tryawait 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).staticfunc freeUp(_ core: any CottonCalling, bytes: Int64) async -> String? {do {returntryawait core.callJSON(CottonMethod.shellFreeUp, FreeUpAsk(expected: bytes)).text("said") } catch {return (error as? CottonCallError)?.message ?? ActionRefused.words(for: error) } }}extensionSettingsReport {/// The report Share a report shows whole before anything goes.staticfunc read(_ core: any CottonCalling) asyncthrows -> SettingsReport {tryawait 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. @MainActorfunc 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).structSettingsLook {var ink: Colorvar quiet: Color/// The rule between rows; clear where the app draws none.var rule: Color/// The report sheet's ground.var ground: Colorvar body: Fontvar 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).structSettingsParts<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) privatevar sync @Environment(\.openURL) privatevar openURL @State privatevar answer: SettingsAnswer?/// Why the first answer did not come, in the core's words (DATA iPhone 3: Storage stood with its title alone). @State privatevar failed: String? @State privatevar reads = ReadInTurn() @State privatevar asked = 0 @State privatevar asking = false @State privatevar report: SettingsReport?/// The report Share was pressed on, shared once its preview has gone. @State privatevar sharing: SettingsReport?var body: someView { VStack(alignment: .leading, spacing: 0) {iflet answer {iflet storage = answer.storage, shows("storage") { storagePart(storage) }iflet help = answer.help, let share = help.share, shows("help") { helpPart(help, share) }iflet about = answer.about, shows("about") { aboutPart(about) } } elseif only != nil {// A part on its own page is never its title alone: Loading… at once, else why it did not come.iflet 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)") {guardlet core else { return } reads.ask {do { answer = tryawaitSettingsAnswer.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" ) {guardlet bytes = answer?.storage?.freeUp?.bytes, bytes > 0else { 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 iniflet share = answer?.help?.share {SettingsReportSheet(share: share, text: shown.text, look: look, close: { report = nil }) { sharing = shown report = nil } } } }privatefunc shows(_ part: String) -> Bool { only == nil || only == part }/// The part's heading in the list; on its own page the header names it. @ViewBuilder privatefunc heading(_ title: String) -> someView {if only == nil { look.heading(title) } }privatefunc storagePart(_ storage: SettingsAnswer.Storage) -> someView { VStack(alignment: .leading, spacing: 0) { heading(storage.title)if only != nil {iflet whole = storage.said {Text(verbatim: whole).font(look.title ?? look.body).foregroundStyle(look.ink) .accessibilityIdentifier("settings-storage-whole") }iflet kept { quietLine(kept).padding(.top, 4) } } elseiflet line = storage.line { quietLine(line).padding(.top, 8) }ForEach(storage.parts, id: \.id) { part inSettingsPartRow(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.iflet line = storage.line, let end = line.range(of: ". ") { quietLine(String(line[end.upperBound...])).padding(.top, 8).accessibilityIdentifier("settings-storage-room") } }iflet free = storage.freeUp {iflet 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") }privatefunc helpPart(_ help: SettingsAnswer.Help, _ share: SettingsAnswer.Share) -> someView { VStack(alignment: .leading, spacing: 0) { heading(help.title)if only != nil { look.heading(SettingsWords.line("help_wrong")) }iflet 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").iflet links = help.links, !links.isEmpty { VStack(spacing: 0) {ForEach(links) { link inSettingsGoRow(label: link.label, line: nil, look: look, id: "settings-link-\(link.id)") {iflet url = URL(string: link.url) { openURL(url) } } } } .padding(.top, 16) } } .accessibilityElement(children: .contain) .accessibilityIdentifier("settings-help") }privatefunc aboutPart(_ about: SettingsAnswer.About) -> someView { 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") }iflet 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 inSettingsPartRow(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") }privatefunc quietLine(_ words: String) -> someView {Text(verbatim: words) .font(look.small) .foregroundStyle(look.quiet) .fixedSize(horizontal: false, vertical: true) }privatefunc freeUp(_ bytes: Int64) async {guardlet core else { return }iflet words = awaitSettingsAnswer.freeUp(core, bytes: bytes) { said(words) } asked += 1 }privatefunc readReport() async {guardlet core else { return }do { report = tryawaitSettingsReport.read(core) } catch { said((error as? CottonCallError)?.message ?? ActionRefused.words(for: error)) } }/// Share opens the share sheet once the preview has gone.privatefunc shareAfterPreview() {guardlet shown = sharing else { return } sharing = nil shown.share() }}extensionSettingsPartswhereMore == 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.structSettingsPartRow: View {let label: Stringlet said: Stringlet line: String?let look: SettingsLooklet id: Stringvar body: someView { VStack(spacing: 0) { HStack(alignment: .firstTextBaseline, spacing: 12) { VStack(alignment: .leading, spacing: 2) {Text(verbatim: label).font(look.body).foregroundStyle(look.ink)iflet 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.structSettingsReportSheet: View {let share: SettingsAnswer.Sharelet text: Stringlet look: SettingsLooklet close: () -> Voidlet onShare: () -> Void @ViewBuilder privatevar acts: someView { look.act(share.previewClose ?? "", "settings-report-close", true, close) look.act(share.previewShare ?? "", "settings-report-share", true, onShare) }var body: someView { 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.structLoadingLine: View {let bringing: HomeAnswer.Bringing?let ink: Colorvar track: Color?var font: Font = .system(size: 13) @Environment(BootModel.self) privatevar boot: BootModel?/// How often the home is asked again while the line stands (Android's `Loading.TICK_MS`).staticlet tick: Duration = .seconds(1)var body: someView {iflet 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? awaitTask.sleep(for: Self.tick)await boot?.ask() } } } }}/// The thin bar: `percent` filled, or, while it is nil, a quarter moving on its own.privatestructLoadingBar: View {let percent: Int?let ink: Colorlet track: Colorvar body: someView {GeometryReader { box inlet width = box.size.width ZStack(alignment: .leading) {Rectangle().fill(track)iflet percent {Rectangle().fill(ink).frame(width: width * CGFloat(min(max(percent, 0), 100)) / 100) } else {TimelineView(.animation) { time inlet at = time.date.timeIntervalSinceReferenceDate.truncatingRemainder(dividingBy: 1.4) / 1.4let w = width * 0.25Rectangle().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.structYourClaudePart: 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) privatevar sync @State privatevar screen: JSONValue? @State privatevar asked = 0 @State privatevar busy = false/// What an act said: under the acts, or under the table it was said of. @State privatevar note: (words: String, table: String?)?var body: someView { VStack(alignment: .leading, spacing: 10) {iflet 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 inText(verbatim: said).font(look.body).foregroundStyle(look.ink) .accessibilityIdentifier("account-your-claude-connection") }iflet none = mine.none {Text(verbatim: none).font(look.small).foregroundStyle(look.quiet) .accessibilityIdentifier("account-your-claude-none") }SettingsFlow(spacing: 10) {iflet offer = mine.connect { look.act(offer, "account-your-claude-connect", !busy) { Task { await connect() } } }iflet remove = mine.remove { look.act(remove, "account-your-claude-remove", !busy) { Task { await call(CottonMethod.assistantRemove, table: nil) } } } }iflet 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.iflet 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")iflet line = reading.line {Text(verbatim: line).font(look.small).foregroundStyle(look.quiet) .fixedSize(horizontal: false, vertical: true) }iflet 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) } } } }iflet note, note.table == group.id { said(note.words) } } .accessibilityElement(children: .contain) .accessibilityIdentifier("account-your-claude-group-\(group.id)") }iflet note = mine.reading?.note {Text(verbatim: note).font(look.small).foregroundStyle(look.quiet) .fixedSize(horizontal: false, vertical: true) .accessibilityIdentifier("account-your-claude-groups-note") } } elseif !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) } } } }iflet 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)") {guardlet core else { return }iflet read = try? await core.callJSON(CottonMethod.assistantScreen) { screen = read } } }privatefunc said(_ words: String) -> someView {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.privatefunc scope(_ table: YourClaude.Table, to access: String) async {guardlet core else { return }if access == "on", table.needsLock { busy = truelet name = table.tablelet handed = awaitVaultAccess().handing(CottonMethod.assistantScope, through: core) { key inYourClaude.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.privatefunc scope(_ group: YourClaude.Group, to access: String) async {guardlet core else { return }if access == "on", group.needsLock { busy = truelet id = group.idlet handed = awaitVaultAccess().handing(CottonMethod.assistantScope, through: core) { key inYourClaude.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.privatefunc connect() async {guardlet core else { return } busy = truelet handed = awaitVaultAccess().handing(CottonMethod.assistantConnect, through: core) { key inYourClaude.Signed(privateKey: key) } take(handed, table: nil, sayDone: true) busy = false asked += 1 }privatefunc take(_ handed: VaultHanding, table: String?, sayDone: Bool) {switch handed {case .answered(let answered): note = sayDone ? answered.text("said").map { (words: $0, table: table) } : nilcase .cancelled:returncase .noPresence: note = (words: ShellLines.line("unlock", "no_presence"), table: table)case .refused(let words): note = (words: words, table: table) } }privatefunc call(_ method: String, _ request: someEncodable & Sendable = EmptyRequest(), table: String?, sayDone: Bool = true) async {guardlet core else { return } busy = truedo {let answered = tryawait 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.structSettingsFlow: Layout {var spacing: CGFloatfunc sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {let width = proposal.width ?? .infinityvar x: CGFloat = 0, y: CGFloat = 0, line: CGFloat = 0, widest: CGFloat = 0for 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 = 0for 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