# Contacts: the core's methods and answers (both shells read these) Owner: CORE. Status: **shapes fixed, methods landing on main one by one**; each line says `landed` once the core answers it. Until then a shell stubs the shape exactly as written here. Design: PEOPLE-DESIGN.md section f. Every method is called like any other app method (`call(method, request) -> answer`), works before sign-in, and reads and writes only sealed personal tables (`person`, `person_handle`, `person_source`, `shared_handle`, `person_fact`, `record_group`/`group_member`). Conventions, as in Comms and Secrets: - `words` is what a row says, `detail` its second line, `initials` the circle (`#` for a number with no name). - Every tappable thing carries `call: {method, request}`: the shell calls it as given and redraws with the answer. - An `acts` entry is `{id, words, red?, call}`; `red` marks a destroying act; `confirm` (when present) is the sentence to ask before calling. - All words come from the core (the app's lines); the shell writes none. - Ids are opaque strings. Counts are numbers. Times are already said in words (`"Talked yesterday"`). ## 1. Home: `contacts.home {kind?, query?}` (status: **landed**, `crates/cotton-ffi/src/phone/contacts_app.rs`) `kind`: `all` (default) | `person` | `organisation` | `assistant`. `query`: the search text (name, number, email). ```json { "title": "Contacts", "search": { "placeholder": "Search", "query": "" }, "kinds": [ { "id": "all", "words": "All", "on": true, "call": {"method": "contacts.home", "request": {"kind": "all"}} }, { "id": "person", "words": "People", "on": false, "call": {...} }, { "id": "organisation", "words": "Organisations", "on": false, "call": {...} }, { "id": "assistant", "words": "Assistants", "on": false, "call": {...} } ], "same": { "words": "47 look like the same person twice", "act": "Review", "call": {"method": "contacts.same.list", "request": {}} }, "sections": [ { "id": "close", "title": "Close", "count": 12, "rows": [ { "id": "", "words": "Asha Menon", "detail": "Talked yesterday · Family", "initials": "AM", "picture": "", "kind": "person", "call": {"method": "contacts.person", "request": {"id": ""}} } ] }, { "id": "often", "title": "Often", "count": 38, "rows": [...] }, { "id": "now", "title": "Now and then", "count": 214, "rows": [...] }, { "id": "rest", "title": "Everyone else", "count": 1236, "rows": [...] } ], "add": { "words": "Add", "call": {"method": "contacts.add.form", "request": {}} }, "import": { "words": "Read your phone's contacts", "hint": "Cotton reads them on this phone; they stay sealed." }, "empty": null } ``` - `same` is absent when there is nothing to review. `import` is absent once this phone's contacts were read. - With a `query`, `sections` is one section `{"id": "found", "title": "Found", ...}`. - With no contacts at all: `sections` is `[]` and `empty` is `{"title": "No contacts yet", "message": "..."}`. - Tiers (written rules, on the phone, from `person_fact`): Close = he and they wrote or called each other in at least 3 of the last 8 weeks, or pinned; Often = 10 or more exchanges in 90 days; Now and then = any exchange he took part in this year; Everyone else = the rest. Inside a tier: most recent first; Everyone else: by name. ## 2. The person page: `contacts.person {id}` (status: **landed**, `crates/cotton-ffi/src/phone/contacts_app.rs`) ```json { "id": "", "kind": "person", "title": "Asha Menon", "initials": "AM", "picture": null, "subtitle": "Close · Family", "archived": false, "mergedInto": null, "between": [ { "app": "comms", "words": "Comms", "detail": "312 messages · yesterday", "open": {"app": "comms", "person": ""} }, { "app": "post", "words": "Post", "detail": "14 mails · last week", "open": {...} }, { "app": "days", "words": "Days", "detail": "5 events together", "open": {...} }, { "app": "albums","words": "Albums","detail": "In 312 of your photos", "open": {...} }, { "app": "health","words": "Health","detail": "Records in Health", "open": {...} } ], "reach": [ { "id": "", "kind": "phone", "words": "+91 98765 43210", "detail": "Mobile", "shared": null, "acts": [ {"id": "remove", "words": "Remove", "red": true, "call": {...}} ] }, { "id": "", "kind": "phone", "words": "+91 22 2345 6789", "detail": "Also Ravi Shah's", "shared": ["Ravi Shah"], "acts": [...] } ], "groups": [ { "id": "", "words": "Family", "call": {"method": "contacts.group", "request": {"id": ""}} } ], "organisation": { "id": "", "words": "Acme", "call": {"method": "contacts.person", "request": {"id": "..."}} }, "sources": [ { "words": "From your contacts", "detail": "This iPhone" }, { "words": "From WhatsApp", "detail": "Asha M" } ], "same": [ { "words": "Asha M, from WhatsApp", "detail": "the same number", "call": {"method": "contacts.same.pair", "request": {"a": "...", "b": "..."}} } ], "pinned": false, "acts": [ { "id": "edit", "words": "Edit", "call": {"method": "contacts.edit.form", "request": {"id": "..."}} }, { "id": "pin", "words": "Keep in Close", "call": {"method": "contacts.pin", "request": {"id": "...", "on": true}} }, { "id": "unmerge", "words": "Unmerge", "call": {"method": "contacts.unmerge", "request": {"id": "..."}} }, { "id": "archive", "words": "Archive", "red": true, "confirm": "...", "call": {...} } ] } ``` - `between` lists only apps with a fact for this person; each row's `open` is a deep link the shell hands to that app (or hides when the app is not on this phone). Health never shows more than the one line. - `unmerge` is present only for 30 days after a merge into this person. - A merged-away id answers `mergedInto` set: the shell opens that id instead. ## 3. Add and edit (status: **landed**: `contacts.add.form`, `contacts.edit.form`, `contacts.add`, `contacts.edit`; a handle comes off with `contacts.edit {id, removeHandle}`) - `contacts.add.form {}` and `contacts.edit.form {id}` answer the form: ```json { "title": "New contact", "kinds": [ {"id": "person", "words": "Person", "on": true}, {"id": "organisation", "words": "Organisation", "on": false} ], "fields": [ {"id": "name", "words": "Name", "value": ""}, {"id": "phones", "words": "Phone", "values": [], "add": "Add a phone"}, {"id": "emails", "words": "Email", "values": [], "add": "Add an email"}, {"id": "notes", "words": "Notes", "value": ""} ], "save": { "words": "Save", "call": {"method": "contacts.add", "request": {}} } } ``` - `contacts.add {kind, name, phones: [], emails: [], notes?}` and `contacts.edit {id, kind?, name?, phones?, emails?, notes?}` answer `{ "id": "", "said": "Saved" }` or `{ "error": "" }`. A number another contact already holds is kept as shared (both keep it), never refused. Assistants are not made here. ## 4. Same person? (status: **landed**, `crates/cotton-ffi/src/phone/contacts_same.rs`) - `contacts.same.list {}`: ```json { "title": "Same person?", "count": 47, "pairs": [ { "a": {"id": "...", "words": "Asha Menon", "detail": "From your contacts", "initials": "AM", "reach": ["+91 98765 43210"]}, "b": {"id": "...", "words": "Asha M", "detail": "From WhatsApp", "initials": "AM", "reach": ["+91 98765 43210"]}, "why": "the same number", "acts": [ {"id": "yes", "words": "Yes, one person", "call": {"method": "contacts.same", "request": {"a": "...", "b": "...", "answer": "yes"}}}, {"id": "no", "words": "Not the same", "call": {... "answer": "no"}}, {"id": "later", "words": "Later", "call": {... "answer": "later"}} ] } ], "empty": null } ``` - Ranked: same number or email first, then same source, then a near name plus one shared handle, then names alone. - `contacts.same {a, b, answer: yes|no|later}`: `yes` merges (b into a) and answers `{ "id": "", "said": "Joined. Unmerge on the page for 30 days." }`; `no` never asks this pair again; `later` hides it until the next list. - `contacts.same.pair {a, b}` answers one pair in the same shape as a `pairs` entry. ## 5. Merge and unmerge (status: **landed**: Unmerge puts back every row the merge moved; what the union filled on the survivor stays) - `contacts.merge {keep, drop}` (also what `contacts.same` yes calls): `{ "id": "", "said": "..." }`. - `contacts.unmerge {id}`: puts back every record merged into `id` in the last 30 days with its own handles and sources: `{ "ids": ["", ""], "said": "..." }`. ### 5.1 The server's half (landed, 28 Nov 2026: `apps/business/src/person_merge.ts`) The core's `contacts.merge` first writes the sealed part itself: it fills `keep` from `drop` (`union_patch`, with its refusals). Then it sends one act over `/v1/act`, owner devices only: - `merge_people {keep, drop}`: - Every clear link to `drop`, on every table, names `keep`, in one write. A single link is replaced. A list (`people`, `member_people`) swaps `drop` for `keep` and never names it twice. - Suggestions are not moved. - `drop` gets `archived_at` and `merged_into` = keep. `merged_into` is a new clear link column on `person`. - It answers `{id, drop, moved: {"table.column": n}, left: ["table.column"]}`. `left` lists the links inside a seal (`film.recommended_by`, Health's `person`, the lab tables): the phone that holds that app repoints those itself. - It refuses `same_person`, `no_such_person`, and `merged_away` (either side already merged away). - `unmerge_people {id}`: - Undoes every merge into `id` from the last 30 days, newest first. - Each row the merge moved that still points at `id` points back. A row made or relinked since is left as it is. - The merged person leaves the archive. - It answers `{ids: [id, ...restored]}`, or `404 nothing_to_unmerge`. The record of what moved is kept on the server only (`person_merge`). The MCP `merge_people` tool still bins the duplicate. Moving it onto this act is the next step. ## 6. Groups: `contacts.groups {}` (status: **landed**, `crates/cotton-ffi/src/phone/contacts_groups.rs`) ```json { "title": "Groups", "sections": [ { "id": "app", "title": "Made by Contacts", "rows": [ {"id": "", "words": "Family", "detail": "6 · from your \"Family\" chat on WhatsApp", "call": {"method": "contacts.group", "request": {"id": "..."}}} ] }, { "id": "you", "title": "Made by you", "rows": [...] } ], "foot": "Each group says why it was made. Change or delete any of them.", "add": { "words": "New group", "call": {"method": "contacts.group.make", "request": {}} } } ``` - `contacts.group {id}`: `{ "id", "title", "detail": "", "madeBy": "app"|"you", "rows": [person rows as on the home], "acts": [rename, delete] }`. - `contacts.group.make {name, people: []}`, `contacts.group.rename {id, name}`, `contacts.group.delete {id}`, `contacts.group.add {id, people: []}`, `contacts.group.remove {id, person}`: each answers the group as above. ## 7. Reading the phone's address book: `contacts.read {cards: [...], device?}` (status: **landed**, `crates/cotton-ffi/src/phone/contacts_app.rs`) The shell asks READ_CONTACTS / CNContactStore in context (never at launch), reads every card, and sends them all in one call. A card is exactly what `sync_device_contacts` takes today: `{deviceContactId, fullName, phones?: [], emails?: [], org?, roleTitle?, city?, birthday?: {month, day, year?}}`. Answers: ```json { "read": 1500, "made": 1320, "attached": 160, "same": 12, "said": "Read 1,500 contacts. 12 may be the same person twice." } ``` Matching (the core, PEOPLE BUILD 1b): the same card (source) first, then a card whose every number and email names one living person with the same name; anything else is a new contact, with a Same person? pair where evidence exists. An import never merges people by itself. Calling it again changes nothing that is already there. ## 8. Tabs Contacts · Groups · Circle · You. The Circle tab draws `circle.list` (section 9). You is the shell's usual You page. ## 9. The Circle (PEOPLE-DESIGN b.4, c, d.1) (status: landing, see 9.0) ### 9.0 Status - **landed** (`crates/cotton-ffi/src/phone/circle.rs`): `circle.list`, `circle.add.page`, `circle.ask`, `circle.ask.stop`, `circle.answer`, `circle.remove.plan`, `circle.remove`, `circle.block`, `circle.unblock`, `circle.check`, `circle.check.confirm`, `circle.check.scan`, `circle.key.accept`, `circle.invite`, `circle.invite.stop`, `circle.invite.open`. - **For the core (albums-design):** `contacts.person` lays the Circle block (9.4) by calling `crate::phone::circle::person_part(&client, person_id) -> Option` and putting it at `circle` (absent on None). - **For the shells:** the invitation link is `https:///c/#`. The app registers it as an app link (iPhone associated domain path `/c/*`, Android intent filter on the same path) and, when opened, calls `circle.invite.open {"link": ""}`; it answers `{said, list}` or `{error}`. Signed out, it answers `signedOut` like every `circle.*`: sign in first, then call it again with the same link. - **landed (CIRCLE 2):** a person is bound to their account when they add back; "left Cotton" (told at their erase) and "This number belongs to someone else on Cotton now" (the number leads to another account) show under `gone` with states `left` and `changed`, and nothing sealed to a person goes to a number that changed hands. - **landed (CIRCLE 3):** Remove and Block end what is shared both ways first, through each app's own methods, and the plan (`ends`) names each: secrets they hold taken back (change the ones they opened), secrets they shared gone, his shared albums they leave (a new key), their albums he leaves. A share that will not end stops the act with words and nothing changed in the Circle. - **Not yet:** the number and name sealed on the server (b.4's last piece); Days invitations and Send offers in Remove. The Circle is the people he and they both accepted on Cotton. Its state lives on the `person`, sealed (`circle`, `circle_since`, the pinned keys, `checked_at`); the server keeps only the routing half (b.4). Every app's Privacy › Your Circle and Contacts' Circle tab draw the same answers. Signed out, every `circle.*` answers `{ "signedOut": {"title": "...", "message": "..."} }` and nothing else (the shell offers its own sign-in). Only a contact of kind `person` can be in the Circle: on any other kind the acts are absent and the method answers `{ "error": "..." }`. **States** (`state` on a row and on the person page): `asking` (they asked him) · `asked` (he asked, waiting for them) · `in` · `blocked` · `left` (they deleted their account) · `changed` (the number now leads to another account). Inside `in`, `check`: `seen` (keys pinned at first sight) · `checked` (safety number compared) · `key_changed`. ### 9.1 `circle.list {}` ```json { "title": "Your Circle", "intro": "People you both accepted on Cotton. Being here shares nothing by itself.", "sections": [ { "id": "asking", "title": "Asks you", "rows": [ { "id": "", "person": "", "words": "Ravi Shah", "initials": "RV", "picture": null, "detail": "In your contacts · asked today", "state": "asking", "acts": [ {"id": "accept", "words": "Accept", "primary": true, "call": {"method": "circle.answer", "request": {"ask": "", "answer": "accept"}}}, {"id": "later", "words": "Not now", "call": {"method": "circle.answer", "request": {"ask": "", "answer": "later"}}}, {"id": "block", "words": "Block", "red": true, "confirm": "...", "call": {"method": "circle.answer", "request": {"ask": "", "answer": "block"}}} ], "call": {"method": "circle.ask.page", "request": {"ask": ""}} } ] }, { "id": "in", "title": "In your Circle", "count": 3, "rows": [ { "id": "", "person": "", "words": "Asha Menon", "initials": "AM", "detail": "Checked · shares 2 albums with you", "state": "in", "check": "checked", "call": {"method": "contacts.person", "request": {"id": ""}} } ] }, { "id": "waiting", "title": "Waiting for them", "count": 1, "rows": [ { "...": "detail: You asked on 20 Nov; acts: Stop asking" } ] }, { "id": "gone", "title": "No longer on Cotton", "rows": [ { "...": "state left or changed; detail says which" } ] }, { "id": "blocked", "title": "Blocked", "rows": [ { "...": "acts: Unblock" } ] } ], "add": { "words": "Add someone", "call": {"method": "circle.add.page", "request": {}} }, "empty": null } ``` - A section with no rows is left out. Someone asking who is not in his contacts: `person` null, `words` is the name they gave, `detail` "Calls themselves Kabir · not in your contacts". Accepting makes a contact for them. - Names come from his contacts (`who(handle)`), never the number alone; with no contact, the name they gave. ### 9.2 Add or invite: `circle.add.page {query?}` ```json { "title": "Add someone", "search": {"placeholder": "Search your contacts", "query": ""}, "rows": [ { "person": "", "words": "Dev Nair", "initials": "DN", "detail": "+91 99887 66554", "acts": [ {"id": "ask", "words": "Ask", "call": {"method": "circle.ask", "request": {"person": "", "handle": ""}}}, {"id": "invite", "words": "Invite", "call": {"method": "circle.invite", "request": {"person": ""}}} ] } ], "number": { "words": "A number that isn't in your contacts", "placeholder": "+91 …", "call": {"method": "circle.ask", "request": {"number": ""}} }, "foot": "Asking sends your name to that number only. Cotton never looks through your contacts to find who is on it." } ``` - Each contact row offers Ask and Invite both: the core never says who is on Cotton (C1). A contact with several numbers answers one row per number. Contacts already in the Circle or asked are left out. - The shell fills `number`'s request with what he typed (`{"number": "+44…"}`). ### 9.3 The acts (each answers `{ "said": "", "list": }` or `{ "error": "" }`) - `circle.ask {person, handle}` or `circle.ask {number}`: sends his own chosen name to that one number. The answer is the same whether or not the number is on Cotton. A typed number no contact holds makes a contact for it. - `circle.invite {person}` → `{ "title": "Invite Meera", "message": "Send her this link from your own messages. Cotton sends nothing.", "link": "https://cottondb.com/c/#", "share": "", "ends": "Ends in 30 days", "stop": {"words": "Stop", "call": {"method": "circle.invite.stop", "request": {"invite": ""}}} }`. The shell hands `share` to the system share sheet; nothing is sent by Cotton. - `circle.invite.stop {invite}`, `circle.ask.stop {person}` (Stop asking). - `circle.answer {ask, answer: accept|later|block}`. - `circle.ask.page {ask}`: one ask with the name they gave, his name for them if he has one, and the same three acts. - `circle.remove.plan {person}` → ```json { "title": "Remove Arjun from your Circle?", "ends": [ {"app": "secrets", "words": "Secrets", "detail": "3 he holds are taken back. He opened 2, so change them."}, {"app": "albums", "words": "Albums", "detail": "He leaves \"Mum's 70th\". His photos there stay 30 days."} ], "stays": [ "What he already saw or saved.", "Your chat, as history." ], "acts": [ {"id": "remove", "words": "Remove Arjun", "red": true, "call": {"method": "circle.remove", "request": {"person": ""}}}, {"id": "block", "words": "Block instead", "red": true, "call": {"method": "circle.block", "request": {"person": ""}}} ] } ``` - `circle.remove {person}`, `circle.block {person}` (a block covers every handle of the person), `circle.unblock {person}`. - `circle.check {person}` → `{ "title": "Safety number", "words": "34127 90815 22764 51093", "qr": "", "message": "Compare this with the number on Asha's phone.", "state": "seen"|"checked"|"key_changed", "acts": [ {"id": "confirm", "words": "They match", "call": {"method": "circle.check.confirm", "request": {"person": ""}}} ] }`. With `key_changed` the answer also carries `"was": "", "now": ""` and an act `circle.key.accept {person}`. Until accepted, nothing new is shared with that person. - `circle.check.scan {person, scanned}`: the QR text read by the camera; answers as `circle.check` (checked on a match). ### 9.4 On the person page (`contacts.person`), added by the Circle ```json "circle": { "state": "in", "check": "checked", "words": "In your Circle · Checked", "safety": {"words": "Safety number", "detail": "34127 90815 22764 51093 · Checked", "call": {"method": "circle.check", "request": {"id": ""}}}, "acts": [ {"id": "remove", "words": "Remove from your Circle", "red": true, "call": {"method": "circle.remove.plan", "request": {"person": ""}}}, {"id": "block", "words": "Block", "red": true, "call": {"method": "circle.remove.plan", "request": {"person": "", "block": true}}} ] }, "shared": { "mine": [ {"app": "albums", "words": "Albums", "detail": "Mum's 70th · can add", "open": {...}} ], "theirs": [ {"app": "albums", "words": "Albums", "detail": "Diwali 2026", "open": {...}} ] } ``` - `circle` is absent for a contact that is not a person; for a person not in the Circle it carries one act, Ask (`circle.ask`) or Invite (with no number). `shared` is `share.by_person` (10.6), absent when empty. ## 10. The one Share sheet (PEOPLE-DESIGN d.1, d.2 mock-ups 4 and 5) (status: landing, see 10.0) ### 10.0 Status - **landed** (`crates/cotton-ffi/src/phone/share_sheet.rs`): `share.sheet`, `share.plan`, `share.do`, `share.with`, `share.role`, `share.stop`, `share.by_person`, for two apps: - `app: "albums"`: `thing` `{kind: "album", space, album}` (a shared album) or `{kind: "album", name}` (a new one: `share.do` founds it with the people picked and answers its `thing` with `space` and `album`, so the shell goes on to add photos with `albums.shared.add`). One role, `add` ("See and add"): the album's roster has no view-only member yet. Stop is the owner's only (a new key, `albums.shared.rekey`). - `app: "secrets"`: `thing` `{kind: "secret", id}`. Roles `see` and `copy`; `until` as 10.1. Only someone whose safety number was compared can be picked; anyone else's row carries `call` to `circle.check`. `share.do` hands every other field of its request to `secrets.share` as it came (the vault's own proof). - `app: "days"` (CONTACT KINDS 3): `thing` `{kind: "event", id}`. Days shares **one event**, not a calendar (Days has no whole-calendar sharing). One role, `invite` ("Invited"); `share.role` answers an error. `share.do` adds the picked Circle members to the event's guest list (`days.change`, everyone already on it kept) and sends the sealed invitations at once (`days.invitations`); they answer in their Days. `share.with` rows say "Coming", "Not coming", "Maybe", "Invited, no answer yet" or "Invitation on its way"; a Cotton guest's row has a stop act ("Take off the list"); a guest Days reaches by email is shown without one (changed in Days itself). `share.stop` takes the person off the list; the next pass tells them it is off. Pass `timezone` (the phone's zone) in `share.do` and `share.stop`; UTC when absent. `has` on the sheet marks who is already invited. - `app: "cinemas"`: `thing` `{kind: "list", id}`, one of his film lists (a `film` group). The first `share.do` founds the shared list `cinemas-` (`shared.found`, now taking `items: [{item, body}]`) with the people picked and every title on it, `{title, year, kind}` each, sealed, never the file. A later `share.do` adds the new people (`shared.add`). After that the list follows on its own: a `groups.update` on a shared film list puts the titles added (`shared.put`) and takes those removed (`shared.take`); offline, the next change or share sends what is owed. One role, `see` ("See the list"). Stop and adding are the founder's only (`shared.remove` gives a new key). Members read it with `shared.read {owner, id}`; no Cinemas screen shows a received list yet. - `app: "words"` and `app: "sites"` answer `{error: "Words can't share yet. It's coming."}` (and Sites the same) until spaces exist (coordinator, 28 Nov 2026). - `people` in a request names each person by contact id or number. `share.do` answers `{said, thing, with}`. - **For the core (albums-design):** `contacts.person`'s `shared` is `share.by_person {person}` (`crate::phone::share_sheet::over(&handle, "share.by_person", &json!({"person": id}))`), absent when both lists are empty. - **Not yet:** `suggested` (answers `[]` until contact groups exist), Words and Sites adapters (waiting on spaces), and the adapters declared in each app's kit (they live in the core for now). Every app calls the same methods with its own `app` and `thing`; the app's adapter (declared in its kit) says the thing kinds, the roles, the way underneath (`space` or `box`) and what never travels. A `thing` is `{ "kind": "", "id": "" }`. ### 10.1 `share.sheet {app, thing}` ```json { "title": "Share \"Mum's 70th\"", "suggested": [ {"id": "", "words": "Family · 5", "people": ["", "..."], "why": "who is in these photos"} ], "people": [ {"person": "", "words": "Asha Menon", "initials": "AM", "on": false, "has": false, "detail": null, "can": true}, {"person": "", "words": "Lata Kumar", "initials": "LK", "on": false, "has": false, "detail": "Waiting for her to accept you", "can": false}, {"person": "", "words": "Priya", "initials": "PR", "on": false, "has": false, "detail": "Not checked: you check her safety number first", "can": false, "call": {"method": "circle.check", "request": {"person": ""}}} ], "roles": [ {"id": "see", "words": "See", "on": true}, {"id": "add", "words": "See and add", "on": false} ], "until": null, "link": { "words": "Make a link for them", "detail": "view and save, 30 days" }, "foot": "They see the photos in 2,048 px, without where they were taken. Faces and names stay on your phone.", "go": { "words": "Share with 2", "call": {"method": "share.do", "request": {"app": "albums", "thing": {...}, "people": [], "role": "see"}} } } ``` - `people` is the Circle (state `in`) first, then those waiting (`can` false, `detail` says why). `has` true for someone who has it already. Nothing is ever `on` until he taps: the shell keeps the picked set, fills `go`'s request (`people`, `role`, `until`) and asks `share.plan` for the button's words and lines as the pick changes. - `until` is present only for a box app (Secrets): `[ {"id": "day", "words": "A day"}, {"id": "week", ...}, {"id": "month", ...}, {"id": "never", "words": "I take it back"}, {"id": "date", "words": "Pick a date"} ]`. - `link` is absent where the app allows none. `suggested` comes only from what the thing itself says. - Assistants are never in `people`. ### 10.2 `share.plan {app, thing, people, role, until?}` `{ "lines": ["Asha and Ravi get a notice.", "..."], "go": {"words": "Share with 2", "call": {...share.do...}}, "error": null }` ### 10.3 `share.do {app, thing, people, role, until?}` → `{ "said": "Shared with Asha and Ravi.", "thing": {...}, "with": }` or `{ "error" }` ### 10.4 `share.with {app, thing}` ```json { "title": "Mum's 70th · Shared with 4", "rows": [ {"person": null, "words": "You", "initials": "YO", "detail": "Made it"}, {"person": "", "words": "Asha Menon", "initials": "AM", "detail": "Can add · checked", "acts": [ {"id": "role", "words": "Can see only", "call": {"method": "share.role", "request": {"app": "...", "thing": {...}, "person": "", "role": "see"}}}, {"id": "stop", "words": "Stop sharing", "red": true, "call": {"method": "share.stop", "request": {"app": "...", "thing": {...}, "person": ""}}} ] }, {"person": null, "words": "Anyone with the link", "detail": "Ends 26 Dec", "acts": [ {"id": "stop", "words": "Stop", "red": true, "call": {...}} ]} ], "more": { "words": "Share with more", "call": {"method": "share.sheet", "request": {"app": "...", "thing": {...}}} } } ``` ### 10.5 `share.role {app, thing, person, role}`, `share.stop {app, thing, person}` → as `share.with`, with `said`. ### 10.6 `share.by_person {person}` → `{ "mine": [rows], "theirs": [rows] }`, each row `{app, words, detail, open}` across apps. Covers (CIRCLE GAPS 3, 28 Nov): **Albums** (spaces), **Secrets** (boxes), **Days** (his events with them on the guest list by Cotton → mine, `open: {app: "days", id}`; invitations they sent → theirs), **Cinemas** (his film lists they see → mine, `open: {app: "cinemas", list}`; lists they shared with him → theirs, `open: {app: "cinemas", owner, id}`, which the shell opens with `cinemas.shared`). **Words** and **Sites** share nothing yet and show nothing here. ### 10.7 A Cinemas list shared with him (CIRCLE GAPS 2, 28 Nov; `crates/cotton-ffi/src/phone/cinemas_shared.rs`) - `cinemas.home` gains `received`: `null`, or `{ title: "Shared with you", rows: [{ owner, id, words, detail, initials, call }] }`, one row a list someone else made (`words` its name, else "Mira's list"; `detail` "From Mira Example · 12 titles"; `call` `cinemas.shared {owner, id}`). Drawn as its own line on home. Home never waits on the network: the rows are as last read, refreshed behind the answer at most once a minute. - `cinemas.shared {owner, id}` → `{ owner, id, title, from: {number, name}, detail, items: [{id, title, year, kind}], unopened, leave: {words, red, confirm, call} }`. The titles are what was shared, never a file. - `cinemas.shared.leave {owner, id}` → `{ said: "You left the list" }`: the row leaves his home at once. A member cannot re-key a list for those who stay (he would know the new key), so he posts a sealed ask (`leave:`) and the founder's phone takes him off with a new key the next time it reads the list (Share's "shared with", or any change to the list). ## 12. Contacts in and out of files (status: landed) - **Import:** `contacts.import {text, format?: "vcf" | "csv"}`. The shell reads the file the person picked (a share sheet, a file picker) as text and sends it whole. `format` is read from the text when absent. - It reads vCard 2.1, 3.0 and 4.0, and a Google Contacts CSV (the current and the older columns). - Answers: ```json { "read": 120, "made": 112, "already": 8, "photos": 40, "notes": 9, "groups": 3, "skipped": 1, "said": "Added 112 contacts; 8 were already here." } ``` - Every card goes through the same door as the phone's address book: `sync_device_contacts`, so the same handle rules and Same person? pairs apply. An import never merges two people by itself. - Each card's source is `file:`, else `file:`, so the same file again makes nothing. - An embedded photo becomes the new contact's picture. A photo given only as a link is never fetched. - A card's note (vCard `NOTE`, Google `Notes`) becomes a note about the new contact. - Each group in the file (`CATEGORIES`, an iCloud group card, a Google label) becomes a People group made by him, or is added to the group of the same name. Google's system labels (`* myContacts`) are not groups. - `skipped` counts blocks that held no contact, and group cards. - **Export:** `contacts.export {ids?: [person id], version?: "4.0" | "3.0"}`. With no `ids`, every contact not in the bin is exported. Answers: ```json { "filename": "Contacts.vcf", "mime": "text/vcard", "count": 1436, "text": "BEGIN:VCARD\r\n…" } ``` - Each card carries the name, every number and email, organisation, title, city, birthday, the notes about the person (as one `NOTE`), groups (`CATEGORIES`), the picture when its bytes are on this phone, and `UID` (the person id). An organisation is `KIND:org` in 4.0 and `X-ABShowAs:COMPANY` in 3.0. - The shell writes `text` to a file named `filename` and offers the share sheet. Nothing is uploaded. - **Where the shells put them:** on the You tab, two rows: "Import contacts from a file" and "Export all contacts". On the person page, "Share contact" calls `contacts.export {ids: [id]}`. These are the core's suggestion; the words will come from the core once the app's lines are in. ## 13. Labels on numbers and addresses, and organisations from files (status: landed) - **Labels.** A number or an address keeps its label: Mobile, Work, Home, Main, Fax, Pager, Other, or his own word (at most 40 characters). It is kept sealed in the kit table `handle_label`, one row per handle. - `contacts.person`: each `reach` row gains `"label": "Mobile" | null`. `detail` shows the label in place of the kind's word ("Phone", "Email"). A number shared with another contact still says "Also …'s". - `contacts.add` and `contacts.edit`: each entry of `phones` and `emails` is a string (as before) or `{"value": "+91 …", "label": "Work"}`. A known word is spelled the usual way (`cell` is Mobile). In `edit`, the label of a value already there changes when it is sent with a new one. - `contacts.edit.form`: the `phones` and `emails` fields gain `"labels": [...]`, beside `values` in the same order, with `null` where there is none. - `contacts.import` reads vCard TYPE and Apple's own labels, and Google's `Phone n - Label` and `E-mail n - Label`. `contacts.export` writes them as TYPE. - **Organisations.** A card that is a company comes in as kind `organisation` (in `person_state`), and goes back out as one. That means 4.0 `KIND:org`, Apple's `X-ABShowAs:COMPANY`, a card with an ORG and no name, or a Google row with an organisation and no name. ## 11. Notes from the Android shell (27 Nov) (for the core to settle) The Android app draws every shape above and calls the methods as written. Until the core answers a method, the shell's stand-in (`apps/android/app/src/contacts/kotlin/com/cottondb/contacts/Local.kt`) answers it in the same shape from `list_people`, `create_person`, `update_person`, `archive_person`, `merge_people`, `list_person_suggestions`, `decide_person_suggestion`, the person groups and `sync_device_contacts`. When `call(method)` refuses with `unknown_method`, the stand-in answers. Once the core answers, the stand-in for that method is never reached. A unit test fails if a method named here has no stand-in. What the shell needs the shapes to say, where the text above leaves a `{...}`: - **Archive, unarchive and pin** (settled with the core): `contacts.archive {id}`, `contacts.unarchive {id}` and `contacts.pin {id, on}` answer `{id, said}`. Archive, unarchive and pin are **landed** (`contacts_groups.rs`; pin is `person_state.pinned` through `contacts_app::put_state`). After archive the shell goes back to the list; after the others it redraws. - **Remove a handle** (settled with the core): a reach row's remove act calls `contacts.edit {id, removeHandle: ""}`. - **Form fields**: the shell sends each field back under its `id`: a `value` field as a string and a `values` field as a list, plus `kind`. The core reads `name`, `phones`, `emails` and `kind`. It ignores the stand-in's `org` and `role` for now. - **`contacts.group.make {name, people}`**: the shell asks for the name, then lets the person pick people, so `people` is never empty, and the core refuses an empty one. Make, rename, add and remove answer the group, with the tool's own sentence as `said`. Delete answers `{id, said}`. A group whose `group_origin` says `app` stands under Made by Contacts, with `count · reason` as its detail; deleting it marks its origin dismissed. `contacts.group.add {id}` with no `people` opens the same picker. - **A `between` row's `open`**: the shell opens `cotton://person/`, and does nothing when that app is not on the phone. Tell us if each app's link takes another form. - **Kinds on the home**: the stand-in has no kind, so everyone is a person. Organisations and Assistants show nothing until the core answers; it keeps kinds in the sealed kit table `person_state`. - **Seen on the emulator** (invented cards): the card "Asha M" with the same number as "Asha Menon" was kept as two people, which is right. But the number landed only on Asha M, and `list_person_suggestions` made no Same person? pair for them. The core says this is main before PEOPLE BUILD 1b. With 1b, both keep the number (`shared_handle`) and `contacts.same.list` makes the pair "the same number".