Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

perf(desktop): 减轻超大 messages 库上的写路径卡顿 (#3386)

Dash487f42fe3d84
diff --git a/apps/desktop/drizzle/0095_scope_messages_fts_update_trigger.sql b/apps/desktop/drizzle/0095_scope_messages_fts_update_trigger.sql
new file mode 100644
index 0000000000..e0ac49d1ec
--- /dev/null
+++ b/apps/desktop/drizzle/0095_scope_messages_fts_update_trigger.sql
@@ -0,0 +1 @@
+SELECT 1;
diff --git a/apps/desktop/drizzle/meta/0095_snapshot.json b/apps/desktop/drizzle/meta/0095_snapshot.json
new file mode 100644
index 0000000000..b935b424b7
--- /dev/null
+++ b/apps/desktop/drizzle/meta/0095_snapshot.json
@@ -0,0 +1,4385 @@
+{
+ "id": "90063e36-1470-45d3-84d6-4bb6139dd4a5",
+ "prevId": "270033b2-a162-45d5-88a7-0d8bc92d6a95",
+ "version": "6",
+ "dialect": "sqlite",
+ "tables": {
+ "account_usage_snapshots": {
+ "name": "account_usage_snapshots",
+ "columns": {
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "snapshot": {
+ "name": "snapshot",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "agent_input_queue_snapshots": {
+ "name": "agent_input_queue_snapshots",
+ "columns": {
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "payload": {
+ "name": "payload",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "agent_input_queue_snapshots_session_id_sessions_id_fk": {
+ "name": "agent_input_queue_snapshots_session_id_sessions_id_fk",
+ "tableFrom": "agent_input_queue_snapshots",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "custom_mcp_servers": {
+ "name": "custom_mcp_servers",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "transport": {
+ "name": "transport",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "headers": {
+ "name": "headers",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "sort_order": {
+ "name": "sort_order",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_custom_mcp_servers_sort_order": {
+ "name": "idx_custom_mcp_servers_sort_order",
+ "columns": [
+ "sort_order"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "custom_providers": {
+ "name": "custom_providers",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "runtimes": {
+ "name": "runtimes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "auth": {
+ "name": "auth",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "sort_order": {
+ "name": "sort_order",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_custom_providers_sort_order": {
+ "name": "idx_custom_providers_sort_order",
+ "columns": [
+ "sort_order"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "daily_model_usage": {
+ "name": "daily_model_usage",
+ "columns": {
+ "day": {
+ "name": "day",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "cost_usd": {
+ "name": "cost_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_amount": {
+ "name": "cost_amount",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_currency": {
+ "name": "cost_currency",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'USD'"
+ },
+ "cost_is_approximate": {
+ "name": "cost_is_approximate",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "input_tokens": {
+ "name": "input_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "output_tokens": {
+ "name": "output_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cache_read_tokens": {
+ "name": "cache_read_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cache_create_tokens": {
+ "name": "cache_create_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "daily_model_usage_day_agent_kind_model_cost_currency_pk": {
+ "columns": [
+ "day",
+ "agent_kind",
+ "model",
+ "cost_currency"
+ ],
+ "name": "daily_model_usage_day_agent_kind_model_cost_currency_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "daily_spend": {
+ "name": "daily_spend",
+ "columns": {
+ "day": {
+ "name": "day",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "cost_usd": {
+ "name": "cost_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_amount": {
+ "name": "cost_amount",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_currency": {
+ "name": "cost_currency",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'USD'"
+ },
+ "cost_is_approximate": {
+ "name": "cost_is_approximate",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "daily_spend_day_cost_currency_pk": {
+ "columns": [
+ "day",
+ "cost_currency"
+ ],
+ "name": "daily_spend_day_cost_currency_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "device_link_ownership": {
+ "name": "device_link_ownership",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "owner_id": {
+ "name": "owner_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "owner_pid": {
+ "name": "owner_pid",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "owner_label": {
+ "name": "owner_label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "heartbeat_at": {
+ "name": "heartbeat_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "embedding_jobs": {
+ "name": "embedding_jobs",
+ "columns": {
+ "rowid": {
+ "name": "rowid",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "source_id": {
+ "name": "source_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chunk_index": {
+ "name": "chunk_index",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "model_id": {
+ "name": "model_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "vec_table": {
+ "name": "vec_table",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "last_error": {
+ "name": "last_error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "scheduled_at": {
+ "name": "scheduled_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "locked_at": {
+ "name": "locked_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_embedding_jobs_natural": {
+ "name": "uniq_embedding_jobs_natural",
+ "columns": [
+ "source",
+ "source_id",
+ "chunk_index",
+ "model_id"
+ ],
+ "isUnique": true
+ },
+ "idx_embedding_jobs_status_scheduled": {
+ "name": "idx_embedding_jobs_status_scheduled",
+ "columns": [
+ "status",
+ "scheduled_at"
+ ],
+ "isUnique": false
+ },
+ "idx_embedding_jobs_source_id": {
+ "name": "idx_embedding_jobs_source_id",
+ "columns": [
+ "source",
+ "source_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "embedding_meta": {
+ "name": "embedding_meta",
+ "columns": {
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "ghost_cards": {
+ "name": "ghost_cards",
+ "columns": {
+ "call_id": {
+ "name": "call_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ghost_id": {
+ "name": "ghost_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "html": {
+ "name": "html",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "height": {
+ "name": "height",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "v": {
+ "name": "v",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "ghost_cards_updated_at_idx": {
+ "name": "ghost_cards_updated_at_idx",
+ "columns": [
+ "updated_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "hook_group_context_cursors": {
+ "name": "hook_group_context_cursors",
+ "columns": {
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "cursor_key": {
+ "name": "cursor_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "cursor_id": {
+ "name": "cursor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "hook_group_context_cursors_updated_at_idx": {
+ "name": "hook_group_context_cursors_updated_at_idx",
+ "columns": [
+ "updated_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "hook_group_context_cursors_provider_cursor_key_pk": {
+ "columns": [
+ "provider",
+ "cursor_key"
+ ],
+ "name": "hook_group_context_cursors_provider_cursor_key_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "hook_group_message_stats": {
+ "name": "hook_group_message_stats",
+ "columns": {
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "row_count": {
+ "name": "row_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "text_bytes": {
+ "name": "text_bytes",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "hook_group_messages": {
+ "name": "hook_group_messages",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chat_id": {
+ "name": "chat_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "thread_id": {
+ "name": "thread_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "message_id": {
+ "name": "message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chat_name": {
+ "name": "chat_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "author": {
+ "name": "author",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "is_bot": {
+ "name": "is_bot",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "text": {
+ "name": "text",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "file_names": {
+ "name": "file_names",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "sent_at": {
+ "name": "sent_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "hook_group_messages_msg_idx": {
+ "name": "hook_group_messages_msg_idx",
+ "columns": [
+ "provider",
+ "chat_id",
+ "thread_id",
+ "message_id"
+ ],
+ "isUnique": true
+ },
+ "hook_group_messages_window_idx": {
+ "name": "hook_group_messages_window_idx",
+ "columns": [
+ "provider",
+ "chat_id",
+ "thread_id",
+ "id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "im_bindings": {
+ "name": "im_bindings",
+ "columns": {
+ "channel": {
+ "name": "channel",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_context_id": {
+ "name": "bot_context_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "scope_key": {
+ "name": "scope_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "target_session_id": {
+ "name": "target_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "attached_at": {
+ "name": "attached_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "attached_via_card_message_id": {
+ "name": "attached_via_card_message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_im_bindings_target": {
+ "name": "idx_im_bindings_target",
+ "columns": [
+ "target_session_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "im_bindings_target_session_id_sessions_id_fk": {
+ "name": "im_bindings_target_session_id_sessions_id_fk",
+ "tableFrom": "im_bindings",
+ "columnsFrom": [
+ "target_session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {
+ "im_bindings_channel_bot_context_id_user_id_scope_key_pk": {
+ "columns": [
+ "channel",
+ "bot_context_id",
+ "user_id",
+ "scope_key"
+ ],
+ "name": "im_bindings_channel_bot_context_id_user_id_scope_key_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "media_blobs": {
+ "name": "media_blobs",
+ "columns": {
+ "hash": {
+ "name": "hash",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ext": {
+ "name": "ext",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mime_type": {
+ "name": "mime_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bytes": {
+ "name": "bytes",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "is_cache": {
+ "name": "is_cache",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_access_at": {
+ "name": "last_access_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "media_invocations": {
+ "name": "media_invocations",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "owner": {
+ "name": "owner",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "model_id": {
+ "name": "model_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "capability": {
+ "name": "capability",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "guide_revision": {
+ "name": "guide_revision",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "guide_json": {
+ "name": "guide_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "state": {
+ "name": "state",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "response_json": {
+ "name": "response_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "media_invocations_owner_created_at_idx": {
+ "name": "media_invocations_owner_created_at_idx",
+ "columns": [
+ "owner",
+ "created_at"
+ ],
+ "isUnique": false
+ },
+ "media_invocations_owner_state_idx": {
+ "name": "media_invocations_owner_state_idx",
+ "columns": [
+ "owner",
+ "state"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "media_refs": {
+ "name": "media_refs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "hash": {
+ "name": "hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ref_kind": {
+ "name": "ref_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ref_id": {
+ "name": "ref_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "origin_session_id": {
+ "name": "origin_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "origin_kind": {
+ "name": "origin_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "origin_id": {
+ "name": "origin_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "label": {
+ "name": "label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "media_refs_hash_idx": {
+ "name": "media_refs_hash_idx",
+ "columns": [
+ "hash"
+ ],
+ "isUnique": false
+ },
+ "media_refs_ref_idx": {
+ "name": "media_refs_ref_idx",
+ "columns": [
+ "ref_kind",
+ "ref_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "media_refs_hash_media_blobs_hash_fk": {
+ "name": "media_refs_hash_media_blobs_hash_fk",
+ "tableFrom": "media_refs",
+ "columnsFrom": [
+ "hash"
+ ],
+ "tableTo": "media_blobs",
+ "columnsTo": [
+ "hash"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "messages": {
+ "name": "messages",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tool_use_id": {
+ "name": "tool_use_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "agent_meta": {
+ "name": "agent_meta",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "rewind_at": {
+ "name": "rewind_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_messages_session_client": {
+ "name": "uniq_messages_session_client",
+ "columns": [
+ "session_id",
+ "client_id"
+ ],
+ "isUnique": true
+ },
+ "idx_messages_session_created": {
+ "name": "idx_messages_session_created",
+ "columns": [
+ "session_id",
+ "created_at"
+ ],
+ "isUnique": false
+ },
+ "idx_messages_created_at": {
+ "name": "idx_messages_created_at",
+ "columns": [
+ "created_at",
+ "id"
+ ],
+ "isUnique": false
+ },
+ "idx_messages_rewind_at": {
+ "name": "idx_messages_rewind_at",
+ "columns": [
+ "rewind_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "messages_session_id_sessions_id_fk": {
+ "name": "messages_session_id_sessions_id_fk",
+ "tableFrom": "messages",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "migration_history": {
+ "name": "migration_history",
+ "columns": {
+ "seq": {
+ "name": "seq",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "file_name": {
+ "name": "file_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "content_hash": {
+ "name": "content_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "applied_at": {
+ "name": "applied_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "migration_meta": {
+ "name": "migration_meta",
+ "columns": {
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "orca_teams": {
+ "name": "orca_teams",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "lead_session_id": {
+ "name": "lead_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "completed_at": {
+ "name": "completed_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_active_team_per_lead": {
+ "name": "uniq_active_team_per_lead",
+ "columns": [
+ "lead_session_id"
+ ],
+ "where": "\"orca_teams\".\"status\" = 'active'",
+ "isUnique": true
+ },
+ "idx_orca_teams_status": {
+ "name": "idx_orca_teams_status",
+ "columns": [
+ "status"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "orca_teams_lead_session_id_sessions_id_fk": {
+ "name": "orca_teams_lead_session_id_sessions_id_fk",
+ "tableFrom": "orca_teams",
+ "columnsFrom": [
+ "lead_session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "orca_worker_creation_reservations": {
+ "name": "orca_worker_creation_reservations",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "label": {
+ "name": "label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_orca_worker_creation_reservations_team_label": {
+ "name": "uniq_orca_worker_creation_reservations_team_label",
+ "columns": [
+ "team_id",
+ "lower(\"label\")"
+ ],
+ "isUnique": true
+ },
+ "idx_orca_worker_creation_reservations_expires_at": {
+ "name": "idx_orca_worker_creation_reservations_expires_at",
+ "columns": [
+ "expires_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "orca_worker_creation_reservations_team_id_orca_teams_id_fk": {
+ "name": "orca_worker_creation_reservations_team_id_orca_teams_id_fk",
+ "tableFrom": "orca_worker_creation_reservations",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "tableTo": "orca_teams",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "orca_workers": {
+ "name": "orca_workers",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'idle'"
+ },
+ "label": {
+ "name": "label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "worktree_branch": {
+ "name": "worktree_branch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'developer'"
+ },
+ "focused": {
+ "name": "focused",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "idle_since": {
+ "name": "idle_since",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_orca_workers_session_id": {
+ "name": "uniq_orca_workers_session_id",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": true
+ },
+ "uniq_orca_workers_team_label": {
+ "name": "uniq_orca_workers_team_label",
+ "columns": [
+ "team_id",
+ "lower(\"label\")"
+ ],
+ "isUnique": true
+ },
+ "uniq_orca_workers_focused_per_team": {
+ "name": "uniq_orca_workers_focused_per_team",
+ "columns": [
+ "team_id"
+ ],
+ "where": "\"orca_workers\".\"focused\" = true",
+ "isUnique": true
+ },
+ "idx_orca_workers_team_id": {
+ "name": "idx_orca_workers_team_id",
+ "columns": [
+ "team_id"
+ ],
+ "isUnique": false
+ },
+ "idx_orca_workers_status": {
+ "name": "idx_orca_workers_status",
+ "columns": [
+ "status"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "orca_workers_team_id_orca_teams_id_fk": {
+ "name": "orca_workers_team_id_orca_teams_id_fk",
+ "tableFrom": "orca_workers",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "tableTo": "orca_teams",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ },
+ "orca_workers_session_id_sessions_id_fk": {
+ "name": "orca_workers_session_id_sessions_id_fk",
+ "tableFrom": "orca_workers",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "project_aliases": {
+ "name": "project_aliases",
+ "columns": {
+ "project_key": {
+ "name": "project_key",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "alias": {
+ "name": "alias",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_project_aliases_updated_at": {
+ "name": "idx_project_aliases_updated_at",
+ "columns": [
+ "updated_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "project_automation_consents": {
+ "name": "project_automation_consents",
+ "columns": {
+ "working_dir": {
+ "name": "working_dir",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "consented_at": {
+ "name": "consented_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "config_hash": {
+ "name": "config_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "recent_workdirs": {
+ "name": "recent_workdirs",
+ "columns": {
+ "path": {
+ "name": "path",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_used_at": {
+ "name": "last_used_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_recent_workdirs_last_used_at": {
+ "name": "idx_recent_workdirs_last_used_at",
+ "columns": [
+ "last_used_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "right_sidebar_tabs": {
+ "name": "right_sidebar_tabs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "position": {
+ "name": "position",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "is_active": {
+ "name": "is_active",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "state": {
+ "name": "state",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "right_sidebar_tabs_session_idx": {
+ "name": "right_sidebar_tabs_session_idx",
+ "columns": [
+ "session_id",
+ "position"
+ ],
+ "isUnique": false
+ },
+ "right_sidebar_tabs_subagents_singleton_idx": {
+ "name": "right_sidebar_tabs_subagents_singleton_idx",
+ "columns": [
+ "session_id"
+ ],
+ "where": "\"right_sidebar_tabs\".\"kind\" = 'subagents'",
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "right_sidebar_tabs_session_id_sessions_id_fk": {
+ "name": "right_sidebar_tabs_session_id_sessions_id_fk",
+ "tableFrom": "right_sidebar_tabs",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "schedule_runs": {
+ "name": "schedule_runs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "schedule_id": {
+ "name": "schedule_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "fired_at": {
+ "name": "fired_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "finished_at": {
+ "name": "finished_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "error_msg": {
+ "name": "error_msg",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "cost_usd": {
+ "name": "cost_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "estimated_value_usd": {
+ "name": "estimated_value_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_amount": {
+ "name": "cost_amount",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "estimated_value_amount": {
+ "name": "estimated_value_amount",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_currency": {
+ "name": "cost_currency",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "cost_is_approximate": {
+ "name": "cost_is_approximate",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "cost_attribution": {
+ "name": "cost_attribution",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'legacy'"
+ },
+ "result_text": {
+ "name": "result_text",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "pre_run_hook_result": {
+ "name": "pre_run_hook_result",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "read_at": {
+ "name": "read_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "heartbeat_at": {
+ "name": "heartbeat_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_schedule_runs_schedule": {
+ "name": "idx_schedule_runs_schedule",
+ "columns": [
+ "schedule_id",
+ "fired_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "schedule_runs_schedule_id_schedules_id_fk": {
+ "name": "schedule_runs_schedule_id_schedules_id_fk",
+ "tableFrom": "schedule_runs",
+ "columnsFrom": [
+ "schedule_id"
+ ],
+ "tableTo": "schedules",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ },
+ "schedule_runs_session_id_sessions_id_fk": {
+ "name": "schedule_runs_session_id_sessions_id_fk",
+ "tableFrom": "schedule_runs",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "set null"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "schedules": {
+ "name": "schedules",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "prompt": {
+ "name": "prompt",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "job_type": {
+ "name": "job_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'prompt'"
+ },
+ "job_config": {
+ "name": "job_config",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "execution_mode": {
+ "name": "execution_mode",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'agent'"
+ },
+ "script_config": {
+ "name": "script_config",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'user'"
+ },
+ "project_config_id": {
+ "name": "project_config_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "legacy_session_fallback": {
+ "name": "legacy_session_fallback",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'cron'"
+ },
+ "cron_expr": {
+ "name": "cron_expr",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "timezone": {
+ "name": "timezone",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "recurring": {
+ "name": "recurring",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ },
+ "manual": {
+ "name": "manual",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "interval_ms": {
+ "name": "interval_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "provider_id": {
+ "name": "provider_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "effort": {
+ "name": "effort",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "fast_mode": {
+ "name": "fast_mode",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "working_dir": {
+ "name": "working_dir",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "workspace_kind": {
+ "name": "workspace_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'project'"
+ },
+ "use_worktree": {
+ "name": "use_worktree",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "target_session_id": {
+ "name": "target_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "persistent_session": {
+ "name": "persistent_session",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "silent_when_idle": {
+ "name": "silent_when_idle",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "pre_run_hook_command": {
+ "name": "pre_run_hook_command",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "pre_run_hook_timeout_ms": {
+ "name": "pre_run_hook_timeout_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "skip_log_session_id": {
+ "name": "skip_log_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "notify_desktop": {
+ "name": "notify_desktop",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ },
+ "notify_feishu": {
+ "name": "notify_feishu",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "notify_wecom_group": {
+ "name": "notify_wecom_group",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_fired_at": {
+ "name": "last_fired_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_finished_at": {
+ "name": "last_finished_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "next_fire_at": {
+ "name": "next_fire_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "expire_at": {
+ "name": "expire_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_schedules_active_next": {
+ "name": "idx_schedules_active_next",
+ "columns": [
+ "status",
+ "next_fire_at"
+ ],
+ "isUnique": false
+ },
+ "idx_schedules_target_session": {
+ "name": "idx_schedules_target_session",
+ "columns": [
+ "target_session_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "schedules_target_session_id_sessions_id_fk": {
+ "name": "schedules_target_session_id_sessions_id_fk",
+ "tableFrom": "schedules",
+ "columnsFrom": [
+ "target_session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "set null"
+ },
+ "schedules_skip_log_session_id_sessions_id_fk": {
+ "name": "schedules_skip_log_session_id_sessions_id_fk",
+ "tableFrom": "schedules",
+ "columnsFrom": [
+ "skip_log_session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "set null"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "session_goals": {
+ "name": "session_goals",
+ "columns": {
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "objective": {
+ "name": "objective",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "budget_tokens": {
+ "name": "budget_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "max_turns": {
+ "name": "max_turns",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "no_progress_limit": {
+ "name": "no_progress_limit",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "turns_used": {
+ "name": "turns_used",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "tokens_used": {
+ "name": "tokens_used",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "no_progress_streak": {
+ "name": "no_progress_streak",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "usage_reset_at": {
+ "name": "usage_reset_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_reason": {
+ "name": "last_reason",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "started_at": {
+ "name": "started_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_session_goals_status": {
+ "name": "idx_session_goals_status",
+ "columns": [
+ "status"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "session_goals_session_id_sessions_id_fk": {
+ "name": "session_goals_session_id_sessions_id_fk",
+ "tableFrom": "session_goals",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "session_pr_refs": {
+ "name": "session_pr_refs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "owner": {
+ "name": "owner",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "repo": {
+ "name": "repo",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "pr_number": {
+ "name": "pr_number",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "first_seen_at": {
+ "name": "first_seen_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_seen_at": {
+ "name": "last_seen_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_session_pr_refs": {
+ "name": "uniq_session_pr_refs",
+ "columns": [
+ "session_id",
+ "owner",
+ "repo",
+ "pr_number"
+ ],
+ "isUnique": true
+ },
+ "idx_session_pr_refs_session_last_seen": {
+ "name": "idx_session_pr_refs_session_last_seen",
+ "columns": [
+ "session_id",
+ "last_seen_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "session_pr_refs_session_id_sessions_id_fk": {
+ "name": "session_pr_refs_session_id_sessions_id_fk",
+ "tableFrom": "session_pr_refs",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "sessions": {
+ "name": "sessions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'New Maker'"
+ },
+ "working_dir": {
+ "name": "working_dir",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "workspace_kind": {
+ "name": "workspace_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'project'"
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'claude-sonnet-4-6'"
+ },
+ "effort": {
+ "name": "effort",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'high'"
+ },
+ "permission_mode": {
+ "name": "permission_mode",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'ask'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "sdk_session_id": {
+ "name": "sdk_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "total_token_usage": {
+ "name": "total_token_usage",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "total_cost_usd": {
+ "name": "total_cost_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "total_cost_amount": {
+ "name": "total_cost_amount",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "total_cost_currency": {
+ "name": "total_cost_currency",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "total_cost_is_approximate": {
+ "name": "total_cost_is_approximate",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "context_tokens": {
+ "name": "context_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "context_window": {
+ "name": "context_window",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "fast_mode": {
+ "name": "fast_mode",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "plan_mode_enabled": {
+ "name": "plan_mode_enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "cleared_at": {
+ "name": "cleared_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "pinned_at": {
+ "name": "pinned_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "summary": {
+ "name": "summary",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "provider_id": {
+ "name": "provider_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "user_send_at": {
+ "name": "user_send_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'cc'"
+ },
+ "orca_role": {
+ "name": "orca_role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "parent_session_id": {
+ "name": "parent_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "forked_at_message_id": {
+ "name": "forked_at_message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "worktree_path": {
+ "name": "worktree_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'desktop'"
+ },
+ "feishu_open_id": {
+ "name": "feishu_open_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "feishu_bot_app_id": {
+ "name": "feishu_bot_app_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "im_bot_context_id": {
+ "name": "im_bot_context_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "im_user_id": {
+ "name": "im_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "used_project_context": {
+ "name": "used_project_context",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "codex_history_has_product_prompt": {
+ "name": "codex_history_has_product_prompt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "codex_plan_json": {
+ "name": "codex_plan_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "extra_dirs": {
+ "name": "extra_dirs",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "remote_host_id": {
+ "name": "remote_host_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "active_turn_started_at": {
+ "name": "active_turn_started_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "active_turn_pid": {
+ "name": "active_turn_pid",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_turn_ended_at": {
+ "name": "last_turn_ended_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_sessions_updated_at": {
+ "name": "idx_sessions_updated_at",
+ "columns": [
+ "updated_at"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_user_send_at": {
+ "name": "idx_sessions_user_send_at",
+ "columns": [
+ "user_send_at"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_sdk_session_id": {
+ "name": "idx_sessions_sdk_session_id",
+ "columns": [
+ "sdk_session_id"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_workdir_created": {
+ "name": "idx_sessions_workdir_created",
+ "columns": [
+ "working_dir",
+ "created_at",
+ "id"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_created_at": {
+ "name": "idx_sessions_created_at",
+ "columns": [
+ "created_at",
+ "id"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_workspace_kind": {
+ "name": "idx_sessions_workspace_kind",
+ "columns": [
+ "workspace_kind"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_parent_session_id": {
+ "name": "idx_sessions_parent_session_id",
+ "columns": [
+ "parent_session_id"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_orca_role": {
+ "name": "idx_sessions_orca_role",
+ "columns": [
+ "orca_role"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_worktree_path": {
+ "name": "idx_sessions_worktree_path",
+ "columns": [
+ "worktree_path"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_feishu_lookup": {
+ "name": "idx_sessions_feishu_lookup",
+ "columns": [
+ "source",
+ "feishu_bot_app_id",
+ "feishu_open_id"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_im_lookup": {
+ "name": "idx_sessions_im_lookup",
+ "columns": [
+ "source",
+ "im_bot_context_id",
+ "im_user_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "sessions_parent_session_id_sessions_id_fk": {
+ "name": "sessions_parent_session_id_sessions_id_fk",
+ "tableFrom": "sessions",
+ "columnsFrom": [
+ "parent_session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "set null"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "skill_usage_exposures": {
+ "name": "skill_usage_exposures",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "analyzer_version": {
+ "name": "analyzer_version",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'6'"
+ },
+ "raw_file_path": {
+ "name": "raw_file_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "raw_line_no": {
+ "name": "raw_line_no",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sdk_session_id": {
+ "name": "sdk_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "skill_name": {
+ "name": "skill_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "skill_path": {
+ "name": "skill_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "skill_document_hash": {
+ "name": "skill_document_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "exposure_content_hash": {
+ "name": "exposure_content_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "document_hash_source": {
+ "name": "document_hash_source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tool_use_id": {
+ "name": "tool_use_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "seen_at": {
+ "name": "seen_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tool_call_count": {
+ "name": "tool_call_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "repeated_tool_call_count": {
+ "name": "repeated_tool_call_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "tool_error_count": {
+ "name": "tool_error_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "command_call_count": {
+ "name": "command_call_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "command_failure_count": {
+ "name": "command_failure_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ }
+ },
+ "indexes": {
+ "idx_skill_usage_exposures_skill_document_version": {
+ "name": "idx_skill_usage_exposures_skill_document_version",
+ "columns": [
+ "analyzer_version",
+ "skill_name",
+ "skill_document_hash"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_exposures_session": {
+ "name": "idx_skill_usage_exposures_session",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_exposures_raw_file": {
+ "name": "idx_skill_usage_exposures_raw_file",
+ "columns": [
+ "raw_file_path"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "skill_usage_exposures_raw_file_path_skill_usage_sources_raw_file_path_fk": {
+ "name": "skill_usage_exposures_raw_file_path_skill_usage_sources_raw_file_path_fk",
+ "tableFrom": "skill_usage_exposures",
+ "columnsFrom": [
+ "raw_file_path"
+ ],
+ "tableTo": "skill_usage_sources",
+ "columnsTo": [
+ "raw_file_path"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "skill_usage_sources": {
+ "name": "skill_usage_sources",
+ "columns": {
+ "raw_file_path": {
+ "name": "raw_file_path",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "analyzer_version": {
+ "name": "analyzer_version",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'6'"
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sdk_session_id": {
+ "name": "sdk_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mtime_ms": {
+ "name": "mtime_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "size_bytes": {
+ "name": "size_bytes",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "last_scanned_at": {
+ "name": "last_scanned_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'ok'"
+ },
+ "error": {
+ "name": "error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_skill_usage_sources_session": {
+ "name": "idx_skill_usage_sources_session",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_sources_sdk_session": {
+ "name": "idx_skill_usage_sources_sdk_session",
+ "columns": [
+ "sdk_session_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "subagent_run_aliases": {
+ "name": "subagent_run_aliases",
+ "columns": {
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "alias": {
+ "name": "alias",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "run_id": {
+ "name": "run_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "subagent_run_aliases_lookup_idx": {
+ "name": "subagent_run_aliases_lookup_idx",
+ "columns": [
+ "session_id",
+ "provider",
+ "alias",
+ "created_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "subagent_run_aliases_session_id_sessions_id_fk": {
+ "name": "subagent_run_aliases_session_id_sessions_id_fk",
+ "tableFrom": "subagent_run_aliases",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ },
+ "subagent_run_aliases_run_id_subagent_runs_id_fk": {
+ "name": "subagent_run_aliases_run_id_subagent_runs_id_fk",
+ "tableFrom": "subagent_run_aliases",
+ "columnsFrom": [
+ "run_id"
+ ],
+ "tableTo": "subagent_runs",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {
+ "subagent_run_aliases_run_id_alias_pk": {
+ "columns": [
+ "run_id",
+ "alias"
+ ],
+ "name": "subagent_run_aliases_run_id_alias_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "subagent_runs": {
+ "name": "subagent_runs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "logical_agent_id": {
+ "name": "logical_agent_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "parent_tool_use_id": {
+ "name": "parent_tool_use_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "aliases": {
+ "name": "aliases",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "provider_run_ids": {
+ "name": "provider_run_ids",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'running'"
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "summary": {
+ "name": "summary",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "returned_result": {
+ "name": "returned_result",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "returned_result_empty": {
+ "name": "returned_result_empty",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "returned_result_truncated": {
+ "name": "returned_result_truncated",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "reasoning_effort": {
+ "name": "reasoning_effort",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "total_tokens": {
+ "name": "total_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "tool_uses": {
+ "name": "tool_uses",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "duration_ms": {
+ "name": "duration_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "cost_usd": {
+ "name": "cost_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "capabilities": {
+ "name": "capabilities",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "activity": {
+ "name": "activity",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "started_at": {
+ "name": "started_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ended_at": {
+ "name": "ended_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "rewind_at": {
+ "name": "rewind_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "deleted_at": {
+ "name": "deleted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "subagent_runs_logical_idx": {
+ "name": "subagent_runs_logical_idx",
+ "columns": [
+ "session_id",
+ "provider",
+ "logical_agent_id"
+ ],
+ "isUnique": false
+ },
+ "subagent_runs_session_idx": {
+ "name": "subagent_runs_session_idx",
+ "columns": [
+ "session_id",
+ "rewind_at",
+ "deleted_at",
+ "started_at"
+ ],
+ "isUnique": false
+ },
+ "subagent_runs_parent_tool_use_idx": {
+ "name": "subagent_runs_parent_tool_use_idx",
+ "columns": [
+ "session_id",
+ "parent_tool_use_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "subagent_runs_session_id_sessions_id_fk": {
+ "name": "subagent_runs_session_id_sessions_id_fk",
+ "tableFrom": "subagent_runs",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "vec_table_meta": {
+ "name": "vec_table_meta",
+ "columns": {
+ "vec_table": {
+ "name": "vec_table",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "model_id": {
+ "name": "model_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "dim": {
+ "name": "dim",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "registered_at": {
+ "name": "registered_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "notes": {
+ "name": "notes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "wechat_file_attachments": {
+ "name": "wechat_file_attachments",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "binding_epoch": {
+ "name": "binding_epoch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "abs_path": {
+ "name": "abs_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "original_name": {
+ "name": "original_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mime_type": {
+ "name": "mime_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bytes": {
+ "name": "bytes",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'staged'"
+ },
+ "promoted_at": {
+ "name": "promoted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_wechat_file_attachments_task": {
+ "name": "idx_wechat_file_attachments_task",
+ "columns": [
+ "binding_epoch",
+ "task_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "wechat_file_attachments_binding_epoch_wechat_sync_state_binding_epoch_fk": {
+ "name": "wechat_file_attachments_binding_epoch_wechat_sync_state_binding_epoch_fk",
+ "tableFrom": "wechat_file_attachments",
+ "columnsFrom": [
+ "binding_epoch"
+ ],
+ "tableTo": "wechat_sync_state",
+ "columnsTo": [
+ "binding_epoch"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ },
+ "wechat_file_attachments_task_id_wechat_inbox_id_fk": {
+ "name": "wechat_file_attachments_task_id_wechat_inbox_id_fk",
+ "tableFrom": "wechat_file_attachments",
+ "columnsFrom": [
+ "task_id"
+ ],
+ "tableTo": "wechat_inbox",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ },
+ "wechat_file_attachments_session_id_sessions_id_fk": {
+ "name": "wechat_file_attachments_session_id_sessions_id_fk",
+ "tableFrom": "wechat_file_attachments",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "set null"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "wechat_inbox": {
+ "name": "wechat_inbox",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "binding_epoch": {
+ "name": "binding_epoch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "platform_message_id": {
+ "name": "platform_message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "platform_seq": {
+ "name": "platform_seq",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "peer_id": {
+ "name": "peer_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "received_at": {
+ "name": "received_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "platform_created_at": {
+ "name": "platform_created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "lease_until": {
+ "name": "lease_until",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "conversation_epoch": {
+ "name": "conversation_epoch",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "payload_json": {
+ "name": "payload_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "context_nonce": {
+ "name": "context_nonce",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "context_ciphertext": {
+ "name": "context_ciphertext",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "context_tag": {
+ "name": "context_tag",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "last_error_code": {
+ "name": "last_error_code",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_wechat_inbox_platform_message": {
+ "name": "uniq_wechat_inbox_platform_message",
+ "columns": [
+ "binding_epoch",
+ "platform_message_id"
+ ],
+ "isUnique": true
+ },
+ "idx_wechat_inbox_queue": {
+ "name": "idx_wechat_inbox_queue",
+ "columns": [
+ "binding_epoch",
+ "status",
+ "received_at"
+ ],
+ "isUnique": false
+ },
+ "idx_wechat_inbox_lease": {
+ "name": "idx_wechat_inbox_lease",
+ "columns": [
+ "binding_epoch",
+ "lease_until"
+ ],
+ "isUnique": false
+ },
+ "idx_wechat_inbox_conversation": {
+ "name": "idx_wechat_inbox_conversation",
+ "columns": [
+ "binding_epoch",
+ "peer_id",
+ "conversation_epoch"
+ ],
+ "isUnique": false
+ },
+ "uniq_wechat_inbox_running_session": {
+ "name": "uniq_wechat_inbox_running_session",
+ "columns": [
+ "binding_epoch",
+ "session_id"
+ ],
+ "where": "\"wechat_inbox\".\"session_id\" IS NOT NULL AND \"wechat_inbox\".\"status\" IN ('dispatching', 'accepted_running', 'waiting_desktop', 'delivery_pending')",
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "wechat_inbox_binding_epoch_wechat_sync_state_binding_epoch_fk": {
+ "name": "wechat_inbox_binding_epoch_wechat_sync_state_binding_epoch_fk",
+ "tableFrom": "wechat_inbox",
+ "columnsFrom": [
+ "binding_epoch"
+ ],
+ "tableTo": "wechat_sync_state",
+ "columnsTo": [
+ "binding_epoch"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ },
+ "wechat_inbox_session_id_sessions_id_fk": {
+ "name": "wechat_inbox_session_id_sessions_id_fk",
+ "tableFrom": "wechat_inbox",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "tableTo": "sessions",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "set null"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "wechat_outbox": {
+ "name": "wechat_outbox",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "binding_epoch": {
+ "name": "binding_epoch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chunk_index": {
+ "name": "chunk_index",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "text": {
+ "name": "text",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "media_json": {
+ "name": "media_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "next_retry_at": {
+ "name": "next_retry_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "delivered_at": {
+ "name": "delivered_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_wechat_outbox_client_id": {
+ "name": "uniq_wechat_outbox_client_id",
+ "columns": [
+ "binding_epoch",
+ "client_id"
+ ],
+ "isUnique": true
+ },
+ "idx_wechat_outbox_delivery": {
+ "name": "idx_wechat_outbox_delivery",
+ "columns": [
+ "binding_epoch",
+ "status",
+ "next_retry_at"
+ ],
+ "isUnique": false
+ },
+ "idx_wechat_outbox_task": {
+ "name": "idx_wechat_outbox_task",
+ "columns": [
+ "binding_epoch",
+ "task_id",
+ "chunk_index"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "wechat_outbox_binding_epoch_wechat_sync_state_binding_epoch_fk": {
+ "name": "wechat_outbox_binding_epoch_wechat_sync_state_binding_epoch_fk",
+ "tableFrom": "wechat_outbox",
+ "columnsFrom": [
+ "binding_epoch"
+ ],
+ "tableTo": "wechat_sync_state",
+ "columnsTo": [
+ "binding_epoch"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ },
+ "wechat_outbox_task_id_wechat_inbox_id_fk": {
+ "name": "wechat_outbox_task_id_wechat_inbox_id_fk",
+ "tableFrom": "wechat_outbox",
+ "columnsFrom": [
+ "task_id"
+ ],
+ "tableTo": "wechat_inbox",
+ "columnsTo": [
+ "id"
+ ],
+ "onUpdate": "no action",
+ "onDelete": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "wechat_sync_state": {
+ "name": "wechat_sync_state",
+ "columns": {
+ "binding_epoch": {
+ "name": "binding_epoch",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "is_active": {
+ "name": "is_active",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "sync_cursor": {
+ "name": "sync_cursor",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "last_poll_at": {
+ "name": "last_poll_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_error_code": {
+ "name": "last_error_code",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_wechat_sync_active": {
+ "name": "uniq_wechat_sync_active",
+ "columns": [
+ "is_active"
+ ],
+ "where": "\"wechat_sync_state\".\"is_active\" = 1",
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ }
+ },
+ "views": {},
+ "enums": {},
+ "_meta": {
+ "columns": {},
+ "schemas": {},
+ "tables": {}
+ },
+ "internal": {
+ "indexes": {
+ "uniq_orca_worker_creation_reservations_team_label": {
+ "columns": {
+ "lower(\"label\")": {
+ "isExpression": true
+ }
+ }
+ },
+ "uniq_orca_workers_team_label": {
+ "columns": {
+ "lower(\"label\")": {
+ "isExpression": true
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/desktop/drizzle/meta/_journal.json b/apps/desktop/drizzle/meta/_journal.json
index c65d2b780e..1e5dae81d7 100644
--- a/apps/desktop/drizzle/meta/_journal.json
+++ b/apps/desktop/drizzle/meta/_journal.json
@@ -666,6 +666,13 @@
"when": 1787387261372,
"tag": "0094_repair_custom_provider_timestamps",
"breakpoints": true
+ },
+ {
+ "idx": 95,
+ "version": "6",
+ "when": 1787644558248,
+ "tag": "0095_scope_messages_fts_update_trigger",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/apps/desktop/drizzle/scripts/0095_scope_messages_fts_update_trigger.ts b/apps/desktop/drizzle/scripts/0095_scope_messages_fts_update_trigger.ts
new file mode 100644
index 0000000000..3ad8fb5229
--- /dev/null
+++ b/apps/desktop/drizzle/scripts/0095_scope_messages_fts_update_trigger.ts
@@ -0,0 +1,29 @@
+import type Database from 'better-sqlite3';
+
+const FTS_ROLE_WHITELIST = "('user', 'assistant', 'ask_user', 'plan_review')";
+
+function tableExists(db: Database.Database, name: string): boolean {
+ return !!db
+ .prepare(`SELECT 1 FROM sqlite_master WHERE type='table' AND name=?`)
+ .get(name);
+}
+
+function run(db: Database.Database): void {
+ if (!tableExists(db, 'messages') || !tableExists(db, 'messages_fts')) return;
+
+ db.exec('DROP TRIGGER IF EXISTS messages_fts_update;');
+
+ db.exec(`
+ CREATE TRIGGER messages_fts_update
+ AFTER UPDATE ON messages
+ WHEN old.role IN ${FTS_ROLE_WHITELIST} OR new.role IN ${FTS_ROLE_WHITELIST}
+ BEGIN
+ DELETE FROM messages_fts WHERE message_id = old.id;
+ INSERT INTO messages_fts(message_id, session_id, role, content)
+ SELECT new.id, new.session_id, new.role, new.content
+ WHERE new.rewind_at IS NULL AND new.role IN ${FTS_ROLE_WHITELIST};
+ END;
+ `);
+}
+
+module.exports = { run };
diff --git a/apps/desktop/src/main/__tests__/claudeLocalSessions.test.ts b/apps/desktop/src/main/__tests__/claudeLocalSessions.test.ts
index 3648cdd02f..c626e2f18b 100644
--- a/apps/desktop/src/main/__tests__/claudeLocalSessions.test.ts
+++ b/apps/desktop/src/main/__tests__/claudeLocalSessions.test.ts
@@ -25,6 +25,9 @@ vi.mock('../logger.js', () => ({
}),
}));
+const mediaRefMock = vi.hoisted(() => ({ commitMessageMediaRefs: vi.fn(async () => null) }));
+vi.mock('../cindy-media/chatAttachments.js', () => mediaRefMock);
+
import {
importExternalClaudeCodeSessions,
importExternalClaudeCodeMessagesForSession,
@@ -615,6 +618,57 @@ describe('parseClaudeCodeMessageLine', () => {
}
});
+ it('scans original oversized tool_result media URLs before capping import rows', async () => {
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'claude-local-home-'));
+ const projectsDir = path.join(home, '.claude', 'projects', '-tmp-project');
+ fs.mkdirSync(projectsDir, { recursive: true });
+ const file = path.join(projectsDir, `${sdkSessionId}.jsonl`);
+ const url = 'cindy-media://blobs/0123456789abcdef.png';
+ const huge = `${'m'.repeat(9000)}${url}`;
+ fs.writeFileSync(
+ file,
+ `${line({
+ type: 'user',
+ uuid: 'user-tool',
+ cwd: '/tmp/project',
+ message: {
+ role: 'user',
+ content: [{ type: 'tool_result', tool_use_id: 'tu-1', content: huge }],
+ },
+ })}\n`,
+ );
+
+ const db = createLocalDb();
+ insertImportedClaudeSession(db, `claude-${sdkSessionId}`, sdkSessionId);
+ const homedir = vi.spyOn(os, 'homedir').mockReturnValue(home);
+ const tx = vi.fn(
+ async (name: string, args: unknown) => runInprocTx(db, { name, args }) as never,
+ );
+ vi.mocked(getRawDb).mockReturnValue(db);
+ setCurrentDbClient({ ...makeTestDbClient(db), tx }, 'test-user');
+ mediaRefMock.commitMessageMediaRefs.mockClear();
+
+ try {
+ await importExternalClaudeCodeMessagesForSession(`claude-${sdkSessionId}`);
+ expect(mediaRefMock.commitMessageMediaRefs).toHaveBeenCalledWith({
+ sessionId: `claude-${sdkSessionId}`,
+ role: 'tool_result',
+ content: huge,
+ });
+ const stored = db
+ .prepare("SELECT content FROM messages WHERE role = 'tool_result' LIMIT 1")
+ .get() as { content: string };
+ const parsed = JSON.parse(stored.content) as string;
+ expect(parsed.length).toBeLessThanOrEqual(8 * 1024);
+ expect(parsed).not.toContain(url);
+ } finally {
+ homedir.mockRestore();
+ resetLocalDb();
+ db.close();
+ fs.rmSync(home, { recursive: true, force: true });
+ }
+ });
+
it('does not reuse unchanged Claude JSONL cache across current DB users', async () => {
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'claude-local-home-'));
const projectsDir = path.join(home, '.claude', 'projects', '-tmp-project');
diff --git a/apps/desktop/src/main/__tests__/messagePersistBroadcasterToolResultCap.test.ts b/apps/desktop/src/main/__tests__/messagePersistBroadcasterToolResultCap.test.ts
new file mode 100644
index 0000000000..1ae6a45bdc
--- /dev/null
+++ b/apps/desktop/src/main/__tests__/messagePersistBroadcasterToolResultCap.test.ts
@@ -0,0 +1,158 @@
+/**
+ * messagePersistBroadcasterToolResultCap.test.ts
+ * ---------------------------------------------------------------------------
+ * tool_result 落库 8KB 截断(chat-data perf):
+ * - DB 只落有界内容(create / eager / orphan / 增长 update / full 覆盖全部入口);
+ * - 返回给 renderer 的 resolvedContent 仍是全文(在途显示不受影响);
+ * - 截断前对原文扫媒体 URL 挂账(被截掉的尾部可能含首次出现的 blob URL);
+ * - 截断后内容不变的重复增长不再重复 UPDATE。
+ */
+
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+vi.mock('../localDb/ipc/messages.js', () => ({
+ broadcastMessageAgentMetaUpdate: vi.fn(async () => true),
+ broadcastMessageRow: vi.fn(),
+ createMessage: vi.fn(async () => ({}) as unknown),
+ findVisibleToolUseMessageByAliases: vi.fn(async () => null),
+ patchMessageAgentMetaWithResult: vi.fn(async () => ({ previous: {}, next: {} })),
+ updateMessageContent: vi.fn(async () => ({}) as unknown),
+}));
+vi.mock('../localDb/subagentRuns.js', () => ({
+ getSubagentRunDetail: vi.fn(async () => null),
+}));
+vi.mock('../logger.js', () => ({
+ createLogger: () => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }),
+}));
+vi.mock('../cindy-media/chatAttachments.js', () => ({
+ commitMessageMediaRefs: vi.fn(async () => null),
+}));
+vi.mock('electron', () => ({
+ BrowserWindow: { getAllWindows: () => [] },
+}));
+vi.mock('../device-link/broadcast-tap.js', () => ({
+ captureDataOwnerBroadcastScope: vi.fn(() => null),
+ isDataOwnerBroadcastScopeCurrent: vi.fn(() => true),
+ getSafeDataOwnerPushStamp: vi.fn(() => undefined),
+ tapWindowBroadcast: vi.fn(),
+}));
+
+import { createMessage, updateMessageContent } from '../localDb/ipc/messages.js';
+import { commitMessageMediaRefs } from '../cindy-media/chatAttachments.js';
+import {
+ clearSessionPersistState,
+ flushOrphanToolResults,
+ onToolResultEvent,
+ onToolResultFullEvent,
+ onToolUseEvent,
+} from '../messagePersistBroadcaster.js';
+import {
+ TOOL_RESULT_PERSIST_CONTENT_LIMIT,
+ TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX,
+} from '../../shared/toolResultPersistCap.js';
+
+const SESSION = 'sess-cap';
+const flushWrites = () => new Promise((resolve) => setTimeout(resolve, 0));
+
+type CreateBody = { role: string; content: unknown; clientId: string };
+
+function createdToolResultBodies(): CreateBody[] {
+ return vi
+ .mocked(createMessage)
+ .mock.calls.map(([, body]) => body as CreateBody)
+ .filter((body) => body.role === 'tool_result');
+}
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ clearSessionPersistState(SESSION);
+});
+
+describe('tool_result persistence cap', () => {
+ it('persists an under-cap result verbatim without a pre-truncation media scan', async () => {
+ onToolUseEvent(SESSION, { toolUseId: 't0', toolName: 'Bash', input: {} }, null);
+ const r = onToolResultEvent(SESSION, { summary: 'small output', toolUseIds: ['t0'] }, null);
+ expect(r?.content).toBe('small output');
+ await flushWrites();
+
+ expect(createdToolResultBodies()[0]?.content).toBe('small output');
+ expect(commitMessageMediaRefs).not.toHaveBeenCalled();
+ });
+
+ it('caps an oversized summary on create while returning the full text for display', async () => {
+ onToolUseEvent(SESSION, { toolUseId: 't1', toolName: 'Bash', input: {} }, null);
+ const bigText = 'a'.repeat(TOOL_RESULT_PERSIST_CONTENT_LIMIT * 2);
+ const r = onToolResultEvent(SESSION, { summary: bigText, toolUseIds: ['t1'] }, null);
+ expect(r?.content).toBe(bigText);
+ await flushWrites();
+
+ const persisted = createdToolResultBodies()[0]?.content as string;
+ expect(persisted.length).toBeLessThanOrEqual(TOOL_RESULT_PERSIST_CONTENT_LIMIT);
+ expect(persisted.endsWith(TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX)).toBe(true);
+ expect(commitMessageMediaRefs).toHaveBeenCalledWith({
+ sessionId: SESSION,
+ role: 'tool_result',
+ content: bigText,
+ });
+ });
+
+ it('scans the full original text for media refs before truncating a full update', async () => {
+ onToolUseEvent(SESSION, { toolUseId: 't2', toolName: 'Bash', input: {} }, null);
+ onToolResultEvent(SESSION, { summary: 'short', toolUseIds: ['t2'] }, null);
+ const url = 'cindy-media://blobs/0123456789abcdef.png';
+ const fullText = `${'b'.repeat(TOOL_RESULT_PERSIST_CONTENT_LIMIT + 100)}${url}`;
+ const r = onToolResultFullEvent(SESSION, { toolUseId: 't2', fullText }, null);
+ expect(r?.content).toBe(fullText);
+ await flushWrites();
+
+ expect(updateMessageContent).toHaveBeenCalledTimes(1);
+ const capped = vi.mocked(updateMessageContent).mock.calls[0][2] as string;
+ expect(capped.length).toBeLessThanOrEqual(TOOL_RESULT_PERSIST_CONTENT_LIMIT);
+ expect(capped).not.toContain(url);
+ expect(commitMessageMediaRefs).toHaveBeenCalledWith({
+ sessionId: SESSION,
+ role: 'tool_result',
+ content: fullText,
+ });
+ });
+
+ it('skips redundant UPDATEs once growth happens entirely beyond the cap', async () => {
+ onToolUseEvent(SESSION, { toolUseId: 't3', toolName: 'Bash', input: {} }, null);
+ onToolResultEvent(SESSION, { summary: 'seed', toolUseIds: ['t3'] }, null);
+ const base = 'c'.repeat(TOOL_RESULT_PERSIST_CONTENT_LIMIT * 2);
+ onToolResultFullEvent(SESSION, { toolUseId: 't3', fullText: base }, null);
+ const grown = onToolResultFullEvent(
+ SESSION,
+ { toolUseId: 't3', fullText: `${base} plus a tail far beyond the cap` },
+ null,
+ );
+ await flushWrites();
+
+ expect(grown?.content).toBe(`${base} plus a tail far beyond the cap`);
+ expect(updateMessageContent).toHaveBeenCalledTimes(1);
+ expect(vi.mocked(commitMessageMediaRefs).mock.calls.length).toBe(2);
+ });
+
+ it('caps the eager-create path (full text arrives before any summary)', async () => {
+ onToolUseEvent(SESSION, { toolUseId: 't4', toolName: 'Read', input: {} }, null);
+ const fullText = 'd'.repeat(TOOL_RESULT_PERSIST_CONTENT_LIMIT + 500);
+ const r = onToolResultFullEvent(SESSION, { toolUseId: 't4', fullText }, null);
+ expect(r?.content).toBe(fullText);
+ await flushWrites();
+
+ const persisted = createdToolResultBodies()[0]?.content as string;
+ expect(persisted.length).toBeLessThanOrEqual(TOOL_RESULT_PERSIST_CONTENT_LIMIT);
+ expect(persisted.endsWith(TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX)).toBe(true);
+ });
+
+ it('caps orphan flush of a buffered full text whose summary never arrived', async () => {
+ const fullText = 'e'.repeat(TOOL_RESULT_PERSIST_CONTENT_LIMIT + 500);
+ expect(onToolResultFullEvent(SESSION, { toolUseId: 'unknown-tu', fullText }, null)).toBeNull();
+ flushOrphanToolResults(SESSION, null);
+ await flushWrites();
+
+ const persisted = createdToolResultBodies()[0]?.content as string;
+ expect(persisted.length).toBeLessThanOrEqual(TOOL_RESULT_PERSIST_CONTENT_LIMIT);
+ expect(persisted.endsWith(TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX)).toBe(true);
+ });
+});
diff --git a/apps/desktop/src/main/localDb/__tests__/scopeMessagesFtsUpdateTriggerMigration.test.ts b/apps/desktop/src/main/localDb/__tests__/scopeMessagesFtsUpdateTriggerMigration.test.ts
new file mode 100644
index 0000000000..3ebafd2ff5
--- /dev/null
+++ b/apps/desktop/src/main/localDb/__tests__/scopeMessagesFtsUpdateTriggerMigration.test.ts
@@ -0,0 +1,128 @@
+import Database from 'better-sqlite3';
+import { describe, expect, it } from 'vitest';
+
+// Migration companion scripts intentionally use CommonJS so the runtime loader can replay them.
+const { default: migration0066 } = (await import(
+ '../../../../drizzle/scripts/0066_slim_messages_fts'
+)) as { default: { run(db: Database.Database): void } };
+const { default: migration0095 } = (await import(
+ '../../../../drizzle/scripts/0095_scope_messages_fts_update_trigger'
+)) as { default: { run(db: Database.Database): void } };
+
+function createMessagesDb(): Database.Database {
+ const db = new Database(':memory:');
+ db.exec(`
+ CREATE TABLE messages (
+ id TEXT PRIMARY KEY NOT NULL,
+ client_id TEXT NOT NULL,
+ session_id TEXT NOT NULL,
+ role TEXT NOT NULL,
+ content TEXT NOT NULL,
+ rewind_at INTEGER
+ );
+ `);
+ return db;
+}
+
+function insertMessage(
+ db: Database.Database,
+ row: { id: string; role: string; content: string; rewindAt?: number | null },
+): void {
+ db.prepare(
+ 'INSERT INTO messages (id, client_id, session_id, role, content, rewind_at) VALUES (?, ?, ?, ?, ?, ?)',
+ ).run(row.id, `client-${row.id}`, 's1', row.role, row.content, row.rewindAt ?? null);
+}
+
+function ftsRows(db: Database.Database): Array<{ message_id: string; content: string }> {
+ return db
+ .prepare('SELECT message_id, content FROM messages_fts ORDER BY message_id')
+ .all() as Array<{ message_id: string; content: string }>;
+}
+
+describe('0095 scope messages_fts update trigger', () => {
+ it('adds a role WHEN clause so non-whitelist updates skip the FTS delete scan', () => {
+ const db = createMessagesDb();
+ try {
+ migration0066.run(db);
+ migration0095.run(db);
+
+ const trigger = db
+ .prepare("SELECT sql FROM sqlite_master WHERE type='trigger' AND name='messages_fts_update'")
+ .get() as { sql: string } | undefined;
+ expect(trigger?.sql).toContain('WHEN old.role IN');
+ expect(trigger?.sql).toContain('OR new.role IN');
+ } finally {
+ db.close();
+ }
+ });
+
+ it('leaves FTS untouched when a tool_result row is updated', () => {
+ const db = createMessagesDb();
+ try {
+ migration0066.run(db);
+ insertMessage(db, { id: 'a1', role: 'assistant', content: 'hello world' });
+ insertMessage(db, { id: 't1', role: 'tool_result', content: 'chunk one' });
+ migration0095.run(db);
+
+ db.prepare('UPDATE messages SET content = ? WHERE id = ?').run('chunk one two', 't1');
+
+ expect(ftsRows(db)).toEqual([{ message_id: 'a1', content: 'hello world' }]);
+ } finally {
+ db.close();
+ }
+ });
+
+ it('still maintains FTS for whitelist-role updates and rewind hiding', () => {
+ const db = createMessagesDb();
+ try {
+ migration0066.run(db);
+ migration0095.run(db);
+ insertMessage(db, { id: 'a1', role: 'assistant', content: 'first draft' });
+
+ db.prepare('UPDATE messages SET content = ? WHERE id = ?').run('final answer', 'a1');
+ expect(ftsRows(db)).toEqual([{ message_id: 'a1', content: 'final answer' }]);
+
+ db.prepare('UPDATE messages SET rewind_at = ? WHERE id = ?').run(123, 'a1');
+ expect(ftsRows(db)).toEqual([]);
+
+ db.prepare('UPDATE messages SET rewind_at = NULL WHERE id = ?').run('a1');
+ expect(ftsRows(db)).toEqual([{ message_id: 'a1', content: 'final answer' }]);
+ } finally {
+ db.close();
+ }
+ });
+
+ it('removes the FTS row when a whitelist role is rewritten to a tombstone', () => {
+ const db = createMessagesDb();
+ try {
+ migration0066.run(db);
+ migration0095.run(db);
+ insertMessage(db, { id: 'a1', role: 'assistant', content: 'to be deleted' });
+ expect(ftsRows(db)).toHaveLength(1);
+
+ db.prepare("UPDATE messages SET role = 'message_tombstone', content = '' WHERE id = ?").run('a1');
+ expect(ftsRows(db)).toEqual([]);
+ } finally {
+ db.close();
+ }
+ });
+
+ it('is safe on databases without the messages or messages_fts tables', () => {
+ const empty = new Database(':memory:');
+ try {
+ expect(() => migration0095.run(empty)).not.toThrow();
+ } finally {
+ empty.close();
+ }
+ const withoutFts = createMessagesDb();
+ try {
+ expect(() => migration0095.run(withoutFts)).not.toThrow();
+ const trigger = withoutFts
+ .prepare("SELECT sql FROM sqlite_master WHERE type='trigger' AND name='messages_fts_update'")
+ .get();
+ expect(trigger).toBeUndefined();
+ } finally {
+ withoutFts.close();
+ }
+ });
+});
diff --git a/apps/desktop/src/main/localDb/client/WorkerThreadTransport.ts b/apps/desktop/src/main/localDb/client/WorkerThreadTransport.ts
index ff0a5b8a57..12a311090a 100644
--- a/apps/desktop/src/main/localDb/client/WorkerThreadTransport.ts
+++ b/apps/desktop/src/main/localDb/client/WorkerThreadTransport.ts
@@ -1052,7 +1052,7 @@ function codexImportMessages(readyDb, args) {
clientId,
sessionId,
role,
- content: stringifyContent(row.content),
+ content: stringifyImportedContent(role, row.content),
agentMeta: JSON.stringify({ sdkSessionId, model }),
createdAt,
}).changes;
@@ -1095,12 +1095,13 @@ function claudeImportMessages(readyDb, args) {
for (const rawRow of rows) {
const row = asRecord(rawRow, 'claude row');
const key = expectNumber(row.lineNo, 'row.lineNo') + '-' + expectNumber(row.partIndex, 'row.partIndex');
+ const role = expectString(row.role, 'row.role');
count += upsert.run({
id: 'claude-import-' + sdkSessionId + '-' + key,
clientId: importClientIdPrefix + key,
sessionId,
- role: expectString(row.role, 'row.role'),
- content: stringifyContent(row.content),
+ role,
+ content: stringifyImportedContent(role, row.content),
toolUseId: nullableString(row.toolUseId),
agentMeta: row.agentMeta ? stringifyContent(row.agentMeta) : null,
createdAt: expectNumber(row.createdAt, 'row.createdAt'),
@@ -1729,6 +1730,23 @@ function stringifyContent(value) {
return json === undefined ? 'null' : json;
}
+function capToolResultTextForPersist(text) {
+ var limit = 8 * 1024;
+ var suffix = '\\n\\n[tool result truncated: stored first 8KB]';
+ if (text.length <= limit) return text;
+ var cut = Math.max(0, limit - suffix.length);
+ var lastKept = text.charCodeAt(cut - 1);
+ if (cut > 0 && lastKept >= 0xd800 && lastKept <= 0xdbff) cut -= 1;
+ return text.slice(0, cut) + suffix;
+}
+
+function stringifyImportedContent(role, content) {
+ if (role === 'tool_result' && typeof content === 'string') {
+ return stringifyContent(capToolResultTextForPersist(content));
+ }
+ return stringifyContent(content);
+}
+
function asRecord(value, label) {
if (!isRecord(value)) throw invalidArgs(label + ' must be an object');
return value;
diff --git a/apps/desktop/src/main/localDb/client/__tests__/tx.test.ts b/apps/desktop/src/main/localDb/client/__tests__/tx.test.ts
index 77d76cd2f8..7c269520bb 100644
--- a/apps/desktop/src/main/localDb/client/__tests__/tx.test.ts
+++ b/apps/desktop/src/main/localDb/client/__tests__/tx.test.ts
@@ -428,6 +428,52 @@ describe('db worker tx handlers', () => {
});
});
+ it('claude.importMessages caps oversized tool_result content at the persistence limit', async () => {
+ await withClient(async (client) => {
+ await seedSession(client, 's1');
+ const cap = 8 * 1024;
+ const result = await client.tx('claude.importMessages', {
+ sessionId: 's1',
+ importClientIdPrefix: 'claude-import:',
+ sdkSessionId: 'sdk-1',
+ rows: [
+ {
+ lineNo: 8,
+ partIndex: 0,
+ role: 'tool_result',
+ content: 'z'.repeat(cap * 2),
+ toolUseId: 'tool-2',
+ agentMeta: null,
+ createdAt: 3100,
+ },
+ {
+ lineNo: 9,
+ partIndex: 0,
+ role: 'assistant',
+ content: { text: 'a'.repeat(cap * 2) },
+ toolUseId: null,
+ agentMeta: null,
+ createdAt: 3200,
+ },
+ ],
+ });
+
+ expect(result).toEqual({ changed: 2 });
+ const toolResult = (await client.queryOne(
+ 'SELECT content FROM messages WHERE client_id = ?',
+ ['claude-import:8-0'],
+ )) as { content: string };
+ const storedText = JSON.parse(toolResult.content) as string;
+ expect(storedText.length).toBeLessThanOrEqual(cap);
+ expect(storedText).toContain('[tool result truncated');
+ const assistant = (await client.queryOne(
+ 'SELECT content FROM messages WHERE client_id = ?',
+ ['claude-import:9-0'],
+ )) as { content: string };
+ expect((JSON.parse(assistant.content) as { text: string }).text.length).toBe(cap * 2);
+ });
+ });
+
it('claude.importMessages does not rewrite rewound imported messages', async () => {
await withClient(async (client) => {
await seedSession(client, 's1');
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/messagesWriteReadback.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/messagesWriteReadback.test.ts
new file mode 100644
index 0000000000..b419b1ade8
--- /dev/null
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/messagesWriteReadback.test.ts
@@ -0,0 +1,230 @@
+/**
+ * messagesWriteReadback.test.ts
+ * ---------------------------------------------------------------------------
+ * 写路径去大字段回读(perf):createMessage happy path 与 updateMessageContent
+ * 不再把整行 content 从 DB worker 读回主进程。这里守住两条不变量:
+ * 1. 返回值语义与"整行回读 + messageToCamel"完全一致(JSON.parse 失败回退
+ * 裸串、字符串 '123' 解析成数字、assistant 引文剥离);
+ * 2. 写后的 SELECT 不再包含 content 列(updateMessageContent 窄回读),
+ * createMessage happy path 在 INSERT 之后没有任何 SELECT。
+ */
+import Database from 'better-sqlite3';
+import { drizzle } from 'drizzle-orm/better-sqlite3';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { messages, sessions } from '../../schema';
+
+const h = vi.hoisted(() => ({
+ db: null as ReturnType<typeof drizzle> | null,
+ sqlite: null as Database.Database | null,
+ client: null as any,
+ queries: [] as string[],
+ mediaRefCalls: [] as Array<{ sessionId: string; role: string; content: unknown }>,
+}));
+
+vi.mock('electron', () => ({
+ ipcMain: { handle: vi.fn() },
+ BrowserWindow: { getAllWindows: () => [] },
+}));
+vi.mock('../../../logger', () => ({
+ createLogger: () => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }),
+}));
+vi.mock('../../../logger.js', () => ({
+ createLogger: () => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }),
+}));
+vi.mock('../../../maker-host/codex-local-sessions', () => ({
+ importExternalCodexMessagesForSession: vi.fn(async () => undefined),
+}));
+vi.mock('../../../maker-host/claude-local-sessions', () => ({
+ importExternalClaudeCodeMessagesForSession: vi.fn(async () => undefined),
+}));
+vi.mock('../../../embedders/chat-history-embedder', () => ({
+ onMessageCreated: vi.fn(async () => undefined),
+}));
+vi.mock('../../../git-context/prRefsStore', () => ({
+ recomputePrRefsForSession: vi.fn(async () => undefined),
+ recordPrRefsForMessage: vi.fn(async () => undefined),
+}));
+vi.mock('../../../cindy-media/chatAttachments', () => ({
+ commitMessageMediaRefs: vi.fn(async (params: { sessionId: string; role: string; content: unknown }) => {
+ h.mediaRefCalls.push(params);
+ return null;
+ }),
+ collectCindyMediaHashes: vi.fn(() => []),
+}));
+vi.mock('../../../cindy-media/ledger', () => ({
+ removeRefs: vi.fn(async () => undefined),
+ removeSessionAttachmentRefIfUnreferencedByLiveMessage: vi.fn(async () => undefined),
+}));
+vi.mock('../../../device-link/invoke-context', () => ({
+ isDeviceLinkInvoke: vi.fn(() => false),
+}));
+vi.mock('../../../device-link/broadcast-tap', () => ({
+ captureDataOwnerBroadcastScope: vi.fn(() => null),
+ getSafeDataOwnerPushStamp: vi.fn(() => undefined),
+ tapWindowBroadcast: vi.fn(),
+}));
+vi.mock('../../client/current', () => ({
+ getDbClient: () => h.client,
+}));
+
+import { createMessage, updateMessageContent } from '../messages';
+
+function setupDb(): void {
+ const sqlite = new Database(':memory:');
+ sqlite.exec(`
+ CREATE TABLE sessions (
+ id TEXT PRIMARY KEY,
+ cleared_at INTEGER,
+ status TEXT NOT NULL DEFAULT 'active'
+ );
+ CREATE TABLE messages (
+ id TEXT PRIMARY KEY,
+ client_id TEXT NOT NULL,
+ session_id TEXT NOT NULL,
+ role TEXT NOT NULL,
+ content TEXT NOT NULL,
+ tool_use_id TEXT,
+ agent_meta TEXT,
+ agent_kind TEXT,
+ created_at INTEGER NOT NULL,
+ rewind_at INTEGER
+ );
+ CREATE UNIQUE INDEX uniq_messages_session_client ON messages(session_id, client_id);
+ `);
+ sqlite.prepare("INSERT INTO sessions (id, cleared_at, status) VALUES ('s1', NULL, 'active')").run();
+ const db = drizzle(sqlite, {
+ schema: { messages, sessions },
+ logger: {
+ logQuery: (query: string) => {
+ h.queries.push(query);
+ },
+ },
+ });
+ h.sqlite = sqlite;
+ h.db = db;
+ h.client = {
+ drizzle: db,
+ exec: vi.fn(async (sql: string, params: unknown[] = []) => h.sqlite!.prepare(sql).run(...params)),
+ query: vi.fn(async (sql: string, params: unknown[] = []) => h.sqlite!.prepare(sql).all(...params)),
+ };
+}
+
+describe('message write paths avoid large-content readback', () => {
+ beforeEach(() => {
+ h.queries.length = 0;
+ h.mediaRefCalls.length = 0;
+ setupDb();
+ });
+
+ describe('createMessage happy path', () => {
+ it('issues no SELECT after the INSERT and returns the inserted row', async () => {
+ const msg = await createMessage('s1', {
+ clientId: 'c1',
+ role: 'tool_result',
+ content: 'big tool output',
+ toolUseId: 'tu1',
+ createdAt: 1000,
+ });
+
+ const insertIdx = h.queries.findIndex((q) => q.startsWith('insert into "messages"'));
+ expect(insertIdx).toBeGreaterThanOrEqual(0);
+ expect(
+ h.queries.slice(insertIdx + 1).filter((q) => q.includes('from "messages"')),
+ ).toEqual([]);
+
+ expect(msg.clientId).toBe('c1');
+ expect(msg.content).toBe('big tool output');
+ expect(msg.toolUseId).toBe('tu1');
+ expect(msg.createdAt).toBe(new Date(1000).toISOString());
+ const stored = h.sqlite!
+ .prepare('SELECT content, rewind_at FROM messages WHERE client_id = ?')
+ .get('c1') as { content: string; rewind_at: number | null };
+ expect(stored).toEqual({ content: 'big tool output', rewind_at: null });
+ });
+
+ it('keeps messageToCamel parse semantics on the constructed return value', async () => {
+ const numericLike = await createMessage('s1', {
+ clientId: 'c-num',
+ role: 'user',
+ content: '123',
+ });
+ expect(numericLike.content).toBe(123);
+
+ const objectContent = await createMessage('s1', {
+ clientId: 'c-obj',
+ role: 'user',
+ content: { text: 'hi', files: [] },
+ });
+ expect(objectContent.content).toEqual({ text: 'hi', files: [] });
+
+ const cited = await createMessage('s1', {
+ clientId: 'c-cite',
+ role: 'assistant',
+ content: 'answerciteopaque tail',
+ });
+ expect(cited.content).toBe('answer tail');
+ });
+
+ it('still returns the existing row on idempotent duplicate create', async () => {
+ await createMessage('s1', { clientId: 'dup', role: 'user', content: 'first' });
+ const again = await createMessage('s1', { clientId: 'dup', role: 'user', content: 'second' });
+ expect(again.content).toBe('first');
+ });
+ });
+
+ describe('updateMessageContent narrow readback', () => {
+ it('re-reads the row without the content column and backfills from the input', async () => {
+ await createMessage('s1', {
+ clientId: 'u1',
+ role: 'tool_result',
+ content: 'summary',
+ toolUseId: 'tu1',
+ });
+ h.queries.length = 0;
+
+ const updated = await updateMessageContent('s1', 'u1', 'full text output');
+ expect(updated?.content).toBe('full text output');
+ expect(updated?.role).toBe('tool_result');
+
+ const postUpdateSelects = h.queries.filter(
+ (q) => q.startsWith('select') && q.includes('from "messages"'),
+ );
+ expect(postUpdateSelects.length).toBeGreaterThan(0);
+ for (const q of postUpdateSelects) {
+ expect(q).not.toMatch(/select[^]*"content"[^]*from "messages"/);
+ }
+
+ const stored = h.sqlite!
+ .prepare('SELECT content FROM messages WHERE client_id = ?')
+ .get('u1') as { content: string };
+ expect(stored.content).toBe('full text output');
+ });
+
+ it('feeds the media-ref hook with the DB role and the just-written content', async () => {
+ await createMessage('s1', { clientId: 'u2', role: 'tool_result', content: 'summary' });
+ h.mediaRefCalls.length = 0;
+
+ await updateMessageContent('s1', 'u2', 'full text with cindy-media url');
+ expect(h.mediaRefCalls).toEqual([
+ { sessionId: 's1', role: 'tool_result', content: 'full text with cindy-media url' },
+ ]);
+ });
+
+ it('returns null when the row does not exist', async () => {
+ const updated = await updateMessageContent('s1', 'missing', 'anything');
+ expect(updated).toBeNull();
+ expect(h.mediaRefCalls).toEqual([]);
+ });
+
+ it('keeps object-content serialization identical to a full readback', async () => {
+ await createMessage('s1', { clientId: 'u3', role: 'ask_user', content: { status: 'pending' } });
+ const updated = await updateMessageContent('s1', 'u3', { status: 'answered', answers: { q: 'a' } });
+ expect(updated?.content).toEqual({ status: 'answered', answers: { q: 'a' } });
+ const stored = h.sqlite!
+ .prepare('SELECT content FROM messages WHERE client_id = ?')
+ .get('u3') as { content: string };
+ expect(JSON.parse(stored.content)).toEqual({ status: 'answered', answers: { q: 'a' } });
+ });
+ });
+});
diff --git a/apps/desktop/src/main/localDb/ipc/messages.ts b/apps/desktop/src/main/localDb/ipc/messages.ts
index d05463ff06..bcc9c5b754 100644
--- a/apps/desktop/src/main/localDb/ipc/messages.ts
+++ b/apps/desktop/src/main/localDb/ipc/messages.ts
@@ -1297,15 +1297,30 @@ export async function updateMessageContent(
): Promise<Message | null> {
const ownerScope = captureOwnerBroadcastScope();
const db = getDbClient().drizzle;
+ const serialized = safeStringify(content);
await db
.update(messages)
- .set({ content: safeStringify(content) })
+ .set({ content: serialized })
.where(and(eq(messages.sessionId, sessionId), eq(messages.clientId, clientId)));
- const [row] = await db
- .select()
+ // 窄回读:刻意不选 content——tool_result 全文可达 MB 级,整行回读会把大字段
+ // 经 DB worker 的 postMessage 结构化克隆再送回主进程一次。content 就是本次
+ // 写入值,用 serialized 回填;行不存在(clientId 未落库)仍以回读判 null。
+ const [narrow] = await db
+ .select({
+ id: messages.id,
+ clientId: messages.clientId,
+ sessionId: messages.sessionId,
+ role: messages.role,
+ toolUseId: messages.toolUseId,
+ agentMeta: messages.agentMeta,
+ agentKind: messages.agentKind,
+ createdAt: messages.createdAt,
+ rewindAt: messages.rewindAt,
+ })
.from(messages)
.where(and(eq(messages.sessionId, sessionId), eq(messages.clientId, clientId)))
.limit(1);
+ const row: MessageRow | undefined = narrow ? { ...narrow, content: serialized } : undefined;
if (row) {
// 挂账钩子同样覆盖"先摘要 create、后全文 update"的 tool_result 顺序
// (review P2:vendor 事件顺序一变,首现于 update 的 blob URL 若不在这里
@@ -1557,8 +1572,23 @@ export async function createMessage(
}
throw err;
}
- const [row] = await db.select().from(messages).where(eq(messages.id, id));
- if (!row) throw new Error('Message 创建后查询失败');
+ // 插入成功后不再整行回读:大 content(tool_result 全文)会经 DB worker 的
+ // postMessage 再送回主进程一次。insertRow 就是刚写入的行(新行 rewind_at 恒
+ // NULL);必须过 messageToCamel 走与回读完全相同的解析路径(JSON.parse 失败
+ // 回退裸串、assistant 引文剥离),否则返回值/广播行的类型语义会漂移。幂等命中
+ // 与 UNIQUE / guarded 回退路径仍保留各自的回读(上方),不受影响。
+ const row: MessageRow = {
+ id: insertRow.id,
+ clientId: insertRow.clientId,
+ sessionId: insertRow.sessionId,
+ role: insertRow.role,
+ content: insertRow.content,
+ toolUseId: insertRow.toolUseId ?? null,
+ agentMeta: insertRow.agentMeta ?? null,
+ agentKind: insertRow.agentKind ?? null,
+ createdAt: insertRow.createdAt,
+ rewindAt: null,
+ };
const msg = messageToCamel(row);
// 媒体总仓挂账钩子(规则 25):消息落库是"blob 归属本会话"的
// 确定时点,覆盖所有落库来源(renderer IPC / hook / im / agent echo / 合成
diff --git a/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts b/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
index 7e84e908d4..ee0c120923 100644
--- a/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
+++ b/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
@@ -5,6 +5,7 @@ import type Database from 'better-sqlite3';
import type { DbTxName } from '../../client/tx/types.js';
import { normalizeWorkingDirForStorage } from '../../../../shared/workingDir.js';
+import { capImportedToolResultContent } from '../../../../shared/toolResultPersistCap.js';
import {
wechatActivateBindingEpoch,
wechatCancelForCommand,
@@ -648,7 +649,7 @@ function codexImportMessages(db: Database.Database, args: unknown): { changed: n
clientId,
sessionId,
role,
- content: stringifyContent(row.content),
+ content: stringifyImportedContent(role, row.content),
agentMeta: JSON.stringify({ sdkSessionId, model }),
createdAt,
}).changes;
@@ -691,12 +692,13 @@ function claudeImportMessages(db: Database.Database, args: unknown): { changed:
for (const rawRow of rows) {
const row = asRecord(rawRow, 'claude row');
const key = `${expectNumber(row.lineNo, 'row.lineNo')}-${expectNumber(row.partIndex, 'row.partIndex')}`;
+ const role = expectString(row.role, 'row.role');
changed += upsert.run({
id: `claude-import-${sdkSessionId}-${key}`,
clientId: `${importClientIdPrefix}${key}`,
sessionId,
- role: expectString(row.role, 'row.role'),
- content: stringifyContent(row.content),
+ role,
+ content: stringifyImportedContent(role, row.content),
toolUseId: nullableString(row.toolUseId),
agentMeta: row.agentMeta ? stringifyContent(row.agentMeta) : null,
createdAt: expectNumber(row.createdAt, 'row.createdAt'),
@@ -1998,6 +2000,15 @@ function stringifyContent(value: unknown): string {
return json === undefined ? 'null' : json;
}
+/**
+ * 外部 CLI 历史导入与 live 落库同口径:tool_result 正文截到 8KB。
+ * 不截会让 rollout / transcript 重导入"复活"全文。媒体挂账在 main 导入层
+ * 对原文执行(本函数跑在 DB worker,碰不到 cindy-media ledger)。
+ */
+function stringifyImportedContent(role: string, content: unknown): string {
+ return stringifyContent(capImportedToolResultContent(role, content));
+}
+
function asRecord(value: unknown, label: string): Record<string, unknown> {
if (!isRecord(value)) throw invalidArgs(`${label} must be an object`);
return value;
diff --git a/apps/desktop/src/main/maker-host/claude-local-sessions.ts b/apps/desktop/src/main/maker-host/claude-local-sessions.ts
index f064b72196..8b3156956f 100644
--- a/apps/desktop/src/main/maker-host/claude-local-sessions.ts
+++ b/apps/desktop/src/main/maker-host/claude-local-sessions.ts
@@ -18,6 +18,8 @@ import { getCurrentDbClientUserId, getDbClient } from '../localDb/client/current
import { createLogger } from '../logger.js';
import { normalizeWorkingDirForStorage } from '../../shared/workingDir.js';
import { recordPrRefsForImportedMessages } from '../git-context/prRefsStore.js';
+import { commitMessageMediaRefs } from '../cindy-media/chatAttachments.js';
+import { capImportedToolResultContent } from '../../shared/toolResultPersistCap.js';
import {
cacheImportedBase64Image,
importedUserContent,
@@ -246,19 +248,36 @@ export async function importExternalClaudeCodeMessagesForSession(sessionId: stri
return;
}
- const { changed } = await getDbClient().tx('claude.importMessages', {
- sessionId,
- importClientIdPrefix,
- sdkSessionId: session.sdkSessionId,
- rows: imported.map((row) => ({
+ const rows = [];
+ for (const row of imported) {
+ if (row.role === 'tool_result' && typeof row.content === 'string') {
+ // 截断前对原文挂账:worker 里的 stringifyImportedContent 看不到 ledger。
+ await commitMessageMediaRefs({
+ sessionId,
+ role: 'tool_result',
+ content: row.content,
+ }).catch((err) => {
+ log.warn('imported tool_result media ref commit failed', {
+ sessionId,
+ error: err instanceof Error ? err.message : String(err),
+ });
+ });
+ }
+ rows.push({
lineNo: row.lineNo,
partIndex: row.partIndex,
role: row.role,
- content: row.content,
+ content: capImportedToolResultContent(row.role, row.content),
toolUseId: row.toolUseId,
agentMeta: row.agentMeta,
createdAt: row.createdAt,
- })),
+ });
+ }
+ const { changed } = await getDbClient().tx('claude.importMessages', {
+ sessionId,
+ importClientIdPrefix,
+ sdkSessionId: session.sdkSessionId,
+ rows,
});
if (cacheScope) {
claudeMessageImportFileCache.set(sessionId, { scope: cacheScope, path: sourceFile, ...sourceStat });
diff --git a/apps/desktop/src/main/messagePersistBroadcaster.ts b/apps/desktop/src/main/messagePersistBroadcaster.ts
index 5d60d81aeb..9319c46059 100644
--- a/apps/desktop/src/main/messagePersistBroadcaster.ts
+++ b/apps/desktop/src/main/messagePersistBroadcaster.ts
@@ -53,7 +53,9 @@ import { messages as messagesTable } from './localDb/schema.js';
import { getSubagentRunDetail } from './localDb/subagentRuns.js';
import { createLogger } from './logger.js';
import * as broadcastTap from './device-link/broadcast-tap.js';
+import { commitMessageMediaRefs } from './cindy-media/chatAttachments.js';
import { takeMediaToolResult } from './mcp-integrations/mediaToolResultFallback.js';
+import { capToolResultTextForPersist } from '../shared/toolResultPersistCap.js';
import { redactSensitiveText } from '@cindy/maker-shared/error-redaction';
import {
isAgentTaskToolName,
@@ -1293,6 +1295,31 @@ function toolResultMeta(sessionId: string, agentMeta: AgentMeta | null): AgentMe
return agentMeta ?? lastAgentMetaBySession.get(sessionId) ?? null;
}
+/**
+ * tool_result 的落库正文:超限截到 8KB(toolResultPersistCap)。渲染端在途气泡
+ * 与本函数的返回值(resolvedContent)继续用全文,只有 DB 行有界——重开任务时
+ * 才会看到截断标记。
+ *
+ * 截断前必须对**原文**扫媒体 URL 挂账:createMessage / updateMessageContent 的
+ * 挂账钩子只能看到截断后的内容,被截掉的尾部若含首次出现的 cindy-media blob URL,
+ * 不在这里补挂就会被 recycler 判零引用回收(聊天历史永久缺图)。幂等(hasRef
+ * 跳过),失败仅 warn,不阻断落库。
+ */
+function persistableToolResultContent(sessionId: string, fullText: string): string {
+ const capped = capToolResultTextForPersist(fullText);
+ if (capped !== fullText) {
+ void commitMessageMediaRefs({ sessionId, role: 'tool_result', content: fullText }).catch(
+ (err) => {
+ log.warn('tool_result media ref commit failed (pre-truncation)', {
+ sessionId,
+ error: err instanceof Error ? err.message : String(err),
+ });
+ },
+ );
+ }
+ return capped;
+}
+
/**
* 处理 tool_result 事件(摘要 + toolUseIds[]),解析出这条 tool_result 的
* { persistId, content } 供 onEvent 盖进 payload 让 renderer 即时显示,并落库(create
@@ -1365,10 +1392,17 @@ export function onToolResultEvent(
if (backgroundState) releaseBackgroundStateForToolUses(sessionId, backgroundState, ids);
return { persistId: existing, content: prev ?? content };
}
+ // contentMap 存全文(增长比较与 renderer 显示都要它);DB 只落有界内容。
+ // 截断后内容没变(全文都在 8KB 之外增长)就跳过 UPDATE——省掉重复写同一
+ // 前缀,也省掉 messages 表 UPDATE 附带的 FTS 触发器开销。
+ const cappedPrev = capToolResultTextForPersist(prev);
contentMap.set(existing, content);
- enqueueWrite(`tool_result_update:${sessionId}:${existing}`, () =>
- updateDbMessageContent(sessionId, existing!, content),
- );
+ const capped = persistableToolResultContent(sessionId, content);
+ if (capped !== cappedPrev) {
+ enqueueWrite(`tool_result_update:${sessionId}:${existing}`, () =>
+ updateDbMessageContent(sessionId, existing!, capped),
+ );
+ }
if (scope !== 'background') notePersistedMessage(sessionId, 'tool_result', existing);
if (backgroundState) releaseBackgroundStateForToolUses(sessionId, backgroundState, ids);
return { persistId: existing, content };
@@ -1380,7 +1414,7 @@ export function onToolResultEvent(
enqueueVisibleDbMessage(`tool_result:${sessionId}:${persistId}`, sessionId, {
clientId: persistId,
role: 'tool_result',
- content,
+ content: persistableToolResultContent(sessionId, content),
toolUseId: primaryToolUseId,
agentMeta: backgroundState ? backgroundState.agentMeta : toolResultMeta(sessionId, agentMeta),
createdAt,
@@ -1436,7 +1470,7 @@ export function onToolResultFullEvent(
enqueueVisibleDbMessage(`tool_result_eager:${sessionId}:${persistId}`, sessionId, {
clientId: persistId,
role: 'tool_result',
- content: fullText,
+ content: persistableToolResultContent(sessionId, fullText),
toolUseId,
agentMeta: backgroundState ? backgroundState.agentMeta : toolResultMeta(sessionId, agentMeta),
createdAt: clampAfterToolUse(
@@ -1456,10 +1490,16 @@ export function onToolResultFullEvent(
const prev = contentMap.get(target);
if (prev === fullText) return null; // 幂等:内容没变,renderer 无需更新。
+ // 同 onToolResultEvent 增长分支:contentMap 存全文,DB 只落有界内容,截断后
+ // 内容不变则跳过 UPDATE(renderer 仍拿全文刷新显示)。
+ const cappedPrev = prev === undefined ? undefined : capToolResultTextForPersist(prev);
contentMap.set(target, fullText);
- enqueueWrite(`tool_result_full:${sessionId}:${target}`, () =>
- updateDbMessageContent(sessionId, target, fullText),
- );
+ const capped = persistableToolResultContent(sessionId, fullText);
+ if (capped !== cappedPrev) {
+ enqueueWrite(`tool_result_full:${sessionId}:${target}`, () =>
+ updateDbMessageContent(sessionId, target, capped),
+ );
+ }
if (scope !== 'background') notePersistedMessage(sessionId, 'tool_result', target);
return { persistId: target, content: fullText };
}
@@ -1609,7 +1649,7 @@ export function flushOrphanToolResults(sessionId: string, agentMeta: AgentMeta |
enqueueVisibleDbMessage(`tool_result_orphan:${sessionId}:${persistId}`, sessionId, {
clientId: persistId,
role: 'tool_result',
- content: text,
+ content: persistableToolResultContent(sessionId, text),
toolUseId,
agentMeta: meta,
createdAt: clampAfterToolUse(sessionId, toolUseId, createdAt),
diff --git a/apps/desktop/src/shared/__tests__/toolResultPersistCap.test.ts b/apps/desktop/src/shared/__tests__/toolResultPersistCap.test.ts
new file mode 100644
index 0000000000..6398d9afac
--- /dev/null
+++ b/apps/desktop/src/shared/__tests__/toolResultPersistCap.test.ts
@@ -0,0 +1,57 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ TOOL_RESULT_PERSIST_CONTENT_LIMIT,
+ TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX,
+ capImportedToolResultContent,
+ capToolResultTextForPersist,
+} from '../toolResultPersistCap';
+
+describe('capToolResultTextForPersist', () => {
+ it('returns short text unchanged', () => {
+ expect(capToolResultTextForPersist('hello')).toBe('hello');
+ const exact = 'x'.repeat(TOOL_RESULT_PERSIST_CONTENT_LIMIT);
+ expect(capToolResultTextForPersist(exact)).toBe(exact);
+ });
+
+ it('caps oversized text to the limit with a truncation suffix', () => {
+ const big = 'a'.repeat(TOOL_RESULT_PERSIST_CONTENT_LIMIT + 1);
+ const capped = capToolResultTextForPersist(big);
+ expect(capped.length).toBeLessThanOrEqual(TOOL_RESULT_PERSIST_CONTENT_LIMIT);
+ expect(capped.endsWith(TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX)).toBe(true);
+ expect(capped.startsWith('aaa')).toBe(true);
+ });
+
+ it('is idempotent', () => {
+ const big = 'b'.repeat(TOOL_RESULT_PERSIST_CONTENT_LIMIT * 3);
+ const once = capToolResultTextForPersist(big);
+ expect(capToolResultTextForPersist(once)).toBe(once);
+ });
+
+ it('does not split a surrogate pair at the cut point', () => {
+ const budget = TOOL_RESULT_PERSIST_CONTENT_LIMIT - TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX.length;
+ const text = `${'x'.repeat(budget - 1)}😀${'y'.repeat(2 * TOOL_RESULT_PERSIST_CONTENT_LIMIT)}`;
+ const capped = capToolResultTextForPersist(text);
+ const kept = capped.slice(0, capped.length - TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX.length);
+ const lastCode = kept.charCodeAt(kept.length - 1);
+ expect(lastCode >= 0xd800 && lastCode <= 0xdbff).toBe(false);
+ expect(kept).toBe('x'.repeat(budget - 1));
+ });
+
+ it('respects a custom limit', () => {
+ const capped = capToolResultTextForPersist('c'.repeat(300), 100);
+ expect(capped.length).toBeLessThanOrEqual(100);
+ expect(capped.endsWith(TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX)).toBe(true);
+ });
+});
+
+describe('capImportedToolResultContent', () => {
+ it('caps string tool_result and leaves other roles alone', () => {
+ const huge = 'z'.repeat(TOOL_RESULT_PERSIST_CONTENT_LIMIT * 2);
+ const capped = capImportedToolResultContent('tool_result', huge);
+ expect(typeof capped).toBe('string');
+ expect((capped as string).length).toBeLessThanOrEqual(TOOL_RESULT_PERSIST_CONTENT_LIMIT);
+ expect(capImportedToolResultContent('assistant', huge)).toBe(huge);
+ expect(capImportedToolResultContent('tool_result', { text: huge })).toEqual({ text: huge });
+ });
+});
diff --git a/apps/desktop/src/shared/toolResultPersistCap.ts b/apps/desktop/src/shared/toolResultPersistCap.ts
new file mode 100644
index 0000000000..ea381b441a
--- /dev/null
+++ b/apps/desktop/src/shared/toolResultPersistCap.ts
@@ -0,0 +1,44 @@
+/**
+ * tool_result 落库正文上限(chat-data perf):全文不再无界写进 messages.content。
+ *
+ * 背景:7GB 级本地库里 tool_result 占了绝对大头(单条可达 MB 级、177 万行里
+ * 4.5GB),而它既不进 FTS、不进嵌入、不做侧栏预览,device-link 同步到手机也早已
+ * 截到 8KB(dispatch.ts REMOTE_TOOL_RESULT_CONTENT_LIMIT)。本地持久化对齐同一
+ * 阈值:重开任务仍能看到开头 8K 字符,当前 turn 的完整内容继续走内存
+ * resolvedContent,Agent 续跑走 SDK transcript,不依赖这张表。
+ *
+ * 媒体挂账契约:截断丢弃的尾部可能含首次出现的 cindy-media blob URL,调用方
+ * 必须**先对原文扫 URL 挂账、再截断**(见 messagePersistBroadcaster 的
+ * persistableToolResultContent),否则生成产物会被 recycler 判零引用回收。
+ *
+ * 纯函数、无依赖:main 侧 broadcaster、Claude 导入准备层与 DB worker importer
+ * (tx.ts / inline worker fallback)共用同一份,保证所有写入口一个口径。
+ * 导入路径的媒体挂账在 main 侧对原文执行(worker 碰不到 cindy-media ledger)。
+ */
+
+export const TOOL_RESULT_PERSIST_CONTENT_LIMIT = 8 * 1024;
+
+export const TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX =
+ '\n\n[tool result truncated: stored first 8KB]';
+
+/**
+ * 把 tool_result 正文截到落库上限,超限时带截断后缀。按字符数截(不是字节):
+ * 上限的意义是"有界",不追求与 device-link 的字节口径逐字节一致。切点回退一位
+ * 避免劈开 surrogate pair。幂等:已截断的文本长度必然 <= 上限,不会二次截断。
+ */
+export function capToolResultTextForPersist(
+ text: string,
+ limit = TOOL_RESULT_PERSIST_CONTENT_LIMIT,
+): string {
+ if (text.length <= limit) return text;
+ let cut = Math.max(0, limit - TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX.length);
+ const lastKept = text.charCodeAt(cut - 1);
+ if (cut > 0 && lastKept >= 0xd800 && lastKept <= 0xdbff) cut -= 1;
+ return `${text.slice(0, cut)}${TOOL_RESULT_PERSIST_TRUNCATION_SUFFIX}`;
+}
+
+/** 导入行与 live 落库同一上限:只有字符串 tool_result 会被截;其它 role 原样返回。 */
+export function capImportedToolResultContent(role: string, content: unknown): unknown {
+ if (role !== 'tool_result' || typeof content !== 'string') return content;
+ return capToolResultTextForPersist(content);
+}