Cotton code
400 lines · 12.4 KB · JSONRaw
{  "format_version": 1,  "id": "assistant",  "list_route": "/assistants",  "scope": "personal",  "setup": true,  "name": "Assistant",  "plural": "Assistants",  "picture": {"photo":"photo:6bab16767d7fe30bcbcbcf341aa755a88544d3e9b964db99cc8d3bf9e159b09f","object":"tool-assistants"},  "builtin": true,  "engine": "assistants",  "screen_family": "assistants",  "columns": [    { "key": "kept", "name": "Kept", "type": "bool", "readonly": true },    { "key": "name", "name": "Name", "type": "text", "required": true },    { "key": "account", "name": "Account", "type": "text", "readonly": true },    { "key": "status", "name": "Status", "type": "text", "readonly": true },    {  "key": "last_synced_at",  "name": "Last used",  "type": "date",  "readonly": true,  "fact": true,  "reading": "Last used {value}",  "format": "calendar-datetime"},    { "key": "expires_at", "name": "Ends", "type": "date", "readonly": true },    { "key": "needs_sign_in_since", "name": "Signed out on", "type": "date", "readonly": true },    { "key": "address", "name": "Address", "type": "text", "readonly": true },    { "key": "can_change", "name": "Can change records", "type": "bool", "default": false },    { "key": "expires", "name": "Expires after", "type": "choice", "choices": ["30 days", "90 days", "Never"], "default": "90 days" },    { "key": "recent_uses", "name": "Last used", "type": "longtext", "readonly": true }  ],  "title": "name",  "date": "last_synced_at",  "project": null,  "order": null,  "slip": { "title": "name", "subtitle": "account", "trailing": "status", "photo": null, "toggle": null },  "tile": { "face": "slip-list" },  "empty": { "title": "No assistant connected yet" },  "page": [    { "heading": null, "columns": ["name", "account", "status"] },    { "heading": "Settings", "columns": ["address", "can_change", "expires"] },    { "heading": "Details", "columns": ["last_synced_at", "expires_at", "needs_sign_in_since", "recent_uses"] }  ],  "instructions": "An assistant is a client that reads this database over MCP with a key Cotton made for it. The list connects a new one (Connect an assistant, Approve a request); an assistant's page shows its address, whether it can change records and when its key expires, its recent uses, and its actions (Copy address, Disconnect, and Remove once it is disconnected or expired). What Cotton itself reads from outside — a Google account, a code host, a mailbox — is the Connections tool, not this one.",  "add": false,  "readonly_when": "kept",  "create": {"label": "Connect an assistant"},  "delete": false,  "commands": [    {"id":"connect","label":"Connect","object":"link","kind":"create","method":"settings.mintAssistant","form":true,"receipt":"Connected",     "bindings":{"name":"name","can_change":"can_change","expires":"expires"},     "reveals":{"answer":"secret","title":"Your new key","note":"Copy this key now. Cotton shows it only once and cannot recover it."}},    {      "id": "disconnect","object":"unlink",      "label": "Disconnect",      "kind": "update",      "method": "settings.mcpToken",      "data": {        "action": "revoke"      },      "bindings": {        "id": "$id"      },      "when": {        "status": {          "not": [            "Disconnected",            "Expired"          ]        }      },      "destructive": true,      "confirm": "Its key stops working at once and cannot be turned back on — connecting it again makes a new key. The connection and its activity stay listed.",      "receipt": "Disconnected {name}",      "does": "destroys"    },    {"id":"remove","object":"bin","label":"Remove","kind":"delete","method":"settings.mcpToken","data":{"action":"delete"},"bindings":{"id":"$id"},     "when":{"status":["Disconnected","Expired"]},"destructive":true,     "confirm":"Its key and its activity leave the list for good.","receipt":"Removed {name}"},    {"id":"copy_address","label":"Copy address","kind":"copy","copies":"address"},    {"id":"approve_request","object":"qrcode","label":"Approve a request","kind":"create","method":"settings.openFlow",     "data":{"flow":"approveRequest","origin_table":"assistant","origin_id":"new"},"list":{"at_least":0},"receipt":"Opened the approval"}  ],  "parts": {    "shape": "sheet",    "head": {      "facts": [        "last_synced_at"      ],      "state": "status"    },    "links": [],    "lists": [],    "acts": {      "main": "connect",      "more": ["copy_address", "remove"],      "away": "disconnect"    },    "cards": [  {    "column": "address",    "row": true  },  {    "column": "can_change"  },  {    "column": "account"  },  {    "column": "recent_uses",    "row": true  },  {    "column": "expires_at"  },  {    "column": "needs_sign_in_since"  }],    "strip": []  },  "tool": {    "name": "Assistants",    "key": "assistants",    "icon": "headset",    "card_stock": "grey",    "route": "/assistants"  ,"purpose":"The assistants with access to your data."},  "tables": [    {      "name": "cotton_agent_accounts",      "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": "provider",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    provider TEXT NOT NULL",          "position": 2        },        {          "name": "email",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    email TEXT NOT NULL",          "position": 3        },        {          "name": "label",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    label TEXT",          "position": 4        },        {          "name": "five_hour_pct",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    five_hour_pct REAL",          "position": 5        },        {          "name": "five_hour_resets_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    five_hour_resets_at TEXT",          "position": 6        },        {          "name": "weekly_pct",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    weekly_pct REAL",          "position": 7        },        {          "name": "weekly_resets_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    weekly_resets_at TEXT",          "position": 8        },        {          "name": "seen_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    seen_at TEXT",          "position": 9        },        {          "name": "seen_on_device_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    seen_on_device_id TEXT",          "position": 10        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 11        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 12        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 13        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 14        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, provider, email)",          "position": 15        },        {          "declaration": "\n    CHECK (provider IN ('anthropic', 'openai'))",          "position": 16        },        {          "declaration": "\n    CHECK (length(trim(email)) > 0)",          "position": 17        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 18        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_agent_accounts (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_agent_accounts_workspace ON cotton_agent_accounts (workspace_id, seen_at DESC)",        "CREATE INDEX IF NOT EXISTS idx_cotton_agent_accounts_author ON cotton_agent_accounts (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_account_usage_samples",      "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": "account_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    account_id TEXT NOT NULL",          "position": 2        },        {          "name": "sampled_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    sampled_at TEXT NOT NULL",          "position": 3        },        {          "name": "five_hour_pct",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    five_hour_pct REAL",          "position": 4        },        {          "name": "weekly_pct",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    weekly_pct REAL",          "position": 5        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 6        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 7        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, account_id, sampled_at)",          "position": 8        },        {          "declaration": "\n    CHECK (length(trim(account_id)) > 0)",          "position": 9        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 10        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_account_usage_samples (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_account_usage_samples_account ON cotton_account_usage_samples (workspace_id, account_id, sampled_at DESC)",        "CREATE INDEX IF NOT EXISTS idx_cotton_account_usage_samples_author ON cotton_account_usage_samples (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ]}