@crewx/sdk 0.9.0-rc.207 → 0.9.0-rc.209
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-sync/index.js +20 -20
- package/dist/esm/app-sync/index.js +19 -19
- package/dist/esm/index.js +245 -245
- package/dist/esm/plugins/index.js +1 -1
- package/dist/esm/repository/index.js +54 -54
- package/dist/index.browser.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +239 -239
- package/dist/migrations/0057_eager_captain_flint.sql +18 -0
- package/dist/migrations/meta/0057_snapshot.json +6971 -0
- package/dist/migrations/meta/_journal.json +7 -0
- package/dist/plugins/index.js +1 -1
- package/dist/provider/cli/meta.d.ts +12 -1
- package/dist/repository/index.js +68 -68
- package/dist/schema/sidebar-tabs.d.ts +1 -1
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ ${r.join(`
|
|
|
29
29
|
OR
|
|
30
30
|
(${t.status} IN ('deferred', 'failed') AND ${t.code} IS NOT NULL
|
|
31
31
|
AND ${t.to_revision} IS NULL)
|
|
32
|
-
)`)}));});var cd=x(()=>{g();sqliteTable("ui_definition_archive",{definition_hash:text("definition_hash").primaryKey().notNull(),definition_json:text("definition_json").notNull(),created_at:integer("created_at").notNull()},t=>({definitionHashCheck:check("ui_definition_archive_definition_hash_ck",sql`length(${t.definition_hash}) = 64 AND ${t.definition_hash} NOT GLOB '*[^0-9a-f]*'`),definitionJsonCheck:check("ui_definition_archive_definition_json_ck",sql`json_valid(${t.definition_json}) AND json_type(${t.definition_json}) = 'object'`),createdAtCheck:check("ui_definition_archive_created_at_ck",sql`${t.created_at} >= 0`)}));});var ld,pd=x(()=>{g();ld=sqliteTable("projects",{id:text("id").primaryKey().notNull(),workspace_id:text("workspace_id").notNull(),name:text("name").notNull(),outcome:text("outcome").notNull(),due_date:text("due_date"),scene:text("scene").notNull().default("planning"),stages_json:text("stages_json").notNull(),stage_index:integer("stage_index").notNull(),created_at:text("created_at").notNull(),updated_at:text("updated_at").notNull(),accepted_at:text("accepted_at"),archived_at:text("archived_at")},t=>({idCheck:check("projects_id_ck",sql`${t.id} GLOB 'prj_*'`),sceneCheck:check("projects_scene_ck",sql`${t.scene} IN ('planning', 'plan_review', 'running', 'human_wait', 'limit_wait', 'failed_stop', 'analyzing_feedback', 'replanned', 'awaiting_review', 'accepted')`),stagesJsonCheck:check("projects_stages_json_ck",sql`json_valid(${t.stages_json}) AND json_type(${t.stages_json}) = 'array'`),stageIndexCheck:check("projects_stage_index_ck",sql`${t.stage_index} >= 1`)})),sqliteTable("project_criteria",{id:text("id").primaryKey().notNull(),project_id:text("project_id").notNull().references(()=>ld.id,{onDelete:"cascade"}),position:integer("position").notNull(),statement:text("statement").notNull(),verify_status:text("verify_status").notNull().default("pending"),verified_at:text("verified_at"),evidence_json:text("evidence_json").notNull().default("[]"),created_at:text("created_at").notNull(),updated_at:text("updated_at").notNull()},t=>({idCheck:check("project_criteria_id_ck",sql`${t.id} GLOB 'pjc_*'`),verifyStatusCheck:check("project_criteria_verify_status_ck",sql`${t.verify_status} IN ('pending', 'verifying', 'passed', 'failed')`),evidenceJsonCheck:check("project_criteria_evidence_json_ck",sql`json_valid(${t.evidence_json}) AND json_type(${t.evidence_json}) = 'array'`),projectPositionUnique:uniqueIndex("project_criteria_project_position_uq").on(t.project_id,t.position)})),sqliteTable("project_events",{id:text("id").primaryKey().notNull(),project_id:text("project_id").notNull().references(()=>ld.id,{onDelete:"restrict"}),seq:integer("seq").notNull(),actor_type:text("actor_type").notNull(),actor_id:text("actor_id"),type:text("type").notNull(),title:text("title").notNull(),summary:text("summary"),payload_json:text("payload_json").notNull().default("{}"),created_at:text("created_at").notNull()},t=>({idCheck:check("project_events_id_ck",sql`${t.id} GLOB 'pje_*'`),actorTypeCheck:check("project_events_actor_type_ck",sql`${t.actor_type} IN ('user', 'project_manager', 'system')`),payloadJsonCheck:check("project_events_payload_json_ck",sql`json_valid(${t.payload_json}) AND json_type(${t.payload_json}) = 'object'`),projectSeqUnique:uniqueIndex("project_events_project_seq_uq").on(t.project_id,t.seq)}));});var gs,hs,M,ms=x(()=>{g();gs=["THREAD_STATE","THREAD_PRIORITY"],hs=["gray","blue","violet","green","amber","orange","red","pink"],M=sqliteTable("common_codes",{code_group:text("code_group").notNull(),code:text("code").notNull(),code_name:text("code_name"),color:text("color").notNull().default("gray"),sort_order:integer("sort_order").notNull(),workspace_id:text("workspace_id"),is_builtin:integer("is_builtin").notNull().default(0),is_archived:integer("is_archived").notNull().default(0),metadata:text("metadata"),created_at:text("created_at").notNull(),updated_at:text("updated_at").notNull()},t=>({pk:primaryKey({columns:[t.code_group,t.code]}),metadataCheck:check("common_codes_metadata_ck",sql`${t.metadata} IS NULL OR (json_valid(${t.metadata}) AND json_type(${t.metadata}) = 'object')`),builtinCheck:check("common_codes_builtin_ck",sql`${t.is_builtin} IN (0, 1)`),archivedCheck:check("common_codes_archived_ck",sql`${t.is_archived} IN (0, 1)`),idxCommonCodesSelection:index("idx_common_codes_group_archived_order").on(t.code_group,t.is_archived,t.sort_order)}));});var _d,fd,gd,hd,md,X,K,B,kd=x(()=>{g();Xn();_d=["thread.snapshot.imported","thread.title.changed","thread.priority.changed","thread.state.changed","thread.highlight.created","thread.highlight.updated","thread.highlight.deleted","thread.highlights.regenerated"],fd=["user","agent","system"],gd=["auto","manual"],hd=["decision","judgment","issue","result","pivot"],md=["queued","running","completed","failed"],X=sqliteTable("thread_events",{id:text("id").primaryKey().notNull(),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),seq:integer("seq").notNull(),type:text("type").notNull(),actor_type:text("actor_type").notNull(),payload_json:text("payload_json").notNull(),created_at:text("created_at").notNull(),actor_id:text("actor_id"),task_id:text("task_id"),highlight_id:text("highlight_id")},t=>({typeCheck:check("thread_events_type_ck",sql`${t.type} IN ('thread.snapshot.imported', 'thread.title.changed', 'thread.priority.changed', 'thread.state.changed', 'thread.highlight.created', 'thread.highlight.updated', 'thread.highlight.deleted', 'thread.highlights.regenerated')`),actorTypeCheck:check("thread_events_actor_type_ck",sql`${t.actor_type} IN ('user', 'agent', 'system')`),payloadJsonCheck:check("thread_events_payload_json_ck",sql`json_valid(${t.payload_json}) AND json_type(${t.payload_json}) = 'object'`),threadSeqIndex:index("idx_thread_events_thread_seq").on(t.thread_id,t.seq),threadCreatedIndex:index("idx_thread_events_thread_created").on(t.thread_id,t.created_at),threadSeqUnique:uniqueIndex("thread_events_thread_seq_uq").on(t.thread_id,t.seq)})),K=sqliteTable("thread_highlight_runs",{id:text("id").primaryKey().notNull(),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),request_id:text("request_id").notNull(),status:text("status").notNull(),detector_version:text("detector_version").notNull(),requested_at:text("requested_at").notNull(),started_at:text("started_at"),completed_at:text("completed_at"),error_code:text("error_code"),previous_auto_count:integer("previous_auto_count"),new_auto_count:integer("new_auto_count")},t=>({statusCheck:check("thread_highlight_runs_status_ck",sql`${t.status} IN ('queued', 'running', 'completed', 'failed')`),countCheck:check("thread_highlight_runs_counts_ck",sql`(${t.previous_auto_count} IS NULL OR ${t.previous_auto_count} >= 0) AND (${t.new_auto_count} IS NULL OR ${t.new_auto_count} >= 0)`),threadRequestUnique:uniqueIndex("thread_highlight_runs_thread_request_uq").on(t.thread_id,t.request_id),inProgressThreadUnique:uniqueIndex("thread_highlight_runs_in_progress_thread_uq").on(t.thread_id).where(sql`${t.status} IN ('queued', 'running')`),threadStatusRequestedIndex:index("idx_thread_highlight_runs_thread_status_requested").on(t.thread_id,t.status,t.requested_at)})),B=sqliteTable("thread_highlights",{id:text("id").primaryKey().notNull(),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),source:text("source").notNull(),kind:text("kind").notNull(),status:text("status").notNull().default("active"),text:text("text"),covers_from_task_id:text("covers_from_task_id").notNull(),covers_to_task_id:text("covers_to_task_id").notNull(),revision:integer("revision").notNull().default(0),created_at:text("created_at").notNull(),updated_at:text("updated_at").notNull(),agent_id:text("agent_id"),source_task_id:text("source_task_id"),detector_version:text("detector_version"),content_fingerprint:text("content_fingerprint"),dismissed_at:text("dismissed_at")},t=>({sourceCheck:check("thread_highlights_source_ck",sql`${t.source} IN ('auto', 'manual')`),kindCheck:check("thread_highlights_kind_ck",sql`${t.kind} IN ('decision', 'judgment', 'issue', 'result', 'pivot')`),statusCheck:check("thread_highlights_status_ck",sql`${t.status} IN ('active', 'dismissed')`),activeTextCheck:check("thread_highlights_active_text_ck",sql`${t.status} = 'dismissed' OR (${t.text} IS NOT NULL AND length(${t.text}) > 0)`),coversCheck:check("thread_highlights_covers_ck",sql`length(${t.covers_from_task_id}) > 0 AND length(${t.covers_to_task_id}) > 0`),autoKeyCheck:check("thread_highlights_auto_key_ck",sql`${t.source} = 'manual' OR (${t.source} = 'auto' AND ${t.source_task_id} IS NOT NULL AND ${t.detector_version} IS NOT NULL AND ${t.content_fingerprint} IS NOT NULL AND length(${t.source_task_id}) > 0 AND length(${t.detector_version}) > 0 AND length(${t.content_fingerprint}) > 0)`),threadStatusCreatedIndex:index("idx_thread_highlights_thread_status_created").on(t.thread_id,t.status,t.created_at),threadCoversIndex:index("idx_thread_highlights_thread_covers").on(t.thread_id,t.covers_from_task_id,t.covers_to_task_id),autoIdempotencyUnique:uniqueIndex("thread_highlights_auto_idempotency_uq").on(t.thread_id,t.source_task_id,t.detector_version,t.content_fingerprint).where(sql`${t.source} = 'auto'`)}));});var Td=x(()=>{g();sqliteTable("storage_metadata",{source_kind:text("source_kind").notNull(),source_id:text("source_id").notNull(),utc_ts:text("utc_ts"),bytes:integer("bytes").notNull()},t=>({pk:primaryKey({columns:[t.source_kind,t.source_id]}),kindTimestampBytesIndex:index("idx_storage_metadata_kind_ts_bytes").on(t.source_kind,t.utc_ts,t.bytes)})),sqliteTable("storage_metadata_state",{unit:text("unit").primaryKey().notNull(),cursor_rowid:integer("cursor_rowid").notNull().default(0),end_rowid:integer("end_rowid"),complete:integer("complete").notNull().default(0),updated_at:text("updated_at").notNull()});});var He,wd=x(()=>{g();He=sqliteTable("agent_send_history",{workspace_id:text("workspace_id").notNull(),actor_id:text("actor_id").notNull(),agent_id:text("agent_id").notNull(),last_accepted_at:text("last_accepted_at").notNull()},t=>({pk:primaryKey({columns:[t.workspace_id,t.actor_id,t.agent_id]}),recentIndex:index("idx_agent_send_history_recent").on(t.workspace_id,t.actor_id,t.last_accepted_at,t.agent_id)}));});var Sd,Id=x(()=>{g();Xn();Gr();sqliteTable("sidebar_states",{workspace_id:text("workspace_id").primaryKey().references(()=>de.id,{onDelete:"cascade"}),revision:integer("revision").notNull().default(0),rail_collapsed:integer("rail_collapsed").notNull().default(0),seeded_at:text("seeded_at").notNull()},t=>({railCollapsedCheck:check("sidebar_states_rail_collapsed_ck",sql`${t.rail_collapsed} IN (0, 1)`)})),Sd=sqliteTable("sidebar_groups",{id:text("id").primaryKey(),workspace_id:text("workspace_id").notNull().references(()=>de.id,{onDelete:"cascade"}),name:text("name").notNull(),color:text("color").notNull(),collapsed:integer("collapsed").notNull().default(0),position:integer("position").notNull()},t=>({colorCheck:check("sidebar_groups_color_ck",sql`${t.color} IN ('cyan', 'orange', 'purple', 'blue')`),collapsedCheck:check("sidebar_groups_collapsed_ck",sql`${t.collapsed} IN (0, 1)`),idxSidebarGroupsWorkspacePosition:index("idx_sidebar_groups_workspace_position").on(t.workspace_id,t.position)})),sqliteTable("sidebar_tabs",{workspace_id:text("workspace_id").notNull().references(()=>de.id,{onDelete:"cascade"}),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),group_id:text("group_id").references(()=>Sd.id,{onDelete:"set null"}),position:integer("position").notNull()},t=>({pk:primaryKey({columns:[t.workspace_id,t.thread_id]})})),sqliteTable("sidebar_closed_tabs",{id:integer("id").primaryKey({autoIncrement:true}),workspace_id:text("workspace_id").notNull().references(()=>de.id,{onDelete:"cascade"}),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),group_id:text("group_id").references(()=>Sd.id,{onDelete:"set null"}),position:integer("position").notNull(),closed_at:text("closed_at").notNull()},t=>({idxSidebarClosedTabsWorkspaceId:index("idx_sidebar_closed_tabs_workspace_id").on(t.workspace_id,t.id)})),sqliteTable("thread_reads",{workspace_id:text("workspace_id").notNull().references(()=>de.id,{onDelete:"cascade"}),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),read_through_at:text("read_through_at").notNull()},t=>({pk:primaryKey({columns:[t.workspace_id,t.thread_id]})}));});var Ad=x(()=>{g();sqliteTable("schedule_runs",{id:text("id").primaryKey(),schedule_id:text("schedule_id").notNull(),workspace_id:text("workspace_id").notNull(),mode:text("mode").notNull(),trigger:text("trigger").notNull(),occurrence_key:text("occurrence_key"),task_id:text("task_id"),app_id:text("app_id"),schedule_name:text("schedule_name"),builtin_id:text("builtin_id"),command:text("command"),high_frequency:integer("high_frequency").notNull().default(0),status:text("status").notNull(),error_code:text("error_code"),exit_code:integer("exit_code"),signal:text("signal"),started_at:text("started_at").notNull(),finished_at:text("finished_at"),duration_ms:integer("duration_ms"),pid:integer("pid"),host_pid:integer("host_pid"),output_tail:text("output_tail"),output_bytes:integer("output_bytes"),output_truncated:integer("output_truncated").notNull().default(0)},t=>({idx_schedule_runs_workspace_started:index("idx_schedule_runs_workspace_started").on(t.workspace_id,sql`${t.started_at} DESC`),idx_schedule_runs_schedule_started:index("idx_schedule_runs_schedule_started").on(t.schedule_id,sql`${t.started_at} DESC`),idx_schedule_runs_task_id:index("idx_schedule_runs_task_id").on(t.task_id),idx_schedule_runs_running:index("idx_schedule_runs_running").on(t.workspace_id,t.started_at).where(sql`${t.status} = 'running'`)}));});var Nd=x(()=>{g();sqliteTable("run_column_backfill",{name:text("name").primaryKey(),cursor:integer("cursor"),anchor_id:text("anchor_id"),completed_at:text("completed_at")});});var Od=x(()=>{g();sqliteTable("doc_sync_connect_requests",{request_id:text("request_id").primaryKey().notNull(),account_key:text("account_key").notNull(),workspace_id:text("workspace_id").notNull(),app_id:text("app_id").notNull(),ref:text("ref").notNull(),sent_hash:text("sent_hash").notNull(),created_at:integer("created_at").notNull()},t=>({requestIdCheck:check("doc_sync_connect_requests_request_id_ck",sql`length(${t.request_id}) = 36`),accountKeyCheck:check("doc_sync_connect_requests_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),workspaceIdCheck:check("doc_sync_connect_requests_workspace_id_ck",sql`length(${t.workspace_id}) BETWEEN 1 AND 256`),appIdCheck:check("doc_sync_connect_requests_app_id_ck",sql`length(${t.app_id}) BETWEEN 1 AND 128`),refCheck:check("doc_sync_connect_requests_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),sentHashCheck:check("doc_sync_connect_requests_sent_hash_ck",sql`length(${t.sent_hash}) = 71 AND substr(${t.sent_hash}, 1, 7) = 'sha256:' AND substr(${t.sent_hash}, 8) NOT GLOB '*[^0-9a-f]*'`),createdAtCheck:check("doc_sync_connect_requests_created_at_ck",sql`${t.created_at} >= 0`),connectUnique:uniqueIndex("doc_sync_connect_requests_connect_uq").on(t.account_key,t.workspace_id,t.app_id,t.ref)}));});var vd=x(()=>{g();sqliteTable("doc_sync_links",{doc_id:text("doc_id").primaryKey().notNull(),account_key:text("account_key").notNull(),workspace_id:text("workspace_id").notNull(),app_id:text("app_id").notNull(),root_segments:text("root_segments").notNull(),ref:text("ref").notNull(),cloud_ref:text("cloud_ref").notNull(),connection_kind:text("connection_kind").$type().notNull().default("document"),app_grant_id:text("app_grant_id"),app_grant_generation:integer("app_grant_generation"),app_scope_version:text("app_scope_version"),origin:text("origin").notNull().default("own"),sync_state:text("sync_state").notNull().default("ok"),end_reason:text("end_reason"),file_state:text("file_state").notNull().default("present"),synced_revision:integer("synced_revision").notNull(),synced_hash:text("synced_hash").notNull(),synced_at:integer("synced_at").notNull(),file_dev_ino:text("file_dev_ino"),conflict_revision:integer("conflict_revision"),conflict_hash:text("conflict_hash"),conflict_at:integer("conflict_at"),remote_revision:integer("remote_revision"),remote_checked_at:integer("remote_checked_at"),published_revision:integer("published_revision"),bundle_sha256:text("bundle_sha256"),missing_since:integer("missing_since"),connected_at:integer("connected_at").notNull(),created_at:integer("created_at").notNull(),updated_at:integer("updated_at").notNull()},t=>({docIdCheck:check("doc_sync_links_doc_id_ck",sql`length(${t.doc_id}) BETWEEN 1 AND 128`),accountKeyCheck:check("doc_sync_links_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),workspaceIdCheck:check("doc_sync_links_workspace_id_ck",sql`length(${t.workspace_id}) BETWEEN 1 AND 256`),appIdCheck:check("doc_sync_links_app_id_ck",sql`length(${t.app_id}) BETWEEN 1 AND 128`),rootSegmentsCheck:check("doc_sync_links_root_segments_ck",sql`json_valid(${t.root_segments}) AND json_type(${t.root_segments}) = 'array'`),refCheck:check("doc_sync_links_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),cloudRefCheck:check("doc_sync_links_cloud_ref_ck",sql`length(${t.cloud_ref}) BETWEEN 1 AND 256`),originCheck:check("doc_sync_links_origin_ck",sql`${t.origin} IN ('own', 'received')`),syncStateCheck:check("doc_sync_links_sync_state_ck",sql`${t.sync_state} IN ('ok', 'conflict', 'ended')`),endReasonCheck:check("doc_sync_links_end_reason_ck",sql`${t.end_reason} IS NULL OR ${t.end_reason} IN ('disconnected', 'cloud_deleted')`),endedMatchesReasonCheck:check("doc_sync_links_ended_reason_ck",sql`(${t.sync_state} = 'ended') = (${t.end_reason} IS NOT NULL)`),fileStateCheck:check("doc_sync_links_file_state_ck",sql`${t.file_state} IN ('present', 'missing', 'root_unavailable')`),syncedRevisionCheck:check("doc_sync_links_synced_revision_ck",sql`${t.synced_revision} >= 0`),syncedHashCheck:check("doc_sync_links_synced_hash_ck",sql`length(${t.synced_hash}) = 71 AND substr(${t.synced_hash}, 1, 7) = 'sha256:' AND substr(${t.synced_hash}, 8) NOT GLOB '*[^0-9a-f]*'`),connectedAtCheck:check("doc_sync_links_connected_at_ck",sql`${t.connected_at} >= 0`),createdAtCheck:check("doc_sync_links_created_at_ck",sql`${t.created_at} >= 0`),updatedAtCheck:check("doc_sync_links_updated_at_ck",sql`${t.updated_at} >= ${t.created_at}`),liveRefUnique:uniqueIndex("doc_sync_links_live_ref_uq").on(t.workspace_id,t.app_id,t.ref).where(sql`${t.sync_state} <> 'ended'`),accountStateIdx:index("doc_sync_links_account_state_idx").on(t.account_key,t.sync_state),workspaceAppIdx:index("doc_sync_links_workspace_app_idx").on(t.workspace_id,t.app_id),connectionKindAccountIdx:index("doc_sync_links_connection_account_idx").on(t.account_key,t.connection_kind,t.app_id)}));});var Cd=x(()=>{g();sqliteTable("doc_create_dispatches",{dispatch_id:text("dispatch_id").primaryKey().notNull(),request_id:text("request_id").notNull(),account_key:text("account_key").notNull(),source:text("source").$type().notNull(),dispatched_at:integer("dispatched_at").notNull()},t=>({dispatchIdCheck:check("doc_create_dispatches_id_ck",sql`length(${t.dispatch_id}) BETWEEN 1 AND 128`),requestIdCheck:check("doc_create_dispatches_request_id_ck",sql`length(${t.request_id}) BETWEEN 1 AND 128`),accountKeyCheck:check("doc_create_dispatches_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),sourceCheck:check("doc_create_dispatches_source_ck",sql`${t.source} IN ('human', 'app_create', 'app_reattach')`),timestampCheck:check("doc_create_dispatches_time_ck",sql`${t.dispatched_at} >= 0`),accountDispatchedIndex:index("doc_create_dispatches_account_time_idx").on(t.account_key,t.dispatched_at)}));});var wn,R_,xd=x(()=>{g();wn=sqliteTable("app_sync_bindings",{binding_id:text("binding_id").primaryKey().notNull(),account_key:text("account_key").notNull(),workspace_id:text("workspace_id").notNull(),app_id:text("app_id").notNull(),root_segments:text("root_segments").notNull(),grant_id:text("grant_id"),grant_generation:integer("grant_generation"),scope_version:text("scope_version"),status:text("status").notNull().default("local_only"),created_at:integer("created_at").notNull(),updated_at:integer("updated_at").notNull()},t=>({bindingIdCheck:check("app_sync_bindings_binding_id_ck",sql`length(${t.binding_id}) BETWEEN 1 AND 128`),accountKeyCheck:check("app_sync_bindings_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),workspaceIdCheck:check("app_sync_bindings_workspace_id_ck",sql`length(${t.workspace_id}) BETWEEN 1 AND 256`),appIdCheck:check("app_sync_bindings_app_id_ck",sql`${t.app_id} = 'workout-log'`),rootSegmentsCheck:check("app_sync_bindings_root_segments_ck",sql`json_valid(${t.root_segments}) AND json_type(${t.root_segments}) = 'array'`),grantGenerationCheck:check("app_sync_bindings_generation_ck",sql`${t.grant_generation} IS NULL OR ${t.grant_generation} >= 1`),statusCheck:check("app_sync_bindings_status_ck",sql`${t.status} IN ('local_only', 'consent_required', 'checking', 'syncing', 'synced', 'partial', 'offline', 'revoked', 'unavailable', 'stopping')`),timestampsCheck:check("app_sync_bindings_timestamps_ck",sql`${t.updated_at} >= ${t.created_at}`),ownerAppUnique:uniqueIndex("app_sync_bindings_owner_app_uq").on(t.account_key,t.app_id)})),sqliteTable("app_sync_creation_jobs",{job_id:text("job_id").primaryKey().notNull(),binding_id:text("binding_id").notNull(),account_key:text("account_key").notNull(),grant_id:text("grant_id").notNull(),grant_generation:integer("grant_generation").notNull(),ref:text("ref").notNull(),request_id:text("request_id").notNull(),fingerprint:text("fingerprint").notNull(),operation_kind:text("operation_kind").$type().notNull().default("create"),document_id:text("document_id"),status:text("status").notNull().default("waiting"),attempts:integer("attempts").notNull().default(0),next_attempt_at:integer("next_attempt_at").notNull().default(0),created_at:integer("created_at").notNull(),updated_at:integer("updated_at").notNull()},t=>({jobIdCheck:check("app_sync_creation_jobs_job_id_ck",sql`length(${t.job_id}) BETWEEN 1 AND 128`),accountKeyCheck:check("app_sync_creation_jobs_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),generationCheck:check("app_sync_creation_jobs_generation_ck",sql`${t.grant_generation} >= 1`),refCheck:check("app_sync_creation_jobs_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),documentIdCheck:check("app_sync_creation_jobs_document_id_ck",sql`${t.document_id} IS NULL OR length(${t.document_id}) BETWEEN 1 AND 128`),operationKindCheck:check("app_sync_creation_jobs_operation_kind_ck",sql`${t.operation_kind} IN ('create', 'reattach')`),reattachDocumentCheck:check("app_sync_creation_jobs_reattach_document_ck",sql`${t.operation_kind} != 'reattach' OR ${t.document_id} IS NOT NULL`),fingerprintCheck:check("app_sync_creation_jobs_fingerprint_ck",sql`length(${t.fingerprint}) = 71 AND substr(${t.fingerprint}, 1, 7) = 'sha256:' AND substr(${t.fingerprint}, 8) NOT GLOB '*[^0-9a-f]*'`),statusCheck:check("app_sync_creation_jobs_status_ck",sql`${t.status} IN ('waiting', 'processing', 'completed', 'failed', 'conflict', 'blocked', 'invalidated', 'deleted')`),attemptsCheck:check("app_sync_creation_jobs_attempts_ck",sql`${t.attempts} >= 0`),timestampsCheck:check("app_sync_creation_jobs_timestamps_ck",sql`${t.updated_at} >= ${t.created_at}`),bindingFk:foreignKey({columns:[t.binding_id],foreignColumns:[wn.binding_id]}).onDelete("cascade"),requestIdUnique:uniqueIndex("app_sync_creation_jobs_request_id_uq").on(t.request_id),activeFingerprintUnique:uniqueIndex("app_sync_creation_jobs_active_identity_uq").on(t.binding_id,t.grant_id,t.grant_generation,t.ref,t.fingerprint,t.operation_kind).where(sql`${t.status} IN ('waiting', 'processing')`),runnableIndex:index("app_sync_creation_jobs_runnable_idx").on(t.binding_id,t.status,t.next_attempt_at),accountIndex:index("app_sync_creation_jobs_account_idx").on(t.account_key,t.status)})),sqliteTable("app_sync_results",{binding_id:text("binding_id").notNull(),account_key:text("account_key").notNull(),ref:text("ref").notNull(),grant_id:text("grant_id").notNull(),grant_generation:integer("grant_generation").notNull(),source_fingerprint:text("source_fingerprint"),synced_fingerprint:text("synced_fingerprint"),document_id:text("document_id"),status:text("status").notNull(),error_code:text("error_code"),next_attempt_at:integer("next_attempt_at").notNull().default(0),attempts:integer("attempts").notNull().default(0),updated_at:integer("updated_at").notNull()},t=>({resultAccountCheck:check("app_sync_results_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),resultRefCheck:check("app_sync_results_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),resultGenerationCheck:check("app_sync_results_generation_ck",sql`${t.grant_generation} >= 1`),resultStatusCheck:check("app_sync_results_status_ck",sql`${t.status} IN ('waiting', 'processing', 'synced', 'failed', 'conflict', 'blocked', 'excluded', 'deleted')`),resultAttemptsCheck:check("app_sync_results_attempts_ck",sql`${t.attempts} >= 0`),resultBindingFk:foreignKey({columns:[t.binding_id],foreignColumns:[wn.binding_id]}).onDelete("cascade"),resultIdentityUnique:uniqueIndex("app_sync_results_binding_ref_uq").on(t.binding_id,t.ref),resultAccountIndex:index("app_sync_results_account_status_idx").on(t.account_key,t.status)})),sqliteTable("app_sync_control_requests",{request_id:text("request_id").primaryKey().notNull(),binding_id:text("binding_id").notNull(),account_key:text("account_key").notNull(),app_id:text("app_id").notNull(),workspace_id:text("workspace_id").notNull(),root_fingerprint:text("root_fingerprint").notNull(),kind:text("kind").notNull(),state:text("state").notNull().default("pending"),grant_id:text("grant_id"),generation:integer("generation"),created_at:integer("created_at").notNull(),updated_at:integer("updated_at").notNull(),resolved_at:integer("resolved_at"),resolution:text("resolution"),resolution_id:text("resolution_id")},t=>({requestIdCheck:check("app_sync_control_requests_request_id_ck",sql`length(${t.request_id}) BETWEEN 1 AND 128`),requestAccountCheck:check("app_sync_control_requests_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),requestAppCheck:check("app_sync_control_requests_app_id_ck",sql`${t.app_id} = 'workout-log'`),requestWorkspaceCheck:check("app_sync_control_requests_workspace_id_ck",sql`length(${t.workspace_id}) BETWEEN 1 AND 256`),rootFingerprintCheck:check("app_sync_control_requests_root_fingerprint_ck",sql`length(${t.root_fingerprint}) = 64 AND ${t.root_fingerprint} NOT GLOB '*[^0-9a-f]*'`),requestKindCheck:check("app_sync_control_requests_kind_ck",sql`${t.kind} IN ('connect', 'revoke')`),requestStateCheck:check("app_sync_control_requests_state_ck",sql`${t.state} IN ('pending', 'unknown', 'confirmed', 'failed')`),revokeGrantCheck:check("app_sync_control_requests_revoke_grant_ck",sql`${t.kind} != 'revoke' OR (${t.grant_id} IS NOT NULL AND ${t.generation} >= 1)`),requestResolutionCheck:check("app_sync_control_requests_resolution_ck",sql`(${t.state} IN ('pending', 'unknown') AND ${t.resolved_at} IS NULL AND ${t.resolution} IS NULL AND ${t.resolution_id} IS NULL) OR (${t.state} IN ('confirmed', 'failed') AND ${t.resolved_at} IS NOT NULL AND ${t.resolution} IN ('remote', 'human') AND length(${t.resolution_id}) BETWEEN 1 AND 128)`),generationCheck:check("app_sync_control_requests_generation_ck",sql`${t.generation} IS NULL OR ${t.generation} >= 1`),timestampsCheck:check("app_sync_control_requests_timestamps_ck",sql`${t.updated_at} >= ${t.created_at}`),bindingFk:foreignKey({columns:[t.binding_id],foreignColumns:[wn.binding_id]}).onDelete("cascade"),unresolvedPerBinding:uniqueIndex("app_sync_control_requests_one_pending_uq").on(t.binding_id).where(sql`${t.state} IN ('pending', 'unknown')`),accountLookup:index("app_sync_control_requests_account_idx").on(t.account_key,t.app_id,t.state)})),sqliteTable("app_sync_deleted_refs",{account_key:text("account_key").notNull(),app_id:text("app_id").notNull(),ref_sha256:text("ref_sha256").notNull(),created_at:integer("created_at").notNull()},t=>({deletedAccountCheck:check("app_sync_deleted_refs_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),deletedAppCheck:check("app_sync_deleted_refs_app_id_ck",sql`${t.app_id} = 'workout-log'`),deletedHashCheck:check("app_sync_deleted_refs_hash_ck",sql`length(${t.ref_sha256}) = 64 AND ${t.ref_sha256} NOT GLOB '*[^0-9a-f]*'`),deletedIdentityUnique:uniqueIndex("app_sync_deleted_refs_identity_uq").on(t.account_key,t.app_id,t.ref_sha256)})),sqliteTable("app_sync_discovery_checkpoints",{binding_id:text("binding_id").primaryKey().notNull(),account_key:text("account_key").notNull(),workspace_id:text("workspace_id").notNull(),root_fingerprint:text("root_fingerprint").notNull(),grant_id:text("grant_id").notNull(),grant_generation:integer("grant_generation").notNull(),scope_version:text("scope_version").notNull(),last_cycle_started_at:integer("last_cycle_started_at"),cycle_started_at:integer("cycle_started_at"),docs_cursor:text("docs_cursor"),docs_complete:integer("docs_complete").notNull().default(0),deleted_cursor:text("deleted_cursor"),deleted_complete:integer("deleted_complete").notNull().default(0),updated_at:integer("updated_at").notNull()},t=>({checkpointAccountCheck:check("app_sync_discovery_checkpoints_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),checkpointRootCheck:check("app_sync_discovery_checkpoints_root_fingerprint_ck",sql`length(${t.root_fingerprint}) = 64 AND ${t.root_fingerprint} NOT GLOB '*[^0-9a-f]*'`),checkpointGenerationCheck:check("app_sync_discovery_checkpoints_generation_ck",sql`${t.grant_generation} >= 1`),checkpointScopeCheck:check("app_sync_discovery_checkpoints_scope_ck",sql`${t.scope_version} = 'workout-log.records.v1'`),checkpointDocsCompleteCheck:check("app_sync_discovery_checkpoints_docs_complete_ck",sql`${t.docs_complete} IN (0, 1)`),checkpointDeletedCompleteCheck:check("app_sync_discovery_checkpoints_deleted_complete_ck",sql`${t.deleted_complete} IN (0, 1)`),checkpointTimeCheck:check("app_sync_discovery_checkpoints_time_ck",sql`${t.updated_at} >= 0 AND (${t.last_cycle_started_at} IS NULL OR ${t.last_cycle_started_at} >= 0) AND (${t.cycle_started_at} IS NULL OR ${t.cycle_started_at} >= 0)`),checkpointBindingFk:foreignKey({columns:[t.binding_id],foreignColumns:[wn.binding_id]}).onDelete("cascade"),checkpointAccountIndex:index("app_sync_discovery_checkpoints_account_idx").on(t.account_key,t.grant_id,t.grant_generation)})),sqliteTable("app_sync_pending_discoveries",{binding_id:text("binding_id").notNull(),account_key:text("account_key").notNull(),grant_id:text("grant_id").notNull(),grant_generation:integer("grant_generation").notNull(),ref:text("ref").notNull(),doc_id:text("doc_id").notNull(),listed_revision:integer("listed_revision").notNull(),listed_fingerprint:text("listed_fingerprint").notNull(),app_grant_generation:integer("app_grant_generation").notNull(),needs_reattach:integer("needs_reattach").notNull().default(0),needs_reconcile:integer("needs_reconcile").notNull().default(0),status:text("status").notNull().default("waiting"),error_code:text("error_code"),attempts:integer("attempts").notNull().default(0),updated_at:integer("updated_at").notNull()},t=>({pendingAccountCheck:check("app_sync_pending_discoveries_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),pendingRefCheck:check("app_sync_pending_discoveries_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),pendingDocCheck:check("app_sync_pending_discoveries_doc_id_ck",sql`length(${t.doc_id}) BETWEEN 1 AND 128`),pendingRevisionCheck:check("app_sync_pending_discoveries_revision_ck",sql`${t.listed_revision} >= 0`),pendingFingerprintCheck:check("app_sync_pending_discoveries_fingerprint_ck",sql`length(${t.listed_fingerprint}) = 71 AND substr(${t.listed_fingerprint}, 1, 7) = 'sha256:' AND substr(${t.listed_fingerprint}, 8) NOT GLOB '*[^0-9a-f]*'`),pendingGenerationCheck:check("app_sync_pending_discoveries_generation_ck",sql`${t.grant_generation} >= 1 AND ${t.app_grant_generation} >= 1`),pendingFlagsCheck:check("app_sync_pending_discoveries_flags_ck",sql`${t.needs_reattach} IN (0, 1) AND ${t.needs_reconcile} IN (0, 1)`),pendingStatusCheck:check("app_sync_pending_discoveries_status_ck",sql`${t.status} IN ('waiting', 'processing', 'failed', 'invalidated')`),pendingAttemptsCheck:check("app_sync_pending_discoveries_attempts_ck",sql`${t.attempts} >= 0 AND ${t.updated_at} >= 0`),pendingBindingFk:foreignKey({columns:[t.binding_id],foreignColumns:[wn.binding_id]}).onDelete("cascade"),pendingIdentityUnique:uniqueIndex("app_sync_pending_discoveries_identity_uq").on(t.binding_id,t.grant_id,t.grant_generation,t.ref),pendingRunnableIdx:index("app_sync_pending_discoveries_runnable_idx").on(t.binding_id,t.grant_id,t.grant_generation,t.status,t.ref)})),R_=sqliteTable("app_sync_conflicts",{conflict_id:text("conflict_id").primaryKey().notNull(),binding_id:text("binding_id").notNull(),account_key:text("account_key").notNull(),workspace_id:text("workspace_id").notNull(),root_fingerprint:text("root_fingerprint").notNull(),grant_id:text("grant_id").notNull(),grant_generation:integer("grant_generation").notNull(),scope_version:text("scope_version").notNull(),ref:text("ref").notNull(),doc_id:text("doc_id").notNull(),local_version:text("local_version").notNull(),local_fingerprint:text("local_fingerprint").notNull(),baseline_revision:integer("baseline_revision"),baseline_fingerprint:text("baseline_fingerprint"),remote_revision:integer("remote_revision").notNull(),remote_fingerprint:text("remote_fingerprint").notNull(),needs_reattach:integer("needs_reattach").notNull().default(0),vault_handle:text("vault_handle"),preservation_status:text("preservation_status").notNull().default("pending"),state:text("state").notNull().default("open"),superseded_by:text("superseded_by"),resolution_request_id:text("resolution_request_id"),resolution_choice:text("resolution_choice"),cleanup_pending:integer("cleanup_pending").notNull().default(0),created_at:integer("created_at").notNull(),updated_at:integer("updated_at").notNull()},t=>({conflictIdCheck:check("app_sync_conflicts_id_ck",sql`length(${t.conflict_id}) BETWEEN 1 AND 128`),conflictAccountCheck:check("app_sync_conflicts_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),conflictRootCheck:check("app_sync_conflicts_root_fingerprint_ck",sql`length(${t.root_fingerprint}) = 64 AND ${t.root_fingerprint} NOT GLOB '*[^0-9a-f]*'`),conflictGenerationCheck:check("app_sync_conflicts_generation_ck",sql`${t.grant_generation} >= 1`),conflictScopeCheck:check("app_sync_conflicts_scope_ck",sql`${t.scope_version} = 'workout-log.records.v1'`),conflictRefCheck:check("app_sync_conflicts_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),conflictDocCheck:check("app_sync_conflicts_doc_id_ck",sql`length(${t.doc_id}) BETWEEN 1 AND 128`),conflictLocalVersionCheck:check("app_sync_conflicts_local_version_ck",sql`length(${t.local_version}) BETWEEN 1 AND 256 AND instr(${t.local_version}, '/') = 0 AND instr(${t.local_version}, char(92)) = 0`),conflictLocalFingerprintCheck:check("app_sync_conflicts_local_fingerprint_ck",sql`length(${t.local_fingerprint}) = 71 AND substr(${t.local_fingerprint}, 1, 7) = 'sha256:' AND substr(${t.local_fingerprint}, 8) NOT GLOB '*[^0-9a-f]*'`),conflictBaselineCheck:check("app_sync_conflicts_baseline_ck",sql`(${t.baseline_revision} IS NULL) = (${t.baseline_fingerprint} IS NULL) AND (${t.baseline_revision} IS NULL OR (${t.baseline_revision} >= 0 AND length(${t.baseline_fingerprint}) = 71 AND substr(${t.baseline_fingerprint}, 1, 7) = 'sha256:' AND substr(${t.baseline_fingerprint}, 8) NOT GLOB '*[^0-9a-f]*'))`),conflictRemoteCheck:check("app_sync_conflicts_remote_ck",sql`${t.remote_revision} >= 0 AND length(${t.remote_fingerprint}) = 71 AND substr(${t.remote_fingerprint}, 1, 7) = 'sha256:' AND substr(${t.remote_fingerprint}, 8) NOT GLOB '*[^0-9a-f]*'`),conflictFlagsCheck:check("app_sync_conflicts_flags_ck",sql`${t.needs_reattach} IN (0, 1) AND ${t.cleanup_pending} IN (0, 1)`),conflictHandleCheck:check("app_sync_conflicts_handle_ck",sql`${t.vault_handle} IS NULL OR (length(${t.vault_handle}) BETWEEN 1 AND 256 AND instr(${t.vault_handle}, '/') = 0 AND instr(${t.vault_handle}, char(92)) = 0)`),conflictPreservationCheck:check("app_sync_conflicts_preservation_ck",sql`${t.preservation_status} IN ('pending', 'ready', 'failed')`),conflictStateCheck:check("app_sync_conflicts_state_ck",sql`${t.state} IN ('open', 'resolving', 'superseded', 'resolved', 'kept_both', 'purging')`),conflictArchiveLifecycleCheck:check("app_sync_conflicts_archive_lifecycle_ck",sql`(
|
|
32
|
+
)`)}));});var cd=x(()=>{g();sqliteTable("ui_definition_archive",{definition_hash:text("definition_hash").primaryKey().notNull(),definition_json:text("definition_json").notNull(),created_at:integer("created_at").notNull()},t=>({definitionHashCheck:check("ui_definition_archive_definition_hash_ck",sql`length(${t.definition_hash}) = 64 AND ${t.definition_hash} NOT GLOB '*[^0-9a-f]*'`),definitionJsonCheck:check("ui_definition_archive_definition_json_ck",sql`json_valid(${t.definition_json}) AND json_type(${t.definition_json}) = 'object'`),createdAtCheck:check("ui_definition_archive_created_at_ck",sql`${t.created_at} >= 0`)}));});var ld,pd=x(()=>{g();ld=sqliteTable("projects",{id:text("id").primaryKey().notNull(),workspace_id:text("workspace_id").notNull(),name:text("name").notNull(),outcome:text("outcome").notNull(),due_date:text("due_date"),scene:text("scene").notNull().default("planning"),stages_json:text("stages_json").notNull(),stage_index:integer("stage_index").notNull(),created_at:text("created_at").notNull(),updated_at:text("updated_at").notNull(),accepted_at:text("accepted_at"),archived_at:text("archived_at")},t=>({idCheck:check("projects_id_ck",sql`${t.id} GLOB 'prj_*'`),sceneCheck:check("projects_scene_ck",sql`${t.scene} IN ('planning', 'plan_review', 'running', 'human_wait', 'limit_wait', 'failed_stop', 'analyzing_feedback', 'replanned', 'awaiting_review', 'accepted')`),stagesJsonCheck:check("projects_stages_json_ck",sql`json_valid(${t.stages_json}) AND json_type(${t.stages_json}) = 'array'`),stageIndexCheck:check("projects_stage_index_ck",sql`${t.stage_index} >= 1`)})),sqliteTable("project_criteria",{id:text("id").primaryKey().notNull(),project_id:text("project_id").notNull().references(()=>ld.id,{onDelete:"cascade"}),position:integer("position").notNull(),statement:text("statement").notNull(),verify_status:text("verify_status").notNull().default("pending"),verified_at:text("verified_at"),evidence_json:text("evidence_json").notNull().default("[]"),created_at:text("created_at").notNull(),updated_at:text("updated_at").notNull()},t=>({idCheck:check("project_criteria_id_ck",sql`${t.id} GLOB 'pjc_*'`),verifyStatusCheck:check("project_criteria_verify_status_ck",sql`${t.verify_status} IN ('pending', 'verifying', 'passed', 'failed')`),evidenceJsonCheck:check("project_criteria_evidence_json_ck",sql`json_valid(${t.evidence_json}) AND json_type(${t.evidence_json}) = 'array'`),projectPositionUnique:uniqueIndex("project_criteria_project_position_uq").on(t.project_id,t.position)})),sqliteTable("project_events",{id:text("id").primaryKey().notNull(),project_id:text("project_id").notNull().references(()=>ld.id,{onDelete:"restrict"}),seq:integer("seq").notNull(),actor_type:text("actor_type").notNull(),actor_id:text("actor_id"),type:text("type").notNull(),title:text("title").notNull(),summary:text("summary"),payload_json:text("payload_json").notNull().default("{}"),created_at:text("created_at").notNull()},t=>({idCheck:check("project_events_id_ck",sql`${t.id} GLOB 'pje_*'`),actorTypeCheck:check("project_events_actor_type_ck",sql`${t.actor_type} IN ('user', 'project_manager', 'system')`),payloadJsonCheck:check("project_events_payload_json_ck",sql`json_valid(${t.payload_json}) AND json_type(${t.payload_json}) = 'object'`),projectSeqUnique:uniqueIndex("project_events_project_seq_uq").on(t.project_id,t.seq)}));});var gs,hs,M,ms=x(()=>{g();gs=["THREAD_STATE","THREAD_PRIORITY"],hs=["gray","blue","violet","green","amber","orange","red","pink"],M=sqliteTable("common_codes",{code_group:text("code_group").notNull(),code:text("code").notNull(),code_name:text("code_name"),color:text("color").notNull().default("gray"),sort_order:integer("sort_order").notNull(),workspace_id:text("workspace_id"),is_builtin:integer("is_builtin").notNull().default(0),is_archived:integer("is_archived").notNull().default(0),metadata:text("metadata"),created_at:text("created_at").notNull(),updated_at:text("updated_at").notNull()},t=>({pk:primaryKey({columns:[t.code_group,t.code]}),metadataCheck:check("common_codes_metadata_ck",sql`${t.metadata} IS NULL OR (json_valid(${t.metadata}) AND json_type(${t.metadata}) = 'object')`),builtinCheck:check("common_codes_builtin_ck",sql`${t.is_builtin} IN (0, 1)`),archivedCheck:check("common_codes_archived_ck",sql`${t.is_archived} IN (0, 1)`),idxCommonCodesSelection:index("idx_common_codes_group_archived_order").on(t.code_group,t.is_archived,t.sort_order)}));});var _d,fd,gd,hd,md,X,K,B,kd=x(()=>{g();Xn();_d=["thread.snapshot.imported","thread.title.changed","thread.priority.changed","thread.state.changed","thread.highlight.created","thread.highlight.updated","thread.highlight.deleted","thread.highlights.regenerated"],fd=["user","agent","system"],gd=["auto","manual"],hd=["decision","judgment","issue","result","pivot"],md=["queued","running","completed","failed"],X=sqliteTable("thread_events",{id:text("id").primaryKey().notNull(),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),seq:integer("seq").notNull(),type:text("type").notNull(),actor_type:text("actor_type").notNull(),payload_json:text("payload_json").notNull(),created_at:text("created_at").notNull(),actor_id:text("actor_id"),task_id:text("task_id"),highlight_id:text("highlight_id")},t=>({typeCheck:check("thread_events_type_ck",sql`${t.type} IN ('thread.snapshot.imported', 'thread.title.changed', 'thread.priority.changed', 'thread.state.changed', 'thread.highlight.created', 'thread.highlight.updated', 'thread.highlight.deleted', 'thread.highlights.regenerated')`),actorTypeCheck:check("thread_events_actor_type_ck",sql`${t.actor_type} IN ('user', 'agent', 'system')`),payloadJsonCheck:check("thread_events_payload_json_ck",sql`json_valid(${t.payload_json}) AND json_type(${t.payload_json}) = 'object'`),threadSeqIndex:index("idx_thread_events_thread_seq").on(t.thread_id,t.seq),threadCreatedIndex:index("idx_thread_events_thread_created").on(t.thread_id,t.created_at),threadSeqUnique:uniqueIndex("thread_events_thread_seq_uq").on(t.thread_id,t.seq)})),K=sqliteTable("thread_highlight_runs",{id:text("id").primaryKey().notNull(),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),request_id:text("request_id").notNull(),status:text("status").notNull(),detector_version:text("detector_version").notNull(),requested_at:text("requested_at").notNull(),started_at:text("started_at"),completed_at:text("completed_at"),error_code:text("error_code"),previous_auto_count:integer("previous_auto_count"),new_auto_count:integer("new_auto_count")},t=>({statusCheck:check("thread_highlight_runs_status_ck",sql`${t.status} IN ('queued', 'running', 'completed', 'failed')`),countCheck:check("thread_highlight_runs_counts_ck",sql`(${t.previous_auto_count} IS NULL OR ${t.previous_auto_count} >= 0) AND (${t.new_auto_count} IS NULL OR ${t.new_auto_count} >= 0)`),threadRequestUnique:uniqueIndex("thread_highlight_runs_thread_request_uq").on(t.thread_id,t.request_id),inProgressThreadUnique:uniqueIndex("thread_highlight_runs_in_progress_thread_uq").on(t.thread_id).where(sql`${t.status} IN ('queued', 'running')`),threadStatusRequestedIndex:index("idx_thread_highlight_runs_thread_status_requested").on(t.thread_id,t.status,t.requested_at)})),B=sqliteTable("thread_highlights",{id:text("id").primaryKey().notNull(),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),source:text("source").notNull(),kind:text("kind").notNull(),status:text("status").notNull().default("active"),text:text("text"),covers_from_task_id:text("covers_from_task_id").notNull(),covers_to_task_id:text("covers_to_task_id").notNull(),revision:integer("revision").notNull().default(0),created_at:text("created_at").notNull(),updated_at:text("updated_at").notNull(),agent_id:text("agent_id"),source_task_id:text("source_task_id"),detector_version:text("detector_version"),content_fingerprint:text("content_fingerprint"),dismissed_at:text("dismissed_at")},t=>({sourceCheck:check("thread_highlights_source_ck",sql`${t.source} IN ('auto', 'manual')`),kindCheck:check("thread_highlights_kind_ck",sql`${t.kind} IN ('decision', 'judgment', 'issue', 'result', 'pivot')`),statusCheck:check("thread_highlights_status_ck",sql`${t.status} IN ('active', 'dismissed')`),activeTextCheck:check("thread_highlights_active_text_ck",sql`${t.status} = 'dismissed' OR (${t.text} IS NOT NULL AND length(${t.text}) > 0)`),coversCheck:check("thread_highlights_covers_ck",sql`length(${t.covers_from_task_id}) > 0 AND length(${t.covers_to_task_id}) > 0`),autoKeyCheck:check("thread_highlights_auto_key_ck",sql`${t.source} = 'manual' OR (${t.source} = 'auto' AND ${t.source_task_id} IS NOT NULL AND ${t.detector_version} IS NOT NULL AND ${t.content_fingerprint} IS NOT NULL AND length(${t.source_task_id}) > 0 AND length(${t.detector_version}) > 0 AND length(${t.content_fingerprint}) > 0)`),threadStatusCreatedIndex:index("idx_thread_highlights_thread_status_created").on(t.thread_id,t.status,t.created_at),threadCoversIndex:index("idx_thread_highlights_thread_covers").on(t.thread_id,t.covers_from_task_id,t.covers_to_task_id),autoIdempotencyUnique:uniqueIndex("thread_highlights_auto_idempotency_uq").on(t.thread_id,t.source_task_id,t.detector_version,t.content_fingerprint).where(sql`${t.source} = 'auto'`)}));});var Td=x(()=>{g();sqliteTable("storage_metadata",{source_kind:text("source_kind").notNull(),source_id:text("source_id").notNull(),utc_ts:text("utc_ts"),bytes:integer("bytes").notNull()},t=>({pk:primaryKey({columns:[t.source_kind,t.source_id]}),kindTimestampBytesIndex:index("idx_storage_metadata_kind_ts_bytes").on(t.source_kind,t.utc_ts,t.bytes)})),sqliteTable("storage_metadata_state",{unit:text("unit").primaryKey().notNull(),cursor_rowid:integer("cursor_rowid").notNull().default(0),end_rowid:integer("end_rowid"),complete:integer("complete").notNull().default(0),updated_at:text("updated_at").notNull()});});var He,wd=x(()=>{g();He=sqliteTable("agent_send_history",{workspace_id:text("workspace_id").notNull(),actor_id:text("actor_id").notNull(),agent_id:text("agent_id").notNull(),last_accepted_at:text("last_accepted_at").notNull()},t=>({pk:primaryKey({columns:[t.workspace_id,t.actor_id,t.agent_id]}),recentIndex:index("idx_agent_send_history_recent").on(t.workspace_id,t.actor_id,t.last_accepted_at,t.agent_id)}));});var Sd,Id=x(()=>{g();Xn();Gr();sqliteTable("sidebar_states",{workspace_id:text("workspace_id").primaryKey().references(()=>de.id,{onDelete:"cascade"}),revision:integer("revision").notNull().default(0),rail_collapsed:integer("rail_collapsed").notNull().default(0),seeded_at:text("seeded_at").notNull()},t=>({railCollapsedCheck:check("sidebar_states_rail_collapsed_ck",sql`${t.rail_collapsed} IN (0, 1)`)})),Sd=sqliteTable("sidebar_groups",{id:text("id").primaryKey(),workspace_id:text("workspace_id").notNull().references(()=>de.id,{onDelete:"cascade"}),name:text("name").notNull(),color:text("color").notNull(),collapsed:integer("collapsed").notNull().default(0),position:integer("position").notNull()},t=>({colorCheck:check("sidebar_groups_color_ck",sql`${t.color} IN ('cyan', 'orange', 'purple', 'blue', 'green', 'lime', 'yellow', 'coral', 'pink', 'indigo', 'sand', 'gray')`),collapsedCheck:check("sidebar_groups_collapsed_ck",sql`${t.collapsed} IN (0, 1)`),idxSidebarGroupsWorkspacePosition:index("idx_sidebar_groups_workspace_position").on(t.workspace_id,t.position)})),sqliteTable("sidebar_tabs",{workspace_id:text("workspace_id").notNull().references(()=>de.id,{onDelete:"cascade"}),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),group_id:text("group_id").references(()=>Sd.id,{onDelete:"set null"}),position:integer("position").notNull()},t=>({pk:primaryKey({columns:[t.workspace_id,t.thread_id]})})),sqliteTable("sidebar_closed_tabs",{id:integer("id").primaryKey({autoIncrement:true}),workspace_id:text("workspace_id").notNull().references(()=>de.id,{onDelete:"cascade"}),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),group_id:text("group_id").references(()=>Sd.id,{onDelete:"set null"}),position:integer("position").notNull(),closed_at:text("closed_at").notNull()},t=>({idxSidebarClosedTabsWorkspaceId:index("idx_sidebar_closed_tabs_workspace_id").on(t.workspace_id,t.id)})),sqliteTable("thread_reads",{workspace_id:text("workspace_id").notNull().references(()=>de.id,{onDelete:"cascade"}),thread_id:text("thread_id").notNull().references(()=>y.id,{onDelete:"cascade"}),read_through_at:text("read_through_at").notNull()},t=>({pk:primaryKey({columns:[t.workspace_id,t.thread_id]})}));});var Ad=x(()=>{g();sqliteTable("schedule_runs",{id:text("id").primaryKey(),schedule_id:text("schedule_id").notNull(),workspace_id:text("workspace_id").notNull(),mode:text("mode").notNull(),trigger:text("trigger").notNull(),occurrence_key:text("occurrence_key"),task_id:text("task_id"),app_id:text("app_id"),schedule_name:text("schedule_name"),builtin_id:text("builtin_id"),command:text("command"),high_frequency:integer("high_frequency").notNull().default(0),status:text("status").notNull(),error_code:text("error_code"),exit_code:integer("exit_code"),signal:text("signal"),started_at:text("started_at").notNull(),finished_at:text("finished_at"),duration_ms:integer("duration_ms"),pid:integer("pid"),host_pid:integer("host_pid"),output_tail:text("output_tail"),output_bytes:integer("output_bytes"),output_truncated:integer("output_truncated").notNull().default(0)},t=>({idx_schedule_runs_workspace_started:index("idx_schedule_runs_workspace_started").on(t.workspace_id,sql`${t.started_at} DESC`),idx_schedule_runs_schedule_started:index("idx_schedule_runs_schedule_started").on(t.schedule_id,sql`${t.started_at} DESC`),idx_schedule_runs_task_id:index("idx_schedule_runs_task_id").on(t.task_id),idx_schedule_runs_running:index("idx_schedule_runs_running").on(t.workspace_id,t.started_at).where(sql`${t.status} = 'running'`)}));});var Nd=x(()=>{g();sqliteTable("run_column_backfill",{name:text("name").primaryKey(),cursor:integer("cursor"),anchor_id:text("anchor_id"),completed_at:text("completed_at")});});var Od=x(()=>{g();sqliteTable("doc_sync_connect_requests",{request_id:text("request_id").primaryKey().notNull(),account_key:text("account_key").notNull(),workspace_id:text("workspace_id").notNull(),app_id:text("app_id").notNull(),ref:text("ref").notNull(),sent_hash:text("sent_hash").notNull(),created_at:integer("created_at").notNull()},t=>({requestIdCheck:check("doc_sync_connect_requests_request_id_ck",sql`length(${t.request_id}) = 36`),accountKeyCheck:check("doc_sync_connect_requests_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),workspaceIdCheck:check("doc_sync_connect_requests_workspace_id_ck",sql`length(${t.workspace_id}) BETWEEN 1 AND 256`),appIdCheck:check("doc_sync_connect_requests_app_id_ck",sql`length(${t.app_id}) BETWEEN 1 AND 128`),refCheck:check("doc_sync_connect_requests_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),sentHashCheck:check("doc_sync_connect_requests_sent_hash_ck",sql`length(${t.sent_hash}) = 71 AND substr(${t.sent_hash}, 1, 7) = 'sha256:' AND substr(${t.sent_hash}, 8) NOT GLOB '*[^0-9a-f]*'`),createdAtCheck:check("doc_sync_connect_requests_created_at_ck",sql`${t.created_at} >= 0`),connectUnique:uniqueIndex("doc_sync_connect_requests_connect_uq").on(t.account_key,t.workspace_id,t.app_id,t.ref)}));});var vd=x(()=>{g();sqliteTable("doc_sync_links",{doc_id:text("doc_id").primaryKey().notNull(),account_key:text("account_key").notNull(),workspace_id:text("workspace_id").notNull(),app_id:text("app_id").notNull(),root_segments:text("root_segments").notNull(),ref:text("ref").notNull(),cloud_ref:text("cloud_ref").notNull(),connection_kind:text("connection_kind").$type().notNull().default("document"),app_grant_id:text("app_grant_id"),app_grant_generation:integer("app_grant_generation"),app_scope_version:text("app_scope_version"),origin:text("origin").notNull().default("own"),sync_state:text("sync_state").notNull().default("ok"),end_reason:text("end_reason"),file_state:text("file_state").notNull().default("present"),synced_revision:integer("synced_revision").notNull(),synced_hash:text("synced_hash").notNull(),synced_at:integer("synced_at").notNull(),file_dev_ino:text("file_dev_ino"),conflict_revision:integer("conflict_revision"),conflict_hash:text("conflict_hash"),conflict_at:integer("conflict_at"),remote_revision:integer("remote_revision"),remote_checked_at:integer("remote_checked_at"),published_revision:integer("published_revision"),bundle_sha256:text("bundle_sha256"),missing_since:integer("missing_since"),connected_at:integer("connected_at").notNull(),created_at:integer("created_at").notNull(),updated_at:integer("updated_at").notNull()},t=>({docIdCheck:check("doc_sync_links_doc_id_ck",sql`length(${t.doc_id}) BETWEEN 1 AND 128`),accountKeyCheck:check("doc_sync_links_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),workspaceIdCheck:check("doc_sync_links_workspace_id_ck",sql`length(${t.workspace_id}) BETWEEN 1 AND 256`),appIdCheck:check("doc_sync_links_app_id_ck",sql`length(${t.app_id}) BETWEEN 1 AND 128`),rootSegmentsCheck:check("doc_sync_links_root_segments_ck",sql`json_valid(${t.root_segments}) AND json_type(${t.root_segments}) = 'array'`),refCheck:check("doc_sync_links_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),cloudRefCheck:check("doc_sync_links_cloud_ref_ck",sql`length(${t.cloud_ref}) BETWEEN 1 AND 256`),originCheck:check("doc_sync_links_origin_ck",sql`${t.origin} IN ('own', 'received')`),syncStateCheck:check("doc_sync_links_sync_state_ck",sql`${t.sync_state} IN ('ok', 'conflict', 'ended')`),endReasonCheck:check("doc_sync_links_end_reason_ck",sql`${t.end_reason} IS NULL OR ${t.end_reason} IN ('disconnected', 'cloud_deleted')`),endedMatchesReasonCheck:check("doc_sync_links_ended_reason_ck",sql`(${t.sync_state} = 'ended') = (${t.end_reason} IS NOT NULL)`),fileStateCheck:check("doc_sync_links_file_state_ck",sql`${t.file_state} IN ('present', 'missing', 'root_unavailable')`),syncedRevisionCheck:check("doc_sync_links_synced_revision_ck",sql`${t.synced_revision} >= 0`),syncedHashCheck:check("doc_sync_links_synced_hash_ck",sql`length(${t.synced_hash}) = 71 AND substr(${t.synced_hash}, 1, 7) = 'sha256:' AND substr(${t.synced_hash}, 8) NOT GLOB '*[^0-9a-f]*'`),connectedAtCheck:check("doc_sync_links_connected_at_ck",sql`${t.connected_at} >= 0`),createdAtCheck:check("doc_sync_links_created_at_ck",sql`${t.created_at} >= 0`),updatedAtCheck:check("doc_sync_links_updated_at_ck",sql`${t.updated_at} >= ${t.created_at}`),liveRefUnique:uniqueIndex("doc_sync_links_live_ref_uq").on(t.workspace_id,t.app_id,t.ref).where(sql`${t.sync_state} <> 'ended'`),accountStateIdx:index("doc_sync_links_account_state_idx").on(t.account_key,t.sync_state),workspaceAppIdx:index("doc_sync_links_workspace_app_idx").on(t.workspace_id,t.app_id),connectionKindAccountIdx:index("doc_sync_links_connection_account_idx").on(t.account_key,t.connection_kind,t.app_id)}));});var Cd=x(()=>{g();sqliteTable("doc_create_dispatches",{dispatch_id:text("dispatch_id").primaryKey().notNull(),request_id:text("request_id").notNull(),account_key:text("account_key").notNull(),source:text("source").$type().notNull(),dispatched_at:integer("dispatched_at").notNull()},t=>({dispatchIdCheck:check("doc_create_dispatches_id_ck",sql`length(${t.dispatch_id}) BETWEEN 1 AND 128`),requestIdCheck:check("doc_create_dispatches_request_id_ck",sql`length(${t.request_id}) BETWEEN 1 AND 128`),accountKeyCheck:check("doc_create_dispatches_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),sourceCheck:check("doc_create_dispatches_source_ck",sql`${t.source} IN ('human', 'app_create', 'app_reattach')`),timestampCheck:check("doc_create_dispatches_time_ck",sql`${t.dispatched_at} >= 0`),accountDispatchedIndex:index("doc_create_dispatches_account_time_idx").on(t.account_key,t.dispatched_at)}));});var wn,R_,xd=x(()=>{g();wn=sqliteTable("app_sync_bindings",{binding_id:text("binding_id").primaryKey().notNull(),account_key:text("account_key").notNull(),workspace_id:text("workspace_id").notNull(),app_id:text("app_id").notNull(),root_segments:text("root_segments").notNull(),grant_id:text("grant_id"),grant_generation:integer("grant_generation"),scope_version:text("scope_version"),status:text("status").notNull().default("local_only"),created_at:integer("created_at").notNull(),updated_at:integer("updated_at").notNull()},t=>({bindingIdCheck:check("app_sync_bindings_binding_id_ck",sql`length(${t.binding_id}) BETWEEN 1 AND 128`),accountKeyCheck:check("app_sync_bindings_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),workspaceIdCheck:check("app_sync_bindings_workspace_id_ck",sql`length(${t.workspace_id}) BETWEEN 1 AND 256`),appIdCheck:check("app_sync_bindings_app_id_ck",sql`${t.app_id} = 'workout-log'`),rootSegmentsCheck:check("app_sync_bindings_root_segments_ck",sql`json_valid(${t.root_segments}) AND json_type(${t.root_segments}) = 'array'`),grantGenerationCheck:check("app_sync_bindings_generation_ck",sql`${t.grant_generation} IS NULL OR ${t.grant_generation} >= 1`),statusCheck:check("app_sync_bindings_status_ck",sql`${t.status} IN ('local_only', 'consent_required', 'checking', 'syncing', 'synced', 'partial', 'offline', 'revoked', 'unavailable', 'stopping')`),timestampsCheck:check("app_sync_bindings_timestamps_ck",sql`${t.updated_at} >= ${t.created_at}`),ownerAppUnique:uniqueIndex("app_sync_bindings_owner_app_uq").on(t.account_key,t.app_id)})),sqliteTable("app_sync_creation_jobs",{job_id:text("job_id").primaryKey().notNull(),binding_id:text("binding_id").notNull(),account_key:text("account_key").notNull(),grant_id:text("grant_id").notNull(),grant_generation:integer("grant_generation").notNull(),ref:text("ref").notNull(),request_id:text("request_id").notNull(),fingerprint:text("fingerprint").notNull(),operation_kind:text("operation_kind").$type().notNull().default("create"),document_id:text("document_id"),status:text("status").notNull().default("waiting"),attempts:integer("attempts").notNull().default(0),next_attempt_at:integer("next_attempt_at").notNull().default(0),created_at:integer("created_at").notNull(),updated_at:integer("updated_at").notNull()},t=>({jobIdCheck:check("app_sync_creation_jobs_job_id_ck",sql`length(${t.job_id}) BETWEEN 1 AND 128`),accountKeyCheck:check("app_sync_creation_jobs_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),generationCheck:check("app_sync_creation_jobs_generation_ck",sql`${t.grant_generation} >= 1`),refCheck:check("app_sync_creation_jobs_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),documentIdCheck:check("app_sync_creation_jobs_document_id_ck",sql`${t.document_id} IS NULL OR length(${t.document_id}) BETWEEN 1 AND 128`),operationKindCheck:check("app_sync_creation_jobs_operation_kind_ck",sql`${t.operation_kind} IN ('create', 'reattach')`),reattachDocumentCheck:check("app_sync_creation_jobs_reattach_document_ck",sql`${t.operation_kind} != 'reattach' OR ${t.document_id} IS NOT NULL`),fingerprintCheck:check("app_sync_creation_jobs_fingerprint_ck",sql`length(${t.fingerprint}) = 71 AND substr(${t.fingerprint}, 1, 7) = 'sha256:' AND substr(${t.fingerprint}, 8) NOT GLOB '*[^0-9a-f]*'`),statusCheck:check("app_sync_creation_jobs_status_ck",sql`${t.status} IN ('waiting', 'processing', 'completed', 'failed', 'conflict', 'blocked', 'invalidated', 'deleted')`),attemptsCheck:check("app_sync_creation_jobs_attempts_ck",sql`${t.attempts} >= 0`),timestampsCheck:check("app_sync_creation_jobs_timestamps_ck",sql`${t.updated_at} >= ${t.created_at}`),bindingFk:foreignKey({columns:[t.binding_id],foreignColumns:[wn.binding_id]}).onDelete("cascade"),requestIdUnique:uniqueIndex("app_sync_creation_jobs_request_id_uq").on(t.request_id),activeFingerprintUnique:uniqueIndex("app_sync_creation_jobs_active_identity_uq").on(t.binding_id,t.grant_id,t.grant_generation,t.ref,t.fingerprint,t.operation_kind).where(sql`${t.status} IN ('waiting', 'processing')`),runnableIndex:index("app_sync_creation_jobs_runnable_idx").on(t.binding_id,t.status,t.next_attempt_at),accountIndex:index("app_sync_creation_jobs_account_idx").on(t.account_key,t.status)})),sqliteTable("app_sync_results",{binding_id:text("binding_id").notNull(),account_key:text("account_key").notNull(),ref:text("ref").notNull(),grant_id:text("grant_id").notNull(),grant_generation:integer("grant_generation").notNull(),source_fingerprint:text("source_fingerprint"),synced_fingerprint:text("synced_fingerprint"),document_id:text("document_id"),status:text("status").notNull(),error_code:text("error_code"),next_attempt_at:integer("next_attempt_at").notNull().default(0),attempts:integer("attempts").notNull().default(0),updated_at:integer("updated_at").notNull()},t=>({resultAccountCheck:check("app_sync_results_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),resultRefCheck:check("app_sync_results_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),resultGenerationCheck:check("app_sync_results_generation_ck",sql`${t.grant_generation} >= 1`),resultStatusCheck:check("app_sync_results_status_ck",sql`${t.status} IN ('waiting', 'processing', 'synced', 'failed', 'conflict', 'blocked', 'excluded', 'deleted')`),resultAttemptsCheck:check("app_sync_results_attempts_ck",sql`${t.attempts} >= 0`),resultBindingFk:foreignKey({columns:[t.binding_id],foreignColumns:[wn.binding_id]}).onDelete("cascade"),resultIdentityUnique:uniqueIndex("app_sync_results_binding_ref_uq").on(t.binding_id,t.ref),resultAccountIndex:index("app_sync_results_account_status_idx").on(t.account_key,t.status)})),sqliteTable("app_sync_control_requests",{request_id:text("request_id").primaryKey().notNull(),binding_id:text("binding_id").notNull(),account_key:text("account_key").notNull(),app_id:text("app_id").notNull(),workspace_id:text("workspace_id").notNull(),root_fingerprint:text("root_fingerprint").notNull(),kind:text("kind").notNull(),state:text("state").notNull().default("pending"),grant_id:text("grant_id"),generation:integer("generation"),created_at:integer("created_at").notNull(),updated_at:integer("updated_at").notNull(),resolved_at:integer("resolved_at"),resolution:text("resolution"),resolution_id:text("resolution_id")},t=>({requestIdCheck:check("app_sync_control_requests_request_id_ck",sql`length(${t.request_id}) BETWEEN 1 AND 128`),requestAccountCheck:check("app_sync_control_requests_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),requestAppCheck:check("app_sync_control_requests_app_id_ck",sql`${t.app_id} = 'workout-log'`),requestWorkspaceCheck:check("app_sync_control_requests_workspace_id_ck",sql`length(${t.workspace_id}) BETWEEN 1 AND 256`),rootFingerprintCheck:check("app_sync_control_requests_root_fingerprint_ck",sql`length(${t.root_fingerprint}) = 64 AND ${t.root_fingerprint} NOT GLOB '*[^0-9a-f]*'`),requestKindCheck:check("app_sync_control_requests_kind_ck",sql`${t.kind} IN ('connect', 'revoke')`),requestStateCheck:check("app_sync_control_requests_state_ck",sql`${t.state} IN ('pending', 'unknown', 'confirmed', 'failed')`),revokeGrantCheck:check("app_sync_control_requests_revoke_grant_ck",sql`${t.kind} != 'revoke' OR (${t.grant_id} IS NOT NULL AND ${t.generation} >= 1)`),requestResolutionCheck:check("app_sync_control_requests_resolution_ck",sql`(${t.state} IN ('pending', 'unknown') AND ${t.resolved_at} IS NULL AND ${t.resolution} IS NULL AND ${t.resolution_id} IS NULL) OR (${t.state} IN ('confirmed', 'failed') AND ${t.resolved_at} IS NOT NULL AND ${t.resolution} IN ('remote', 'human') AND length(${t.resolution_id}) BETWEEN 1 AND 128)`),generationCheck:check("app_sync_control_requests_generation_ck",sql`${t.generation} IS NULL OR ${t.generation} >= 1`),timestampsCheck:check("app_sync_control_requests_timestamps_ck",sql`${t.updated_at} >= ${t.created_at}`),bindingFk:foreignKey({columns:[t.binding_id],foreignColumns:[wn.binding_id]}).onDelete("cascade"),unresolvedPerBinding:uniqueIndex("app_sync_control_requests_one_pending_uq").on(t.binding_id).where(sql`${t.state} IN ('pending', 'unknown')`),accountLookup:index("app_sync_control_requests_account_idx").on(t.account_key,t.app_id,t.state)})),sqliteTable("app_sync_deleted_refs",{account_key:text("account_key").notNull(),app_id:text("app_id").notNull(),ref_sha256:text("ref_sha256").notNull(),created_at:integer("created_at").notNull()},t=>({deletedAccountCheck:check("app_sync_deleted_refs_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),deletedAppCheck:check("app_sync_deleted_refs_app_id_ck",sql`${t.app_id} = 'workout-log'`),deletedHashCheck:check("app_sync_deleted_refs_hash_ck",sql`length(${t.ref_sha256}) = 64 AND ${t.ref_sha256} NOT GLOB '*[^0-9a-f]*'`),deletedIdentityUnique:uniqueIndex("app_sync_deleted_refs_identity_uq").on(t.account_key,t.app_id,t.ref_sha256)})),sqliteTable("app_sync_discovery_checkpoints",{binding_id:text("binding_id").primaryKey().notNull(),account_key:text("account_key").notNull(),workspace_id:text("workspace_id").notNull(),root_fingerprint:text("root_fingerprint").notNull(),grant_id:text("grant_id").notNull(),grant_generation:integer("grant_generation").notNull(),scope_version:text("scope_version").notNull(),last_cycle_started_at:integer("last_cycle_started_at"),cycle_started_at:integer("cycle_started_at"),docs_cursor:text("docs_cursor"),docs_complete:integer("docs_complete").notNull().default(0),deleted_cursor:text("deleted_cursor"),deleted_complete:integer("deleted_complete").notNull().default(0),updated_at:integer("updated_at").notNull()},t=>({checkpointAccountCheck:check("app_sync_discovery_checkpoints_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),checkpointRootCheck:check("app_sync_discovery_checkpoints_root_fingerprint_ck",sql`length(${t.root_fingerprint}) = 64 AND ${t.root_fingerprint} NOT GLOB '*[^0-9a-f]*'`),checkpointGenerationCheck:check("app_sync_discovery_checkpoints_generation_ck",sql`${t.grant_generation} >= 1`),checkpointScopeCheck:check("app_sync_discovery_checkpoints_scope_ck",sql`${t.scope_version} = 'workout-log.records.v1'`),checkpointDocsCompleteCheck:check("app_sync_discovery_checkpoints_docs_complete_ck",sql`${t.docs_complete} IN (0, 1)`),checkpointDeletedCompleteCheck:check("app_sync_discovery_checkpoints_deleted_complete_ck",sql`${t.deleted_complete} IN (0, 1)`),checkpointTimeCheck:check("app_sync_discovery_checkpoints_time_ck",sql`${t.updated_at} >= 0 AND (${t.last_cycle_started_at} IS NULL OR ${t.last_cycle_started_at} >= 0) AND (${t.cycle_started_at} IS NULL OR ${t.cycle_started_at} >= 0)`),checkpointBindingFk:foreignKey({columns:[t.binding_id],foreignColumns:[wn.binding_id]}).onDelete("cascade"),checkpointAccountIndex:index("app_sync_discovery_checkpoints_account_idx").on(t.account_key,t.grant_id,t.grant_generation)})),sqliteTable("app_sync_pending_discoveries",{binding_id:text("binding_id").notNull(),account_key:text("account_key").notNull(),grant_id:text("grant_id").notNull(),grant_generation:integer("grant_generation").notNull(),ref:text("ref").notNull(),doc_id:text("doc_id").notNull(),listed_revision:integer("listed_revision").notNull(),listed_fingerprint:text("listed_fingerprint").notNull(),app_grant_generation:integer("app_grant_generation").notNull(),needs_reattach:integer("needs_reattach").notNull().default(0),needs_reconcile:integer("needs_reconcile").notNull().default(0),status:text("status").notNull().default("waiting"),error_code:text("error_code"),attempts:integer("attempts").notNull().default(0),updated_at:integer("updated_at").notNull()},t=>({pendingAccountCheck:check("app_sync_pending_discoveries_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),pendingRefCheck:check("app_sync_pending_discoveries_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),pendingDocCheck:check("app_sync_pending_discoveries_doc_id_ck",sql`length(${t.doc_id}) BETWEEN 1 AND 128`),pendingRevisionCheck:check("app_sync_pending_discoveries_revision_ck",sql`${t.listed_revision} >= 0`),pendingFingerprintCheck:check("app_sync_pending_discoveries_fingerprint_ck",sql`length(${t.listed_fingerprint}) = 71 AND substr(${t.listed_fingerprint}, 1, 7) = 'sha256:' AND substr(${t.listed_fingerprint}, 8) NOT GLOB '*[^0-9a-f]*'`),pendingGenerationCheck:check("app_sync_pending_discoveries_generation_ck",sql`${t.grant_generation} >= 1 AND ${t.app_grant_generation} >= 1`),pendingFlagsCheck:check("app_sync_pending_discoveries_flags_ck",sql`${t.needs_reattach} IN (0, 1) AND ${t.needs_reconcile} IN (0, 1)`),pendingStatusCheck:check("app_sync_pending_discoveries_status_ck",sql`${t.status} IN ('waiting', 'processing', 'failed', 'invalidated')`),pendingAttemptsCheck:check("app_sync_pending_discoveries_attempts_ck",sql`${t.attempts} >= 0 AND ${t.updated_at} >= 0`),pendingBindingFk:foreignKey({columns:[t.binding_id],foreignColumns:[wn.binding_id]}).onDelete("cascade"),pendingIdentityUnique:uniqueIndex("app_sync_pending_discoveries_identity_uq").on(t.binding_id,t.grant_id,t.grant_generation,t.ref),pendingRunnableIdx:index("app_sync_pending_discoveries_runnable_idx").on(t.binding_id,t.grant_id,t.grant_generation,t.status,t.ref)})),R_=sqliteTable("app_sync_conflicts",{conflict_id:text("conflict_id").primaryKey().notNull(),binding_id:text("binding_id").notNull(),account_key:text("account_key").notNull(),workspace_id:text("workspace_id").notNull(),root_fingerprint:text("root_fingerprint").notNull(),grant_id:text("grant_id").notNull(),grant_generation:integer("grant_generation").notNull(),scope_version:text("scope_version").notNull(),ref:text("ref").notNull(),doc_id:text("doc_id").notNull(),local_version:text("local_version").notNull(),local_fingerprint:text("local_fingerprint").notNull(),baseline_revision:integer("baseline_revision"),baseline_fingerprint:text("baseline_fingerprint"),remote_revision:integer("remote_revision").notNull(),remote_fingerprint:text("remote_fingerprint").notNull(),needs_reattach:integer("needs_reattach").notNull().default(0),vault_handle:text("vault_handle"),preservation_status:text("preservation_status").notNull().default("pending"),state:text("state").notNull().default("open"),superseded_by:text("superseded_by"),resolution_request_id:text("resolution_request_id"),resolution_choice:text("resolution_choice"),cleanup_pending:integer("cleanup_pending").notNull().default(0),created_at:integer("created_at").notNull(),updated_at:integer("updated_at").notNull()},t=>({conflictIdCheck:check("app_sync_conflicts_id_ck",sql`length(${t.conflict_id}) BETWEEN 1 AND 128`),conflictAccountCheck:check("app_sync_conflicts_account_key_ck",sql`length(${t.account_key}) = 64 AND ${t.account_key} NOT GLOB '*[^0-9a-f]*'`),conflictRootCheck:check("app_sync_conflicts_root_fingerprint_ck",sql`length(${t.root_fingerprint}) = 64 AND ${t.root_fingerprint} NOT GLOB '*[^0-9a-f]*'`),conflictGenerationCheck:check("app_sync_conflicts_generation_ck",sql`${t.grant_generation} >= 1`),conflictScopeCheck:check("app_sync_conflicts_scope_ck",sql`${t.scope_version} = 'workout-log.records.v1'`),conflictRefCheck:check("app_sync_conflicts_ref_ck",sql`length(${t.ref}) BETWEEN 1 AND 256`),conflictDocCheck:check("app_sync_conflicts_doc_id_ck",sql`length(${t.doc_id}) BETWEEN 1 AND 128`),conflictLocalVersionCheck:check("app_sync_conflicts_local_version_ck",sql`length(${t.local_version}) BETWEEN 1 AND 256 AND instr(${t.local_version}, '/') = 0 AND instr(${t.local_version}, char(92)) = 0`),conflictLocalFingerprintCheck:check("app_sync_conflicts_local_fingerprint_ck",sql`length(${t.local_fingerprint}) = 71 AND substr(${t.local_fingerprint}, 1, 7) = 'sha256:' AND substr(${t.local_fingerprint}, 8) NOT GLOB '*[^0-9a-f]*'`),conflictBaselineCheck:check("app_sync_conflicts_baseline_ck",sql`(${t.baseline_revision} IS NULL) = (${t.baseline_fingerprint} IS NULL) AND (${t.baseline_revision} IS NULL OR (${t.baseline_revision} >= 0 AND length(${t.baseline_fingerprint}) = 71 AND substr(${t.baseline_fingerprint}, 1, 7) = 'sha256:' AND substr(${t.baseline_fingerprint}, 8) NOT GLOB '*[^0-9a-f]*'))`),conflictRemoteCheck:check("app_sync_conflicts_remote_ck",sql`${t.remote_revision} >= 0 AND length(${t.remote_fingerprint}) = 71 AND substr(${t.remote_fingerprint}, 1, 7) = 'sha256:' AND substr(${t.remote_fingerprint}, 8) NOT GLOB '*[^0-9a-f]*'`),conflictFlagsCheck:check("app_sync_conflicts_flags_ck",sql`${t.needs_reattach} IN (0, 1) AND ${t.cleanup_pending} IN (0, 1)`),conflictHandleCheck:check("app_sync_conflicts_handle_ck",sql`${t.vault_handle} IS NULL OR (length(${t.vault_handle}) BETWEEN 1 AND 256 AND instr(${t.vault_handle}, '/') = 0 AND instr(${t.vault_handle}, char(92)) = 0)`),conflictPreservationCheck:check("app_sync_conflicts_preservation_ck",sql`${t.preservation_status} IN ('pending', 'ready', 'failed')`),conflictStateCheck:check("app_sync_conflicts_state_ck",sql`${t.state} IN ('open', 'resolving', 'superseded', 'resolved', 'kept_both', 'purging')`),conflictArchiveLifecycleCheck:check("app_sync_conflicts_archive_lifecycle_ck",sql`(
|
|
33
33
|
(${t.preservation_status} IN ('pending', 'failed') AND ${t.vault_handle} IS NULL
|
|
34
34
|
AND ${t.state} IN ('open', 'purging') AND ${t.cleanup_pending} = 0
|
|
35
35
|
AND (${t.state} = 'purging' OR ${t.superseded_by} IS NULL))
|