// THE ACCOUNT CARD'S PAGE (owner, 11 Nov 2026): this phone's sign-in and its// sync, one card, the first to the LEFT of the app's first card in every// Cotton app. The core answers it whole (`shell.account`,// `crates/cotton-ffi/src/methods/shell_account.rs`): who is signed in, the// app and its build, the database and the Worker's host, the last sync, the// rows waiting and the rows here, the last error — every line a kit line —// and the acts that stand now (Sign in; Back up now and Sign out). This page// draws that card on the plain face, whole in one screenshot, and turns the// fan into its acts on a tap or a hold; a tap on one runs it as every tool// act runs (`EditingFan.runTool`, `tools.act`). It decides nothing.//// YOUR PEOPLE (14 Nov 2026), part of the same answer while signed in: the// people this person connects with, one relationship with Cotton chat's.// A card says who they are (asking, waiting, connected, in the core's order,// each section's names on it) and its fan holds Add a person, whose number is// typed in the short-text input (`DeckEditor.addPerson`, the same add Send's// tier opens); a card after it for each person, whose fan holds the acts the// core answered (Accept, Refuse, Block, Remove), each run as the core named// its call.//// RECOVERY AND WHAT ASSISTANTS READ (16 Nov 2026; e2e// rulings R4, R7c, R7d), two more cards on the same plain face, every word// the core's: on a phone holding the vault, the recovery card (the code's// line, the iCloud Keychain copy, who can help) whose fan holds Show my// recovery code, Make a new code and Ask someone to help, each behind the// phone's lock (`Boot/RecoveryKeys.swift`), and the code itself while shown// with Copy and Done; and What assistants read (`unlock.reads`): the latest// reads.//// OPEN ACCESS (the owner, 17 Nov 2026), right after the Account card while// any window is open (`OpenAccess.swift`, `unlock.windows`): each window by// its assistant, its tables and the time left, and End on each on the fan.// It replaced the standing banner at the foot; no window, no card.//// PASSKEYS (19 Nov 2026; Android's `PasskeyPart.kt`), after// recovery's while signed in (`signin.passkeys`): the heading and its line,// Add a passkey on its fan (the system sheet, `AccountPasskeySheet`), then a// card for each passkey, whose fan holds Remove, asked first on the slip.importCottonFacesimportCottonKitimportCottonPaperimportCottonValuesimportSwiftUI/// `shell.account`'s answer.structAccountAnswer: Decodable, Sendable {structFact: Decodable, Equatable, Sendable {/// Which fact (`app`, `database`, `synced`, `waiting`, `here`, `sent_up`, `error`).var id: String?let label: Stringlet said: String }structCard: Decodable, Equatable, Sendable {let title: Stringlet subtitle: Stringlet facts: [Fact] }/// Your people: each person and what can be done with them.structPeople: Decodable, Equatable, Sendable {structAct: Decodable, Equatable, Sendable {structCall: Decodable, Equatable, Sendable {let method: Stringlet request: JSONValue }let id: Stringlet words: Stringvar red: Bool?var primary: Bool?let call: Call }structRow: Decodable, Equatable, Sendable {let number: Stringlet words: Stringvar detail: String?var initials: String?var acts: [Act]? }structSection: Decodable, Equatable, Sendable {let id: Stringlet title: Stringlet rows: [Row] }let title: Stringlet add: SendAdd?var sections: [Section]?/// Nobody yet, or the object out of reach, in the core's words.var empty: String?var unreachable: String?/// Each person in the core's order, with the section they stand in.var rows: [(section: Section, row: Row)] { (sections ?? []).flatMap { section in section.rows.map { (section, $0) } } } }let line: Stringlet stand: Stringlet card: Card/// This phone cannot reach the person's database now (the sync stopped, a sign-in or backup that did not finish).var trouble: Bool?let actions: [CardAction]let tile: FanTileLook?var people: People?/// The card as the plain face draws it: its title, who is signed in,/// and each line under its label.var drawn: DeckCard {DeckCard(face: "plain", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["title": .text(card.title),"subtitle": .text(card.subtitle),"facts": .list(card.facts.map { .object(["label": .text($0.label), "said": .text($0.said)]) }), ]) }/// Your people's card: each section under its title with its names; or/// why nobody stands there.staticfunc drawn(_ people: People) -> DeckCard {let facts: [RecordValue] = (people.sections ?? []).map { section in .object(["label": .text(section.title), "said": .text(section.rows.map(\.words).joined(separator: "\n"))]) }returnDeckCard(face: "plain", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["title": .text(people.title),"subtitle": .text(people.unreachable ?? people.empty ?? ""),"facts": .list(facts), ]) }/// One person's card: who they are, what stands between you, and where.staticfunc drawn(_ row: People.Row, in section: People.Section) -> DeckCard {DeckCard(face: "plain", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["title": .text(row.words),"subtitle": .text(row.detail ?? ""),"facts": .list([.object(["label": .text(section.title), "said": .text(row.number)])]), ]) }}extensionNotification.Name {/// Someone added from the short-text input (`DeckEditor.addPerson`): Account reads its people again.staticlet cottonPeopleChanged = Notification.Name("com.cottondb.people.changed")}structAccountPage: View {/// The card's id on the fan (`account`).let card: String/// The table of the tool whose views tier holds the card: what the acts/// fan stands over (`DeckEditTarget.emptyDeck`).let table: String @Environment(\.cottonCore) privatevar core @Environment(\.cottonSync) privatevar sync @Environment(\.deckEditor) privatevar editor @Environment(\.cottonHaptics) privatevar haptics @Environment(\.scenePhase) privatevar scenePhase @Environment(ToastCenter.self) privatevar toasts: ToastCenter? @State privatevar answer: AccountAnswer? @State privatevar recovery: RecoveryKeys? @State privatevar windows: JSONValue? @State privatevar claude: JSONValue? @State privatevar reads: JSONValue? @State privatevar passkeys: JSONValue?/// The passkey Remove was asked for, until the slip is answered. @State privatevar removing: AccountPasskeyRow?privatestructItem: Identifiable { let id: String }privatestructAsk: Encodable, Sendable { let commit: String }privatestructAsked: Hashable {var revision: Intvar pulled: String?var phase: Stringvar active: Bool }/// The Account card, Open access, recovery's and What assistants read/// while they stand, Your people's, then each person's.privatevar items: [Item] {guardlet answer else { return [] }var items = [Item(id: card)]ifOpenAccess(windows) != nil { items.append(Item(id: Self.openAccessCard)) }ifYourClaude(claude) != nil { items.append(Item(id: Self.claudeCard)) }if holdsVault { items.append(Item(id: Self.recoveryCard)) }if reads?.text("heading") != nil { items.append(Item(id: Self.readsCard)) }// The card stands where a passkey can be added here, or while one is kept, so it can be removed.if passkeys?.text("heading") != nil, Self.offersPasskey || !AccountPasskeyRow.all(passkeys).isEmpty { items.append(Item(id: Self.passkeysCard)) items += AccountPasskeyRow.all(passkeys).map { Item(id: Self.passkeyCard($0.id)) } }guardlet people = answer.people else { return items }return items + [Item(id: Self.peopleCard)] + people.rows.map { Item(id: Self.personCard($0.row.number)) } }staticlet peopleCard = "people"staticlet recoveryCard = "recovery"staticlet readsCard = "reads"staticlet openAccessCard = "open-access"staticlet claudeCard = "your-claude"staticlet passkeysCard = "passkeys"/// Whether this app and phone can make a Cotton passkey for the host the app signs in at (`PasskeyPlatform`).staticlet offersPasskey: Bool = FlavourManifest.current?.personalObject.map { PasskeyPlatform.offersHere(server: $0.server) } ?? falsestaticfunc passkeyCard(_ id: String) -> String { "passkey-\(id)" }/// Signed in on a phone holding the vault: recovery's card stands.privatevar holdsVault: Bool {guardlet status = recovery?.status else { returnfalse }return status.flag("signedIn") && status.flag("holdsVault") }staticfunc personCard(_ number: String) -> String { "person-\(number)" }var body: someView {CardDeck(items: items, emptyLine: "", open: { offer($0.id) }, holds: { offer($0.id) }) { item iniflet answer {PlainFace(card: drawn(item.id, in: answer)) .onCardPaper(.framed) } } .confirmDecision(item: $removing, title: \.confirm, message: { _ in"" }, confirmLabel: \.remove, identifier: "passkey-remove-confirm") { row inTask { await removePasskey(row) } } .preference(key: FanPageReadingPreference.self, value: FanPageReading(filled: answer != nil)) .onReceive(NotificationCenter.default.publisher(for: .cottonPeopleChanged)) { _ inTask { await read() } }// It moves with the sync and with a sign-in made over it: read on// each pass, as the app comes back, and every few seconds. .task(id: Asked(revision: sync?.revision ?? 0, pulled: sync?.lastPullAt, phase: sync?.loop?.state ?? "", active: scenePhase == .active)) {while !Task.isCancelled {await read()try? awaitTask.sleep(for: .seconds(HomeSyncKnobs.every)) } } }privatefunc read() async {guardlet core else { return }let ask = Ask(commit: (Bundle.main.object(forInfoDictionaryKey: "CottonBuildCommit") as? String) ?? "")iflet next = try? await core.call(CottonMethod.shellAccount, ask, as: AccountAnswer.self) { answer = next }if recovery == nil { recovery = RecoveryKeys(core: core, vault: VaultAccess(), say: { [toasts] words, tone in toasts?.show(words, tone: tone) }) }await recovery?.refresh() windows = try? await core.callJSON(CottonMethod.unlockWindows) claude = try? await core.callJSON(CottonMethod.assistantScreen) reads = try? await core.callJSON(CottonMethod.unlockReads)// Signed in only: a phone with no door to its object answers nothing, and no card stands. passkeys = try? await core.callJSON(CottonMethod.signinPasskeys) }/// Passkeys' card: the heading, and how many sign in (or how to start).privatefunc passkeysDrawn() -> DeckCard {DeckCard(face: "plain", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["title": .text(passkeys?.text("heading") ?? ""),"subtitle": .text(passkeys?.text("line") ?? ""),"facts": .list([]), ]) }/// Add a passkey: the creation request, the system sheet, then the passkey kept at the object.privatefunc addPasskey() async {guardlet core else { return } #if os(iOS)do {let options = tryawait core.callJSON(CottonMethod.signinPasskeyOptions)guardlet request = options.text("requestJson") else { throwCottonCallError(code: "passkey_refused", message: "") }let response: Stringdo { response = tryawaitAccountPasskeySheet.add(requestJSON: request) } catchAccountPasskeyRefusal.cancelled { toasts?.show(SignInWords.passkeyCancelled)return } catch {throwCottonCallError(code: "passkey_refused", message: "") }structAdd: Encodable, Sendable { let responseJson: String; let name: String }let said = tryawait core.callJSON(CottonMethod.signinPasskeyAdd, Add(responseJson: response, name: ThisPhone.deviceName()))iflet words = said.text("said") { toasts?.show(words, tone: .success) } } catchlet error asCottonCallError { toasts?.show(HomeCustomerRefusal.line(code: error.code, business: ShellLines.speaker ?? ""), tone: .error) } catch { toasts?.show(ActionRefused.words(for: error), tone: .error) } #endifawait read() }privatefunc removePasskey(_ row: AccountPasskeyRow) async {guardlet core else { return }structRemove: Encodable, Sendable { let id: String; let name: String }do {let said = tryawait core.callJSON(CottonMethod.signinPasskeyRemove, Remove(id: row.id, name: row.name))iflet words = said.text("said") { toasts?.show(words) } } catch { toasts?.show((error as? CottonCallError)?.message ?? ActionRefused.words(for: error), tone: .error) }await read() }/// Recovery's card: the code's line (no code yet, out of date, or made/// on its date), the iCloud copy's line, who can help, and the code/// itself while shown.privatefunc recoveryDrawn() -> DeckCard {let status = recovery?.statuslet code = status?["code"]let title: String?if code?.text("made") == nil { title = recovery?.line("offer") } elseif code?.maybeFlag("current") == false { title = recovery?.line("stale") } else { title = code?.text("line") }var facts: [RecordValue] = []iflet helper = status?["trusted"]?.text("line") { facts.append(.object(["label": .text(""), "said": .text(helper)])) }iflet shown = recovery?.shown { facts.append(.object(["label": .text(""), "said": .text(shown.code)])) }let apple = status?["apple"]?.text("made") != nil ? recovery?.line("appleKept") : nilreturnDeckCard(face: "plain", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["title": .text(title ?? ""),"subtitle": .text(apple ?? ""),"facts": .list(facts), ]) }/// What assistants read: the latest reads; or that none read anything/// yet. The open windows stand on Open access.privatefunc readsDrawn() -> DeckCard {let facts: [RecordValue] = (reads?.list("reads") ?? []).compactMap { read in read.text("said").map { .object(["label": .text(""), "said": .text($0)]) } }returnDeckCard(face: "plain", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["title": .text(reads?.text("heading") ?? ""),"subtitle": .text(facts.isEmpty ? reads?.text("none") ?? "" : ""),"facts": .list(facts), ]) }privatefunc drawn(_ id: String, in answer: AccountAnswer) -> DeckCard {if id == Self.recoveryCard { return recoveryDrawn() }if id == Self.readsCard { return readsDrawn() }if id == Self.openAccessCard, letopen = OpenAccess(windows) { returnopen.drawn }if id == Self.claudeCard, let mine = YourClaude(claude) { return mine.drawn }if id == Self.passkeysCard { return passkeysDrawn() }iflet row = AccountPasskeyRow.all(passkeys).first(where: { Self.passkeyCard($0.id) == id }) { return row.drawn }guardlet people = answer.people else { return answer.drawn }if id == Self.peopleCard { returnAccountAnswer.drawn(people) }iflet person = people.rows.first(where: { Self.personCard($0.row.number) == id }) {returnAccountAnswer.drawn(person.row, in: person.section) }return answer.drawn }/// The fan becomes the card's acts, as the core says they stand now:/// the Account card's tool acts, Your people's Add a person, or a/// person's acts.privatefunc offer(_ id: String) {guardlet editor else { return } haptics.press()Task {await read()guardlet answer else { return }let target = DeckEditTarget.emptyDeck(of: table)if id == Self.recoveryCard, let recovery { editor.offer(recoveryOffers(recovery, answer: answer, target: target), for: target) } elseif id == Self.passkeysCard, Self.offersPasskey, let add = passkeys?.text("add") { editor.offer([DeckOffer(id: "passkey-add", word: add, primary: true, tile: answer.tile) { _ inawait addPasskey() }], for: target) } elseiflet row = AccountPasskeyRow.all(passkeys).first(where: { Self.passkeyCard($0.id) == id }) { editor.offer([DeckOffer(id: "passkey-remove", word: row.remove, tile: answer.tile) { _ in removing = row }], for: target) } elseif id == Self.claudeCard, let mine = YourClaude(claude) { editor.offer(claudeOffers(mine, answer: answer, target: target), for: target) } elseif id == Self.openAccessCard || id == Self.readsCard { editor.offer(endOffers(answer: answer), for: target) } elseif id == Self.peopleCard, let add = answer.people?.add { editor.offer([DeckOffer(id: "people-add", word: add.words, tile: answer.tile) { _ in editor.addPerson(add, core: core) }], for: target) } elseiflet person = answer.people?.rows.first(where: { Self.personCard($0.row.number) == id }) {let acts = (person.row.acts ?? []).map { act inDeckOffer(id: "people-\(act.id)", word: act.words, primary: act.primary == true, tile: answer.tile) { _ inawait run(act) } } editor.offer(acts, for: target) } else { editor.openToolActs(answer.actions, for: target, tile: answer.tile) } } }/// Recovery's acts: Copy and Done while the code is shown; else Show my/// recovery code (while the code is current), Make a new code, and Ask/// someone to help, which deals the person's connected people.privatefunc recoveryOffers(_ recovery: RecoveryKeys, answer: AccountAnswer, target: DeckEditTarget) -> [DeckOffer] {var offers: [DeckOffer] = []let word = { (key: String) in recovery.line(key) }if recovery.shown != nil {iflet copy = word("copy") { offers.append(DeckOffer(id: "recovery-copy", word: copy, tile: answer.tile) { _ in recovery.copy() }) }iflet done = word("done") { offers.append(DeckOffer(id: "recovery-done", word: done, tile: answer.tile) { _ inawait recovery.dismiss() }) }return offers }let code = recovery.status?["code"]if code?.text("made") != nil, code?.maybeFlag("current") != false, let show = word("show") { offers.append(DeckOffer(id: "recovery-show", word: show, tile: answer.tile) { _ inawait recovery.show() }) }iflet make = word("makeNew") { offers.append(DeckOffer(id: "recovery-make", word: make, tile: answer.tile) { _ inawait recovery.makeNew() }) }let people = answer.people?.sections?.first { $0.id == Self.connected }?.rows ?? []if !people.isEmpty, let ask = word("askHelp") { offers.append(DeckOffer(id: "recovery-ask", word: ask, tile: answer.tile) { _ iniflet pick = word("helperPick") { toasts?.show(pick) } editor?.offer(people.map { person inDeckOffer(id: "recovery-trust-\(person.number)", word: person.words, tile: answer.tile) { _ inawait recovery.trust(number: person.number, name: person.words) } }, for: target) }) }return offers }/// Your Claude's acts: each table (a tap deals its three settings),/// Remove, and Connect Claude.privatefunc claudeOffers(_ mine: YourClaude, answer: AccountAnswer, target: DeckEditTarget) -> [DeckOffer] {var offers: [DeckOffer] = mine.tables.map { table inDeckOffer(id: "claude-table-\(table.table)", word: "\(table.label) · \(table.said)", tile: answer.tile) { _ in editor?.offer(table.choices.filter { !$0.on }.map { choice inDeckOffer(id: "claude-\(table.table)-\(choice.access)", word: choice.label, tile: answer.tile) { _ inawait scope(table, to: choice.access) } }, for: target) } }iflet remove = mine.remove { offers.append(DeckOffer(id: "claude-remove", word: remove, tile: answer.tile) { _ inawait claudeCall(CottonMethod.assistantRemove) }) }iflet connect = mine.connect { offers.append(DeckOffer(id: "claude-connect", word: connect, primary: true, tile: answer.tile) { _ inawait connectClaude() }) }return offers }/// 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 {let name = table.tablelet handed = awaitVaultAccess().handing(CottonMethod.assistantScope, through: core) { key inYourClaude.SignedScope(table: name, access: access, privateKey: key) } sayHanded(handed, done: nil) } else {await claudeCall(CottonMethod.assistantScope, YourClaude.Scope(table: table.table, access: access)) }await read() }/// Connect Claude: behind the phone's lock; the core says where to add it.privatefunc connectClaude() async {guardlet core else { return }let handed = awaitVaultAccess().handing(CottonMethod.assistantConnect, through: core) { key inYourClaude.Signed(privateKey: key) } sayHanded(handed, done: nil)await read() }privatefunc sayHanded(_ handed: VaultHanding, done: String?) {switch handed {case .answered(let said):iflet words = said.text("said") ?? done { toasts?.show(words, tone: .success) }case .cancelled:returncase .noPresence: toasts?.show(ShellLines.line("unlock", "no_presence"), tone: .error)case .refused(let words): toasts?.show(words, tone: .error) } }privatefunc claudeCall(_ method: String, _ request: someEncodable & Sendable = EmptyRequest()) async {guardlet core else { return }do {let said = tryawait core.callJSON(method, request)iflet words = said.text("said") { toasts?.show(words) } } catch { toasts?.show((error as? CottonCallError)?.message ?? ActionRefused.words(for: error), tone: .error) }await read() }/// The section of Your people a helper is chosen from.staticlet connected = "people"/// End on each open window, named by its assistant.privatefunc endOffers(answer: AccountAnswer) -> [DeckOffer] {guardlet core, letopen = OpenAccess(windows) else { return [] }returnopen.rows.compactMap { row inguardlet word = open.endWord(row) else { returnnil }returnDeckOffer(id: "end-\(row.grantId)", word: word, tile: answer.tile) { _ indo {tryawaitOpenAccess.end(row, core: core)iflet receipt = open.end?.receipt { toasts?.show(receipt) } } catch { toasts?.show((error as? CottonCallError)?.message ?? ActionRefused.words(for: error), tone: .error) }await read() } } }/// One act on a person, run as the core named its call; what it says is/// said, and the people are read again.privatefunc run(_ act: AccountAnswer.People.Act) async {guardlet core else { return }do {let said = tryawait core.callJSON(act.call.method, act.call.request)iflet words = said["said"]?.string, !words.isEmpty { toasts?.show(words) } } catch { toasts?.show((error as? CottonCallError)?.message ?? ActionRefused.words(for: error), tone: .error) }await read() }}/// One passkey as `signin.passkeys` says it.structAccountPasskeyRow: Equatable, Identifiable {let id: Stringlet name: Stringlet when: Stringlet remove: Stringlet confirm: Stringstaticfunc all(_ answer: JSONValue?) -> [AccountPasskeyRow] { (answer?["passkeys"]?.array ?? []).compactMap { one inguardlet id = one.text("id"), let remove = one.text("remove") else { returnnil }returnAccountPasskeyRow(id: id, name: one.text("name") ?? "", when: one.text("when") ?? "", remove: remove, confirm: one.text("confirm") ?? remove) } }var drawn: DeckCard {DeckCard(face: "plain", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["title": .text(name), "subtitle": .text(when), "facts": .list([]), ]) }}