Cotton code
579 lines · 26.7 KB · RustRaw
//! 33 primitives, the verb grid over the primitives registry. Every kind has an answer or//! a reason its verb is unavailable.use crate::mcp::tool_surface::{VerbCell, VerbSet};/// Every record kind the primitives registry declares — `PRIMITIVE_KINDS`.////// A HAND COPY of `cotton_core::constants::PrimitiveKind::ALL`, and/// `the_kind_list_is_the_registrys_own` holds the two equal. It is a copy at/// all because the grid below is keyed by the same strings and reads better/// beside them; it stopped being an UNHELD copy on 2026-09-20, when adding a/// kind to the enum would have left a silent hole in the verb grid — which is/// the exact failure the grid's own doc comment says it exists to prevent.pub static PRIMITIVE_KINDS: &[&str] = &[    "todo",    "todo_recurrence",    "event",    "note",    "journal",    "person",    "transaction",    "statement",    "money_account",    "statement_line",    "evidence",    "document",    "memory",    "email_thread",    "email",    "thread",    "message",    "session",    "session_message",    "project",    "prompt",    "photo",    "video",    "album",    "call",    "secret",    "device",    "repository",    "pull",    "issue",    "repo_comment",    "release",    "run",    // gen-kind: primitive-kinds];/// The kinds `get_record` can EXPAND. The grid must never promise/// `get_record` for a kind the validator would refuse.pub static GET_RECORD_KINDS: &[&str] = &[    "todo",    "event",    "note",    "journal",    "person",    "document",    "memory",    "transaction",];/// Every verb of a code-hosting kind (`repository`, `pull`, `issue`,/// `repo_comment`, `release`, `run`): the tables are held as retired.const RETIRED_CODE: &str = r#"the code tables are held as retired (TABLE DROP 1, 27 Nov 2026): nothing serves, reads or writes them"#;/// Cross-cutting tools no single primitive owns.pub static SHARED_TOOLS: &[&str] = &[    // Database lifecycle belongs to the serving Mac, outside record verbs.    "archive_database",    "list_databases",    // reserve@1: a claim against any package's capacity, and its release.    "reserve_record",    "run_record_act",    "cancel_reservation",    // The serving server's daily copy to the backup disk, taken on demand.    "backup_now",    "move_record",    "move_records",    "parse_phrase",    "search_records",    "get_record",    "update_summary",    "today_agenda",    "notify_owner",    "brief",    "recall",    "list_bin",    "restore_from_bin",    "empty_bin",    "storage_summary",    "media_repair",    // What a phone keeps: rules over tables, groups and records alike, shown    // on the phone's device row — never a write to the device list itself.    "list_keep_rules",    "set_keep_rule",    "clear_keep_rule",    // Who may hold a record of a shared database: the owner's act.    "set_audience",    "create_link",    // History is every versioned kind's, so putting a version back is too.    "restore_version",    // The generic record verbs (store v47): one set over every table, addressed    // by the table definition's id rather than owned by one kind.    "export_tool",    "import_tool",    "list_tools",    "list_toolkits",    "save_toolkit",    "update_toolkit",    "delete_toolkit",    "remove_tool",    "add_tool",    "update_definition",    "arrange_tools",    "list_records",    "get_record_by_table",    "summarize_records",    "reserve_record",    "cancel_reservation",    "create_record",    "update_record",    "save_theme",    "get_board",    "update_board",    "delete_record",    "reorder_records",    "link_records",    "undo",    // Groups (Spec 6): hand-picked lists of one table's records.    "list_groups",    "create_group",    "update_group",    "delete_group",    // Connections (Spec 9.7): the mapping an MCP server connection reads by.    "list_connections",    "get_connection",    "propose_connection_mapping",    "set_connection_mapping",    // A mailbox or a calendar wired to a password already in the vault.    "connect",];/// The DEVELOPER TOOLS, named once so the verb grid stays total.////// They are not a primitive's verbs and they are not shared facilities: what/// they have in common is not a table but a SWITCH — `COTTON_DEV_TOOLS`, which/// is the only thing that makes them exist (the owner's decision of 27 Sep 2026,/// [until-the-app-goes-public-a-developer-mcp-dev-tools-behind-a-ser]). So they/// take a place of their own here rather than being filed under a kind they only/// half belong to, and `every_tool_is_owned_by_exactly_one_primitive_or_shared`/// counts this list as a claim.////// HELD AGAINST THE PREFIX IN BOTH DIRECTIONS: every name here begins/// `dev_` and every `dev_`-prefixed tool in the catalogue is here/// (`tool_surface_tests`). A developer tool that reached the catalogue without a/// line here would be one the grid never noticed, and a line here naming/// nothing would be a promise to a model that no handler keeps.pub static DEV_TOOLS: &[&str] = &[    "dev_reveal_secret",];/// One row per primitive kind, in the registry's own order.pub static TOOL_SURFACE: &[(&str, VerbSet)] = &[    (        "todo",        VerbSet {            create: VerbCell::Tool("create_todo"),            list: VerbCell::Tool("list_todos"),            get: VerbCell::Tool("get_record"),            update: VerbCell::Tool("update_todo"),            remove: VerbCell::Not(                r#"delete_record { table: "todo" } puts a todo in the bin, as every record; completing or dropping it is update_todo's status"#,            ),            also: &["complete_todo", "update_todos"],        },    ),    (        "todo_recurrence",        VerbSet {            create: VerbCell::Not(                r#"born from create_todo's rrule — the repeat is part of the todo's own grammar"#,            ),            list: VerbCell::Not(r#"the occurrences it mints are the todos list_todos shows"#),            get: VerbCell::Not(r#"machinery behind its todos; nothing to expand"#),            update: VerbCell::Not(                r#"editing one occurrence is update_todo; reshaping the rule is its own record page in the app"#,            ),            remove: VerbCell::Not(                r#"ends by editing the rule in the app; occurrences already minted stay todos"#,            ),            also: &[                "make_todo_recurring",                "update_todo_recurrence",                "stop_todo_recurrence",                "materialize_todo_recurrences",            ],        },    ),    (        "event",        VerbSet {            create: VerbCell::Tool("create_event"),            list: VerbCell::Tool("list_events"),            get: VerbCell::Tool("get_record"),            update: VerbCell::Tool("update_event"),            remove: VerbCell::Tool("delete_event"),            also: &[                "update_events",                "delete_events",                "respond_to_invite",                "update_attendees",            ],        },    ),    (        "note",        VerbSet {            create: VerbCell::Tool("create_note"),            list: VerbCell::Not(                r#"no browse verb yet — search_records and get_project reach notes; a bare chronological list of every note is the app's Notes tool"#,            ),            get: VerbCell::Tool("get_record"),            update: VerbCell::Tool("update_note"),            remove: VerbCell::Not(                r#"archive_note puts it away and unarchive_note brings it back — an assistant never erases prose"#,            ),            also: &[                "archive_note",                "unarchive_note",                "upsert_managed_note",                "list_managed_notes",            ],        },    ),    (        "journal",        VerbSet {            create: VerbCell::Tool("append_journal"),            list: VerbCell::Not(                r#"a journal is read by date; search_records covers recall, and the day's page rides get_record"#,            ),            get: VerbCell::Tool("get_record"),            update: VerbCell::Not(                r#"append-only by design — the day's page grows through append_journal, it is not rewritten"#,            ),            remove: VerbCell::Not(                r#"a journal page IS its date; deleting one would lie about the day"#,            ),            also: &[],        },    ),    (        "person",        VerbSet {            create: VerbCell::Tool("create_person"),            list: VerbCell::Tool("list_people"),            get: VerbCell::Tool("get_record"),            update: VerbCell::Tool("update_person"),            remove: VerbCell::Not(                r#"archive_person puts them away and unarchive_person brings them back — a person anchors money, links and threads, so nothing is ever erased"#,            ),            also: &[                "archive_person",                "unarchive_person",                "merge_people",                "sync_device_contacts",            ],        },    ),    (        "transaction",        VerbSet {            create: VerbCell::Tool("record_transaction"),            list: VerbCell::Tool("list_money_transactions"),            get: VerbCell::Tool("get_record"),            update: VerbCell::Tool("update_transaction"),            remove: VerbCell::Tool("delete_transaction"),            also: &[                "list_money_accounts",                "settle_expected",                "set_period",                "set_tag",                "set_person",                "mark_transfer",                "match_external",                "create_money_account",                "update_money_account",            ],        },    ),    (        "statement",        VerbSet {            create: VerbCell::Tool("read_statement"),            list: VerbCell::Tool("list_statements"),            get: VerbCell::Tool("get_statement"),            update: VerbCell::Tool("update_statement_line"),            remove: VerbCell::Not(                r#"a statement IS its document — delete the document and the statement goes with it; figures with no paper behind them are not something anyone can check"#,            ),            also: &["book_statement", "submit_statement_reading"],        },    ),    (        "money_account",        VerbSet {            create: VerbCell::Not("Created by the money engine, never by generic writes."),            list: VerbCell::Tool("list_records"),            get: VerbCell::Tool("get_record_by_table"),            update: VerbCell::Not("Changed by the money engine, never by generic writes."),            remove: VerbCell::Not("Removed by the money engine, never by generic writes."),            also: &[],        },    ),    (        "statement_line",        VerbSet {            create: VerbCell::Not("Created by the money engine, never by generic writes."),            list: VerbCell::Tool("list_records"),            get: VerbCell::Tool("get_record_by_table"),            update: VerbCell::Not("Changed by the money engine, never by generic writes."),            remove: VerbCell::Not("Removed by the money engine, never by generic writes."),            also: &[],        },    ),    (        "evidence",        VerbSet {            create: VerbCell::Tool("attach_evidence"),            list: VerbCell::Tool("list_records"),            get: VerbCell::Tool("get_record_by_table"),            update: VerbCell::Not("Evidence is attached or removed, never edited."),            remove: VerbCell::Tool("remove_evidence"),            also: &[],        },    ),    ("document", VerbSet {        create: VerbCell::Tool("file_document"),        list: VerbCell::Tool("list_documents"),        get: VerbCell::Tool("get_document"),        update: VerbCell::Tool("update_document"),        remove: VerbCell::Tool("delete_document"),        also: &["search_documents", "get_document_bytes", "request_document_upload", "export_package", "import_package"],    }),    ("memory", VerbSet {        create: VerbCell::Tool("remember"),        list: VerbCell::Not(r#"brief and recall are the readers — memory surfaces as context, never as a browsable table"#),        get: VerbCell::Tool("get_record"),        update: VerbCell::Tool("memory_update"),        remove: VerbCell::Tool("memory_archive"),        also: &["memory_reorder"],    }),    ("email_thread", VerbSet {        create: VerbCell::Not(r#"a thread exists the moment its first email is ingested — ingest_emails mints it from the conversation key"#),        list: VerbCell::Tool("list_email_threads"),        get: VerbCell::Tool("read_email_thread"),        update: VerbCell::Not(r#"the state a conversation has — read, starred, inbox, bin — is per MESSAGE, which is Gmail's own model, so update_email takes a threadId and applies to every message in it; subject and participants come from the mail itself, and the summary is update_summary's"#),        remove: VerbCell::Not(r#"binned with update_email { threadId, bin: true } and erased only by empty_bin — what was said stays until the owner throws it away"#),        also: &[],    }),    ("email", VerbSet {        create: VerbCell::Tool("ingest_emails"),        list: VerbCell::Not(r#"read_email_thread pages a thread and list_email_senders groups across them; a flat list of every email in the archive is a question nobody asks"#),        get: VerbCell::Not(r#"an email is read in its thread's context — read_email_thread carries full bodies"#),        update: VerbCell::Tool("update_email"),        remove: VerbCell::Not(r#"binned with update_email { bin: true } and erased only by empty_bin — nothing removes an email in one act, because the whole point of a bin is that being wrong costs a tap"#),        also: &["update_emails", "list_email_senders", "block_sender", "unblock_sender", "list_blocked_senders", "add_sender_to_people", "empty_junk"],    }),    ("thread", VerbSet {        create: VerbCell::Not(r#"a conversation arrives with the import — the archive is read from WhatsApp, iMessage and SMS, and nothing in Cotton starts one"#),        list: VerbCell::Tool("list_message_threads"),        get: VerbCell::Tool("read_message_thread"),        update: VerbCell::Not(r#"a thread's name and membership are the import's, not a record patch — the summary is the one owner-side field, and update_summary writes it"#),        remove: VerbCell::Not(r#"clearing or archiving a chat is the owner's private state, written only by their devices (clear_thread, set_thread_archived and delete_thread are those devices' own verbs, owner-scope)"#),        also: &[            // Every one below is owner-scope and is listed to nobody: the            // cells above refuse the assistant in writing, and these are the            // NAMES the owner's own app needs because `write { tool }` is its            // one write path. All of them write the owner's PRIVATE state over            // an imported conversation; none touches its content.            "mark_thread_read",            "mark_thread_unread",            "set_thread_muted",            "set_thread_pinned",            "set_thread_archived",            "clear_thread",            "delete_thread",        ],    }),    ("message", VerbSet {        create: VerbCell::Not(r#"an assistant never writes a message into a chat — messages arrive through the import (cotton-client/src/ingest/), and the one text written out is the owner's own, from their own app, into a WhatsApp chat that can send; the multi-person relay is removed, and its code is on the branch archive/sharing-v1"#),        list: VerbCell::Not(r#"read_message_thread pages a conversation; messages are never listed across conversations"#),        get: VerbCell::Not(r#"a message is read in its conversation's context"#),        update: VerbCell::Not(r#"a message in the archive is what was actually written — nothing edits it; the owner's own app only sends a failed text of theirs again"#),        remove: VerbCell::Not(r#"removing a line from this copy is the owner's own act, not a record tool (hide_chat_messages is the owner's, owner-scope)"#),        also: &[            "search_messages",            // Owner-scope, listed to nobody — see the `thread` row.            "hide_chat_messages",            "star_message",        ],    }),    ("session", VerbSet {        create: VerbCell::Tool("create_session"),        list: VerbCell::Tool("list_sessions"),        get: VerbCell::Tool("get_session"),        update: VerbCell::Not(r#"a session's state is written by the Mac that runs it and by the agent's own hooks; log_session adds what only the session knows, and the owner's own two writes are rename_session and move_session"#),        remove: VerbCell::Not(r#"the work happened; the log is the audit trail"#),        also: &[            "move_session",            // The owner's name for a session — their write, as the filing is.            "rename_session",            // `log_session` is the SESSION'S OWN write, not the create: it            // records a session that already exists somewhere — on a Mac, in a            // cloud run — and `create_session` is what brings one into being.            // Both write the same table and only one of them can hold the            // create cell.            "log_session",            // A PROJECT'S STANDING CONVERSATION (v31) — the one session per            // project the owner talks to, opened here if it has none.            "open_project_conversation",            // THE QUEUE IS THE SESSION LIST NOW (v23). `poll_session_launches`,            // `update_session_launch` and `list_launches` were the three verbs            // of `cotton_session_launches`, a second row beside the session            // that the launch folded into; `list_sessions` answers `queued`            // rows with the rest, and the Mac that runs one claims its own row            // against its own copy of the file rather than over MCP.            //            // "NOTHING OVER MCP STARTS A SESSION" WAS THE RULE HERE UNTIL v31,            // and it is RETIRED. It was a rule            // about WHO: starting an agent on somebody's Mac is the owner's            // act. A project's CONVERSATION is a session the owner opened, on            // a Mac they admitted, and opening threads is the whole of what it            // is for — so a session is opened by the owner in the app OR by a            // session over MCP, and every opening goes through the one            // `cotton_tools::session_birth::write_session`.            //            // `list_agent_accounts` sat here until the AI-account tables were            // retired (OPEN TABLES, owner, 24 Nov 2026). `list_machines` and            // `forget_machine` went at v14: `list_devices` answers a machine.        ],    }),    // RETIRED (owner, 15 Nov 2026): the session inbox went, and with it the    // four bus verbs. The rows already written are the owner's and stay.    ("session_message", VerbSet {        create: VerbCell::Not(r#"the session inbox is retired: no message is written any more"#),        list: VerbCell::Not(r#"the session inbox is retired; search_records still finds the messages already kept"#),        get: VerbCell::Not(r#"the session inbox is retired; the messages already kept are read through search_records"#),        update: VerbCell::Not(r#"the session inbox is retired: a kept message is the record of what was asked"#),        remove: VerbCell::Not(r#"the queue is the audit trail; a withdrawn message says it was withdrawn"#),        also: &[],    }),    ("project", VerbSet {        create: VerbCell::Tool("create_project"),        list: VerbCell::Tool("list_projects"),        get: VerbCell::Tool("get_project"),        update: VerbCell::Tool("update_project"),        remove: VerbCell::Not(r#"archived by status through update_project; the linked records outlive any project"#),        also: &["link_to_project", "unlink_from_project"],    }),    ("prompt", VerbSet {        create: VerbCell::Not(r#"private by construction — prompts are logged with their session, never authored as records"#),        list: VerbCell::Not(r#"private by construction; a prompt surfaces only as its session's search hit"#),        get: VerbCell::Not(r#"private by construction"#),        update: VerbCell::Not(r#"written once at log time"#),        remove: VerbCell::Not(r#"the session log is the audit trail"#),        also: &[],    }),    ("photo", VerbSet {        create: VerbCell::Tool("add_photo"),        list: VerbCell::Tool("list_photos"),        get: VerbCell::Tool("get_photo"),        update: VerbCell::Tool("update_photo"),        remove: VerbCell::Tool("remove_photo"),        also: &["get_photo_bytes", "update_face", "list_duplicates", "decide_duplicate"],    }),    ("video", VerbSet {        create: VerbCell::Not(r#"a video enters as bytes — the app's picker or share sheet, or a chat; assistants describe and file what exists"#),        list: VerbCell::Tool("list_videos"),        get: VerbCell::Tool("get_video"),        update: VerbCell::Tool("update_video"),        remove: VerbCell::Tool("remove_video"),        also: &[],    }),    ("album", VerbSet {        create: VerbCell::Tool("create_album"),        list: VerbCell::Tool("list_albums"),        get: VerbCell::Tool("get_album"),        update: VerbCell::Tool("update_album"),        remove: VerbCell::Not(r#"dismissed is the album's own state — decide_album; nothing about an album is deleted, and the pictures in it are never touched"#),        also: &["decide_album"],    }),    ("call", VerbSet {        create: VerbCell::Not(r#"a call is not made in Cotton and never recorded by hand — the row is what a device read out of the phone's own log, and an assistant writing one would be inventing a conversation that never happened"#),        list: VerbCell::Tool("list_calls"),        get: VerbCell::Tool("get_call"),        update: VerbCell::Not(r#"a device's record of what happened is not edited — what was said on a call is a note, never an edit of the log"#),        remove: VerbCell::Not(r#"a call log entry is a fact the phone recorded; nothing deletes one by rule, and an assistant erasing evidence nobody asked to lose is the opposite of what this record is for"#),        also: &[],    }),    // The vault (v6 of the Rust ladder). The three secrets verbs were SHARED    // tools while `cotton_secrets` was a supporting table with no kind of its    // own; a secret is a primitive now, so they are its verbs and `get` is the    // written refusal it has always been in practice.    ("secret", VerbSet {        create: VerbCell::Tool("create_secret"),        list: VerbCell::Tool("list_secrets"),        get: VerbCell::Not(r#"THERE IS NO get_secret AND THERE WILL NOT BE ONE. A record surface for a secret could carry only the plain columns — name, site, username, service and the four-character hint — which is exactly what list_secrets already answers; and the one field an expander would seem to promise is the one nothing over MCP may ever read. The reveal is the owner's own app, against its own copy of the file, with a key only their device holds"#),        update: VerbCell::Tool("update_secret"),        remove: VerbCell::Tool("delete_secret"),        // Asking the owner to put secrets on Macs: where, never what.        also: &[],    }),    // A device, v13. ONE verb and four written refusals, and the refusals are    // the point: every write to this table is a person on a screen, and a tool    // that could perform one is a tool an assistant could be talked into    // performing. Cotton note "Devices — how a machine is admitted to your database".    ("device", VerbSet {        create: VerbCell::Not(r#"a device JOINS — it presents its own key, six digits appear on both screens, and a person already in compares them and says yes. There is nothing for a tool to call: the whole point of the pairing design is that admission costs a human comparing a number, and a create verb would be a way to skip that"#),        list: VerbCell::Tool("list_devices"),        get: VerbCell::Not(r#"list_devices answers whole — a person has a handful of devices and every column of each is in that answer, so an expander would promise a page that is not there"#),        update: VerbCell::Not(r#"renaming a device is the owner's own act in their own app, on the Your devices screen or on the device itself. A label is what a person recognises their own Mac by, and an assistant rewriting it would be an assistant rewriting the list they read to decide what to revoke"#),        remove: VerbCell::Not(r#"THERE IS NO revoke_device AND THERE WILL NOT BE ONE. Revoking a key is the one act that decides who may open this database at all, and a tool that could do it is a tool that could lock the owner out of their own data — or quietly cut off the Mac that serves it. Revoke and Leave are red rows on a screen, confirmed by the person, and a revocation is MONOTONE besides: nothing undoes one, so being wrong once is permanent"#),        also: &[],    }),    // The code-hosting kinds are held as retired (TABLE DROP 1, 27 Nov 2026):    // the kinds stay in the registry until the erase, and every verb refuses.    ("repository", VerbSet {        create: VerbCell::Not(RETIRED_CODE),        list: VerbCell::Not(RETIRED_CODE),        get: VerbCell::Not(RETIRED_CODE),        update: VerbCell::Not(RETIRED_CODE),        remove: VerbCell::Not(RETIRED_CODE),        also: &[],    }),    ("pull", VerbSet {        create: VerbCell::Not(RETIRED_CODE),        list: VerbCell::Not(RETIRED_CODE),        get: VerbCell::Not(RETIRED_CODE),        update: VerbCell::Not(RETIRED_CODE),        remove: VerbCell::Not(RETIRED_CODE),        also: &[],    }),    ("issue", VerbSet {        create: VerbCell::Not(RETIRED_CODE),        list: VerbCell::Not(RETIRED_CODE),        get: VerbCell::Not(RETIRED_CODE),        update: VerbCell::Not(RETIRED_CODE),        remove: VerbCell::Not(RETIRED_CODE),        also: &[],    }),    ("repo_comment", VerbSet {        create: VerbCell::Not(RETIRED_CODE),        list: VerbCell::Not(RETIRED_CODE),        get: VerbCell::Not(RETIRED_CODE),        update: VerbCell::Not(RETIRED_CODE),        remove: VerbCell::Not(RETIRED_CODE),        also: &[],    }),    ("release", VerbSet {        create: VerbCell::Not(RETIRED_CODE),        list: VerbCell::Not(RETIRED_CODE),        get: VerbCell::Not(RETIRED_CODE),        update: VerbCell::Not(RETIRED_CODE),        remove: VerbCell::Not(RETIRED_CODE),        also: &[],    }),    ("run", VerbSet {        create: VerbCell::Not(RETIRED_CODE),        list: VerbCell::Not(RETIRED_CODE),        get: VerbCell::Not(RETIRED_CODE),        update: VerbCell::Not(RETIRED_CODE),        remove: VerbCell::Not(RETIRED_CODE),        also: &[],    }),    // gen-kind: tool-surface];