Cotton code
153 lines · 9.2 KB · MarkdownRaw
# Cotton Meetings: the core's methodsEvery rule of Meetings lives in the Rust core once. Both phones call thesemethods through cotton-ffi (`cotton_call(handle, method, json)`), as everyother `<app>.*` method (`crates/cotton-ffi/src/phone/meetings_app.rs`). Amethod answers JSON, or the ffi's error `{ code, message }`. A body that hasnot landed answers `{ code: "not_yet" }`. Names and shapes are fixed from thefirst push; any later change is written at the top ofthe core session's report first.## TablesFresh, sealed from the first build (`crates/cotton-core/kits/personal/tables/`):- `meetings_meeting`: title, kind (`meeting`|`memo`), status  (`recording`|`waiting`|`transcribing`|`ready`|`failed`), status_why,  started_at, ended_at, duration_ms, audio (file), audio_bytes, languages  (BCP 47, comma separated, in order of first speech), speakers, lines  (counts), transcribed_by (`<where>:<engine>`, e.g. `mac:sherpa:whisper-large-v3`),  transcribed_at, transcribe_on (`any`|`mac`|`phone`|`service`), asked_at,  attempts, summary, actions, summarised_by, summarised_at, recorded_on,  on_phone (this device's answer, never stored: `absent`|`kept`).- `meetings_speaker`: meeting, label (`S1`, `S2`… in order of first speech),  name, person (link to `person`, this meeting only: no voice print is ever  kept), lines, talk_ms, first_ms.- `meetings_line`: meeting, speaker, position, start_ms, end_ms, text,  language, edited.`meeting` / `meeting_utterance` are the Mac era's rows, kept as they are;`meetings.create` (the old Cotton app's door) is unchanged and writes them.Status walk: `recording` → (stop) `waiting` → (a transcriber claims it)`transcribing` → `ready`, or `failed` with `status_why` (a word from the`meetings` line set's `why.*`). `meetings.transcribe` puts `ready`/`failed`back to `waiting`.## Recording- `meetings.record.start { kind?: "meeting"|"memo", title?, id?, started_at?, recorded_on? }` →  `{ meeting, audio_path, started_at }`. The row exists from the first  second (status `recording`). `id` is the platform's take id when it has one  (the row's id is then that id, and a start sent twice is one recording).  `audio_path` is the file the platform appends  to (16 kHz mono 16-bit PCM WAV, header rewritten at stop or recovery; the  platform may write AAC/M4A instead and say so at stop with `format`).- `meetings.record.tick { meeting, duration_ms }` → `{}`: every ~10 s while  recording, so a crash still knows the length.- `meetings.record.stop { id, duration_ms?, path?, format?: "wav"|"m4a"|"aac", ended_at?, marks?: [ms…], silenced?: [[from_ms, to_ms]…], recovered? }` →  `{ meeting, status: "waiting", audio_bytes }`. Fixes the WAV header,  copies the bytes into the sealed media store, writes the upload ledger row  (the existing media drain; large files go in parts), stamps ended_at.  `aac` is ADTS frames (Android's take: whole up to its last frame at any  byte). The core keeps `marks` (the moments the person marked) and  `silenced` (stretches a call took the microphone) on the row as JSON text,  and `recovered: true` (a take finished after a kill) as `status_why:  recovered`.- `meetings.record.discard { id }` → `{ meeting, discarded: true }`: on the  person's word, a recording still `recording` goes, its row to the bin and  its working file deleted; a stopped one is refused (`refusal.not_recording`), one already gone  answers as discarded.- `meetings.record.recover {}` or `{ id, path, … as stop }` → `{ recovered: [{ meeting, status, duration_ms }] }`:  called at launch, for every take the platform recovered or with none to sweep. Every `recording` row whose audio file is on this  device is finished as stop would (status `waiting`); one whose file is  missing or empty becomes `failed` (`why.no_audio`).## Transcription (one interface, three implementations)Input: the meeting's audio. Output, the **transcript**:```json{ "by": "mac:sherpa:whisper-large-v3",  "languages": ["en", "hi"],  "speakers": [{ "label": "S1" }, { "label": "S2" }],  "lines": [{ "speaker": "S1", "start_ms": 0, "end_ms": 4210, "text": "…", "language": "en" }] }```- `meetings.transcribed { meeting, transcript }` → `{ meeting, lines, speakers }`:  the event `meeting.transcribed` lands lines and speakers in ONE write; a line  a person corrected (edited) is kept over the new one it overlaps; names given  to speakers are kept by label where the new transcript keeps that label.- `meetings.transcribe { id }` → `{ meeting, status: "waiting" }` (again).- `meetings.next { on: "phone", charging: bool, peek?, except?: [id…], id? }` → `{ meeting?, audio_path?, plan? }`:  the next `waiting` recording this phone should transcribe (its own audio,  `transcribe_on` `any` or `phone`, only while charging); claims it  (`transcribing`).  signed in, the phone claims through the object first (`meeting_claim { id,  by: "phone" }`, refused 409 when the Mac holds it): `peek` names the  candidate and claims nothing, `except` passes over ones the object refused,  and `id` takes that one only (iPhone).- `meetings.windows { duration_ms, speech?: [{ start_ms, end_ms }] }` →  `{ windows: [{ index, start_ms, end_ms }] }`: long audio cut in windows  with overlap, cut in silence where voice-activity says so.- `meetings.merge { windows: [{ index, start_ms, end_ms, language?, lines: [...] , speakers?: [{ label, embedding? }] }] }`  → `{ transcript }`: overlap de-duplicated, speakers made one set across  windows, languages per line, labels renumbered in order of first speech.The Mac drains the Worker's queue as film import does (`cotton-mac`); theoutside service is an adaptor on the Worker that ships DISABLED.### How a language is writtenTelugu speech lands in Latin letters for now (owner, 17 Nov 2026). The onevalue is `crates/cotton-rules/src/script/written.json` (`"te": "latin"`;`native` keeps Telugu letters), spelt by the table `script/te.json`. Bothlandings (the Mac's `meetings::land`, the phone's `meetings.transcribed`) passthe engine's lines through `meetings::as_written`; a corrected line is theperson's and is kept as typed. The summariser reads older lines the same way,and day words are matched in Latin letters whichever way a line was landed.No setting or UI yet: a later owner setting replaces that one value.## Reading, naming, finding, exporting- `meetings.read { id, charging? }` → `{ meeting, speakers: [...], lines: [...], marks: [ms…], silenced: [[from_ms, to_ms]…],  audio: { key, path? }?, audio_path?, actions, summary_note, status_words, transcribed_by }`: `audio_path` (and  `audio.path`) only while this device holds the recording's bytes; otherwise the phone asks `media.ensure { key }`.- `meetings.line.correct { line, text }` → `{ line }`: the person's correction (edited), kept over every later transcription of that moment.- `meetings.speaker.name { speaker, name?, person? }` → `{ speaker }` (this meeting only).- `meetings.search { q, id?, limit? }` → `{ hits: [{ meeting, line, start_ms, end_ms, text, speaker }], total }` (`id` narrows to one meeting).- `meetings.export { id, dir?, format?: "txt"|"srt"|"json"|"audio" }` → `{ files: [{ name, path, type }], dir }`: the open  bundle — the audio, `transcript.txt`, `transcript.srt`, `transcript.json`.- `meetings.summarise { id }` → `{ meeting, status: "asked", said }`: asks the  person's Mac for the summary (again) by stamping `summary_asked_at`, and  puts `summarise_on` back to `mac`. Nothing leaves the person's devices.## Summary and actionsOwner's decision (17 Nov 2026): a meeting's summary and actions are made onthe person's Mac by a local open-weight model (`cotton-mac` `summarise`,`pnpm meetings:summarise`; the catalogue `kits/shell/meetings/models.json`;the rules `cotton_rules::meetings_summary`). No cloud model is called byCotton; a person who wants one asks their own assistant over Cotton MCP,which writes the same columns and rows.- `meetings_meeting` adds `summary_why` (`no_mac`|`model_missing`|`failed`|`off`),  `summarise_on` (`mac`|`off`, default `mac`) and `summary_asked_at`;  `summary`, `actions`, `summarised_by` and `summarised_at` are writable by an  assistant (its own name in `summarised_by`).- `meetings_action`: meeting, position, words, who (a speaker's label or a  name the transcript says), speaker, due (a day), due_said (the transcript's  words for it), at_ms, todo (written by the core only), made_by. An owner or  a day is kept only where the transcript says it; the day is worked out from  the words and the meeting's own day, never taken from the model.- `meetings.read` also answers `actions: [{ id, words, who, due, due_said,  at_ms, todo, added, act?: { label, method }, said? }]` and `summary_note`  (why a ready meeting has no summary, in the person's words, or null).- `meetings.action.todo { id }` → `{ action, todo, added: true, already, said }`:  Add to todos makes a todo (the action's words, its day as `due_at`, the  meeting it came from in its notes) and links it from the action; an action  already added answers its todo and makes no other.Every method naming a meeting takes `id` (or `meeting`). `meetings.transcribed`also takes `{ id, by, windows }` (the core merges them) or `{ id, failed: <why> }`.`meetings.windows` takes `{ id }` or `{ duration_ms, speech? }`.