//! THE primitives registry — every record kind Cotton has, declared once, with//! every cross-cutting facility it does or does not participate in (spec//! 2026-08-29-cotton-primitives-registry-design.md). The port of//! `packages/core/src/primitives.ts`.//!//! This is a REGISTRY, not a framework: it never generates behaviour. Each//! facility keeps its hand-written implementation and its own `*_KINDS` list//! ([`crate::constants`]) mirroring a DB CHECK; what this table adds is the//! single place where all of a kind's memberships are decided together — and//! the rule that a "no" is never a missing entry, it is a WRITTEN REASON.//!//! `RECORD_KINDS` is no longer the master list — it is the `addressable`//! facility's membership (the flattened search/get/comment record surface,//! 2026-08-17). The kinds that outgrew it (goal, thread, message,//! session, project, prompt) are first-class here.//!//! # What the port had to change, and what it buys//!//! The TypeScript declares `PRIMITIVES` as a `Record<string, PrimitiveSpec>`//! and needs a module-load loop plus a gate test to prove the record total; the//! Rust spelling is an exhaustive `match` over [`PrimitiveKind`], so a kind//! added to the enum without a spec fails the BUILD. That is the same trade//! `rules::capture_links` makes, one registry up: adding a kind is one entry,//! and the compiler names the seam.//!//! [`Membership`] has no `false`, exactly as the TypeScript's//! `true | string` has none: an exclusion with no written reason is the drift//! this registry exists to end. [`SearchLane`] is the same shape with two//! yeses, because a kind search reaches names WHICH lane it is reached by.//!//! `PRIMITIVE_KINDS` is [`PrimitiveKind::ALL`], in the registry's declaration//! order — the order the MCP verb grid and the generated catalogue both walk.pubmod words;usecrate::constants::PrimitiveKind;/// `true` = the kind participates; a written reason = it does not.////// `false` is deliberately not a variant: an exclusion with no written reason/// is the drift this registry exists to end.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pubenumMembership {Yes,/// The reason, in prose. `primitives_tests.rs` holds every one of them to/// a real sentence — never a bare flag, never a TODO.No(&'static str),}implMembership {pubconstfn is_member(self) -> bool { matches!(self, Membership::Yes) }/// The written reason, or `None` where the kind participates.pubconstfn reason(self) -> Option<&'static str> {matchself {Membership::Yes => None,Membership::No(reason) => Some(reason), } }}/// How search-everything reaches a kind: its FTS5 table, an indexed LIKE scan/// until its row counts earn an index of its own, or the reason it stays out of/// the one search surface.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pubenumSearchLane {Fts,Like,No(&'static str),}implSearchLane {/// Whether search-everything reaches the kind at all — its/// `EVERYTHING_KINDS` membership.pubconstfn is_searchable(self) -> bool { !matches!(self, SearchLane::No(_)) }/// The lane's wire spelling, or `None` where the kind is out.pubconstfn as_str(self) -> Option<&'static str> {matchself {SearchLane::Fts => Some("fts"),SearchLane::Like => Some("like"),SearchLane::No(_) => None, } }pubconstfn reason(self) -> Option<&'static str> {matchself {SearchLane::No(reason) => Some(reason), _ => None, } }}/// One kind's whole declaration.////// The field order is the TypeScript interface's, which is the order a reader/// decides them in: where the rows live, how they are FOUND, what history and/// discussion they earn, and what may leave the file with them.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pubstructPrimitiveSpec {/// The synced table holding this kind's rows (`note` and `journal` share/// `cotton_notes` — the one row-level split, on its `kind` column).pub table: &'static str,/// A dedicated `fts_*` table in the file (store `FTS_SOURCES`).pub fts: Membership,/// The kind's text earns vectors, so the meaning lane can find it (store/// `EMBED_SOURCES`, spec 2026-09-02-cotton-semantic-search-design D2).////// FTS finds the words a person typed; this finds the rows that MEAN what/// they asked. Seven kinds qualify, and the "no"s are mostly one argument:/// a title is five words, a vector over five words sits close to everything/// vaguely adjacent, and the false hits would crowd out the true ones in a/// section a person scans in one glance. The rest are containers whose/// children carry the prose (a thread, an email thread), or lanes the one/// search surface cannot reach at all — and a lane search cannot reach/// cannot have a meaning lane inside it.////// Stated on the KIND, not on the table: `document` is `Yes` although the/// vectors sit on its pages, exactly as `fts: Yes` is stated on `document`/// while `fts_document_pages` is a table of its own.pub embedded: Membership,/// Search-everything membership (`EVERYTHING_KINDS`) and its lane, or the/// reason the kind stays out of the one search surface.pub search: SearchLane,/// Edits earn `cotton_changes` history rows (store `VERSIONED`).pub versioned: Membership,/// `cotton_comments` admits the kind (`COMMENT_RECORD_KINDS`).pub commentable: Membership,/// The kind carries a `summary` with provenance (`SUMMARY_KINDS`, schema/// v15) — a paragraph an assistant or the owner writes about the record,/// with who wrote it and when.////// A "no" here is a real answer, not an oversight: most kinds ARE their own/// summary. A todo is one line; a memory entry is one sentence by/// construction; a message is somebody's words. The kinds that earn one are/// the kinds a person opens a PAGE of and cannot read at a glance.pub summarized: Membership,/// `cotton_project_links` admits the kind (`PROJECT_LINK_KINDS`).pub project_linkable: Membership,/// `cotton_links` admits the kind on either end (`LINK_KINDS`).pub linkable: Membership,/// An inbox capture can route into the kind (`ROUTE_TARGET_KINDS`).pub route_target: Membership,/// In the flattened record surface (`RECORD_KINDS`, the app's `recordPath`/// vocabulary).////// The MCP get/search/comment vocabularies are the SERVER's deliberately/// narrower subsets — addressable here does not promise a `get_record`/// expander; the verb grid says which kinds have one, and its gate/// reconciles the two.pub addressable: Membership,/// The kind lands in the BIN when the owner removes one (`BIN_KINDS`,/// schema v33) — a soft delete on a `trashed_at` column: readers hide the/// row, the bin lists it, Restore brings it back and emptying the bin is the/// one act that erases it.////// A "no" here is almost never "this cannot be removed". Most kinds already/// have a BETTER answer than a bin and say which: a todo is dropped, a note/// is archived, a goal is withdrawn by status, a document's bytes are/// deleted outright because a bin would quietly go on paying to store them./// The bin exists for the kinds where removal is BULK and ROUTINE — a/// morning's mail — and where being wrong about one of forty must cost a/// tap, not a re-import.pub binnable: Membership,/// A record of this kind may LEAVE this file into a scope — mirrored into/// another person's database, under a grant they and the owner both agreed/// to (`SHAREABLE_KINDS`, sharing spec S-D5).////// A "yes" is a promise with a column behind it: the kind's table carries/// `origin_handle` (schema v45), so a row that came from somebody else can/// say so, and the writer can refuse a local edit to it. A kind whose table/// cannot say who wrote a row would mirror a peer's record as the owner's/// own — which is why the gate holds this list and the eight tables with/// that column to the same set.////// The "no"s are three arguments and a wait. Some records are about a THIRD/// PARTY who never agreed to sit in a second person's file. Some already/// have their own way of travelling — a conversation IS a scope kind, a/// document has its own link share. And most of the rest are "not yet": no/// consent question has been asked about them, and a facility nobody has/// thought about is not a facility anybody should get by default.////// The JOIN tables that travel with a scope are not kinds and cannot be/// marked here; they are declared beside the list as/// [`crate::constants::SHAREABLE_LINK_TABLES`].pub shareable: Membership,}/// The facilities a kind can be a member of — the TypeScript's/// `keyof Omit<PrimitiveSpec, "table" | "search">`.////// `search` is not one of them because its answer is a LANE rather than a yes;/// [`searchable_kinds`] is its reader.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pubenumFacility {Fts,Embedded,Versioned,Commentable,Summarized,ProjectLinkable,Linkable,RouteTarget,Addressable,Binnable,Shareable,}implFacility {/// The TypeScript's own key, which is what a failure message names.pubconstfn as_str(self) -> &'static str {matchself {Facility::Fts => "fts",Facility::Embedded => "embedded",Facility::Versioned => "versioned",Facility::Commentable => "commentable",Facility::Summarized => "summarized",Facility::ProjectLinkable => "projectLinkable",Facility::Linkable => "linkable",Facility::RouteTarget => "routeTarget",Facility::Addressable => "addressable",Facility::Binnable => "binnable",Facility::Shareable => "shareable", } }pubconst ALL: [Facility; 11] = [Facility::Fts,Facility::Embedded,Facility::Versioned,Facility::Commentable,Facility::Summarized,Facility::ProjectLinkable,Facility::Linkable,Facility::RouteTarget,Facility::Addressable,Facility::Binnable,Facility::Shareable, ];}impl std::fmt::DisplayforFacility {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(self.as_str()) }}implPrimitiveSpec {/// One facility's answer, so a caller can ask the question the TypeScript/// asks with a computed key.pubconstfn facility(&self, facility: Facility) -> Membership {match facility {Facility::Fts => self.fts,Facility::Embedded => self.embedded,Facility::Versioned => self.versioned,Facility::Commentable => self.commentable,Facility::Summarized => self.summarized,Facility::ProjectLinkable => self.project_linkable,Facility::Linkable => self.linkable,Facility::RouteTarget => self.route_target,Facility::Addressable => self.addressable,Facility::Binnable => self.binnable,Facility::Shareable => self.shareable, } }}/// Every kind's declaration — the registry itself.////// TOTAL by construction: this `match` is the module-load loop the TypeScript/// needs, made into a build error. A kind added to [`PrimitiveKind`] with no/// entry here does not compile, which is the whole discipline — a kind missing/// from a registry reads to every caller as "there is none of that".pubconstfn primitive(kind: PrimitiveKind) -> PrimitiveSpec {useMembership::{No, Yes};match kind {PrimitiveKind::Todo => PrimitiveSpec { table: "cotton_todos", fts: Yes, embedded: No("a title is five words; a vector over five words sits close to everything vaguely adjacent, and the false hits would crowd out the true ones in a section a person scans in one glance"), search: SearchLane::Fts, versioned: Yes, commentable: Yes, summarized: No("a todo is one line; its short LABEL is a column the summaries worker fills, not the summaries facility"), project_linkable: Yes, linkable: Yes, route_target: Yes, addressable: Yes, binnable: Yes, shareable: No("whose phone rings — a todo is an obligation on ONE person's day, and asking somebody else to do something is a message, not a row mirrored into their file"), },PrimitiveKind::TodoRecurrence => PrimitiveSpec { table: "cotton_todo_recurrences", fts: No("the rule is machinery; the occurrences it materializes are the todos search finds"), embedded: No("the rule is machinery, not prose — there is nothing in it to mean anything"), search: SearchLane::No("found through its todos — the rule row is machinery, not a result"), versioned: Yes, commentable: No("discussion belongs on the todo an occurrence became"), summarized: No("machinery behind its todos; there is nothing to summarize"), project_linkable: No("a project holds the todos; the rule follows them implicitly"), linkable: No("links land on the todo an occurrence became"), route_target: No("a capture becomes a todo; the rule is born from that todo's repeat"), addressable: Yes, binnable: No("machinery behind its todos; ending a repeat is editing the rule, and the occurrences already minted stay todos"), shareable: No("not yet; no consent question has been asked about it"), },PrimitiveKind::Event => PrimitiveSpec { table: "cotton_events", fts: Yes, embedded: No("a title, a time and a place; five words embed to something near everything, and FTS answers a title exactly"), search: SearchLane::Fts, versioned: Yes, commentable: Yes, summarized: No("an event is a title, a time and a place — already the summary"), project_linkable: Yes, linkable: Yes, route_target: Yes, addressable: Yes, binnable: Yes, shareable: No("whose phone rings — an event is one person's calendar, and inviting somebody is an invitation, not a row mirrored into their file"), },PrimitiveKind::Note => PrimitiveSpec { table: "cotton_notes", fts: Yes, embedded: Yes, search: SearchLane::Fts, versioned: Yes, commentable: Yes, summarized: No("a note is the prose; a summary of it would be a second, staler copy"), project_linkable: Yes, linkable: Yes, route_target: Yes, addressable: Yes, binnable: Yes, shareable: Yes, },PrimitiveKind::Journal => PrimitiveSpec { table: "cotton_notes", fts: No("rides fts_notes — one table, one index"), embedded: No("rides the note source — one table, one index, one section, the fts_notes precedent exactly"), search: SearchLane::No("found as a note: one table, one index, one section in the results"), versioned: Yes, commentable: Yes, summarized: No("a journal page is the day in the owner's own words"), project_linkable: Yes, linkable: No("a journal page's identity is its date; a link would pin prose better kept as a note"), route_target: Yes, addressable: Yes, binnable: No("a journal page IS its date; there is no day to put in a bin"), shareable: No("the same table as a note and a different act: a diary is not a document somebody hands over"), },PrimitiveKind::Person => PrimitiveSpec { table: "cotton_people", fts: Yes, embedded: Yes, search: SearchLane::Fts, versioned: Yes, commentable: Yes, summarized: Yes, project_linkable: Yes, linkable: Yes, route_target: No("a person capture lands as a person_note — context about someone, not a new someone"), addressable: Yes, binnable: No("archived, not binned — a person anchors money, links and threads, so archive_person puts them away and nothing erases them"), shareable: No("third-party facts — a person row is what this file knows ABOUT somebody, and they never agreed to sit in a second person's file"), },PrimitiveKind::Transaction => PrimitiveSpec { table: "cotton_money_transactions", fts: No("money is browsed by account and window; text search rides the LIKE lane"), embedded: No("a payee and an amount; the money engine's own filters are the right way to find money"), search: SearchLane::Like, versioned: Yes, commentable: No("a payment has nothing to discuss"), summarized: No("an amount, a payee and a date; the money engine's rollups are the summary of many"), project_linkable: Yes, linkable: Yes, route_target: Yes, addressable: Yes, binnable: Yes, shareable: No("third-party facts — a transaction is derived from a statement, and a statement is the bank's account of the owner alone"), },PrimitiveKind::Statement => PrimitiveSpec { table: "cotton_money_statements", fts: No("its lines are browsed by account and period; text search over them rides the LIKE lane the day anyone asks for it"), embedded: No("a period, two balances and an institution — there is no prose in a statement header to mean anything"), search: SearchLane::No("opened from its account, not the one search surface"), versioned: No("written by the reader and re-written by a re-read; the DOCUMENT is the history, and it never changes"), commentable: No("a bank's paper has nothing to discuss; the transactions it booked do"), summarized: No("its header IS its summary — a period, a balance check and a line count"), project_linkable: No("a statement is the bank's paper ABOUT AN ACCOUNT, not a project's material — its transactions link"), linkable: No("the evidence table is the statement's edge, and it carries an excerpt an edge cannot"), route_target: No("a capture is never a statement; paper is filed as a document and read from there"), addressable: No("opened with get_statement, not through the flattened record surface"), binnable: No("a statement IS its document; deleting the document takes it, and figures with no paper behind them are not checkable"), shareable: No("third-party facts — a statement is the bank's account of the owner alone, and it is the source every transaction points at"), },PrimitiveKind::MoneyAccount => PrimitiveSpec { table: "cotton_money_accounts", fts: No("accounts hold the ledger and are created by the money engine"), embedded: No("accounts hold the ledger and are created by the money engine"), search: SearchLane::No("read through its money engine view"), versioned: No("accounts hold the ledger and are created by the money engine"), commentable: No("accounts hold the ledger and are created by the money engine"), summarized: No("accounts hold the ledger and are created by the money engine"), project_linkable: No("projects link the transaction"), linkable: No("the money engine keeps its relationships"), route_target: No("captures become transactions"), addressable: No("read through its generic table view"), binnable: No("removed deliberately by the money engine"), shareable: No("money and its evidence are private"), },PrimitiveKind::StatementLine => PrimitiveSpec { table: "cotton_money_statement_lines", fts: No("printed statement lines are kept by the reader and booked by the money engine"), embedded: No("printed statement lines are kept by the reader and booked by the money engine"), search: SearchLane::No("read through its money engine view"), versioned: No("printed statement lines are kept by the reader and booked by the money engine"), commentable: No("printed statement lines are kept by the reader and booked by the money engine"), summarized: No("printed statement lines are kept by the reader and booked by the money engine"), project_linkable: No("projects link the transaction"), linkable: No("the money engine keeps its relationships"), route_target: No("captures become transactions"), addressable: No("read through its generic table view"), binnable: No("removed deliberately by the money engine"), shareable: No("money and its evidence are private"), },PrimitiveKind::Evidence => PrimitiveSpec { table: "cotton_money_evidence", fts: No("evidence proves a transaction and is kept by the money engine"), embedded: No("evidence proves a transaction and is kept by the money engine"), search: SearchLane::No("read through its money engine view"), versioned: No("evidence proves a transaction and is kept by the money engine"), commentable: No("evidence proves a transaction and is kept by the money engine"), summarized: No("evidence proves a transaction and is kept by the money engine"), project_linkable: No("projects link the transaction"), linkable: No("the money engine keeps its relationships"), route_target: No("captures become transactions"), addressable: No("read through its generic table view"), binnable: No("removed deliberately by the money engine"), shareable: No("money and its evidence are private"), },PrimitiveKind::Document => PrimitiveSpec { table: "cotton_documents", fts: Yes, embedded: Yes, search: SearchLane::Fts, versioned: Yes, commentable: Yes, summarized: No("the documents pipeline writes `summary` at its profile stage; §D6 leaves it there, so update_summary refuses this kind"), project_linkable: Yes, linkable: Yes, route_target: No("documents enter through the vault pipeline (file_document / share sheet), never as a routed capture"), addressable: Yes,// A deleted document waits in the bin as a photo does (6 Oct// 2026): its file goes on costing storage while it waits, which// the Bin pays knowingly and Storage shows, and only emptying the// bin lets the bytes go. binnable: Yes, shareable: Yes, },PrimitiveKind::Memory => PrimitiveSpec { table: "cotton_memories", fts: Yes, embedded: Yes, search: SearchLane::Fts, versioned: Yes, commentable: Yes, summarized: No("a memory entry is one sentence of at most 280 characters, by construction"), project_linkable: Yes, linkable: No("a memory cites records in prose by [slug]; nothing links TO a memory"), route_target: No("memory is the founder's mind — entries are written or transcribed, never routed"), addressable: Yes, binnable: No("archived, not binned — memory_archive keeps a dropped sentence where the owner can bring it back, and the Dropped screen is where it waits"), shareable: No("one person's own sentences — memory holds the owner's mind, and there is no second file those sentences belong in"), },PrimitiveKind::EmailThread => PrimitiveSpec { table: "cotton_email_threads", fts: No("a thread is a subject line and an address set; its emails carry the searchable text"), embedded: No("a subject line and an address set; its EMAILS carry the text and the vectors"), search: SearchLane::Like, versioned: No("an append-only archive — ingest writes it, nothing edits it, so history would record no edit"), commentable: No("an email thread IS a conversation; discussion belongs on the records it produced"), summarized: Yes, project_linkable: Yes, linkable: Yes, route_target: No("a thread exists the moment its first email is ingested, never by routing a capture"), addressable: No("opened with read_email_thread, not get_record"), binnable: Yes, shareable: No("third-party facts — a thread is the correspondents' own words; the archive is the owner's copy of them, not a thing to pass on"), },PrimitiveKind::Email => PrimitiveSpec { table: "cotton_emails", fts: Yes, embedded: Yes, search: SearchLane::Fts, versioned: No("written once at ingest and never edited — the owner's mail client owns the live copy"), commentable: No("an email is somebody else's words; discussion belongs on the owner's own records"), summarized: No("one email carries its own snippet; the THREAD is what a person reads a summary of"), project_linkable: No("the THREAD carries the membership — which is what survives a re-import"), linkable: No("quoted in prose, never linked from records"), route_target: No("emails arrive by ingest over MCP, never by routing"), addressable: No("read through its thread (read_email_thread), not get_record"), binnable: Yes, shareable: No("third-party facts — a message somebody sent the owner is theirs to have sent once, to one person"), },PrimitiveKind::Thread => PrimitiveSpec { table: "cotton_msg_threads", fts: No("a thread is a name and a member list; its messages carry the searchable text"), embedded: No("a name and a member list; its MESSAGES carry the text and the vectors"), search: SearchLane::Like, versioned: No("shared chat state is relayed between files, not edited history"), commentable: No("a thread IS a conversation; comments would be a second one inside it"), summarized: Yes, project_linkable: Yes, linkable: No("reached through the chat surface, not the link graph"), route_target: No("threads are made by messaging someone, never by routing a capture"), addressable: No("opened with read_message_thread, not get_record"), binnable: No("a chat is archived or cleared, and both are the owner's own private state written only by their devices"), shareable: No("its own scope kind — a conversation travels as a chat scope, and the thread IS that scope's root"), },PrimitiveKind::Message => PrimitiveSpec { table: "cotton_msg_messages", fts: Yes, embedded: Yes, search: SearchLane::Fts, versioned: Yes, commentable: No("a message is already the discussion"), summarized: No("somebody's words; the THREAD is what a person reads a summary of"), project_linkable: No("the THREAD carries the membership — which is what survives a WhatsApp re-import"), linkable: No("quoted or forwarded inside chat, never linked from records"), route_target: No("messages arrive by relay or import, never by routing"), addressable: No("read through its thread (read_message_thread), not get_record"),// Only a WhatsApp text of the owner's that failed to send is ever// binned (`BinKind::Message`); every other message is hidden per// reader, never binned — chat is the other person's record too. binnable: Yes, shareable: No("its own scope kind — a conversation travels as a chat scope, so a message is never a member of somebody else's project"), },PrimitiveKind::Session => PrimitiveSpec { table: "cotton_sessions", fts: No("searched through fts_prompts — what the owner typed, folded to the session that said it"), embedded: No("a person searching their own past sessions is searching their own vocabulary, which is the one case FTS is already best at"), search: SearchLane::Fts, versioned: No("a session log is append-and-close; log_session writes it once"), commentable: No("a session is a record of work already done; steering happens in memory and projects"), summarized: No("log_session writes the session's own title and summary at the end of a turn"), project_linkable: No("carries its own project_id column — a session is logged INTO a project, not filed"), linkable: No("cited in prose, never linked"), route_target: No("sessions are logged by assistants, never captured"), addressable: No("listed through list_sessions, not the flattened record surface"), binnable: No("the work happened; the log is the audit trail"), shareable: No("not yet; no consent question has been asked about it"), },// A message on the bus (spec 2026-09-04 §2). Cotton is how sessions talk:// an assistant sends here, another session claims from here, and the// owner reads and answers from the phone. No session ever talks to// another directly, which is why this is a row and not a socket.PrimitiveKind::SessionMessage => PrimitiveSpec { table: "cotton_session_messages", fts: Yes, embedded: No("a message is an instruction or a report about work in flight, read in its own thread within the hour; the meaning lane exists for the records somebody searches months later, and vectors over a queue would answer every query about work with the whole queue"), search: SearchLane::Fts, versioned: No("status moves once each way; the row is the trail"), commentable: No("the reply IS the discussion"), summarized: No("an instruction or a one-paragraph report — already shorter than a summary of it"), project_linkable: No("project_id is the address, not a membership"), linkable: No("reached through its thread and the thought that produced it; nothing in the record graph is ABOUT one message"), route_target: No("a session is chosen deliberately, by machine and account; nothing routes there on its own"), addressable: Yes, binnable: No("the queue is the audit trail; a withdrawn message says it was withdrawn"), shareable: No("not yet; no consent question has been asked about it"), },PrimitiveKind::Project => PrimitiveSpec { table: "cotton_memory_projects", fts: No("a dozen rows with names; list_projects is the reader"), embedded: No("a name and a description the owner wrote and already knows; get_project is the reader, and the records linked to it carry the prose"), search: SearchLane::No("listed through list_projects; the working set is get_project's answer"), versioned: No("a project row is a name and a description; the linked records carry the history"), commentable: No("discussion lands on the project's records, not its container row"), summarized: Yes, project_linkable: No("it is the TARGET of project links"), linkable: No("membership is the project_links table, not the link graph"), route_target: No("projects are created deliberately, never captured"), addressable: No("reached through the project tools"), binnable: No("archived by status; the records a project gathered outlive it"), shareable: Yes, },PrimitiveKind::Prompt => PrimitiveSpec { table: "cotton_prompts", fts: Yes, embedded: No("searching one's own past prompts is searching one's own vocabulary — FTS's best case, and a prompt never surfaces on its own"), search: SearchLane::No("surfaces as its SESSION's hit — a prompt is the evidence, the session is the answer"), versioned: No("a derived stream: written once at log time, never edited (tableSpecs)"), commentable: No("private by construction"), summarized: No("what the owner typed, kept verbatim"), project_linkable: No("its session carries the project"), linkable: No("private by construction"), route_target: No("prompts are logged, never captured"), addressable: No("private by construction — no record surface shows a bare prompt"), binnable: No("private by construction; a prompt belongs to its session, and the session log is the audit trail"), shareable: No("not yet; no consent question has been asked about it"), },// Photos and videos (spec 2026-09-04-cotton-photos-videos-design.md,// schema v31) — the pictures a person already has, made into records// they can search, describe, file and consciously delete.//// TWO KINDS, not one with a `kind` column (D1): a video carries a// duration and a poster a photo never does, the words people say are "my// photos" and "my videos", and the verb grid compiles per kind. The two// entries are deliberately identical apart from that — the same answer// to the same question about the same material.//// A row is a REFERENCE to bytes the person already holds, addressed by// its own hash (D2), which is why the same picture in four chats is one// record.PrimitiveKind::Photo => PrimitiveSpec { table: "cotton_photos", fts: Yes, embedded: No("a caption and one or two sentences of description a row; FTS answers 'the boarding pass' exactly, and vectors over a corpus of machine-written descriptions that all read alike would return the whole camera roll for every query — a follow-on once descriptions exist at scale, not now"), search: SearchLane::Fts, versioned: No("the two editable fields are a caption and a review note, both a handful of words somebody retypes rather than revises; a version pair per picture would put a history table beside tens of thousands of rows to remember a typo"), commentable: No("a caption and a review note are the two things anyone says about a picture, and both live on the row; a discussion ABOUT one is a chat, which exists"), summarized: No("the material is PIXELS, not text, so summaryPatchFor cannot make one and update_summary refuses the kind — the describe worker looks at the image and writes `summary` itself, the documents precedent (D5)"), project_linkable: Yes, linkable: Yes, route_target: No("a capture is words the owner typed or spoke; a picture enters as bytes — from a chat, the share sheet or the library picker"), addressable: Yes, binnable: Yes, shareable: Yes, },PrimitiveKind::Video => PrimitiveSpec { table: "cotton_videos", fts: Yes, embedded: No("the photo's reason exactly — a description a row, machine-written, all alike"), search: SearchLane::Fts, versioned: No("the photo's reason exactly — a caption and a review note are retyped, not revised"), commentable: No("the photo's reason exactly — what anyone says about it is the caption or the note"), summarized: No("pixels again, and fewer of them the model can see: the describe worker reads the POSTER frame and writes `summary`; a video with no poster rests rather than being guessed at (D5)"), project_linkable: Yes, linkable: Yes, route_target: No("the photo's reason exactly — a video enters as bytes, never as a routed sentence"), addressable: Yes, binnable: Yes, shareable: Yes, },// A suggested album (schema v42, spec// 2026-09-05-cotton-photo-albums-design): a PROPOSAL the server derives// from the pictures the person holds — a trip or an event — open until// they keep or dismiss it, and theirs once kept. A set of pictures with// a title, not a picture: the facilities below say so.PrimitiveKind::Album => PrimitiveSpec { table: "cotton_media_albums", fts: No("a title is one line, listed rather than searched; the pictures inside are found through their own captions and descriptions, and search_records answers with the photo, which names its albums"), embedded: No("a title is one line; nothing to embed"), search: SearchLane::No("no lane of its own — list_albums is the finder, and a title is one line the person or the pass wrote"), versioned: No("the one editable field is a title the person retypes; membership changes are add and remove, not revisions"), commentable: No("a proposal is decided — kept or dismissed — not discussed; a kept album is the person's own and a conversation about pictures is a chat"), summarized: No("the members are the summary: a title, a span of days and the pictures themselves say what happened"), project_linkable: Yes, linkable: No("a link is between records, and an album is a set of them — link the picture; and `linkable` rides on RECORD_KINDS, which is the addressable surface an album stays out of"), route_target: No("a capture is words; an album is pictures the server grouped, or the person chose"), addressable: No("a search hit is a picture, which opens on its own page and names its albums; get_record over an album would answer what get_album already does"), binnable: No("dismissed is the album's own state — a tombstone the pass compares against — and a kept one is removed by dismissing it; nothing about an album costs bytes to keep"), shareable: Yes, },// A call the phone recorded (spec// 2026-09-05-mac-ingest-messages-calls-design §D7, schema v36) —// cellular, FaceTime, and the WhatsApp calls iOS logs through CallKit,// read off a Mac that syncs the same Apple ID.//// A RECORD OF SOMETHING THAT ALREADY HAPPENED, written by a device and// never by the person. That is what separated it from `cotton_calls`,// Cotton's own live-calling state machine (rooms, nodes, members) — a// supporting table retired at schema 5 with the rest of the sharing era.// One ran while people were talking, this one is what is left// afterwards, and the two were never one table because every read would// then have had to ask which kind it was looking at.PrimitiveKind::Call => PrimitiveSpec { table: "cotton_call_log", fts: No("a call has no prose — a number, a clock reading and a duration; there is nothing in the row to rank, and an index over handles would answer every query with every call"), embedded: No("there is no text to embed — what was SAID on a call is not in the log, and the meaning of one is carried by the person it was with"), search: SearchLane::Like, versioned: No("a device's record of what happened is not edited; a correction would be the phone's own log disagreeing with itself, and there is no hand that writes one"), commentable: Yes, summarized: No("a number, a direction, an outcome and a duration is already shorter than any summary of it could be — and the one thing worth saying about a call is what was said ON it, which is a comment, not a summary of the row"), project_linkable: Yes, linkable: No("the person is a COLUMN on the row (`person_id`, resolved from the contact), so an edge in `cotton_links` would be the same fact written twice and two places to keep in step"), route_target: No("a capture is words the owner typed or spoke; a call arrives as a row a device read out of the phone's own log"), addressable: Yes, binnable: No("a call log entry is a fact the phone recorded, so nothing deletes one by rule; hiding one is a `hidden_at` the day the owner asks for it, and a bin would offer to erase evidence nobody asked to lose"), shareable: No("third-party facts — a call log is who rang whom, and the number at the other end never agreed to be in a third file"), },// The vault (v6 of the Rust ladder). A secret stopped being a// credential the server holds under an environment string and became a// record the person opens, sealed under a key only their own devices// carry — which is what made a page, a search hit and a bin safe to// give it. Cotton note "The vault — the honest sentence".PrimitiveKind::Secret => PrimitiveSpec { table: "cotton_secrets", fts: Yes, embedded: No("the plain columns are a name, a site and a username — five words, which embed to something near everything — and the part with meaning in it is SEALED: sending a payload to a provider to be vectorised is the one thing this design exists to make impossible"), search: SearchLane::Fts, versioned: No("a password's history is OLD PASSWORDS, and a history row would keep its snapshots — a kind whose whole point is that nothing reads it cannot have a table beside it that keeps every value it ever had"), commentable: No("a note about a password belongs in the payload's own notes field, sealed with it; a comment thread would be that note in the clear"), summarized: No("a name, a site and a username — a person reads the whole row at a glance, and the part a summary could add is the part nothing may read"), project_linkable: Yes, linkable: Yes, route_target: No("a capture never becomes a password by routing — a sentence somebody dictated is not a credential, and a classifier that decided otherwise would be writing secrets nobody typed"), addressable: Yes, binnable: Yes, shareable: No("a shared password is a password the other person now has for ever, whatever the grant says afterwards — telling somebody a credential is a conversation, not a row mirrored into their file"), },// A device (v13 of the Rust ladder). It was a supporting table from v9,// on the strength of one sentence — "nobody files a device or searches// for one" — and that sentence stayed true while the only readers were// the chokepoint and two screens. What changed is that other rows now// POINT at one: a session says which device it ran on, a machine's// telemetry reading says which device it is about, and a media holding// has said which device holds the bytes since v12. A row three other// tables reference is a kind, and leaving it classified as// infrastructure meant the registry had no place to write down which// facilities it refuses and why. Cotton note "Devices — how a machine is admitted to your database".PrimitiveKind::Device => PrimitiveSpec { table: "cotton_devices", fts: No("a name, a platform and a version — a person has a handful of devices and reads the whole list at once, so an index over four words would cost a table in the file to answer a question the list already answers"), embedded: No("a name and a platform; there is no prose in the row to mean anything, and a vector over \"Asha's iPhone\" sits close to every sentence with a name in it"), search: SearchLane::No("listed through list_devices, never found by searching — search-everything answers about the person's LIFE, and a device is the machinery their life is held on; a device turning up beside a note about the same trip would be a category error in the one surface that must not have them"), versioned: No("the two edits a device row takes are the two stamps already on it — approved_at and revoked_at — and a rename is the owner correcting a label they typed, never history worth keeping"), commentable: No("there is nothing to discuss about a key; what a device DID is the sessions logged on it and the records it wrote, and those carry their own comments"), summarized: No("a name, a platform and when it joined — a person reads the whole row in one glance, and a paragraph about a device would be a paragraph about nothing"), project_linkable: No("a device holds the WHOLE database, not a piece of work — filing one under a project would say the opposite of what is true about it"), linkable: No("pointed AT by its own column, never edged — a session, a machine reading and a media holding each carry device_id, which is a foreign key with one meaning, and a link in the record graph would be a second, vaguer one beside it"), route_target: No("a device is admitted by a person comparing six digits on two screens; nothing a classifier reads from a captured sentence could ever produce one"), addressable: No("no page in the flattened record surface: search does not reach it and get_record cannot expand it, and the screen a person opens a device on is the Your devices list, which list_devices already answers"), binnable: No("REVOKED, never binned — revoked_at is the device's bin, and it is MONOTONE (the mirror of an insert-only cotton_revocations fact, written only by revocation::revoke()): a patch that clears it is refused. A bin is a soft delete Restore can undo, and re-admitting a key that was cut off must be a new approval on a new row, never a tap that puts the old one back"), shareable: No("which keys open THIS database is the one fact that must never leave it — mirroring a device row into somebody else's file would be handing them the list of what to attack, and there is no version of the consent question that makes that a good trade"), },PrimitiveKind::Repository => PrimitiveSpec { table: "cotton_repos", fts: No("a name, an owner and a one-line description — a person has a handful of repositories and reads the whole list at once, and an index over eight words would cost a table in the file to answer what `list_repositories` already answers"), embedded: No("a slug and a description; there is no prose in the row to mean anything, and a vector over `alpaca/field-notes` sits close to every sentence with a project name in it"),// An indexed LIKE scan over the key and the name, which is what// "where is that repo" needs: the answer is one of a handful of// rows, so a dedicated index would cost a table in every device's// file to rank five candidates. search: SearchLane::Like, versioned: No("the row MIRRORS what the host said about the repository — its default branch, its counts, its description — so a history of it would be a history of the host's answers, and the history that matters is the git history the clone already holds"), commentable: No("a comment belongs on the pull request or the issue it is about, and both of those carry their own timeline; a thread on the repository itself would be the one place nobody would look for it"), summarized: No("a name, an owner and the host's own description — a person reads the whole row in a glance, and a paragraph about a repository would be a paragraph about its README, which is a file the browse read already answers"), project_linkable: Yes, linkable: Yes, route_target: No("a repository is added by the owner naming one on a screen, with a host and a token behind it; nothing a classifier reads from a captured sentence could produce one"), addressable: Yes, binnable: No("FORGOTTEN, never binned — forgetting a repository is a prefix sweep over its media and a delete of its clone, and there is no half-state in between that Restore could put back. A bin promises the bytes are still there, and for a repository they are not"), shareable: No("not yet; no consent question has been asked about it. A repository's bytes are the one thing in the file that is somebody else's code as often as the owner's, and what may leave with it is a question about a licence rather than about Cotton"), },PrimitiveKind::Pull => PrimitiveSpec { table: "cotton_repo_pulls", fts: Yes, embedded: No("a title and a body that is mostly a checklist and a diff summary; a vector over \"fix the crash\" sits close to every note about a crash, and the text lane answers that question exactly"), search: SearchLane::Fts, versioned: No("the HOST is the history — a pull request's edits, its force-pushes and its state changes are all on the host's own timeline, and a second history derived from what the worker last polled would disagree with it the first time a pass was missed"), commentable: No("A REPLY IS A `repo_comment` — the timeline the host keeps is the discussion, and a Cotton comment thread beside it would be a second conversation nobody on the host can see"), summarized: No("a long pull request is summarised by its own description, which its author wrote; a generated paragraph over a diff would be an assistant guessing at an intent the title already states"), project_linkable: No("the REPOSITORY carries the membership — the child rule: a pull request belongs to its repository, and the repository belongs to the project, so a second edge would be a second answer to one question"), linkable: Yes, route_target: No("a pull request is opened from a branch, on a screen or by `pnpm forge`; a captured sentence has no head, no base and no diff, so nothing a classifier reads could produce one"), addressable: Yes, binnable: No("CLOSED, never binned — closing is the host's own state and it replicates as a column, and a bin would be a soft delete of somebody else's row that the next poll would undo"), shareable: No("not yet; no consent question has been asked about it. What a pull request says about unreleased work is the owner's to decide per repository, and that decision has no shape in the sharing design"), },PrimitiveKind::Issue => PrimitiveSpec { table: "cotton_repo_issues", fts: Yes, embedded: No("the pull request's argument, one facility over: a title and a body of prose whose meaning is already reached by the words in it"), search: SearchLane::Fts, versioned: No("the host is the history, for the pull request's reason"), commentable: No("a reply is a `repo_comment`, for the pull request's reason"), summarized: No("an issue is a question somebody wrote in their own words, and a summary of it would be a paraphrase standing between a reader and the words"), project_linkable: No("the REPOSITORY carries the membership, for the pull request's reason"), linkable: Yes, route_target: No("an issue is filed on a screen against a repository the owner chose; a capture has no repository, and guessing one would file a thought on somebody else's tracker"), addressable: Yes, binnable: No("closed, never binned, for the pull request's reason"), shareable: No("not yet; no consent question has been asked about it"), },PrimitiveKind::RepoComment => PrimitiveSpec { table: "cotton_repo_comments", fts: No("FEEDBACK'S ARGUMENT, verbatim: a workspace-wide index over comment text would answer every search with everybody's review notes, and the comment a person is looking for is always read in the timeline of the pull request it is on"), embedded: No("the same argument one lane over — a vector index over review chatter would put \"looks good to me\" next to every approving sentence in the file"), search: SearchLane::No("read in the timeline of the pull request or the issue it is on, never found on its own: a comment with no thread around it is a sentence with no subject, and a search result of one would be a tap that opens the thread anyway"), versioned: No("the host is the history — an edited comment is an edit the host recorded, and the worker writes what the host now says"), commentable: No("a reply to a comment is ANOTHER `repo_comment` with a parent, which is how the host models it; a Cotton comment on it would be a third layer nobody can see"), summarized: No("a comment is somebody's sentence, and a summary of one sentence is the sentence"), project_linkable: No("the REPOSITORY carries the membership, for the pull request's reason"), linkable: No("pointed at through the pull request or the issue it is on — an edge to one comment out of a timeline would name a row whose meaning is its neighbours"), route_target: No("a comment is typed against a pull request the owner has open; nothing routes into a timeline"), addressable: No("no page of its own in the flattened record surface: a comment is drawn in its timeline, and `get_pull` answers the whole of one"), binnable: No("the host's own delete is what removes a comment, and the next pass writes what the host now says; a Cotton bin would hold a row the host no longer has"), shareable: No("not yet; no consent question has been asked about it, and the words are somebody else's rather than the owner's"), },PrimitiveKind::Release => PrimitiveSpec { table: "cotton_repo_releases", fts: No("a tag, a name and release notes that are mostly a changelog — the list per repository is short and read in one screen, and an index over it would cost a table in every device's file to rank what a scan orders by date"), embedded: No("a changelog is a list of changes already stated in the commits it names; a vector over it would answer every question about the work with the release that shipped it"),// An indexed LIKE scan over the tag and the name — "which release// was 0.6.6" is a lookup rather than a ranking, and the answer is// one row. search: SearchLane::Like, versioned: No("a release is a MARK on a commit; editing its notes is correcting what was written about a thing that has already shipped, and the shipped thing is the tag"), commentable: No("what there is to say about a release is said on the pull requests it carries; a thread on the tag would be a conversation about a label"), summarized: No("the notes ARE the summary, written by whoever cut the release"), project_linkable: No("the REPOSITORY carries the membership, for the pull request's reason"), linkable: No("reached through its repository's releases list; an edge to a tag would point at a moment rather than at a thing, and the thing it is about is the repository"), route_target: No("a release is cut from a screen or by the shipping lane, with a tag and assets behind it; nothing a capture says could produce one"), addressable: Yes, binnable: No("the host's own delete removes a release and the next pass writes what the host now says; a bin would hold a tag the host no longer has, with assets whose bytes the sweep has already taken"), shareable: No("not yet; no consent question has been asked about it — and a release's assets are bytes whose licence is the repository's rather than the file's"), },PrimitiveKind::Run => PrimitiveSpec { table: "cotton_repo_runs", fts: No("a run has no prose in it — a workflow name, an event, a ref and a commit, every one of them a lookup rather than a search. The one thing a run does carry a lot of text in is its LOG, and a log is a file on the serving Mac rather than a row, which is the whole reason there is nothing here to index"), embedded: No("nothing in a run is a meaning: \"pr-checks.yml on main failed\" is four facts, and a vector over them would put every failure next to every other failure and answer no question either of them asked"), search: SearchLane::No("found through its repository and its number, never by a word: the runs screen lists them newest first and a pull's checks block opens the one that judged it. A run nobody can name by repository and number is a run nobody is looking for"), versioned: No("a run is a LOG of what happened, and it is written once forward — queued, in progress, completed. Its history IS its own columns plus its jobs, and a second history of the status column moving would be a history of a stopwatch"), commentable: No("what there is to say about a failed run is said on the pull request the run judged, where the person who has to fix it is already reading; a thread on a run would be a conversation about a process that has already exited"), summarized: No("the CONCLUSION is the summary, and the failing job's name is the next sentence — a generated paragraph would stand between a person and a log they are about to open"), project_linkable: No("the REPOSITORY carries the membership, for the pull request's reason"), linkable: No("reached through its repository or the pull it judged; an edge to one run would name a moment, and the thing it is about — the pull request, the repository — is already linkable"), route_target: No("a run is started by a push, a pull request, a cron tick or a dispatch the owner asked for; nothing a classifier reads from a captured sentence has a commit in it"), addressable: Yes, binnable: No("a run is HISTORY: it says what happened on a commit, and a bin promising to put one back would be promising to put back a process. Old runs age out with their logs when the owner prunes a repository, which is a sweep rather than a bin"), shareable: No("not yet; no consent question has been asked about it — and a run's log carries whatever the build printed, which is the one place a token most often ends up by accident"), },// gen-kind: primitive-spec }}/// The kinds whose spec marks a facility a member.pubfn kinds_with(facility: Facility) -> Vec<PrimitiveKind> {PrimitiveKind::ALL .into_iter() .filter(|kind| primitive(*kind).facility(facility).is_member()) .collect()}/// The kinds search-everything reaches, whatever the lane.pubfn searchable_kinds() -> Vec<PrimitiveKind> {PrimitiveKind::ALL .into_iter() .filter(|kind| primitive(*kind).search.is_searchable()) .collect()}/// Every synced table that does NOT hold a primitive's rows, and the role it/// plays instead — child rows, join tables, infrastructure.////// The gate asserts this list plus the primitives' tables partition/// `TABLE_SPECS` EXACTLY, so a new table must either declare a primitive or say/// here what it supports; there is no third, silent state.////// A list of pairs rather than a map, in the TypeScript's own declaration/// order: the reasons are read as prose beside each other, and/// [`supporting_table`] is the lookup.pubconst SUPPORTING_TABLES: &[(&str, &str)] = &[ ("cotton_media_backups", "serving-epoch bucket verification evidence for media release; bookkeeping about an object copy, never a searchable or linkable record"), ("cotton_ai_jobs", "Durable typed work for a record in this database, claimed by a device offering its AI level; supports processing and usage rather than a new kind of life record."), ("cotton_ai_calls", "AI usage: the person's record of provider calls and one transition per pause; the shared model client alone writes it."), ("cotton_ai_budgets", "AI usage: one settings record per database, with the owner's hourly and daily budgets."), ("cotton_device_keep", "What a device keeps (v118) — one keep rule of one device: a table with all, none or a horizon in days, a group always, a record always. Bookkeeping about which copies a device holds, not a record of a life; a Mac holds everything whatever a row says"), ("cotton_records", "Legacy rows of user-defined tools, retained for older peers inside the additive exchange floor until the gated non-additive retirement; current record verbs use each tool's real table. Infrastructure for carrying older writes, not a record kind of its own"), ("cotton_groups", "A group (137): a stack over one table's list, by the records a person put in it or a filter; once a _group row of the generic store."), ("cotton_group_members", "One record a person put in a group, at its place (137): a row each, so members added on two devices both survive."), ("cotton_tool_assets", "One picture a tool package carries (137), by tool and file name, its bytes as the package gave them."), ("cotton_automation_runs", "One firing of an act or automation (137): what fired, the changes it made (what an undo takes back) and how it went."), ("cotton_storage_rules", "Storage's per-device, per-tool keep rules and the device's last measured bytes; bookkeeping about copies on a disk, not another copy of the records they belong to"), ("cotton_assistant_runs", "assistant runs (v46) — one row per bounded model run the server made on the owner's own key: what was asked, which latency class it was given, what it cost, and the note it produced. Deliberately not a record kind: nobody files a run, edits one or searches for one — what it is ABOUT is the note it wrote, and the run row is the receipt and the transparency log `/activity` reads"), ("cotton_agent_accounts", "the Code tool (v14 of the Rust ladder) — one row per agent login any Mac in the household has seen (anthropic or openai, by email), with the usage windows it last reported. It replaces cotton_account_usage, which was a reading keyed by an account string and forgotten the moment a Mac signed out; this row SURVIVES A LOGOUT, so the devices page can say \"not signed in on any Mac\" beside the last reading it has. Not a record kind: nobody files, searches or links a login, and Cotton never touches the credential behind it — sign-in is the agent's own flow, on the Mac"), ("cotton_account_usage_samples", "the Code tool (v14 of the Rust ladder) — one reading of an agent account's two windows every fifteen minutes, kept for thirty days and swept after (cotton_core::rules::samples). It is the strip the accounts page draws under the latest reading. Not a record kind for the reason no sample is one: a sample has no life of its own, it is a point on a line about the row it names"), ("cotton_ai_access", "infrastructure — which AI lane a workspace may bill"), ("cotton_blocked_senders", "email — the addresses the owner does not want to hear from; an address is blocked, never a person, because most of these belong to nobody in the contact book"), ("cotton_msg_contact_handles", "child of messaging contacts (v36) — the numbers and addresses one contact is reachable at, so a person who writes from an Apple ID and a phone is ONE contact rather than two"), ("cotton_collections", "container — calendars only since the 2026-08-17 fold-down"), ("cotton_comments", "cross-cutting facility — the comment threads themselves"), ("cotton_dictations", "keyboard capture buffer — explicitly not a record kind (keyboard spec)"), ("cotton_document_pages", "child of documents — per-page text the pipeline lands"), ("cotton_email_participants", "child of email threads — the address set person matching joins against"), ("cotton_email_senders", "email (v107) — who each address that writes to the owner is: person, service or junk, written by the mail reader (never by making a person) and copied onto each thread as its sender_kind, which the People, Records and Junk stacks key on"), ("cotton_event_attendees", "child of events — per-attendee responses"), ("cotton_google_accounts", "infrastructure — calendar sync credentials"), ("cotton_usage", "Personal interaction history for Home suggestions; supporting the board, never copied into another person's database"), ("cotton_home_arrangement", "Home (v10 of the Rust ladder) — ONE row per workspace: the order the person gave Home's project caps and tool objects, and which tools they put away. Deliberately not a record kind: it is about the SCREEN, not the person's life — nobody files, searches or links an arrangement, and its absence is a real answer (the default order)"), ("cotton_links", "cross-cutting facility — the record-to-record edges"), ("cotton_device_samples", "the Code tool (v14 of the Rust ladder) — one reading of a Mac every fifteen minutes (load, free memory, free disk, sessions running, whether the build lock is held), kept for thirty days and swept after (cotton_core::rules::samples). The DEVICE row carries the latest reading; this is the thirty-day strip under it, which is how a person answers \"is that Mac usually free at this hour\" rather than only \"is it free now\". Not a record kind: a sample is a point on a line about the device it names, with no life of its own"), ("cotton_mcp_audit", "infrastructure — one row per MCP tool call, and SERVER-ONLY since v13 (cotton_store::schema::table_specs::SERVER_ONLY_TABLES): the transparency log is read on the server, of the server, and about two hundred thousand rows of it have no reader on a phone"), ("cotton_mcp_tokens", "infrastructure — pasted-token credentials, hashed in the owner's file"), ("cotton_media_album_items", "child of albums (v42) — membership, one row per picture, naming which writer put it there: the pass while the album is open, the person once it is kept"), ("cotton_media_duplicates", "child of photos and videos (v40) — the Mac's PROPOSAL that one picture is a copy of another (keep this, these are copies), decided by the owner and acted on only through remove_photo; an opinion, never a deletion"), ("cotton_media_faces", "child of photos and videos (v39) — the faces a source detected, with the rectangle each sits in; a face is evidence, the person link is the fact"), ("cotton_media_holdings", "infrastructure for media (v12 of the Rust ladder) — one row per (object, device, tier) saying which device HOLDS which bytes, so \"at least two devices hold every original\" is a query rather than a hope and a phone's eviction pass can refuse to drop the last copy of anything. Exactly one writer per row (the device it is about), and an eviction sets `dropped_at` rather than deleting, because \"I had these bytes and I no longer do\" is a fact the other devices need. Not a record kind: nobody files, searches or links a holding — it is bookkeeping ABOUT a photo, and the photo is the record"), ("cotton_media_sightings", "child of photos and videos (v39) — every place a picture was seen (a chat, the share sheet, the picker, the Apple Photos library), one row per sighting; the record is the content, this is its history"), ("cotton_meeting_utterances", "child of meetings — the transcript, one row per utterance"), ("cotton_msg_contacts", "chat — the owner's contact book for relay addressing"), ("cotton_msg_owner_settings", "chat — the owner's handle and message-me settings"), ("cotton_msg_reactions", "child of messages — deterministic-id reactions"), ("cotton_stories", "the Stories tool's rows (schema 88, owner ruling 7 Oct) — a status or story any app showed, by person, kept after the app forgets it; never a chat message. Supporting until its definition and grid land"), ("cotton_msg_receipts", "child of threads — one delivered/read cursor per reader"), ("cotton_msg_thread_participants", "child of threads — who is in the conversation"), ("cotton_msg_thread_filings", "child of threads (v114) — a chat the owner filed in a shared database: which database, and whether new messages are flowing there, paused by a newcomer, or unfiled. Not a record kind: the chat is the record, and this is where its live copy goes"), ("cotton_push_acks", "delivery acknowledgements for a device notification (v126), supporting push delivery rather than a record of the person's life"), ("cotton_device_relay_keys", "a Mac's relay identity key kept by the serving Mac (v136), supporting the household's relay roster rather than a record of the person's life"), ("cotton_arrivals", "what arrived in the personal database (rise 138): one row per arriving record and the decision on it, no longer written, supporting filing rather than a record of the person's life"), ("cotton_filing_proposals", "a filing proposal for the owner to approve or decline (rise 138), supporting filing rather than a record of the person's life"), ("cotton_audiences", "who may hold one record of a shared database (onlyyou rise): an only-you hold or the owner's release, supporting sync rather than a record of the person's life"), ("cotton_msg_thread_marks", "a reader's own marks on a filed chat (v125) — where one person keeps a chat filed in a shared database (pinned, muted, archived, cleared), in that person's personal database only. Not a record kind: the filed chat is the record, and this is how one reader keeps it"), ("cotton_news_seen", "child of news — URL dedupe memory, pruned after 60 days"), ("cotton_news_settings", "child of news — edition times and switches"), ("cotton_news_stories", "child of editions — the ranked story rows"), ("cotton_news_topics", "child of news — the declared interests the harvester walks"), ("cotton_note_attachments", "child of notes (v32 of the Rust ladder) — the pictures a note shows, one row per attached photo, video or document, in the note's own order and with a caption that overrides the record's own. A picture on a note is a REFERENCE to a record that already exists with its own bytes, its own holdings and its own bin, never a copy, so the attachment is the third row naming both sides. It is NOT `cotton_links`: that edge is symmetric, unordered and vocabulary-checked in the table itself, and an attachment is an ordered CHILD of one note — `cotton_media_album_items` one table over. There is no foreign key on `record_id`, because it names one of three tables, and therefore no cascade: a removed picture LEAVES ITS ROW and the reader answers `missing`, since a cascade would let tidying a photo library silently rewrite a note. Not a record kind: nobody files, searches or links an attachment — what it is about is the note and the picture, and both are records already"), ("cotton_thought_attachments", "child of thoughts (v36 of the Rust ladder) — the pictures a thought shows, one row per attached photo, video or document, in the thought's own order and with a caption that overrides the record's own: `cotton_note_attachments` with the owner changed, so a bug report from the phone is ONE thought with a screenshot on it. A picture on a thought is a REFERENCE to a record that already exists, never a copy; there is no foreign key on `record_id` and therefore no cascade from a removed picture (the reader answers `missing`), and no `origin_handle`, because a thought is not shareable. Not a record kind: nobody files, searches or links an attachment — what it is about is the thought and the picture, and both are records already"), ("cotton_person_suggestions", "child of people (v44) — the PROPOSAL that an imported person is someone the file already holds (\"same as <name>?\"), one row per candidate pair, open until the owner merges or says different; a question, never a merge nobody asked for. Not a primitive of its own: it has no life outside the two people it names, and the owner's answer to it is a change to THEM"), ("cotton_project_links", "cross-cutting facility — project membership rows"), ("cotton_repo_commits", "child of repositories (v16 of the Rust ladder) — the last two hundred commits on the default branch, so the repository page can draw recent history without dialling the host. The worker deletes past the window and the delete replicates like any other write. Not a record kind: a commit is a fact of the repository, there is no commit screen this phase, and tapping one opens the host's own page"), ("cotton_repo_bundles", "child of repositories (v17 of the Rust ladder) — the REPLICATION LEDGER of a held repository's bytes: one row per git bundle, with the media key the bytes are under, whether it is full or incremental, the basis it was cut from and the refs it carries. Every replicated unit in Cotton is one immutable content-addressed object and a bare clone is not one, so a repository replicates as bundles and inherits the drain, the two-holder pull, the mirror and the restore lane unchanged. Written by the serving Mac alone; a STANDBY reads these rows to know what it still has to apply, and which ones it HAS applied is a fact about its own disk and lives in a file beside its clone. Not a record kind: a bundle is how the bytes travel, and the record it is about is the repository"), ("cotton_repo_clones", "child of repositories (schema 77) — what ONE Mac's own clone of a held repository is doing, one row per (repository, device), written only by the Mac it names: `forked` with the sentence naming both commits while that Mac's default branch has forked from the newest bundle, `ok` once it has not. The serving Mac's mirror state stays on the repository row; a standby's fork used to be written there too, and the two Macs overwrote each other. Not a record kind: it is a fact about a device's disk, and the record it is about is the repository"), ("cotton_repo_rules", "child of repositories (v19 of the Rust ladder) — the BRANCH PROTECTION a merge is judged against: which check contexts must be green, how many approvals, whether a pull request whose base has moved is out of date, and whether a direct push is allowed at all. One row per repository per branch. **THE OWNER'S OWN ROUTE IS THE ONLY WRITER** (`repo.setRules`), on either origin: nothing mirrors a git host's branch protection into this table, so a repository protected from the host's own website reads here as one with no rule and a Save replaces what the host holds with what the panel sent. Mirroring it is a follow-up named in the Cotton note on Code hosting. `cotton_core::rules::repos::merge_readiness_with_rules` is the one reader. Not a record kind: a rule is a SETTING of the repository, and the repository is the record"), ("cotton_repo_labels", "child of repositories (v19 of the Rust ladder) — the labels a repository offers, with the host's own colour, so a pull request's chips can be drawn offline without asking the Mac what `bug` looks like. `name` is the natural key because a label is named by what it says and that name is what a pull's `labels` array carries. Not a record kind: nobody files a label or searches their life for one — it is vocabulary belonging to the repository"), ("cotton_repo_runners", "CI (v20 of the Rust ladder) — one row per runner the household has admitted: the uuid it sends back on every call, the labels it declared, the version it runs and when it was last seen. It holds NO credential: `credential_id` names a `cotton_code_credentials` grant, and since version 29 there is no hash of a token anywhere. **SYNCED since version 29**, where it was server-only before: which Mac answers the relay name is runtime, so a registration only the admitting Mac held was a registration the household lost on every hand-over — the 22 Sep outage, in which every runner read \"this runner is not registered with this server\". A NULL `repo_id` is a runner that takes work from every repository in the workspace. Not a record kind: a runner is a process on a machine, not a thing that happened in the person's life"), ("cotton_code_credentials", "code hosting (v29 of the Rust ladder) — the GRANT behind a `ctg_`: its id, the device that holds it, its name, its scope and its three stamps. The credential itself is SIGNED off the workspace key (`vault::code_tokens`) and stored nowhere, so this row carries no secret and is the only thing that can stop one. Since v44 it keeps the token's SHA-256 (`token_digest`, not presentable), which is what admits a live credential after the workspace key rotates past the version it was signed under, and the device id of the Mac that minted it (`minted_by`), which is who the sync route accepts the grant from besides the device it names and whose revocation revokes it — `revoked_at`, the mirror of a `cotton_revocations` fact, with the fold refusing a patch that clears it. Synced rather than server-only, which is the whole point: a grant only the minting Mac held is exactly what took the code surface down three times on 22 Sep. There is NO row for a `run` credential — a job's token names its job and dies when the job completes, because one synced row per CI job would put thousands a month into a file that reaches the person's phone. Not a record kind: a credential is a key to a surface, not a thing that happened in the person's life"), ("cotton_repo_jobs", "child of runs (v20 of the Rust ladder) — one job of one workflow run: its one `runs-on` label, the jobs it needs, its status and conclusion, the runner that took it, its steps and outputs, and the three columns that make a LOG A FILE — how many lines are on disk, the index the runner is told to trim to, and the media object the finished log was filed as. `cancel_requested` is the cancellation channel, because the runner protocol has no cancel call and no push: a job is stopped by a flag its next status report reads back. `token_digest` (v44) is the SHA-256 of the `run` token handed out with the job, which is that token's grant. Not a record kind: a job is read inside the run that planned it, and the run is the record"), ("cotton_machine_runners", "which Macs run jobs (v22 of the Rust ladder) — ONE ROW PER DEVICE saying whether that Mac runs CI jobs, which labels it declares and how many at once. SYNCED, which is the point: the phone writes the declaration and the Mac whose `device_id` it names applies it to itself. Until v22 these were three keys in `<dataDir>/env` on each machine, so nothing ran until the owner sat at it; the objection that killed a synced setting — every Mac taking work the moment one was asked to — is answered by the row being per DEVICE rather than per workspace. `cotton_secret_placements` is its shape exactly, including no foreign key on the device: a declaration about a machine outlives the approval row. Not a record kind: a declaration is a SETTING of a device, and the device is the record"), ("cotton_repo_vars", "CI (v20 of the Rust ladder) — a repository's plain CI variables, the half of the pair whose SECRET half is the vault (`cotton_secrets`, service `ci.<repo_id>`, sealed). **SERVER-ONLY**, and stored in the clear, which is exactly why the vault exists for anything that matters. Not a record kind: a variable is an input to a process"), ("cotton_session_tasks", "child of sessions (v31 of the Rust ladder) — the task list a session MIRRORS onto its own row, one row per task in the agent's own order, so a card can say \"4/6\" and a tap can show the list. `log_session { tasks }` replaces the list whole rather than patching it, because a task list is ONE value and a half-applied edit draws a task twice; the id is derived from (session, seq) so a mirror that reaches two servers is one row. Not a record kind: nobody files, searches, links or comments on a task an agent kept for itself — what it is about is the session, and the session is the record. The owner's own to-do list is `cotton_todos`, and these never become one"), ("cotton_secret_placements", "child of secrets (v6 of the Rust ladder) — a secret written onto ONE paired Mac as a file: where it goes, in what format, and the hash of what was last written so an unchanged secret is not rewritten. Not a record kind: a placement is an instruction to a machine, and the record it is about is the secret"), ("cotton_placement_proposals", "the vault's placements (v93 of the Rust ladder) — a LIST of placements an assistant asked the owner to approve (`propose_secret_placements`): its title, the items (secret id, device id, path, format; never a value) and whether the owner approved, declined or has not yet answered. Approving writes every `cotton_secret_placements` row of the list in one act, or none, because half a migration is a Mac with some of its credentials; until then no Mac writes anything. Not a record kind: a proposal is a question put to the owner, and what it is about is the secrets and the Macs"), ("cotton_vault_keys", "the vault (v6 of the Rust ladder) — one row per device that can open this workspace's passwords, holding that device's X25519 PUBLIC key and the vault master key wrapped to it, plus the literal `recovery` row for the age identity. Nothing private is in it: the private halves live in each device's Keychain, and a row is worth nothing to anybody who does not hold one"), ("cotton_vault_state", "the vault (v6 of the Rust ladder) — one row per workspace saying which version of the vault master key is current and when it was last rotated. It is what makes a device's wrap STALE rather than merely different"), ("cotton_voice_vocabulary", "infrastructure — dictation bias terms"), ("cotton_outages", "Outages (v120) — one row per continuous outage the serving Mac saw in the household: what kind, the condition it keys on, when it started and ended, what it meant for the owner and what was done, written by that Mac alone and rung to the owner on open and on close. Not a record kind: it is a fact about the household's machines, kept so the owner reads it as a list; nobody files, searches or links an outage"), ("cotton_workspaces", "infrastructure — the file's own identity row"), ("cotton_oauth_clients", "infrastructure (v9 of the Rust ladder) — the assistants the owner has CONSENTED to, with the hash of the client secret and the registration document verbatim. The row crosses at consent and never at registration, because the registration route is open to the internet. Never a live token"), ("cotton_dev_jobs", "developer jobs (v35 of the Rust ladder) — ONE ROW PER SHELL COMMAND a developer tool queued for one named Mac, with the state that Mac's own client moves it through: queued, running, done, failed, or expired when nobody claimed it inside ten minutes. A Mac accepts no inbound connection for work, so reaching one is a row it reads rather than a request anybody sends, exactly as a coding session is. The WHOLE output is an append-only file on the Mac that ran it (`log_path`) and the row carries only the bookkeeping over it and the last 64 KiB — `cotton_repo_jobs`' own shape, because ten thousand lines of build output is not something every device should hold as rows. It exists at all only while a server has `COTTON_DEV_TOOLS` on, since `dev_run_on_mac` is the one writer. Not a record kind: a command run on a machine is not a thing that happened in the person's life, and nobody files, searches or links one"), ("cotton_repo_merge_queue", "the merge queue (v38 of the Rust ladder) — ONE ROW PER PULL REQUEST THAT ASKED TO LAND on a Cotton-hosted repository. A pull is never merged on its own green: it queues, the `ci` worker squashes the queued heads one after another onto main's tip as a TRAIN, the train is checked once as that exact tree, and main moves to it. A train is its member rows (same `train_number`, base and tip); a red train of more than one dissolves into halves, so a clash is bisected without a second lane of Macs; an ejected row carries the sentence that says why. Server only — a phone reads the queue through the `Merge queue` context the train writes into the pull's own checks. Not a record kind: a pull request waiting to land is not a thing that happened in the person's life"), ("cotton_oauth_grants", "infrastructure (v9 of the Rust ladder) — the standing consent: this client may act on this database at this scope until the owner revokes it, plus (v21) the `cotton_mcp_tokens` row it minted and where its refresh chain has got to. The whole row travels, because ANY Mac of the household may be the one answering; the credential itself is signed rather than stored (`cotton_core::vault::tokens`), so no token is here to travel — only (v45) the SHA-256 of the refresh token the chain stands at, which admits it once after a key rotation and cannot be rebuilt from the row and the old key, because the token carries random bytes no row holds — guard `cotton-store/tests/no_bearer_in_the_file.rs`"), ("cotton_table_definitions", "table definitions (v46 of the Rust ladder) — one table's shape and faces as the shared-format JSON (`crate::definitions`): its columns and their types, its title, date, project and order keys, its slip, tile and page, and the paragraph an assistant reads about it. The built-in ones are seeded at every launch from the files the app ships. Not a record kind: a definition describes a kind of record rather than being a thing that happened in the person's life, and nobody files, searches or links one"), ("cotton_tool_definitions", "tool definitions (v46 of the Rust ladder) — one tool as the shared-format JSON (`crate::definitions`): its name, its picture, the tables it works with and its instructions. Not a record kind, for the table definitions' reason: it describes a way of working with records rather than being one"), ("cotton_board_definitions", "board definitions (v92) — one screen's composition as JSON (`crate::definitions::board`): the parts Home, the Tools screen, the database page or a tool's landing screen draws, in order, from a closed set. Built-in defaults are seeded at every launch; a person's row at the same id overrides one. Not a record kind, for the table definitions' reason: it describes how records are shown rather than being one"), ("cotton_toolkits", "toolkits (v97) — one starter kit a database can be made from: its name, picture, description and ordered tools, each a built-in tool key or a tool package carried inline. Kept in the personal database; the shipped kits are seeded at every launch, a person's are made with create_record (the `toolkit` built-in definition) or save_toolkit, and a shipped one is never changed in place. Not a record kind — no search, versions or links: it describes how a database begins rather than being something in the person's life — so it is a supporting built-in"), ("cotton_theme_definitions", "theme definitions (v92) — one skin as JSON (`crate::definitions::theme`): a face family's palette, type roles, metrics, texture and cap. The built-in paper theme is seeded at every launch; a database draws its own row when it has one. Not a record kind, for the table definitions' reason"), ("cotton_changes", "the change log (v47 of the Rust ladder) — one row per write through the generic verbs: its byline, the values before and after, and the change that undid it. Not a record kind: nobody files or searches a change; it is the receipt the app shows after a command and the thing `undo` reads"), ("cotton_authors", "sync identity (v49) — one row per author a device minted, the identity its stamps carry and why it was minted. Not a record kind: an author is how a write is signed, not a thing that happened in the person's life"), ("cotton_revocations", "sync identity (v49) — one row per revocation of a device, author, grant or key, with its reason and successor. Not a record kind: it is bookkeeping about who may write, and the thing revoked is the subject"), ("cotton_serving_machine", "sync (v49) — one row per serving epoch: which device served the workspace from when, and where each stream stood at the hand-over. Not a record kind: it is about the machines, not the person's life"), ("cotton_vault_retired_keys", "the vault (v49) — a retired vault master key version, wrapped under its successor so older sealed values still open. Not a record kind: nothing private is readable in it and nobody files or searches a key"), ("cotton_media_erasures", "media (v49) — one row per media object the owner erased, so every device drops the bytes and nothing re-uploads them. Not a record kind: it is a receipt about a photo or document, and that record is the record"), ("cotton_undos", "the change log (v49) — one row per undo, naming the change undone and the change that undid it. Not a record kind, for `cotton_changes`' reason: it is the receipt of a command"), ("cotton_grant_rotations", "infrastructure (v49) — one row per rotation of a standing grant's credential, the generation reached and its digest. Not a record kind: a credential's history is bookkeeping about access, not a thing that happened in the person's life"), ("cotton_databases", "infrastructure (v53) — in the personal database, one row per project database the person holds: its file id, the name the switcher shows and the person's order. Not a record kind: it lists files, it is not a thing that happened in the person's life"), ("cotton_database_departures", "infrastructure (v53) — a fact that a device, or every device, stops holding a project database: left, removed or handed over. Not a record kind: it is bookkeeping about which device holds which file"), ("cotton_person_keys", "the person key (v56) — in the personal database only, the person's one signing key: its fingerprint, its public half, and its private half sealed under the vault master key. Insert-only, synced so the phone signs as the person, and read by no MCP tool, generic record reader or export. Not a record kind, for `cotton_vault_keys`' reason: it is key material, not a thing that happened in the person's life"), ("cotton_admissions", "keys (v57) — one row per admission of a person to this database, with their rights and the admitter's signature. Not a record kind: it is bookkeeping about who may enter, and the person is the record"), ("cotton_member_person_claims", "member identity (v91) — a member's signed claim that a People record in this database represents their current admission. Not a record kind: it binds access bookkeeping to the person, who is the record"), ("cotton_device_statements", "keys (v57) — one row per statement that a device key is a member's device, signed by the person and by the device. Not a record kind: it is bookkeeping about which device may write"), ("cotton_invites", "keys (v57) — one row per invite to this database: the hash of its secret, the rights it offers and when it lapses. Not a record kind: an invite is a way in, not a thing that happened in the person's life"), ("cotton_joined_places", "In the personal database, one row per database the person joined at another person's Mac: where it is served and which Mac, so every device of the person can present itself there as that person's device. Deleted when the person leaves it."), ("cotton_imports", "imports (v70) — one row per import run that changed this database: where it came from (contacts, a chat export, a recording, a password export, the Mac's messages, calls, backup or photos), what it was in words, how many records it added and skipped, which device ran it and when. Not a record kind: a run is a receipt about records that arrived, and the records are what the person keeps"), ("cotton_connections", "connections (v73) — one row per thing Cotton keeps reading from outside: a WhatsApp number, a Google account, a mailbox, a calendar, Cloudflare, a git host, an MCP server; what it reaches, the vault secret that signs it in, its schedule and per-kind config, and the serving Mac's last read and error. Not a record kind: a connection is the door the records came through, and the records are what the person keeps"), ("cotton_person_handles", "one person across apps (v90) — every way a person is reached: a phone, an email, an Instagram, Facebook or LinkedIn handle, one row each, unique per handle, so a sender is linked to at most one person. Not a record kind: a handle is a fact about the person, and the person is the record"), ("cotton_person_languages", "Me (v109) — the languages a person speaks, one row each with how well. Not a record kind: a language is a fact about the person, and the person is the record"),];/// The synced tables a database holds as RETIRED (owner, 17 Nov 2026: the/// old screenplay tables go; Cotton Story is the one screenwriting app): no/// kind, no engine, no verb and no screen reads them, and the owner's rows/// stay in storage untouched, with their storage, history and CHECK/// vocabulary. The third written state beside a primitive's table and a/// supporting one; `crate::retired` holds the definitions they belonged to.pubconst RETIRED_TABLES: &[&str] = &["cotton_screenplays","cotton_screenplay_scenes","cotton_screenplay_characters","cotton_screenplay_drafts","cotton_screenplay_draft_scenes","cotton_screenplay_documents",// TABLE DROP 1 (27 Nov 2026): storage kept so a copy holding them retires and erases them."cotton_alarms","cotton_decisions","cotton_feedback","cotton_goals","cotton_inbox_items","cotton_locations","cotton_meetings","cotton_moods","cotton_news_editions","cotton_pages","cotton_person_notes","cotton_posts",];/// The record kinds the retired tables' storage still names — in the version/// rows' `kind` and the project links' and comments' CHECK vocabulary — that/// no longer are kinds.pubconst RETIRED_KINDS: &[&str] = &["screenplay", "screenplay_scene", "screenplay_document",// TABLE DROP 1 (27 Nov 2026)."alarm", "decision", "feedback", "goal", "location", "meeting", "news_edition", "page", "person_note", "thought",];/// What a supporting table supports, or `None` if it is not one.pubfn supporting_table(table: &str) -> Option<&'static str> { SUPPORTING_TABLES .iter() .find(|(name, _)| *name == table) .map(|(_, role)| *role)}#[cfg(test)]#[path = "primitives_tests.rs"]mod tests;