Cotton code
245 lines · 6.8 KB · JSONRaw
{  "format_version": 1,  "id": "prompt",  "name": "Prompt",  "plural": "Prompts",  "picture": null,  "builtin": true,  "delete": false,  "engine": "sessions",  "columns": [    {      "key": "session_id",      "name": "Session",      "type": "link",      "link_to": "session",      "readonly": true    },    {      "key": "project_id",      "name": "Project",      "type": "link",      "link_to": "project",      "readonly": true    },    {      "key": "seq",      "name": "Turn",      "type": "number",      "readonly": true    },    {      "key": "ts",      "name": "At",      "type": "date",      "readonly": true    },    {  "key": "role",  "type": "choice",  "choices": [    "user",    "assistant"  ],  "readonly": true,  "labels": {    "user": "You",    "assistant": "Assistant"  }},    {      "key": "text",      "type": "longtext",      "required": true,      "markdown": true,      "readonly": true    }  ],  "title": "text",  "date": "ts",  "project": "project_id",  "order": null,  "slip": {    "title": "text",    "subtitle": "role",    "trailing": "ts",    "photo": null,    "toggle": null  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "text"      ]    },    {      "heading": "Details",      "columns": [        "role",        "ts",        "seq",        "session_id",        "project_id"      ]    }  ],  "instructions": "A prompt is one turn of a coding session's transcript, from the person or the assistant, in transcript order. Prompts are redacted before they are stored, so never try to restore removed text.",  "add": false,  "tables": [    {      "name": "cotton_prompts",      "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": "session_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    session_id TEXT NOT NULL",          "position": 2        },        {          "name": "project_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    project_id TEXT",          "position": 3        },        {          "name": "seq",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    seq INTEGER NOT NULL",          "position": 4        },        {          "name": "ts",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    ts TEXT NOT NULL",          "position": 5        },        {          "name": "text",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    text TEXT NOT NULL",          "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": "role",          "type": "TEXT",          "default": "'user'",          "nullable": false,          "primary_key": false,          "declaration": " role TEXT NOT NULL DEFAULT 'user' CHECK (role IN ('user', 'assistant'))",          "position": 10        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 11        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (session_id, seq)",          "position": 12        },        {          "declaration": "\n    CHECK (seq >= 0)",          "position": 13        },        {          "declaration": "\n    CHECK ((length(trim(text)) > 0) AND (length(text) <= 8000))",          "position": 14        },        {          "declaration": "\n    FOREIGN KEY (session_id) REFERENCES cotton_sessions(id)",          "position": 15        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 16        }      ],      "prefix": "CREATE TABLE cotton_prompts (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_prompts_workspace ON cotton_prompts (workspace_id)",        "CREATE INDEX idx_cotton_prompts_session ON cotton_prompts (workspace_id, session_id, seq)",        "CREATE INDEX IF NOT EXISTS idx_cotton_prompts_author ON cotton_prompts (substr(_hlc, 20), _hlc)"      ],      "full_text": [        "CREATE VIRTUAL TABLE fts_prompts USING fts5(\n       text, content = 'cotton_prompts', content_rowid = 'rowid',\n       tokenize = 'unicode61 remove_diacritics 2'\n     )"      ],      "triggers": [        "CREATE TRIGGER fts_prompts_ai AFTER INSERT ON cotton_prompts WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_prompts'), 0) BEGIN\n       INSERT INTO fts_prompts (rowid, text) VALUES (new.rowid, new.text);\n     END",        "CREATE TRIGGER fts_prompts_ad AFTER DELETE ON cotton_prompts WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_prompts'), 0) BEGIN\n       INSERT INTO fts_prompts (fts_prompts, rowid, text) VALUES ('delete', old.rowid, old.text);\n     END",        "CREATE TRIGGER fts_prompts_au AFTER UPDATE OF text ON cotton_prompts\n       FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_prompts'), 0) AND (new.text IS NOT old.text) BEGIN\n       INSERT INTO fts_prompts (fts_prompts, rowid, text) VALUES ('delete', old.rowid, old.text);\n       INSERT INTO fts_prompts (rowid, text) VALUES (new.rowid, new.text);\n     END"      ]    }  ]}