Cotton code
867 lines · 21.6 KB · JSONRaw
{  "format_version": 1,  "id": "thought",  "name": "Thought",  "plural": "Thoughts",  "record_route": "/thoughts/thought/[id]",  "linked_when": {    "made": "captured {when}"  },  "picture": {    "photo": "photo:5b1d4715a5305ceb5075a7eaad5557b3a1c34f264b23bbd97b56272a468deebd",    "object": "tool-thoughts"  },  "builtin": true,  "engine": "thoughts",  "role": "thought",  "record_kind": "thought",  "views": [    {      "face": "capture",      "name": "Capture",      "sizes": [        "small",        "medium",        "large"      ],      "everywhere": true    }  ],  "columns": [    {      "key": "raw_text",      "name": "Words",      "type": "longtext",      "readonly": true,      "placeholder": "Nothing written"    },    {      "key": "audio_url",      "name": "Recording",      "type": "file",      "readonly": true    },    {      "key": "transcript",      "name": "What Cotton heard",      "type": "longtext",      "readonly": true    },    {      "key": "captured_at",      "name": "Captured",      "type": "date",      "readonly": true    },    {      "key": "route_status",      "name": "Status",      "type": "choice",      "choices": [        "pending",        "routed",        "corrected",        "dismissed"      ],      "labels": {        "pending": "Waiting to be filed",        "routed": "Filed",        "corrected": "Filed by you",        "dismissed": "Dismissed"      },      "stamps": {        "dismissed": "dropped"      },      "readonly": true    },    {      "key": "routed_kind",      "name": "Became",      "type": "text",      "readonly": true    },    {      "key": "became",      "name": "What it became",      "type": "text",      "readonly": true    },    {      "key": "standing",      "name": "Standing",      "type": "choice",      "choices": [        "open",        "filed"      ],      "labels": {        "open": "Open",        "filed": "Filed"      },      "readonly": true    },    {  "key": "story",  "name": "Story",  "type": "choice",  "choices": [    "waiting",    "thought",    "one",    "several",    "dismissed"  ],  "readonly": true,  "labels": {    "waiting": "Waiting",    "thought": "Thought",    "one": "One",    "several": "Several",    "dismissed": "Dismissed"  }},    {  "key": "became_count",  "name": "Records it became",  "type": "number",  "readonly": true,  "units": {    "one": "record",    "other": "records",    "zero": "0 records"  }},    {      "key": "why",      "name": "Why it stopped",      "type": "text",      "readonly": true    },    {      "key": "filed_elsewhere",      "name": "Filed into another table",      "type": "bool",      "readonly": true    },    {      "key": "said_table",      "name": "Said in",      "type": "text",      "readonly": true    },    {      "key": "said_record_id",      "name": "Said on",      "type": "text",      "readonly": true    }  ],  "title": "raw_text",  "date": "captured_at",  "project": null,  "order": null,  "slip": {    "title": "raw_text",    "title_fallback": "transcript",    "subtitle": "became",    "trailing": "captured_at",    "photo": null,    "toggle": null,    "links": {      "except": []    }  },  "tile": {    "face": "slip-list",    "current": {      "column": "captured_at",      "days": 2    }  },  "hidden": {    "column": "route_status",    "values": [      "dismissed"    ]  },  "filter": {    "column": "standing",    "all": "All",    "words": {      "open": "Open"    },    "order": [      "open"    ],    "empty": {      "open": {        "title": "Nothing open.",        "message": "Every thought you captured has been filed."      }    }  },  "create": {    "label": "New thought",    "path": "/capture"  },  "empty": {    "title": "No thoughts yet.",    "message": "What you capture lands here."  },  "delete": false,  "hand_over": {    "when": {      "column": "story",      "values": [        "one"      ]    }  },  "attachments": {    "editable": true,    "sources": [      "library",      "camera"    ]  },  "send_to_session": {    "label": "Send to a session…",    "body": "raw_text",    "record_as": "thoughtId"  },  "page": [    {      "heading": null,      "columns": [],      "when": {        "column": "audio_url",        "present": true      },      "note": "Spoken"    },    {      "heading": null,      "columns": [        "raw_text",        "transcript",        "audio_url",        "captured_at"      ]    },    {      "heading": null,      "columns": [],      "when": {        "column": "route_status",        "values": [          "pending"        ]      },      "note": "Not filed yet — your assistant files it when it next runs",      "hand": "{why}"    },    {      "heading": null,      "columns": [],      "when": {        "column": "story",        "values": [          "several"        ]      },      "hand": "This one became {became_count} records."    },    {      "heading": null,      "columns": [],      "when": {        "column": "story",        "values": [          "thought"        ]      },      "note": "Stayed a thought — nothing was made of it, and nothing needs to be."    },    {      "heading": null,      "columns": [],      "when": {        "column": "route_status",        "values": [          "dismissed"        ]      },      "note": "Dismissed — it stays on the record, out of the way."    },    {      "heading": "What it became",      "links": {        "except": []      }    }  ],  "commands": [    {      "id": "todo",      "label": "Make todo",      "object": "done",      "kind": "update",      "verb": "file_thought",      "data": {        "as": "todo"      },      "bindings": {        "id": "$id"      },      "when": {        "story": "waiting"      },      "receipt": "Made a todo",      "undo": "untodo",      "does": "moves"    },    {      "id": "note",      "label": "Save note",      "object": "edit",      "kind": "update",      "verb": "file_thought",      "data": {        "as": "note"      },      "bindings": {        "id": "$id"      },      "when": {        "story": "waiting"      },      "receipt": "Made a note",      "undo": "unnote",      "does": "moves"    },    {      "id": "file",      "label": "File",      "kind": "update",      "verb": "file_thought",      "pick_table": "as",      "bindings": {        "id": "$id"      },      "when": {        "story": "waiting"      },      "receipt": "Filed",      "does": "moves"    },    {      "id": "untodo",      "label": "Undo todo",      "object": "restore",      "kind": "update",      "verb": "file_thought",      "data": {        "as": null      },      "bindings": {        "id": "$id"      },      "when": {        "route_status": "corrected",        "story": "one",        "routed_kind": "todo"      },      "receipt": "Waiting to be filed again",      "undo": "todo"    },    {      "id": "unnote",      "label": "Undo note",      "object": "restore",      "kind": "update",      "verb": "file_thought",      "data": {        "as": null      },      "bindings": {        "id": "$id"      },      "when": {        "route_status": "corrected",        "story": "one",        "routed_kind": "note"      },      "receipt": "Waiting to be filed again",      "undo": "note"    },    {      "id": "dismiss",      "label": "Dismiss",      "object": "archive",      "kind": "update",      "verb": "update_record",      "data": {        "table": "thought",        "patch": {          "route_status": "dismissed"        }      },      "bindings": {        "id": "$id"      },      "when": {        "route_status": "pending"      },      "receipt": "Thought dismissed",      "does": "puts-away"    }  ],  "instructions": "A thought is a quick capture, typed or spoken, before it is filed. Pending thoughts have not been filed yet; routed ones became records such as a todo or a note, corrected ones were filed or re-filed by the owner — into any table, and dismissed ones became nothing. Keep the captured words verbatim; the records it became carry the meaning.",  "parts": {    "shape": "desk",    "head": {      "facts": [        "captured_at"      ]    },    "links": [],    "body": "raw_text",    "lists": [],    "acts": {      "more": [        "todo",        "note",        "file",        "untodo",        "unnote"      ],      "away": "dismiss"    },    "strip": [      {        "column": "transcript"      },      {        "column": "audio_url"      },      {        "column": "captured_at"      }    ]  },  "tool": {    "name": "Thoughts",    "key": "thoughts",    "card_stock": "cream",    "icon": "lightbulb",    "route": "/thoughts"  ,"purpose":"Capture something to file or turn into a task."},  "tables": [    {      "name": "cotton_thought_attachments",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "thought_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    thought_id TEXT NOT NULL",          "position": 2        },        {          "name": "record_kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    record_kind TEXT NOT NULL",          "position": 3        },        {          "name": "record_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    record_id TEXT NOT NULL",          "position": 4        },        {          "name": "position",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    position INTEGER NOT NULL",          "position": 5        },        {          "name": "caption",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    caption TEXT",          "position": 6        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 7        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 8        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 9        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 10        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (thought_id, record_kind, record_id)",          "position": 11        },        {          "declaration": "\n    CHECK (record_kind IN ('photo', 'video', 'document'))",          "position": 12        },        {          "declaration": "\n    CHECK (length(record_id) > 0)",          "position": 13        },        {          "declaration": "\n    CHECK (position >= 0)",          "position": 14        },        {          "declaration": "\n    CHECK (caption IS NULL OR length(caption) <= 500)",          "position": 15        },        {          "declaration": "\n    FOREIGN KEY (thought_id) REFERENCES cotton_inbox_items(id)",          "position": 16        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 17        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_thought_attachments (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_thought_attachments_author ON cotton_thought_attachments (substr(_hlc, 20), _hlc)",        "CREATE INDEX IF NOT EXISTS idx_cotton_thought_attachments_thought ON cotton_thought_attachments (thought_id, position)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_inbox_items",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "raw_text",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    raw_text TEXT",          "position": 2        },        {          "name": "audio_url",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    audio_url TEXT",          "position": 3        },        {          "name": "captured_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    captured_at TEXT NOT NULL",          "position": 4        },        {          "name": "route_status",          "type": "TEXT",          "default": "'pending'",          "nullable": false,          "primary_key": false,          "declaration": "\n    route_status TEXT NOT NULL DEFAULT 'pending'",          "position": 5        },        {          "name": "routed_kind",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    routed_kind TEXT",          "position": 6        },        {          "name": "routed_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    routed_id TEXT",          "position": 7        },        {          "name": "route_confidence",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    route_confidence TEXT",          "position": 8        },        {          "name": "correction_of",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    correction_of TEXT",          "position": 9        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 10        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 11        },        {          "name": "transcript",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    transcript TEXT",          "position": 12        },        {          "name": "route_reason",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    route_reason TEXT",          "position": 13        },        {          "name": "route_proposal",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    route_proposal TEXT",          "position": 14        },        {          "name": "routed_records",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    routed_records TEXT",          "position": 15        },        {          "name": "route_plan",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    route_plan TEXT",          "position": 16        },        {          "name": "route_plan_user_edited",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    route_plan_user_edited INTEGER",          "position": 17        },        {          "name": "swept_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    -- v20: the chat sweep's two marks on a capture.\n    swept_at TEXT",          "position": 18        },        {          "name": "sweep_note",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    sweep_note TEXT",          "position": 19        },        {          "name": "said_table",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    -- v75: where the thought was said (Spec 7): the tool's table when it\n    -- was said inside one, and the record when it was said on a record's\n    -- page. Both NULL for a thought said on the database's own page.\n    -- capture.create refuses a record without its table; no constraint here, a\n    -- synced row arrives column by column (tests/no_cross_column_checks.rs).\n    said_table TEXT",          "position": 20        },        {          "name": "said_record_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    said_record_id TEXT",          "position": 21        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 22        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 23        },        {          "name": "trashed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " trashed_at TEXT",          "position": 24        }      ],      "constraints": [        {          "declaration": "\n    CHECK ((raw_text IS NOT NULL) OR (audio_url IS NOT NULL))",          "position": 25        },        {          "declaration": "\n    CHECK (route_status IN ('pending', 'routed', 'corrected', 'dismissed'))",          "position": 26        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 27        }      ],      "prefix": "CREATE TABLE \"cotton_inbox_items\" (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_inbox_items_workspace ON cotton_inbox_items (workspace_id, route_status)",        "CREATE INDEX idx_cotton_inbox_items_said ON cotton_inbox_items (said_table, said_record_id) WHERE said_table IS NOT NULL",        "CREATE INDEX IF NOT EXISTS idx_cotton_inbox_items_author ON cotton_inbox_items (substr(_hlc, 20), _hlc)"      ],      "full_text": [        "CREATE VIRTUAL TABLE fts_thoughts USING fts5(\n       raw_text, content = 'cotton_inbox_items', content_rowid = 'rowid',\n       tokenize = 'unicode61 remove_diacritics 2'\n     )"      ],      "triggers": [        "CREATE TRIGGER fts_thoughts_ai AFTER INSERT ON cotton_inbox_items WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_thoughts'), 0) BEGIN\n       INSERT INTO fts_thoughts (rowid, raw_text) VALUES (new.rowid, new.raw_text);\n     END",        "CREATE TRIGGER fts_thoughts_ad AFTER DELETE ON cotton_inbox_items WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_thoughts'), 0) BEGIN\n       INSERT INTO fts_thoughts (fts_thoughts, rowid, raw_text) VALUES ('delete', old.rowid, old.raw_text);\n     END",        "CREATE TRIGGER fts_thoughts_au AFTER UPDATE OF raw_text ON cotton_inbox_items\n       FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_thoughts'), 0) AND (new.raw_text IS NOT old.raw_text) BEGIN\n       INSERT INTO fts_thoughts (fts_thoughts, rowid, raw_text) VALUES ('delete', old.rowid, old.raw_text);\n       INSERT INTO fts_thoughts (rowid, raw_text) VALUES (new.rowid, new.raw_text);\n     END"      ]    }  ],  "page_parts": [    "content",    "grid",    "sections"  ]}