// Home's tiles, the figures under them, and the places found by name.//// The app ships no tool (owner's ruling, 21 Oct 2026: tools are records// only). Every tool it shows is a package record (`ToolDefinition`, from// `tools.list`), drawn as a data tile; `builtin` on a table definition says// only that its schema is code, never that it is a tool the app ships. The// few places found by name that are no table's tool — Projects, About, the// Tools screen — are said in `Resources/Places/places.json`.//// Every figure obeys **figure or silence**: a count appears only when it is// the number that would make you open the thing, and it says what it counts// (`TableToolFigure.words`). Every zero is silence.importCottonKitimportFoundation/// One row Find matches: a package tool or a place.////// `path` is a route PATH STRING, not a `Route` case, and deliberately: the/// design-system gallery renders/// them with nothing to navigate, and a value type that cannot be built without/// the router is a value type the tests have to launch an app to see.publicstructFindTool: Sendable, Equatable {publiclet key: String/// The proper noun the user reads.publiclet name: String/// kebab-case lucide glyph — never an emoji.publiclet icon: Stringpubliclet path: String/// The figure sentence, or `nil` for silence.publiclet figure: String?publicinit(key: String, name: String, icon: String, path: String, figure: String? = nil) {self.key = keyself.name = nameself.icon = iconself.path = pathself.figure = figure }}extensionFindTool: Identifiable {/// The tool's own key. A row is a TOOL, not a position: the arrange grid/// re-seats the same objects rather than replacing them, and a `ForEach`/// keyed by offset would give a moved object a new identity mid-drag.publicvar id: String { key }}/// One tile on Home: a VIEW of a tool (owner's ruling, 12 Oct 2026 — "a/// tile points at a view"), and whether it has nothing to show. An empty tile/// is drawn faint, after the ones that hold something, until it holds a record.publicstructHomeTile: Sendable, Equatable, Identifiable {/// The view's id: `tool/<key>` (a tool's list), `<tool>/<table>` (one/// table of a tool with several), `ready/today`, `chart/mood`,/// `<table>/<groupId>` (a group), or `ready/everything`.publiclet id: Stringpubliclet empty: Bool/// The tool whose picture the tile wears; nil for Everything.publiclet tool: String?/// The view's own name ("Today", a group's); nil names it by its tool.publiclet name: String?/// The path the tile opens, when the view's definition names one.publiclet opens: String?/// The table whose list the tile opens — one table of a tool with/// several. Said by the core, never parsed from the id, which has a/// group's shape.publiclet table: String?publicinit(id: String, empty: Bool = false, tool: String? = nil, name: String? = nil, opens: String? = nil, table: String? = nil) {self.id = idself.empty = emptyself.tool = tool ?? HomeTiles.toolKey(of: id)self.name = nameself.opens = opensself.table = table }/// The key the tile is drawn under: its tool's for the tool's own list,/// Everything's, else the view itself — one tile per view, so two views of/// one tool are two tiles.publicvar key: String { HomeTiles.tileKey(of: id) ?? id }}/// Home's tiles for the shown database, as `read.home`'s `arrangement`/// answers them (`crates/cotton-core/src/rules/home_arrangement.rs`).////// There is no "put away" (owner's ruling, 12 Oct 2026): a tool is in a/// database or it is not, and Home is an ordered list of view ids. The crate/// answers `tiles` ALREADY in draw order — the ones with something to show in/// the person's order, then the empty ones — and `viewIds`, the person's own/// order. The app only reads it: the arrangement is set over MCP alone/// (owner, 16 Oct 2026), never by a control in the app.publicstructHomeTiles: Sendable, Equatable {/// The tiles in draw order.publiclet tiles: [HomeTile]/// The person's order, as MCP last set it.publiclet viewIds: [String]/// The database's tools, by key, in the person's order.publiclet tools: [String]publicinit(tiles: [HomeTile], viewIds: [String]? = nil, tools: [String]? = nil) {self.tiles = tilesself.viewIds = viewIds ?? tiles.map(\.id)self.tools = tools ?? tiles.compactMap { Self.toolKey(of: $0.id) } }/// Everything's view: a shipped view over every table, not a tool.publicstaticlet everything = "ready/everything"privatestaticlet toolPrefix = "tool/"/// A tool's own view — its list.publicstaticfunc view(ofTool key: String) -> String { toolPrefix + key }/// The tool whose list `view` is; nil for any other view.publicstaticfunc toolKey(of view: String) -> String? {guard view.hasPrefix(toolPrefix) else { returnnil }let key = String(view.dropFirst(toolPrefix.count))return key.isEmpty ? nil : key }/// The key a tool's list or Everything is drawn under — the tool's own,/// or Everything's; nil for any other view, which is drawn under its id.publicstaticfunc tileKey(of view: String) -> String? { toolKey(of: view) ?? (view == everything ? HomeData.everythingKey : nil) }/// The tools Home's tiles wear (Everything's key for Everything), each/// once, in draw order — what the board lays out before it places a tile/// per view.publicvar keys: [String] {var seen: Set<String> = []return tiles.compactMap { tile inlet key = tile.id == Self.everything ? HomeData.everythingKey : tile.toolreturn key.flatMap { seen.insert($0).inserted ? $0 : nil } } }/// Of the tiles `drawn`, by key, the ones hidden from the fan: drawn/// grey. Grey says one thing — this tool is not on the fan — never that/// it holds nothing yet; a tool on the fan is never grey, empty or not/// (walker pass 4, 16 Oct 2026: two tools greyed on the/// Tools grid while their fan cards stood in colour).publicfunc hiddenFromFan(_ drawn: [String]) -> Set<String> {let onFan = Set(tiles.map(\.key) + keys)returnSet(drawn.filter { !onFan.contains($0) }) }/// Whether `view` is a tile on Home.publicfunc shows(_ view: String) -> Bool { viewIds.contains(view) }/// The `arrangement` block of `read.home`; nil, or a block with no/// `tiles`, holds no tile. There is no order of the app's own to fall/// back on: a database's tiles are its answer's, or none (295 A, walker294:/// the bundle's built-ins by name were drawn as an arrangement, then/// re-dealt).publicinit(answer arrangement: JSONValue?) {self = HomeTiles(arranged: arrangement) ?? HomeTiles(tiles: []) }/// The `arrangement` block of `read.home`, or nil when there is none or/// it has no `tiles` — no arrangement to draw. Keys the app does not draw/// (the core's `offers`) are passed over.publicinit?(arranged arrangement: JSONValue?) {guardlet arrangement, arrangement["tiles"]?.array != nilelse { returnnil }let tiles = arrangement.list("tiles").compactMap { tile -> HomeTile? inguardlet id = tile.text("id") else { returnnil }returnHomeTile( id: id, empty: tile.flag("empty"), tool: tile.text("tool"), name: tile.text("name"), opens: tile.text("opens"), table: tile.text("table")) }self.init(tiles: tiles, viewIds: arrangement.strings("viewIds"), tools: arrangement.strings("tools")) }}publicenumHomeData {// ── Where a place is said ─────────────────────────────────────────────/// The places found by name that are no table's tool/// (`Resources/Places/places.json`), in that file's order. A place is/// the app's own screen; a tool is a package record and never one of/// these (owner's ruling, 21 Oct 2026: tools are records only).staticlet places: [TableTool] = places(from: CottonUIResources.bundle)staticfunc places(from bundle: Bundle?) -> [TableTool] {guardlet url = bundle?.url(forResource: "places", withExtension: "json", subdirectory: "Places"),let data = try? FixtureDefinitions.readBundledJSON(url),let tools = try? JSONDecoder().decode([TableTool].self, from: data)else { return [] }return tools }/// A place as a row: its key, its name, its glyph, its route.staticfunc row(of place: TableTool) -> FindTool {FindTool( key: place.key ?? place.name, name: place.name, icon: place.icon ?? "table", path: place.route ?? "/") }// ── What Find matches ─────────────────────────────────────────────────/// The shown database's package tools, then the places — what Find/// matches a typed name against. A tool's row is its record: the key is/// its id, the name its name, the glyph its home table's `tool` icon and/// the path the one route rule a tile tap follows/// (`BoardLayout.route(for:in:)`). The app ships no tool of its own, so/// with no tools in hand Find matches the places alone.publicstaticfunc findTools(_ tools: [ToolDefinition], definitions: TableDefinitions) -> [FindTool] {let rows = tools.map { tool inFindTool( key: tool.id, name: tool.name, icon: BoardLayout.home(for: tool, in: definitions)?.tool?.icon ?? "table", path: BoardLayout.route(for: tool, in: definitions, tools: tools).path) }return rows + places.map { row(of: $0) } }/// The one place with this key, or `nil` — a key from a later build, or/// one that names no place. A tool is found among the package records/// the caller holds (`findTools`), never here.publicstaticfunc toolPlace(_ key: String) -> FindTool? { places.first { ($0.key ?? $0.name) == key }.map { row(of: $0) } }/// The families no Home tile counts: a write that moved only these never/// re-reads Home (architect 2335 item 6 — only the tiles' tables).publicstaticlet noTileFamilies: Set<ScreenFamily> = [ .activity, .devices, .dictation, .feedback, .storage, .summary, .bin, .projects, ]/// Whether an own write that moved `families` moved a table a tile counts.publicstaticfunc tileReads(_ families: Set<ScreenFamily>) -> Bool { !families.subtracting(noTileFamilies).isEmpty }/// The key Everything's tile is drawn under (`everything.json`'s tool key)./// Everything is no tool (owner's ruling, 12 Oct 2026): it is a shipped/// view, `ready/everything`.publicstaticlet everythingKey = "everything"}