//! THE PUSH VOCABULARY — the closed set of types a server composes and a phone //! maps, declared once so the two can be held against each other. //! //! Design P14 asks for *"the same guard that a new server type lands with its //! entry and its test in the same change"*. Until this module there was no such //! guard on either side, and the two vocabularies had drifted apart in four //! places — see [`UNMAPPED_BY_THE_APP`] and [`EMITTED_BY_NOBODY`], which are //! where that drift was written down. **Both are EMPTY now**: all four names //! were share pushes, and they left with the multi-person sharing data plane //! (the code is on the branch `archive/sharing-v1`). The two lists stay, //! declared and held empty, because the next disagreement has to land in one //! of them on purpose rather than arrive unnoticed. //! //! **Here rather than in `cotton-server`, because the PHONE build must see it** //! (`phone_boundary.rs` forbids a phone linking the server), and the phone is //! the side whose table has to be total. The server reaches it the other way, //! through its own `dependency_boundary`-clean dependency on this crate. //! //! Three lists and two holes that are currently empty: //! //! * [`PUSH_TYPES`] — what the APP maps to a route. The Swift table is held //! TOTAL against this, through `routes.list`. //! * [`SERVER_PUSH_TYPES`] — what the server can compose. Every emitter //! constant is named in `cotton-server`'s own guard. //! * [`RETIRED_PUSH_TYPES`] — the ten types that LEFT, and must not come //! back without their sender. //! //! The holes are declared, not tolerated by accident: a guard that failed on //! them would be a guard nobody could keep green, and a guard that ignored the //! difference entirely would let the NEXT one in silently. So the difference //! between the two lists must equal the two named lists exactly — which today //! means the two lists are IDENTICAL — and a new disagreement in either //! direction is red. //! //! A THIRD hole is held empty for a different failure: //! [`SENT_FOR_A_ROW_THE_PHONE_ALSO_PLANS`]. The phone schedules the //! time-based notifications itself, from its own copy of the database //! ([`crate::rules::reminders`]), so a server push about one of THOSE rows //! would ring one phone twice. That list names the collisions, and it is empty. /// The types the APP maps to a route, sorted. /// /// One entry per row of the push tap table in /// `apps/cotton/Sources/CottonKit/Notifications/NotificationRoutes.swift`, /// which is held TOTAL against this list through /// `crates/cotton-ffi/src/phone/routes.rs`. The design's /// P14 and Cotton note "The phone and Mac app — how a screen is built" both say *twenty*; the code wins /// ([feedback-should-be-a-primitive-weigh-it-by-who-said-it-and-how-m]). /// /// The emitter named beside each is where the push is composed today. Every /// one but `cotton_feedback_capture` has one, which is why /// [`EMITTED_BY_NOBODY`] names that one and nothing else. pub const PUSH_TYPES: &[&str] = &[ // `cotton-tools`: `documents::tools`'s `notify_owner`. "cotton_agent_note", // `cotton-server`: `assistant::worker`. "cotton_assistant_result", // `cotton-server`: `documents::notify`. "cotton_document_ready", // NOTHING EMITS THIS any more — the feedback ingest route was // retired. Rows written while it was live must still route. See // [`EMITTED_BY_NOBODY`]. "cotton_feedback_capture", // `cotton-server`: `push::first_push` — the serving Mac's own sender rang // the owner for the first time, or the owner pressed Test push. "cotton_first_push", // `cotton-server`: `meetings::notify`, both lanes. "cotton_meeting_failed", "cotton_meeting_ready", // `cotton-server`: `money::notify`. "cotton_money_statement_read", // `cotton-server`: `news::notify`, both lanes. "cotton_news_edition_failed", "cotton_news_edition_ready", // `cotton-server`: `sessions::notify` — a hosted session's process is // gone, with its exit. "cotton_session_ended", // A session's question to the owner (the retired session inbox wrote it; kept for rows that hold it). "cotton_session_question", // `cotton-server`: `sessions::notify` — a hosted session is blocked on the // person: a permission, a question, or input. "cotton_session_waiting", // `cotton-server`: `standby_watch`, both — a Mac that holds the // household's copy and does not serve it: its own copy has fallen behind, // or the Mac that serves has gone quiet. The only two pushes a standby's // sender takes; each is also its own clearing. "cotton_standby_behind", "cotton_standby_silent", // Sorted order splits the two device pushes from the third, so each name // carries its own owner rather than a block comment that has to be true of // the lines under it. "device_approved", // `cotton-server`: `devices::notify` // A device ASKED to join, and every admitted device is asked to compare the // six digits with the ones on its screen. The only one of the four that is // sent before anything has been decided. "device_join_requested", // `cotton-server`: `devices::notify` "device_revoked", // `cotton-server`: `devices::notify` "recovery_key_shown", // `cotton-server`: `devices::notify` ]; /// Who receives a composed notification. Only requests requiring /// the owner's action interrupt the phone; routine work reaches the coordinator. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum PushAudience { Owner, Coordinator, } // One declaration per sender: routing and the vocabulary derive from this table. macro_rules! push_kinds { ($( $kind:literal => $audience:ident ),* $(,)?) => { pub const SERVER_PUSH_TYPES: &[&str] = &[$($kind),*]; pub const PUSH_KINDS: &[(&str, PushAudience)] = &[$(($kind, PushAudience::$audience)),*]; }; } push_kinds! { "cotton_agent_note" => Coordinator, "cotton_assistant_result" => Coordinator, "cotton_document_ready" => Coordinator, "cotton_first_push" => Owner, "cotton_meeting_failed" => Coordinator, "cotton_meeting_ready" => Coordinator, "cotton_money_statement_read" => Coordinator, "cotton_news_edition_failed" => Coordinator, "cotton_news_edition_ready" => Coordinator, "cotton_session_ended" => Coordinator, "cotton_session_question" => Owner, "cotton_session_waiting" => Owner, "cotton_standby_behind" => Coordinator, "cotton_standby_silent" => Owner, "device_approved" => Coordinator, "device_join_requested" => Owner, "device_revoked" => Coordinator, "recovery_key_shown" => Coordinator, } /// Unknown kinds are refused, never treated as owner pushes. pub fn push_audience(kind: &str) -> Option { PUSH_KINDS.iter().find(|(name, _)| *name == kind).map(|(_, audience)| *audience) } /// Types a SERVER sends that no client maps — the drift, in the direction that /// costs a person something. /// /// EMPTY, and the guard below holds it so. It carried `share_revoked` and /// `share_stale` as a known baseline; both went with the multi-person sharing /// data plane (the code is on the branch `archive/sharing-v1`), so the drift /// they recorded is not a baseline any more, it is gone. pub const UNMAPPED_BY_THE_APP: &[&str] = &[]; /// Types the app maps that nothing emits — unreachable entries. /// /// `cotton_feedback_capture` is the one, and it landed here when the feedback /// ingest's whole server half was retired — `register_feedback_app`, /// `list_feedback_apps` and the anonymous `POST /v1/feedback/ingest` that /// composed this push. It is HERE rather than in [`RETIRED_PUSH_TYPES`] on /// purpose: the sender is gone, but a notification row written while the route /// was live is still in the file, and a tap on one has to open something. The /// app keeps its route; nothing writes a new one. /// /// (`share_ended` and `share_key_changed` were here until the multi-person /// sharing plane left, which took their route-map entries with them.) pub const EMITTED_BY_NOBODY: &[&str] = &["cotton_feedback_capture"]; /// Types the SERVER sends about a row the PHONE also plans a local /// notification for — the collision that rings one phone twice. /// /// EMPTY, and the guard below holds it so. It is the third declared hole, and /// it exists because the two halves of Cotton's notifications are decided in /// different places and neither can see the other: /// /// * **Tier one** is [`crate::rules::reminders`]: the phone reads its own /// copy and schedules the time-based ones itself — a todo's due instant, an /// event ten minutes out, a birthday, the mood nudge. Every device that /// holds the database plans its own, off its own clock, in its own zone. /// * **Tier two** is this vocabulary: a row the SERVER creates, pushed /// because only the Mac could know it happened — a document finished, a /// statement read, a device asking to join. /// /// The two are disjoint TODAY and this list is how that stays true rather than /// being a coincidence nobody is watching. **A new server push about a todo's /// due instant, an event start, a birthday or the mood check-in would arrive /// beside a local notification the phone had already scheduled for the same /// row**, and the person would be told twice. /// /// **When one lands here, the local twin is what gives way.** The remote /// carries the row the server composed and the phone cannot refuse delivery of /// it — an iOS notification service extension may rewrite an alert but not drop /// one — so the dedupe has to withdraw the notification this app owns: /// `reminders.reconcile` already names every pending request, and a twin is /// `cotton:::` for the record the push names. The /// entry here is what says a sender has to build that; an empty list is what /// says nobody has needed to yet. /// /// The rule in one sentence, for the page that repeats it /// (Cotton note "Notifications — how one actually reaches your phone"): **a device that plans a row locally /// must not also be pushed about it.** pub const SENT_FOR_A_ROW_THE_PHONE_ALSO_PLANS: &[&str] = &[]; /// The ten types that LEFT: the two Calls pushes, retired 2026-08-23 with the /// cell that sent them, the seven that went with the multi-person sharing data /// plane, and the walkthrough pin notification, retired with the walkthrough at /// store version 33. /// /// Named rather than merely absent: *"a route for a push nobody sends is a /// promise nothing keeps"*, and when Calls is ported — or sharing is rebuilt — /// the types come back with their sender and their tests in the same change. A /// build that quietly re-added one would otherwise look like a fix. pub const RETIRED_PUSH_TYPES: &[&str] = &[ // Retired with TABLE DROP 1 (27 Nov 2026): the agent-account, outage, repository and CI tables they were // about are held as retired, so nothing composes them and the app maps none. "cotton_account_usage_high", "cotton_call_missed", "cotton_call_ring", // The seven that left with the multi-person sharing data plane. // `cotton_message` was the relay delivering somebody else's line; the six // `share_*` were the invitation, the acceptance, a rotated key, a stale // copy and the two ends of a share. The archive the app still reads is // imported, never received, so nothing rings a phone for it. "cotton_message", "cotton_money_receivable_overdue", "cotton_outage", "cotton_repo_checks_failed", "cotton_repo_comment", "cotton_repo_pull_opened", "cotton_repo_pull_ready", "cotton_repo_review_requested", "cotton_repo_run_failed", // Retired with the walkthrough itself (store version 33). The push pointed // a tap at a screen inside a walkthrough, and every walkthrough is now a // note whose pictures have no pins on them — so there is no nearest screen // worth guessing at, and an old row in the file reads as the deliberate // no-op `app_maps_push_type` describes. Its composer had no production // caller by the time it went. "cotton_walkthrough_feedback", // Retired with the Assistants screen it opened (27 Oct 2026): its sender, // `cotton-server`'s `oauth::status`, left with the server. "grant_created", "share_accepted", "share_ended", "share_invitation", "share_key_changed", "share_revoked", "share_stale", ]; /// Does the app map this type to a route? /// /// The tap handler's own question. An unmapped type is a deliberate no-op — /// never a guess at the nearest screen. pub fn app_maps_push_type(push_type: &str) -> bool { PUSH_TYPES.contains(&push_type) } #[cfg(test)] #[path = "notifications_tests.rs"] mod tests;