Cotton code
699 lines · 18.9 KB · JSONRaw
{  "format_version": 1,  "id": "memory",  "name": "Memory",  "plural": "Memories",  "visibility": "owner",  "title": "title",  "columns": [    {      "key": "slug",      "type": "text",      "required": true,      "indexed": true,      "readonly": true,      "name": "Citation"    },    {      "key": "title",      "type": "text",      "required": true,      "readonly": true,      "name": "Entry"    },    {      "key": "body",      "name": "Body",      "type": "longtext",      "readonly": true    },    {      "key": "status",      "name": "Status",      "type": "choice",      "choices": [        "active",        "archived",        "proposed"      ],      "default": "active",      "readonly": true,      "labels": {        "proposed": "Proposed",        "active": "Active",        "archived": "Archived"      }    },    {      "key": "machine",      "type": "text",      "readonly": true,      "name": "Device"    },    {      "key": "visibility",      "name": "Visibility",      "type": "choice",      "choices": [        "private",        "shared",        "public"      ],      "default": "private",      "readonly": true,      "labels": {        "private": "Only you",        "shared": "Shared",        "public": "Public"      }    },    {      "key": "origin_kind",      "type": "choice",      "choices": [        "user",        "agent"      ],      "required": true,      "readonly": true,      "name": "Written by",      "labels": {        "user": "You",        "agent": "Assistant"      }    },    {      "key": "origin_label",      "type": "text",      "readonly": true,      "name": "Assistant"    },    {      "key": "source",      "name": "Source",      "type": "text",      "readonly": true    },    {      "key": "superseded_by",      "type": "link",      "readonly": true,      "name": "Replaced by",      "link_to": "memory",      "contributes": false    },    {      "key": "source_external_id",      "name": "Source external id",      "type": "text"    },    {      "key": "archived_at",      "name": "Archived at",      "type": "text"    },    {      "key": "reviewed_at",      "name": "Reviewed",      "type": "date",      "readonly": true    },    {      "key": "created_at",      "name": "Added",      "type": "date",      "readonly": true,      "fact": true,      "reading": "{value}",      "format": "calendar-datetime"    }  ],  "instructions": "A memory is one thing the owner said that should hold across sessions, in the owner's own words and order. An assistant only transcribes what the owner said: an entry an assistant writes is marked unreviewed until the owner keeps it. Cite an entry by its citation slug, and change or archive one only when the owner has said so.",  "tables": [    {      "name": "cotton_memory_projects",      "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": "slug",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    slug TEXT NOT NULL",          "position": 2        },        {          "name": "name",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    name TEXT NOT NULL",          "position": 3        },        {          "name": "repos",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    repos TEXT NOT NULL DEFAULT '[]'",          "position": 4        },        {          "name": "brand",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    brand TEXT CHECK (brand IS NULL OR json_type(brand) = 'object')",          "position": 5        },        {          "name": "description",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    description TEXT",          "position": 6        },        {          "name": "summary_updated_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary_updated_at TEXT",          "position": 7        },        {          "name": "summary_by",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary_by TEXT",          "position": 8        },        {          "name": "status",          "type": "TEXT",          "default": "'active'",          "nullable": false,          "primary_key": false,          "declaration": "\n    status TEXT NOT NULL DEFAULT 'active'",          "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": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 12        },        {          "name": "origin_handle",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0)",          "position": 13        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 14        },        {          "name": "section_order",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    section_order TEXT CHECK (section_order IS NULL OR json_type(section_order) = 'array')",          "position": 15        },        {          "name": "trashed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " trashed_at TEXT",          "position": 16        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, slug)",          "position": 17        },        {          "declaration": "\n    CHECK (length(trim(name)) > 0)",          "position": 18        },        {          "declaration": "\n    CHECK (json_type(repos) = 'array')",          "position": 19        },        {          "declaration": "\n    CHECK (length(slug) BETWEEN 1 AND 64 AND slug GLOB '[a-z0-9]*' AND NOT slug GLOB '*[^a-z0-9-]*')",          "position": 20        },        {          "declaration": "\n    CHECK (status IN ('active', 'archived'))",          "position": 21        },        {          "declaration": "\n    CHECK ((summary_by IS NULL) OR (length(trim(summary_by)) > 0))",          "position": 22        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 23        }      ],      "prefix": "CREATE TABLE cotton_memory_projects (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_memory_projects_origin ON cotton_memory_projects (origin_handle) WHERE origin_handle IS NOT NULL",        "CREATE INDEX IF NOT EXISTS idx_cotton_memory_projects_author ON cotton_memory_projects (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_memories",      "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": "slug",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    slug TEXT NOT NULL",          "position": 2        },        {          "name": "title",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    title TEXT NOT NULL",          "position": 3        },        {          "name": "body",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    body TEXT NOT NULL DEFAULT ''",          "position": 4        },        {          "name": "status",          "type": "TEXT",          "default": "'active'",          "nullable": false,          "primary_key": false,          "declaration": "\n    status TEXT NOT NULL DEFAULT 'active'",          "position": 5        },        {          "name": "machine",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    machine TEXT",          "position": 6        },        {          "name": "visibility",          "type": "TEXT",          "default": "'private'",          "nullable": false,          "primary_key": false,          "declaration": "\n    visibility TEXT NOT NULL DEFAULT 'private'",          "position": 7        },        {          "name": "origin_kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    origin_kind TEXT NOT NULL",          "position": 8        },        {          "name": "origin_label",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    origin_label TEXT",          "position": 9        },        {          "name": "reviewed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    reviewed_at TEXT",          "position": 10        },        {          "name": "source_external_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    source_external_id TEXT",          "position": 11        },        {          "name": "archived_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    archived_at TEXT",          "position": 12        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 13        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 14        },        {          "name": "source",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    source TEXT",          "position": 15        },        {          "name": "superseded_by",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    superseded_by TEXT CHECK (superseded_by IS NULL OR status = 'archived')",          "position": 16        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 17        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 18        }      ],      "constraints": [        {          "declaration": "\n    CHECK ((status = 'archived') = (archived_at IS NOT NULL))",          "position": 19        },        {          "declaration": "\n    CHECK (length(body) <= 4000)",          "position": 20        },        {          "declaration": "\n    CHECK ((machine IS NULL) OR (length(trim(machine)) > 0))",          "position": 21        },        {          "declaration": "\n    CHECK (origin_kind IN ('user', 'agent'))",          "position": 22        },        {          "declaration": "\n    CHECK ((origin_kind = 'agent') = (origin_label IS NOT NULL))",          "position": 23        },        {          "declaration": "\n    CHECK (length(slug) BETWEEN 1 AND 64 AND slug GLOB '[a-z0-9]*' AND NOT slug GLOB '*[^a-z0-9-]*')",          "position": 24        },        {          "declaration": "\n    CHECK (status IN ('active', 'archived'))",          "position": 25        },        {          "declaration": "\n    CHECK ((length(trim(title)) > 0) AND (length(title) <= 280))",          "position": 26        },        {          "declaration": "\n    CHECK (visibility IN ('private', 'shared', 'public'))",          "position": 27        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 28        }      ],      "prefix": "CREATE TABLE \"cotton_memories\" (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_memories_glance ON cotton_memories (workspace_id,status,visibility,origin_kind,reviewed_at,created_at,id,title)",        "CREATE UNIQUE INDEX idx_cotton_memories_slug ON cotton_memories (workspace_id, slug)",        "CREATE UNIQUE INDEX idx_cotton_memories_source_external ON cotton_memories (workspace_id, source_external_id) WHERE source_external_id IS NOT NULL",        "CREATE INDEX idx_cotton_memories_superseded_by ON cotton_memories (superseded_by) WHERE superseded_by IS NOT NULL",        "CREATE INDEX idx_cotton_memories_unreviewed ON cotton_memories (workspace_id, updated_at DESC) WHERE (status = 'active') AND (reviewed_at IS NULL)",        "CREATE INDEX IF NOT EXISTS idx_cotton_memories_author ON cotton_memories (substr(_hlc, 20), _hlc)"      ],      "full_text": [        "CREATE VIRTUAL TABLE fts_memories USING fts5(\n       title, body, content = 'cotton_memories', content_rowid = 'rowid',\n       tokenize = 'unicode61 remove_diacritics 2'\n     )"      ],      "triggers": [        "CREATE TRIGGER fts_memories_ai AFTER INSERT ON cotton_memories WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_memories'), 0) BEGIN\n       INSERT INTO fts_memories (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n     END",        "CREATE TRIGGER fts_memories_ad AFTER DELETE ON cotton_memories WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_memories'), 0) BEGIN\n       INSERT INTO fts_memories (fts_memories, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n     END",        "CREATE TRIGGER fts_memories_au AFTER UPDATE OF title, body ON cotton_memories\n       FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_memories'), 0) AND (new.title IS NOT old.title OR new.body IS NOT old.body) BEGIN\n       INSERT INTO fts_memories (fts_memories, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n       INSERT INTO fts_memories (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n     END"      ]    }  ],  "picture": {    "photo": "photo:afa2e7071fc4a1861bf373c9f655432be3c584b1394989048eec4fc6bb1c789a",    "object": "tool-memory"  },  "builtin": true,  "engine": "memory",  "date": "created_at",  "project": null,  "order": null,  "slip": {    "title": "title",    "subtitle": null,    "trailing": "created_at",    "photo": null,    "toggle": null,    "title_lines": 0  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "title",        "body"      ]    },    {      "heading": "Origin",      "columns": [        "origin_kind",        "origin_label",        "reviewed_at",        "status"      ]    },    {      "heading": "Details",      "columns": [        "slug",        "machine",        "visibility",        "superseded_by"      ]    }  ],  "add": false,  "record_route": "/memory/[id]",  "delete": false,  "commands": [    {      "id": "open-superseded-by",      "label": "Open replaced by",      "object": "open",      "kind": "open",      "opens": "superseded_by"    }  ],  "tool": {    "views": [      {        "id": "all",        "label": "All",        "visibility": "owner",        "is_default": true,        "read": {          "table": "memory"        }      }    ],    "name": "Memory",    "purpose": "What Cotton should remember in this database.",    "tables": [      "memory",      "briefing"    ],    "key": "memory",    "icon": "brain",    "card_stock": "cream"  },  "card": {    "face": "memory",    "fields": [      {        "slot": "title",        "column": "title"      },      {        "slot": "body",        "column": "body"      },      {        "slot": "date",        "column": "created_at",        "form": "relative"      }    ]  },  "parts": {    "shape": "desk",    "head": {      "facts": [        "created_at"      ]    },    "links": [],    "body": "body",    "lists": [],    "acts": {      "more": [        "open-superseded-by"      ]    },    "cards": [      {        "column": "status"      },      {        "column": "slug"      },      {        "column": "origin_label"      },      {        "column": "reviewed_at"      }    ],    "strip": []  },  "groups": {    "stack": "slips"  }}