Cotton code
501 lines · 11.5 KB · JSONRaw
{  "format_version": 1,  "id": "email_sender",  "name": "Email sender",  "plural": "Email senders",  "builtin": true,  "visibility": "owner",  "columns": [    {      "key": "address",      "type": "text",      "readonly": true,      "fact": true,      "reading": "{value}"    },    {      "key": "kind",      "name": "Is",      "type": "choice",      "choices": [        "person",        "service",        "junk"      ],      "labels": {        "person": "Person",        "service": "Service",        "junk": "Junk"      },      "readonly": true    },    {      "key": "written_to",      "type": "bool",      "readonly": true    },    {      "key": "decided_by",      "type": "text",      "readonly": true    },    {      "key": "verdict",      "type": "text",      "readonly": true    },    {      "key": "reason",      "name": "Why",      "type": "text",      "readonly": true    },    {      "key": "decided_at",      "type": "date",      "format": "calendar-datetime",      "readonly": true    },    {      "key": "name",      "type": "text",      "readonly": true    },    {      "key": "last_at",      "name": "Latest email",      "type": "date",      "readonly": true    },    {      "key": "email_count",      "name": "Emails",      "type": "number",      "readonly": true,      "units": {        "one": "email",        "other": "emails",        "zero": "0 emails"      }    },    {      "key": "unread_count",      "name": "Unread",      "type": "number",      "readonly": true,      "units": {        "one": "unread email",        "other": "unread emails",        "zero": "0 unread emails"      }    },    {      "key": "blocked",      "name": "Blocked",      "type": "bool",      "readonly": true    },    {      "key": "in_people",      "name": "In People",      "type": "bool",      "readonly": true    }  ],  "instructions": "Imported email archive. Ingest and Gmail sync run in Rust. Cotton has no send or reply verb. Never create imported mail as a substitute for delivery.",  "tables": [    {      "name": "cotton_blocked_senders",      "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": "address",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    address TEXT NOT NULL",          "position": 2        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 3        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 4        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 5        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, address)",          "position": 6        },        {          "declaration": "\n    CHECK (length(address) > 0)",          "position": 7        },        {          "declaration": "\n    CHECK (address = lower(address))",          "position": 8        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 9        }      ],      "prefix": "CREATE TABLE cotton_blocked_senders (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_blocked_senders_address ON cotton_blocked_senders (workspace_id, address)",        "CREATE INDEX IF NOT EXISTS idx_cotton_blocked_senders_author ON cotton_blocked_senders (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_email_senders",      "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": "address",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    address TEXT NOT NULL",          "position": 2        },        {          "name": "kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    kind TEXT NOT NULL",          "position": 3        },        {          "name": "written_to",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    written_to INTEGER NOT NULL DEFAULT 0",          "position": 4        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 5        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 6        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 7        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 8        },        {          "name": "decided_by",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    decided_by TEXT CHECK (decided_by IS NULL OR decided_by IN ('owner', 'assistant'))",          "position": 9        },        {          "name": "verdict",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    verdict TEXT CHECK (verdict IS NULL OR verdict IN ('person', 'service', 'junk'))",          "position": 10        },        {          "name": "reason",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    reason TEXT",          "position": 11        },        {          "name": "decided_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    decided_at TEXT",          "position": 12        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, address)",          "position": 13        },        {          "declaration": "\n    CHECK (length(address) > 0)",          "position": 14        },        {          "declaration": "\n    CHECK (address = lower(address))",          "position": 15        },        {          "declaration": "\n    CHECK (kind IN ('person', 'service', 'junk'))",          "position": 16        },        {          "declaration": "\n    CHECK (written_to IN (0, 1))",          "position": 17        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 18        }      ],      "prefix": "CREATE TABLE cotton_email_senders (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_email_senders_author ON cotton_email_senders (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ],  "card": {    "face": "plain",    "fields": [      {        "slot": "title",        "column": "name"      },      {        "slot": "subtitle",        "column": "address"      },      {        "slot": "facts",        "column": "last_at",        "also": [          "email_count",          "unread_count",          "kind",          "blocked"        ]      }    ]  },  "picture": null,  "engine": "email",  "title": "name",  "date": "last_at",  "project": null,  "order": null,  "slip": {    "title": "name",    "subtitle": "address",    "trailing": "last_at",    "photo": null,    "toggle": null,    "caption": {      "columns": [        "email_count"      ]    }  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "name",        "address",        "email_count",        "unread_count",        "last_at",        "blocked",        "kind",        "reason"      ]    }  ],  "empty": {    "title": "No senders in this view",    "message": "Senders appear here as email arrives from connected accounts."  },  "delete": false,  "commands": [    {      "id": "junk",      "label": "Block sender",      "kind": "update",      "verb": "block_sender",      "destructive": true,      "confirm": "Mail from this sender goes to Junk from now on. Keep brings it back.",      "bindings": {        "address": "$id"      },      "when": {        "blocked": false      },      "receipt": "Moved {name} to Junk",      "does": "destroys",      "object": "block"    },    {      "id": "keep",      "label": "Keep",      "kind": "update",      "verb": "unblock_sender",      "bindings": {        "address": "$id"      },      "when": {        "blocked": true      },      "receipt": "Kept {name}",      "does": "completes"    },    {      "id": "add_to_people",      "label": "Add person",      "kind": "create",      "verb": "add_sender_to_people",      "bindings": {        "address": "$id"      },      "when": {        "in_people": false,        "blocked": false      },      "receipt": "Added to People",      "does": "moves"    }  ],  "parts": {    "shape": "sheet",    "head": {      "facts": [        "address"      ]    },    "links": [],    "lists": [      {        "table": "email_thread",        "match": {          "column": "sender_address",          "parent": "address"        },        "heading": "Mail"      }    ],    "acts": {      "more": [        "keep",        "junk",        "add_to_people"      ]    },    "cards": [      {        "column": "kind"      },      {        "column": "last_at"      },      {        "column": "unread_count"      },      {        "column": "blocked"      }    ],    "strip": []  }}