/** * The acts `POST /v1/act` dispatches, each with its arguments and what it * does. The dispatch in src/business.ts is keyed by this table (a name here * with no branch there, or a branch with no name here, does not compile), and * Cotton MCP's `run_act` lists and admits exactly these. */ export const ACTS = { definition: { args: ["kind", "definition?", "remove?", "base?"], meaning: "the owner puts a tool, board or theme whole, changes only a table's look, or removes a whole by id; base is the last definition the phone received, and a conflict answers the object's version" }, book: { args: ["slot", "quantity?", "member?"], meaning: "books a slot through its table's reserve act; staff and the owner name the member, a member books for themselves" }, order: { args: ["slot", "quantity?", "member?"], meaning: "the same as book, said for a kitchen's dish" }, cancel: { args: ["id"], meaning: "cancels a booking or an order; a member cancels only their own, and never a day already past" }, record_act: { args: ["table", "id", "act", "picked?"], meaning: "runs an act a table's definition declares (its `acts`) on one of its records; `picked` answers the act's picks in order" }, message: { args: ["text", "about?", "person?"], meaning: "writes a message between the business and a person; staff and the owner name the person" }, profile: { args: ["name"], meaning: "a signed-in person names themselves, and their card follows" }, create: { args: ["table", "data", "id?"], meaning: "writes a new record directly: the owner, or staff on a table staff may write" }, update: { args: ["table", "id", "data", "expect_version?"], meaning: "changes a record directly, under the same rule as create; with expect_version, kept only while the row is still at that version, else refused (version_moved) and the writer reads it again" }, delete: { args: ["table", "id"], meaning: "removes a record directly, under the same rule as create" }, seal: { args: ["table", "id", "expect_version", "data", "blind?"], meaning: "the owner's own device (never a token) seals a row of a sealed table: data is the row's clear columns and its seal (the sealed blob, the wrapped row key and the table key's version), blind its blind tokens, each the decimal text of a signed 64-bit number; kept only while the row is still at expect_version, else refused and the device reads it again; the row's open copies of its sealed columns go, from the row and from its logged changes" }, seal_many: { args: ["rows"], meaning: "the owner's own device seals up to 200 rows in one act, each as `seal` does ({ table, id, expect_version, data, blind? }): each row kept or refused on its own (a row moved since is refused version_moved and the rest still land). Answers { results: [{ table, id, ok, status?, code? }] } in the order asked (SYNC STUCK, 25 Nov 2026: a phone's sweep sealed one row per round trip)" }, seal_stage: { args: ["table", "rows"], meaning: "the owner's own device (never a token) migrating a sealed table's open rows (sealing plan §7): at most 500 rows of { id, expect_version, data, blind? }, each row's sealed twin, kept beside its clear row, which is not touched; a row the object lacks or at another version than expect_version is left by name. Answers { staged: [{ id, twin }], left: [{ id, code }] }; the device reads the twins back (GET /v1/seal/twins), opens each, and commits only those it verified" }, seal_commit: { args: ["table", "twins"], meaning: "the owner's own device puts at most 500 verified twins (seal_stage's ids) in place of their rows, each only while its row is still at the version it was staged at, else the twin goes and the row is left, its version moved; the row's open copies of its sealed columns go, from the row and from its logged changes. Answers { sealed: [ids], left: [{ id, code }] }" }, seal_purge: { args: ["table"], meaning: "the owner's own device takes a sealed table's sealed columns out of the act log's earlier args, once its rows are sealed. Answers { table, scrubbed }" }, unlock_allow: { args: ["request_id", "tables", "minutes", "wrapped", "signer", "sig"], meaning: "the owner's own device (never a token) allows an unlock request: tables the subset it allows, minutes 1 to 15 and no more than asked, wrapped the w1 wrap to the request's worker_pub of every table key version and blind key, signer the person key's fingerprint and sig its Ed25519 signature over the unlock statement; the object checks the signature, opens the wrap, deletes the request's key, and opens the window until now plus minutes on its own clock. Answers { grant, ends_at }" }, assistant_allow: { args: ["request_id?", "grant_id?", "member_id?", "member_secret?", "name?", "tables", "withheld", "wrapped", "signer", "sig"], meaning: "the owner's own device (never a token) makes or widens the standing grant to their own Claude (src/agent.ts): request_id answers the one card, grant_id re-signs a live grant, member_id with member_secret is Connect Claude (the phone's own member pair, waiting at most 15 minutes for the next connection); tables the tables whose keys the wrap hands, withheld the policy (every sealed table except these; passkey, secret and the retired code runner's credentials always), wrapped the w1 wrap to the member key, sig the person key's Ed25519 signature over the agent statement. Answers { grant, member }" }, assistant_add: { args: ["grant_id", "tables", "wrapped"], meaning: "the owner's own device hands more keys inside a live grant's signed policy (a table the kit added, a table's next key version): wrapped to the member key, unsigned; a withheld table is refused" }, assistant_scope: { args: ["table", "access"], meaning: "the owner's own device sets a sealed table on, ask (a read files a timed card) or off (refused) for their Claude; on is refused while the signed policy withholds it. Answers { table, access }" }, assistant_remove: { args: [], meaning: "the owner's own device ends every grant to their Claude and drops every wrap; the phone moves those tables to fresh keys. Answers { ended }" }, unlock_decline: { args: ["request_id"], meaning: "the owner's own device says not now to an unlock request; its key goes" }, unlock_end: { args: ["grant_id"], meaning: "the owner's own device ends an unlock window now: the object drops its keys" }, restore: { args: ["rows"], meaning: "the owner's phone brings back the rows its copy of a database that is gone still holds (restore-from-phone, 10 Nov 2026): at most 500 rows of { table, id, data, created_at?, updated_at? } in order, each kept with its own id and times. A row the object lacks is made; one it holds live takes the phone's version when the phone's updated_at is not older than its own and keeps its own otherwise; one it deleted stays deleted. A held id is answered, never refused; a row the object cannot take (a table it lacks, a link to a row it lacks) refuses the whole call and nothing is kept. Answers { restored: [{ table, id, landed }] }, landed made, written, unchanged, standing or deleted" }, import_rows: { args: ["rows"], meaning: "the owner's Mac importer (its own device, never a token) lands the rows its import engine planned over its own copy (messages, calls, mail, stories), in one transaction: at most 500 rows of { table, id, data?, blind?, created_at?, updated_at?, retract? } in order. A row the object lacks (or deleted) is made under its id; one it holds takes data as a patch; retract deletes it. A sealed table's row carries its seal (the sealed block, its wrapped key and its seal version) and its blind tokens, never a sealed column in the clear. Answers { made, changed } by table" }, set_role: { args: ["phone", "role", "name?"], meaning: "the owner makes the person at a phone number a member, staff or an owner; a member again loses their signed-in sessions" }, mint_token: { args: ["name", "scopes", "expires_in_days?", "machine?", "allow?"], meaning: "the owner mints a Cotton MCP token (personal database only); the answer carries the token once. allow { read, write, outward } is what it may do: unnamed, the narrowest useful set (its memory and session logs)" }, token_allow: { args: ["id", "allow"], meaning: "the owner's own device sets what a token may do: allow { read: [tables] | \"*\", write: [tables] | \"*\", outward }; an OAuth connection's later tokens carry it" }, revoke_token: { args: ["id"], meaning: "the owner ends a Cotton MCP token; its row stays, revoked" }, merge_people: { args: ["keep", "drop"], meaning: "two people are one (Contacts' merge; the phone has already filled keep's sealed fields): every clear link to drop, on every table, names keep instead, in one write; drop is archived with merged_into keep; a link inside a seal is named in left for the phone that holds it" }, unmerge_people: { args: ["id"], meaning: "every merge into this person in the last 30 days is undone: each row the merge moved and still pointing here points back, and the merged person leaves the archive" }, make_todo_recurring: { args: ["todo", "rrule", "dtstart?"], meaning: "a todo becomes the first occurrence of a repeating series (an iCal rule: FREQ=DAILY, WEEKLY, MONTHLY or YEARLY, with INTERVAL, COUNT, UNTIL and a weekly BYDAY), anchored at dtstart or its own due; the next occurrence comes when it is finished or its moment passes" }, update_todo_recurrence: { args: ["recurrence", "rrule?", "dtstart?", "title?", "notes?", "priority?", "paused?"], meaning: "a repeating todo's series takes what is given; its open occurrences still ahead follow (a new rule, anchor or a pause bins them and makes the next one owed); overdue and finished ones are never touched" }, stop_todo_recurrence: { args: ["recurrence", "keep?"], meaning: "a repeating todo stops: the series goes to the bin with its open occurrences still ahead, except keep; every open one left becomes a plain todo; finished ones stay" }, // Retired apps' acts (TABLE DROP 1, 27 Nov 2026): each answers 410 retired, naming its app (src/business.ts RETIRED_ACTS). read_statement: { args: [], meaning: "Money is retired: refused 410 retired, its tables are no longer served" }, submit_statement_reading: { args: [], meaning: "Money is retired: refused 410 retired, its tables are no longer served" }, book_statement: { args: [], meaning: "Money is retired: refused 410 retired, its tables are no longer served" }, settle_expected: { args: [], meaning: "Money is retired: refused 410 retired, its tables are no longer served" }, match_external: { args: [], meaning: "Money is retired: refused 410 retired, its tables are no longer served" }, merge_accounts: { args: [], meaning: "Money is retired: refused 410 retired, its tables are no longer served" }, subscribe_podcast: { args: [], meaning: "Podcasts is retired: refused 410 retired, its tables are no longer served" }, refresh_podcast: { args: [], meaning: "Podcasts is retired: refused 410 retired, its tables are no longer served" }, import_opml: { args: [], meaning: "Podcasts is retired: refused 410 retired, its tables are no longer served" }, export_opml: { args: [], meaning: "Podcasts is retired: refused 410 retired, its tables are no longer served" }, fetch_cover: { args: [], meaning: "Music is retired: refused 410 retired, its tables are no longer served" }, find_lyrics: { args: [], meaning: "Music is retired: refused 410 retired, its tables are no longer served" }, drop_old_music: { args: [], meaning: "Music is retired: refused 410 retired, its tables are no longer served" }, start_book: { args: ["book"], meaning: "the owner starts reading a book: its status becomes reading and started_on today (the database's own day); a finished book started again is a re-read, its finished_on cleared. Refused when it is being read already" }, finish_book: { args: ["book"], meaning: "the owner finished a book: its status becomes finished, finished_on today and read_count one more. Refused when it is finished already" }, find_book: { args: ["query?", "isbn?", "book?"], meaning: "looks a book up on Open Library: a query (its name, and its author if known) makes a Want to read book from the first match, or fills the book already holding that Open Library work; an isbn makes one; either fills the book named by book instead (its Find details). Only empty columns are filled (title, author, year, pages, isbn, ol_work, language, cover); answers { book, made, filled }, and cover_unanswered when Open Library did not answer for the cover. Nothing found is refused, and so is a lookup Open Library turns away for being asked too often or does not answer even when asked a second time: try it again later" }, import_goodreads: { args: ["file"], meaning: "brings a Goodreads library export (its CSV text, as Goodreads writes it: My Books › Import and export › Export Library): each row is a book, found again by its Goodreads id so a second import updates it, never backwards: status only moves forward (want_to_read, reading, stopped, finished; a dnf shelf never stops a finished book) and dates, position, progress, rating and review already set in Cotton are only filled when empty; Exclusive Shelf gives the status (to-read want_to_read, currently-reading reading, read finished, a shelf naming dnf stopped), every other shelf is a list of books made once by its name, and ratings, reviews, dates, pages and times read come across, 0 meaning none. Answers { books, made, updated, lists, first }: first is the first book it made, in the export's order, else the first it found again" }, find_film: { args: ["query?", "film?"], meaning: "looks a film or a series up on TMDB: a query (its name, its year too if known) makes a Want to watch film from the best match, or fills the film already holding that TMDB id; film names a film row to fill, by its tmdb_id, else its title and year. Only empty columns are filled (title, year, poster, backdrop, synopsis, genres, director, cast, certificate, language, country, minutes, tmdb_id, imdb_id, tvdb_id), each named in filled_from; a series' seasons and episodes are made or filled the same way, matched by number. Answers { film, made, filled, seasons, episodes, more? }; more says pictures were left for the next look. Nothing found is refused, and so is TMDB asked too often: try it again later; on a server holding no TMDB key, TMDB is not connected and it is refused" }, reshape_films: { args: [], meaning: "the owner's one-time move of the film tables onto Cotton Cinemas, keeping every row: each film's status watchlist becomes want_to_watch, its notes are copied into an empty review (notes stays stored, retired) and an empty added_on is the day it was made; the kit's film, film_season, film_episode and watch are laid whole, the Films tool goes and the kit's Cinemas tool is laid. Answers { mapped: { status, review, added_on }, laid, removed }; run again it does nothing and answers zeros" }, film_converted: { args: ["table", "id", "file", "poster?"], meaning: "the Mac importer's word that a film or an episode (table film or film_episode) waiting for it now plays: file, its stream in the row's own folder (/films//master.m3u8 or whole.), becomes the row's file, needs_mac false and source_file cleared, and the upload it converted goes from the media; poster (a file in the same folder) fills an empty poster, or an episode's still. Answers { table, id, file, dropped }" }, fetch_add: { args: ["source", "wants?", "title?"], meaning: "the owner queues a link for the Mac to fetch as an owned file (Downloads): source is a magnet, an http(s) link to a .torrent or a file, or a page any site yt-dlp reads; wants is video (a page's default), audio (the sound alone) or files (a torrent's or a file's default); title is what the link is called where it came from (a saved page's title). The row is queued with its kind and that title, else one read off the link, until the Mac's. Answers { fetch }" }, fetch_cancel: { args: ["fetch"], meaning: "the owner stops a download still queued, fetching or landing: its state becomes cancelled and the Mac stops it when it next reports. Answers { fetch, state }" }, fetch_retry: { args: ["fetch"], meaning: "the owner queues a failed or cancelled download again, its error and progress cleared. Answers { fetch, state }" }, fetch_again: { args: ["fetch"], meaning: "the owner queues a done download once more (so the films it landed come back keeping their originals): its link untouched, its last run's figures cleared, again_on stamped. A second fetch that fails or is cancelled leaves the row done with what it landed still linked, again_outcome and again_error saying why. Refused for a row that is not done. Answers { fetch, state }" }, fetch_claim: { args: ["id", "machine"], meaning: "the Mac fetcher (pnpm fetch:run) takes a queued download: state fetching, machine and started_on stamped. Refused when the row is not queued. Answers { fetch, state }" }, fetch_stage: { args: ["id", "stage?", "done?", "of?", "line?"], meaning: "the Mac fetcher says where a download it holds has got to while it lands, and a landed film while its smaller copies are made: stage one of the fetch table's stage choices (none clears it), done and of its two figures, line the words the card shows. At most one call every 15 seconds. Answers { fetch, stage }" }, fetch_progress: { args: ["id", "progress?", "bytes?", "of_bytes?", "speed_bps?", "eta_seconds?", "files?", "title?", "picture?", "source_kind?", "landing?"], meaning: "the Mac fetcher says how far a download it holds is: progress a share 0 to 1, sizes in bytes, the title and picture (a photo sent first) from the fetcher's metadata, landing true once the files are going in. Refused fetch_cancelled once the owner cancelled it: the Mac stops. Answers { fetch, state }" }, fetch_landed: { args: ["id", "landed"], meaning: "the Mac fetcher's word that every file of a download is in: landed is [{ table, id, name?, bytes? }] of the records it made (film, film_episode, book, photo, document), each kept as a fetch_file row linking the record in its own tool; the row is done. Answers { fetch, state, landed }" }, meeting_claim: { args: ["id", "by"], meaning: "a transcriber (by: mac, phone or service) takes a Cotton Meetings recording waiting for it: status transcribing and one more attempt. Refused not_waiting when another holds it, and not_yours when the recording waits for another transcriber. Answers { meeting, status, attempts }" }, meeting_failed: { args: ["id", "why"], meaning: "the transcriber holding a recording gives it up: status failed, status_why the reason (no_audio, engine_failed, too_long, not_enabled). The audio stays and it can be asked again. Answers { meeting, status }" }, fetch_failed: { args: ["id", "error"], meaning: "the Mac fetcher's word that a download failed, error the fetcher's reason in one sentence (a site behind DRM says so); a cancelled row stays cancelled. Answers { fetch, state }" }, } as const satisfies Record; export type ActName = keyof typeof ACTS; export function isAct(name: string): name is ActName { return Object.hasOwn(ACTS, name); } /** One line per act, as run_act's description lists them: `- book { slot, quantity?, member? }: books …`. */ export function actLines(offered: (act: string) => boolean = () => true): string { return Object.entries(ACTS) .filter(([name]) => offered(name)) .map(([name, act]) => `- ${name} ${act.args.length ? `{ ${act.args.join(", ")} }` : "{}"}: ${act.meaning}`) .join("\n"); }