@opengeni/db 0.36.1 → 3.1.0-canary.0

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.
Files changed (274) hide show
  1. package/dist/attached-browser-devices.d.ts +7 -0
  2. package/dist/automations.d.ts +154 -0
  3. package/dist/canonical-human-identities.js +3 -3
  4. package/dist/capability-integrations.d.ts +13 -0
  5. package/dist/child-lifecycle-notices.d.ts +68 -0
  6. package/dist/{chunk-GYO7ED2Q.js → chunk-EULAN2NP.js} +2 -2
  7. package/dist/{chunk-VTPRIXKG.js → chunk-NJVZPWXY.js} +3 -3
  8. package/dist/{chunk-HSOWSYOX.js → chunk-NMUBV7Z5.js} +19 -11
  9. package/dist/chunk-NMUBV7Z5.js.map +1 -0
  10. package/dist/chunk-OF5OBB76.js +4457 -0
  11. package/dist/chunk-OF5OBB76.js.map +1 -0
  12. package/dist/{chunk-5KTIEDX7.js → chunk-PR2WMLOQ.js} +7714 -4443
  13. package/dist/chunk-PR2WMLOQ.js.map +1 -0
  14. package/dist/{chunk-Z7VYMNPZ.js → chunk-SCPUJS53.js} +41 -4
  15. package/dist/chunk-SCPUJS53.js.map +1 -0
  16. package/dist/{chunk-SK7YYHBI.js → chunk-SIBYBA2D.js} +46 -1
  17. package/dist/chunk-SIBYBA2D.js.map +1 -0
  18. package/dist/chunk-TIKF3KTI.js +383 -0
  19. package/dist/chunk-TIKF3KTI.js.map +1 -0
  20. package/dist/chunk-ZZ5LJEFX.js +516 -0
  21. package/dist/chunk-ZZ5LJEFX.js.map +1 -0
  22. package/dist/codemode-operations.d.ts +1 -6
  23. package/dist/company-brain-context-selection-schema.d.ts +705 -0
  24. package/dist/company-brain-context-selection.d.ts +94 -0
  25. package/dist/company-brain-governed-writes.d.ts +24 -0
  26. package/dist/company-brain.d.ts +55 -0
  27. package/dist/company-profile-agent-admin.d.ts +15 -0
  28. package/dist/company-profile-schema.d.ts +619 -2
  29. package/dist/company-profile.d.ts +9 -4
  30. package/dist/connection-authority.d.ts +95 -0
  31. package/dist/connection-scopes.d.ts +8 -0
  32. package/dist/connection-tenancy-backfill.d.ts +41 -0
  33. package/dist/connection-token-resolver.d.ts +30 -1
  34. package/dist/database.d.ts +19 -0
  35. package/dist/editable-artifact-durable-export.d.ts +10 -0
  36. package/dist/editable-artifact-durable-export.js +18 -3
  37. package/dist/editable-artifact-durable-export.js.map +1 -1
  38. package/dist/editable-artifacts.d.ts +2 -2
  39. package/dist/editable-artifacts.js +3 -3
  40. package/dist/governed-learning-activation-schema.d.ts +984 -0
  41. package/dist/governed-learning-activation.d.ts +98 -0
  42. package/dist/governed-learning-evaluator-schema.d.ts +633 -0
  43. package/dist/governed-learning-evaluator.d.ts +28 -0
  44. package/dist/index.d.ts +1633 -87
  45. package/dist/index.js +22004 -8109
  46. package/dist/index.js.map +1 -1
  47. package/dist/insights.d.ts +18 -0
  48. package/dist/integration-bindings.d.ts +1 -0
  49. package/dist/integration-facets.d.ts +30 -0
  50. package/dist/interaction-placement-loss.d.ts +22 -0
  51. package/dist/knowledge-source-sync-schema.d.ts +730 -0
  52. package/dist/knowledge-source-sync.d.ts +60 -0
  53. package/dist/managed-human-provisioning.d.ts +25 -0
  54. package/dist/memory-domain.d.ts +3 -3
  55. package/dist/migrate.d.ts +11 -1
  56. package/dist/migrate.js +1 -1
  57. package/dist/new-session-drafts.d.ts +43 -5
  58. package/dist/organization-membership-backfill.d.ts +174 -0
  59. package/dist/organization-membership-lifecycle.d.ts +162 -0
  60. package/dist/pr-review.d.ts +107 -0
  61. package/dist/preference-registry-schema.d.ts +2 -0
  62. package/dist/preference-registry.d.ts +2 -0
  63. package/dist/provision-roles.js +1 -1
  64. package/dist/runtime-posture.d.ts +23 -9
  65. package/dist/schema.d.ts +24925 -13697
  66. package/dist/schema.js +103 -1
  67. package/dist/scoped-knowledge-schema.d.ts +52 -1
  68. package/dist/session-background-commands.d.ts +125 -0
  69. package/dist/session-background-commands.js +34 -0
  70. package/dist/session-background-commands.js.map +1 -0
  71. package/dist/session-control.d.ts +156 -3
  72. package/dist/session-goal-pacing.d.ts +68 -0
  73. package/dist/session-queue-commands.d.ts +42 -5
  74. package/dist/session-realtime-ledger.d.ts +3 -0
  75. package/dist/session-tenancy.d.ts +71 -1
  76. package/dist/session-tenancy.js +25 -3
  77. package/dist/session-tool-call-settlement.d.ts +9 -4
  78. package/dist/slack-routing-personal-workspace.d.ts +23 -0
  79. package/dist/slack-routing.d.ts +153 -0
  80. package/dist/slack-task-policy-schema.d.ts +34 -0
  81. package/dist/slack-task-policy.d.ts +8 -0
  82. package/dist/slack-user-link-access.d.ts +1 -0
  83. package/dist/task-notes-schema.d.ts +594 -0
  84. package/dist/task-notes.d.ts +39 -0
  85. package/dist/turn-initiator.d.ts +2 -0
  86. package/dist/user-resource-authority.d.ts +109 -0
  87. package/dist/video-generation.js +3 -3
  88. package/dist/workspace-authority.d.ts +81 -0
  89. package/dist/workspace-instruction-policies-schema.d.ts +279 -0
  90. package/dist/workspace-instruction-policies.d.ts +62 -0
  91. package/dist/workspace-learning-policy.d.ts +1 -0
  92. package/dist/workspace-membership-permissions.d.ts +2 -0
  93. package/drizzle/0240_enrollment_connection_authority.sql +39 -0
  94. package/drizzle/0240_model_context_user_messages.sql +204 -0
  95. package/drizzle/0241_atomic_personal_resource_delegation.sql +1000 -0
  96. package/drizzle/0241_enrollment_agent_runtime.sql +70 -0
  97. package/drizzle/0243_google_drive_object_acl_authority.sql +554 -0
  98. package/drizzle/0244_slack_app_home_refresh_queue.sql +120 -0
  99. package/drizzle/0245_model_context_contribution_facts.sql +88 -0
  100. package/drizzle/0246_integration_personal_instance_authority.sql +70 -0
  101. package/drizzle/0247_terraform_stacks_provenance_repair.sql +428 -0
  102. package/drizzle/0248_terraform_stacks_component_resolution_fence.sql +83 -0
  103. package/drizzle/0249_personal_resource_delegation_authority_correction.sql +662 -0
  104. package/drizzle/0250_direct_retained_process_owner_liveness.sql +199 -0
  105. package/drizzle/0251_connected_machine_operation_policy.sql +45 -0
  106. package/drizzle/0252_scheduled_personal_resource_delegation.sql +1867 -0
  107. package/drizzle/0253_common_user_resource_authority_lifecycle.sql +1555 -0
  108. package/drizzle/0254_scoped_variable_set_authority.sql +1255 -0
  109. package/drizzle/0255_company_brain_governed_write_proposals.sql +524 -0
  110. package/drizzle/0256_connection_authority_delegation.sql +703 -0
  111. package/drizzle/0257_goal_revision_decisions_and_root_constraints.sql +436 -0
  112. package/drizzle/0258_three_scope_document_knowledge_authority.sql +1273 -0
  113. package/drizzle/0259_company_brain_context_selection_receipts.sql +869 -0
  114. package/drizzle/0260_task_note_knowledge_promotion.sql +820 -0
  115. package/drizzle/0261_preference_knowledge_proposal_actor_binding.sql +471 -0
  116. package/drizzle/0262_scoped_connected_machines_and_rigs.sql +1700 -0
  117. package/drizzle/0263_organization_membership_lifecycle.sql +3284 -0
  118. package/drizzle/0264_connection_authority_runtime_activation.sql +1084 -0
  119. package/drizzle/0266_company_brain_context_receipt_inspection.sql +156 -0
  120. package/drizzle/0268_governed_learning_decision_receipts.sql +825 -0
  121. package/drizzle/0269_governed_learning_activation_controller.sql +1874 -0
  122. package/drizzle/0270_governed_learning_history_inspection.sql +170 -0
  123. package/drizzle/0271_company_brain_retrieval_only_default.sql +524 -0
  124. package/drizzle/0272_human_confirmed_learning_activation.sql +591 -0
  125. package/drizzle/0273_scheduled_variable_set_materialization.sql +268 -0
  126. package/drizzle/0274_human_confirmed_knowledge_review.sql +310 -0
  127. package/drizzle/0275_scheduled_connection_authority.sql +5527 -0
  128. package/drizzle/0276_onboarding_proposal_initiating_human_guc.sql +198 -0
  129. package/drizzle/0277_workspace_writer_authority_attribution.sql +393 -0
  130. package/drizzle/0278_workspace_membership_removal_fencing.sql +1174 -0
  131. package/drizzle/0279_workspace_connection_use_lane.sql +343 -0
  132. package/drizzle/0280_connection_and_variable_set_audit_attribution.sql +773 -0
  133. package/drizzle/0281_viewer_holder_authority_claims.sql +52 -0
  134. package/drizzle/0282_variable_set_session_attach_attribution.sql +178 -0
  135. package/drizzle/0283_editable_spreadsheet_authored_state.sql +82 -0
  136. package/drizzle/0284_truthful_human_confirmed_review_reason.sql +930 -0
  137. package/drizzle/0285_organization_tenancy_inventory.sql +329 -0
  138. package/drizzle/0286_widen_task_note_expiry_ceiling.sql +391 -0
  139. package/drizzle/0287_open_suffix_pending_tool_calls.sql +18 -0
  140. package/drizzle/0288_attached_browser_reenrollment.sql +64 -0
  141. package/drizzle/0289_session_composer_policy_authority.sql +597 -0
  142. package/drizzle/0290_organization_membership_backfill.sql +268 -0
  143. package/drizzle/0291_resource_authority_classification_assertion.sql +371 -0
  144. package/drizzle/0292_truthful_tenancy_inventory_counters.sql +291 -0
  145. package/drizzle/0293_confirm_time_rule_rebaseline.sql +615 -0
  146. package/drizzle/0294_preference_activation_authority.sql +237 -0
  147. package/drizzle/0295_retire_legacy_standing_memory_mode.sql +476 -0
  148. package/drizzle/0296_force_rls_backfill_noop_repair.sql +215 -0
  149. package/drizzle/0297_session_ownership_classification_and_backfill.sql +752 -0
  150. package/drizzle/0298_organization_tenancy_parity.sql +609 -0
  151. package/drizzle/0299_organization_membership_lock_order.sql +291 -0
  152. package/drizzle/0300_tenancy_backfill_ledger.sql +459 -0
  153. package/drizzle/0301_session_snapshot_and_pin_visibility.sql +181 -0
  154. package/drizzle/0302_personal_workspace_session_ownership.sql +303 -0
  155. package/drizzle/0303_session_tenancy_product_activation.sql +919 -0
  156. package/drizzle/0304_personal_workspace_private_session_reads.sql +97 -0
  157. package/drizzle/0305_personal_resource_grant_management.sql +584 -0
  158. package/drizzle/0306_atomic_personal_resource_attachments.sql +1374 -0
  159. package/drizzle/0307_session_attention_state.sql +51 -0
  160. package/drizzle/0308_session_archives.sql +35 -0
  161. package/drizzle/0309_channel_project_pins.sql +6 -0
  162. package/drizzle/0310_channel_project_order.sql +27 -0
  163. package/drizzle/0311_company_scope_and_private_session_create.sql +656 -0
  164. package/drizzle/0312_quiescent_session_tree_deletion.sql +39 -0
  165. package/drizzle/0313_private_child_session_authority.sql +365 -0
  166. package/drizzle/0314_unregistered_organization_invitations.sql +606 -0
  167. package/drizzle/0315_personal_github_repository_selection.sql +624 -0
  168. package/drizzle/0316_human_confirmed_activation_resumed_generation.sql +869 -0
  169. package/drizzle/0317_session_goal_continuation_hold.sql +64 -0
  170. package/drizzle/0318_session_turn_startup_milestones.sql +115 -0
  171. package/drizzle/0319_event_triggered_automations.sql +254 -0
  172. package/drizzle/0320_pr_review_pack.sql +113 -0
  173. package/drizzle/0321_slack_bot_environment_display_name.sql +15 -0
  174. package/drizzle/0322_session_turns_unclaimed_prompt_trigger_index.sql +5 -0
  175. package/drizzle/0323_organization_private_session_enablement.sql +489 -0
  176. package/drizzle/0324_human_confirmed_company_profile_agent_admin.sql +856 -0
  177. package/drizzle/0325_child_lifecycle_notices.sql +44 -0
  178. package/drizzle/0326_interaction_operation_error_codes.sql +62 -0
  179. package/drizzle/0327_slack_first_task_hint.sql +29 -0
  180. package/drizzle/0328_session_background_commands.sql +590 -0
  181. package/drizzle/0329_slack_orchestration_delivery_events.sql +91 -0
  182. package/drizzle/0330_api_key_descriptions.sql +20 -0
  183. package/drizzle/0331_managed_organization_creation.sql +163 -0
  184. package/drizzle/0332_organization_shared_workspace_control_plane.sql +539 -0
  185. package/drizzle/0333_session_turn_prompt_routing.sql +45 -0
  186. package/drizzle/0334_connected_machine_workspace_root.sql +99 -0
  187. package/drizzle/0335_slack_workspace_routing.sql +460 -0
  188. package/drizzle/0336_atomic_session_fork_visibility.sql +667 -0
  189. package/drizzle/0337_slack_routed_action_handles.sql +189 -0
  190. package/drizzle/0338_atomic_connected_machine_attachments.sql +410 -0
  191. package/drizzle/0339_document_authority_reclassification.sql +1153 -0
  192. package/drizzle/0340_tenancy_backfill_activation_evidence.sql +1347 -0
  193. package/drizzle/0341_slack_routing_probe_organization_fence.sql +109 -0
  194. package/package.json +10 -6
  195. package/src/attached-browser-devices.ts +233 -5
  196. package/src/automations.ts +911 -0
  197. package/src/browser-sessions.ts +10 -0
  198. package/src/capability-integrations.ts +175 -1
  199. package/src/child-lifecycle-notices.ts +241 -0
  200. package/src/codemode-operations.ts +1 -35
  201. package/src/company-brain-context-selection-schema.ts +100 -0
  202. package/src/company-brain-context-selection.ts +359 -0
  203. package/src/company-brain-governed-writes.ts +1170 -0
  204. package/src/company-brain.ts +309 -0
  205. package/src/company-profile-agent-admin.ts +225 -0
  206. package/src/company-profile-schema.ts +121 -1
  207. package/src/company-profile.ts +21 -0
  208. package/src/computer-sessions.ts +10 -1
  209. package/src/connection-authority.ts +290 -0
  210. package/src/connection-scopes.ts +20 -0
  211. package/src/connection-tenancy-backfill.ts +81 -0
  212. package/src/connection-token-resolver.ts +263 -31
  213. package/src/database.ts +75 -2
  214. package/src/editable-artifact-durable-export.ts +27 -0
  215. package/src/editable-artifacts-schema.ts +10 -5
  216. package/src/editable-artifacts.ts +21 -11
  217. package/src/governed-learning-activation-schema.ts +121 -0
  218. package/src/governed-learning-activation.ts +588 -0
  219. package/src/governed-learning-evaluator-schema.ts +72 -0
  220. package/src/governed-learning-evaluator.ts +217 -0
  221. package/src/index.ts +12001 -1699
  222. package/src/insights.ts +107 -0
  223. package/src/integration-bindings.ts +88 -6
  224. package/src/integration-facets.ts +287 -84
  225. package/src/interaction-placement-loss.ts +234 -0
  226. package/src/knowledge-source-sync-schema.ts +83 -0
  227. package/src/knowledge-source-sync.ts +530 -0
  228. package/src/managed-human-provisioning.ts +116 -0
  229. package/src/memory-domain.ts +27 -32
  230. package/src/migrate.ts +77 -1
  231. package/src/new-session-drafts.ts +229 -35
  232. package/src/organization-membership-backfill.ts +735 -0
  233. package/src/organization-membership-lifecycle.ts +985 -0
  234. package/src/pr-review.ts +890 -0
  235. package/src/preference-registry.ts +31 -1
  236. package/src/provision-roles.ts +931 -24
  237. package/src/runtime-posture-cli.ts +2 -0
  238. package/src/runtime-posture.ts +1315 -52
  239. package/src/schema.ts +3336 -438
  240. package/src/scoped-knowledge-schema.ts +16 -8
  241. package/src/scoped-knowledge.ts +1 -1
  242. package/src/session-background-commands.ts +759 -0
  243. package/src/session-control.ts +640 -74
  244. package/src/session-goal-pacing.ts +126 -0
  245. package/src/session-queue-commands.ts +450 -98
  246. package/src/session-realtime-context.ts +19 -3
  247. package/src/session-realtime-ledger.ts +75 -12
  248. package/src/session-realtime-mirror.ts +1 -1
  249. package/src/session-tenancy.ts +403 -49
  250. package/src/session-tool-call-settlement.ts +38 -29
  251. package/src/slack-routing-personal-workspace.ts +67 -0
  252. package/src/slack-routing.ts +469 -0
  253. package/src/slack-task-policy-schema.ts +5 -0
  254. package/src/slack-task-policy.ts +18 -0
  255. package/src/slack-user-link-access.ts +17 -1
  256. package/src/task-notes-schema.ts +74 -0
  257. package/src/task-notes.ts +124 -2
  258. package/src/turn-initiator.ts +8 -0
  259. package/src/user-resource-authority.ts +377 -0
  260. package/src/workspace-authority.ts +160 -0
  261. package/src/workspace-instruction-policies-schema.ts +53 -1
  262. package/src/workspace-instruction-policies.ts +528 -77
  263. package/src/workspace-learning-policy.ts +21 -5
  264. package/src/workspace-membership-permissions.ts +9 -0
  265. package/dist/chunk-5KTIEDX7.js.map +0 -1
  266. package/dist/chunk-FPVAD4CO.js +0 -117
  267. package/dist/chunk-FPVAD4CO.js.map +0 -1
  268. package/dist/chunk-HSOWSYOX.js.map +0 -1
  269. package/dist/chunk-SK7YYHBI.js.map +0 -1
  270. package/dist/chunk-VKLB2ZGI.js +0 -2389
  271. package/dist/chunk-VKLB2ZGI.js.map +0 -1
  272. package/dist/chunk-Z7VYMNPZ.js.map +0 -1
  273. /package/dist/{chunk-GYO7ED2Q.js.map → chunk-EULAN2NP.js.map} +0 -0
  274. /package/dist/{chunk-VTPRIXKG.js.map → chunk-NJVZPWXY.js.map} +0 -0
@@ -44,18 +44,227 @@ const DEDICATED_ARTIFACT_CAPABILITY_ROUTINES = new Set<string>([
44
44
 
45
45
  const KNOWLEDGE_SOURCE_SYNC_LOCK_AUTHORITY_ROUTINE =
46
46
  "knowledge_source_sync_lock_authority(uuid, uuid, uuid)";
47
+ const GOOGLE_DRIVE_FILE_AUTHORIZATION_ROUTINE =
48
+ "google_drive_file_authorized(uuid, uuid, text, uuid)";
49
+ const GOOGLE_DRIVE_DOCUMENT_CITATION_ROUTINE =
50
+ "google_drive_document_citation(uuid, uuid, text, uuid, uuid)";
51
+ const GOOGLE_DRIVE_AUTHORITY_TABLES = [
52
+ "connections",
53
+ "files",
54
+ "google_drive_object_acl_evidence",
55
+ "google_drive_object_acl_principals",
56
+ "knowledge_document_versions",
57
+ "knowledge_providers",
58
+ "knowledge_source_objects",
59
+ "knowledge_source_sync_index_obligations",
60
+ "knowledge_source_sync_states",
61
+ "knowledge_sources",
62
+ ] as const;
47
63
  const KNOWLEDGE_SOURCE_SYNC_LOCK_AUTHORITY_TABLES = [
48
64
  "knowledge_sources",
49
65
  "knowledge_source_objects",
50
66
  ] as const;
51
67
  const MANAGED_HUMAN_PERSONAL_WORKSPACE_ROUTINE =
52
68
  "ensure_managed_human_personal_workspace(uuid, text, uuid)";
69
+ const ORGANIZATION_MEMBERSHIP_LIFECYCLE_ROUTINES = [
70
+ "list_self_organization_memberships(text)",
71
+ "list_self_organization_invitations(text)",
72
+ "list_self_organization_invitations(text, uuid, integer)",
73
+ "get_self_organization_invitation(text, uuid)",
74
+ "list_organization_invitations(uuid, text, uuid, integer)",
75
+ "list_organization_members(uuid, text)",
76
+ "get_organization_administration_overview(uuid, text)",
77
+ "create_managed_organization(text, text, text, uuid)",
78
+ "assert_organization_shared_workspace_administrator(uuid, uuid, text)",
79
+ "open_organization_shared_workspace_administration_capability(uuid, uuid, text)",
80
+ "close_organization_shared_workspace_administration_capability(uuid)",
81
+ "create_organization_shared_workspace(uuid, text, text, text, text, uuid)",
82
+ "upsert_organization_shared_workspace_member(uuid, uuid, text, uuid, text, text, jsonb, boolean)",
83
+ "update_organization_name(uuid, text, text, timestamp with time zone, uuid)",
84
+ "create_organization_invitation_v2(jsonb)",
85
+ "bind_pending_organization_invitations_for_verified_email(text, text)",
86
+ "has_pending_organization_invitation_for_subject(text)",
87
+ "accept_organization_invitation_v2(jsonb)",
88
+ "organization_membership_command(jsonb)",
89
+ "prepare_organization_membership_protocol_settlements(jsonb)",
90
+ "assert_active_managed_human_organization_membership(uuid, text)",
91
+ "resolve_workspace_writer_grant_identity(uuid, text)",
92
+ "prepare_workspace_membership_removal_settlements(jsonb)",
93
+ "workspace_membership_removal_command(jsonb)",
94
+ "get_organization_retention_policy(uuid, text)",
95
+ "preview_organization_retention_deletions(uuid, integer)",
96
+ "claim_organization_retention_deletion(uuid, uuid, uuid[])",
97
+ "list_organization_retention_deletion_objects(uuid, uuid, uuid, text, integer)",
98
+ "record_organization_retention_object_deleted(uuid, uuid, uuid, text, text, text, text)",
99
+ "fail_organization_retention_deletion(uuid, uuid, uuid, text)",
100
+ "finalize_organization_retention_deletion(uuid, uuid, uuid, text)",
101
+ "complete_organization_retention_deletion(uuid, uuid, uuid, text)",
102
+ ] as const;
103
+ const ORGANIZATION_MEMBERSHIP_LIFECYCLE_AUTHORITY_TABLES = [
104
+ "organization_invitation_binding_events",
105
+ "organization_membership_invitations",
106
+ "organization_membership_lifecycle_events",
107
+ "organization_membership_operation_receipts",
108
+ "organization_memberships",
109
+ "organization_profile_events",
110
+ "organization_shared_workspace_administration_capabilities",
111
+ "organization_user_resource_authorities",
112
+ "organization_user_resource_grants",
113
+ "organization_user_retention_deletion_events",
114
+ "organization_user_retention_deletions",
115
+ "organization_user_retention_object_deletion_receipts",
116
+ "organization_user_retention_object_obligations",
117
+ "organization_user_retention_policies",
118
+ ] as const;
119
+ const PRIVATE_SESSION_CREATE_POLICY_ROUTINE = "get_private_session_create_policy(uuid, uuid, text)";
120
+ const ORGANIZATION_PRIVATE_SESSION_SETTINGS_READ_ROUTINE =
121
+ "get_organization_private_session_settings(uuid, text)";
122
+ const ORGANIZATION_PRIVATE_SESSION_SETTINGS_UPDATE_ROUTINE =
123
+ "update_organization_private_session_settings(uuid, text, boolean, bigint, uuid)";
124
+ const ORGANIZATION_PRIVATE_SESSION_ROUTINE_AUTHORITY_TABLES = {
125
+ [PRIVATE_SESSION_CREATE_POLICY_ROUTINE]: [
126
+ "organization_memberships",
127
+ "organization_private_session_settings",
128
+ "session_tenancy_activations",
129
+ "workspace_memberships",
130
+ "workspaces",
131
+ ],
132
+ [ORGANIZATION_PRIVATE_SESSION_SETTINGS_READ_ROUTINE]: [
133
+ "managed_accounts",
134
+ "organization_memberships",
135
+ "organization_private_session_settings",
136
+ "session_tenancy_activations",
137
+ ],
138
+ [ORGANIZATION_PRIVATE_SESSION_SETTINGS_UPDATE_ROUTINE]: [
139
+ "managed_accounts",
140
+ "organization_memberships",
141
+ "organization_private_session_setting_events",
142
+ "organization_private_session_settings",
143
+ "session_tenancy_activations",
144
+ ],
145
+ } as const;
146
+ const ORGANIZATION_PRIVATE_SESSION_ROUTINES = Object.keys(
147
+ ORGANIZATION_PRIVATE_SESSION_ROUTINE_AUTHORITY_TABLES,
148
+ );
149
+ const ORGANIZATION_PRIVATE_SESSIONS_ENABLED_ROUTINE = "organization_private_sessions_enabled(uuid)";
150
+ const PREFERENCE_KNOWLEDGE_PROPOSAL_ROUTINE =
151
+ "preference_registry_create_knowledge_proposal_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid, text, uuid, text, text, text, text, integer, text, jsonb, timestamp with time zone, text)";
152
+ const PREFERENCE_KNOWLEDGE_PROPOSAL_AUTHORITY_TABLES = [
153
+ "company_brain_preference_proposal_receipts",
154
+ "knowledge_change_proposals",
155
+ "knowledge_claim_evidence",
156
+ "knowledge_claim_reviews",
157
+ "knowledge_claims",
158
+ "preference_registry_events",
159
+ "preference_registry_preferences",
160
+ "preference_registry_revisions",
161
+ "session_attempt_interruptions",
162
+ "session_turn_attempts",
163
+ "session_turns",
164
+ "sessions",
165
+ "workspaces",
166
+ ] as const;
53
167
  const MANAGED_HUMAN_PERSONAL_WORKSPACE_AUTHORITY_TABLES = [
54
168
  "organization_memberships",
55
169
  "organization_user_retention_policies",
56
170
  "organization_user_resource_authorities",
57
171
  "organization_user_resource_grants",
58
172
  ] as const;
173
+ const PERSONAL_RESOURCE_ATTEMPT_RESOLVER_ROUTINE =
174
+ "resolve_session_attempt_personal_resources(uuid, uuid, uuid)";
175
+ const USER_RESOURCE_LIFECYCLE_ROUTINES = [
176
+ "accept_turn_personal_resource_attachment(uuid, uuid, uuid, uuid, text, integer, boolean, integer)",
177
+ "list_self_user_resource_authorities(uuid, uuid, text, uuid, integer)",
178
+ "issue_self_user_resource_grant(uuid, uuid, uuid, text, text, text, uuid, integer, boolean)",
179
+ "revoke_self_user_resource_grant(uuid, uuid, uuid)",
180
+ "authorize_session_attempt_personal_resource_reads(uuid, uuid, uuid)",
181
+ ] as const;
182
+ const CONNECTION_AUTHORITY_ROUTINES = [
183
+ "resolve_personal_connection_authority_selection(uuid, uuid, text, uuid, jsonb)",
184
+ "resolve_accepted_connection_use(uuid, uuid, uuid, uuid, uuid, integer, uuid, text, text, uuid, text, text, text, text)",
185
+ "resolve_connection_use_authority(uuid, uuid, uuid, jsonb)",
186
+ ] as const;
187
+ const PERSONAL_GITHUB_REPOSITORY_AUTHORITY_ROUTINES = [
188
+ "get_self_personal_github_repository_selection(uuid, uuid, text, uuid)",
189
+ "mutate_self_personal_github_repository_selection(uuid, uuid, text, uuid, bigint, bigint, text, jsonb, boolean)",
190
+ ] as const;
191
+ const PERSONAL_GITHUB_REPOSITORY_AUTHORITY_TABLES = [
192
+ "personal_github_repository_selection_heads",
193
+ "personal_github_repository_selection_operations",
194
+ "personal_github_repository_selections",
195
+ ] as const;
196
+ const SCHEDULED_PERSONAL_RESOURCE_ROUTINES = [
197
+ "freeze_scheduled_task_personal_resources(uuid, uuid, uuid, bigint)",
198
+ "clone_scheduled_task_personal_resource_authority(uuid, uuid, uuid, bigint, bigint)",
199
+ "refresh_scheduled_task_personal_resources_clone_connections(uuid, uuid, uuid, bigint, bigint)",
200
+ "create_scheduled_agent_run_with_admission(uuid, uuid, uuid, uuid, bigint, text, text, text, timestamp with time zone, timestamp with time zone, jsonb)",
201
+ "materialize_scheduled_task_reusable_session_from_run(uuid, uuid, uuid, uuid, uuid, bigint, text)",
202
+ "scheduled_task_run_personal_resource_authority(uuid, uuid, uuid)",
203
+ "scheduled_task_run_connection_authority_subject(uuid, uuid, uuid)",
204
+ "scheduled_task_personal_resource_authority_subject(uuid, uuid, uuid, bigint)",
205
+ "record_scheduled_task_revision_authority(uuid, uuid, uuid, bigint)",
206
+ "clone_scheduled_task_revision_authority(uuid, uuid, uuid, bigint, bigint)",
207
+ "scheduled_task_revision_authority_subject(uuid, uuid, uuid, bigint)",
208
+ "scheduled_task_revision_authority_snapshot(uuid, uuid, uuid, bigint)",
209
+ "validate_scheduled_agent_run_live_authority(uuid, uuid, uuid)",
210
+ "scheduled_scoped_rig_version_metadata(uuid, uuid, text, uuid, uuid)",
211
+ "scheduled_variable_set_expected_generation_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid)",
212
+ "bind_scheduled_task_run_session(uuid, uuid, uuid, uuid)",
213
+ "transition_scheduled_agent_run(uuid, uuid, uuid, uuid, uuid, text, text)",
214
+ ] as const;
215
+ const PERSONAL_RESOURCE_CAPABILITY_PREDICATE_ROUTINE =
216
+ "personal_resource_delegation_capability_active(text)";
217
+ const PERSONAL_RESOURCE_CAPABILITY_TABLE = "personal_resource_delegation_capabilities";
218
+ const SCHEDULED_PERSONAL_RESOURCE_CAPABILITY_PREDICATE_ROUTINE =
219
+ "scheduled_personal_resource_capability_active(text)";
220
+ const SCHEDULED_PERSONAL_RESOURCE_CAPABILITY_TABLE = "scheduled_personal_resource_capabilities";
221
+ const VARIABLE_SET_CAPABILITY_PREDICATE_ROUTINE = "variable_set_authority_capability_active(text)";
222
+ const VARIABLE_SET_CAPABILITY_TABLE = "variable_set_authority_capabilities";
223
+ const PERSONAL_DOCUMENT_CAPABILITY_PREDICATE_ROUTINE =
224
+ "personal_document_authority_capability_active(text)";
225
+ const PERSONAL_DOCUMENT_CAPABILITY_TABLE = "personal_document_authority_capabilities";
226
+ const PERSONAL_DOCUMENT_AUTHORITY_ROUTINES = [
227
+ "create_personal_document_authority(uuid, uuid, uuid)",
228
+ "resolve_document_original_file(uuid, uuid, text, uuid)",
229
+ "resolve_session_attempt_personal_document_reads(uuid, uuid, uuid, uuid)",
230
+ ] as const;
231
+ const DOCUMENT_MIGRATION_CAPABILITY_PREDICATE_ROUTINE =
232
+ "document_migration_capability_active(text)";
233
+ const DOCUMENT_MIGRATION_CAPABILITY_TABLE = "document_migration_capabilities";
234
+ const DOCUMENT_MIGRATION_AUTHORITY_ROUTINES = [
235
+ "list_document_authority_reclassifications(uuid, uuid, text, uuid, integer, timestamp with time zone, uuid)",
236
+ "reclassify_document_authority(jsonb)",
237
+ "run_document_default_collection_backfill(jsonb)",
238
+ ] as const;
239
+ const VARIABLE_SET_AUTHORITY_ROUTINES = [
240
+ "create_scoped_variable_set(uuid, uuid, text, text, text, jsonb, boolean)",
241
+ "list_scoped_variable_sets(uuid, uuid, uuid, text, text)",
242
+ "count_scoped_variable_sets(uuid, uuid, text)",
243
+ "mutate_scoped_variable_set(uuid, uuid, uuid, text, text, boolean, text, boolean, text, text, boolean)",
244
+ "read_scoped_variable_set_secret(uuid, uuid, uuid, text, text, text, uuid, uuid, uuid, integer)",
245
+ "materialize_scoped_variable_set_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid)",
246
+ "materialize_scoped_variable_set_for_session(uuid, uuid, uuid, uuid)",
247
+ ] as const;
248
+ const SCOPED_COMPUTE_CAPABILITY_PREDICATE_ROUTINE = "scoped_compute_capability_active(text)";
249
+ const SCOPED_COMPUTE_CAPABILITY_TABLE = "scoped_compute_capabilities";
250
+ const CONNECTION_TENANCY_BACKFILL_CAPABILITY_TABLE = "connection_tenancy_backfill_capabilities";
251
+ const CONNECTION_TENANCY_BACKFILL_CAPABILITY_PREDICATE_ROUTINE =
252
+ "connection_tenancy_backfill_capability_active(uuid)";
253
+ const SCOPED_COMPUTE_AUTHORITY_ROUTINES = [
254
+ "create_scoped_rig(uuid, uuid, text, text, text, text, jsonb, boolean)",
255
+ "list_scoped_rigs(uuid, uuid, uuid, text, text)",
256
+ "count_scoped_rigs(uuid, uuid, text)",
257
+ "mutate_scoped_rig(uuid, uuid, uuid, text, text, boolean, text, boolean, boolean)",
258
+ "finalize_scoped_enrollment(uuid, uuid, text, text, boolean, boolean, text, text, text, boolean)",
259
+ "list_scoped_enrollments(uuid, uuid, uuid, text)",
260
+ "get_scoped_sandbox(uuid, uuid, uuid)",
261
+ "authorize_scoped_sandbox_attach(uuid, uuid, uuid)",
262
+ "materialize_scoped_rig_version_for_attempt(uuid, uuid, uuid, uuid, uuid, integer)",
263
+ "authorize_session_attempt_personal_machine(uuid, uuid, uuid, uuid, uuid, integer, uuid)",
264
+ "assert_session_attempt_personal_machine(uuid, uuid, uuid, uuid, uuid, integer, uuid, boolean)",
265
+ "list_scoped_machine_dependent_sessions(uuid, uuid, uuid)",
266
+ "detach_scoped_machine_dependent_sessions(uuid, uuid, uuid)",
267
+ ] as const;
59
268
  const CANONICAL_HUMAN_IDENTITY_ROUTINES = [
60
269
  "ensure_canonical_human_identity(text, text)",
61
270
  "validate_canonical_human_session(text, text, boolean)",
@@ -75,17 +284,130 @@ const TASK_NOTE_CAPABILITY_ROUTINES = [
75
284
  "create_task_note_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid, text, text, integer)",
76
285
  "archive_task_note_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid, uuid, integer, text)",
77
286
  "list_task_notes_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, boolean, integer)",
287
+ "replace_task_note_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid, uuid, uuid, uuid, integer, text, text, integer, text)",
288
+ "resolve_task_note_knowledge_promotion_source(uuid, uuid, uuid, uuid, uuid, integer, uuid, integer, text, text, text)",
289
+ ] as const;
290
+ const COMPANY_BRAIN_CONTEXT_SELECTION_ROUTINE =
291
+ "company_brain_context_get_or_create_selection(uuid, uuid, uuid, uuid, uuid, integer)";
292
+ const COMPANY_BRAIN_CONTEXT_INSPECTION_ROUTINE =
293
+ "company_brain_inspect_context_receipts(uuid, uuid, text, uuid, timestamp with time zone, uuid, integer)";
294
+ const GOVERNED_LEARNING_EVALUATION_ROUTINE =
295
+ "evaluate_governed_learning_proposal(uuid, uuid, uuid, uuid, uuid, integer, uuid, uuid, uuid, uuid, uuid)";
296
+ const GOVERNED_LEARNING_ACTIVATION_ROUTINES = [
297
+ "activate_governed_learning_decision(uuid, uuid, uuid, uuid)",
298
+ "activate_human_confirmed_learning_decision(uuid, uuid, uuid, uuid, uuid)",
299
+ "confirm_remember_knowledge_claim(uuid, uuid, uuid, uuid, integer, uuid, uuid, uuid)",
300
+ "undo_governed_learning_activation(uuid, uuid, uuid, uuid)",
301
+ ] as const;
302
+ const GOVERNED_LEARNING_INSPECTION_ROUTINES = [
303
+ "inspect_governed_learning_decisions(uuid, uuid, text, integer)",
304
+ "inspect_governed_learning_activations(uuid, uuid, text, integer)",
305
+ "inspect_governed_learning_activation_undos(uuid, uuid, text, integer)",
306
+ ] as const;
307
+ const GOVERNED_LEARNING_INSPECTION_AUTHORITY_TABLES = [
308
+ "governed_learning_decision_receipts",
309
+ "governed_learning_activation_receipts",
310
+ "governed_learning_activation_undo_receipts",
311
+ "sessions",
312
+ ] as const;
313
+ const COMPANY_PROFILE_AGENT_ADMIN_ROUTINES = [
314
+ "propose_company_profile_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid, text, text, text)",
315
+ "confirm_company_profile_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid, uuid, uuid)",
316
+ ] as const;
317
+ const COMPANY_PROFILE_AGENT_ADMIN_AUTHORITY_TABLES = [
318
+ "company_profile_activation_events",
319
+ "company_profile_agent_confirmation_receipts",
320
+ "company_profile_agent_proposal_receipts",
321
+ "company_profile_heads",
322
+ "company_profile_revisions",
323
+ "managed_accounts",
324
+ "organization_memberships",
325
+ "session_human_input_requests",
326
+ "session_turn_attempts",
327
+ "session_turns",
328
+ "sessions",
329
+ "workspaces",
330
+ ] as const;
331
+ const GOVERNED_LEARNING_EVALUATION_AUTHORITY_TABLES = [
332
+ "document_chunks",
333
+ "documents",
334
+ "governed_learning_decision_receipts",
335
+ "knowledge_change_proposals",
336
+ "knowledge_claim_evidence",
337
+ "knowledge_claim_relations",
338
+ "knowledge_claim_reviews",
339
+ "knowledge_claims",
340
+ "knowledge_document_versions",
341
+ "knowledge_providers",
342
+ "knowledge_source_acl_versions",
343
+ "knowledge_source_objects",
344
+ "knowledge_sources",
345
+ "session_attempt_interruptions",
346
+ "session_turn_attempts",
347
+ "session_turns",
348
+ "sessions",
349
+ "task_notes",
350
+ "workspace_learning_policy_snapshots",
351
+ "workspaces",
352
+ ] as const;
353
+ const GOVERNED_LEARNING_ACTIVATION_AUTHORITY_TABLES = [
354
+ ...GOVERNED_LEARNING_EVALUATION_AUTHORITY_TABLES,
355
+ "company_brain_preference_proposal_receipts",
356
+ "governed_learning_activation_receipts",
357
+ "governed_learning_activation_undo_receipts",
358
+ "preference_registry_events",
359
+ "preference_registry_preferences",
360
+ "preference_registry_revisions",
361
+ "remember_knowledge_confirmation_receipts",
362
+ "session_human_input_requests",
363
+ "workspace_instruction_policy_activation_events",
364
+ "workspace_instruction_policy_deactivation_events",
365
+ "workspace_instruction_policy_heads",
366
+ "workspace_instruction_policy_onboarding_proposals",
367
+ "workspace_instruction_policy_revisions",
368
+ "workspace_learning_policy_heads",
369
+ "workspace_learning_policy_revisions",
78
370
  ] as const;
79
371
  const TRANSITION_SESSION_VISIBILITY_ROUTINE =
80
- "transition_session_visibility(uuid, uuid, uuid, text, text, integer, text, text)";
372
+ "transition_session_visibility(uuid, uuid, uuid, text, text, integer, text, text, integer)";
373
+ const LEGACY_FORK_SESSION_CONTENT_ROUTINE =
374
+ "fork_session_content(uuid, uuid, uuid, text, uuid, text, text, text, integer)";
81
375
  const FORK_SESSION_CONTENT_ROUTINE =
82
- "fork_session_content(uuid, uuid, uuid, text, uuid, text, text, text)";
376
+ "fork_session_content(uuid, uuid, uuid, text, uuid, text, boolean, text, text, integer)";
377
+ const REPLAY_APPLIED_SESSION_FORK_ROUTINE =
378
+ "replay_applied_session_fork(uuid, uuid, uuid, text, uuid, text, boolean, text, text, integer)";
379
+ const SESSION_TENANCY_ACTIVATED_ROUTINE = "session_tenancy_product_activated(uuid, integer)";
380
+ const SESSION_TENANCY_ANY_ACTIVATION_ROUTINE = "session_tenancy_any_product_activation()";
381
+ const SESSION_TENANCY_QUIESCENCE_ROUTINE =
382
+ "assert_session_tenancy_quiescent(uuid, uuid, uuid, boolean)";
383
+ const TENANCY_BACKFILL_ACTIVATION_EVIDENCE_ROUTINE =
384
+ "check_tenancy_backfill_activation_evidence(uuid)";
385
+ const SESSION_VISIBILITY_LIFECYCLE_CAPABILITY_ROUTINE =
386
+ "session_visibility_lifecycle_capability_held()";
387
+ const PRIVATE_SESSION_CREATE_CAPABILITY_ROUTINES = [
388
+ "open_private_session_create_capability(uuid, uuid, uuid, text)",
389
+ "open_private_child_session_create_capability(uuid, uuid, uuid, uuid, uuid, uuid, integer)",
390
+ "close_private_session_create_capability(uuid)",
391
+ ] as const;
83
392
  const SESSION_AUTHORITY_ROUTINES = new Set<string>([
393
+ LEGACY_FORK_SESSION_CONTENT_ROUTINE,
84
394
  FORK_SESSION_CONTENT_ROUTINE,
395
+ REPLAY_APPLIED_SESSION_FORK_ROUTINE,
396
+ SESSION_TENANCY_ACTIVATED_ROUTINE,
397
+ SESSION_TENANCY_ANY_ACTIVATION_ROUTINE,
398
+ SESSION_TENANCY_QUIESCENCE_ROUTINE,
399
+ PERSONAL_RESOURCE_ATTEMPT_RESOLVER_ROUTINE,
400
+ ...USER_RESOURCE_LIFECYCLE_ROUTINES,
401
+ ...CONNECTION_AUTHORITY_ROUTINES,
402
+ ...SCHEDULED_PERSONAL_RESOURCE_ROUTINES,
85
403
  SESSION_PRIVATE_ACTOR_VISIBLE_ROUTINE,
86
404
  SESSION_REFERENCE_VISIBLE_ROUTINE,
405
+ SESSION_VISIBILITY_LIFECYCLE_CAPABILITY_ROUTINE,
406
+ ...PRIVATE_SESSION_CREATE_CAPABILITY_ROUTINES,
87
407
  TRANSITION_SESSION_VISIBILITY_ROUTINE,
88
408
  ...TASK_NOTE_CAPABILITY_ROUTINES,
409
+ COMPANY_BRAIN_CONTEXT_SELECTION_ROUTINE,
410
+ COMPANY_BRAIN_CONTEXT_INSPECTION_ROUTINE,
89
411
  ]);
90
412
  const XAI_CREATE_CREDENTIAL_ROUTINE =
91
413
  "create_xai_subscription_credential(uuid, uuid, text, text, text, text, text, text, text, timestamp with time zone)";
@@ -106,15 +428,42 @@ const XAI_AUTHORITY_TABLES = [
106
428
  ] as const;
107
429
 
108
430
  export const RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES = [
431
+ COMPANY_BRAIN_CONTEXT_INSPECTION_ROUTINE,
432
+ COMPANY_BRAIN_CONTEXT_SELECTION_ROUTINE,
433
+ ...COMPANY_PROFILE_AGENT_ADMIN_ROUTINES,
434
+ GOVERNED_LEARNING_EVALUATION_ROUTINE,
435
+ ...GOVERNED_LEARNING_ACTIVATION_ROUTINES,
436
+ ...GOVERNED_LEARNING_INSPECTION_ROUTINES,
109
437
  FORK_SESSION_CONTENT_ROUTINE,
438
+ LEGACY_FORK_SESSION_CONTENT_ROUTINE,
439
+ REPLAY_APPLIED_SESSION_FORK_ROUTINE,
440
+ SESSION_TENANCY_ACTIVATED_ROUTINE,
441
+ SESSION_TENANCY_ANY_ACTIVATION_ROUTINE,
110
442
  XAI_AUTHORITY_LIVE_ROUTINE,
111
443
  XAI_CREATE_CREDENTIAL_ROUTINE,
112
444
  XAI_DISCONNECT_CREDENTIAL_ROUTINE,
445
+ GOOGLE_DRIVE_DOCUMENT_CITATION_ROUTINE,
446
+ GOOGLE_DRIVE_FILE_AUTHORIZATION_ROUTINE,
113
447
  KNOWLEDGE_SOURCE_SYNC_LOCK_AUTHORITY_ROUTINE,
114
448
  MANAGED_HUMAN_PERSONAL_WORKSPACE_ROUTINE,
449
+ ...ORGANIZATION_MEMBERSHIP_LIFECYCLE_ROUTINES,
450
+ ...ORGANIZATION_PRIVATE_SESSION_ROUTINES,
451
+ ...PRIVATE_SESSION_CREATE_CAPABILITY_ROUTINES,
452
+ PERSONAL_RESOURCE_ATTEMPT_RESOLVER_ROUTINE,
453
+ ...USER_RESOURCE_LIFECYCLE_ROUTINES,
454
+ PREFERENCE_KNOWLEDGE_PROPOSAL_ROUTINE,
455
+ ...VARIABLE_SET_AUTHORITY_ROUTINES,
456
+ ...CONNECTION_AUTHORITY_ROUTINES,
457
+ ...PERSONAL_GITHUB_REPOSITORY_AUTHORITY_ROUTINES,
458
+ ...PERSONAL_DOCUMENT_AUTHORITY_ROUTINES,
459
+ ...DOCUMENT_MIGRATION_AUTHORITY_ROUTINES,
460
+ ...SCOPED_COMPUTE_AUTHORITY_ROUTINES,
461
+ ...SCHEDULED_PERSONAL_RESOURCE_ROUTINES,
115
462
  ...CANONICAL_HUMAN_IDENTITY_ROUTINES,
463
+ ...TASK_NOTE_CAPABILITY_ROUTINES,
116
464
  SESSION_PRIVATE_ACTOR_VISIBLE_ROUTINE,
117
465
  SESSION_REFERENCE_VISIBLE_ROUTINE,
466
+ SESSION_VISIBILITY_LIFECYCLE_CAPABILITY_ROUTINE,
118
467
  TRANSITION_SESSION_VISIBILITY_ROUTINE,
119
468
  XAI_POOL_VISIBLE_ROUTINE,
120
469
  XAI_RESOLVE_POOL_ROUTINE,
@@ -122,6 +471,13 @@ export const RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES = [
122
471
  XAI_SNAPSHOT_VALIDATOR_ROUTINE,
123
472
  ] as const;
124
473
 
474
+ /** Owner-internal helpers that must exist but must never be callable by the runtime role. */
475
+ export const RUNTIME_TARGET_SCHEMA_FORBIDDEN_ROUTINES = [
476
+ ORGANIZATION_PRIVATE_SESSIONS_ENABLED_ROUTINE,
477
+ SESSION_TENANCY_QUIESCENCE_ROUTINE,
478
+ TENANCY_BACKFILL_ACTIVATION_EVIDENCE_ROUTINE,
479
+ ] as const;
480
+
125
481
  export const RUNTIME_TARGET_SCHEMA_INVOKER_ROUTINES = [
126
482
  SESSION_REFERENCE_VISIBLE_ROUTINE,
127
483
  XAI_SNAPSHOT_VALIDATOR_ROUTINE,
@@ -142,6 +498,12 @@ export const FORCE_RLS_TABLES = [
142
498
  "attached_browser_inventories",
143
499
  "audit_events",
144
500
  "auth_runs",
501
+ "automation_run_event_links",
502
+ "automation_runs",
503
+ "automation_sources",
504
+ "automation_trigger_events",
505
+ "automation_trigger_revisions",
506
+ "automation_triggers",
145
507
  "billing_customers",
146
508
  "browser_identities",
147
509
  "browser_revision_components",
@@ -175,7 +537,12 @@ export const FORCE_RLS_TABLES = [
175
537
  "codex_reset_redemption_attempts",
176
538
  "codex_rotation_settings",
177
539
  "codex_subscription_credentials",
540
+ "company_brain_context_selection_receipts",
541
+ "company_brain_preference_proposal_receipts",
542
+ "company_brain_turn_context_snapshots",
178
543
  "company_profile_activation_events",
544
+ "company_profile_agent_confirmation_receipts",
545
+ "company_profile_agent_proposal_receipts",
179
546
  "company_profile_heads",
180
547
  "company_profile_revisions",
181
548
  "company_profile_snapshots",
@@ -183,13 +550,19 @@ export const FORCE_RLS_TABLES = [
183
550
  "computer_session_associations",
184
551
  "computer_sessions",
185
552
  "connection_disconnect_operations",
553
+ "connection_use_audit_facts",
554
+ "connection_use_once_consumption_receipts",
186
555
  "connections",
187
556
  "connector_action_policies",
188
557
  "connector_action_requests",
189
558
  "credit_ledger_entries",
190
559
  "device_enrollment_requests",
560
+ "document_authority_reclassifications",
191
561
  "document_bases",
192
562
  "document_chunks",
563
+ "document_default_collection_backfill_operations",
564
+ "document_default_collection_backfill_receipts",
565
+ "document_default_collection_backfill_runs",
193
566
  "documents",
194
567
  "editable_artifact_blob_refs",
195
568
  "editable_artifact_idempotency_receipts",
@@ -214,6 +587,11 @@ export const FORCE_RLS_TABLES = [
214
587
  "generated_video_artifacts",
215
588
  "github_installation_repositories",
216
589
  "github_installations",
590
+ "google_drive_object_acl_evidence",
591
+ "google_drive_object_acl_principals",
592
+ "governed_learning_activation_receipts",
593
+ "governed_learning_activation_undo_receipts",
594
+ "governed_learning_decision_receipts",
217
595
  "host_export_config",
218
596
  "host_export_consumers",
219
597
  "host_export_cursor_state",
@@ -263,16 +641,37 @@ export const FORCE_RLS_TABLES = [
263
641
  "model_call_facts",
264
642
  "network_routes",
265
643
  "new_session_drafts",
644
+ "organization_invitation_binding_events",
645
+ "organization_membership_invitations",
646
+ "organization_membership_lifecycle_events",
647
+ "organization_membership_operation_receipts",
266
648
  "organization_memberships",
649
+ "organization_private_session_setting_events",
650
+ "organization_private_session_settings",
651
+ "organization_profile_events",
652
+ "organization_shared_workspace_administration_capabilities",
267
653
  "organization_user_resource_authorities",
268
654
  "organization_user_resource_grants",
655
+ "organization_user_retention_deletion_events",
656
+ "organization_user_retention_deletions",
657
+ "organization_user_retention_object_deletion_receipts",
658
+ "organization_user_retention_object_obligations",
269
659
  "organization_user_retention_policies",
270
660
  "pack_installation_components",
271
661
  "pack_installations",
662
+ "personal_document_once_consumption_receipts",
663
+ "personal_github_repository_selection_heads",
664
+ "personal_github_repository_selection_operations",
665
+ "personal_github_repository_selections",
666
+ "personal_resource_once_consumption_receipts",
667
+ "pr_review_app_registrations",
668
+ "pr_review_repository_bindings",
272
669
  "preference_registry_events",
273
670
  "preference_registry_preferences",
274
671
  "preference_registry_revisions",
275
672
  "preference_registry_snapshots",
673
+ "private_session_create_capabilities",
674
+ "remember_knowledge_confirmation_receipts",
276
675
  "retained_screenshot_artifacts",
277
676
  "rig_changes",
278
677
  "rig_versions",
@@ -285,11 +684,26 @@ export const FORCE_RLS_TABLES = [
285
684
  "sandbox_session_envelopes",
286
685
  "sandbox_workspace_mutation_admissions",
287
686
  "sandboxes",
687
+ "scheduled_task_connection_authority_snapshots",
688
+ "scheduled_task_personal_resource_authorities",
689
+ "scheduled_task_personal_resource_snapshots",
690
+ "scheduled_task_reusable_connection_materializations",
691
+ "scheduled_task_revision_authorities",
692
+ "scheduled_task_run_connection_authority_snapshots",
693
+ "scheduled_task_run_personal_resource_admissions",
694
+ "scheduled_task_run_personal_resource_once_receipts",
695
+ "scheduled_task_run_personal_resource_snapshots",
288
696
  "scheduled_task_runs",
289
697
  "scheduled_tasks",
290
698
  "session_attempt_codemode_calls",
699
+ "session_attempt_connected_machine_authorizations",
291
700
  "session_attempt_interruptions",
701
+ "session_attempt_personal_document_admissions",
702
+ "session_attempt_personal_document_snapshots",
703
+ "session_attempt_personal_resource_admissions",
704
+ "session_attempt_personal_resource_snapshots",
292
705
  "session_attempt_tool_catalogs",
706
+ "session_background_commands",
293
707
  "session_command_receipts",
294
708
  "session_events",
295
709
  "session_goal_revisions",
@@ -309,37 +723,52 @@ export const FORCE_RLS_TABLES = [
309
723
  "session_stream_acknowledgments",
310
724
  "session_system_update_outbox",
311
725
  "session_system_updates",
726
+ "session_tenancy_activations",
312
727
  "session_turn_attempts",
728
+ "session_turn_startup_milestones",
313
729
  "session_turns",
314
730
  "session_visibility_write_capabilities",
315
731
  "session_workflow_wake_outbox",
316
732
  "sessions",
317
733
  "site_auth_connections",
734
+ "slack_app_home_refreshes",
318
735
  "slack_bot_delete_operations",
319
736
  "slack_bot_post_operations",
320
737
  "slack_bot_update_operations",
321
738
  "slack_bot_user_links",
739
+ "slack_channel_routes",
322
740
  "slack_installation_bindings",
323
741
  "slack_interaction_action_handles",
324
742
  "slack_interaction_inbox",
325
743
  "slack_interaction_progress_deliveries",
326
744
  "slack_interactions",
745
+ "slack_route_prompt_options",
746
+ "slack_route_prompts",
327
747
  "slack_shared_task_origins",
328
748
  "slack_task_policy_activation_events",
329
749
  "slack_task_policy_heads",
330
750
  "slack_task_policy_revisions",
751
+ "slack_user_dm_routes",
331
752
  "slack_user_link_access_request_operations",
332
753
  "slack_user_link_access_requests",
333
754
  "social_connections",
334
755
  "social_posts",
335
756
  "task_note_events",
757
+ "task_note_knowledge_promotion_capabilities",
758
+ "task_note_replacement_receipts",
336
759
  "task_note_write_capabilities",
337
760
  "task_notes",
338
761
  "temporal_schedule_cleanup_outbox",
762
+ "tenancy_backfill_receipts",
763
+ "tenancy_backfill_unresolved_rows",
339
764
  "transcription_recording_chunks",
340
765
  "transcription_recording_objects",
341
766
  "transcription_recording_segments",
342
767
  "transcription_recordings",
768
+ "turn_connection_authority_snapshots",
769
+ "turn_personal_resource_attachment_receipts",
770
+ "turn_personal_resource_once_receipts",
771
+ "turn_personal_resource_snapshots",
343
772
  "usage_events",
344
773
  "video_generation_operations",
345
774
  "video_generation_references",
@@ -350,6 +779,7 @@ export const FORCE_RLS_TABLES = [
350
779
  "workspace_control_events",
351
780
  "workspace_inference_controls",
352
781
  "workspace_instruction_policy_activation_events",
782
+ "workspace_instruction_policy_deactivation_events",
353
783
  "workspace_instruction_policy_heads",
354
784
  "workspace_instruction_policy_onboarding_proposals",
355
785
  "workspace_instruction_policy_revisions",
@@ -385,6 +815,7 @@ export const NON_RLS_RUNTIME_TABLES = [
385
815
  "auth_sessions",
386
816
  "auth_users",
387
817
  "auth_verifications",
818
+ "automation_webhook_endpoints",
388
819
  "integration_oauth_clients",
389
820
  "managed_accounts",
390
821
  "nested_agent_depth_configuration",
@@ -407,6 +838,13 @@ export const RUNTIME_FULL_DML_TABLES = [
407
838
  "auth_sessions",
408
839
  "auth_users",
409
840
  "auth_verifications",
841
+ "automation_run_event_links",
842
+ "automation_runs",
843
+ "automation_sources",
844
+ "automation_trigger_events",
845
+ "automation_trigger_revisions",
846
+ "automation_triggers",
847
+ "automation_webhook_endpoints",
410
848
  "billing_customers",
411
849
  "browser_session_associations",
412
850
  "capability_catalog_items",
@@ -464,6 +902,8 @@ export const RUNTIME_FULL_DML_TABLES = [
464
902
  "new_session_drafts",
465
903
  "pack_installation_components",
466
904
  "pack_installations",
905
+ "pr_review_app_registrations",
906
+ "pr_review_repository_bindings",
467
907
  "retained_screenshot_artifacts",
468
908
  "rig_changes",
469
909
  "rig_versions",
@@ -476,9 +916,8 @@ export const RUNTIME_FULL_DML_TABLES = [
476
916
  "sandbox_session_envelopes",
477
917
  "sandbox_workspace_mutation_admissions",
478
918
  "sandboxes",
479
- "scheduled_task_runs",
480
- "scheduled_tasks",
481
919
  "session_attempt_interruptions",
920
+ "session_background_commands",
482
921
  "session_command_receipts",
483
922
  "session_events",
484
923
  "session_goals",
@@ -500,14 +939,19 @@ export const RUNTIME_FULL_DML_TABLES = [
500
939
  "session_turns",
501
940
  "session_workflow_wake_outbox",
502
941
  "sessions",
942
+ "slack_app_home_refreshes",
503
943
  "slack_bot_delete_operations",
504
944
  "slack_bot_post_operations",
505
945
  "slack_bot_update_operations",
506
946
  "slack_bot_user_links",
947
+ "slack_channel_routes",
507
948
  "slack_interaction_action_handles",
508
949
  "slack_interaction_inbox",
509
950
  "slack_interaction_progress_deliveries",
510
951
  "slack_interactions",
952
+ "slack_route_prompt_options",
953
+ "slack_route_prompts",
954
+ "slack_user_dm_routes",
511
955
  "social_connections",
512
956
  "social_posts",
513
957
  "stripe_webhook_events",
@@ -527,8 +971,6 @@ export const RUNTIME_FULL_DML_TABLES = [
527
971
  "workspace_model_policies",
528
972
  "workspace_packs",
529
973
  "workspace_screenshot_quotas",
530
- "workspace_variable_set_variables",
531
- "workspace_variable_sets",
532
974
  "workspace_video_generation_policies",
533
975
  "workspace_video_generation_quotas",
534
976
  "workspaces",
@@ -544,16 +986,19 @@ export const RUNTIME_READ_ONLY_TABLES = [
544
986
  "company_profile_activation_events",
545
987
  "company_profile_heads",
546
988
  "company_profile_snapshots",
989
+ "document_authority_reclassifications",
547
990
  "knowledge_lifecycle_events",
548
991
  "knowledge_memory_lifecycle_events",
549
992
  "knowledge_memory_relationships",
550
993
  "nested_agent_depth_configuration",
551
994
  "preference_registry_events",
552
995
  "preference_registry_snapshots",
996
+ "session_tenancy_activations",
553
997
  "slack_installation_bindings",
554
998
  "slack_task_policy_activation_events",
555
999
  "slack_task_policy_heads",
556
1000
  "slack_task_policy_revisions",
1001
+ "workspace_instruction_policy_deactivation_events",
557
1002
  "workspace_instruction_policy_snapshots",
558
1003
  "workspace_learning_policy_activation_events",
559
1004
  "workspace_learning_policy_heads",
@@ -579,6 +1024,8 @@ export const RUNTIME_READ_INSERT_TABLES = [
579
1024
  "editable_artifact_transactions",
580
1025
  "editable_artifact_undo_claims",
581
1026
  "editable_artifact_versions",
1027
+ "google_drive_object_acl_evidence",
1028
+ "google_drive_object_acl_principals",
582
1029
  "knowledge_change_proposals",
583
1030
  "knowledge_claim_evidence",
584
1031
  "knowledge_claim_relations",
@@ -637,7 +1084,10 @@ export const RUNTIME_READ_INSERT_UPDATE_TABLES = [
637
1084
  "interaction_operations",
638
1085
  "interaction_resource_operations",
639
1086
  "network_routes",
1087
+ "scheduled_task_runs",
1088
+ "scheduled_tasks",
640
1089
  "session_attempt_codemode_calls",
1090
+ "session_turn_startup_milestones",
641
1091
  "site_auth_connections",
642
1092
  "slack_user_link_access_requests",
643
1093
  "workspace_interaction_revisions",
@@ -652,21 +1102,77 @@ export const PROTECTED_NO_DIRECT_DML_TABLES = [
652
1102
  "canonical_human_identity_operations",
653
1103
  "canonical_human_identity_subjects",
654
1104
  "canonical_human_login_bindings",
1105
+ "company_brain_context_selection_receipts",
1106
+ "company_brain_preference_proposal_receipts",
1107
+ "company_brain_turn_context_snapshots",
1108
+ "company_profile_agent_confirmation_receipts",
1109
+ "company_profile_agent_proposal_receipts",
1110
+ "connection_use_audit_facts",
1111
+ "connection_use_once_consumption_receipts",
1112
+ "document_default_collection_backfill_operations",
1113
+ "document_default_collection_backfill_receipts",
1114
+ "document_default_collection_backfill_runs",
655
1115
  "editable_artifact_live_tickets",
656
1116
  "editable_artifact_scope_authorization_heads",
1117
+ "governed_learning_activation_receipts",
1118
+ "governed_learning_activation_undo_receipts",
1119
+ "governed_learning_decision_receipts",
657
1120
  "host_export_config",
658
1121
  "host_export_consumers",
659
1122
  "host_export_cursor_state",
660
1123
  "host_export_dead_letters",
661
1124
  "host_export_outbox",
1125
+ "organization_invitation_binding_events",
1126
+ "organization_membership_invitations",
1127
+ "organization_membership_lifecycle_events",
1128
+ "organization_membership_operation_receipts",
662
1129
  "organization_memberships",
1130
+ "organization_private_session_setting_events",
1131
+ "organization_private_session_settings",
1132
+ "organization_profile_events",
1133
+ "organization_shared_workspace_administration_capabilities",
663
1134
  "organization_user_resource_authorities",
664
1135
  "organization_user_resource_grants",
1136
+ "organization_user_retention_deletion_events",
1137
+ "organization_user_retention_deletions",
1138
+ "organization_user_retention_object_deletion_receipts",
1139
+ "organization_user_retention_object_obligations",
665
1140
  "organization_user_retention_policies",
1141
+ "personal_document_once_consumption_receipts",
1142
+ "personal_github_repository_selection_heads",
1143
+ "personal_github_repository_selection_operations",
1144
+ "personal_github_repository_selections",
1145
+ "personal_resource_once_consumption_receipts",
1146
+ "private_session_create_capabilities",
1147
+ "remember_knowledge_confirmation_receipts",
1148
+ "scheduled_task_connection_authority_snapshots",
1149
+ "scheduled_task_personal_resource_authorities",
1150
+ "scheduled_task_personal_resource_snapshots",
1151
+ "scheduled_task_reusable_connection_materializations",
1152
+ "scheduled_task_revision_authorities",
1153
+ "scheduled_task_run_connection_authority_snapshots",
1154
+ "scheduled_task_run_personal_resource_admissions",
1155
+ "scheduled_task_run_personal_resource_once_receipts",
1156
+ "scheduled_task_run_personal_resource_snapshots",
1157
+ "session_attempt_connected_machine_authorizations",
1158
+ "session_attempt_personal_document_admissions",
1159
+ "session_attempt_personal_document_snapshots",
1160
+ "session_attempt_personal_resource_admissions",
1161
+ "session_attempt_personal_resource_snapshots",
666
1162
  "session_visibility_write_capabilities",
667
1163
  "task_note_events",
1164
+ "task_note_knowledge_promotion_capabilities",
1165
+ "task_note_replacement_receipts",
668
1166
  "task_note_write_capabilities",
669
1167
  "task_notes",
1168
+ "tenancy_backfill_receipts",
1169
+ "tenancy_backfill_unresolved_rows",
1170
+ "turn_connection_authority_snapshots",
1171
+ "turn_personal_resource_attachment_receipts",
1172
+ "turn_personal_resource_once_receipts",
1173
+ "turn_personal_resource_snapshots",
1174
+ "workspace_variable_set_variables",
1175
+ "workspace_variable_sets",
670
1176
  ] as const;
671
1177
 
672
1178
  export type RuntimeTableDmlPrivilege = "SELECT" | "INSERT" | "UPDATE" | "DELETE";
@@ -706,6 +1212,7 @@ export type RuntimeDatabasePostureOptions = {
706
1212
  protectedTables?: readonly string[];
707
1213
  tablePrivileges?: RuntimeTablePrivilegeContract;
708
1214
  protectedNoDirectDmlTables?: readonly string[];
1215
+ organizationTenancyCanonicalActivationEnabled?: boolean;
709
1216
  };
710
1217
 
711
1218
  export type RuntimeDatabaseIdentity = {
@@ -753,6 +1260,7 @@ export type RuntimeRoutinePosture = {
753
1260
  name: string;
754
1261
  owner: string;
755
1262
  execute: boolean;
1263
+ publicExecute?: boolean;
756
1264
  securityDefiner: boolean;
757
1265
  };
758
1266
 
@@ -760,6 +1268,15 @@ export type RuntimeTargetRoutinePosture = RuntimeRoutinePosture & {
760
1268
  publicExecute: boolean;
761
1269
  };
762
1270
 
1271
+ export type RuntimePrivateTablePosture = {
1272
+ name: string;
1273
+ owner: string;
1274
+ select: boolean;
1275
+ insert: boolean;
1276
+ update: boolean;
1277
+ delete: boolean;
1278
+ };
1279
+
763
1280
  export type RuntimeDatabasePosture = {
764
1281
  identity: RuntimeDatabaseIdentity;
765
1282
  /** Privilege-bearing role relationships; exact PG16+ management-only grants are excluded. */
@@ -768,8 +1285,10 @@ export type RuntimeDatabasePosture = {
768
1285
  ownedSchemas: string[];
769
1286
  ownedRelations: string[];
770
1287
  tables: RuntimeTablePosture[];
1288
+ privateTables: RuntimePrivateTablePosture[];
771
1289
  targetRoutines: RuntimeTargetRoutinePosture[];
772
1290
  privateRoutines: RuntimeRoutinePosture[];
1291
+ sessionTenancyProductActivationPresent: boolean;
773
1292
  };
774
1293
 
775
1294
  export class RuntimeDatabasePostureError extends Error {
@@ -817,7 +1336,7 @@ function difference(left: ReadonlySet<string>, right: ReadonlySet<string>): stri
817
1336
  return sorted([...left].filter((value) => !right.has(value)));
818
1337
  }
819
1338
 
820
- /** Inspect only PostgreSQL catalogs and privilege functions; no tenant rows. */
1339
+ /** Inspect PostgreSQL catalogs plus one value-free global activation predicate; no tenant content. */
821
1340
  export async function inspectRuntimeDatabasePosture(
822
1341
  db: Database,
823
1342
  options: RuntimeDatabasePostureOptions,
@@ -868,6 +1387,15 @@ export async function inspectRuntimeDatabasePosture(
868
1387
  bypassRls: identity.rolbypassrls,
869
1388
  };
870
1389
 
1390
+ // The forward-only activation receipt outlives topology. Embedded/scoped
1391
+ // deployments must enforce the same environment interlock as standalone
1392
+ // FORCE-RLS deployments, so inspect the value-free predicate before the
1393
+ // scoped catalog fast-path.
1394
+ const activationRows = resultRows<{ activated: boolean }>(
1395
+ await tx.execute(sql`select session_tenancy_any_product_activation() as activated`),
1396
+ );
1397
+ const sessionTenancyProductActivationPresent = activationRows[0]?.activated === true;
1398
+
871
1399
  // Scoped/embedded topology deliberately leaves ownership and isolation to
872
1400
  // the host. Prove the connection identity is coherent, but do not impose
873
1401
  // the standalone opengeni_app object/grant contract on the host's role.
@@ -879,8 +1407,10 @@ export async function inspectRuntimeDatabasePosture(
879
1407
  ownedSchemas: [],
880
1408
  ownedRelations: [],
881
1409
  tables: [],
1410
+ privateTables: [],
882
1411
  targetRoutines: [],
883
1412
  privateRoutines: [],
1413
+ sessionTenancyProductActivationPresent,
884
1414
  };
885
1415
  }
886
1416
 
@@ -999,6 +1529,45 @@ export async function inspectRuntimeDatabasePosture(
999
1529
  trigger: row.can_trigger,
1000
1530
  }));
1001
1531
 
1532
+ const privateTables = resultRows<{
1533
+ name: string;
1534
+ owner: string;
1535
+ can_select: boolean;
1536
+ can_insert: boolean;
1537
+ can_update: boolean;
1538
+ can_delete: boolean;
1539
+ }>(
1540
+ await tx.execute(sql`
1541
+ select
1542
+ c.relname::text as name,
1543
+ pg_get_userbyid(c.relowner)::text as owner,
1544
+ has_table_privilege(current_user, c.oid, 'SELECT') as can_select,
1545
+ has_table_privilege(current_user, c.oid, 'INSERT') as can_insert,
1546
+ has_table_privilege(current_user, c.oid, 'UPDATE') as can_update,
1547
+ has_table_privilege(current_user, c.oid, 'DELETE') as can_delete
1548
+ from pg_class c
1549
+ join pg_namespace n on n.oid = c.relnamespace
1550
+ where n.nspname = 'opengeni_private'
1551
+ and c.relkind in ('r', 'p')
1552
+ and c.relname in (
1553
+ ${PERSONAL_RESOURCE_CAPABILITY_TABLE},
1554
+ ${SCHEDULED_PERSONAL_RESOURCE_CAPABILITY_TABLE},
1555
+ ${VARIABLE_SET_CAPABILITY_TABLE},
1556
+ ${PERSONAL_DOCUMENT_CAPABILITY_TABLE},
1557
+ ${DOCUMENT_MIGRATION_CAPABILITY_TABLE},
1558
+ ${SCOPED_COMPUTE_CAPABILITY_TABLE},
1559
+ ${CONNECTION_TENANCY_BACKFILL_CAPABILITY_TABLE}
1560
+ )
1561
+ `),
1562
+ ).map((row) => ({
1563
+ name: row.name,
1564
+ owner: row.owner,
1565
+ select: row.can_select,
1566
+ insert: row.can_insert,
1567
+ update: row.can_update,
1568
+ delete: row.can_delete,
1569
+ }));
1570
+
1002
1571
  const targetRoutines = resultRows<{
1003
1572
  name: string;
1004
1573
  owner: string;
@@ -1024,25 +1593,31 @@ export async function inspectRuntimeDatabasePosture(
1024
1593
  and (p.proname || '(' || pg_catalog.oidvectortypes(p.proargtypes) || ')') = any(
1025
1594
  array[
1026
1595
  ${sql.join(
1027
- RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES.map((name) => sql`${name}`),
1596
+ [
1597
+ ...RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES,
1598
+ ...RUNTIME_TARGET_SCHEMA_FORBIDDEN_ROUTINES,
1599
+ ].map((name) => sql`${name}`),
1028
1600
  sql`, `,
1029
1601
  )}
1030
1602
  ]::text[]
1031
1603
  )
1032
1604
  order by p.proname, pg_catalog.oidvectortypes(p.proargtypes)
1033
1605
  `),
1034
- ).map((row) => ({
1035
- name: row.name,
1036
- owner: row.owner,
1037
- execute: row.can_execute,
1038
- publicExecute: row.public_execute,
1039
- securityDefiner: row.security_definer,
1040
- }));
1606
+ )
1607
+ .map((row) => ({
1608
+ name: row.name,
1609
+ owner: row.owner,
1610
+ execute: row.can_execute,
1611
+ publicExecute: row.public_execute,
1612
+ securityDefiner: row.security_definer,
1613
+ }))
1614
+ .sort((left, right) => left.name.localeCompare(right.name));
1041
1615
 
1042
1616
  const privateRoutines = resultRows<{
1043
1617
  name: string;
1044
1618
  owner: string;
1045
1619
  can_execute: boolean;
1620
+ public_execute: boolean;
1046
1621
  security_definer: boolean;
1047
1622
  }>(
1048
1623
  await tx.execute(sql`
@@ -1050,6 +1625,11 @@ export async function inspectRuntimeDatabasePosture(
1050
1625
  (p.proname || '(' || pg_catalog.oidvectortypes(p.proargtypes) || ')')::text as name,
1051
1626
  pg_get_userbyid(p.proowner)::text as owner,
1052
1627
  has_function_privilege(current_user, p.oid, 'EXECUTE') as can_execute,
1628
+ exists (
1629
+ select 1
1630
+ from aclexplode(coalesce(p.proacl, acldefault('f', p.proowner))) acl
1631
+ where acl.grantee = 0 and acl.privilege_type = 'EXECUTE'
1632
+ ) as public_execute,
1053
1633
  p.prosecdef as security_definer
1054
1634
  from pg_proc p
1055
1635
  join pg_namespace n on n.oid = p.pronamespace
@@ -1061,6 +1641,7 @@ export async function inspectRuntimeDatabasePosture(
1061
1641
  name: row.name,
1062
1642
  owner: row.owner,
1063
1643
  execute: row.can_execute,
1644
+ publicExecute: row.public_execute,
1064
1645
  securityDefiner: row.security_definer,
1065
1646
  }));
1066
1647
 
@@ -1071,8 +1652,10 @@ export async function inspectRuntimeDatabasePosture(
1071
1652
  ownedSchemas,
1072
1653
  ownedRelations,
1073
1654
  tables,
1655
+ privateTables,
1074
1656
  targetRoutines,
1075
1657
  privateRoutines,
1658
+ sessionTenancyProductActivationPresent,
1076
1659
  };
1077
1660
  },
1078
1661
  { isolationLevel: "repeatable read", accessMode: "read only" },
@@ -1087,6 +1670,15 @@ export function evaluateRuntimeDatabasePosture(
1087
1670
  const violations: string[] = [];
1088
1671
  const identity = posture.identity;
1089
1672
 
1673
+ if (
1674
+ posture.sessionTenancyProductActivationPresent &&
1675
+ options.organizationTenancyCanonicalActivationEnabled !== true
1676
+ ) {
1677
+ violations.push(
1678
+ "session-tenancy product activation is durable but OPENGENI_ORGANIZATION_TENANCY_CANONICAL_ACTIVATION_ENABLED is not true",
1679
+ );
1680
+ }
1681
+
1090
1682
  if (!identity.currentUser || !identity.sessionUser) {
1091
1683
  violations.push("database identity is empty");
1092
1684
  }
@@ -1242,6 +1834,33 @@ export function evaluateRuntimeDatabasePosture(
1242
1834
  }
1243
1835
 
1244
1836
  const targetSchemaOwner = posture.schemas.find((schema) => schema.name === targetSchema)?.owner;
1837
+ for (const forbiddenRoutine of RUNTIME_TARGET_SCHEMA_FORBIDDEN_ROUTINES) {
1838
+ const matches = posture.targetRoutines.filter((routine) => routine.name === forbiddenRoutine);
1839
+ if (matches.length !== 1) {
1840
+ violations.push(
1841
+ `owner-internal target-schema helper ${forbiddenRoutine} is missing or ambiguous`,
1842
+ );
1843
+ continue;
1844
+ }
1845
+ const routine = matches[0]!;
1846
+ if (!routine.securityDefiner) {
1847
+ violations.push(
1848
+ `owner-internal target-schema helper ${routine.name} is not SECURITY DEFINER`,
1849
+ );
1850
+ }
1851
+ const authorityOwner = tableByName.get("sessions")?.owner ?? targetSchemaOwner;
1852
+ if (authorityOwner && routine.owner !== authorityOwner) {
1853
+ violations.push(
1854
+ `owner-internal target-schema helper ${routine.name} owner ${routine.owner} does not match session authority owner ${authorityOwner}`,
1855
+ );
1856
+ }
1857
+ if (routine.execute) {
1858
+ violations.push(`runtime role has forbidden owner-internal helper ${routine.name}`);
1859
+ }
1860
+ if (routine.publicExecute) {
1861
+ violations.push(`PUBLIC has forbidden owner-internal helper ${routine.name}`);
1862
+ }
1863
+ }
1245
1864
  for (const expectedRoutine of RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES) {
1246
1865
  const matches = posture.targetRoutines.filter((routine) => routine.name === expectedRoutine);
1247
1866
  if (matches.length !== 1) {
@@ -1260,7 +1879,33 @@ export function evaluateRuntimeDatabasePosture(
1260
1879
  } else if (!routine.securityDefiner) {
1261
1880
  violations.push(`target-schema runtime capability ${routine.name} is not SECURITY DEFINER`);
1262
1881
  }
1263
- if (routine.name === KNOWLEDGE_SOURCE_SYNC_LOCK_AUTHORITY_ROUTINE) {
1882
+ if (
1883
+ routine.name === GOOGLE_DRIVE_FILE_AUTHORIZATION_ROUTINE ||
1884
+ routine.name === GOOGLE_DRIVE_DOCUMENT_CITATION_ROUTINE
1885
+ ) {
1886
+ const missingAuthorityTables = GOOGLE_DRIVE_AUTHORITY_TABLES.filter(
1887
+ (tableName) => !tableByName.has(tableName),
1888
+ );
1889
+ if (missingAuthorityTables.length > 0) {
1890
+ violations.push(
1891
+ `target-schema runtime capability ${routine.name} authority tables are missing: ${missingAuthorityTables.join(", ")}`,
1892
+ );
1893
+ } else {
1894
+ const authorityTables = GOOGLE_DRIVE_AUTHORITY_TABLES.map(
1895
+ (tableName) => tableByName.get(tableName)!,
1896
+ );
1897
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
1898
+ if (authorityOwners.size !== 1) {
1899
+ violations.push(
1900
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`,
1901
+ );
1902
+ } else if (routine.owner !== authorityTables[0]!.owner) {
1903
+ violations.push(
1904
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0]!.owner}`,
1905
+ );
1906
+ }
1907
+ }
1908
+ } else if (routine.name === KNOWLEDGE_SOURCE_SYNC_LOCK_AUTHORITY_ROUTINE) {
1264
1909
  const missingAuthorityTables = KNOWLEDGE_SOURCE_SYNC_LOCK_AUTHORITY_TABLES.filter(
1265
1910
  (tableName) => !tableByName.has(tableName),
1266
1911
  );
@@ -1297,47 +1942,65 @@ export function evaluateRuntimeDatabasePosture(
1297
1942
  `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0].owner}`,
1298
1943
  );
1299
1944
  }
1300
- } else if ((CANONICAL_HUMAN_IDENTITY_ROUTINES as readonly string[]).includes(routine.name)) {
1301
- const authorityTables = CANONICAL_HUMAN_IDENTITY_AUTHORITY_TABLES.filter((tableName) =>
1302
- tableByName.has(tableName),
1303
- ).map((tableName) => tableByName.get(tableName)!);
1304
- const authorityOwners = new Set(authorityTables.map((table) => table.owner));
1305
- if (authorityTables.length !== CANONICAL_HUMAN_IDENTITY_AUTHORITY_TABLES.length) {
1306
- violations.push(
1307
- `target-schema runtime capability ${routine.name} canonical identity authority tables are missing`,
1308
- );
1309
- } else if (authorityOwners.size !== 1) {
1945
+ } else if (routine.name === GOVERNED_LEARNING_EVALUATION_ROUTINE) {
1946
+ if (!tableByName.has("governed_learning_decision_receipts")) {
1947
+ continue;
1948
+ }
1949
+ const missingAuthorityTables = GOVERNED_LEARNING_EVALUATION_AUTHORITY_TABLES.filter(
1950
+ (tableName) => !tableByName.has(tableName),
1951
+ );
1952
+ if (missingAuthorityTables.length > 0) {
1310
1953
  violations.push(
1311
- `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`,
1954
+ `target-schema runtime capability ${routine.name} authority tables are missing: ${missingAuthorityTables.join(", ")}`,
1312
1955
  );
1313
- } else if (routine.owner !== authorityTables[0]!.owner) {
1314
- violations.push(
1315
- `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0]!.owner}`,
1956
+ } else {
1957
+ const authorityTables = GOVERNED_LEARNING_EVALUATION_AUTHORITY_TABLES.map(
1958
+ (tableName) => tableByName.get(tableName)!,
1316
1959
  );
1960
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
1961
+ if (authorityOwners.size !== 1) {
1962
+ violations.push(
1963
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`,
1964
+ );
1965
+ } else if (routine.owner !== authorityTables[0]!.owner) {
1966
+ violations.push(
1967
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0]!.owner}`,
1968
+ );
1969
+ }
1317
1970
  }
1318
- } else if (SESSION_AUTHORITY_ROUTINES.has(routine.name)) {
1319
- const authorityOwner = tableByName.get("sessions")?.owner ?? targetSchemaOwner;
1320
- if (authorityOwner && routine.owner !== authorityOwner) {
1971
+ } else if (
1972
+ GOVERNED_LEARNING_INSPECTION_ROUTINES.includes(
1973
+ routine.name as (typeof GOVERNED_LEARNING_INSPECTION_ROUTINES)[number],
1974
+ )
1975
+ ) {
1976
+ if (!tableByName.has("governed_learning_decision_receipts")) continue;
1977
+ const missingAuthorityTables = GOVERNED_LEARNING_INSPECTION_AUTHORITY_TABLES.filter(
1978
+ (name) => !tableByName.has(name),
1979
+ );
1980
+ if (missingAuthorityTables.length > 0) {
1321
1981
  violations.push(
1322
- `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match session authority owner ${authorityOwner}`,
1982
+ `target-schema runtime capability ${routine.name} authority tables are missing: ${missingAuthorityTables.join(", ")}`,
1323
1983
  );
1984
+ } else {
1985
+ const authorityTables = GOVERNED_LEARNING_INSPECTION_AUTHORITY_TABLES.map(
1986
+ (name) => tableByName.get(name)!,
1987
+ );
1988
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
1989
+ if (authorityOwners.size !== 1 || routine.owner !== authorityTables[0]!.owner) {
1990
+ violations.push(
1991
+ `target-schema runtime capability ${routine.name} owner does not match governed-learning inspection authority`,
1992
+ );
1993
+ }
1324
1994
  }
1325
- } else if (routine.name === XAI_SNAPSHOT_VALIDATOR_ROUTINE) {
1326
- // The immutable SQL validator is invoker-rights and reads no table. Its
1327
- // exact ACL is posture-checked above; it does not participate in the
1328
- // SECURITY DEFINER same-owner authority graph.
1329
1995
  } else if (
1330
- routine.name === XAI_CREATE_CREDENTIAL_ROUTINE ||
1331
- routine.name === XAI_DISCONNECT_CREDENTIAL_ROUTINE ||
1332
- routine.name === XAI_AUTHORITY_LIVE_ROUTINE ||
1333
- routine.name === XAI_POOL_VISIBLE_ROUTINE ||
1334
- routine.name === XAI_RESOLVE_POOL_ROUTINE ||
1335
- routine.name === XAI_REVALIDATE_CREDENTIAL_ROUTINE
1996
+ GOVERNED_LEARNING_ACTIVATION_ROUTINES.includes(
1997
+ routine.name as (typeof GOVERNED_LEARNING_ACTIVATION_ROUTINES)[number],
1998
+ )
1336
1999
  ) {
1337
- if (!tableByName.has("xai_subscription_credentials")) {
2000
+ if (!tableByName.has("governed_learning_activation_receipts")) {
1338
2001
  continue;
1339
2002
  }
1340
- const missingAuthorityTables = XAI_AUTHORITY_TABLES.filter(
2003
+ const missingAuthorityTables = GOVERNED_LEARNING_ACTIVATION_AUTHORITY_TABLES.filter(
1341
2004
  (tableName) => !tableByName.has(tableName),
1342
2005
  );
1343
2006
  if (missingAuthorityTables.length > 0) {
@@ -1345,7 +2008,7 @@ export function evaluateRuntimeDatabasePosture(
1345
2008
  `target-schema runtime capability ${routine.name} authority tables are missing: ${missingAuthorityTables.join(", ")}`,
1346
2009
  );
1347
2010
  } else {
1348
- const authorityTables = XAI_AUTHORITY_TABLES.map(
2011
+ const authorityTables = GOVERNED_LEARNING_ACTIVATION_AUTHORITY_TABLES.map(
1349
2012
  (tableName) => tableByName.get(tableName)!,
1350
2013
  );
1351
2014
  const authorityOwners = new Set(authorityTables.map((table) => table.owner));
@@ -1359,11 +2022,244 @@ export function evaluateRuntimeDatabasePosture(
1359
2022
  );
1360
2023
  }
1361
2024
  }
1362
- } else if (targetSchemaOwner && routine.owner !== targetSchemaOwner) {
1363
- violations.push(
1364
- `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match schema owner ${targetSchemaOwner}`,
1365
- );
1366
- }
2025
+ } else if (
2026
+ COMPANY_PROFILE_AGENT_ADMIN_ROUTINES.includes(
2027
+ routine.name as (typeof COMPANY_PROFILE_AGENT_ADMIN_ROUTINES)[number],
2028
+ )
2029
+ ) {
2030
+ const missingAuthorityTables = COMPANY_PROFILE_AGENT_ADMIN_AUTHORITY_TABLES.filter(
2031
+ (tableName) => !tableByName.has(tableName),
2032
+ );
2033
+ if (missingAuthorityTables.length > 0) {
2034
+ violations.push(
2035
+ `target-schema runtime capability ${routine.name} authority tables are missing: ${missingAuthorityTables.join(", ")}`,
2036
+ );
2037
+ } else {
2038
+ const authorityTables = COMPANY_PROFILE_AGENT_ADMIN_AUTHORITY_TABLES.map(
2039
+ (tableName) => tableByName.get(tableName)!,
2040
+ );
2041
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2042
+ if (authorityOwners.size !== 1) {
2043
+ violations.push(
2044
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`,
2045
+ );
2046
+ } else if (routine.owner !== authorityTables[0]!.owner) {
2047
+ violations.push(
2048
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0]!.owner}`,
2049
+ );
2050
+ }
2051
+ }
2052
+ } else if (
2053
+ (ORGANIZATION_MEMBERSHIP_LIFECYCLE_ROUTINES as readonly string[]).includes(routine.name)
2054
+ ) {
2055
+ const missingAuthorityTables = ORGANIZATION_MEMBERSHIP_LIFECYCLE_AUTHORITY_TABLES.filter(
2056
+ (tableName) => !tableByName.has(tableName),
2057
+ );
2058
+ if (missingAuthorityTables.length > 0) {
2059
+ violations.push(
2060
+ `target-schema runtime capability ${routine.name} authority tables are missing: ${missingAuthorityTables.join(", ")}`,
2061
+ );
2062
+ } else {
2063
+ const authorityTables = ORGANIZATION_MEMBERSHIP_LIFECYCLE_AUTHORITY_TABLES.map(
2064
+ (tableName) => tableByName.get(tableName)!,
2065
+ );
2066
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2067
+ if (authorityOwners.size !== 1) {
2068
+ violations.push(
2069
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`,
2070
+ );
2071
+ } else if (routine.owner !== authorityTables[0]!.owner) {
2072
+ violations.push(
2073
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0]!.owner}`,
2074
+ );
2075
+ }
2076
+ }
2077
+ } else if (
2078
+ (ORGANIZATION_PRIVATE_SESSION_ROUTINES as readonly string[]).includes(routine.name)
2079
+ ) {
2080
+ if (!tableByName.has("organization_private_session_settings")) {
2081
+ continue;
2082
+ }
2083
+ const authorityTableNames =
2084
+ ORGANIZATION_PRIVATE_SESSION_ROUTINE_AUTHORITY_TABLES[
2085
+ routine.name as keyof typeof ORGANIZATION_PRIVATE_SESSION_ROUTINE_AUTHORITY_TABLES
2086
+ ];
2087
+ const missingAuthorityTables = authorityTableNames.filter(
2088
+ (tableName) => !tableByName.has(tableName),
2089
+ );
2090
+ if (missingAuthorityTables.length > 0) {
2091
+ violations.push(
2092
+ `target-schema runtime capability ${routine.name} authority tables are missing: ${missingAuthorityTables.join(", ")}`,
2093
+ );
2094
+ } else {
2095
+ const authorityTables = authorityTableNames.map((tableName) => tableByName.get(tableName)!);
2096
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2097
+ if (authorityOwners.size !== 1) {
2098
+ violations.push(
2099
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`,
2100
+ );
2101
+ } else if (routine.owner !== authorityTables[0]!.owner) {
2102
+ violations.push(
2103
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0]!.owner}`,
2104
+ );
2105
+ }
2106
+ }
2107
+ } else if (routine.name === PREFERENCE_KNOWLEDGE_PROPOSAL_ROUTINE) {
2108
+ if (!tableByName.has("company_brain_preference_proposal_receipts")) {
2109
+ continue;
2110
+ }
2111
+ const missingAuthorityTables = PREFERENCE_KNOWLEDGE_PROPOSAL_AUTHORITY_TABLES.filter(
2112
+ (tableName) => !tableByName.has(tableName),
2113
+ );
2114
+ if (missingAuthorityTables.length > 0) {
2115
+ violations.push(
2116
+ `target-schema runtime capability ${routine.name} authority tables are missing: ${missingAuthorityTables.join(", ")}`,
2117
+ );
2118
+ } else {
2119
+ const authorityTables = PREFERENCE_KNOWLEDGE_PROPOSAL_AUTHORITY_TABLES.map(
2120
+ (tableName) => tableByName.get(tableName)!,
2121
+ );
2122
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2123
+ if (authorityOwners.size !== 1) {
2124
+ violations.push(
2125
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`,
2126
+ );
2127
+ } else if (routine.owner !== authorityTables[0]!.owner) {
2128
+ violations.push(
2129
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0]!.owner}`,
2130
+ );
2131
+ }
2132
+ }
2133
+ } else if ((CANONICAL_HUMAN_IDENTITY_ROUTINES as readonly string[]).includes(routine.name)) {
2134
+ const authorityTables = CANONICAL_HUMAN_IDENTITY_AUTHORITY_TABLES.filter((tableName) =>
2135
+ tableByName.has(tableName),
2136
+ ).map((tableName) => tableByName.get(tableName)!);
2137
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2138
+ if (authorityTables.length !== CANONICAL_HUMAN_IDENTITY_AUTHORITY_TABLES.length) {
2139
+ violations.push(
2140
+ `target-schema runtime capability ${routine.name} canonical identity authority tables are missing`,
2141
+ );
2142
+ } else if (authorityOwners.size !== 1) {
2143
+ violations.push(
2144
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`,
2145
+ );
2146
+ } else if (routine.owner !== authorityTables[0]!.owner) {
2147
+ violations.push(
2148
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0]!.owner}`,
2149
+ );
2150
+ }
2151
+ } else if (
2152
+ (PERSONAL_GITHUB_REPOSITORY_AUTHORITY_ROUTINES as readonly string[]).includes(routine.name)
2153
+ ) {
2154
+ const authorityTables = PERSONAL_GITHUB_REPOSITORY_AUTHORITY_TABLES.map((tableName) =>
2155
+ tableByName.get(tableName),
2156
+ ).filter((table): table is RuntimeTablePosture => table !== undefined);
2157
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2158
+ if (authorityOwners.size > 1) {
2159
+ violations.push(
2160
+ `target-schema runtime capability ${routine.name} personal GitHub repository authority table owners do not match`,
2161
+ );
2162
+ } else {
2163
+ const authorityOwner = authorityTables[0]?.owner ?? targetSchemaOwner;
2164
+ if (authorityOwner && routine.owner !== authorityOwner) {
2165
+ violations.push(
2166
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match personal GitHub repository authority owner ${authorityOwner}`,
2167
+ );
2168
+ }
2169
+ }
2170
+ } else if (
2171
+ (PERSONAL_DOCUMENT_AUTHORITY_ROUTINES as readonly string[]).includes(routine.name) ||
2172
+ (DOCUMENT_MIGRATION_AUTHORITY_ROUTINES as readonly string[]).includes(routine.name)
2173
+ ) {
2174
+ const authorityOwner = tableByName.get("documents")?.owner ?? targetSchemaOwner;
2175
+ if (authorityOwner && routine.owner !== authorityOwner) {
2176
+ violations.push(
2177
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match document authority owner ${authorityOwner}`,
2178
+ );
2179
+ }
2180
+ } else if ((VARIABLE_SET_AUTHORITY_ROUTINES as readonly string[]).includes(routine.name)) {
2181
+ const authorityTables = ["workspace_variable_sets", "workspace_variable_set_variables"]
2182
+ .map((tableName) => tableByName.get(tableName))
2183
+ .filter((table): table is RuntimeTablePosture => table !== undefined);
2184
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2185
+ if (authorityOwners.size > 1) {
2186
+ violations.push(
2187
+ `target-schema runtime capability ${routine.name} variable-set table owners do not match`,
2188
+ );
2189
+ } else {
2190
+ const authorityOwner = authorityTables[0]?.owner ?? targetSchemaOwner;
2191
+ if (authorityOwner && routine.owner !== authorityOwner) {
2192
+ violations.push(
2193
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match variable-set authority owner ${authorityOwner}`,
2194
+ );
2195
+ }
2196
+ }
2197
+ } else if ((SCOPED_COMPUTE_AUTHORITY_ROUTINES as readonly string[]).includes(routine.name)) {
2198
+ const authorityTables = ["rigs", "rig_versions", "enrollments", "sandboxes"]
2199
+ .map((tableName) => tableByName.get(tableName))
2200
+ .filter((table): table is RuntimeTablePosture => table !== undefined);
2201
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2202
+ if (authorityOwners.size > 1) {
2203
+ violations.push(
2204
+ `target-schema runtime capability ${routine.name} scoped-compute table owners do not match`,
2205
+ );
2206
+ } else {
2207
+ const authorityOwner = authorityTables[0]?.owner ?? targetSchemaOwner;
2208
+ if (authorityOwner && routine.owner !== authorityOwner) {
2209
+ violations.push(
2210
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match scoped-compute authority owner ${authorityOwner}`,
2211
+ );
2212
+ }
2213
+ }
2214
+ } else if (SESSION_AUTHORITY_ROUTINES.has(routine.name)) {
2215
+ const authorityOwner = tableByName.get("sessions")?.owner ?? targetSchemaOwner;
2216
+ if (authorityOwner && routine.owner !== authorityOwner) {
2217
+ violations.push(
2218
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match session authority owner ${authorityOwner}`,
2219
+ );
2220
+ }
2221
+ } else if (routine.name === XAI_SNAPSHOT_VALIDATOR_ROUTINE) {
2222
+ // The immutable SQL validator is invoker-rights and reads no table. Its
2223
+ // exact ACL is posture-checked above; it does not participate in the
2224
+ // SECURITY DEFINER same-owner authority graph.
2225
+ } else if (
2226
+ routine.name === XAI_CREATE_CREDENTIAL_ROUTINE ||
2227
+ routine.name === XAI_DISCONNECT_CREDENTIAL_ROUTINE ||
2228
+ routine.name === XAI_AUTHORITY_LIVE_ROUTINE ||
2229
+ routine.name === XAI_POOL_VISIBLE_ROUTINE ||
2230
+ routine.name === XAI_RESOLVE_POOL_ROUTINE ||
2231
+ routine.name === XAI_REVALIDATE_CREDENTIAL_ROUTINE
2232
+ ) {
2233
+ if (!tableByName.has("xai_subscription_credentials")) {
2234
+ continue;
2235
+ }
2236
+ const missingAuthorityTables = XAI_AUTHORITY_TABLES.filter(
2237
+ (tableName) => !tableByName.has(tableName),
2238
+ );
2239
+ if (missingAuthorityTables.length > 0) {
2240
+ violations.push(
2241
+ `target-schema runtime capability ${routine.name} authority tables are missing: ${missingAuthorityTables.join(", ")}`,
2242
+ );
2243
+ } else {
2244
+ const authorityTables = XAI_AUTHORITY_TABLES.map(
2245
+ (tableName) => tableByName.get(tableName)!,
2246
+ );
2247
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2248
+ if (authorityOwners.size !== 1) {
2249
+ violations.push(
2250
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`,
2251
+ );
2252
+ } else if (routine.owner !== authorityTables[0]!.owner) {
2253
+ violations.push(
2254
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0]!.owner}`,
2255
+ );
2256
+ }
2257
+ }
2258
+ } else if (targetSchemaOwner && routine.owner !== targetSchemaOwner) {
2259
+ violations.push(
2260
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match schema owner ${targetSchemaOwner}`,
2261
+ );
2262
+ }
1367
2263
  if (!routine.execute) {
1368
2264
  violations.push(`runtime role lacks target-schema capability ${routine.name}`);
1369
2265
  }
@@ -1538,9 +2434,376 @@ export function evaluateRuntimeDatabasePosture(
1538
2434
  }
1539
2435
  }
1540
2436
 
2437
+ const personalResourceCapabilityTables = posture.privateTables.filter(
2438
+ (table) => table.name === PERSONAL_RESOURCE_CAPABILITY_TABLE,
2439
+ );
2440
+ const personalResourceCapabilityRoutines = posture.privateRoutines.filter(
2441
+ (routine) => routine.name === PERSONAL_RESOURCE_CAPABILITY_PREDICATE_ROUTINE,
2442
+ );
2443
+ if (personalResourceCapabilityTables.length !== 1) {
2444
+ violations.push(
2445
+ `personal-resource capability table ${PERSONAL_RESOURCE_CAPABILITY_TABLE} is missing or ambiguous`,
2446
+ );
2447
+ }
2448
+ if (personalResourceCapabilityRoutines.length !== 1) {
2449
+ violations.push(
2450
+ `personal-resource capability predicate ${PERSONAL_RESOURCE_CAPABILITY_PREDICATE_ROUTINE} is missing or ambiguous`,
2451
+ );
2452
+ }
2453
+ if (
2454
+ personalResourceCapabilityTables.length === 1 &&
2455
+ personalResourceCapabilityRoutines.length === 1
2456
+ ) {
2457
+ const table = personalResourceCapabilityTables[0]!;
2458
+ const routine = personalResourceCapabilityRoutines[0]!;
2459
+ if (routine.owner !== table.owner) {
2460
+ violations.push(
2461
+ `personal-resource capability predicate ${routine.name} owner ${routine.owner} does not match table owner ${table.owner}`,
2462
+ );
2463
+ }
2464
+ if (!routine.securityDefiner) {
2465
+ violations.push(
2466
+ `personal-resource capability predicate ${routine.name} is not SECURITY DEFINER`,
2467
+ );
2468
+ }
2469
+ if (!routine.execute) {
2470
+ violations.push(`runtime role lacks personal-resource capability predicate ${routine.name}`);
2471
+ }
2472
+ if (routine.publicExecute) {
2473
+ violations.push(
2474
+ `PUBLIC has forbidden personal-resource capability predicate ${routine.name}`,
2475
+ );
2476
+ }
2477
+ const directPrivileges = [
2478
+ ["SELECT", table.select],
2479
+ ["INSERT", table.insert],
2480
+ ["UPDATE", table.update],
2481
+ ["DELETE", table.delete],
2482
+ ].filter(([, granted]) => granted);
2483
+ if (directPrivileges.length > 0) {
2484
+ violations.push(
2485
+ `runtime role has forbidden direct privileges on private table ${table.name}: ${directPrivileges.map(([privilege]) => privilege).join(", ")}`,
2486
+ );
2487
+ }
2488
+ }
2489
+
2490
+ const personalDocumentCapabilityTables = posture.privateTables.filter(
2491
+ (table) => table.name === PERSONAL_DOCUMENT_CAPABILITY_TABLE,
2492
+ );
2493
+ const personalDocumentCapabilityRoutines = posture.privateRoutines.filter(
2494
+ (routine) => routine.name === PERSONAL_DOCUMENT_CAPABILITY_PREDICATE_ROUTINE,
2495
+ );
2496
+ if (personalDocumentCapabilityTables.length !== 1) {
2497
+ violations.push(
2498
+ `personal-document capability table ${PERSONAL_DOCUMENT_CAPABILITY_TABLE} is missing or ambiguous`,
2499
+ );
2500
+ }
2501
+ if (personalDocumentCapabilityRoutines.length !== 1) {
2502
+ violations.push(
2503
+ `personal-document capability predicate ${PERSONAL_DOCUMENT_CAPABILITY_PREDICATE_ROUTINE} is missing or ambiguous`,
2504
+ );
2505
+ }
2506
+ if (
2507
+ personalDocumentCapabilityTables.length === 1 &&
2508
+ personalDocumentCapabilityRoutines.length === 1
2509
+ ) {
2510
+ const table = personalDocumentCapabilityTables[0]!;
2511
+ const routine = personalDocumentCapabilityRoutines[0]!;
2512
+ if (routine.owner !== table.owner) {
2513
+ violations.push(
2514
+ `personal-document capability predicate ${routine.name} owner ${routine.owner} does not match table owner ${table.owner}`,
2515
+ );
2516
+ }
2517
+ if (!routine.securityDefiner) {
2518
+ violations.push(
2519
+ `personal-document capability predicate ${routine.name} is not SECURITY DEFINER`,
2520
+ );
2521
+ }
2522
+ if (!routine.execute) {
2523
+ violations.push(`runtime role lacks personal-document capability predicate ${routine.name}`);
2524
+ }
2525
+ if (routine.publicExecute) {
2526
+ violations.push(
2527
+ `PUBLIC has forbidden personal-document capability predicate ${routine.name}`,
2528
+ );
2529
+ }
2530
+ const directPrivileges = [
2531
+ ["SELECT", table.select],
2532
+ ["INSERT", table.insert],
2533
+ ["UPDATE", table.update],
2534
+ ["DELETE", table.delete],
2535
+ ].filter(([, granted]) => granted);
2536
+ if (directPrivileges.length > 0) {
2537
+ violations.push(
2538
+ `runtime role has forbidden direct privileges on private table ${table.name}: ${directPrivileges.map(([privilege]) => privilege).join(", ")}`,
2539
+ );
2540
+ }
2541
+ }
2542
+
2543
+ const documentMigrationCapabilityTables = posture.privateTables.filter(
2544
+ (table) => table.name === DOCUMENT_MIGRATION_CAPABILITY_TABLE,
2545
+ );
2546
+ const documentMigrationCapabilityRoutines = posture.privateRoutines.filter(
2547
+ (routine) => routine.name === DOCUMENT_MIGRATION_CAPABILITY_PREDICATE_ROUTINE,
2548
+ );
2549
+ if (documentMigrationCapabilityTables.length !== 1) {
2550
+ violations.push(
2551
+ `document-migration capability table ${DOCUMENT_MIGRATION_CAPABILITY_TABLE} is missing or ambiguous`,
2552
+ );
2553
+ }
2554
+ if (documentMigrationCapabilityRoutines.length !== 1) {
2555
+ violations.push(
2556
+ `document-migration capability predicate ${DOCUMENT_MIGRATION_CAPABILITY_PREDICATE_ROUTINE} is missing or ambiguous`,
2557
+ );
2558
+ }
2559
+ if (
2560
+ documentMigrationCapabilityTables.length === 1 &&
2561
+ documentMigrationCapabilityRoutines.length === 1
2562
+ ) {
2563
+ const table = documentMigrationCapabilityTables[0]!;
2564
+ const routine = documentMigrationCapabilityRoutines[0]!;
2565
+ if (routine.owner !== table.owner) {
2566
+ violations.push(
2567
+ `document-migration capability predicate ${routine.name} owner ${routine.owner} does not match table owner ${table.owner}`,
2568
+ );
2569
+ }
2570
+ if (!routine.securityDefiner) {
2571
+ violations.push(
2572
+ `document-migration capability predicate ${routine.name} is not SECURITY DEFINER`,
2573
+ );
2574
+ }
2575
+ if (!routine.execute) {
2576
+ violations.push(`runtime role lacks document-migration capability predicate ${routine.name}`);
2577
+ }
2578
+ if (routine.publicExecute) {
2579
+ violations.push(
2580
+ `PUBLIC has forbidden document-migration capability predicate ${routine.name}`,
2581
+ );
2582
+ }
2583
+ const directPrivileges = [
2584
+ ["SELECT", table.select],
2585
+ ["INSERT", table.insert],
2586
+ ["UPDATE", table.update],
2587
+ ["DELETE", table.delete],
2588
+ ].filter(([, granted]) => granted);
2589
+ if (directPrivileges.length > 0) {
2590
+ violations.push(
2591
+ `runtime role has forbidden direct privileges on private table ${table.name}: ${directPrivileges.map(([privilege]) => privilege).join(", ")}`,
2592
+ );
2593
+ }
2594
+ }
2595
+
2596
+ const scheduledCapabilityTables = posture.privateTables.filter(
2597
+ (table) => table.name === SCHEDULED_PERSONAL_RESOURCE_CAPABILITY_TABLE,
2598
+ );
2599
+ const scheduledCapabilityRoutines = posture.privateRoutines.filter(
2600
+ (routine) => routine.name === SCHEDULED_PERSONAL_RESOURCE_CAPABILITY_PREDICATE_ROUTINE,
2601
+ );
2602
+ if (scheduledCapabilityTables.length !== 1) {
2603
+ violations.push(
2604
+ `scheduled personal-resource capability table ${SCHEDULED_PERSONAL_RESOURCE_CAPABILITY_TABLE} is missing or ambiguous`,
2605
+ );
2606
+ }
2607
+ if (scheduledCapabilityRoutines.length !== 1) {
2608
+ violations.push(
2609
+ `scheduled personal-resource capability predicate ${SCHEDULED_PERSONAL_RESOURCE_CAPABILITY_PREDICATE_ROUTINE} is missing or ambiguous`,
2610
+ );
2611
+ }
2612
+ if (scheduledCapabilityTables.length === 1 && scheduledCapabilityRoutines.length === 1) {
2613
+ const table = scheduledCapabilityTables[0]!;
2614
+ const routine = scheduledCapabilityRoutines[0]!;
2615
+ if (routine.owner !== table.owner) {
2616
+ violations.push(
2617
+ `scheduled personal-resource capability predicate ${routine.name} owner ${routine.owner} does not match table owner ${table.owner}`,
2618
+ );
2619
+ }
2620
+ if (!routine.securityDefiner) {
2621
+ violations.push(
2622
+ `scheduled personal-resource capability predicate ${routine.name} is not SECURITY DEFINER`,
2623
+ );
2624
+ }
2625
+ if (!routine.execute) {
2626
+ violations.push(
2627
+ `runtime role lacks scheduled personal-resource capability predicate ${routine.name}`,
2628
+ );
2629
+ }
2630
+ if (routine.publicExecute) {
2631
+ violations.push(
2632
+ `PUBLIC has forbidden scheduled personal-resource capability predicate ${routine.name}`,
2633
+ );
2634
+ }
2635
+ const directPrivileges = [
2636
+ ["SELECT", table.select],
2637
+ ["INSERT", table.insert],
2638
+ ["UPDATE", table.update],
2639
+ ["DELETE", table.delete],
2640
+ ].filter(([, granted]) => granted);
2641
+ if (directPrivileges.length > 0) {
2642
+ violations.push(
2643
+ `runtime role has forbidden direct privileges on private table ${table.name}: ${directPrivileges.map(([privilege]) => privilege).join(", ")}`,
2644
+ );
2645
+ }
2646
+ }
2647
+
2648
+ if (options.protectedTables === undefined) {
2649
+ const variableSetCapabilityTables = posture.privateTables.filter(
2650
+ (table) => table.name === VARIABLE_SET_CAPABILITY_TABLE,
2651
+ );
2652
+ const variableSetCapabilityRoutines = posture.privateRoutines.filter(
2653
+ (routine) => routine.name === VARIABLE_SET_CAPABILITY_PREDICATE_ROUTINE,
2654
+ );
2655
+ if (variableSetCapabilityTables.length !== 1) {
2656
+ violations.push(
2657
+ `variable-set capability table ${VARIABLE_SET_CAPABILITY_TABLE} is missing or ambiguous`,
2658
+ );
2659
+ }
2660
+ if (variableSetCapabilityRoutines.length !== 1) {
2661
+ violations.push(
2662
+ `variable-set capability predicate ${VARIABLE_SET_CAPABILITY_PREDICATE_ROUTINE} is missing or ambiguous`,
2663
+ );
2664
+ }
2665
+ if (variableSetCapabilityTables.length === 1 && variableSetCapabilityRoutines.length === 1) {
2666
+ const table = variableSetCapabilityTables[0]!;
2667
+ const routine = variableSetCapabilityRoutines[0]!;
2668
+ if (routine.owner !== table.owner) {
2669
+ violations.push(
2670
+ `variable-set capability predicate ${routine.name} owner ${routine.owner} does not match table owner ${table.owner}`,
2671
+ );
2672
+ }
2673
+ if (!routine.securityDefiner) {
2674
+ violations.push(
2675
+ `variable-set capability predicate ${routine.name} is not SECURITY DEFINER`,
2676
+ );
2677
+ }
2678
+ if (!routine.execute) {
2679
+ violations.push(`runtime role lacks variable-set capability predicate ${routine.name}`);
2680
+ }
2681
+ if (routine.publicExecute) {
2682
+ violations.push(`PUBLIC has forbidden variable-set capability predicate ${routine.name}`);
2683
+ }
2684
+ const directPrivileges = [
2685
+ ["SELECT", table.select],
2686
+ ["INSERT", table.insert],
2687
+ ["UPDATE", table.update],
2688
+ ["DELETE", table.delete],
2689
+ ].filter(([, granted]) => granted);
2690
+ if (directPrivileges.length > 0) {
2691
+ violations.push(
2692
+ `runtime role has forbidden direct privileges on private table ${table.name}: ${directPrivileges.map(([privilege]) => privilege).join(", ")}`,
2693
+ );
2694
+ }
2695
+ }
2696
+ const scopedComputeCapabilityTables = posture.privateTables.filter(
2697
+ (table) => table.name === SCOPED_COMPUTE_CAPABILITY_TABLE,
2698
+ );
2699
+ const scopedComputeCapabilityRoutines = posture.privateRoutines.filter(
2700
+ (routine) => routine.name === SCOPED_COMPUTE_CAPABILITY_PREDICATE_ROUTINE,
2701
+ );
2702
+ if (scopedComputeCapabilityTables.length !== 1) {
2703
+ violations.push(
2704
+ `scoped-compute capability table ${SCOPED_COMPUTE_CAPABILITY_TABLE} is missing or ambiguous`,
2705
+ );
2706
+ }
2707
+ if (scopedComputeCapabilityRoutines.length !== 1) {
2708
+ violations.push(
2709
+ `scoped-compute capability predicate ${SCOPED_COMPUTE_CAPABILITY_PREDICATE_ROUTINE} is missing or ambiguous`,
2710
+ );
2711
+ }
2712
+ if (
2713
+ scopedComputeCapabilityTables.length === 1 &&
2714
+ scopedComputeCapabilityRoutines.length === 1
2715
+ ) {
2716
+ const table = scopedComputeCapabilityTables[0]!;
2717
+ const routine = scopedComputeCapabilityRoutines[0]!;
2718
+ if (routine.owner !== table.owner) {
2719
+ violations.push(
2720
+ `scoped-compute capability predicate ${routine.name} owner ${routine.owner} does not match table owner ${table.owner}`,
2721
+ );
2722
+ }
2723
+ if (!routine.securityDefiner) {
2724
+ violations.push(
2725
+ `scoped-compute capability predicate ${routine.name} is not SECURITY DEFINER`,
2726
+ );
2727
+ }
2728
+ if (!routine.execute) {
2729
+ violations.push(`runtime role lacks scoped-compute capability predicate ${routine.name}`);
2730
+ }
2731
+ if (routine.publicExecute) {
2732
+ violations.push(`PUBLIC has forbidden scoped-compute capability predicate ${routine.name}`);
2733
+ }
2734
+ const directPrivileges = [
2735
+ ["SELECT", table.select],
2736
+ ["INSERT", table.insert],
2737
+ ["UPDATE", table.update],
2738
+ ["DELETE", table.delete],
2739
+ ].filter(([, granted]) => granted);
2740
+ if (directPrivileges.length > 0) {
2741
+ violations.push(
2742
+ `runtime role has forbidden direct privileges on private table ${table.name}: ${directPrivileges.map(([privilege]) => privilege).join(", ")}`,
2743
+ );
2744
+ }
2745
+ }
2746
+ }
2747
+
1541
2748
  if (posture.privateRoutines.length === 0) {
1542
2749
  violations.push("opengeni_private has no helper routines");
1543
2750
  }
2751
+
2752
+ const connectionBackfillCapabilityTables = posture.privateTables.filter(
2753
+ (table) => table.name === CONNECTION_TENANCY_BACKFILL_CAPABILITY_TABLE,
2754
+ );
2755
+ const connectionBackfillCapabilityRoutines = posture.privateRoutines.filter(
2756
+ (routine) => routine.name === CONNECTION_TENANCY_BACKFILL_CAPABILITY_PREDICATE_ROUTINE,
2757
+ );
2758
+ if (connectionBackfillCapabilityTables.length !== 1) {
2759
+ violations.push(
2760
+ `connection-tenancy backfill capability table ${CONNECTION_TENANCY_BACKFILL_CAPABILITY_TABLE} is missing or ambiguous`,
2761
+ );
2762
+ }
2763
+ if (connectionBackfillCapabilityRoutines.length !== 1) {
2764
+ violations.push(
2765
+ `connection-tenancy backfill capability predicate ${CONNECTION_TENANCY_BACKFILL_CAPABILITY_PREDICATE_ROUTINE} is missing or ambiguous`,
2766
+ );
2767
+ }
2768
+ if (
2769
+ connectionBackfillCapabilityTables.length === 1 &&
2770
+ connectionBackfillCapabilityRoutines.length === 1
2771
+ ) {
2772
+ const table = connectionBackfillCapabilityTables[0]!;
2773
+ const routine = connectionBackfillCapabilityRoutines[0]!;
2774
+ if (routine.owner !== table.owner) {
2775
+ violations.push(
2776
+ `connection-tenancy backfill capability predicate ${routine.name} owner ${routine.owner} does not match table owner ${table.owner}`,
2777
+ );
2778
+ }
2779
+ if (!routine.securityDefiner) {
2780
+ violations.push(
2781
+ `connection-tenancy backfill capability predicate ${routine.name} is not SECURITY DEFINER`,
2782
+ );
2783
+ }
2784
+ if (!routine.execute) {
2785
+ violations.push(
2786
+ `runtime role lacks connection-tenancy backfill capability predicate ${routine.name}`,
2787
+ );
2788
+ }
2789
+ if (routine.publicExecute) {
2790
+ violations.push(
2791
+ `PUBLIC has forbidden connection-tenancy backfill capability predicate ${routine.name}`,
2792
+ );
2793
+ }
2794
+ const directPrivileges = [
2795
+ ["SELECT", table.select],
2796
+ ["INSERT", table.insert],
2797
+ ["UPDATE", table.update],
2798
+ ["DELETE", table.delete],
2799
+ ].filter(([, granted]) => granted);
2800
+ if (directPrivileges.length > 0) {
2801
+ violations.push(
2802
+ `runtime role has forbidden direct privileges on private table ${table.name}: ${directPrivileges.map(([privilege]) => privilege).join(", ")}`,
2803
+ );
2804
+ }
2805
+ }
2806
+
1544
2807
  for (const routine of posture.privateRoutines) {
1545
2808
  if (routine.owner === expectedRole) {
1546
2809
  violations.push(`runtime role owns private routine ${routine.name}`);