importCottonKitimportSwiftUI/// What a personal table's page draws while its own database is not yet in/// hand: never blank cream for good (architect, 14 Oct 2026 — the fan's/// Machines page drew nothing while the held list was unread). A skeleton/// while the held list is on its way, else why the records cannot be read.enumPersonalScopeWait: Equatable {case readingcase unread(title: String, message: String, retries: Bool)staticfunc says(plural: String, core: Bool, listed: Bool?, refusal: String?, personal: String?) -> Self {let title = ShellLines.line("reading", "list.could_not_read", ["plural": plural])guard core, let listed else { return .unread(title: title, message: Words.noRecords, retries: false) }if personal != nil || !listed { return .reading }iflet refusal { return .unread(title: title, message: refusal, retries: true) }return .unread(title: title, message: Words.noPersonal, retries: true) }enumWords {staticvar noRecords: String { ShellLines.line("boot", "personal.no_records") }staticvar noPersonal: String { ShellLines.line("boot", "personal.no_personal") }staticvar retry: String { ShellLines.line("boot", "personal.retry") } }}/// A personal tool keeps its own database even while the window shows another./// The content uses the ordinary record surfaces and the native record store.structPersonalRecordScope<Content: View>: View {/// The table's plural, for the words while it waits.let plural: Stringlet content: Content @Environment(\.cottonCore) privatevar core @Environment(\.records) privatevar parent @Environment(DatabasesModel.self) privatevar databases: DatabasesModel?/// The personal database's reader, made in the frame the page opens in:/// a local list never waits a frame behind a skeleton for it (owner,/// 15 Oct 2026: "we're on the local database, everything should load/// instantly"). One per identity, so the list's model keeps its store. @State privatevar made = Made()init(plural: String, @ViewBuilder content: () -> Content) {self.plural = pluralself.content = content() }privatestructIdentity: Hashable {let backend: ObjectIdentifier?let personal: String?let corePresent: Bool }privatevar identity: Identity {Identity(backend: parent.map { ObjectIdentifier($0) }, personal: databases?.held.first(where: \.isPersonal)?.databaseId, corePresent: core != nil) }var body: someView {Group {iflet records = made.records(for: identity, core: core) { content.environment(\.records, records) } else { waiting } }// The page needs the held list: it asks for it when nobody has yet. .task {iflet databases, !databases.listed { await databases.refresh() } } }/// Holds the reader across draws without being state a draw writes. @MainActor privatefinalclassMade {privatevar built: (identity: Identity, records: CoreRecords)?func records(for identity: Identity, core: (any CottonCalling)?) -> CoreRecords? {iflet built, built.identity == identity { return built.records }guardlet core, let personal = identity.personal else { returnnil }let records = CoreRecords(core: DatabaseScopedCore(underlying: core, database: personal)) built = (identity, records)return records } } @ViewBuilder privatevar waiting: someView {let says = PersonalScopeWait.says( plural: plural, core: core != nil, listed: databases?.listed, refusal: databases?.readRefusal, personal: identity.personal)PaperScreen {switch says {case .reading:SkeletonPage(identifier: "personal-scope-reading")case .unread(let title, let message, let retries):QuietState( title: title, message: message, actionLabel: retries ? PersonalScopeWait.Words.retry : nil, action: retries ? { Task { await databases?.refresh() } } : nil) } } }}/// Session defaults (`/code/defaults`): drawn once this app's remembered/// model has reached the core (`CodeDefaults.carryOver`), so the page's/// Model card reads the device's choice rather than none.structCodeDefaultsCarried<Content: View>: View {let content: Content @Environment(\.cottonCore) privatevar core @State privatevar carried = false @State privatevar refused: String?init(@ViewBuilder content: () -> Content) { self.content = content() }var body: someView {Group {if carried { content } elseiflet refused {PaperScreen { QuietState(title: ShellLines.line("boot", "defaults.unread_title"), message: refused, actionLabel: ShellLines.line("refusal", "actions.try_again"), action: { self.refused = nil }) } } else {PaperScreen { EmptyView() } } } .task(id: refused == nil) {guardlet core, !carried, refused == nilelse { return }do {tryawaitCodeDefaults.carryOver(core) carried = true } catchlet said asActionRefused { refused = said.sentence } catch { refused = ShellLines.line("empty", "unchanged") } } }}