930 lines · 25.5 KB · JSONRaw
{ "format_version": 1, "id": "document", "name": "Document", "plural": "Documents", "record_route": "/documents/document/[id]", "picture": {"photo": "photo:e1f1afc03a39eee6facd9c74b47b0eb62bf0d48378636a2e0cd0d363a5ba4ad3", "object": "tool-documents"}, "builtin": true, "links": [ { "label": "Deleted", "table": "bin", "where": { "table": "document" } } ], "deletion": { "bin": true }, "engine": "documents", "takes_files": true, "columns": [ { "key": "title", "type": "text", "readonly": false }, { "key": "original_name", "name": "File name", "type": "text", "readonly": true }, { "key": "storage_path", "name": "File", "type": "file", "presentation": "file", "readonly": true }, { "key": "byte_size", "name": "Size", "type": "number", "readonly": true, "format": "bytes" }, { "key": "page_count", "name": "Pages", "type": "number", "readonly": true }, { "key": "status", "type": "choice", "choices": [ "processing", "summarizing", "ready", "locked", "failed" ], "readonly": true, "labels": { "processing": "Being read", "summarizing": "Being summarised", "ready": "Ready", "locked": "Locked — needs its password", "failed": "Could not be read" } }, { "key": "failed_stage", "name": "Failed at", "type": "choice", "choices": [ "unlock", "extract", "summarize", "land" ], "readonly": true }, { "key": "error_code", "name": "Problem", "type": "text", "readonly": true }, { "key": "doc_type", "name": "Kind", "type": "choice", "choices": [ "bank_statement", "card_statement", "invoice", "receipt", "tax", "id", "insurance", "medical", "legal", "ticket", "statement_other", "letter", "manual", "other" ], "readonly": true, "labels": { "bank_statement": "Bank statement", "card_statement": "Card statement", "invoice": "Invoice", "receipt": "Receipt", "tax": "Tax", "id": "ID", "insurance": "Insurance", "medical": "Medical", "legal": "Legal", "ticket": "Ticket", "statement_other": "Statement", "letter": "Letter", "manual": "Manual", "other": "Other" } }, { "key": "document_date", "name": "Dated", "type": "date", "readonly": true }, { "key": "period_start", "name": "Covers from", "type": "date", "readonly": true }, { "key": "period_end", "name": "Covers to", "type": "date", "readonly": true }, { "key": "issuer", "name": "From", "type": "text", "readonly": true }, { "key": "summary", "name": "Reading", "type": "longtext", "readonly": true }, { "key": "source", "name": "Added from", "type": "choice", "choices": [ "app", "agent", "share" ], "readonly": true, "labels": { "app": "This app", "agent": "An assistant", "share": "Shared in" } }, { "key": "created_at", "name": "Added", "type": "date", "readonly": true }, { "key": "secret_id", "name": "Password", "type": "link", "link_to": "secret", "readonly": true }, { "key": "statement_id", "name": "Statement", "type": "link", "link_to": "statement", "readonly": true }, { "key": "pages_text", "type": "longtext", "readonly": true, "name": "Pages" }, { "key": "facts", "type": "longtext", "readonly": true, "name": "Facts" }, { "key": "state_message", "type": "longtext", "readonly": true, "name": "Reading status" }, { "key": "type_line", "type": "text", "readonly": true, "name": "Kind and date" }, { "key": "page_line", "type": "text", "readonly": true, "name": "Pages" }, { "key": "provenance", "type": "text", "readonly": true, "name": "Added" }, { "key": "period_years", "type": "text", "readonly": true, "name": "Year" }, { "key": "projects", "name": "Project", "type": "link", "link_to": "project" }, { "key": "people", "edges": true, "name": "People", "type": "link", "link_to": "person", "multiple": true, "readonly": true }, { "key": "unlock_password", "type": "text", "name": "File password", "presentation": "password", "shown_when": { "column": "status", "values": [ "locked" ] } } ], "title": "title", "date": "document_date", "project": "projects", "order": null, "layout": "cards", "slip": { "title": "title", "subtitle": [ "doc_type", "issuer" ], "trailing": "document_date", "photo": null, "toggle": null, "status": "state_message", "edge": "receipt" }, "viewer": {}, "tile": { "face": "cover-grid" }, "page": [ { "heading": null, "columns": [ "title", "storage_path", "original_name", "status", "state_message" ] }, { "heading": "Facts", "columns": [ "facts", "doc_type", "statement_id", "issuer", "document_date", "period_start", "period_end", "page_count", "byte_size" ] }, { "heading": "Cotton’s reading", "columns": [ "summary" ] }, { "heading": "Pages", "columns": [ "pages_text" ] }, { "heading": "Password", "columns": [ "unlock_password", "secret_id" ] }, { "heading": "Source", "columns": [ "provenance", "source", "created_at", "projects" ] } ], "sort": { "column": "created_at", "descending": true }, "instructions": "A document is a filed file, usually a PDF, with what was read from it: its kind, issuer, dates and a short summary. A locked document needs its password before it can be read, and that password is kept as a password record, never in the document. Use the dated day or the covered period exactly as printed; never guess them. Engine projection must omit protected page text and a drawable file reference while locked without a decrypted rendition. File replacement/upload invokes existing Rust document intake through the file-column editor. unlock_password is a write-only engine input; never project/store its plaintext in a document. Facts keeps all extracted amounts/account/people fields as readable labelled lines. period_years is a list of every covered year. Title retains original-name fallback; type_line waits for a ready, non-other classification.", "commands": [ { "id": "statement", "label": "Open", "kind": "open", "opens": "statement_id" }, { "id": "delete", "label": "Delete", "kind": "delete", "verb": "delete_record", "data": { "table": "document" }, "bindings": { "id": "$id" }, "when": { "statement_id": null }, "confirm": "Undo on the receipt brings it back.", "receipt": "Deleted", "does": "destroys" } ], "add": false, "cover": { "footer": [ "type_line", "page_line", "state_message" ] }, "create": { "label": "Add document", "path": "/documents/import" }, "empty": { "title": "No documents yet.", "message": "Add a bill, a statement, an ID or a letter — its file, or a photograph of the paper." }, "groups": { "stack": "covers" }, "parts": { "shape": "desk", "head": { "facts": [] }, "links": [], "body": "facts", "lists": [], "acts": { "more": [ "statement" ], "away": "delete" }, "strip": [ { "column": "summary" }, { "column": "issuer" }, { "column": "document_date" }, { "column": "status", "when": { "column": "status", "values": [ "processing", "summarizing", "locked", "failed" ] } }, { "column": "state_message", "when": { "column": "status", "values": [ "processing", "summarizing", "locked", "failed" ] } }, { "column": "unlock_password" }, { "column": "period_start", "until": "period_end" } ] }, "tool": { "name": "Documents", "key": "documents", "icon": "file-text", "card_stock": "cream", "route": "/documents", "figures": [ { "read": "lockedDocuments", "one": "1 needs a password", "many": "{n} need a password" } ] ,"purpose":"Your files and the information inside them."}, "tables": [ { "name": "cotton_document_pages", "columns": [ { "name": "id", "type": "TEXT", "default": null, "nullable": true, "primary_key": true, "declaration": "\n id TEXT PRIMARY KEY", "position": 0 }, { "name": "document_id", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n document_id TEXT NOT NULL", "position": 1 }, { "name": "workspace_id", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n workspace_id TEXT NOT NULL", "position": 2 }, { "name": "page", "type": "INTEGER", "default": null, "nullable": false, "primary_key": false, "declaration": "\n page INTEGER NOT NULL", "position": 3 }, { "name": "text", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n text TEXT NOT NULL", "position": 4 }, { "name": "created_at", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n created_at TEXT NOT NULL", "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 (document_id, page)", "position": 8 }, { "declaration": "\n CHECK (page >= 1)", "position": 9 }, { "declaration": "\n FOREIGN KEY (document_id) REFERENCES cotton_documents(id)", "position": 10 }, { "declaration": "\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n ", "position": 11 } ], "prefix": "CREATE TABLE cotton_document_pages (", "suffix": ")", "indexes": [ "CREATE INDEX idx_cotton_document_pages_workspace ON cotton_document_pages (workspace_id)", "CREATE INDEX IF NOT EXISTS idx_cotton_document_pages_author ON cotton_document_pages (substr(_hlc, 20), _hlc)" ], "full_text": [ "CREATE VIRTUAL TABLE fts_document_pages USING fts5(\n text, content = 'cotton_document_pages', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" ], "triggers": [ "CREATE TRIGGER fts_document_pages_ai AFTER INSERT ON cotton_document_pages WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_document_pages'), 0) BEGIN\n INSERT INTO fts_document_pages (rowid, text) VALUES (new.rowid, new.text);\n END", "CREATE TRIGGER fts_document_pages_ad AFTER DELETE ON cotton_document_pages WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_document_pages'), 0) BEGIN\n INSERT INTO fts_document_pages (fts_document_pages, rowid, text) VALUES ('delete', old.rowid, old.text);\n END", "CREATE TRIGGER fts_document_pages_au AFTER UPDATE OF text ON cotton_document_pages\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_document_pages'), 0) AND (new.text IS NOT old.text) BEGIN\n INSERT INTO fts_document_pages (fts_document_pages, rowid, text) VALUES ('delete', old.rowid, old.text);\n INSERT INTO fts_document_pages (rowid, text) VALUES (new.rowid, new.text);\n END" ] }, { "name": "cotton_documents", "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": "title", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n title TEXT", "position": 2 }, { "name": "original_name", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n original_name TEXT NOT NULL", "position": 3 }, { "name": "mime", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n mime TEXT NOT NULL", "position": 4 }, { "name": "byte_size", "type": "INTEGER", "default": null, "nullable": false, "primary_key": false, "declaration": "\n byte_size INTEGER NOT NULL", "position": 5 }, { "name": "sha256", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n sha256 TEXT NOT NULL", "position": 6 }, { "name": "storage_path", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n storage_path TEXT NOT NULL", "position": 7 }, { "name": "decrypted_path", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n decrypted_path TEXT", "position": 8 }, { "name": "password", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n password TEXT", "position": 9 }, { "name": "page_count", "type": "INTEGER", "default": null, "nullable": true, "primary_key": false, "declaration": "\n page_count INTEGER", "position": 10 }, { "name": "status", "type": "TEXT", "default": "'processing'", "nullable": false, "primary_key": false, "declaration": "\n status TEXT NOT NULL DEFAULT 'processing'", "position": 11 }, { "name": "failed_stage", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n failed_stage TEXT", "position": 12 }, { "name": "error_code", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n error_code TEXT", "position": 13 }, { "name": "status_changed_at", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n status_changed_at TEXT NOT NULL", "position": 14 }, { "name": "doc_type", "type": "TEXT", "default": "'other'", "nullable": false, "primary_key": false, "declaration": "\n doc_type TEXT NOT NULL DEFAULT 'other'", "position": 15 }, { "name": "document_date", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n document_date TEXT", "position": 16 }, { "name": "period_start", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n period_start TEXT", "position": 17 }, { "name": "period_end", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n period_end TEXT", "position": 18 }, { "name": "issuer", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n issuer TEXT", "position": 19 }, { "name": "summary", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n summary TEXT", "position": 20 }, { "name": "facts", "type": "TEXT", "default": "'{}'", "nullable": false, "primary_key": false, "declaration": "\n facts TEXT NOT NULL DEFAULT '{}'", "position": 21 }, { "name": "text_extracted", "type": "INTEGER", "default": "0", "nullable": false, "primary_key": false, "declaration": "\n text_extracted INTEGER NOT NULL DEFAULT 0", "position": 22 }, { "name": "source", "type": "TEXT", "default": "'app'", "nullable": false, "primary_key": false, "declaration": "\n source TEXT NOT NULL DEFAULT 'app'", "position": 23 }, { "name": "mcp_token_id", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n mcp_token_id TEXT", "position": 24 }, { "name": "created_at", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n created_at TEXT NOT NULL", "position": 25 }, { "name": "updated_at", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n updated_at TEXT NOT NULL", "position": 26 }, { "name": "_hlc", "type": "TEXT", "default": "''", "nullable": false, "primary_key": false, "declaration": "\n _hlc TEXT NOT NULL DEFAULT ''", "position": 27 }, { "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": 28 }, { "name": "secret_id", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": " secret_id TEXT", "position": 29 }, { "name": "_born", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n _born TEXT", "position": 30 }, { "name": "trashed_at", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n trashed_at TEXT", "position": 31 } ], "constraints": [ { "declaration": "\n UNIQUE (workspace_id, sha256)", "position": 32 }, { "declaration": "\n CHECK (byte_size >= 0)", "position": 33 }, { "declaration": "\n CHECK (doc_type IN ('bank_statement', 'card_statement', 'invoice', 'receipt', 'tax', 'id', 'insurance', 'medical', 'legal', 'ticket', 'statement_other', 'letter', 'manual', 'other'))", "position": 34 }, { "declaration": "\n CHECK ((status = 'failed') = (failed_stage IS NOT NULL))", "position": 35 }, { "declaration": "\n CHECK (failed_stage IS NULL OR failed_stage IN ('unlock', 'extract', 'summarize', 'land'))", "position": 36 }, { "declaration": "\n CHECK ((page_count IS NULL) OR (page_count >= 0))", "position": 37 }, { "declaration": "\n CHECK ((period_start IS NULL) OR (period_end IS NULL) OR (period_end >= period_start))", "position": 38 }, { "declaration": "\n CHECK (length(sha256) = 64 AND NOT sha256 GLOB '*[^0-9a-f]*')", "position": 39 }, { "declaration": "\n CHECK (source IN ('app', 'agent', 'share'))", "position": 40 }, { "declaration": "\n CHECK (status IN ('processing', 'summarizing', 'ready', 'locked', 'failed'))", "position": 41 }, { "declaration": "\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n ", "position": 42 } ], "prefix": "CREATE TABLE \"cotton_documents\" (", "suffix": ")", "indexes": [ "CREATE INDEX idx_cotton_documents_pipeline ON cotton_documents (status, status_changed_at) WHERE status IN ('processing', 'summarizing')", "CREATE INDEX idx_cotton_documents_type ON cotton_documents (workspace_id, doc_type)", "CREATE INDEX idx_cotton_documents_workspace_date ON cotton_documents (workspace_id, document_date DESC, created_at DESC)", "CREATE INDEX idx_cotton_documents_origin ON cotton_documents (origin_handle) WHERE origin_handle IS NOT NULL", "CREATE INDEX IF NOT EXISTS idx_cotton_documents_author ON cotton_documents (substr(_hlc, 20), _hlc)" ], "full_text": [ "CREATE VIRTUAL TABLE fts_documents USING fts5(\n title, issuer, summary, original_name, content = 'cotton_documents', content_rowid = 'rowid',\n tokenize = 'unicode61 remove_diacritics 2'\n )" ], "triggers": [ "CREATE TRIGGER fts_documents_ai AFTER INSERT ON cotton_documents WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_documents'), 0) BEGIN\n INSERT INTO fts_documents (rowid, title, issuer, summary, original_name) VALUES (new.rowid, new.title, new.issuer, new.summary, new.original_name);\n END", "CREATE TRIGGER fts_documents_ad AFTER DELETE ON cotton_documents WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_documents'), 0) BEGIN\n INSERT INTO fts_documents (fts_documents, rowid, title, issuer, summary, original_name) VALUES ('delete', old.rowid, old.title, old.issuer, old.summary, old.original_name);\n END", "CREATE TRIGGER fts_documents_au AFTER UPDATE OF title, issuer, summary, original_name ON cotton_documents\n FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_documents'), 0) AND (new.title IS NOT old.title OR new.issuer IS NOT old.issuer OR new.summary IS NOT old.summary OR new.original_name IS NOT old.original_name) BEGIN\n INSERT INTO fts_documents (fts_documents, rowid, title, issuer, summary, original_name) VALUES ('delete', old.rowid, old.title, old.issuer, old.summary, old.original_name);\n INSERT INTO fts_documents (rowid, title, issuer, summary, original_name) VALUES (new.rowid, new.title, new.issuer, new.summary, new.original_name);\n END" ] } ]}