// FlavourManifest.swift — which app this build is.//// One tree builds Cotton and, beside it, Cotton Development and one app per// business (`project.yml`'s `businessFlavours`). Each bundle carries its// manifest as `flavour.json`: its name, how many databases it shows and which// (`database`), and its Home — the board its root page// draws, section by section, which the core holds in place of Cotton's Home.// Cotton's manifest (`App/CottonManifest`) names Personal and no Home, so it// draws the shipped one. A bundle with none — the Mac app, a test bundle —// shows every database. Its fan holds the database's tools, package// records: an app whose manifest names its kit (`"kit": "books"`) keeps to// the kit's tools and tables, signed in or not, and one that names none// (Cotton) to the whole object; the core reads it (`kit::AppKit`), never// the screens. The app reads it once at launch and// hands it to the core unchanged (`CottonConfig.manifest`); the screens read the// same value here.importFoundationpublicstructFlavourManifest: Codable, Equatable, Sendable {/// The flavour's name in `project.yml` — `sharmila`.publicvar flavour: String/// Whether a fresh install may start its own Personal database.publicvar genesis: GenesispublicenumGenesis: String, Codable, Sendable { case personal, none }/// The app's name, as the business says it.publicvar name: String/// `single`: one database shown, no caps and no Databases screen;/// `only`: one database ever.publicvar databases: Databases/// Which database the app shows — `"personal"`, or one database by its id/// and the host it signs in at: `{"id", "host", "named"}`. None is every/// database it holds. The core reads it (`shell::scope`).publicvar database: JSONValue?/// The app's Home: a board (`boards/home.json`'s shape) whose parts are the/// root page's sections, in order. Handed to the core whole, which holds/// it as this app's Home. None: the shipped Home (Cotton's own); every/// business app names one (`HomeNeverMeTests`).publicvar home: JSONValue?/// Which of Cotton's own cards the dial holds beside the tools (`fan`):/// absent, Home and Tools; Rigby holds no Home and no Tools card and ends/// in a Settings card (owner and architect, 22 Oct 2026); Cotton keeps/// Home and Tools and ends in the same Settings card, so its owner exports/// from it as from Rigby (the owner, 23 Oct 2026).publicvar fan: FanpublicstructFan: Codable, Equatable, Sendable {publicvar home: Boolpublicvar tools: Bool/// A Settings card last on the dial: the settings list, reachable/// from every page by the dial.publicvar settings: Bool/// The tool the dial opens on; with Home kept beside it, Home is/// dealt last (Cotton Music). Nil, the dial opens on Home, else its/// first card.publicvar opens: String?/// The app's face is one stream of the conversations of the tool it/// opens on (Cotton Messages): no fan and no hub are drawn, and the/// core names the chats (`shell.stream`). Absent, the fan.publicvar stream: Boolpublicinit(home: Bool = true, tools: Bool = true, settings: Bool = false, opens: String? = nil, stream: Bool = false) {self.home = homeself.tools = toolsself.settings = settingsself.opens = opensself.stream = stream }publicinit(from decoder: Decoder) throws {let keys = try decoder.container(keyedBy: CodingKeys.self) home = try keys.decodeIfPresent(Bool.self, forKey: .home) ?? true tools = try keys.decodeIfPresent(Bool.self, forKey: .tools) ?? true settings = try keys.decodeIfPresent(Bool.self, forKey: .settings) ?? false opens = try keys.decodeIfPresent(String.self, forKey: .opens) stream = try keys.decodeIfPresent(Bool.self, forKey: .stream) ?? false }/// Written as the manifest says it: only the keys that differ from/// Cotton's own answer, which is what the core reads an absent key/// as (`FanCards`) — so `{"tools": false}` crosses as written and not/// as a whole dial the file never said (Nancy's, 23 Oct 2026).publicfunc encode(to encoder: Encoder) throws {var keys = encoder.container(keyedBy: CodingKeys.self)if !home { try keys.encode(home, forKey: .home) }if !tools { try keys.encode(tools, forKey: .tools) }if settings { try keys.encode(settings, forKey: .settings) }try keys.encodeIfPresent(opens, forKey: .opens)if stream { try keys.encode(stream, forKey: .stream) } }privateenumCodingKeys: String, CodingKey { case home, tools, settings, opens, stream }/// The dial of a manifest that says no `fan`: Home and Tools, no/// Settings card. Cotton's own until its manifest named the Settings/// card (the owner, 23 Oct 2026); every business app's still.publicstaticlet cottons = Fan() }/// Whether this app syncs at all (`sync`): absent, true, as in Cotton./// Rigby says false — one device, no Mac — and the core reads the same/// key from the manifest it is handed (architect, 22 Oct 2026).publicvar sync: Bool/// The business's object this app runs against (`business`): the/// Worker's address and the business's slug. Named, the app opens on the/// business's shell (`CustomerShell`), every page drawn from what the/// object answers; none, it is Cotton's frame. Cotton's names its server/// per side of the build, so Cotton Dev signs in at the dev Worker/// (`BusinessAddress`).publicvar business: BusinessAddress?/// The ground this app stands on (`ground`), a `FaceGround` by its id:/// the material its icon's object stands on (the calendar's kitchen tile,/// the people's amethyst desk). The launch screen and the splash are laid/// on its tile, and wherever a card or a page would lie on/// the shell's paper the app lays its ground instead. Absent, Cotton's/// paper (Cotton, Rigby, a business app).publicvar ground: String?/// The ground this app LAUNCHES on (`launch`), where it stands on none of/// its own: Messages' chats lie on the shell's paper, and its launch/// screen and splash are still its icon's pegboard with the object on it/// (owner, 15 Nov 2026: build 5 launched bare, because `ground` was the/// one switch for both). Absent, the app launches on `ground`.publicvar launch: String?/// The owner's personal object this app's database is (Cotton): a/// personal app whose manifest names an object. It signs in as a business/// app does and then opens on Cotton's own frame, its decks reading the/// phone's copy (`personal.connect`).publicvar personalObject: BusinessAddress? { genesis == .personal ? business : nil }/// THE FILE AS THE BUNDLE CARRIES IT, every key — what crosses to the core/// (`CottonConfig.manifest`) with this struct's own fields laid over it./// The core reads keys the app never does (`database`, `web`); re-encoding/// only this struct's fields dropped them, and Cotton Development opened/// on Personal (walk, 19 Oct 2026).privatevar whole: [String: JSONValue] = [:]publicenumDatabases: String, Codable, Sendable {/// One database shown at a time.case singlecase many/// Exactly one database ever: no new, no join, no Databases screen/// (Rigby; architect, 22 Oct 2026). Shown as `single` everywhere.case only }privateenumCodingKeys: String, CodingKey {case flavour, genesis, name, databases, database, home, business, fan, sync, ground, launch }publicinit(from decoder: Decoder) throws {let keys = try decoder.container(keyedBy: CodingKeys.self) flavour = try keys.decode(String.self, forKey: .flavour)if keys.contains(.genesis) { genesis = try keys.decode(Genesis.self, forKey: .genesis) }else { genesis = .personal } name = try keys.decode(String.self, forKey: .name) databases = try keys.decode(Databases.self, forKey: .databases) database = try keys.decodeIfPresent(JSONValue.self, forKey: .database) home = try keys.decodeIfPresent(JSONValue.self, forKey: .home) business = try keys.decodeIfPresent(BusinessAddress.self, forKey: .business) fan = try keys.decodeIfPresent(Fan.self, forKey: .fan) ?? .cottons sync = try keys.decodeIfPresent(Bool.self, forKey: .sync) ?? true ground = try keys.decodeIfPresent(String.self, forKey: .ground) launch = try keys.decodeIfPresent(String.self, forKey: .launch)ifcase .object(let all) = try JSONValue(from: decoder) { whole = all } }publicfunc encode(to encoder: Encoder) throws {var all = whole all["flavour"] = .string(flavour) all["genesis"] = .string(genesis.rawValue) all["name"] = .string(name) all["databases"] = .string(databases.rawValue) all["database"] = database all["home"] = home// Absent is Home and Tools, so a manifest that never said it stays unsaid. all["fan"] = fan == .cottons ? nil : try JSONDecoder().decode(JSONValue.self, from: JSONEncoder().encode(fan))// Absent is a syncing app, so a manifest that never said it stays unsaid. all["sync"] = sync ? nil : .bool(false) all["ground"] = ground.map(JSONValue.string) all["launch"] = launch.map(JSONValue.string) all["business"] = try business.map { try JSONDecoder().decode(JSONValue.self, from: JSONEncoder().encode($0)) }try JSONValue.object(all).encode(to: encoder) }publicinit(flavour: String, name: String, databases: Databases, genesis: Genesis = .personal, database: JSONValue? = nil, home: JSONValue?, business: BusinessAddress? = nil, fan: Fan = .cottons, sync: Bool = true, ground: String? = nil) {self.flavour = flavourself.genesis = genesisself.name = nameself.databases = databasesself.database = databaseself.home = homeself.business = businessself.fan = fanself.sync = syncself.ground = ground }/// Whether the app launches flat (flavour.json `flat`): one colour of its/// own, light and dark, laid by its launch storyboard as `LaunchGround`/// (`scripts/gen-launch-screens.py`), with no ground's tiles under it.publicvar flat: Bool { whole["flat"] != nil }/// The bundle resource a business app carries.publicstaticlet resource = "flavour"/// A bundle's manifest: nil when it carries none (Cotton). A manifest that/// is there and does not read is a broken build, said out loud rather than/// opened as Cotton.publicstaticfunc of(_ bundle: Bundle) -> FlavourManifest? {guardlet url = bundle.url(forResource: resource, withExtension: "json") else { returnnil }do {returntry JSONDecoder().decode(FlavourManifest.self, from: Data(contentsOf: url)) } catch { fatalError("flavour.json in \(bundle.bundlePath) does not read: \(error)") } }/// This process's manifest.publicstaticlet current: FlavourManifest? = of(.main).map(onThisMachine)/// The launch arguments a SIMULATOR build may take in place of the/// manifest's business, so a walk runs against a synthetic business/// served on the Mac beside it/// (`-businessServer http://127.0.0.1:8787 -businessSlug <slug>`).publicstaticlet businessServerArgument = "businessServer"publicstaticlet businessSlugArgument = "businessSlug"/// The manifest as this machine runs it. On a device it is the bundle's,/// unchanged — a phone in a customer's hand signs in only where the/// business's manifest says (`FlavourOverrideTests`).staticfunc onThisMachine(_ manifest: FlavourManifest) -> FlavourManifest { #if targetEnvironment(simulator)let arguments = UserDefaults.standardreturn manifest .servingBusiness( server: arguments.string(forKey: businessServerArgument), slug: arguments.string(forKey: businessSlugArgument)) #elsereturn manifest #endif }/// This manifest with its business served elsewhere: both named, or/// unchanged; a manifest that names no business is unchanged. A manifest/// at the open host (Cotton's, no slug) moves its server alone: the/// override never makes Cotton a business (`FlavourOverrideTests`).publicfunc servingBusiness(server: String?, slug: String?) -> FlavourManifest {guardlet business, let server, !server.isEmpty else { returnself }var served = selfif business.slug == nil { served.business = BusinessAddress(server: server, window: business.window)return served }guardlet slug, !slug.isEmpty else { returnself } served.business = BusinessAddress(server: server, slug: slug, window: business.window)return served }/// One database on screen: no caps row and no Databases screen.publicvar isSingleDatabase: Bool { databases != .many }}extensionFlavourManifest {/// A sentence as this app says it: the word Cotton becomes the app's own/// name, so a business's customer never reads Cotton on a gate screen, in/// a refusal or in an error (lane phonewalk, 19 Oct 2026). Every table/// sentence goes through here (`CottonStrings.local`), and so does every/// error's words (`CottonCallError`); Cotton's own build says Cotton.publicstaticfunc said(_ text: String, by manifest: FlavourManifest? = current) -> String {ShellLines.said(text, as: manifest?.name) }}