Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
perf(desktop): 收敛自动化与错误尾行查询开销 (#3556)
DavidShenXD7a52654e0fbf
diff --git a/apps/desktop/drizzle/0098_bright_baron_zemo.sql b/apps/desktop/drizzle/0098_bright_baron_zemo.sqlnew file mode 100644index 0000000000..e0ac49d1ec--- /dev/null+++ b/apps/desktop/drizzle/0098_bright_baron_zemo.sql@@ -0,0 +1 @@+SELECT 1;diff --git a/apps/desktop/drizzle/meta/0098_snapshot.json b/apps/desktop/drizzle/meta/0098_snapshot.jsonnew file mode 100644index 0000000000..0ceca55e7c--- /dev/null+++ b/apps/desktop/drizzle/meta/0098_snapshot.json@@ -0,0 +1,4557 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "254c59fb-6027-454f-b038-de7548595750",+ "prevId": "1a52644f-09ab-4a17-ad9d-878590e73f6d",+ "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",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "sessions",+ "columnsFrom": [+ "target_session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "media_blobs",+ "columnsFrom": [+ "hash"+ ],+ "columnsTo": [+ "hash"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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+ },+ "idx_messages_active_error_tail": {+ "name": "idx_messages_active_error_tail",+ "columns": [+ "session_id",+ "created_at"+ ],+ "isUnique": false,+ "where": "\"messages\".\"role\" = 'error' AND \"messages\".\"rewind_at\" IS NULL"+ }+ },+ "foreignKeys": {+ "messages_session_id_sessions_id_fk": {+ "name": "messages_session_id_sessions_id_fk",+ "tableFrom": "messages",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "messages_fts_rows": {+ "name": "messages_fts_rows",+ "columns": {+ "fts_rowid": {+ "name": "fts_rowid",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "message_id": {+ "name": "message_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "messages_fts_rows_message_id_idx": {+ "name": "messages_fts_rows_message_id_idx",+ "columns": [+ "message_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "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"+ ],+ "isUnique": true,+ "where": "\"orca_teams\".\"status\" = 'active'"+ },+ "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",+ "tableTo": "sessions",+ "columnsFrom": [+ "lead_session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "orca_teams",+ "columnsFrom": [+ "team_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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"+ ],+ "isUnique": true,+ "where": "\"orca_workers\".\"focused\" = 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",+ "tableTo": "orca_teams",+ "columnsFrom": [+ "team_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "orca_workers_session_id_sessions_id_fk": {+ "name": "orca_workers_session_id_sessions_id_fk",+ "tableFrom": "orca_workers",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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"+ ],+ "isUnique": true,+ "where": "\"right_sidebar_tabs\".\"kind\" = 'subagents'"+ }+ },+ "foreignKeys": {+ "right_sidebar_tabs_session_id_sessions_id_fk": {+ "name": "right_sidebar_tabs_session_id_sessions_id_fk",+ "tableFrom": "right_sidebar_tabs",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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+ },+ "idx_schedule_runs_running_schedule": {+ "name": "idx_schedule_runs_running_schedule",+ "columns": [+ "schedule_id"+ ],+ "isUnique": false,+ "where": "\"schedule_runs\".\"status\" = 'running'"+ },+ "idx_schedule_runs_running_heartbeat": {+ "name": "idx_schedule_runs_running_heartbeat",+ "columns": [+ "heartbeat_at"+ ],+ "isUnique": false,+ "where": "\"schedule_runs\".\"status\" = 'running' AND \"schedule_runs\".\"heartbeat_at\" IS NOT NULL"+ },+ "idx_schedule_runs_running_legacy": {+ "name": "idx_schedule_runs_running_legacy",+ "columns": [+ "fired_at"+ ],+ "isUnique": false,+ "where": "\"schedule_runs\".\"status\" = 'running' AND \"schedule_runs\".\"heartbeat_at\" IS NULL"+ },+ "idx_schedule_runs_unread_terminal": {+ "name": "idx_schedule_runs_unread_terminal",+ "columns": [+ "schedule_id",+ "status",+ "fired_at"+ ],+ "isUnique": false,+ "where": "\"schedule_runs\".\"read_at\" IS NULL AND \"schedule_runs\".\"status\" IN ('success', 'failed', 'aborted', 'interrupted')"+ },+ "idx_schedule_runs_session_latest": {+ "name": "idx_schedule_runs_session_latest",+ "columns": [+ "session_id",+ "fired_at",+ "id"+ ],+ "isUnique": false,+ "where": "\"schedule_runs\".\"session_id\" IS NOT NULL"+ }+ },+ "foreignKeys": {+ "schedule_runs_schedule_id_schedules_id_fk": {+ "name": "schedule_runs_schedule_id_schedules_id_fk",+ "tableFrom": "schedule_runs",+ "tableTo": "schedules",+ "columnsFrom": [+ "schedule_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "schedule_runs_session_id_sessions_id_fk": {+ "name": "schedule_runs_session_id_sessions_id_fk",+ "tableFrom": "schedule_runs",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "schedule_session_latest_runs": {+ "name": "schedule_session_latest_runs",+ "columns": {+ "session_id": {+ "name": "session_id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "run_id": {+ "name": "run_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "fired_at": {+ "name": "fired_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "idx_schedule_session_latest_runs_run": {+ "name": "idx_schedule_session_latest_runs_run",+ "columns": [+ "run_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "schedule_session_latest_runs_session_id_sessions_id_fk": {+ "name": "schedule_session_latest_runs_session_id_sessions_id_fk",+ "tableFrom": "schedule_session_latest_runs",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "schedule_session_latest_runs_run_id_schedule_runs_id_fk": {+ "name": "schedule_session_latest_runs_run_id_schedule_runs_id_fk",+ "tableFrom": "schedule_session_latest_runs",+ "tableTo": "schedule_runs",+ "columnsFrom": [+ "run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "sessions",+ "columnsFrom": [+ "target_session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "schedules_skip_log_session_id_sessions_id_fk": {+ "name": "schedules_skip_log_session_id_sessions_id_fk",+ "tableFrom": "schedules",+ "tableTo": "sessions",+ "columnsFrom": [+ "skip_log_session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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+ },+ "list_preview": {+ "name": "list_preview",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "list_preview_role": {+ "name": "list_preview_role",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "list_message_count": {+ "name": "list_message_count",+ "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",+ "tableTo": "sessions",+ "columnsFrom": [+ "parent_session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "skill_usage_sources",+ "columnsFrom": [+ "raw_file_path"+ ],+ "columnsTo": [+ "raw_file_path"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "subagent_run_aliases_run_id_subagent_runs_id_fk": {+ "name": "subagent_run_aliases_run_id_subagent_runs_id_fk",+ "tableFrom": "subagent_run_aliases",+ "tableTo": "subagent_runs",+ "columnsFrom": [+ "run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "wechat_sync_state",+ "columnsFrom": [+ "binding_epoch"+ ],+ "columnsTo": [+ "binding_epoch"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "wechat_file_attachments_task_id_wechat_inbox_id_fk": {+ "name": "wechat_file_attachments_task_id_wechat_inbox_id_fk",+ "tableFrom": "wechat_file_attachments",+ "tableTo": "wechat_inbox",+ "columnsFrom": [+ "task_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "wechat_file_attachments_session_id_sessions_id_fk": {+ "name": "wechat_file_attachments_session_id_sessions_id_fk",+ "tableFrom": "wechat_file_attachments",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "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"+ ],+ "isUnique": true,+ "where": "\"wechat_inbox\".\"session_id\" IS NOT NULL AND \"wechat_inbox\".\"status\" IN ('dispatching', 'accepted_running', 'waiting_desktop', 'delivery_pending')"+ }+ },+ "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",+ "tableTo": "wechat_sync_state",+ "columnsFrom": [+ "binding_epoch"+ ],+ "columnsTo": [+ "binding_epoch"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "wechat_inbox_session_id_sessions_id_fk": {+ "name": "wechat_inbox_session_id_sessions_id_fk",+ "tableFrom": "wechat_inbox",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "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",+ "tableTo": "wechat_sync_state",+ "columnsFrom": [+ "binding_epoch"+ ],+ "columnsTo": [+ "binding_epoch"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "wechat_outbox_task_id_wechat_inbox_id_fk": {+ "name": "wechat_outbox_task_id_wechat_inbox_id_fk",+ "tableFrom": "wechat_outbox",+ "tableTo": "wechat_inbox",+ "columnsFrom": [+ "task_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "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"+ ],+ "isUnique": true,+ "where": "\"wechat_sync_state\".\"is_active\" = 1"+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ }+ },+ "views": {},+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ },+ "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 filediff --git a/apps/desktop/drizzle/meta/_journal.json b/apps/desktop/drizzle/meta/_journal.jsonindex 4a07f73df8..e040cbc666 100644--- a/apps/desktop/drizzle/meta/_journal.json+++ b/apps/desktop/drizzle/meta/_journal.json@@ -687,6 +687,13 @@"when": 1787739425748,"tag": "0097_fresh_stryfe","breakpoints": true+ },+ {+ "idx": 98,+ "version": "6",+ "when": 1787833091152,+ "tag": "0098_bright_baron_zemo",+ "breakpoints": true}]}\ No newline at end of filediff --git a/apps/desktop/drizzle/scripts/0098_bright_baron_zemo.ts b/apps/desktop/drizzle/scripts/0098_bright_baron_zemo.tsnew file mode 100644index 0000000000..58d5d2565b--- /dev/null+++ b/apps/desktop/drizzle/scripts/0098_bright_baron_zemo.ts@@ -0,0 +1,145 @@+function tableHasColumns(db, name, requiredColumns) {+ const table = db+ .prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?")+ .get(name);+ if (!table) return false;+ const columns = new Set(db.prepare(`PRAGMA table_info(${name})`).all().map((row) => row.name));+ return requiredColumns.every((column) => columns.has(column));+}++function run(db) {+ if (tableHasColumns(db, 'messages', ['session_id', 'created_at', 'role', 'rewind_at'])) {+ db.exec(`+ CREATE INDEX IF NOT EXISTS idx_messages_active_error_tail+ ON messages (session_id, created_at)+ WHERE role = 'error' AND rewind_at IS NULL;+ `);+ }++ if (+ tableHasColumns(db, 'schedule_runs', [+ 'id',+ 'schedule_id',+ 'session_id',+ 'fired_at',+ 'status',+ 'read_at',+ 'heartbeat_at',+ ])+ ) {+ db.exec(`+ CREATE INDEX IF NOT EXISTS idx_schedule_runs_running_schedule+ ON schedule_runs (schedule_id) WHERE status = 'running';+ CREATE INDEX IF NOT EXISTS idx_schedule_runs_running_heartbeat+ ON schedule_runs (heartbeat_at)+ WHERE status = 'running' AND heartbeat_at IS NOT NULL;+ CREATE INDEX IF NOT EXISTS idx_schedule_runs_running_legacy+ ON schedule_runs (fired_at)+ WHERE status = 'running' AND heartbeat_at IS NULL;+ CREATE INDEX IF NOT EXISTS idx_schedule_runs_unread_terminal+ ON schedule_runs (schedule_id, status, fired_at)+ WHERE read_at IS NULL+ AND status IN ('success', 'failed', 'aborted', 'interrupted');+ CREATE INDEX IF NOT EXISTS idx_schedule_runs_session_latest+ ON schedule_runs (session_id, fired_at, id) WHERE session_id IS NOT NULL;+ `);+ }++ if (+ tableHasColumns(db, 'sessions', ['id']) &&+ tableHasColumns(db, 'schedule_runs', ['id', 'session_id', 'fired_at'])+ ) {+ db.exec(`+ CREATE TABLE IF NOT EXISTS schedule_session_latest_runs (+ session_id text PRIMARY KEY NOT NULL,+ run_id text NOT NULL,+ fired_at integer NOT NULL,+ FOREIGN KEY (session_id) REFERENCES sessions(id) ON UPDATE no action ON DELETE cascade,+ FOREIGN KEY (run_id) REFERENCES schedule_runs(id) ON UPDATE no action ON DELETE cascade+ );+ CREATE UNIQUE INDEX IF NOT EXISTS idx_schedule_session_latest_runs_run+ ON schedule_session_latest_runs (run_id);+ `);+ }++ if (+ !tableHasColumns(db, 'schedule_runs', ['id', 'session_id', 'fired_at']) ||+ !tableHasColumns(db, 'schedule_session_latest_runs', ['session_id', 'run_id', 'fired_at'])+ ) {+ return;+ }++ db.exec(`+ DELETE FROM schedule_session_latest_runs;+ INSERT INTO schedule_session_latest_runs (session_id, run_id, fired_at)+ SELECT session_id, id, fired_at+ FROM (+ SELECT session_id, id, fired_at,+ ROW_NUMBER() OVER (+ PARTITION BY session_id+ ORDER BY fired_at DESC, id DESC+ ) AS position+ FROM schedule_runs+ WHERE session_id IS NOT NULL+ )+ WHERE position = 1;++ CREATE TRIGGER IF NOT EXISTS schedule_session_latest_run_insert+ AFTER INSERT ON schedule_runs+ WHEN NEW.session_id IS NOT NULL+ BEGIN+ INSERT INTO schedule_session_latest_runs (session_id, run_id, fired_at)+ VALUES (NEW.session_id, NEW.id, NEW.fired_at)+ ON CONFLICT(session_id) DO UPDATE SET+ run_id = excluded.run_id,+ fired_at = excluded.fired_at+ WHERE excluded.fired_at > schedule_session_latest_runs.fired_at+ OR (excluded.fired_at = schedule_session_latest_runs.fired_at+ AND excluded.run_id > schedule_session_latest_runs.run_id);+ END;++ CREATE TRIGGER IF NOT EXISTS schedule_session_latest_run_delete+ AFTER DELETE ON schedule_runs+ WHEN OLD.session_id IS NOT NULL+ BEGIN+ DELETE FROM schedule_session_latest_runs+ WHERE session_id = OLD.session_id AND run_id = OLD.id;+ INSERT INTO schedule_session_latest_runs (session_id, run_id, fired_at)+ SELECT OLD.session_id, id, fired_at+ FROM schedule_runs+ WHERE session_id = OLD.session_id+ ORDER BY fired_at DESC, id DESC+ LIMIT 1+ ON CONFLICT(session_id) DO UPDATE SET+ run_id = excluded.run_id,+ fired_at = excluded.fired_at;+ END;++ CREATE TRIGGER IF NOT EXISTS schedule_session_latest_run_update+ AFTER UPDATE OF session_id, fired_at ON schedule_runs+ BEGIN+ DELETE FROM schedule_session_latest_runs+ WHERE session_id = OLD.session_id AND run_id = OLD.id;+ INSERT INTO schedule_session_latest_runs (session_id, run_id, fired_at)+ SELECT OLD.session_id, id, fired_at+ FROM schedule_runs+ WHERE OLD.session_id IS NOT NULL AND session_id = OLD.session_id+ ORDER BY fired_at DESC, id DESC+ LIMIT 1+ ON CONFLICT(session_id) DO UPDATE SET+ run_id = excluded.run_id,+ fired_at = excluded.fired_at;+ INSERT INTO schedule_session_latest_runs (session_id, run_id, fired_at)+ SELECT NEW.session_id, NEW.id, NEW.fired_at+ WHERE NEW.session_id IS NOT NULL+ ON CONFLICT(session_id) DO UPDATE SET+ run_id = excluded.run_id,+ fired_at = excluded.fired_at+ WHERE excluded.fired_at > schedule_session_latest_runs.fired_at+ OR (excluded.fired_at = schedule_session_latest_runs.fired_at+ AND excluded.run_id > schedule_session_latest_runs.run_id);+ END;+ `);+}++module.exports = { run };diff --git a/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts b/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.tsindex 8dbf3e09a4..86e6f96093 100644--- a/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts+++ b/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts@@ -87,6 +87,13 @@ function indexExists(db: Database.Database, indexName: string): boolean {);}+function triggerExists(db: Database.Database, triggerName: string): boolean {+ return (+ db.prepare("SELECT 1 FROM sqlite_master WHERE type='trigger' AND name=?").get(triggerName) !==+ undefined+ );+}+function columnNames(db: Database.Database, tableName: string): string[] {return db.prepare(`PRAGMA table_info('${tableName}')`)@@ -118,6 +125,14 @@ describeMigrationReplay('migration replay', () => {).pluck().all();+ const unreadRunPlan = db+ .prepare(+ `EXPLAIN QUERY PLAN+ SELECT count(*) FROM schedule_runs+ WHERE read_at IS NULL+ AND status IN ('success', 'failed', 'aborted', 'interrupted')`,+ )+ .all() as Array<{ detail: string }>;expect(result.applied.map((migration) => migration.seq)).toEqual(listMigrations(drizzleDir()).map((migration) => migration.seq),@@ -134,6 +149,18 @@ describeMigrationReplay('migration replay', () => {expect(tableExists(db, 'wechat_inbox')).toBe(true);expect(tableExists(db, 'wechat_outbox')).toBe(true);expect(tableExists(db, 'wechat_file_attachments')).toBe(true);+ expect(tableExists(db, 'schedule_session_latest_runs')).toBe(true);+ expect(indexExists(db, 'idx_messages_active_error_tail')).toBe(true);+ expect(indexExists(db, 'idx_schedule_runs_running_schedule')).toBe(true);+ expect(indexExists(db, 'idx_schedule_runs_running_heartbeat')).toBe(true);+ expect(indexExists(db, 'idx_schedule_runs_running_legacy')).toBe(true);+ expect(indexExists(db, 'idx_schedule_runs_unread_terminal')).toBe(true);+ expect(indexExists(db, 'idx_schedule_runs_session_latest')).toBe(true);+ expect(triggerExists(db, 'schedule_session_latest_run_insert')).toBe(true);+ expect(triggerExists(db, 'schedule_session_latest_run_delete')).toBe(true);+ expect(triggerExists(db, 'schedule_session_latest_run_update')).toBe(true);+ expect(unreadRunPlan.some((row) => row.detail.includes('idx_schedule_runs_unread_terminal')))+ .toBe(true);} finally {cleanup();}diff --git a/apps/desktop/src/main/localDb/schema.ts b/apps/desktop/src/main/localDb/schema.tsindex cc7f6c7076..fd9e01eab7 100644--- a/apps/desktop/src/main/localDb/schema.ts+++ b/apps/desktop/src/main/localDb/schema.ts@@ -404,6 +404,9 @@ export const messages = sqliteTable(// 游标分页先用 createdAt 过滤;同毫秒次序在 IPC 层用 SQLite rowid 保持写入顺序。idxCreatedAtId: index('idx_messages_created_at').on(t.createdAt, t.id),idxRewindAt: index('idx_messages_rewind_at').on(t.rewindAt),+ idxActiveErrorTail: index('idx_messages_active_error_tail')+ .on(t.sessionId, t.createdAt)+ .where(sql`${t.role} = 'error' AND ${t.rewindAt} IS NULL`),}),);@@ -1095,6 +1098,39 @@ export const scheduleRuns = sqliteTable(},(t) => ({idxBySchedule: index('idx_schedule_runs_schedule').on(t.scheduleId, t.firedAt),+ idxRunningSchedule: index('idx_schedule_runs_running_schedule')+ .on(t.scheduleId)+ .where(sql`${t.status} = 'running'`),+ idxRunningHeartbeat: index('idx_schedule_runs_running_heartbeat')+ .on(t.heartbeatAt)+ .where(sql`${t.status} = 'running' AND ${t.heartbeatAt} IS NOT NULL`),+ idxRunningLegacy: index('idx_schedule_runs_running_legacy')+ .on(t.firedAt)+ .where(sql`${t.status} = 'running' AND ${t.heartbeatAt} IS NULL`),+ idxUnreadTerminal: index('idx_schedule_runs_unread_terminal')+ .on(t.scheduleId, t.status, t.firedAt)+ .where(+ sql`${t.readAt} IS NULL AND ${t.status} IN ('success', 'failed', 'aborted', 'interrupted')`,+ ),+ idxSessionLatest: index('idx_schedule_runs_session_latest')+ .on(t.sessionId, t.firedAt, t.id)+ .where(sql`${t.sessionId} IS NOT NULL`),+ }),+);++export const scheduleSessionLatestRuns = sqliteTable(+ 'schedule_session_latest_runs',+ {+ sessionId: text('session_id')+ .primaryKey()+ .references(() => sessions.id, { onDelete: 'cascade' }),+ runId: text('run_id')+ .notNull()+ .references(() => scheduleRuns.id, { onDelete: 'cascade' }),+ firedAt: integer('fired_at').notNull(),+ },+ (t) => ({+ idxRun: uniqueIndex('idx_schedule_session_latest_runs_run').on(t.runId),}),);diff --git a/apps/desktop/src/main/maker-ipc/channels.ts b/apps/desktop/src/main/maker-ipc/channels.tsindex 38291d8d27..624a0aea1d 100644--- a/apps/desktop/src/main/maker-ipc/channels.ts+++ b/apps/desktop/src/main/maker-ipc/channels.ts@@ -592,9 +592,9 @@ export const MAKER_INVOKE = {/** 表单「AI 生成」:按自然语言描述生成前置检查脚本并落盘,返回可填入的命令。 */SCHEDULE_GENERATE_PRE_RUN_HOOK: 'maker:schedule:generate-pre-run-hook',SCHEDULE_LIST_RUNS: 'maker:schedule:list-runs',- /** Sidebar 聚合索引:带 sessionId 的 run + 未读终态 run,避免固定 history limit 截断。 */+ /** Sidebar 聚合索引:每个 session 最新映射 + 全部 running / 未读终态 run。 */SCHEDULE_LIST_SIDEBAR_INDEX_RUNS: 'maker:schedule:list-sidebar-index-runs',- /** Automation 列表总开销:按 schedule 去重 session 汇总 sessions.total_cost_usd。 */+ /** 已移除累计费用展示;保留 channel 供旧 device-link 控制端降级为空结果。 */SCHEDULE_LIST_COST_SUMMARIES: 'maker:schedule:list-cost-summaries',SCHEDULE_DELETE_RUN: 'maker:schedule:delete-run',/** Renderer 在 delete/pause 前查这条 schedule 当前有多少个 in-flight run,>0 时弹二次确认。 */diff --git a/apps/desktop/src/main/maker-ipc/schedule.ts b/apps/desktop/src/main/maker-ipc/schedule.tsindex 5ab1001f70..64294cf158 100644--- a/apps/desktop/src/main/maker-ipc/schedule.ts+++ b/apps/desktop/src/main/maker-ipc/schedule.ts@@ -560,9 +560,7 @@ export function registerScheduleHandlers(getMaker?: () => Maker | null): void {})),);- ipcMain.handle(MAKER_INVOKE.SCHEDULE_LIST_COST_SUMMARIES, async () =>- withScheduler(({ storage }) => storage.listCostSummaries()),- );+ ipcMain.handle(MAKER_INVOKE.SCHEDULE_LIST_COST_SUMMARIES, async () => []);ipcMain.handle(MAKER_INVOKE.SCHEDULE_DELETE_RUN, async (_e, runId: unknown) => {const id = requireString(runId, 'runId');diff --git a/apps/desktop/src/main/scheduler-host/__tests__/storage.db.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/storage.db.test.tsindex f01d9887e6..062f23bf99 100644--- a/apps/desktop/src/main/scheduler-host/__tests__/storage.db.test.ts+++ b/apps/desktop/src/main/scheduler-host/__tests__/storage.db.test.ts@@ -188,6 +188,72 @@ const SCHEDULER_DDL = [)`,'CREATE INDEX idx_schedule_runs_schedule ON schedule_runs(schedule_id, fired_at)',+ `+ CREATE TABLE schedule_session_latest_runs (+ session_id TEXT PRIMARY KEY REFERENCES sessions(id) ON DELETE CASCADE,+ run_id TEXT NOT NULL UNIQUE REFERENCES schedule_runs(id) ON DELETE CASCADE,+ fired_at INTEGER NOT NULL+ )+ `,+ `+ CREATE TRIGGER schedule_session_latest_run_insert+ AFTER INSERT ON schedule_runs+ WHEN NEW.session_id IS NOT NULL+ BEGIN+ INSERT INTO schedule_session_latest_runs (session_id, run_id, fired_at)+ VALUES (NEW.session_id, NEW.id, NEW.fired_at)+ ON CONFLICT(session_id) DO UPDATE SET+ run_id = excluded.run_id,+ fired_at = excluded.fired_at+ WHERE excluded.fired_at > schedule_session_latest_runs.fired_at+ OR (excluded.fired_at = schedule_session_latest_runs.fired_at+ AND excluded.run_id > schedule_session_latest_runs.run_id);+ END+ `,+ `+ CREATE TRIGGER schedule_session_latest_run_delete+ AFTER DELETE ON schedule_runs+ WHEN OLD.session_id IS NOT NULL+ BEGIN+ DELETE FROM schedule_session_latest_runs+ WHERE session_id = OLD.session_id AND run_id = OLD.id;+ INSERT INTO schedule_session_latest_runs (session_id, run_id, fired_at)+ SELECT OLD.session_id, id, fired_at+ FROM schedule_runs+ WHERE session_id = OLD.session_id+ ORDER BY fired_at DESC, id DESC+ LIMIT 1+ ON CONFLICT(session_id) DO UPDATE SET+ run_id = excluded.run_id,+ fired_at = excluded.fired_at;+ END+ `,+ `+ CREATE TRIGGER schedule_session_latest_run_update+ AFTER UPDATE OF session_id, fired_at ON schedule_runs+ BEGIN+ DELETE FROM schedule_session_latest_runs+ WHERE session_id = OLD.session_id AND run_id = OLD.id;+ INSERT INTO schedule_session_latest_runs (session_id, run_id, fired_at)+ SELECT OLD.session_id, id, fired_at+ FROM schedule_runs+ WHERE OLD.session_id IS NOT NULL AND session_id = OLD.session_id+ ORDER BY fired_at DESC, id DESC+ LIMIT 1+ ON CONFLICT(session_id) DO UPDATE SET+ run_id = excluded.run_id,+ fired_at = excluded.fired_at;+ INSERT INTO schedule_session_latest_runs (session_id, run_id, fired_at)+ SELECT NEW.session_id, NEW.id, NEW.fired_at+ WHERE NEW.session_id IS NOT NULL+ ON CONFLICT(session_id) DO UPDATE SET+ run_id = excluded.run_id,+ fired_at = excluded.fired_at+ WHERE excluded.fired_at > schedule_session_latest_runs.fired_at+ OR (excluded.fired_at = schedule_session_latest_runs.fired_at+ AND excluded.run_id > schedule_session_latest_runs.run_id);+ END+ `,];function createStorageHarness() {@@ -279,6 +345,140 @@ describe('DrizzleScheduleStorage (in-memory)', () => {}});+ it('returns one latest session mapping plus bounded running and unread rows', async () => {+ const harness = createStorageHarness();+ const schedule = baseSchedule({ id: 'sch-sidebar-index' });+ try {+ harness.db.run(sql`+ INSERT INTO sessions (id, title, source, workspace_kind, created_at, updated_at)+ VALUES ('sess-sidebar-index', 'Persistent schedule session', 'desktop', 'dialogue', 1, 1)+ `);+ await harness.storage.insert(schedule);+ await harness.storage.insertRun({+ id: 'run-old-read',+ scheduleId: schedule.id,+ sessionId: 'sess-sidebar-index',+ firedAt: 10,+ finishedAt: 11,+ status: 'success',+ readAt: 11,+ });+ await harness.storage.insertRun({+ id: 'run-old-running',+ scheduleId: schedule.id,+ sessionId: 'sess-sidebar-index',+ firedAt: 12,+ status: 'running',+ });+ await harness.storage.insertRun({+ id: 'run-old-unread',+ scheduleId: schedule.id,+ sessionId: 'sess-sidebar-index',+ firedAt: 15,+ finishedAt: 16,+ status: 'failed',+ });+ await harness.storage.insertRun({+ id: 'run-latest-read',+ scheduleId: schedule.id,+ sessionId: 'sess-sidebar-index',+ firedAt: 20,+ finishedAt: 21,+ status: 'success',+ readAt: 21,+ });++ const initial = new Map(+ (await harness.storage.listSidebarIndexRuns()).map((run) => [run.runId, run]),+ );+ expect([...initial.keys()]).toEqual([+ 'run-old-unread',+ 'run-old-running',+ 'run-latest-read',+ ]);+ expect(initial.get('run-latest-read')?.sessionId).toBe('sess-sidebar-index');+ expect(initial.get('run-old-unread')?.sessionId).toBe('sess-sidebar-index');+ expect(initial.get('run-old-running')?.sessionId).toBeUndefined();++ await harness.storage.deleteRun('run-latest-read');+ const afterDelete = new Map(+ (await harness.storage.listSidebarIndexRuns()).map((run) => [run.runId, run]),+ );+ expect(afterDelete.get('run-old-unread')?.sessionId).toBe('sess-sidebar-index');++ await harness.storage.updateRun('run-old-running', { firedAt: 30 });+ const afterUpdate = new Map(+ (await harness.storage.listSidebarIndexRuns()).map((run) => [run.runId, run]),+ );+ expect(afterUpdate.get('run-old-running')?.sessionId).toBe('sess-sidebar-index');+ expect(afterUpdate.get('run-old-unread')?.sessionId).toBe('sess-sidebar-index');+ expect([...afterUpdate.keys()]).toEqual(['run-old-unread', 'run-old-running']);++ harness.db.run(sql`DELETE FROM sessions WHERE id = 'sess-sidebar-index'`);+ await expect(harness.db.select().from(schema.scheduleSessionLatestRuns)).resolves.toEqual([]);+ expect(+ (await harness.storage.listSidebarIndexRuns()).every((run) => run.sessionId === undefined),+ ).toBe(true);+ } finally {+ harness.close();+ }+ });++ it('keeps renamed legacy aliases from the latest-session projection', async () => {+ const harness = createStorageHarness();+ const schedule = baseSchedule({+ id: 'sch-renamed-legacy',+ name: 'new automation name',+ workingDir: '/repo',+ });+ try {+ harness.db.run(sql`+ INSERT INTO sessions (+ id, title, source, workspace_kind, working_dir, created_at, updated_at+ ) VALUES+ (+ 'sess-renamed-anchor', '[Schedule] old automation name', 'scheduler',+ 'project', '/repo', 1, 1+ ),+ (+ 'sess-renamed-orphan', '[Schedule] old automation name', 'scheduler',+ 'project', '/repo', 2, 2+ )+ `);+ await harness.storage.insert(schedule);+ enableLegacySessionFallback(harness, schedule.id);+ await harness.storage.insertRun({+ id: 'run-renamed-anchor',+ scheduleId: schedule.id,+ sessionId: 'sess-renamed-anchor',+ firedAt: 10,+ finishedAt: 11,+ status: 'success',+ readAt: 11,+ });++ const runs = await harness.storage.listSidebarIndexRuns();++ expect(runs).toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ runId: 'run-renamed-anchor',+ scheduleId: schedule.id,+ sessionId: 'sess-renamed-anchor',+ }),+ expect.objectContaining({+ runId: 'legacy-session:sess-renamed-orphan',+ scheduleId: schedule.id,+ sessionId: 'sess-renamed-orphan',+ }),+ ]),+ );+ expect(runs).toHaveLength(2);+ } finally {+ harness.close();+ }+ });+it('hydrates exact run cost from persisted assistant runId metadata', async () => {const harness = createStorageHarness();const schedule = baseSchedule({ id: 'sch-run-cost' });@@ -300,9 +500,9 @@ describe('DrizzleScheduleStorage (in-memory)', () => {INSERT INTO messages (id, client_id, session_id, role, content, agent_meta, created_at)VALUES('run-exact-assistant-1', 'run-exact-assistant-1', 'sess-run-cost', 'assistant', '{}',- '{"origin":{"kind":"scheduler","scheduleId":"sch-run-cost","runId":"run-exact"},"turnCostUsd":0.42}', 11),+ '{"origin":{"kind":"scheduler","scheduleId":"sch-run-cost","runId":"run-exact"},"turnCostUsd":0.42,"turnUsageDetails":{"inputTokens":100,"outputTokens":20,"cacheReadTokens":30,"cacheCreateTokens":5}}', 11),('run-exact-assistant-2', 'run-exact-assistant-2', 'sess-run-cost', 'assistant', '{}',- '{"origin":{"kind":"scheduler","scheduleId":"sch-run-cost","runId":"run-exact"},"turnCostUsd":0.29,"turnCostIsEstimate":true}', 12)+ '{"origin":{"kind":"scheduler","scheduleId":"sch-run-cost","runId":"run-exact"},"turnCostUsd":0.29,"turnCostIsEstimate":true,"turnUsageDetails":{"inputTokens":200,"outputTokens":25,"cacheReadTokens":50,"cacheCreateTokens":0}}', 12)`);await expect(harness.storage.listRuns(schedule.id)).resolves.toEqual([@@ -312,6 +512,7 @@ describe('DrizzleScheduleStorage (in-memory)', () => {estimatedValueUsd: 0,costMoney: actualMoneyFromLegacyUsd(0.42),estimatedValueMoney: estimatedMoneyFromLegacyUsd(0.29),+ totalTokens: 430,costAttribution: 'exact',}),]);diff --git a/apps/desktop/src/main/scheduler-host/storage.ts b/apps/desktop/src/main/scheduler-host/storage.tsindex 71170952cd..a1afa4590f 100644--- a/apps/desktop/src/main/scheduler-host/storage.ts+++ b/apps/desktop/src/main/scheduler-host/storage.ts@@ -21,7 +21,13 @@ import { broadcastSessionPatched } from '../localDb/ipc/sessions.js';import type { Schedule, ScheduleRun, ScheduleStorage, ListFilter } from '@cindy/maker-scheduler';import * as schema from '../localDb/schema';-import { messages, schedules, scheduleRuns, sessions } from '../localDb/schema';+import {+ messages,+ schedules,+ scheduleRuns,+ scheduleSessionLatestRuns,+ sessions,+} from '../localDb/schema';import {scheduleToCamel,scheduleCreateToRow,@@ -39,6 +45,7 @@ import {type RegionalMoney,zeroUsageMoney,} from '../../shared/regionalMoney.js';+import { normalizeTurnUsageDetails } from '../../shared/turnUsageDetails.js';export type SchedulerDrizzleDb = BetterSQLite3Database<typeof schema>;@@ -165,12 +172,8 @@ interface LegacyScheduleSessionAlias {const LEGACY_SCHEDULE_TITLE_PREFIX = '[Schedule] ';const LEGACY_SESSION_RUN_ID_PREFIX = 'legacy-session:';-const UNREAD_TERMINAL_RUN_STATUSES: ScheduleRun['status'][] = [- 'success',- 'failed',- 'aborted',- 'interrupted',-];+const unreadTerminalRunWhere = () =>+ sql`${scheduleRuns.readAt} IS NULL AND ${scheduleRuns.status} IN ('success', 'failed', 'aborted', 'interrupted')`;function toScheduleSource(value: string | null): Schedule['source'] | undefined {if (value === 'user' || value === 'project') return value;@@ -235,12 +238,14 @@ function turnCostFromAgentMeta(agentMeta: string | null): {costMoney: RegionalMoney | null;estimatedValueMoney: RegionalMoney | null;legacyProjectedActualAmount: number;+ totalTokens: number;} {if (!agentMeta) {return {costMoney: null,estimatedValueMoney: null,legacyProjectedActualAmount: 0,+ totalTokens: 0,};}try {@@ -248,7 +253,9 @@ function turnCostFromAgentMeta(agentMeta: string | null): {turnCost?: unknown;turnCostUsd?: unknown;turnCostIsEstimate?: unknown;+ turnUsageDetails?: unknown;};+ const totalTokens = normalizeTurnUsageDetails(parsed.turnUsageDetails)?.totalTokens ?? 0;const structured = normalizeRegionalMoney(parsed.turnCost);const legacy =typeof parsed.turnCostUsd === 'number' &&@@ -262,6 +269,7 @@ function turnCostFromAgentMeta(agentMeta: string | null): {costMoney: null,estimatedValueMoney: null,legacyProjectedActualAmount: 0,+ totalTokens,};}const isEstimate = parsed.turnCostIsEstimate === true || money.kind === 'value-estimate';@@ -269,12 +277,14 @@ function turnCostFromAgentMeta(agentMeta: string | null): {costMoney: isEstimate ? null : money,estimatedValueMoney: isEstimate ? asValueEstimateMoney(money) : null,legacyProjectedActualAmount: !structured && !isEstimate ? money.amount : 0,+ totalTokens,};} catch {return {costMoney: null,estimatedValueMoney: null,legacyProjectedActualAmount: 0,+ totalTokens: 0,};}}@@ -484,9 +494,9 @@ export class DrizzleScheduleStorage implements ScheduleStorage {}/**- * message agent_meta 是 runId + 单段费用的持久化账本。正常路径已同步更新- * schedule_runs 聚合;这里在读取时用消息账本覆盖,修复进程恰好在两次写之间退出- * 留下的短暂不一致。legacy run 没有 runId,保持“不可精确拆分”。+ * message agent_meta 是 runId、单段费用与 Token 用量的持久化账本。正常路径已同步更新+ * schedule_runs 费用聚合;这里在读取时用消息账本覆盖费用,并顺手汇总展示所需 Token,+ * 不增加额外查询。legacy run 没有 runId,保持“不可精确拆分”。*/private async hydrateRunCostsFromMessages(db: SchedulerDrizzleDb,@@ -519,7 +529,7 @@ export class DrizzleScheduleStorage implements ScheduleStorage {).flat();const ledger = new Map<string,- { costValues: RegionalMoney[]; estimatedValues: RegionalMoney[] }+ { costValues: RegionalMoney[]; estimatedValues: RegionalMoney[]; totalTokens: number }>();for (const row of rows) {const origin = scheduleOriginFromAgentMeta(row.agentMeta);@@ -528,11 +538,13 @@ export class DrizzleScheduleStorage implements ScheduleStorage {const current = ledger.get(origin.runId) ?? {costValues: [],estimatedValues: [],+ totalTokens: 0,};if (cost.costMoney) current.costValues.push(cost.costMoney);if (cost.estimatedValueMoney) {current.estimatedValues.push(cost.estimatedValueMoney);}+ current.totalTokens += cost.totalTokens;ledger.set(origin.runId, current);}@@ -552,6 +564,7 @@ export class DrizzleScheduleStorage implements ScheduleStorage {];return {...run,+ ...(persisted.totalTokens > 0 ? { totalTokens: persisted.totalTokens } : {}),costMoney:addCompatibleRegionalMoney(costValues,@@ -566,10 +579,15 @@ export class DrizzleScheduleStorage implements ScheduleStorage {};}if (run.costAttribution === 'mixed') {- return { ...run, costAttribution: 'exact' };+ return {+ ...run,+ ...(persisted.totalTokens > 0 ? { totalTokens: persisted.totalTokens } : {}),+ costAttribution: 'exact',+ };}return {...run,+ ...(persisted.totalTokens > 0 ? { totalTokens: persisted.totalTokens } : {}),costMoney:addCompatibleRegionalMoney(persisted.costValues) ??zeroUsageMoney(),@@ -583,37 +601,53 @@ export class DrizzleScheduleStorage implements ScheduleStorage {/*** Sidebar 聚合索引用的轻量 run 列表:- * - 所有带 sessionId 的 run 都返回,保证高频 schedule 超过 history limit 后仍能归组。- * - 额外包含无 sessionId 的未读终态 run,保证自动化任务列表的小红点不被漏掉。+ * - 每个 session 只返回最新的 run 映射,读取量不随同一任务的运行次数增长。+ * - 额外包含全部 running 与未读终态 run,供运行标记对账和未读计数。+ * - 未读旧 run 先返回以累计 session 红点,最新映射最后返回以裁决 Automation 归属。+ * - 非最新 running 不携带 sessionId,只参与运行标记对账。*/async listSidebarIndexRuns(): Promise<ScheduleSidebarIndexRun[]> {const db = this.getDb();- const rows = await db- .select({- runId: scheduleRuns.id,- scheduleId: schedules.id,- scheduleName: schedules.name,- scheduleStatus: schedules.status,- scheduleSource: schedules.source,- nextFireAt: schedules.nextFireAt,- workingDir: schedules.workingDir,- projectConfigId: schedules.projectConfigId,- sessionId: scheduleRuns.sessionId,- status: scheduleRuns.status,- readAt: scheduleRuns.readAt,- firedAt: scheduleRuns.firedAt,- })- .from(scheduleRuns)- .innerJoin(schedules, eq(scheduleRuns.scheduleId, schedules.id))- .where(- or(- isNotNull(scheduleRuns.sessionId),- and(- isNull(scheduleRuns.readAt),- inArray(scheduleRuns.status, UNREAD_TERMINAL_RUN_STATUSES),- ),- ),- );+ const projection = {+ runId: scheduleRuns.id,+ scheduleId: schedules.id,+ scheduleName: schedules.name,+ scheduleStatus: schedules.status,+ scheduleSource: schedules.source,+ nextFireAt: schedules.nextFireAt,+ workingDir: schedules.workingDir,+ projectConfigId: schedules.projectConfigId,+ sessionId: scheduleRuns.sessionId,+ status: scheduleRuns.status,+ readAt: scheduleRuns.readAt,+ firedAt: scheduleRuns.firedAt,+ };+ const [latestSessionRows, unreadRows, runningRows] = await Promise.all([+ db+ .select(projection)+ .from(scheduleSessionLatestRuns)+ .innerJoin(scheduleRuns, eq(scheduleSessionLatestRuns.runId, scheduleRuns.id))+ .innerJoin(schedules, eq(scheduleRuns.scheduleId, schedules.id))+ .where(isNotNull(scheduleRuns.sessionId)),+ db+ .select(projection)+ .from(scheduleRuns)+ .innerJoin(schedules, eq(scheduleRuns.scheduleId, schedules.id))+ .where(unreadTerminalRunWhere()),+ db+ .select(projection)+ .from(scheduleRuns)+ .innerJoin(schedules, eq(scheduleRuns.scheduleId, schedules.id))+ .where(eq(scheduleRuns.status, 'running')),+ ]);+ const latestRunIds = new Set(latestSessionRows.map((row) => row.runId));+ const rows = [+ ...unreadRows.filter((row) => !latestRunIds.has(row.runId)),+ ...runningRows+ .filter((row) => !latestRunIds.has(row.runId))+ .map((row) => ({ ...row, sessionId: null })),+ ...latestSessionRows,+ ];const indexedRuns = rows.map((row) => ({runId: row.runId,@@ -634,16 +668,19 @@ export class DrizzleScheduleStorage implements ScheduleStorage {indexedRuns.map((run) => run.sessionId).filter((id): id is string => Boolean(id)),);const scheduleByLegacyKey = await this.listSchedulesByLegacyKey(db);- const legacySessions = await db- .select({- id: sessions.id,- title: sessions.title,- workspaceKind: sessions.workspaceKind,- workingDir: sessions.workingDir,- updatedAt: sessions.updatedAt,- })- .from(sessions)- .where(legacyTitleWhere());+ const legacySessions =+ scheduleByLegacyKey.size === 0+ ? []+ : await db+ .select({+ id: sessions.id,+ title: sessions.title,+ workspaceKind: sessions.workspaceKind,+ workingDir: sessions.workingDir,+ updatedAt: sessions.updatedAt,+ })+ .from(sessions)+ .where(legacyTitleWhere());const legacyRuns: ScheduleSidebarIndexRun[] = [];for (const session of legacySessions) {@@ -1049,6 +1086,10 @@ export class DrizzleScheduleStorage implements ScheduleStorage {// interrupted,留下假失败红点与 errorMsg 残留。excludeRunIds(本进程// in-flight)无条件排除,自家心跳停摆也不自伤。const legacyStaleBefore = opts?.legacyStaleBefore ?? staleBefore;+ const excludedRunCondition =+ excludeRunIds && excludeRunIds.length > 0+ ? [notInArray(scheduleRuns.id, [...excludeRunIds])]+ : [];const staleRunningCond = () =>and(eq(scheduleRuns.status, 'running'),@@ -1062,14 +1103,34 @@ export class DrizzleScheduleStorage implements ScheduleStorage {sql`${scheduleRuns.firedAt} < ${legacyStaleBefore}`,),),- ...(excludeRunIds && excludeRunIds.length > 0- ? [notInArray(scheduleRuns.id, [...excludeRunIds])]- : []),+ ...excludedRunCondition,);- const staleRows = await db- .select({ id: scheduleRuns.id, scheduleId: scheduleRuns.scheduleId })- .from(scheduleRuns)- .where(staleRunningCond());+ const projection = { id: scheduleRuns.id, scheduleId: scheduleRuns.scheduleId };+ const [heartbeatRows, legacyRows] = await Promise.all([+ db+ .select(projection)+ .from(scheduleRuns)+ .where(+ and(+ eq(scheduleRuns.status, 'running'),+ isNotNull(scheduleRuns.heartbeatAt),+ sql`${scheduleRuns.heartbeatAt} < ${staleBefore}`,+ ...excludedRunCondition,+ ),+ ),+ db+ .select(projection)+ .from(scheduleRuns)+ .where(+ and(+ eq(scheduleRuns.status, 'running'),+ isNull(scheduleRuns.heartbeatAt),+ sql`${scheduleRuns.firedAt} < ${legacyStaleBefore}`,+ ...excludedRunCondition,+ ),+ ),+ ]);+ const staleRows = [...heartbeatRows, ...legacyRows];if (staleRows.length === 0) return [];// UPDATE 的 WHERE 重查完整僵尸条件而不是只按上面 SELECT 的 id 快照:两步之间// owner 实例可能刚好正常收口(status 已翻 success/failed),不能把它改回@@ -1120,12 +1181,7 @@ export class DrizzleScheduleStorage implements ScheduleStorage {const [row] = await db.select({ n: sql<number>`count(*)` }).from(scheduleRuns)- .where(- and(- isNull(scheduleRuns.readAt),- inArray(scheduleRuns.status, ['success', 'failed', 'aborted', 'interrupted']),- ),- );+ .where(unreadTerminalRunWhere());return Number(row?.n ?? 0);}@@ -1182,12 +1238,7 @@ export class DrizzleScheduleStorage implements ScheduleStorage {const result = await db.update(scheduleRuns).set({ readAt: Date.now() })- .where(- and(- isNull(scheduleRuns.readAt),- inArray(scheduleRuns.status, ['success', 'failed', 'aborted', 'interrupted']),- ),- )+ .where(unreadTerminalRunWhere()).run();const changes = (result as unknown as { changes?: number }).changes;return typeof changes === 'number' ? changes : 0;@@ -1202,8 +1253,7 @@ export class DrizzleScheduleStorage implements ScheduleStorage {.where(and(eq(scheduleRuns.scheduleId, scheduleId),- isNull(scheduleRuns.readAt),- inArray(scheduleRuns.status, ['success', 'failed', 'aborted', 'interrupted']),+ unreadTerminalRunWhere(),),).run();@@ -1347,6 +1397,9 @@ export class DrizzleScheduleStorage implements ScheduleStorage {});}+ // 每个 session 只需要最新一次显式 run 归属来裁决 legacy key。直接扫+ // schedule_runs 会让 Sidebar 查询随 Automation 全历史线性增长;0098 的+ // 投影把这里收敛为每个 session 至多一行。const linkedLegacyRows = await db.select({id: schedules.id,@@ -1361,14 +1414,15 @@ export class DrizzleScheduleStorage implements ScheduleStorage {sessionTitle: sessions.title,sessionWorkspaceKind: sessions.workspaceKind,sessionWorkingDir: sessions.workingDir,- firedAt: scheduleRuns.firedAt,+ firedAt: scheduleSessionLatestRuns.firedAt,updatedAt: schedules.updatedAt,})- .from(scheduleRuns)+ .from(scheduleSessionLatestRuns)+ .innerJoin(scheduleRuns, eq(scheduleSessionLatestRuns.runId, scheduleRuns.id)).innerJoin(schedules, eq(scheduleRuns.scheduleId, schedules.id))- .innerJoin(sessions, eq(scheduleRuns.sessionId, sessions.id))+ .innerJoin(sessions, eq(scheduleSessionLatestRuns.sessionId, sessions.id)).where(legacyTitleWhere())- .orderBy(desc(scheduleRuns.firedAt), desc(schedules.updatedAt));+ .orderBy(desc(scheduleSessionLatestRuns.firedAt), desc(schedules.updatedAt));const linkedKeys = new Set<string>();for (const row of linkedLegacyRows) {diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.tsindex 3efeb22615..1570d7c432 100644--- a/apps/desktop/src/preload/preload.ts+++ b/apps/desktop/src/preload/preload.ts@@ -6855,8 +6855,6 @@ contextBridge.exposeInMainWorld('electronAPI', {// runId 不是特权数据(renderer 的标记里就存着它)。listSidebarIndexRuns: (): Promise<unknown> =>ipcRenderer.invoke('maker:schedule:list-sidebar-index-runs'),- listCostSummaries: (): Promise<unknown[]> =>- ipcRenderer.invoke('maker:schedule:list-cost-summaries'),deleteRun: (runId: string): Promise<void> =>ipcRenderer.invoke('maker:schedule:delete-run', runId),/** delete/pause 前查这条 schedule 当前 in-flight run 数,>0 时 renderer 弹二次确认。 */diff --git a/apps/desktop/src/renderer/__tests__/automationGeneratedSessions.test.ts b/apps/desktop/src/renderer/__tests__/automationGeneratedSessions.test.tsindex c0a19aee3a..75441bb819 100644--- a/apps/desktop/src/renderer/__tests__/automationGeneratedSessions.test.ts+++ b/apps/desktop/src/renderer/__tests__/automationGeneratedSessions.test.ts@@ -41,8 +41,6 @@ import {isUnreadFailedScheduleRun,isUnreadScheduleRun,} from '@/features/scheduler/lib/runUnread';-import { formatUsd } from '@/features/scheduler/lib/formatters';-// Windows checkout(core.autocrlf)下源码是 CRLF;统一归一成 LF,含 \n 的多行片段断言才跨平台成立。const readTextLf = (...args: Parameters<typeof readFileSync>): string =>String(readFileSync(...args)).replace(/\r\n/g, '\n');@@ -1063,8 +1061,9 @@ describe('automation-generated sessions', () => {expect(unreadCountsHookSource).not.toContain('RUNS_PER_SCHEDULE_LIMIT');expect(unreadCountsHookSource).not.toContain('listRuns(');expect(storageSource).toContain('listSidebarIndexRuns');+ expect(storageSource).toContain('.from(scheduleSessionLatestRuns)');expect(storageSource).toContain('isNotNull(scheduleRuns.sessionId)');- expect(storageSource).toContain('UNREAD_TERMINAL_RUN_STATUSES');+ expect(storageSource).toContain('unreadTerminalRunWhere');expect(storageSource).toContain('nextFireAt: schedules.nextFireAt');expect(storageSource).toContain('listSchedulesByLegacyKey(db)');expect(storageSource).toContain('legacyScheduleNameFromSessionTitle(session.title)');@@ -1080,11 +1079,7 @@ describe('automation-generated sessions', () => {expect(preloadSource).toContain('listSidebarIndexRuns');});- it('surfaces total automation task cost from deduped schedule sessions', () => {- const storageSource = readTextLf(- new URL('../../main/scheduler-host/storage.ts', import.meta.url),- 'utf8',- );+ it('keeps per-run Automation cost without loading cumulative list cost', () => {const schedulePageSource = readTextLf(new URL('../features/scheduler/SchedulerPage.tsx', import.meta.url),'utf8',@@ -1105,47 +1100,15 @@ describe('automation-generated sessions', () => {new URL('../features/scheduler/components/RunHistoryPane.tsx', import.meta.url),'utf8',);- const hookSource = readTextLf(- new URL('../features/scheduler/hooks/useScheduleCostSummaries.ts', import.meta.url),- 'utf8',- );const preloadSource = readTextLf(new URL('../../preload/preload.ts', import.meta.url), 'utf8');const zh = JSON.parse(readTextLf(new URL('../i18n/locales/zh-CN/common.json', import.meta.url), 'utf8'),);- expect(formatUsd(0)).toBe('$0.00');- expect(formatUsd(0.001)).toBe('<$0.01');- expect(formatUsd(1.234)).toBe('$1.23');- expect(storageSource).toContain('listCostSummaries');- expect(storageSource).toContain('messages.agentMeta');- expect(storageSource).toContain('scheduleOriginFromAgentMeta');- expect(storageSource).toContain("origin?.kind !== 'scheduler'");- expect(storageSource).toContain('turnCostFromAgentMeta');- expect(storageSource).toContain('turnCostIsEstimate === true');- expect(storageSource).toContain('SQLITE_IN_CHUNK_SIZE');- expect(storageSource).toContain("when 'user' then 0 else 1 end");- expect(storageSource).toContain('entry.costValues.push(turnCost.costMoney)');- expect(storageSource).toContain(- 'addCompatibleRegionalMoney(summary.costValues, summary.latestCurrency)',- );- expect(storageSource).toContain('totalMoney');- expect(storageSource).toContain('listLegacySessionRuns');- expect(storageSource).toContain("LEGACY_SCHEDULE_TITLE_PREFIX = '[Schedule] '");- expect(storageSource).toContain("LEGACY_SESSION_RUN_ID_PREFIX = 'legacy-session:'");- expect(storageSource).toContain('legacyScheduleNameFromSessionTitle(session.title)');- expect(storageSource).toContain('listLegacyAliasesForSchedule');- expect(storageSource).toContain('inArray(sessions.title, titles)');- expect(storageSource).toContain('legacyAliases.has(');- expect(storageSource).toContain('directScheduleId && directScheduleId !== schedule.id');- expect(preloadSource).toContain('listCostSummaries');- expect(hookSource).toContain('onUsageSessionSpendChanged');- expect(hookSource).toContain('onUsageMessageTurnCost');- expect(hookSource).toContain('maker.schedule.listCostSummaries()');- expect(schedulePageSource).toContain('useScheduleCostSummaries(sorted)');- expect(taskListPaneSource).toContain('costSummariesLoaded');- expect(taskListCellSource).toContain('scheduler.cell.totalCost');- expect(taskListCellSource).toContain('formatTurnCostMoney(totalMoney)');+ expect(preloadSource).not.toContain('listCostSummaries');+ expect(schedulePageSource).not.toContain('useScheduleCostSummaries');+ expect(taskListPaneSource).not.toContain('costSummaries');+ expect(taskListCellSource).not.toContain('scheduler.cell.totalCost');expect(runHistoryPaneSource).toContain('groupRunsForHistory');expect(runHistoryPaneSource).toContain('PERSISTENT_SESSION_PREVIEW_LIMIT = 3');expect(runHistoryPaneSource).toContain('expandRemainingRuns');@@ -1154,8 +1117,6 @@ describe('automation-generated sessions', () => {expect(runHistoryCardSource).toContain("!isLegacySessionRun && run.status !== 'running'");expect(runHistoryCardSource).toContain('scheduler.runs.runCost');expect(runHistoryCardSource).toContain("run.costAttribution === 'legacy'");- expect(zh.scheduler.cell.totalCost).toBe('开销 {{cost}}');- expect(zh.scheduler.cell.totalValue).toBe('价值 {{value}}');expect(zh.scheduler.runs.sessionCost).toBe('任务开销 {{cost}}');expect(zh.scheduler.runs.sessionValue).toBe('任务价值 {{value}}');expect(zh.scheduler.runs.runCost).toBe('本次开销 {{cost}}');diff --git a/apps/desktop/src/renderer/__tests__/automationScheduleSilenceHook.test.ts b/apps/desktop/src/renderer/__tests__/automationScheduleSilenceHook.test.tsindex a11bd4e4cd..c57440b66d 100644--- a/apps/desktop/src/renderer/__tests__/automationScheduleSilenceHook.test.ts+++ b/apps/desktop/src/renderer/__tests__/automationScheduleSilenceHook.test.ts@@ -198,7 +198,7 @@ describe('useAutomationScheduleSessionIndex silence events', () => {/*** 事件丢失的自愈:refresh 拉到的 sidebar run 列表就是 scheduler 落库的权威状态- * (且包含所有带 sessionId 的 run,没有 history limit),据它对账标记。+ * (且包含所有 running run),据它对账标记。* 刻意不用定时器猜 run 是否还在飞行 —— 三种判据(事件序 / renderer running 快照 /* 固定时长)都被证明会误判,见 silencedSessionDoneStore 的文件头注释。*/@@ -229,6 +229,38 @@ describe('useAutomationScheduleSessionIndex marker reconciliation', () => {};}+ it('keeps old unread ids while the latest row wins session ownership', async () => {+ stubApiWithRuns([+ indexRun({+ runId: 'run-old-unread',+ scheduleId: 'schedule-old',+ scheduleName: '旧自动化',+ status: 'failed',+ readAt: undefined,+ firedAt: 10,+ }),+ indexRun({+ runId: 'run-latest',+ scheduleId: 'schedule-latest',+ scheduleName: '最新自动化',+ status: 'success',+ readAt: 20,+ firedAt: 20,+ }),+ ]);++ const { result } = renderHook(() => useAutomationScheduleSessionIndex());+ await waitFor(() => {+ expect(result.current.get('session-1')).toMatchObject({+ scheduleId: 'schedule-latest',+ scheduleName: '最新自动化',+ unreadRunIds: ['run-old-unread'],+ unreadFailedRunIds: ['run-old-unread'],+ latestUnreadFailedRunId: 'run-old-unread',+ });+ });+ });+it('clears markers whose run already reached a terminal status', async () => {vi.useFakeTimers();try {diff --git a/apps/desktop/src/renderer/__tests__/schedulerTemplateEntry.test.ts b/apps/desktop/src/renderer/__tests__/schedulerTemplateEntry.test.tsindex 2fc6ee453b..ea0f1eae50 100644--- a/apps/desktop/src/renderer/__tests__/schedulerTemplateEntry.test.ts+++ b/apps/desktop/src/renderer/__tests__/schedulerTemplateEntry.test.ts@@ -130,10 +130,6 @@ vi.mock('@/features/scheduler/hooks/useScheduleUnreadRunCounts', () => ({useScheduleUnreadRunCounts: () => new Map(),}));-vi.mock('@/features/scheduler/hooks/useScheduleCostSummaries', () => ({- useScheduleCostSummaries: () => ({ summaries: new Map(), loaded: true }),-}));-vi.mock('@/features/scheduler/hooks/useSessionReferences', () => ({useSessionReferences: () => new Map(),}));diff --git a/apps/desktop/src/renderer/features/cc-agent/hooks/useAutomationScheduleSessionIndex.ts b/apps/desktop/src/renderer/features/cc-agent/hooks/useAutomationScheduleSessionIndex.tsindex 8fcb4a10a0..fba7569e04 100644--- a/apps/desktop/src/renderer/features/cc-agent/hooks/useAutomationScheduleSessionIndex.ts+++ b/apps/desktop/src/renderer/features/cc-agent/hooks/useAutomationScheduleSessionIndex.ts@@ -98,8 +98,8 @@ export function useAutomationScheduleSessionIndex(): ReadonlyMap<string, Automatconst { runs, inflightRunIds } = await loadScheduleSidebarIndexSnapshot();if (refreshSeqRef.current !== seq || cancelledRef.current) return;- // 抑制标记的事件丢失自愈:这份列表是 scheduler 落库的权威 run 状态(且包含所有- // 带 sessionId 的 run,没有 history limit),据它清掉「已终态」和「已不存在」的+ // 抑制标记的事件丢失自愈:这份列表包含所有 running run,以及每个 session 的最新+ // 映射和未读终态 run,据它清掉「已终态」和「已不存在」的// 标记。RunStatus 里只有 'running' 不是终态。刻意不用定时器猜 run 还在不在飞行// —— 见 silencedSessionDoneStore 的文件头与 reconcileRunMarkers 注释。const dbRunStatus = new Map<string, RunLivenessStatus>();diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsxindex 2fd6d9e087..9b8f0ff590 100644--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx@@ -88,7 +88,10 @@ import {useSessionBoundSchedules,scheduleFocusPath,} from '@/features/scheduler/lib/scheduleSessionBinding';-import { loadScheduleSidebarIndexRuns } from '@/features/scheduler/lib/scheduleSidebarIndexRuns';+import {+ findLatestSidebarIndexRunForSession,+ loadScheduleSidebarIndexRuns,+} from '@/features/scheduler/lib/scheduleSidebarIndexRuns';import { projectSidebarSessionActivity, resolveSidebarRightStatus } from './sidebarRightStatus';import { Tip } from '@/components/ui/tooltip';import { SidebarRightStatusIndicator } from './SidebarRightStatusIndicator';@@ -492,7 +495,7 @@ export function SessionCard({e.stopPropagation();try {const runs = await loadScheduleSidebarIndexRuns();- const hit = runs.find((r) => r.sessionId === session.id);+ const hit = findLatestSidebarIndexRunForSession(runs, session.id);navigate(hit ? scheduleFocusPath(hit.scheduleId) : '/cc-agent/scheduled');} catch {navigate('/cc-agent/scheduled');diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsxindex b8818deb3c..0820ed34bc 100644--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx@@ -75,6 +75,7 @@ import {} from '../lib/sessionDisplayTitle';import { useSessionBoundSchedules } from '@/features/scheduler/lib/scheduleSessionBinding';import {+ findLatestSidebarIndexRunForSession,loadScheduleSidebarIndexRuns,type ScheduleSidebarIndexRun,} from '@/features/scheduler/lib/scheduleSidebarIndexRuns';@@ -434,7 +435,7 @@ export const SessionItem = memo(function SessionItem({const handleAutomationIconClick = useCallback(async () => {try {const runs = await loadScheduleSidebarIndexRuns();- const hit = runs.find((r) => r.sessionId === session.id);+ const hit = findLatestSidebarIndexRunForSession(runs, session.id);navigate(hit ? scheduleFocusPath(hit.scheduleId) : '/cc-agent/scheduled');} catch {navigate('/cc-agent/scheduled');@@ -459,7 +460,7 @@ export const SessionItem = memo(function SessionItem({loadScheduleSidebarIndexRunsCached().then((runs) => {if (cancelled) return;- const hit = runs.find((r) => r.sessionId === session.id);+ const hit = findLatestSidebarIndexRunForSession(runs, session.id);setResolvedScheduleId(hit?.scheduleId ?? null);}).catch(() => {@@ -1356,7 +1357,7 @@ export const SessionItem = memo(function SessionItem({// 统一 hover 浮层:PR 优先;来源标签已写在标题旁,不再用浮层重复。// 具体优先级、配色和 orca-lead 回退详见 SessionTooltip.tsx。// 单独 automation-generated 会话(未被 AutomationSessionGroupItem 吸走)在 hover 时- // 显示「下次运行倒计时 + 累计运行次数」,与分组头 rowTooltip 同语义。分组内子行+ // 显示下次运行或停止状态。分组内子行// (insideAutomationGroup=true)由组头承担,这里不再挂 automation 浮层。const showAutomationTooltip = isAutomationGenerated && !insideAutomationGroup;return (diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionTooltip.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionTooltip.tsxindex 36602ef137..2030a124e9 100644--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionTooltip.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionTooltip.tsx@@ -25,8 +25,11 @@ import { prStatusKey, MAX_STATUS_QUERIES } from '@/lib/prStatus';import { usePrStatuses } from '@/contexts/PrRefsContext';import { PR_STATUS_COLOR, PR_STATUS_ICON } from '../gitContextPrVisuals';import { formatSidebarFutureTime } from '../lib/formatSidebarTime';-import { loadScheduleSidebarIndexRuns } from '@/features/scheduler/lib/scheduleSidebarIndexRuns';-import type { ScheduleSidebarIndexRun } from '@/features/scheduler/lib/scheduleSidebarIndexRuns';+import {+ findLatestSidebarIndexRunForSession,+ loadScheduleSidebarIndexRuns,+ type ScheduleSidebarIndexRun,+} from '@/features/scheduler/lib/scheduleSidebarIndexRuns';const CONTENT_SURFACE_CLASS = cn('bg-[var(--surface-elevated)] text-[var(--text-primary)]',@@ -44,7 +47,7 @@ export interface SessionTooltipProps {sourceLabel?: string;/*** 单独渲染的 automation-generated 会话(未被 AutomationSessionGroupItem 吸走)- * 需要展示「下次运行倒计时 + 累计运行次数」浮层,和分组头 rowTooltip 语义一致。+ * 需要展示下次运行或停止状态浮层。* 优先级:PR > automation > sourceLabel(PR 承载工程上下文最重,automation 承载* 计划信息次之,sourceLabel 只是「来自哪个项目」的静态标签)。*/@@ -143,10 +146,8 @@ function PrTooltip({}/**- * 单独 automation-generated 会话行的 hover 浮层 —— 显示「下次运行剩余时间 + 累计运行- * 次数」,和 AutomationSessionGroupItem 的 rowTooltip 语义一致。数据源和 Timer chip- * 点击复用同一套 loadScheduleSidebarIndexRuns:runs 里每条自带 nextFireAt /- * scheduleStatus,同 scheduleId 的条数即为总运行次数。tooltip 打开时才发起一次拉取+ * 单独 automation-generated 会话行的 hover 浮层 —— 显示下次运行剩余时间或停止状态。+ * 数据源和 Timer chip 点击复用同一套 loadScheduleSidebarIndexRuns;tooltip 打开时才发起一次拉取* (与 PrTooltip 的 fetchStatusesForSession 同风格,不在密集渲染路径上常驻拉数据);* 拉到的 nextFireAt 用一次性 formatSidebarFutureTime 转成 "N 分钟后运行",不做秒级 tick* (tooltip 通常只停留几秒,静态文案够用)。@@ -179,17 +180,14 @@ function AutomationTooltip({};}, [effectiveOpen, runs]);- const hit = runs?.find((r) => r.sessionId === sessionId) ?? null;+ const hit = runs ? (findLatestSidebarIndexRunForSession(runs, sessionId) ?? null) : null;const countdownText =hit && hit.scheduleStatus === 'active' && typeof hit.nextFireAt === 'number'? formatSidebarFutureTime(hit.nextFireAt, t): '';const isStopped = hit?.scheduleStatus === 'paused' || hit?.scheduleStatus === 'expired';const stoppedText = isStopped ? t('ccAgent.sidebar.automationGroup.stopped') : '';- const runCount = hit ? runs!.filter((r) => r.scheduleId === hit.scheduleId).length : 0;- const runCountText =- runCount > 0 ? t('ccAgent.sidebar.automationGroup.runCount', { count: runCount }) : '';- const hasContent = countdownText || stoppedText || runCountText;+ const hasContent = countdownText || stoppedText;return (<Tooltip.Provider delayDuration={0} skipDelayDuration={0}>@@ -202,7 +200,6 @@ function AutomationTooltip({<div className="flex flex-col gap-0.5">{countdownText && <span>{countdownText}</span>}{stoppedText && <span>{stoppedText}</span>}- {runCountText && <span>{runCountText}</span>}</div></Tooltip.Content>)}diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.tsindex e1bab2a389..124bf82858 100644--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts@@ -154,6 +154,7 @@ vi.mock('@/features/scheduler/lib/scheduleSessionBinding', () => ({vi.mock('@/features/scheduler/lib/scheduleSidebarIndexRuns', () => ({loadScheduleSidebarIndexRuns: async () => [],+ findLatestSidebarIndexRunForSession: () => undefined,}));function scheduleForCase(id: string, status: 'active' | 'paused') {diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionRowRenderIsolation.test.ts b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionRowRenderIsolation.test.tsindex f7cd665583..3b10690856 100644--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionRowRenderIsolation.test.ts+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionRowRenderIsolation.test.ts@@ -82,6 +82,7 @@ vi.mock('@/features/scheduler/lib/scheduleSessionBinding', () => {vi.mock('@/features/scheduler/lib/scheduleSidebarIndexRuns', () => ({loadScheduleSidebarIndexRuns: async () => [],+ findLatestSidebarIndexRunForSession: () => undefined,}));vi.mock('@/components/sidebar/WorktreeBadge', () => ({diff --git a/apps/desktop/src/renderer/features/scheduler/SchedulerPage.tsx b/apps/desktop/src/renderer/features/scheduler/SchedulerPage.tsxindex d5456000f8..30cd1afc77 100644--- a/apps/desktop/src/renderer/features/scheduler/SchedulerPage.tsx+++ b/apps/desktop/src/renderer/features/scheduler/SchedulerPage.tsx@@ -46,7 +46,6 @@ import { useHorizontalResize } from '@/hooks/useHorizontalResize';import { useSchedules } from './hooks/useSchedules';import { useDeleteScheduleWithSessions } from './hooks/useDeleteScheduleWithSessions';import { useScheduleUnreadRunCounts } from './hooks/useScheduleUnreadRunCounts';-import { useScheduleCostSummaries } from './hooks/useScheduleCostSummaries';import { useRunNowBusyGuard } from './hooks/useRunNowBusyGuard';import { ScheduleFormDialog } from './components/ScheduleFormDialog';import { TemplateGallery } from './components/TemplateGallery';@@ -339,8 +338,6 @@ export function SchedulerPage() {[sorted, selectedId],);const unreadRunCounts = useScheduleUnreadRunCounts(sorted);- const { summaries: costSummaries, loaded: costSummariesLoaded } =- useScheduleCostSummaries(sorted);// 仅用户在 TaskListFilterPopover 主动切换时持久化;focus 同步 / 新建任务的// 程序性 setStatusFilter 不写入,避免覆盖用户偏好(详见 statusFilterStorage)。@@ -653,8 +650,6 @@ export function SchedulerPage() {schedules={sorted}selectedId={selectedId}unreadRunCounts={unreadRunCounts}- costSummaries={costSummaries}- costSummariesLoaded={costSummariesLoaded}onSelect={(s) => setSelectedId(s.id)}statusFilter={statusFilter}onStatusFilterChange={handleStatusFilterChange}diff --git a/apps/desktop/src/renderer/features/scheduler/components/RunHistoryCard.tsx b/apps/desktop/src/renderer/features/scheduler/components/RunHistoryCard.tsxindex 10003becf4..ac147e52cb 100644--- a/apps/desktop/src/renderer/features/scheduler/components/RunHistoryCard.tsx+++ b/apps/desktop/src/renderer/features/scheduler/components/RunHistoryCard.tsx@@ -32,11 +32,8 @@ import {import { AgentMark } from './AgentMark';import { AttentionDot } from '@/components/sidebar/AttentionDot';import { formatDuration, formatRunTimestamp, formatStartedAgo } from '../lib/formatters';-import { formatTurnCostMoney } from '@/lib/usageFormat';-import {- legacyUsdMoney,- usdMoney,-} from '../../../../shared/regionalMoney';+import { formatCompactTokens, formatTurnCostMoney } from '@/lib/usageFormat';+import { legacyUsdMoney } from '../../../../shared/regionalMoney';import { isUnreadScheduleRun } from '../lib/runUnread';import { markScheduleRunReadAndSync } from '../lib/scheduleRunReadSync';@@ -157,38 +154,24 @@ export function RunHistoryCard({run.status === 'running'? formatStartedAgo(run.firedAt, Date.now(), t): t('scheduler.runs.took', { duration: formatDuration(run.firedAt, run.finishedAt) });- const costText = run.status === 'running'- ? null- : run.costAttribution === 'legacy'- ? t('scheduler.runs.legacyCostUnavailable')- : run.costAttribution === 'unavailable'- ? t('scheduler.runs.costUnavailable')- : run.costAttribution === 'exact' ||- run.costAttribution === 'direct' ||- run.costAttribution === 'mixed' ||- run.costAttribution === 'zero'- ? (() => {- const costMoney =- run.costMoney ??- legacyUsdMoney(run.costUsd ?? 0);- const valueMoney =- run.estimatedValueMoney ??- usdMoney(run.estimatedValueUsd ?? 0, 'value-estimate', 'legacy-usd');- return [- costMoney.amount > 0- ? t('scheduler.runs.runCost', { cost: formatTurnCostMoney(costMoney) })- : null,- valueMoney.amount > 0- ? t('scheduler.runs.runValue', { value: formatTurnCostMoney(valueMoney) })- : null,- ]- .filter(Boolean)- .join(' · ') ||- t('scheduler.runs.runCost', {- cost: formatTurnCostMoney(costMoney),- });- })()- : null;+ const costText = (() => {+ if (run.status === 'running') return null;+ if (run.costAttribution === 'legacy') {+ return t('scheduler.runs.legacyCostUnavailable');+ }++ const costMoney = run.costMoney ?? legacyUsdMoney(run.costUsd ?? 0);+ if (costMoney.amount > 0 || run.costAttribution === 'zero') {+ return t('scheduler.runs.runCost', { cost: formatTurnCostMoney(costMoney) });+ }+ if (typeof run.totalTokens === 'number' && run.totalTokens > 0) {+ return t('scheduler.runs.runTokens', {+ tokens: formatCompactTokens(run.totalTokens),+ });+ }+ if (run.costAttribution) return t('scheduler.runs.costUnavailable');+ return null;+ })();// 终态且未读 → 在 agent 图标右上角点一个状态点(全端统一色表:失败结局红 / 成功绿)。// running 不算未读(结果还没出来,没什么"漏看")。diff --git a/apps/desktop/src/renderer/features/scheduler/components/TaskListCell.tsx b/apps/desktop/src/renderer/features/scheduler/components/TaskListCell.tsxindex e5256afd2d..a41a3f1a30 100644--- a/apps/desktop/src/renderer/features/scheduler/components/TaskListCell.tsx+++ b/apps/desktop/src/renderer/features/scheduler/components/TaskListCell.tsx@@ -29,7 +29,6 @@ import { useTranslation } from 'react-i18next';import { cn } from '@/lib/utils';import { AttentionDot } from '@/components/sidebar/AttentionDot';import type { Schedule } from '@cindy/maker-scheduler';-import type { RegionalMoney } from '../../../../shared/regionalMoney';import {DropdownMenu,DropdownMenuContent,@@ -39,15 +38,11 @@ import {} from '@/components/ui/dropdown-menu';import { formatLastRun, formatNextRun } from '../lib/formatters';-import { formatTurnCostMoney } from '@/lib/usageFormat';interface Props {schedule: Schedule;selected: boolean;unreadCount?: number;- totalMoney?: RegionalMoney;- totalEstimatedValueMoney?: RegionalMoney;- hasUnavailableCost?: boolean;onSelect: (s: Schedule) => void;/** 右键菜单的 Pause/Resume 动作;与 RunHistoryPane ⋯ 菜单同行为。 */onTogglePause?: (s: Schedule) => void | Promise<void>;@@ -88,9 +83,6 @@ export function TaskListCell({schedule: s,selected,unreadCount = 0,- totalMoney,- totalEstimatedValueMoney,- hasUnavailableCost = false,onSelect,onTogglePause,onDelete,@@ -178,31 +170,8 @@ export function TaskListCell({} else {subtitle = lastText ?? nextText;}- const costText =- totalMoney == null && !hasUnavailableCost- ? null- : [- totalMoney && totalMoney.amount > 0- ? t('scheduler.cell.totalCost', {- cost: formatTurnCostMoney(totalMoney),- })- : null,- (totalEstimatedValueMoney?.amount ?? 0) > 0- ? t('scheduler.cell.totalValue', {- value: formatTurnCostMoney(totalEstimatedValueMoney!),- })- : null,- hasUnavailableCost ? t('scheduler.cell.costUnavailable') : null,- ]- .filter(Boolean)- .join(' · ') ||- (totalMoney- ? t('scheduler.cell.totalCost', {- cost: formatTurnCostMoney(totalMoney),- })- : t('scheduler.cell.costUnavailable'));// 副标题行是否渲染:决定右下角 Run 按钮的"预留位"落在哪一行(见下方两处 pr-3.5)。- const hasMetaRow = Boolean(subtitle || costText);+ const hasMetaRow = Boolean(subtitle);// ── Double-click rename(与 SessionItem 完全同款)──// - 单击立即选择;双击只额外进入重命名(仅在 onRename 传入时启用)@@ -417,15 +386,7 @@ export function TaskListCell({)}</div>{hasMetaRow && (- <div- className={cn(- 'flex min-w-0 items-center gap-2',- // 无 cost 的行,右下角 Run 按钮没有可替换的对象,给副标题常驻预留按钮位,- // 避免悬浮时压住文字;预留量与标题行同款(pr-5 = 补齐 14px 侵入 + 6px 间隙)。- // 有 cost 的行不预留——按钮悬浮时原位替换 cost(见下方 costText 的淡出)。- onRunNow && !costText && 'pr-5',- )}- >+ <div className={cn('flex min-w-0 items-center gap-2', onRunNow && 'pr-5')}>{subtitle && (<spanclassName={cn(@@ -440,25 +401,6 @@ export function TaskListCell({{subtitle}</span>)}- {costText && (- <span- className={cn(- 'ml-auto shrink-0 text-11',- selected- ? 'text-[var(--settings-section-desc)]'- : 'text-[var(--cmd-palette-item-meta)]',- // 行悬浮时淡出,让右下角的 Run 按钮原位替换 cost(与侧栏"meta 让位给- // 操作按钮"的手法一致);仅 opacity 过渡,宽度保留,副标题不回流。- // 键盘可达性:按钮经 Tab 聚焦(focus-visible)显示时 cost 同样让位。- // 精确匹配"按钮自身 focus-visible"而非 group-focus-within——行本身也- // focusable,点选/Tab 到行时按钮并不显示,不应误藏 cost。- onRunNow &&- 'transition-opacity group-hover:opacity-0 group-has-[button:focus-visible]:opacity-0',- )}- >- {costText}- </span>- )}</div>)}{/* 右键菜单:复用 ProjectNode 的 controlled DropdownMenu + 不可见 trigger 模式,diff --git a/apps/desktop/src/renderer/features/scheduler/components/TaskListPane.tsx b/apps/desktop/src/renderer/features/scheduler/components/TaskListPane.tsxindex 2548937d5c..8c48b390ca 100644--- a/apps/desktop/src/renderer/features/scheduler/components/TaskListPane.tsx+++ b/apps/desktop/src/renderer/features/scheduler/components/TaskListPane.tsx@@ -20,7 +20,6 @@ import type { Schedule, SchedulerRuntimeSnapshot } from '@cindy/maker-scheduler'import { TaskListCell } from './TaskListCell';import { TaskListFilterPopover, type StatusFilter } from './TaskListFilterPopover';-import type { ScheduleCostSummary } from '../hooks/useScheduleCostSummaries';const COLLAPSE_KEY = 'xdt:scheduler.collapsedProjects';const OTHER_GROUP_KEY = 'other';@@ -30,8 +29,6 @@ interface Props {schedules: Schedule[];selectedId: string | null;unreadRunCounts: ReadonlyMap<string, number>;- costSummaries: ReadonlyMap<string, ScheduleCostSummary>;- costSummariesLoaded: boolean;onSelect: (s: Schedule) => void;/** 当前 status 筛选值;默认 'active'。 */statusFilter: StatusFilter;@@ -69,8 +66,6 @@ export function TaskListPane({schedules,selectedId,unreadRunCounts,- costSummaries,- costSummariesLoaded,onSelect,statusFilter,onStatusFilterChange,@@ -236,21 +231,6 @@ export function TaskListPane({schedule={s}selected={s.id === selectedId}unreadCount={unreadRunCounts.get(s.id) ?? 0}- totalMoney={- costSummariesLoaded- ? costSummaries.get(s.id)?.totalMoney- : undefined- }- totalEstimatedValueMoney={- costSummariesLoaded- ? costSummaries.get(s.id)?.totalEstimatedValueMoney- : undefined- }- hasUnavailableCost={- costSummariesLoaded- ? costSummaries.get(s.id)?.hasUnavailableCost- : undefined- }onSelect={onSelect}onTogglePause={onTogglePause}onDelete={s.source === 'project' ? undefined : onDelete}diff --git a/apps/desktop/src/renderer/features/scheduler/components/__tests__/RunHistoryCard.test.tsx b/apps/desktop/src/renderer/features/scheduler/components/__tests__/RunHistoryCard.test.tsxindex 0dbbd57c4c..b9b0d329be 100644--- a/apps/desktop/src/renderer/features/scheduler/components/__tests__/RunHistoryCard.test.tsx+++ b/apps/desktop/src/renderer/features/scheduler/components/__tests__/RunHistoryCard.test.tsx@@ -108,6 +108,56 @@ describe('RunHistoryCard 前置检查结果', () => {});describe('RunHistoryCard 费用展示', () => {+ it('有真实费用时只显示费用,不同时显示估算价值或 Token', () => {+ renderRun({+ id: 'run-priced',+ scheduleId: 'schedule-1',+ firedAt: 1,+ finishedAt: 11,+ status: 'success',+ costAttribution: 'exact',+ costUsd: 0.12,+ estimatedValueUsd: 0.2,+ totalTokens: 12_400,+ });++ expect(screen.getByText('scheduler.runs.runCost')).toBeTruthy();+ expect(screen.queryByText('scheduler.runs.runValue')).toBeNull();+ expect(screen.queryByText('scheduler.runs.runTokens')).toBeNull();+ });++ it('只有估算价值时改为显示 Token 用量', () => {+ renderRun({+ id: 'run-estimate-only',+ scheduleId: 'schedule-1',+ firedAt: 1,+ finishedAt: 11,+ status: 'success',+ costAttribution: 'exact',+ estimatedValueUsd: 0.2,+ totalTokens: 12_400,+ });++ expect(screen.getByText('scheduler.runs.runTokens')).toBeTruthy();+ expect(screen.queryByText('scheduler.runs.runCost')).toBeNull();+ expect(screen.queryByText('scheduler.runs.runValue')).toBeNull();+ });++ it('不可可靠计价但有 Token 事实时显示 Token 用量', () => {+ renderRun({+ id: 'run-unavailable-token-usage',+ scheduleId: 'schedule-1',+ firedAt: 1,+ finishedAt: 11,+ status: 'success',+ costAttribution: 'unavailable',+ totalTokens: 8_000,+ });++ expect(screen.getByText('scheduler.runs.runTokens')).toBeTruthy();+ expect(screen.queryByText('scheduler.runs.costUnavailable')).toBeNull();+ });+it('不可可靠计价时不显示假 $0.00', () => {renderRun({id: 'run-unavailable-cost',diff --git a/apps/desktop/src/renderer/features/scheduler/components/__tests__/TaskListCell.test.tsx b/apps/desktop/src/renderer/features/scheduler/components/__tests__/TaskListCell.test.tsxindex beb65017af..12b38c337f 100644--- a/apps/desktop/src/renderer/features/scheduler/components/__tests__/TaskListCell.test.tsx+++ b/apps/desktop/src/renderer/features/scheduler/components/__tests__/TaskListCell.test.tsx@@ -109,56 +109,3 @@ describe('TaskListCell 并发等待提示', () => {expect(screen.queryByText('scheduler.cell.subtitleWaitingForResources')).toBeNull();});});--describe('TaskListCell 费用展示', () => {- it('无汇总时不伪造 $0.00', () => {- render(- createElement(TaskListCell, {- schedule,- selected: false,- onSelect: vi.fn(),- }),- );-- expect(screen.queryByText('scheduler.cell.totalCost')).toBeNull();- });-- it('不可可靠计价时显示费用不可用', () => {- render(- createElement(TaskListCell, {- schedule,- selected: false,- onSelect: vi.fn(),- totalMoney: {- amount: 0,- currency: 'USD',- approximate: false,- kind: 'actual-cost',- },- hasUnavailableCost: true,- }),- );-- expect(screen.getByText('scheduler.cell.costUnavailable')).toBeTruthy();- expect(screen.queryByText('scheduler.cell.totalCost')).toBeNull();- });-- it('已确认真实零费用时仍显示 $0.00', () => {- render(- createElement(TaskListCell, {- schedule,- selected: false,- onSelect: vi.fn(),- totalMoney: {- amount: 0,- currency: 'USD',- approximate: false,- kind: 'actual-cost',- },- hasUnavailableCost: false,- }),- );-- expect(screen.getByText('scheduler.cell.totalCost')).toBeTruthy();- });-});diff --git a/apps/desktop/src/renderer/features/scheduler/hooks/useScheduleCostSummaries.ts b/apps/desktop/src/renderer/features/scheduler/hooks/useScheduleCostSummaries.tsdeleted file mode 100644index dca18922cc..0000000000--- a/apps/desktop/src/renderer/features/scheduler/hooks/useScheduleCostSummaries.ts+++ /dev/null@@ -1,113 +0,0 @@-import { useCallback, useEffect, useMemo, useRef, useState } from 'react';-import type { Schedule, SchedulerEvent } from '@cindy/maker-scheduler';--import { isDataOwnerPushCurrent } from '@/contexts/dataOwnerGeneration';-import { createLogger } from '@/lib/logger';-import type { RegionalMoney } from '../../../../shared/regionalMoney';--const log = createLogger('ScheduleCostSummaries');--/** 单个自动化任务按自动化触发的 turn 汇总出的累计开销。 */-export interface ScheduleCostSummary {- scheduleId: string;- totalMoney: RegionalMoney;- totalEstimatedValueMoney: RegionalMoney;- totalCostUsd?: number;- totalEstimatedValueUsd?: number;- /** 至少一轮自动化无法取得可靠费用。 */- hasUnavailableCost?: boolean;- /** 产生过自动化 turn cost 的去重 session 数;legacy 会话兜底同样计入。 */- sessionCount: number;- sessions?: readonly ScheduleSessionCostSummary[];-}--export interface ScheduleSessionCostSummary {- sessionId: string;- totalMoney: RegionalMoney;- totalEstimatedValueMoney: RegionalMoney;- totalCostUsd?: number;- totalEstimatedValueUsd?: number;-}--/** Automation 任务列表的 cost summary 状态;loaded=false 时 UI 不显示占位金额。 */-export interface UseScheduleCostSummariesResult {- summaries: ReadonlyMap<string, ScheduleCostSummary>;- loaded: boolean;-}--export function useScheduleCostSummaries(- schedules: readonly Schedule[],-): UseScheduleCostSummariesResult {- const scheduleIdsKey = useMemo(- () => schedules.map((schedule) => schedule.id).join('\u0000'),- [schedules],- );- const [summaries, setSummaries] = useState<ReadonlyMap<string, ScheduleCostSummary>>(- () => new Map(),- );- const [loaded, setLoaded] = useState(false);- const refreshSeqRef = useRef(0);-- const refresh = useCallback(async () => {- const scheduleIds = scheduleIdsKey ? scheduleIdsKey.split('\u0000') : [];- const seq = refreshSeqRef.current + 1;- refreshSeqRef.current = seq;- if (scheduleIds.length === 0) {- setSummaries(new Map());- setLoaded(true);- return;- }-- try {- const visibleScheduleIds = new Set(scheduleIds);- const rows =- (await window.electronAPI.maker.schedule.listCostSummaries()) as ScheduleCostSummary[];- if (refreshSeqRef.current !== seq) return;-- const next = new Map<string, ScheduleCostSummary>();- for (const row of rows) {- if (!visibleScheduleIds.has(row.scheduleId)) continue;- next.set(row.scheduleId, row);- }- setSummaries(next);- setLoaded(true);- } catch (error) {- log.warn('failed to refresh schedule cost summaries', {- error: error instanceof Error ? error.message : String(error),- });- }- }, [scheduleIdsKey]);-- useEffect(() => {- void refresh();- const offSchedule = window.electronAPI.maker.schedule.onEvent((raw, ownerStamp) => {- if (!isDataOwnerPushCurrent(ownerStamp)) return;- const event = raw as SchedulerEvent;- if (- event.type === 'fired' ||- event.type === 'completed' ||- event.type === 'failed' ||- event.type === 'session-bound' ||- event.type === 'changed' ||- event.type === 'ready'- ) {- void refresh();- }- });- const offSpend = window.electronAPI.onUsageSessionSpendChanged((_payload, ownerStamp) => {- if (!isDataOwnerPushCurrent(ownerStamp)) return;- void refresh();- });- const offTurnCost = window.electronAPI.onUsageMessageTurnCost?.((_payload, ownerStamp) => {- if (!isDataOwnerPushCurrent(ownerStamp)) return;- void refresh();- });- return () => {- offSchedule();- offSpend();- offTurnCost?.();- };- }, [refresh]);-- return { summaries, loaded };-}diff --git a/apps/desktop/src/renderer/features/scheduler/lib/__tests__/scheduleSidebarIndexRuns.test.ts b/apps/desktop/src/renderer/features/scheduler/lib/__tests__/scheduleSidebarIndexRuns.test.tsnew file mode 100644index 0000000000..d60890db81--- /dev/null+++ b/apps/desktop/src/renderer/features/scheduler/lib/__tests__/scheduleSidebarIndexRuns.test.ts@@ -0,0 +1,41 @@+import { describe, expect, it } from 'vitest';++import {+ findLatestSidebarIndexRunForSession,+ type ScheduleSidebarIndexRun,+} from '../scheduleSidebarIndexRuns';++const run = (partial: Partial<ScheduleSidebarIndexRun>): ScheduleSidebarIndexRun => ({+ runId: 'run-1',+ scheduleId: 'schedule-1',+ scheduleName: 'Automation',+ scheduleStatus: 'active',+ status: 'success',+ ...partial,+});++describe('findLatestSidebarIndexRunForSession', () => {+ it('chooses the latest Automation mapping when an older unread run appears first', () => {+ const olderUnread = run({+ runId: 'run-old',+ scheduleId: 'schedule-old',+ sessionId: 'session-1',+ firedAt: 100,+ });+ const latest = run({+ runId: 'run-latest',+ scheduleId: 'schedule-latest',+ sessionId: 'session-1',+ firedAt: 200,+ });++ expect(findLatestSidebarIndexRunForSession([olderUnread, latest], 'session-1')).toBe(latest);+ });++ it('uses run id as the deterministic tie-breaker used by the database projection', () => {+ const first = run({ runId: 'run-a', sessionId: 'session-1', firedAt: 200 });+ const second = run({ runId: 'run-b', sessionId: 'session-1', firedAt: 200 });++ expect(findLatestSidebarIndexRunForSession([second, first], 'session-1')).toBe(second);+ });+});diff --git a/apps/desktop/src/renderer/features/scheduler/lib/scheduleSidebarIndexRuns.ts b/apps/desktop/src/renderer/features/scheduler/lib/scheduleSidebarIndexRuns.tsindex 10dbdf191a..2fa351790d 100644--- a/apps/desktop/src/renderer/features/scheduler/lib/scheduleSidebarIndexRuns.ts+++ b/apps/desktop/src/renderer/features/scheduler/lib/scheduleSidebarIndexRuns.ts@@ -29,6 +29,30 @@ export interface ScheduleSidebarIndexSnapshot {inflightRunIds: string[];}+/**+ * 同一 session 可能同时返回最新映射和更早的未读 run。需要 Automation 归属的入口+ * 必须按 projection 的 (firedAt, runId) 规则取最新一条,不能依赖数组顺序或 find()。+ */+export function findLatestSidebarIndexRunForSession(+ runs: readonly ScheduleSidebarIndexRun[],+ sessionId: string,+): ScheduleSidebarIndexRun | undefined {+ let latest: ScheduleSidebarIndexRun | undefined;+ for (const run of runs) {+ if (run.sessionId !== sessionId) continue;+ const firedAt = run.firedAt ?? Number.NEGATIVE_INFINITY;+ const latestFiredAt = latest?.firedAt ?? Number.NEGATIVE_INFINITY;+ if (+ latest === undefined ||+ firedAt > latestFiredAt ||+ (firedAt === latestFiredAt && run.runId > latest.runId)+ ) {+ latest = run;+ }+ }+ return latest;+}+export async function loadScheduleSidebarIndexSnapshot(): Promise<ScheduleSidebarIndexSnapshot> {// main 与 renderer 同包发布,不存在版本 skew,所以这里不做跨形态兼容 —— 形态不符就是// bug,应该暴露出来而不是静默降级成「没有 in-flight 信息」(那会让对账去误清仍在跑的diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 6acbfb0561..2974825fa3 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -9107,7 +9107,7 @@"sessionCost": "Session cost {{cost}}","sessionValue": "Session value {{value}}","runCost": "Run cost {{cost}}",- "runValue": "Estimated run value {{value}}",+ "runTokens": "Token usage {{tokens}}","costUnavailable": "Cost unavailable","legacyCostUnavailable": "Historical cost unavailable","persistentSessionGroup": "Persistent session {{session}} · {{count}} runs",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 3bab03e4ad..3295e8a9f4 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -9092,7 +9092,7 @@"sessionCost": "セッションコスト {{cost}}","sessionValue": "セッション価値 {{value}}","runCost": "実行コスト {{cost}}",- "runValue": "実行の推定価値 {{value}}",+ "runTokens": "トークン使用量 {{tokens}}","costUnavailable": "コストを取得できません","legacyCostUnavailable": "過去のコストは実行別に分割できません","persistentSessionGroup": "継続セッション {{session}} · {{count}} 回の実行",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex a3a913ff72..dc5bc44dbf 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -9092,7 +9092,7 @@"sessionCost": "세션 비용 {{cost}}","sessionValue": "세션 가치 {{value}}","runCost": "실행 비용 {{cost}}",- "runValue": "실행 추정 가치 {{value}}",+ "runTokens": "토큰 사용량 {{tokens}}","costUnavailable": "비용을 확인할 수 없음","legacyCostUnavailable": "이전 비용은 실행별로 구분할 수 없습니다","persistentSessionGroup": "지속 세션 {{session}} · {{count}}회 실행",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 749fadbabc..6cd44d5355 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -9084,7 +9084,7 @@"sessionCost": "任务开销 {{cost}}","sessionValue": "任务价值 {{value}}","runCost": "本次开销 {{cost}}",- "runValue": "本次估算价值 {{value}}",+ "runTokens": "Token 消耗 {{tokens}}","costUnavailable": "费用不可用","legacyCostUnavailable": "历史费用无法拆分","persistentSessionGroup": "持续任务 {{session}} · {{count}} 次运行",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex 8c995512a6..1df1b13260 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -9084,7 +9084,7 @@"sessionCost": "任務開銷 {{cost}}","sessionValue": "任務價值 {{value}}","runCost": "本次開銷 {{cost}}",- "runValue": "本次估算價值 {{value}}",+ "runTokens": "Token 消耗 {{tokens}}","costUnavailable": "費用不可用","legacyCostUnavailable": "歷史費用無法拆分","persistentSessionGroup": "持續任務 {{session}} · {{count}} 次執行",diff --git a/apps/desktop/src/renderer/lib/silencedSessionDoneStore.ts b/apps/desktop/src/renderer/lib/silencedSessionDoneStore.tsindex 3bfd893e6b..e7c7ca8ab3 100644--- a/apps/desktop/src/renderer/lib/silencedSessionDoneStore.ts+++ b/apps/desktop/src/renderer/lib/silencedSessionDoneStore.ts@@ -167,8 +167,8 @@ export interface ReconcileRunMarkersResult {* - 两份都没有 → 同样排 linger 退场。该 run 已经不存在了:删除 schedule 会级联删掉* 它的 `schedule_runs` 行,deferred run 也会被显式删除,这两种情况永远等不到一个终态* 状态。这里不可能是「标记建好但 run 还没落库」的极早期 —— 引擎先 `updateRun` 写- * sessionId、再 emit `session-bound` / `silenced`,而权威快照包含所有带 sessionId 的- * run,所以标记存在就意味着该 run 当时已进入快照范围。异步拉取的过期结果由调用方的+ * sessionId、再 emit `session-bound` / `silenced`,而权威快照包含所有 running run,+ * 所以标记存在就意味着该 run 当时已进入快照范围。异步拉取的过期结果由调用方的* seq 守卫挡掉,不会走到这里。** **空的 dbRunStatus 不是异常,一样要对账**:权威查询在库里没有匹配行时合法返回空数组diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.tsindex f1af1f70fb..6b6ca1eff6 100644--- a/apps/desktop/src/renderer/vite-env.d.ts+++ b/apps/desktop/src/renderer/vite-env.d.ts@@ -6194,7 +6194,6 @@ interface ElectronAPI {listRuns: (id: string, limit?: number) => Promise<unknown[]>;/** { runs, inflightRunIds } —— 形态见 features/scheduler/lib/scheduleSidebarIndexRuns。 */listSidebarIndexRuns: () => Promise<unknown>;- listCostSummaries: () => Promise<unknown[]>;deleteRun: (runId: string) => Promise<void>;getInflightCount: (id: string) => Promise<number>;getRuntimeState: () => Promise<unknown>;diff --git a/packages/maker-scheduler/src/types.ts b/packages/maker-scheduler/src/types.tsindex 6402d46d9b..67af2e1546 100644--- a/packages/maker-scheduler/src/types.ts+++ b/packages/maker-scheduler/src/types.ts@@ -282,6 +282,8 @@ export interface ScheduleRun {costMoney?: ScheduleRunMoney;/** 新版区域订阅价值估算;不代表实际账单。 */estimatedValueMoney?: ScheduleRunMoney;+ /** 本次 run 关联 assistant 消息的 Token 用量总和,供无法可靠计价时展示。 */+ totalTokens?: number;/*** exact = 已确认费用(可能是实际账单,也可能是 estimate-only);direct = 费用仅来自* 无法挂载消息的直接账本;mixed = 快照同时包含直接账本和消息账本;zero = 已确认零费用;