Skip to content

armgit / cindy

Public Imported from GitHub
0

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

fix(context): 修复小预算空回复与上下文圆环回退 (#4233)

Chris Zhange384c8eb8581
diff --git a/apps/desktop/drizzle/0105_context_window_runtime.sql b/apps/desktop/drizzle/0105_context_window_runtime.sql
new file mode 100644
index 0000000000..b2441612c8
--- /dev/null
+++ b/apps/desktop/drizzle/0105_context_window_runtime.sql
@@ -0,0 +1 @@
+ALTER TABLE `sessions` ADD `context_window_runtime` integer;
\ No newline at end of file
diff --git a/apps/desktop/drizzle/meta/0105_snapshot.json b/apps/desktop/drizzle/meta/0105_snapshot.json
new file mode 100644
index 0000000000..9b87a45248
--- /dev/null
+++ b/apps/desktop/drizzle/meta/0105_snapshot.json
@@ -0,0 +1,5795 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "ff51d467-9cdb-483f-8397-6043b5e7aabd",
+ "prevId": "fd130f32-aea4-433b-bcc0-647be7e90a5d",
+ "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": {}
+ },
+ "bot_delegations": {
+ "name": "bot_delegations",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "requesting_bot_id": {
+ "name": "requesting_bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "target_bot_id": {
+ "name": "target_bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "parent_session_id": {
+ "name": "parent_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "child_session_id": {
+ "name": "child_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "objective": {
+ "name": "objective",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "context_refs_json": {
+ "name": "context_refs_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "artifact_refs_json": {
+ "name": "artifact_refs_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "permission_snapshot_json": {
+ "name": "permission_snapshot_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "lineage_json": {
+ "name": "lineage_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "target_profile_version": {
+ "name": "target_profile_version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "depth": {
+ "name": "depth",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "budget_tokens": {
+ "name": "budget_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "tokens_used": {
+ "name": "tokens_used",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'queued'"
+ },
+ "result_summary": {
+ "name": "result_summary",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "output_artifacts_json": {
+ "name": "output_artifacts_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "pending_interaction_json": {
+ "name": "pending_interaction_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_error": {
+ "name": "last_error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "run_sequence": {
+ "name": "run_sequence",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "accepted_at": {
+ "name": "accepted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "completed_at": {
+ "name": "completed_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "completion_delivered_at": {
+ "name": "completion_delivered_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_bot_delegations_requester_status": {
+ "name": "idx_bot_delegations_requester_status",
+ "columns": [
+ "requesting_bot_id",
+ "status"
+ ],
+ "isUnique": false
+ },
+ "idx_bot_delegations_target_status": {
+ "name": "idx_bot_delegations_target_status",
+ "columns": [
+ "target_bot_id",
+ "status"
+ ],
+ "isUnique": false
+ },
+ "idx_bot_delegations_parent_session": {
+ "name": "idx_bot_delegations_parent_session",
+ "columns": [
+ "parent_session_id"
+ ],
+ "isUnique": false
+ },
+ "uniq_bot_delegations_child_session": {
+ "name": "uniq_bot_delegations_child_session",
+ "columns": [
+ "child_session_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "bot_delegations_requesting_bot_id_bot_profiles_id_fk": {
+ "name": "bot_delegations_requesting_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_delegations",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "requesting_bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_delegations_target_bot_id_bot_profiles_id_fk": {
+ "name": "bot_delegations_target_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_delegations",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "target_bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_delegations_parent_session_id_sessions_id_fk": {
+ "name": "bot_delegations_parent_session_id_sessions_id_fk",
+ "tableFrom": "bot_delegations",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "parent_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "bot_delegations_child_session_id_sessions_id_fk": {
+ "name": "bot_delegations_child_session_id_sessions_id_fk",
+ "tableFrom": "bot_delegations",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "child_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_direct_message_threads": {
+ "name": "bot_direct_message_threads",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_a_id": {
+ "name": "bot_a_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_b_id": {
+ "name": "bot_b_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "close_reason": {
+ "name": "close_reason",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "message_count": {
+ "name": "message_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "max_messages": {
+ "name": "max_messages",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "blocked_until": {
+ "name": "blocked_until",
+ "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
+ },
+ "closed_at": {
+ "name": "closed_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_bot_dm_threads_active_pair": {
+ "name": "uniq_bot_dm_threads_active_pair",
+ "columns": [
+ "bot_a_id",
+ "bot_b_id"
+ ],
+ "isUnique": true,
+ "where": "\"bot_direct_message_threads\".\"status\" = 'active'"
+ },
+ "idx_bot_dm_threads_pair_updated": {
+ "name": "idx_bot_dm_threads_pair_updated",
+ "columns": [
+ "bot_a_id",
+ "bot_b_id",
+ "updated_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_direct_message_threads_bot_a_id_bot_profiles_id_fk": {
+ "name": "bot_direct_message_threads_bot_a_id_bot_profiles_id_fk",
+ "tableFrom": "bot_direct_message_threads",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_a_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_direct_message_threads_bot_b_id_bot_profiles_id_fk": {
+ "name": "bot_direct_message_threads_bot_b_id_bot_profiles_id_fk",
+ "tableFrom": "bot_direct_message_threads",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_b_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_direct_messages": {
+ "name": "bot_direct_messages",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "thread_id": {
+ "name": "thread_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sequence": {
+ "name": "sequence",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sender_bot_id": {
+ "name": "sender_bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "recipient_bot_id": {
+ "name": "recipient_bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sender_session_id": {
+ "name": "sender_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "recipient_session_id": {
+ "name": "recipient_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "delivery_status": {
+ "name": "delivery_status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_bot_direct_messages_thread_sequence": {
+ "name": "uniq_bot_direct_messages_thread_sequence",
+ "columns": [
+ "thread_id",
+ "sequence"
+ ],
+ "isUnique": true
+ },
+ "idx_bot_direct_messages_thread_created": {
+ "name": "idx_bot_direct_messages_thread_created",
+ "columns": [
+ "thread_id",
+ "created_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_direct_messages_thread_id_bot_direct_message_threads_id_fk": {
+ "name": "bot_direct_messages_thread_id_bot_direct_message_threads_id_fk",
+ "tableFrom": "bot_direct_messages",
+ "tableTo": "bot_direct_message_threads",
+ "columnsFrom": [
+ "thread_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_direct_messages_sender_bot_id_bot_profiles_id_fk": {
+ "name": "bot_direct_messages_sender_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_direct_messages",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "sender_bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_direct_messages_recipient_bot_id_bot_profiles_id_fk": {
+ "name": "bot_direct_messages_recipient_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_direct_messages",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "recipient_bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_direct_messages_sender_session_id_sessions_id_fk": {
+ "name": "bot_direct_messages_sender_session_id_sessions_id_fk",
+ "tableFrom": "bot_direct_messages",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "sender_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "bot_direct_messages_recipient_session_id_sessions_id_fk": {
+ "name": "bot_direct_messages_recipient_session_id_sessions_id_fk",
+ "tableFrom": "bot_direct_messages",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "recipient_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_lifecycle_events": {
+ "name": "bot_lifecycle_events",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_id": {
+ "name": "bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "event_type": {
+ "name": "event_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "payload_json": {
+ "name": "payload_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_bot_lifecycle_events_bot_created": {
+ "name": "idx_bot_lifecycle_events_bot_created",
+ "columns": [
+ "bot_id",
+ "created_at"
+ ],
+ "isUnique": false
+ },
+ "idx_bot_lifecycle_events_session_created": {
+ "name": "idx_bot_lifecycle_events_session_created",
+ "columns": [
+ "session_id",
+ "created_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_lifecycle_events_bot_id_bot_profiles_id_fk": {
+ "name": "bot_lifecycle_events_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_lifecycle_events",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_lifecycle_events_session_id_sessions_id_fk": {
+ "name": "bot_lifecycle_events_session_id_sessions_id_fk",
+ "tableFrom": "bot_lifecycle_events",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_profile_versions": {
+ "name": "bot_profile_versions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_id": {
+ "name": "bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "version": {
+ "name": "version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "identity_source": {
+ "name": "identity_source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "capabilities_json": {
+ "name": "capabilities_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_bot_profile_versions_bot_version": {
+ "name": "uniq_bot_profile_versions_bot_version",
+ "columns": [
+ "bot_id",
+ "version"
+ ],
+ "isUnique": true
+ },
+ "idx_bot_profile_versions_bot_created": {
+ "name": "idx_bot_profile_versions_bot_created",
+ "columns": [
+ "bot_id",
+ "created_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_profile_versions_bot_id_bot_profiles_id_fk": {
+ "name": "bot_profile_versions_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_profile_versions",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_profiles": {
+ "name": "bot_profiles",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "display_name": {
+ "name": "display_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "avatar": {
+ "name": "avatar",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'🤖'"
+ },
+ "avatar_color": {
+ "name": "avatar_color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'violet'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "hidden_at": {
+ "name": "hidden_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "pinned_at": {
+ "name": "pinned_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "attention_reason": {
+ "name": "attention_reason",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "attention_at": {
+ "name": "attention_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "current_version": {
+ "name": "current_version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "canonical_session_id": {
+ "name": "canonical_session_id",
+ "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": {
+ "idx_bot_profiles_status_updated": {
+ "name": "idx_bot_profiles_status_updated",
+ "columns": [
+ "status",
+ "updated_at"
+ ],
+ "isUnique": false
+ },
+ "idx_bot_profiles_canonical_session": {
+ "name": "idx_bot_profiles_canonical_session",
+ "columns": [
+ "canonical_session_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_profiles_canonical_session_id_sessions_id_fk": {
+ "name": "bot_profiles_canonical_session_id_sessions_id_fk",
+ "tableFrom": "bot_profiles",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "canonical_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_runtime_snapshots": {
+ "name": "bot_runtime_snapshots",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_id": {
+ "name": "bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "profile_version": {
+ "name": "profile_version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "working_dir": {
+ "name": "working_dir",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "memory_scope_key": {
+ "name": "memory_scope_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "configured_json": {
+ "name": "configured_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "resolved_json": {
+ "name": "resolved_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "prepared_at": {
+ "name": "prepared_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "applied_at": {
+ "name": "applied_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "failed_at": {
+ "name": "failed_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "failure_json": {
+ "name": "failure_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_bot_runtime_snapshots_bot_prepared": {
+ "name": "idx_bot_runtime_snapshots_bot_prepared",
+ "columns": [
+ "bot_id",
+ "prepared_at"
+ ],
+ "isUnique": false
+ },
+ "idx_bot_runtime_snapshots_session_prepared": {
+ "name": "idx_bot_runtime_snapshots_session_prepared",
+ "columns": [
+ "session_id",
+ "prepared_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_runtime_snapshots_bot_id_bot_profiles_id_fk": {
+ "name": "bot_runtime_snapshots_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_runtime_snapshots",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_runtime_snapshots_session_id_sessions_id_fk": {
+ "name": "bot_runtime_snapshots_session_id_sessions_id_fk",
+ "tableFrom": "bot_runtime_snapshots",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_session_links": {
+ "name": "bot_session_links",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_id": {
+ "name": "bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "profile_version": {
+ "name": "profile_version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "route_key": {
+ "name": "route_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "archived_at": {
+ "name": "archived_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_bot_session_links_session": {
+ "name": "uniq_bot_session_links_session",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": true
+ },
+ "uniq_bot_session_links_canonical_per_bot": {
+ "name": "uniq_bot_session_links_canonical_per_bot",
+ "columns": [
+ "bot_id"
+ ],
+ "isUnique": true,
+ "where": "\"bot_session_links\".\"role\" = 'canonical'"
+ },
+ "idx_bot_session_links_bot_role": {
+ "name": "idx_bot_session_links_bot_role",
+ "columns": [
+ "bot_id",
+ "role"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_session_links_bot_id_bot_profiles_id_fk": {
+ "name": "bot_session_links_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_session_links",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_session_links_session_id_sessions_id_fk": {
+ "name": "bot_session_links_session_id_sessions_id_fk",
+ "tableFrom": "bot_session_links",
+ "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'"
+ },
+ "right_sidebar_tabs_bot_artifacts_singleton_idx": {
+ "name": "right_sidebar_tabs_bot_artifacts_singleton_idx",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": true,
+ "where": "\"right_sidebar_tabs\".\"kind\" = 'bot-artifacts'"
+ }
+ },
+ "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_agent_kind": {
+ "name": "model_agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "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
+ },
+ "context_window_runtime": {
+ "name": "context_window_runtime",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "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": "'[]'"
+ },
+ "writable_dirs": {
+ "name": "writable_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_skill_recent": {
+ "name": "idx_skill_usage_exposures_skill_recent",
+ "columns": [
+ "skill_name",
+ "analyzer_version",
+ "seen_at"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_exposures_skill_recent_any_version": {
+ "name": "idx_skill_usage_exposures_skill_recent_any_version",
+ "columns": [
+ "skill_name",
+ "seen_at"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_exposures_analyzer_recent_source": {
+ "name": "idx_skill_usage_exposures_analyzer_recent_source",
+ "columns": [
+ "analyzer_version",
+ "seen_at",
+ "raw_file_path"
+ ],
+ "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 file
diff --git a/apps/desktop/drizzle/meta/_journal.json b/apps/desktop/drizzle/meta/_journal.json
index 061fda29b6..d337d3608c 100644
--- a/apps/desktop/drizzle/meta/_journal.json
+++ b/apps/desktop/drizzle/meta/_journal.json
@@ -736,6 +736,13 @@
"when": 1788783797334,
"tag": "0104_schedule-model-harness",
"breakpoints": true
+ },
+ {
+ "idx": 105,
+ "version": "6",
+ "when": 1789033649781,
+ "tag": "0105_context_window_runtime",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/apps/desktop/src/main/__tests__/fork.test.ts b/apps/desktop/src/main/__tests__/fork.test.ts
index c28392d1ae..57092719db 100644
--- a/apps/desktop/src/main/__tests__/fork.test.ts
+++ b/apps/desktop/src/main/__tests__/fork.test.ts
@@ -18,6 +18,7 @@ import path from 'node:path';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { CodexResumePreparationBlockedError } from '@cindy/maker-core';
import { CODEX_RESUME_NOT_READY_WIRE_MESSAGE } from '@cindy/maker-shared/agent-input-projection';
+import { projectSessionContextWindow } from '../../shared/sessionContextWindow';
import { computeForkSourceMessagesDigest } from '../localDb/forkRecoverySnapshot.js';
const UUID_V4_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
@@ -204,7 +205,11 @@ async function writeClaudeJsonlInConfigDir(
// ── tests ──────────────────────────────────────────────────────────────────
describe('forkSessionAtMessage', () => {
- it('happy path: fork copies prior messages, calls maker.forkSdkSession with assistant uuid, seeds context snapshot', async () => {
+ it.each([
+ { marker: 200000, projectedWindow: 200000 },
+ { marker: null, projectedWindow: 272000 },
+ { marker: 100000, projectedWindow: 272000 },
+ ])('fork preserves only proven runtime context (marker=$marker)', async ({ marker, projectedWindow }) => {
const target = makeMessageRow({ id: 'target-user', role: 'user', createdAt: 3000 });
const priorAssistant = makeMessageRow({
id: 'asst-1',
@@ -220,7 +225,7 @@ describe('forkSessionAtMessage', () => {
createdAt: 2000,
});
- selectQueue.push([makeSourceRow()]); // source session
+ selectQueue.push([makeSourceRow({ contextWindowRuntime: marker })]); // source session
selectQueue.push([target]); // target message
selectQueue.push([priorUser, priorAssistant]); // prior messages asc (for bulk copy)
selectQueue.push([
@@ -276,6 +281,13 @@ describe('forkSessionAtMessage', () => {
expect(sv.totalCostUsd).toBe(0);
expect(sv.contextTokens).toBe(123456);
expect(sv.contextWindow).toBe(200000);
+ expect(sv.contextWindowRuntime).toBe(marker === 200000 ? 200000 : null);
+ // list/get apply this projection after loading the inserted fork row.
+ const projected = projectSessionContextWindow({
+ contextWindow: sv.contextWindow as number,
+ contextWindowRuntime: sv.contextWindowRuntime as number | null,
+ }, () => 272000);
+ expect(projected.contextWindow).toBe(projectedWindow);
expect(sv.clearedAt).toBeNull();
expect(sv.pinnedAt).toBeNull();
expect(typeof sv.userSendAt).toBe('number');
@@ -1182,7 +1194,13 @@ describe('forkSessionAtMessage', () => {
expect(txCalls).toHaveLength(0);
});
- it('forks a historical Claude node from the parked native session instead of the current Codex thread', async () => {
+ it.each([
+ { route: 'current Codex thread', agentKind: 'codex', model: 'gpt-5.4', providerId: 'xd', expectedMarker: null },
+ { route: 'different engine', agentKind: 'pi', model: 'claude-sonnet-4-6', providerId: null, expectedMarker: null },
+ { route: 'different model', agentKind: 'cc', model: 'claude-opus-4-6', providerId: null, expectedMarker: null },
+ { route: 'different provider', agentKind: 'cc', model: 'claude-sonnet-4-6', providerId: 'xd', expectedMarker: null },
+ { route: 'same route', agentKind: 'cc', model: 'claude-sonnet-4-6', providerId: null, expectedMarker: 1000000 },
+ ])('forks historical Claude history with $route window provenance', async ({ agentKind, model, providerId, expectedMarker }) => {
const target = makeMessageRow({
id: 'historical-assistant',
clientId: 'historical-assistant-cid',
@@ -1201,8 +1219,11 @@ describe('forkSessionAtMessage', () => {
});
selectQueue.push([
makeSourceRow({
- agentKind: 'codex',
- model: 'gpt-5.4',
+ agentKind,
+ model,
+ providerId,
+ contextWindow: 1000000,
+ contextWindowRuntime: 1000000,
sdkSessionId: 'current-codex-thread',
}),
]);
@@ -1224,6 +1245,7 @@ describe('forkSessionAtMessage', () => {
fromAgentKind: 'cc',
toAgentKind: 'codex',
fromModel: 'claude-sonnet-4-6',
+ fromProviderId: null,
fromSdkSessionId: 'parked-claude-session',
handoff: 'handoff',
}),
@@ -1257,6 +1279,12 @@ describe('forkSessionAtMessage', () => {
expect(txArgs.newSession.agentKind).toBe('cc');
expect(txArgs.newSession.model).toBe('claude-sonnet-4-6');
expect(txArgs.newSession.providerId).toBeNull();
+ expect(txArgs.newSession.contextWindowRuntime).toBe(expectedMarker);
+ const projected = projectSessionContextWindow({
+ contextWindow: txArgs.newSession.contextWindow as number,
+ contextWindowRuntime: txArgs.newSession.contextWindowRuntime as number | null,
+ }, () => 200000);
+ expect(projected.contextWindow).toBe(expectedMarker ?? 200000);
});
it.each([false, true])('restores the provider snapshot from a new historical switch boundary (recovery=%s)', async (recovery) => {
diff --git a/apps/desktop/src/main/__tests__/sessionSpendBroadcaster.test.ts b/apps/desktop/src/main/__tests__/sessionSpendBroadcaster.test.ts
index c17dd6a66c..02bc6df0b0 100644
--- a/apps/desktop/src/main/__tests__/sessionSpendBroadcaster.test.ts
+++ b/apps/desktop/src/main/__tests__/sessionSpendBroadcaster.test.ts
@@ -47,6 +47,11 @@ beforeEach(() => {
});
describe('recordSessionContextSnapshot', () => {
+ it('does not certify an old catalog window when a status only supplies tokens', async () => {
+ await recordSessionContextSnapshot('s1', 42, 0);
+ expect(setMock).toHaveBeenCalledWith({ contextTokens: 42 });
+ });
+
it('skips 0/0 placeholder snapshots from interrupted compact turns', async () => {
await recordSessionContextSnapshot('s1', 0, 0);
@@ -58,7 +63,7 @@ describe('recordSessionContextSnapshot', () => {
it('persists zero context tokens when the context window is authoritative', async () => {
await recordSessionContextSnapshot('s1', 0, 200000);
- expect(setMock).toHaveBeenCalledWith({ contextTokens: 0, contextWindow: 200000 });
+ expect(setMock).toHaveBeenCalledWith({ contextTokens: 0, contextWindow: 200000, contextWindowRuntime: 200000 });
expect(runMock).toHaveBeenCalledTimes(1);
expect(getMock).toHaveBeenCalledTimes(1);
});
diff --git a/apps/desktop/src/main/__tests__/sessionsListIncludePinned.test.ts b/apps/desktop/src/main/__tests__/sessionsListIncludePinned.test.ts
index e99f52e096..3cddb23db6 100644
--- a/apps/desktop/src/main/__tests__/sessionsListIncludePinned.test.ts
+++ b/apps/desktop/src/main/__tests__/sessionsListIncludePinned.test.ts
@@ -120,6 +120,7 @@ function sessionRow(id: string, patch: Record<string, unknown> = {}) {
totalCostUsd: 0,
contextTokens: 0,
contextWindow: 0,
+ contextWindowRuntime: null as number | null,
fastMode: 0,
clearedAt: null,
pinnedAt: null,
@@ -174,25 +175,25 @@ function resolveReferencesHandler() {
}
describe('local-db:sessions:list includePinned', () => {
- it('projects usage-history windows before stripping agent identity from the response', async () => {
+ it('preserves applied usage-history windows when stripping agent identity from the response', async () => {
const resolveContextWindow = vi.fn((row: { agentKind?: string | null }) =>
row.agentKind === 'codex' ? 272_000 : null,
);
registerSessionIpc(undefined, { resolveContextWindow });
const handler = h.ipcHandle.mock.calls.find(([name]) => name === 'local-db:sessions:list')![1];
h.queryResults.push([
- sessionRow('codex', { agentKind: 'codex', contextWindow: 1_050_000, contextTokens: 140_500 }),
+ sessionRow('codex', { agentKind: 'codex', contextWindow: 1_050_000, contextWindowRuntime: 1_050_000, contextTokens: 140_500 }),
sessionRow('pi', { agentKind: 'pi', contextWindow: 872_000, contextTokens: 140_500 }),
]);
const result = await handler({}, 20, 'all', { usageHistory: true });
- expect(result[0]).toMatchObject({ contextWindow: 272_000, contextTokens: 140_500 });
+ expect(result[0]).toMatchObject({ contextWindow: 1_050_000, contextTokens: 140_500 });
expect(result[1]).toMatchObject({ contextWindow: 872_000, contextTokens: 140_500 });
expect(result[0]).not.toHaveProperty('agentKind');
expect(result[1]).not.toHaveProperty('agentKind');
});
it.each(['local-db:sessions:get', 'local-db:sessions:list'])(
- '%s projects historical context using the stored route without writing it',
+ '%s corrects legacy history but preserves proven runtime windows without writing it',
async (channel) => {
const resolveContextWindow = vi.fn(() => 272_000);
registerSessionIpc(undefined, { resolveContextWindow });
@@ -210,6 +211,15 @@ describe('local-db:sessions:list includePinned', () => {
agentKind: 'codex', model: 'gpt-6-astra', providerId: 'openai',
}));
expect(saved.session.contextWindow).toBe(1_050_000);
+ expect(result).not.toHaveProperty('contextWindowRuntime');
+ saved.session.contextWindow = 1_000;
+ saved.session.contextWindowRuntime = 1_000;
+ h.queryResults.push([saved]);
+ const runtime = channel.endsWith(':get')
+ ? await handler({}, 'old-astra')
+ : (await handler({}, 20, 'active'))[0];
+ expect(runtime).toMatchObject({ contextTokens: 140_500, contextWindow: 1_000 });
+ expect(runtime).not.toHaveProperty('contextWindowRuntime');
},
);
@@ -270,6 +280,7 @@ describe('local-db:sessions:list includePinned', () => {
'totalTokenUsage',
'contextTokens',
'contextWindow',
+ 'contextWindowRuntime',
'agentKind',
'userSendAt',
'updatedAt',
diff --git a/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts b/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts
index a887c8308b..ca9e715488 100644
--- a/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts
+++ b/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts
@@ -102,6 +102,25 @@ function columnNames(db: Database.Database, tableName: string): string[] {
}
describeMigrationReplay('migration replay', () => {
+ it('adds runtime provenance without certifying or changing legacy context values', () => {
+ const { db, cleanup } = createTempDb();
+ const stagedDir = mkdtempSync(path.join(tmpdir(), 'cindy-context-provenance-'));
+ try {
+ db.exec(`CREATE TABLE migration_meta (key TEXT PRIMARY KEY NOT NULL, value TEXT NOT NULL);
+ CREATE TABLE sessions (id TEXT PRIMARY KEY, context_tokens INTEGER, context_window INTEGER);
+ INSERT INTO sessions VALUES ('legacy', 140500, 1050000);`);
+ const migration = listMigrations(drizzleDir()).find((item) => item.fileName.endsWith('_context_window_runtime.sql'))!;
+ copyFileSync(migration.sqlPath, path.join(stagedDir, migration.fileName));
+ runMigrationReplay(db, { drizzleDir: stagedDir, currentVersion: migration.seq - 1 });
+ expect(db.prepare('SELECT * FROM sessions').get()).toEqual({
+ id: 'legacy', context_tokens: 140500, context_window: 1050000, context_window_runtime: null,
+ });
+ } finally {
+ rmSync(stagedDir, { recursive: true, force: true });
+ cleanup();
+ }
+ });
+
it.each(['missing table', 'legacy table', 'existing column'] as const)(
'replays the scheduled Harness migration safely with %s',
(state) => {
diff --git a/apps/desktop/src/main/localDb/__tests__/orcaTeamStore.test.ts b/apps/desktop/src/main/localDb/__tests__/orcaTeamStore.test.ts
index 4389c5ccbc..468e44b1e2 100644
--- a/apps/desktop/src/main/localDb/__tests__/orcaTeamStore.test.ts
+++ b/apps/desktop/src/main/localDb/__tests__/orcaTeamStore.test.ts
@@ -392,6 +392,7 @@ describe('orcaTeamStore', () => {
total_cost_is_approximate INTEGER NOT NULL DEFAULT 0,
context_tokens INTEGER NOT NULL DEFAULT 0,
context_window INTEGER NOT NULL DEFAULT 0,
+ context_window_runtime INTEGER,
fast_mode INTEGER NOT NULL DEFAULT 0,
plan_mode_enabled INTEGER NOT NULL DEFAULT 0,
cleared_at INTEGER,
diff --git a/apps/desktop/src/main/localDb/client/WorkerThreadTransport.ts b/apps/desktop/src/main/localDb/client/WorkerThreadTransport.ts
index 673d6cecfe..3fd19d1bdb 100644
--- a/apps/desktop/src/main/localDb/client/WorkerThreadTransport.ts
+++ b/apps/desktop/src/main/localDb/client/WorkerThreadTransport.ts
@@ -1854,7 +1854,7 @@ function forkSession(readyDb, args) {
throw invalidArgs('newMessageIds length mismatch: expected ' + sourceMessages.length + ', got ' + newMessageIds.length);
}
readyDb.prepare(
- 'INSERT INTO sessions (id, title, working_dir, model, provider_id, effort, permission_mode, status, sdk_session_id, total_token_usage, total_cost_usd, context_tokens, context_window, fast_mode, cleared_at, pinned_at, user_send_at, agent_kind, workspace_kind, codex_history_has_product_prompt, parent_session_id, forked_at_message_id, created_at, updated_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
+ 'INSERT INTO sessions (id, title, working_dir, model, provider_id, effort, permission_mode, status, sdk_session_id, total_token_usage, total_cost_usd, context_tokens, context_window, context_window_runtime, fast_mode, cleared_at, pinned_at, user_send_at, agent_kind, workspace_kind, codex_history_has_product_prompt, parent_session_id, forked_at_message_id, created_at, updated_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
).run(
expectString(newSession.id, 'newSession.id'),
expectString(newSession.title, 'newSession.title'),
@@ -1869,6 +1869,7 @@ function forkSession(readyDb, args) {
expectNumber(newSession.totalCostUsd, 'newSession.totalCostUsd'),
expectNumber(newSession.contextTokens, 'newSession.contextTokens'),
expectNumber(newSession.contextWindow, 'newSession.contextWindow'),
+ nullableNumber(newSession.contextWindowRuntime),
newSession.fastMode ? 1 : 0,
nullableNumber(newSession.clearedAt),
nullableNumber(newSession.pinnedAt),
diff --git a/apps/desktop/src/main/localDb/client/__tests__/drizzleProxy.test.ts b/apps/desktop/src/main/localDb/client/__tests__/drizzleProxy.test.ts
index b3d69e8d1a..a4a028d2bc 100644
--- a/apps/desktop/src/main/localDb/client/__tests__/drizzleProxy.test.ts
+++ b/apps/desktop/src/main/localDb/client/__tests__/drizzleProxy.test.ts
@@ -32,6 +32,7 @@ const DRIZZLE_PROXY_SCHEMA = [
total_cost_is_approximate INTEGER NOT NULL DEFAULT 0,
context_tokens INTEGER NOT NULL DEFAULT 0,
context_window INTEGER NOT NULL DEFAULT 0,
+ context_window_runtime INTEGER,
fast_mode INTEGER NOT NULL DEFAULT 0,
plan_mode_enabled INTEGER NOT NULL DEFAULT 0,
cleared_at INTEGER,
diff --git a/apps/desktop/src/main/localDb/client/__tests__/tx.test.ts b/apps/desktop/src/main/localDb/client/__tests__/tx.test.ts
index f8dc6d3a0e..470c67f921 100644
--- a/apps/desktop/src/main/localDb/client/__tests__/tx.test.ts
+++ b/apps/desktop/src/main/localDb/client/__tests__/tx.test.ts
@@ -71,6 +71,7 @@ CREATE TABLE sessions (
total_cost_is_approximate INTEGER NOT NULL DEFAULT 0,
context_tokens INTEGER NOT NULL DEFAULT 0,
context_window INTEGER NOT NULL DEFAULT 0,
+ context_window_runtime INTEGER,
fast_mode INTEGER NOT NULL DEFAULT 0,
cleared_at INTEGER,
pinned_at INTEGER,
@@ -199,6 +200,7 @@ interface TestSessionRow {
totalCostUsd: number;
contextTokens: number;
contextWindow: number;
+ contextWindowRuntime?: number | null;
fastMode: boolean;
clearedAt: number | null;
pinnedAt: number | null;
@@ -1679,7 +1681,7 @@ describe('db worker tx handlers', () => {
});
});
- it('fork.session inserts the new session and copies/remaps source messages', async () => {
+ it.each([false, true])('fork.session persists runtime provenance and remaps messages (inline=%s)', async (useInlineWorker) => {
await withClient(async (client) => {
await seedSession(client, 'src');
await client.exec(
@@ -1717,6 +1719,8 @@ describe('db worker tx handlers', () => {
parentSessionId: 'src',
forkedAtMessageId: 'c2',
providerId: 'xd',
+ contextWindow: 100000,
+ contextWindowRuntime: 100000,
}),
uuidMap: [
['old', 'new'],
@@ -1729,7 +1733,7 @@ describe('db worker tx handlers', () => {
expect(result).toEqual({ messageCount: 1 });
await expect(
client.queryOne(
- 'SELECT working_dir, parent_session_id, forked_at_message_id, provider_id FROM sessions WHERE id = ?',
+ 'SELECT working_dir, parent_session_id, forked_at_message_id, provider_id, context_window, context_window_runtime FROM sessions WHERE id = ?',
['forked'],
),
).resolves.toEqual({
@@ -1737,6 +1741,8 @@ describe('db worker tx handlers', () => {
parent_session_id: 'src',
forked_at_message_id: 'c2',
provider_id: 'xd',
+ context_window: 100000,
+ context_window_runtime: 100000,
});
const copied = await client.queryOne<{
id: string;
@@ -1754,7 +1760,7 @@ describe('db worker tx handlers', () => {
parentUuid: 'new-parent-tool',
transcriptParentUuid: 'new-parent',
});
- });
+ }, { useInlineWorker });
});
it.each([false, true])('fork.session recovery marker is atomic with the child (inline=%s)', async (useInlineWorker) => {
diff --git a/apps/desktop/src/main/localDb/client/tx/types.ts b/apps/desktop/src/main/localDb/client/tx/types.ts
index 1940f61a40..e4f4e33321 100644
--- a/apps/desktop/src/main/localDb/client/tx/types.ts
+++ b/apps/desktop/src/main/localDb/client/tx/types.ts
@@ -150,6 +150,7 @@ export interface ForkSessionArgs {
totalCostUsd: number;
contextTokens: number;
contextWindow: number;
+ contextWindowRuntime?: number | null;
fastMode: boolean | number;
clearedAt: number | null;
pinnedAt: number | null;
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
index adb36e4c03..03890c3c43 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
@@ -230,6 +230,7 @@ function createDb(filename = ':memory:'): void {
total_cost_is_approximate INTEGER NOT NULL DEFAULT 0,
context_tokens INTEGER NOT NULL DEFAULT 0,
context_window INTEGER NOT NULL DEFAULT 0,
+ context_window_runtime INTEGER,
fast_mode INTEGER NOT NULL DEFAULT 0,
plan_mode_enabled INTEGER NOT NULL DEFAULT 0,
cleared_at INTEGER,
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/sessionAutoTitlePersist.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/sessionAutoTitlePersist.test.ts
index f3684ac5ad..1109b81827 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionAutoTitlePersist.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionAutoTitlePersist.test.ts
@@ -71,6 +71,7 @@ function createDb(initialTitle: string): void {
total_cost_is_approximate INTEGER NOT NULL DEFAULT 0,
context_tokens INTEGER NOT NULL DEFAULT 0,
context_window INTEGER NOT NULL DEFAULT 0,
+ context_window_runtime INTEGER,
fast_mode INTEGER NOT NULL DEFAULT 0,
cleared_at INTEGER,
pinned_at INTEGER,
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsRestoreIfArchived.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsRestoreIfArchived.test.ts
index 50766917c5..4f84362d55 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsRestoreIfArchived.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsRestoreIfArchived.test.ts
@@ -96,6 +96,7 @@ function createDb(): void {
total_cost_is_approximate INTEGER NOT NULL DEFAULT 0,
context_tokens INTEGER NOT NULL DEFAULT 0,
context_window INTEGER NOT NULL DEFAULT 0,
+ context_window_runtime INTEGER,
fast_mode INTEGER NOT NULL DEFAULT 0,
cleared_at INTEGER,
pinned_at INTEGER,
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
index 935816287c..38f1cdf2a6 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
@@ -158,6 +158,7 @@ function createDb(): void {
total_cost_is_approximate INTEGER NOT NULL DEFAULT 0,
context_tokens INTEGER NOT NULL DEFAULT 0,
context_window INTEGER NOT NULL DEFAULT 0,
+ context_window_runtime INTEGER,
fast_mode INTEGER NOT NULL DEFAULT 0,
cleared_at INTEGER,
pinned_at INTEGER,
diff --git a/apps/desktop/src/main/localDb/ipc/sessions.ts b/apps/desktop/src/main/localDb/ipc/sessions.ts
index 6668304dc3..2e570f909e 100644
--- a/apps/desktop/src/main/localDb/ipc/sessions.ts
+++ b/apps/desktop/src/main/localDb/ipc/sessions.ts
@@ -1202,14 +1202,13 @@ export function registerSessionIpc(
scheduleSessionListProjectionBackfill(mergedRows);
return mergedRows.map((r) =>
- projectSessionContextWindow(
- sessionToCamel({
+ sessionToCamel(
+ projectSessionContextWindow({
...r.session,
messageCount: r.messageCount,
latestMessageExtract: r.latestMessageExtract,
latestMessageRole: r.latestMessageRole,
- }),
- opts.resolveContextWindow,
+ }, opts.resolveContextWindow),
),
);
};
@@ -1489,7 +1488,7 @@ export function registerSessionIpc(
const db = getDbClient().drizzle;
const row = await selectSessionWithCount(db, sid);
if (!row) throwIpcError('NOT_FOUND', 'Session 不存在');
- return projectSessionContextWindow(sessionToCamel(row), opts.resolveContextWindow);
+ return sessionToCamel(projectSessionContextWindow(row, opts.resolveContextWindow));
});
/**
@@ -2568,6 +2567,7 @@ function selectSessionUsageRows(
| 'totalTokenUsage'
| 'contextTokens'
| 'contextWindow'
+ | 'contextWindowRuntime'
| 'agentKind'
| 'userSendAt'
| 'updatedAt'
@@ -2583,6 +2583,7 @@ function selectSessionUsageRows(
totalTokenUsage: sessions.totalTokenUsage,
contextTokens: sessions.contextTokens,
contextWindow: sessions.contextWindow,
+ contextWindowRuntime: sessions.contextWindowRuntime,
agentKind: sessions.agentKind,
userSendAt: sessions.userSendAt,
updatedAt: sessions.updatedAt,
diff --git a/apps/desktop/src/main/localDb/schema.ts b/apps/desktop/src/main/localDb/schema.ts
index f6a758644a..3359e0b45b 100644
--- a/apps/desktop/src/main/localDb/schema.ts
+++ b/apps/desktop/src/main/localDb/schema.ts
@@ -79,6 +79,9 @@ export const sessions = sqliteTable(
.default(false),
contextTokens: integer('context_tokens').notNull().default(0),
contextWindow: integer('context_window').notNull().default(0),
+ /** Last window written by the runtime snapshot writer. Equality with contextWindow
+ * proves provenance; a later legacy/import writer changing the value invalidates it. */
+ contextWindowRuntime: integer('context_window_runtime'),
fastMode: integer('fast_mode', { mode: 'boolean' }).notNull().default(false),
/**
* 计划模式一级开关(与 permissionMode 正交):开启时 agent 先产出计划、经用户
diff --git a/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts b/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
index f17471397d..615be6a255 100644
--- a/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
+++ b/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
@@ -2469,11 +2469,11 @@ function forkSession(db: Database.Database, args: unknown): { messageCount: numb
`INSERT INTO sessions (
id, title, working_dir, model, provider_id, effort, permission_mode, status,
sdk_session_id, total_token_usage, total_cost_usd, context_tokens,
- context_window, fast_mode, cleared_at, pinned_at, user_send_at,
+ context_window, context_window_runtime, fast_mode, cleared_at, pinned_at, user_send_at,
agent_kind, workspace_kind, codex_history_has_product_prompt,
parent_session_id, forked_at_message_id,
created_at, updated_at
- ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
+ ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
).run(
expectString(newSession.id, 'newSession.id'),
expectString(newSession.title, 'newSession.title'),
@@ -2488,6 +2488,7 @@ function forkSession(db: Database.Database, args: unknown): { messageCount: numb
expectNumber(newSession.totalCostUsd, 'newSession.totalCostUsd'),
expectNumber(newSession.contextTokens, 'newSession.contextTokens'),
expectNumber(newSession.contextWindow, 'newSession.contextWindow'),
+ nullableNumber(newSession.contextWindowRuntime),
newSession.fastMode ? 1 : 0,
nullableNumber(newSession.clearedAt),
nullableNumber(newSession.pinnedAt),
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts
index b4ed20a855..bfe673b7a2 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts
@@ -430,35 +430,23 @@ describe('production Session event pipeline', () => {
await h.dispose();
});
- it('records context after status delivery and preserves Pi runtime context windows', async () => {
- const h = harness();
- Object.defineProperty(h.session, 'agentKind', { value: 'pi' });
- effects.fn('resolveVerifiedContextWindow').mockReturnValue(99999);
- h.emit(
- event(
- 'status',
- { isRunning: false, status: 'Done', contextTokens: 50, contextWindow: 12345 },
- { source: 'pi' },
- ),
- );
- ordered('broadcast', 'recordSessionContextSnapshot');
- expect(effects.fn('recordSessionContextSnapshot')).toHaveBeenCalledWith('task', 50, 12345);
- await h.dispose();
- });
-
- it('prefers the verified context window for a non-Pi session', async () => {
- const h = harness();
- effects.fn('resolveVerifiedContextWindow').mockReturnValue(99999);
- h.emit(
- event(
- 'status',
- { isRunning: false, status: 'Done', contextTokens: 50, contextWindow: 12345 },
- { source: 'claude-code' },
- ),
- );
- expect(effects.fn('recordSessionContextSnapshot')).toHaveBeenCalledWith('task', 50, 99999);
- await h.dispose();
- });
+ it.each(['pi', 'claude-code', 'codex'] as const)(
+ 'records the applied %s context after status delivery without catalog substitution',
+ async (agentKind) => {
+ const h = harness();
+ Object.defineProperty(h.session, 'agentKind', { value: agentKind });
+ effects.fn('resolveVerifiedContextWindow').mockReturnValue(1_050_000);
+ for (const contextWindow of [1_000, 32_000, 500_000]) {
+ h.emit(event('status', {
+ isRunning: false, status: 'Done', contextTokens: 6_000, contextWindow,
+ }, { source: agentKind }));
+ ordered('broadcast', 'recordSessionContextSnapshot');
+ expect(effects.fn('recordSessionContextSnapshot'))
+ .toHaveBeenLastCalledWith('task', 6_000, contextWindow);
+ }
+ await h.dispose();
+ },
+ );
it('keeps a retryable error running without resetting persistence', async () => {
const h = harness();
diff --git a/apps/desktop/src/main/maker-ipc/sessionEventSnapshots.ts b/apps/desktop/src/main/maker-ipc/sessionEventSnapshots.ts
index c7dadec807..138cd91c08 100644
--- a/apps/desktop/src/main/maker-ipc/sessionEventSnapshots.ts
+++ b/apps/desktop/src/main/maker-ipc/sessionEventSnapshots.ts
@@ -2,37 +2,18 @@ import { isOpenAiSubscriptionProviderId } from '../maker-host/codex-account-auth
import type { Session } from '@cindy/maker-core';
import { recordSessionContextSnapshot } from '../sessionSpendBroadcaster.js';
import { recordCodexAccountUsageSnapshot } from '../usageBroadcaster.js';
-import { dbToMakerAgentKind } from '../../shared/agentKindConversion.js';
-import { lookupVerifiedContextWindow } from './contextOverflowRollover.js';
import { getSessionProvider } from '../maker-host/session-provider-store.js';
-import { getActiveCatalog } from '../maker-host/active-catalog.js';
-import { resolveVerifiedContextWindow } from '../maker-host/catalog-to-descriptors.js';
import type { PreparedSessionEvent } from './sessionEventPreparation.js';
export function recordSessionEventSnapshots(session: Session, prepared: PreparedSessionEvent) {
const { pendingContextSnapshot, pendingCodexAccountUsageSnapshot } = prepared;
if (pendingContextSnapshot) {
- const piRuntimeWindow =
- session.agentKind === 'pi' &&
- Number.isFinite(pendingContextSnapshot.contextWindow) &&
- pendingContextSnapshot.contextWindow > 0
- ? pendingContextSnapshot.contextWindow
- : null;
- const verifiedWindow = lookupVerifiedContextWindow(
- (agentKind, modelId, providerId) =>
- resolveVerifiedContextWindow(
- getActiveCatalog(),
- dbToMakerAgentKind(agentKind),
- providerId,
- modelId,
- ),
- session.model,
- getSessionProvider(session.id),
- session.agentKind,
- );
+ // Harness translators already normalize the applied runtime budget. Replacing
+ // it with the current catalog here corrupts persistence and the later UI push,
+ // even when the live status event initially displayed the correct window.
recordSessionContextSnapshot(
session.id,
pendingContextSnapshot.contextTokens,
- piRuntimeWindow ?? verifiedWindow ?? pendingContextSnapshot.contextWindow,
+ pendingContextSnapshot.contextWindow,
);
}
if (pendingCodexAccountUsageSnapshot) {
diff --git a/apps/desktop/src/main/maker-orchestration/fork.ts b/apps/desktop/src/main/maker-orchestration/fork.ts
index bf2ffcdcaf..0dcdb5a98f 100644
--- a/apps/desktop/src/main/maker-orchestration/fork.ts
+++ b/apps/desktop/src/main/maker-orchestration/fork.ts
@@ -937,6 +937,8 @@ export async function forkSessionAtMessage(
}
const forkContextTokens = normalizePositiveInt(initialContextTokens);
const forkContextWindow = needsHistoryRecovery ? 0 : normalizePositiveInt(source.contextWindow);
+ const sameContextRoute = forkSource.agentKind === normalizeDbAgentKind(source.agentKind) &&
+ forkSource.model === source.model && forkSource.providerId === source.providerId;
// 5. SQLite 事务:insert 新 session + bulk copy messages
const now = Date.now();
@@ -979,6 +981,8 @@ export async function forkSessionAtMessage(
totalCostUsd: 0,
contextTokens: forkContextTokens,
contextWindow: forkContextWindow,
+ contextWindowRuntime: sameContextRoute && forkContextWindow > 0 && source.contextWindowRuntime === forkContextWindow
+ ? forkContextWindow : null,
fastMode: forkSource.agentKind === source.agentKind ? source.fastMode : false,
clearedAt: null,
pinnedAt: null,
diff --git a/apps/desktop/src/main/sessionSpendBroadcaster.ts b/apps/desktop/src/main/sessionSpendBroadcaster.ts
index 6d7fc3efaa..783c4848d7 100644
--- a/apps/desktop/src/main/sessionSpendBroadcaster.ts
+++ b/apps/desktop/src/main/sessionSpendBroadcaster.ts
@@ -243,11 +243,12 @@ export async function recordSessionContextSnapshot(
const ownerScope = captureOwnerScope();
try {
const db = getDbClient().drizzle;
- const updates: { contextTokens: number; contextWindow?: number } = {
+ const updates: { contextTokens: number; contextWindow?: number; contextWindowRuntime?: number } = {
contextTokens: Math.floor(contextTokens),
};
if (Number.isFinite(contextWindow) && contextWindow > 0) {
updates.contextWindow = Math.floor(contextWindow);
+ updates.contextWindowRuntime = updates.contextWindow;
}
await db
.update(sessions)
diff --git a/apps/desktop/src/renderer/__tests__/contextWindowDisplay.test.ts b/apps/desktop/src/renderer/__tests__/contextWindowDisplay.test.ts
index e20c619add..0009dd3336 100644
--- a/apps/desktop/src/renderer/__tests__/contextWindowDisplay.test.ts
+++ b/apps/desktop/src/renderer/__tests__/contextWindowDisplay.test.ts
@@ -33,42 +33,24 @@ describe('resolveDisplayContextWindow', () => {
})).toBe(0);
});
- it('replaces a restored large window only with verified route metadata', () => {
- expect(resolveDisplayContextWindow({
- sdkContextWindow: 1_050_000,
- modelContextWindow: 272_000,
- verifiedContextWindow: 272_000,
- })).toBe(272_000);
- expect(resolveDisplayContextWindow({
- sdkContextWindow: 1_050_000,
- modelContextWindow: 272_000,
- })).toBe(1_050_000);
- });
+ it.each([1_000, 32_000, 100_000, 128_000, 200_000, 872_000])(
+ 'preserves applied Claude/Pi budget %s even when catalog values disagree',
+ (sdkContextWindow) => {
+ expect(resolveDisplayContextWindow({
+ sdkContextWindow, verifiedContextWindow: 1_050_000, modelContextWindow: 1_050_000,
+ })).toBe(sdkContextWindow);
+ },
+ );
- it('follows an explicit long window and ignores invalid verified values', () => {
+ it('uses verified route metadata only before runtime usage is available', () => {
expect(resolveDisplayContextWindow({
- sdkContextWindow: 272_000,
- verifiedContextWindow: 872_000,
- })).toBe(872_000);
+ sdkContextWindow: 0, modelContextWindow: 1_050_000, verifiedContextWindow: 272_000,
+ })).toBe(272_000);
for (const verifiedContextWindow of [null, 0, -1, NaN, Infinity]) {
expect(resolveDisplayContextWindow({ sdkContextWindow: 872_000, verifiedContextWindow }))
.toBe(872_000);
}
});
- it('prefers maker capability when SDK reports the unknown-model 200K default', () => {
- expect(resolveDisplayContextWindow({
- modelContextWindow: 992_000,
- sdkContextWindow: 200_000,
- })).toBe(992_000);
- });
-
- it('does not let a stale 200K value from the previous model hide DeepSeek 1M context', () => {
- expect(resolveDisplayContextWindow({
- modelContextWindow: 1_048_576,
- sdkContextWindow: 200_000,
- })).toBe(1_048_576);
- });
-
it('keeps non-default SDK values as runtime ground truth', () => {
expect(resolveDisplayContextWindow({
modelContextWindow: 992_000,
@@ -85,14 +67,37 @@ describe('resolveDisplayContextWindow', () => {
});
describe('makerChatStore context window refresh', () => {
- it('preserves Codex usage when a model selection supplies another catalog window', () => {
- const sessionId = 'codex-context-window-switch-test';
+ it.each(['pi', 'claude-code'] as const)('refreshes %s metadata on consecutive model choices before any runtime usage', (agentKind) => {
+ const sessionId = `${agentKind}-context-window-switch-test`;
makerChatStore.purgeSession(sessionId);
- makerChatStore.setContextWindow(sessionId, 258_400);
- makerChatStore.setSessionRuntime(sessionId, { agentKind: 'codex' });
+ makerChatStore.setSessionRuntime(sessionId, { agentKind });
+ for (const window of [1_000, 32_000, 1_050_000, 1_000]) {
+ makerChatStore.setContextWindow(sessionId, window);
+ expect(makerChatStore.getSnapshot(sessionId).agentStatus.contextWindow).toBe(window);
+ }
+ makerChatStore.purgeSession(sessionId);
+ });
+ it.each([0, 9_000])('preserves an actual runtime budget with %s tokens against later metadata', (contextTokens) => {
+ const sessionId = 'runtime-budget-test';
+ makerChatStore.purgeSession(sessionId);
+ makerChatStore.setContextWindow(sessionId, 32_000);
+ makerChatStore.__applyStatusUpdateForTest(sessionId, {
+ sessionId, status: 'Done', isRunning: false, tokenUsage: 0, costUsd: 0,
+ contextTokens, contextWindow: 1_000,
+ });
makerChatStore.setContextWindow(sessionId, 1_050_000);
- expect(makerChatStore.getSnapshot(sessionId).agentStatus.contextWindow).toBe(258_400);
+ expect(makerChatStore.getSnapshot(sessionId).agentStatus.contextWindow).toBe(1_000);
+ makerChatStore.purgeSession(sessionId);
+ });
+
+ it('keeps Codex metadata unknown before a native snapshot arrives', () => {
+ const sessionId = 'codex-metadata-test';
+ makerChatStore.purgeSession(sessionId);
+ makerChatStore.setSessionRuntime(sessionId, { agentKind: 'codex' });
+ makerChatStore.setContextWindow(sessionId, 1_000);
+ makerChatStore.setContextWindow(sessionId, 32_000);
+ expect(makerChatStore.getSnapshot(sessionId).agentStatus.contextWindow).toBe(0);
makerChatStore.purgeSession(sessionId);
});
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreActiveView.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreActiveView.test.ts
index c3d0af7028..0a2b513a86 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreActiveView.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreActiveView.test.ts
@@ -47,6 +47,7 @@ vi.mock('@/lib/composerDraftStore', () => ({
import { makerChatStore } from '@/lib/makerChatStore';
import * as messageService from '@/lib/messageService';
+import * as sessionService from '@/lib/sessionService';
import {
markSessionAutomaticHistoryLoadCompleted,
restoreSessionAutomaticHistoryLoadAttempts,
@@ -240,6 +241,20 @@ describe('makerChatStore active view tracking', () => {
expect(makerChatStore.getSnapshot(otherIds[0]).messages).toHaveLength(0);
});
+ it.each([0, 9_000])('keeps read-projected windows replaceable unless history has %s used tokens', async (contextTokens) => {
+ const sessionId = sid('projected-context');
+ vi.mocked(sessionService.get).mockResolvedValueOnce({
+ agentKind: 'cc', remoteHostId: null, sdkSessionId: null, fastMode: false,
+ contextTokens, contextWindow: 272_000, totalCostUsd: 0,
+ } as Awaited<ReturnType<typeof sessionService.get>>);
+ makerChatStore.ensureInitialMessages(sessionId);
+ await flushPromises();
+ expect(makerChatStore.getSnapshot(sessionId).agentStatus.contextWindow).toBe(272_000);
+ makerChatStore.setContextWindow(sessionId, 1_000_000);
+ expect(makerChatStore.getSnapshot(sessionId).agentStatus.contextWindow)
+ .toBe(contextTokens > 0 ? 272_000 : 1_000_000);
+ });
+
it('initial history load backfills to the latest plan boundary', async () => {
const sessionId = sid('initial-plan-backfill');
const latestPage = Array.from({ length: 49 }, (_, i) =>
diff --git a/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx b/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx
index ffbac4ab21..7d7eb64e4e 100644
--- a/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx
+++ b/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx
@@ -65,7 +65,7 @@ import type {
ProviderView,
} from '@cindy/model-providers';
-import { MANAGED_OLLAMA_PROVIDER_ID } from '../../../shared/localModelRuntime';
+import { isLocalRuntimeBetaProviderId, MANAGED_OLLAMA_PROVIDER_ID } from '../../../shared/localModelRuntime';
import { modelBrand } from './modelManagementPresentation';
import { ModelPriceOverrideDialog } from './ModelPriceOverrideDialog';
import type { UnionModelRow } from './UnifiedModelList';
@@ -256,6 +256,13 @@ export function ModelAdvancedDrawer({
const ctxDirtyRef = useRef(false);
const defaultWindow = contextAgent === 'codex' && ctx.codexContext
? ctx.codexContext.contextWindow : contextModel?.contextWindow ?? 0;
+ // The editor guard is not a native request-capacity limit. Keep small/local
+ // model windows selectable and never derive this floor from a saved override.
+ // Local runtimes own their loaded window; their catalog maximum cannot set an editor floor.
+ const modelWindows = chatAgents.map((agent) => row?.byAgent[agent]?.contextWindow)
+ .filter((window): window is number => typeof window === 'number' && Number.isFinite(window) && window > 0);
+ const minimumContextK = isLocalRuntimeBetaProviderId(provider.id)
+ ? 1 : Math.max(1, Math.floor(Math.min(100_000, ...modelWindows) / 1000));
const routeWindow = primaryModel?.contextWindowMax ?? primaryModel?.contextWindow ?? 0;
const effectiveLimit = ctx.limit ?? (defaultWindow > 0 ? defaultWindow : null);
useEffect(() => {
@@ -270,8 +277,8 @@ export function ModelAdvancedDrawer({
const parsedK = Number(ctxDraft.trim());
const parsedTokens = parsedK * 1000;
const ctxInvalid =
- ctxDraft.trim() !== '' &&
- (!Number.isSafeInteger(parsedK) || parsedTokens < 1000 || parsedTokens > 100_000_000);
+ ctxDirtyRef.current && ctxDraft.trim() !== '' &&
+ (!Number.isSafeInteger(parsedK) || parsedK < minimumContextK || parsedTokens > 100_000_000);
const commitCtxDraft = useCallback(() => {
if (!ctxDirtyRef.current || ctxInvalid || ctx.loading) return;
ctxDirtyRef.current = false;
@@ -700,6 +707,7 @@ export function ModelAdvancedDrawer({
<p role="status" className="mt-1.5 text-12 text-[var(--warning-fg)]">
{t(
`settings.providers.models.advanced.${ctxInvalid ? 'contextInvalid' : ctx.error ? 'contextWriteFailed' : 'contextMixed'}`,
+ { min: minimumContextK },
)}
</p>
)}
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx
index 850d4125d9..bacc40944e 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx
@@ -65,7 +65,7 @@ const provider = {
agents: ['codex', 'claude-code'],
models: {},
} as ProviderView;
-function drawer(primary = model, bridgeDefault = primary.defaultEffort, bridgeEfforts = primary.efforts) {
+function drawer(primary = model, bridgeDefault = primary.defaultEffort, bridgeEfforts = primary.efforts, source = provider) {
const row = {
id: primary.id,
name: primary.name,
@@ -77,7 +77,7 @@ function drawer(primary = model, bridgeDefault = primary.defaultEffort, bridgeEf
};
return (
<ModelAdvancedDrawer
- provider={provider}
+ provider={source}
row={row}
open
onOpenChange={vi.fn()}
@@ -99,6 +99,53 @@ beforeEach(() => {
});
describe('model advanced editor', () => {
+ it('rejects new small settings but accepts 100K without rewriting existing small overrides', () => {
+ mocks.limit = 1_000;
+ draw();
+ const input = screen.getByRole('textbox') as HTMLInputElement;
+ expect(input.value).toBe('1');
+ expect(input.hasAttribute('aria-invalid')).toBe(false);
+ fireEvent.blur(input);
+ expect(mocks.setLimit).not.toHaveBeenCalled();
+ fireEvent.change(input, { target: { value: '2' } });
+ fireEvent.blur(input);
+ expect(input.getAttribute('aria-invalid')).toBe('true');
+ expect(mocks.setLimit).not.toHaveBeenCalled();
+ fireEvent.change(input, { target: { value: '99' } });
+ fireEvent.blur(input);
+ expect(mocks.setLimit).not.toHaveBeenCalled();
+ fireEvent.change(input, { target: { value: '100' } });
+ fireEvent.blur(input);
+ expect(mocks.setLimit).toHaveBeenLastCalledWith(100_000);
+ fireEvent.change(input, { target: { value: '1' } });
+ fireEvent.blur(input);
+ expect(mocks.setLimit).toHaveBeenCalledTimes(1);
+ });
+
+ it.each(['cindy-local-ollama', 'ollama', 'cindy-local-lmstudio'])('keeps %s editable at 1K even when the catalog advertises a large window', (id) => {
+ render(drawer(model, model.defaultEffort, model.efforts, { ...provider, id, source: 'user' }));
+ const input = screen.getByRole('textbox');
+ fireEvent.change(input, { target: { value: '4' } });
+ fireEvent.blur(input);
+ expect(mocks.setLimit).toHaveBeenLastCalledWith(4_000);
+ fireEvent.change(input, { target: { value: '1' } });
+ fireEvent.blur(input);
+ expect(mocks.setLimit).toHaveBeenLastCalledWith(1_000);
+ });
+
+ it.each([2_048, 4_096, 8_192, 32_768])('keeps a small model with %s native tokens editable below 100K', (window) => {
+ draw({ ...model, contextWindow: window, contextWindowMax: window });
+ const input = screen.getByRole('textbox');
+ const floor = Math.floor(window / 1000);
+ fireEvent.change(input, { target: { value: String(floor - 1) } });
+ fireEvent.blur(input);
+ expect(mocks.setLimit).not.toHaveBeenCalled();
+ fireEvent.change(input, { target: { value: String(floor) } });
+ fireEvent.blur(input);
+ expect(mocks.setLimit).toHaveBeenCalledWith(floor * 1000);
+ });
+
+
it('keeps useful identity fields without exposing internal defaults, normal lifecycle or raw descriptions', () => {
draw({ ...model, status: 'active', defaultEnabled: false, description: 'GPT for coding tasks' });
expect(screen.queryByText('active')).toBeNull();
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
index bc3e841fba..4185d2a42a 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
@@ -5958,7 +5958,7 @@ function ContextCapacityRing({
? 'var(--warning-fg)'
: 'var(--msg-tool-card-chevron)';
- const usedTokens = Math.min(contextTokens, contextWindow || Infinity);
+ const usedTokens = Math.max(0, contextTokens);
const tooltipText =
contextWindow > 0
? `Context — ${formatTokenCount(usedTokens)} / ${formatTokenCount(contextWindow)} (${pct}%)`
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 9679acc5e0..51abd313c5 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -1922,7 +1922,7 @@
"close": "Close",
"maxOutput": "Maximum output",
"catalogCapabilities": "Capabilities declared in the catalog",
- "contextInvalid": "Enter a whole number from 1 to 100,000 K.",
+ "contextInvalid": "Enter a whole number from {{min}} to 100,000 K.",
"contextWriteFailed": "Not saved. Please retry.",
"contextMixed": "Existing harness settings differ. Editing or resetting applies to all harnesses.",
"inputModalities": "Input types",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index ddf680d823..acb6edd0a4 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -1921,7 +1921,7 @@
"close": "閉じる",
"maxOutput": "最大出力",
"catalogCapabilities": "カタログに記載された機能",
- "contextInvalid": "1~100,000 K の整数を入力してください。",
+ "contextInvalid": "{{min}}~100,000 K の整数を入力してください。",
"contextWriteFailed": "保存できませんでした。再試行してください。",
"contextMixed": "実行環境ごとに設定が異なります。変更やリセットはすべてに適用されます。",
"inputModalities": "入力形式",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 775356d846..4a3de12c90 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -1921,7 +1921,7 @@
"close": "닫기",
"maxOutput": "최대 출력",
"catalogCapabilities": "카탈로그에 명시된 기능",
- "contextInvalid": "1–100,000 K 범위의 정수를 입력하세요.",
+ "contextInvalid": "{{min}}–100,000 K 범위의 정수를 입력하세요.",
"contextWriteFailed": "저장되지 않았습니다. 다시 시도하세요.",
"contextMixed": "실행 환경별 설정이 다릅니다. 변경하거나 초기화하면 모두에 적용됩니다.",
"inputModalities": "입력 형식",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index eff097a001..24deac05b8 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -1921,7 +1921,7 @@
"close": "关闭",
"maxOutput": "最大输出",
"catalogCapabilities": "目录声明的能力",
- "contextInvalid": "请输入 1–100,000 K 的整数。",
+ "contextInvalid": "请输入 {{min}}–100,000 K 的整数。",
"contextWriteFailed": "未保存,请重试。",
"contextMixed": "已有引擎配置不同;修改或恢复默认将应用到全部引擎。",
"inputModalities": "输入类型",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 1193933274..01b899d1cb 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -1921,7 +1921,7 @@
"close": "關閉",
"maxOutput": "最大輸出",
"catalogCapabilities": "目錄宣告的能力",
- "contextInvalid": "請輸入 1–100,000 K 的整數。",
+ "contextInvalid": "請輸入 {{min}}–100,000 K 的整數。",
"contextWriteFailed": "未儲存,請重試。",
"contextMixed": "現有引擎設定不同;修改或恢復預設將套用至所有引擎。",
"inputModalities": "輸入類型",
diff --git a/apps/desktop/src/renderer/lib/contextWindow.ts b/apps/desktop/src/renderer/lib/contextWindow.ts
index 084750a978..809b966af9 100644
--- a/apps/desktop/src/renderer/lib/contextWindow.ts
+++ b/apps/desktop/src/renderer/lib/contextWindow.ts
@@ -11,13 +11,7 @@ interface ResolveDisplayContextWindowOptions {
runtimeWindowAuthoritative?: boolean;
}
-/**
- * Resolve the context window shown in the renderer.
- *
- * SDK/modelUsage values are normally runtime ground truth, but 200K is also
- * Claude Code's unknown-model default and can remain in session state after a
- * model switch. Maker capabilities are more accurate for provider-routed models.
- */
+/** Runtime snapshots already contain the applied working budget. Catalogs only fill missing data. */
export function resolveDisplayContextWindow({
sdkContextWindow,
modelContextWindow,
@@ -31,23 +25,11 @@ export function resolveDisplayContextWindow({
return Number.isFinite(nativeContextWindow) && (nativeContextWindow ?? 0) > 0
? Math.floor(nativeContextWindow!) : 0;
}
- // Restored snapshots and SDK values share this slot. Only route-verified
- // metadata may supersede it, matching the host's runtime normalization.
- if (Number.isFinite(verifiedContextWindow) && (verifiedContextWindow ?? 0) > 0) {
- return Math.floor(verifiedContextWindow!);
+ if (Number.isFinite(sdkContextWindow) && sdkContextWindow > 0) {
+ return Math.floor(sdkContextWindow);
}
- const configured =
- Number.isFinite(modelContextWindow) && (modelContextWindow ?? 0) > 0
- ? Math.floor(modelContextWindow!)
- : undefined;
- const sdk =
- Number.isFinite(sdkContextWindow) && sdkContextWindow > 0
- ? Math.floor(sdkContextWindow)
- : undefined;
-
- if (configured && (!sdk || (sdk <= DEFAULT_CONTEXT_WINDOW && configured > sdk))) {
- return configured;
+ for (const fallback of [verifiedContextWindow, modelContextWindow]) {
+ if (Number.isFinite(fallback) && (fallback ?? 0) > 0) return Math.floor(fallback!);
}
-
- return sdk ?? configured ?? DEFAULT_CONTEXT_WINDOW;
+ return DEFAULT_CONTEXT_WINDOW;
}
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 0a66b888eb..b3ecdc88f6 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -675,6 +675,8 @@ export interface AgentStatus {
contextTokens: number;
/** Context window size from SDK modelUsage (0 = not yet known). */
contextWindow: number;
+ /** Model-picker metadata is replaceable until a runtime snapshot arrives. */
+ contextWindowFromRuntime?: boolean;
isRunning: boolean;
startedAt: number | null;
/** Turn-cumulative output tokens for live TPS. */
@@ -6753,6 +6755,7 @@ function applyBackgroundStatus(
: rawStatus;
let contextTokens = state.agentStatus.contextTokens;
let contextWindow = state.agentStatus.contextWindow;
+ let contextWindowFromRuntime = state.agentStatus.contextWindowFromRuntime;
if (
typeof data.contextWindow === 'number' &&
data.contextWindow > 0 &&
@@ -6761,6 +6764,7 @@ function applyBackgroundStatus(
) {
contextTokens = data.contextTokens;
contextWindow = data.contextWindow;
+ contextWindowFromRuntime = true;
}
return {
...state,
@@ -6769,6 +6773,7 @@ function applyBackgroundStatus(
status,
contextTokens,
contextWindow,
+ contextWindowFromRuntime,
},
};
}
@@ -6885,6 +6890,7 @@ function handleStatusUpdate(
costUsd: cu,
contextTokens: ct,
contextWindow: cw,
+ contextWindowFromRuntime: hasContextSnapshot || state.agentStatus.contextWindowFromRuntime,
isRunning: update.isRunning,
startedAt,
...mergeLiveGenerationStatus(isTurnStart, update, state.agentStatus),
@@ -10992,6 +10998,7 @@ function ensureInitialMessages(sessionId: string): void {
costUsd: session.totalCostUsd ?? s.agentStatus.costUsd,
contextTokens: session.contextTokens || s.agentStatus.contextTokens,
contextWindow: session.contextWindow || s.agentStatus.contextWindow,
+ // Read projection can supply catalog metadata; only status events prove runtime origin.
};
}
return Object.keys(updates).length > 0 ? { ...s, ...updates } : s;
@@ -16222,8 +16229,10 @@ function setContextWindow(sessionId: string, contextWindow: number | undefined):
return;
const nextContextWindow = Math.floor(contextWindow);
setState(sessionId, (s) => {
- // Model-selection metadata must not overwrite Codex's native usage snapshot.
- if (s.agentKind === 'codex') return s;
+ // Model-selection metadata cannot relabel usage from an applied runtime budget.
+ // Keep Codex unknown until its native total is read, even before its first turn.
+ if (s.agentKind === 'codex' || s.agentStatus.contextWindowFromRuntime ||
+ s.agentStatus.contextTokens > 0) return s;
if (s.agentStatus.contextWindow === nextContextWindow) return s;
return {
...s,
diff --git a/apps/desktop/src/shared/__tests__/sessionContextWindow.test.ts b/apps/desktop/src/shared/__tests__/sessionContextWindow.test.ts
index ed242da11d..06b51375ea 100644
--- a/apps/desktop/src/shared/__tests__/sessionContextWindow.test.ts
+++ b/apps/desktop/src/shared/__tests__/sessionContextWindow.test.ts
@@ -71,19 +71,27 @@ describe('session context read projection', () => {
expect(resolveVerifiedContextWindow(routes, 'codex', 'xd', model.id, 1_000_000)).toBe(272_000);
});
- it.each(['cc', 'claude-code'])(
- 'corrects %s history without mutating its stored snapshot',
+ it.each(['cc', 'claude-code', 'pi', 'codex'])(
+ 'preserves the applied %s history budget when catalog or settings change',
(agentKind) => {
- const saved = { ...session, agentKind };
- const result = projectSessionContextWindow(saved, (row) =>
- resolveSessionContextWindow(catalog, row),
- );
- expect(result).toEqual({ ...saved, contextWindow: 272_000 });
- expect(saved.contextWindow).toBe(1_050_000);
- expect(Math.round((result.contextTokens / result.contextWindow) * 100)).toBe(52);
+ for (const contextWindow of [1_000, 32_000, 500_000, 1_050_000]) {
+ const saved = { ...session, agentKind, contextWindow, contextWindowRuntime: contextWindow };
+ expect(projectSessionContextWindow(saved, () => 272_000)).toBe(saved);
+ }
+ const unknown = { ...session, agentKind, contextWindow: 0 };
+ expect(projectSessionContextWindow(unknown, () => 32_000))
+ .toEqual({ ...unknown, contextWindow: 32_000 });
},
);
+ it.each([undefined, null, 500_000])('corrects unproven legacy windows with runtime marker %s', (contextWindowRuntime) => {
+ const legacy = { ...session, contextWindowRuntime };
+ expect(projectSessionContextWindow(legacy, (row) => resolveSessionContextWindow(catalog, row)))
+ .toEqual({ ...legacy, contextWindow: 272_000 });
+ expect(legacy.contextWindow).toBe(1_050_000);
+ expect(projectSessionContextWindow(legacy, () => null)).toBe(legacy);
+ });
+
it('uses the actual provider, preserving explicit long-window overrides', () => {
const routes = {
providers: [provider('openai'), provider('custom', { ...model, contextWindow: 872_000 })],
diff --git a/apps/desktop/src/shared/sessionContextWindow.ts b/apps/desktop/src/shared/sessionContextWindow.ts
index bdd84610fe..1fce5c22d6 100644
--- a/apps/desktop/src/shared/sessionContextWindow.ts
+++ b/apps/desktop/src/shared/sessionContextWindow.ts
@@ -56,10 +56,12 @@ export function resolveSessionContextWindow(
);
}
-/** Read-only projection: retain token counts and storage, refresh only the denominator. */
+/** Preserve proven runtime budgets; legacy catalog snapshots retain read-time correction. */
export function projectSessionContextWindow<
- T extends ContextWindowSession & { contextWindow: number },
+ T extends ContextWindowSession & { contextWindow: number; contextWindowRuntime?: number | null },
>(session: T, resolve?: (session: ContextWindowSession) => number | null): T {
+ if (Number.isFinite(session.contextWindow) && session.contextWindow > 0 &&
+ session.contextWindowRuntime === session.contextWindow) return session;
const window = resolve?.(session);
return window && Number.isFinite(window) && window > 0 && window !== session.contextWindow
? { ...session, contextWindow: window }
diff --git a/docs/dev-rules/model-catalog-runtime.md b/docs/dev-rules/model-catalog-runtime.md
index 92b2a141eb..a54ef06919 100644
--- a/docs/dev-rules/model-catalog-runtime.md
+++ b/docs/dev-rules/model-catalog-runtime.md
@@ -113,8 +113,21 @@ Registry 的全部模型及其 routes,防止只翻译当前默认启用的几
不包含这项百分比调整,不能据此断言小预算无效,需验证真实 `compact_boundary`。
- 预算控制自动整理的触发时机,不代表每个请求(系统提示、工具定义、最新消息和输出)
都能严格压到该 token 数以内。原生引擎的最少历史组数和保留空间仍适用。
-- Pi 继承原生目录时通过 `modelOverrides.contextWindow` 应用工作窗口,保留原生协议、
- OAuth 和兼容参数;生成的压缩预留空间必须使用同一工作窗口。
+- Pi 的模型窗口同时用于请求输出长度裁剪,不能把 1K 等小预算直接写成模型容量。
+ 保留目录容量(显式较大预算可提高运行窗口)及原生协议、OAuth、兼容参数,通过
+ `compaction.reserveTokens = capacity - budget * pct / 100` 设置原生压缩阈值。
+ 用量快照与圆环报告已应用的工作预算;设置变更等待原生配置重载后再更新。
+- Claude/Pi 已校正的运行时预算和已确认来源的历史用量快照不得再被目录值覆盖。
+ 持久化时原子记录 `contextWindowRuntime`,只有与 `contextWindow` 相等的正数才证明
+ 运行时来源;旧记录缺标记、或被旧写入路径改成不同窗口时仍走既有读取校正。
+ 该标记仅用于 Desktop 数据库投影,不进入跨端返回值;Codex/Pi 原生窗口仍不借目录猜测。
+ 首轮前的模型选择元数据可以连续更新,收到实际运行快照后才冻结其分母。
+ 圆环最多填满 100%,但提示中的已用 token 不截断,须保留实际超预算用量。
+- 模型高级设置的新编辑值默认最低 100K;若可用引擎的模型默认窗口不足 100K,取其中
+ 最小窗口的整数 K(最低 1K)。已识别的 Ollama / 本地运行时保持原有 1K 编辑下限,
+ 不从其目录最大容量推断实际加载窗口,不修改 Ollama 加载参数。此为编辑防误设,
+ 不是模型容量声明;已有低值和精确值在未编辑时保持原样,恢复默认仍取模型默认值。
+ 底层继续兼容旧的小预算。Pi `/context` 的分母与百分比统一按已应用预算报告。
- 原生回归进入显式 integration tier,使用隔离目录与本地假上游,不能依赖开发者凭证。
### 本地模型目录
diff --git a/docs/dev-rules/pi-harness.md b/docs/dev-rules/pi-harness.md
index cbcb43973d..260c748b4c 100644
--- a/docs/dev-rules/pi-harness.md
+++ b/docs/dev-rules/pi-harness.md
@@ -66,7 +66,9 @@ Cindy 显式设置:models.json、`settings.json` 的 `transport:sse` 与 `retry.
Cindy 消费 compaction 事件做 UI、usage、digest 投影,并只在本机原生自动压缩确定性失败后锁存
下一次发送前换窗。设置页的 Pi 百分比默认 90%(已有显式 override 保留),在每次启动或恢复
Pi 任务时冻结,并写入该任务 `settings.json` 的 `compaction.reserveTokens`
-(`window * (1 - pct/100)`);切模只按这份快照重算,不回读最新全局值。
+(`capacity - budget * pct/100`);切模只按这份百分比快照重算,不回读最新全局值。
+模型容量用于 Pi 原生请求长度裁剪,不能随小预算缩到 1K;工作预算只调整原生压缩阈值,
+并作为已应用预算进入 Cindy 的用量快照。
大窗切小窗先由 Desktop 的统一目标窗口事务按目标窗口 90% 固定压力线评估(独立于 Pi
日常自动压缩百分比),命中时换干净原生窗口;未命中时 Pi 重写 settings 后调用
`switch_session`,必须重新 `set_model` 并用 `get_state` 校验
@@ -84,7 +86,8 @@ SSH 不套用本机限核值。沿用现有默认值与 override 存储,不新
放任 pi 默认(未写 settings.json):`httpIdleTimeoutMs=300000`、`websocketConnectTimeoutMs`、
`compaction.keepRecentTokens`、`defaultProjectTrust`。Cindy 会在每次 startSession 覆写
`transport`、`retry.maxRetries=6`(provider 级保持 0)与 `compaction.reserveTokens`;
-未配置 Pi 百分比时不写 `reserveTokens`,沿用 Pi 默认 16384。
+未配置 Pi 百分比且未缩小工作预算时不写 `reserveTokens`,沿用 Pi 默认 16384;
+显式小预算仍以默认 90% 计算触发阈值。
Skill 停用适配同时保存物理身份与管理页已扫描的词法发现入口;启动前只采用仍指向该
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/rewind-runtime-settings.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/rewind-runtime-settings.test.ts
index 9ede04f6c6..37835511b4 100644
--- a/packages/maker-core/src/agents/claude-code/__tests__/rewind-runtime-settings.test.ts
+++ b/packages/maker-core/src/agents/claude-code/__tests__/rewind-runtime-settings.test.ts
@@ -271,6 +271,23 @@ afterEach(async () => {
});
describe('ClaudeCodeAgent runtime settings during rewind window', () => {
+ it('does not relabel an in-flight result with a newly saved budget', async () => {
+ let budget = 1_000;
+ const { handle, firstQuery } = await startRewindableSession({ resolveModelContextLimit: () => budget });
+ try {
+ budget = 32_000;
+ firstQuery.stream.emit({
+ type: 'result', subtype: 'success', stop_reason: 'end_turn',
+ total_cost_usd: 0,
+ usage: { input_tokens: 6_000, output_tokens: 10 },
+ modelUsage: { 'claude-opus-4-6': { contextWindow: 1_000_000 } },
+ });
+ await vi.waitFor(() => expect(handle.getUsageSnapshot().contextTokens).toBeGreaterThan(0));
+ expect(handle.getUsageSnapshot().contextWindow).toBe(1_000);
+ expect(await handle.requiresModelSwitchRebuild?.('claude-opus-4-6')).toBe(true);
+ } finally { await handle.close(); }
+ });
+
it('requires a history-preserving rebuild when the active route budget changes', async () => {
let budget: number | null = 80_000;
const { handle } = await startRewindableSession({ autoCompactThresholdPct: 90, resolveModelContextLimit: () => budget });
diff --git a/packages/maker-core/src/agents/claude-code/index.ts b/packages/maker-core/src/agents/claude-code/index.ts
index c8b84fd8cd..162891ab0d 100644
--- a/packages/maker-core/src/agents/claude-code/index.ts
+++ b/packages/maker-core/src/agents/claude-code/index.ts
@@ -2642,9 +2642,10 @@ export class ClaudeCodeAgent extends BaseAgent {
// ── Usage tracker (Stage 2 B') ──────────────────────────────────────────
// 单 session 共享的 mutable usage state. translator 通过 ctx 注入访问.
// handle.getUsageSnapshot 也读它, 形成"SDK 原始 usage → tracker → status event / handle snapshot"
- // 单一可信源. 窗口跟白名单同一份实时目录,不冻启动快照。
+ // 单一可信源。预算跟随已应用的进程配置;设置变更等待重建后才反映到用量。
+ let appliedContextWindow = resolveModelContextWindow(mutableModel);
const usageTracker = new UsageTracker();
- usageTracker.setContextWindow(resolveModelContextWindow(mutableModel) ?? 0);
+ usageTracker.setContextWindow(appliedContextWindow ?? 0);
// ── 跨 turn 共享状态 ───────────────────────────────────────────────────
let configuredResumeSessionId: string | undefined = opts.resumeSessionId;
@@ -3066,6 +3067,7 @@ export class ClaudeCodeAgent extends BaseAgent {
}): Promise<Query> => {
const currentSdkModel = sdkModelFor(mutableModel);
const workingWindow = resolveModelContextWindow(mutableModel);
+ appliedContextWindow = workingWindow;
applyClaudeContextWindow(env, workingWindow, this.deps.runtimeConfig.autoCompactThresholdPct);
if (remoteEnv) applyClaudeContextWindow(remoteEnv, workingWindow, this.deps.runtimeConfig.autoCompactThresholdPct);
const currentSdkEffort = getSdkEffortForModel(mutableModel, mutableEffort);
@@ -4918,7 +4920,7 @@ export class ClaudeCodeAgent extends BaseAgent {
log,
getModel: () => mutableModel,
getProviderId: () => mutableProviderId,
- getModelContextWindow: () => resolveModelContextWindow(mutableModel),
+ getModelContextWindow: () => appliedContextWindow,
getEffort: () => mutableEffort,
getPermissionMode: () => mutablePermissionMode,
getFastMode: () => mutableFastMode,
@@ -6716,6 +6718,7 @@ export class ClaudeCodeAgent extends BaseAgent {
});
}
const newContextWindow = resolveModelContextWindow(mutableModel);
+ appliedContextWindow = newContextWindow;
if (newContextWindow === undefined) {
// setContextWindow(0) 是 no-op —— tracker 会静默沿用旧模型窗口直到下一个
// result 的 modelUsage 修正。UI 环 / auto-compact 期间按旧窗口算(偏乐观),
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts
index e8a964568a..96ce663c16 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts
@@ -443,7 +443,7 @@ describe.skipIf(!piAvailable)('PiAgent integration (real pi binary + fake gatewa
let handle: AgentSessionHandle | undefined;
let nativeId: string | undefined;
try {
- for (const next of [80_000, 140_000, 60_000, null]) {
+ for (const next of [80_000, 1_000, 32_000, 1_000, 140_000, 60_000, null]) {
limit = next;
handle = await agent.startSession({
sessionId: 'context-window-resume', workingDir, model: 'pi-test-model',
@@ -463,6 +463,14 @@ describe.skipIf(!piAvailable)('PiAgent integration (real pi binary + fake gatewa
await handle.send({ type: 'user', content: 'remember CONTEXT_HISTORY_CANARY' });
await done;
expect(events.some((event) => event.type === 'text')).toBe(true);
+ expect(events.filter((event) => event.type === 'error')).toEqual([]);
+ // This is the real Pi request builder: a 1K compaction budget used to
+ // clamp max_tokens to 1, even for the very first short prompt.
+ for (const request of seenRequests.slice(before)) {
+ const body = JSON.parse(request.body);
+ expect(body.max_tokens).toBeGreaterThan(1);
+ }
+ expect(handle.getUsageSnapshot().contextWindow).toBe(next ?? 200_000);
expect(seenRequests.slice(before).some((request) => request.body.includes('CONTEXT_HISTORY_CANARY'))).toBe(true);
if (next !== 80_000) {
const body = JSON.parse(seenRequests[before]!.body);
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-native-auto-compact.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-native-auto-compact.test.ts
index 8ee2259774..d180aefec8 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-native-auto-compact.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-native-auto-compact.test.ts
@@ -17,6 +17,7 @@ const knobs = vi.hoisted(() => ({
runtimeProvider: "cindy",
runtimeModel: "m",
runtimeContextWindow: 200_000,
+ contextTokens: null as number | null,
targetRuntimeContextWindow: 100_000,
setModelReportsContextWindow: true,
verifiedContextWindows: [] as number[],
@@ -58,6 +59,11 @@ vi.mock("../rpc-client.js", () => ({
error?: string;
}> {
knobs.rpcCalls.push(cmd);
+ if (cmd.type === "get_session_stats" && knobs.contextTokens !== null) {
+ return { success: true, data: { contextUsage: {
+ tokens: knobs.contextTokens, contextWindow: knobs.runtimeContextWindow,
+ } } };
+ }
if (cmd.type === "get_state") {
return {
success: true,
@@ -129,6 +135,10 @@ const noopLogger: Logger = {
};
describe("Pi native settings", () => {
+ it.each([1_000, 32_000, 200_000])('uses budget %s for compaction without shrinking request capacity', (budget) => {
+ const settings = JSON.parse(buildPiSettingsJsonContent(200_000, 90, [], budget));
+ expect(200_000 - settings.compaction.reserveTokens).toBe(budget * 0.9);
+ });
it("maps the configured percentage to Pi reserve tokens", () => {
const retry = {
enabled: true,
@@ -168,6 +178,7 @@ describe("PiAgent native auto-compaction ownership", () => {
knobs.runtimeProvider = "cindy";
knobs.runtimeModel = "m";
knobs.runtimeContextWindow = 200_000;
+ knobs.contextTokens = null;
knobs.targetRuntimeContextWindow = 100_000;
knobs.setModelReportsContextWindow = true;
knobs.verifiedContextWindows = [];
@@ -183,6 +194,27 @@ describe("PiAgent native auto-compaction ownership", () => {
rmSync(cwd, { recursive: true, force: true });
});
+ it('keeps the applied small budget until native settings are reloaded', async () => {
+ let budget: number | null = 1_000;
+ const deps = buildDeps();
+ deps.resolveModelContextLimit = () => budget;
+ const handle = await new PiAgent(deps).startSession({ sessionId: 'small-budget', workingDir: cwd, model: 'm', providerId: 'xd' });
+ try {
+ expect(handle.getUsageSnapshot().contextWindow).toBe(1_000);
+ expect((await handle.getContextUsage!()).maxTokens).toBe(1_000);
+ knobs.contextTokens = 6_000;
+ expect(await handle.getContextUsage!()).toMatchObject({
+ totalTokens: 6_000, maxTokens: 1_000, rawMaxTokens: 1_000, percentage: 100,
+ });
+ expect(await handle.requiresModelSwitchRebuild?.('m', { providerId: 'xd' })).toBe(false);
+ budget = 32_000;
+ expect(handle.getUsageSnapshot().contextWindow).toBe(1_000);
+ expect(await handle.requiresModelSwitchRebuild?.('m', { providerId: 'xd' })).toBe(true);
+ budget = null;
+ expect(await handle.requiresModelSwitchRebuild?.('m', { providerId: 'xd' })).toBe(true);
+ } finally { await handle.close(); }
+ });
+
it.each([null, 'xd', 'cindy'] as const)('refreshes gateway aliases from a %s source without changing routes', async (providerId) => {
let window = 200_000;
const deps = buildDeps();
diff --git a/packages/maker-core/src/agents/pi/index.ts b/packages/maker-core/src/agents/pi/index.ts
index b91941eecb..aa02a02b37 100644
--- a/packages/maker-core/src/agents/pi/index.ts
+++ b/packages/maker-core/src/agents/pi/index.ts
@@ -1649,11 +1649,17 @@ export function buildPiSettingsJsonContent(
contextWindow: number,
piCompactionPct?: number,
packages: readonly PiNativePackageEntry[] = [],
+ workingContextWindow?: number,
): string {
const effectiveContextWindow = contextWindow > 0 ? contextWindow : 128_000;
- const reserveTokens = piCompactionPct === undefined
+ // Pi also uses model.contextWindow to clamp request max_tokens (including a
+ // 4096-token safety margin). A small compaction budget must never shrink that
+ // request capacity. Express the budget through native reserveTokens instead.
+ const budget = workingContextWindow && workingContextWindow > 0
+ ? Math.min(workingContextWindow, effectiveContextWindow) : effectiveContextWindow;
+ const reserveTokens = piCompactionPct === undefined && budget === effectiveContextWindow
? undefined
- : Math.max(1, Math.ceil(effectiveContextWindow * (1 - piCompactionPct / 100)));
+ : Math.max(1, Math.ceil(effectiveContextWindow - budget * ((piCompactionPct ?? 90) / 100)));
return JSON.stringify({
transport: 'sse',
retry: {
@@ -2032,11 +2038,13 @@ export class PiAgent extends BaseAgent {
contextWindow?: number,
piCompactionPct?: number,
packages: readonly PiNativePackageEntry[] = [],
+ workingContextWindow?: number,
): string {
return buildPiSettingsJsonContent(
contextWindow && contextWindow > 0 ? contextWindow : 128_000,
piCompactionPct,
packages,
+ workingContextWindow,
);
}
@@ -2056,6 +2064,7 @@ export class PiAgent extends BaseAgent {
opts: {
fileOps?: PiRemoteFileOps;
contextWindow?: number;
+ workingContextWindow?: number;
piCompactionPct?: number;
packages?: readonly PiNativePackageEntry[];
disabledSkills?: DisabledSkillLaunchSnapshot;
@@ -2065,6 +2074,7 @@ export class PiAgent extends BaseAgent {
opts.contextWindow,
opts.piCompactionPct,
opts.packages,
+ opts.workingContextWindow,
);
if (opts.fileOps) return built;
const readOrNull = async (file: string): Promise<string | null> => {
@@ -2096,6 +2106,7 @@ export class PiAgent extends BaseAgent {
opts: {
fileOps?: PiRemoteFileOps;
contextWindow?: number;
+ workingContextWindow?: number;
piCompactionPct?: number;
packages?: readonly PiNativePackageEntry[];
disabledSkills?: DisabledSkillLaunchSnapshot;
@@ -2132,6 +2143,7 @@ export class PiAgent extends BaseAgent {
offlineValidationOnly?: boolean;
/** Current model context window used to translate the Pi percentage setting. */
contextWindow?: number;
+ workingContextWindow?: number;
/** Session-frozen Pi auto-compact percentage. Do not re-read the live getter. */
piCompactionPct?: number;
/** Host-installed roots/specs for Pi's own package discovery. */
@@ -2234,8 +2246,9 @@ export class PiAgent extends BaseAgent {
: {}),
reasoning: m.efforts.length > 0,
input: supportsImageInput ? ['text', 'image'] : ['text'],
- // Model Access v3 requires this value; never replace the server limit with a client guess.
- contextWindow: this.deps.resolveModelContextLimit?.(gatewayProviderId ?? 'xd', m.id) ?? m.contextWindow,
+ // Keep request capacity at least as large as the catalog default. A
+ // smaller working budget is expressed by native compaction settings.
+ contextWindow: Math.max(m.contextWindow, this.deps.resolveModelContextLimit?.(gatewayProviderId ?? 'xd', m.id) ?? 0),
maxTokens: m.maxOutputTokens && m.maxOutputTokens > 0 ? m.maxOutputTokens : piMaxTokensFallback(m.contextWindow),
// 计费单位与目录一致($/1M tokens);pi 按此自行计价,usage 事件的 cost 才有真值。
cost: {
@@ -2275,8 +2288,10 @@ export class PiAgent extends BaseAgent {
const nativeModels = (
np.inheritModels ? np.models.filter((model) => model.api !== undefined || model.catalogAddition === true) : np.models
).map((m) => {
- const contextWindow = this.deps.resolveModelContextLimit?.(np.sourceProviderId ?? np.id, m.id)
- ?? (m.contextWindow && m.contextWindow > 0 ? m.contextWindow : 128_000);
+ const contextWindow = Math.max(
+ m.contextWindow && m.contextWindow > 0 ? m.contextWindow : 128_000,
+ this.deps.resolveModelContextLimit?.(np.sourceProviderId ?? np.id, m.id) ?? 0,
+ );
return {
id: m.wireId ?? m.id,
name: m.name ?? m.id,
@@ -2302,12 +2317,12 @@ export class PiAgent extends BaseAgent {
...(np.api ? { api: np.api } : {}),
// keyless(本机 Ollama 等)也要给 dummy key,否则 pi /model 不显示该模型。
apiKey: np.apiKeyEnvVar ? `$${np.apiKeyEnvVar}` : 'pi-native-keyless',
- // Preserve native protocol/compatibility metadata while applying Cindy's
- // route default or explicit working window to inherited models as well.
+ // Preserve native protocol/compatibility metadata. Larger supported
+ // budgets may raise capacity; smaller budgets only change compaction.
...(np.inheritModels ? {
modelOverrides: Object.fromEntries(np.models.flatMap((model) => {
- const window = this.deps.resolveModelContextLimit?.(np.sourceProviderId ?? np.id, model.id)
- ?? model.contextWindow;
+ const window = Math.max(model.contextWindow ?? 0,
+ this.deps.resolveModelContextLimit?.(np.sourceProviderId ?? np.id, model.id) ?? 0);
return typeof window === 'number' && Number.isSafeInteger(window) && window > 0
? [[model.wireId ?? model.id, { contextWindow: window }]] : [];
})),
@@ -2598,9 +2613,13 @@ export class PiAgent extends BaseAgent {
});
}
}
- const startupContextWindow =
- this.deps.resolveModelContextLimit?.(authProviderId, opts.model) ??
- selectedRuntimeModel?.contextWindow ?? publicRuntimeModel?.contextWindow ?? 128_000;
+ const startupWorkingContextWindow = this.deps.resolveModelContextLimit?.(authProviderId, opts.model) ?? undefined;
+ const nativeModel = nativeProviders.find((provider) => provider.id === initialProvider)?.models
+ .find((model) => (model.wireId ?? model.id) === initialWireModel);
+ const startupContextWindow = Math.max(
+ nativeModel?.contextWindow ?? selectedRuntimeModel?.contextWindow ?? publicRuntimeModel?.contextWindow ?? 128_000,
+ startupWorkingContextWindow ?? 0,
+ );
// 普通远端会话直连网关(remoteEndpoint),不生成本地 proxy token。只有显式声明
// hostProxyForward 的 provider(当前为 xAI)仍通过 Desktop compat proxy:
@@ -2991,6 +3010,7 @@ export class PiAgent extends BaseAgent {
fileOps,
preview: true,
contextWindow: startupContextWindow,
+ workingContextWindow: startupWorkingContextWindow,
piCompactionPct: sessionPiAutoCompactPct,
});
configHome = joinRemotePosixPath(
@@ -3004,7 +3024,11 @@ export class PiAgent extends BaseAgent {
nativeProviders,
retainedRuntimeModel,
authProviderId,
- { remote, fileOps, contextWindow: startupContextWindow, piCompactionPct: sessionPiAutoCompactPct },
+ {
+ remote, fileOps, contextWindow: startupContextWindow,
+ workingContextWindow: startupWorkingContextWindow,
+ piCompactionPct: sessionPiAutoCompactPct,
+ },
);
const explicitlyRequestedGateway = isExplicitPiGatewayProviderId(opts.providerId);
if (
@@ -3576,6 +3600,7 @@ export class PiAgent extends BaseAgent {
nativePackagePaths = await this.deps.resolvePiNativePackagePaths();
await this.writePiRuntimeSettings(configHome, {
contextWindow: startupContextWindow,
+ workingContextWindow: startupWorkingContextWindow,
piCompactionPct: sessionPiAutoCompactPct,
packages: nativePackagePaths,
});
@@ -3663,6 +3688,7 @@ export class PiAgent extends BaseAgent {
const queue: AsyncQueue<AgentEvent> = createAsyncQueue<AgentEvent>();
const ctx: PiTranslateContext = createPiTranslateContext(this.deps.logger);
ctx.getPriceVariant = opts.getPriceVariant;
+ ctx.workingContextWindow = startupWorkingContextWindow;
const contextModeRoot = findContextModePackageRoot([
...nativePackageRoots,
...managedPackageResources.packageRoots,
@@ -5817,6 +5843,7 @@ export class PiAgent extends BaseAgent {
remote,
fileOps,
contextWindow: ctx.contextWindow || startupContextWindow,
+ workingContextWindow: ctx.workingContextWindow,
piCompactionPct: sessionPiAutoCompactPct,
packages: nativePackagePaths,
disabledSkills: disabledSkillLaunch,
@@ -5897,6 +5924,7 @@ export class PiAgent extends BaseAgent {
remote,
fileOps,
contextWindow: ctx.contextWindow || startupContextWindow,
+ workingContextWindow: ctx.workingContextWindow,
piCompactionPct: sessionPiAutoCompactPct,
packages: nativePackagePaths,
disabledSkills: disabledSkillLaunch,
@@ -6217,6 +6245,7 @@ export class PiAgent extends BaseAgent {
?.contextWindow ??
ctx.contextWindow;
if (nextWindow > 0) ctx.contextWindow = nextWindow;
+ ctx.workingContextWindow = this.deps.resolveModelContextLimit?.(mutableProviderId, model) ?? undefined;
// Always reload and read get_state after set_model. The catalog and even the
// set_model response can disagree with the materialized runtime window; callers
// must not decide whether to destroy native context until this verification ends.
@@ -6228,6 +6257,7 @@ export class PiAgent extends BaseAgent {
await this.writePiRuntimeSettings(configHome, {
fileOps,
contextWindow: nextWindow,
+ workingContextWindow: ctx.workingContextWindow,
piCompactionPct: sessionPiAutoCompactPct,
packages: nativePackagePaths,
disabledSkills: disabledSkillLaunch,
@@ -6284,6 +6314,7 @@ export class PiAgent extends BaseAgent {
await this.writePiRuntimeSettings(configHome, {
fileOps,
contextWindow: verifiedWindow,
+ workingContextWindow: ctx.workingContextWindow,
piCompactionPct: sessionPiAutoCompactPct,
packages: nativePackagePaths,
disabledSkills: disabledSkillLaunch,
@@ -6903,7 +6934,7 @@ export class PiAgent extends BaseAgent {
id == null || id === 'xd' || id === PI_PROVIDER_ID ? PI_PROVIDER_ID : id;
if (model !== mutableModel || contextSource(provider) !== contextSource(mutableProviderId)) return false;
const window = deps.resolveModelContextLimit?.(provider, model);
- return typeof window === 'number' && window > 0 && window !== ctx.contextWindow;
+ return (window ?? undefined) !== ctx.workingContextWindow;
},
async setModel(model: string, setOpts?: { providerId?: string | null; effort?: Effort }): Promise<void> {
@@ -7214,7 +7245,7 @@ export class PiAgent extends BaseAgent {
tree,
messages: activePiHistoryFromTree(after.data, tree),
contextTokens,
- contextWindow,
+ contextWindow: usageSnapshotOf(ctx).contextWindow,
...(draftText ? { draftText } : {}),
};
},
@@ -7235,15 +7266,19 @@ export class PiAgent extends BaseAgent {
| undefined
)?.contextUsage;
const totalTokens = typeof contextUsage?.tokens === 'number' && contextUsage.tokens >= 0 ? contextUsage.tokens : ctx.contextTokens;
- const maxTokens =
+ const nativeCapacity =
typeof contextUsage?.contextWindow === 'number' && contextUsage.contextWindow > 0
? contextUsage.contextWindow
: ctx.contextWindow;
+ const maxTokens = ctx.workingContextWindow && ctx.workingContextWindow > 0
+ ? Math.min(ctx.workingContextWindow, nativeCapacity) : nativeCapacity;
const percentage = maxTokens > 0 ? Math.min(100, (totalTokens / maxTokens) * 100) : 0;
return {
categories: [{ name: 'Messages', tokens: totalTokens, color: '#8b8b8b' }],
totalTokens,
maxTokens,
+ // Context cards and shared summaries use rawMaxTokens as their denominator.
+ // Pi has no separate usable-window reserve within the working budget.
rawMaxTokens: maxTokens,
percentage,
gridRows: [],
diff --git a/packages/maker-core/src/agents/pi/translator.ts b/packages/maker-core/src/agents/pi/translator.ts
index 42c6aa3b1c..97a6fa91d0 100644
--- a/packages/maker-core/src/agents/pi/translator.ts
+++ b/packages/maker-core/src/agents/pi/translator.ts
@@ -97,6 +97,8 @@ export interface PiTranslateContext {
getPriceVariant?: () => 'standard' | 'priority';
/** get_state 拿到的 contextWindow(模型切换时更新)。 */
contextWindow: number;
+ /** Applied compaction budget; separate from the native request capacity. */
+ workingContextWindow?: number;
/** turn 内累计 input+output;turn 结束 reset。 */
turnTokens: number;
/** turn 内 usage 分量累计(did-turn-end / ghost 订阅上报用);agent_start reset。 */
@@ -347,7 +349,8 @@ export function usageSnapshotOf(ctx: PiTranslateContext): UsageSnapshot {
{
tokenUsage: ctx.turnTokens,
contextTokens: ctx.contextTokens,
- contextWindow: ctx.contextWindow,
+ contextWindow: ctx.workingContextWindow && ctx.workingContextWindow > 0
+ ? Math.min(ctx.workingContextWindow, ctx.contextWindow) : ctx.contextWindow,
costUsd: ctx.costUsd,
},
{