@opengeni/db 1.0.1 → 3.2.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 (271) 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-4SR4HKKA.js → chunk-2EH4WRHL.js} +19 -11
  7. package/dist/chunk-2EH4WRHL.js.map +1 -0
  8. package/dist/{chunk-CUPM3FGB.js → chunk-2PRS4J5Q.js} +3 -3
  9. package/dist/chunk-6HMM2R5T.js +390 -0
  10. package/dist/chunk-6HMM2R5T.js.map +1 -0
  11. package/dist/{chunk-ZWREYEWA.js → chunk-AZHW7R5V.js} +56 -11
  12. package/dist/chunk-AZHW7R5V.js.map +1 -0
  13. package/dist/{chunk-LTG3S6ZY.js → chunk-E6CLMKEE.js} +2 -2
  14. package/dist/{chunk-6ZYKCRFO.js → chunk-KRLPEMLH.js} +7591 -4417
  15. package/dist/chunk-KRLPEMLH.js.map +1 -0
  16. package/dist/chunk-NAB6FKFN.js +516 -0
  17. package/dist/chunk-NAB6FKFN.js.map +1 -0
  18. package/dist/{chunk-SK7YYHBI.js → chunk-SIBYBA2D.js} +46 -1
  19. package/dist/chunk-SIBYBA2D.js.map +1 -0
  20. package/dist/chunk-UZNXG44K.js +4508 -0
  21. package/dist/chunk-UZNXG44K.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 +85 -0
  33. package/dist/connection-token-resolver.d.ts +30 -1
  34. package/dist/database.d.ts +23 -4
  35. package/dist/editable-artifact-durable-export.js +2 -2
  36. package/dist/editable-artifacts.d.ts +2 -2
  37. package/dist/editable-artifacts.js +3 -3
  38. package/dist/governed-learning-activation-schema.d.ts +984 -0
  39. package/dist/governed-learning-activation.d.ts +98 -0
  40. package/dist/governed-learning-evaluator-schema.d.ts +633 -0
  41. package/dist/governed-learning-evaluator.d.ts +28 -0
  42. package/dist/index.d.ts +1606 -81
  43. package/dist/index.js +21898 -8147
  44. package/dist/index.js.map +1 -1
  45. package/dist/insights.d.ts +18 -0
  46. package/dist/integration-bindings.d.ts +1 -0
  47. package/dist/integration-facets.d.ts +30 -0
  48. package/dist/interaction-placement-loss.d.ts +22 -0
  49. package/dist/managed-human-provisioning.d.ts +25 -0
  50. package/dist/memory-domain.d.ts +3 -3
  51. package/dist/migrate.d.ts +11 -1
  52. package/dist/migrate.js +1 -1
  53. package/dist/new-session-drafts.d.ts +43 -5
  54. package/dist/organization-membership-backfill.d.ts +174 -0
  55. package/dist/organization-membership-lifecycle.d.ts +162 -0
  56. package/dist/pr-review.d.ts +107 -0
  57. package/dist/preference-registry-schema.d.ts +2 -0
  58. package/dist/preference-registry.d.ts +2 -0
  59. package/dist/provision-roles.js +1 -1
  60. package/dist/runtime-posture.d.ts +29 -8
  61. package/dist/schema.d.ts +24914 -13703
  62. package/dist/schema.js +99 -1
  63. package/dist/scoped-knowledge-schema.d.ts +52 -1
  64. package/dist/session-background-commands.d.ts +125 -0
  65. package/dist/session-background-commands.js +34 -0
  66. package/dist/session-background-commands.js.map +1 -0
  67. package/dist/session-control.d.ts +156 -3
  68. package/dist/session-goal-pacing.d.ts +68 -0
  69. package/dist/session-queue-commands.d.ts +43 -4
  70. package/dist/session-realtime-ledger.d.ts +2 -0
  71. package/dist/session-tenancy.d.ts +71 -1
  72. package/dist/session-tenancy.js +25 -3
  73. package/dist/session-tool-call-settlement.d.ts +9 -4
  74. package/dist/slack-routing-personal-workspace.d.ts +23 -0
  75. package/dist/slack-routing.d.ts +268 -0
  76. package/dist/slack-task-policy-schema.d.ts +34 -0
  77. package/dist/slack-task-policy.d.ts +8 -0
  78. package/dist/slack-user-link-access.d.ts +28 -0
  79. package/dist/task-notes-schema.d.ts +594 -0
  80. package/dist/task-notes.d.ts +39 -0
  81. package/dist/turn-initiator.d.ts +2 -0
  82. package/dist/user-resource-authority.d.ts +109 -0
  83. package/dist/video-generation.js +3 -3
  84. package/dist/workspace-authority.d.ts +81 -0
  85. package/dist/workspace-instruction-policies-schema.d.ts +279 -0
  86. package/dist/workspace-instruction-policies.d.ts +62 -0
  87. package/dist/workspace-learning-policy.d.ts +1 -0
  88. package/dist/workspace-membership-permissions.d.ts +2 -0
  89. package/drizzle/0240_enrollment_connection_authority.sql +39 -0
  90. package/drizzle/0241_atomic_personal_resource_delegation.sql +1000 -0
  91. package/drizzle/0241_enrollment_agent_runtime.sql +70 -0
  92. package/drizzle/0244_slack_app_home_refresh_queue.sql +120 -0
  93. package/drizzle/0245_model_context_contribution_facts.sql +88 -0
  94. package/drizzle/0246_integration_personal_instance_authority.sql +70 -0
  95. package/drizzle/0247_terraform_stacks_provenance_repair.sql +428 -0
  96. package/drizzle/0248_terraform_stacks_component_resolution_fence.sql +83 -0
  97. package/drizzle/0249_personal_resource_delegation_authority_correction.sql +662 -0
  98. package/drizzle/0250_direct_retained_process_owner_liveness.sql +199 -0
  99. package/drizzle/0251_connected_machine_operation_policy.sql +45 -0
  100. package/drizzle/0252_scheduled_personal_resource_delegation.sql +1867 -0
  101. package/drizzle/0253_common_user_resource_authority_lifecycle.sql +1555 -0
  102. package/drizzle/0254_scoped_variable_set_authority.sql +1255 -0
  103. package/drizzle/0255_company_brain_governed_write_proposals.sql +524 -0
  104. package/drizzle/0256_connection_authority_delegation.sql +703 -0
  105. package/drizzle/0257_goal_revision_decisions_and_root_constraints.sql +436 -0
  106. package/drizzle/0258_three_scope_document_knowledge_authority.sql +1273 -0
  107. package/drizzle/0259_company_brain_context_selection_receipts.sql +869 -0
  108. package/drizzle/0260_task_note_knowledge_promotion.sql +820 -0
  109. package/drizzle/0261_preference_knowledge_proposal_actor_binding.sql +471 -0
  110. package/drizzle/0262_scoped_connected_machines_and_rigs.sql +1700 -0
  111. package/drizzle/0263_organization_membership_lifecycle.sql +3284 -0
  112. package/drizzle/0264_connection_authority_runtime_activation.sql +1084 -0
  113. package/drizzle/0266_company_brain_context_receipt_inspection.sql +156 -0
  114. package/drizzle/0268_governed_learning_decision_receipts.sql +825 -0
  115. package/drizzle/0269_governed_learning_activation_controller.sql +1874 -0
  116. package/drizzle/0270_governed_learning_history_inspection.sql +170 -0
  117. package/drizzle/0271_company_brain_retrieval_only_default.sql +524 -0
  118. package/drizzle/0272_human_confirmed_learning_activation.sql +591 -0
  119. package/drizzle/0273_scheduled_variable_set_materialization.sql +268 -0
  120. package/drizzle/0274_human_confirmed_knowledge_review.sql +310 -0
  121. package/drizzle/0275_scheduled_connection_authority.sql +5527 -0
  122. package/drizzle/0276_onboarding_proposal_initiating_human_guc.sql +198 -0
  123. package/drizzle/0277_workspace_writer_authority_attribution.sql +393 -0
  124. package/drizzle/0278_workspace_membership_removal_fencing.sql +1174 -0
  125. package/drizzle/0279_workspace_connection_use_lane.sql +343 -0
  126. package/drizzle/0280_connection_and_variable_set_audit_attribution.sql +773 -0
  127. package/drizzle/0281_viewer_holder_authority_claims.sql +52 -0
  128. package/drizzle/0282_variable_set_session_attach_attribution.sql +178 -0
  129. package/drizzle/0283_editable_spreadsheet_authored_state.sql +82 -0
  130. package/drizzle/0284_truthful_human_confirmed_review_reason.sql +930 -0
  131. package/drizzle/0285_organization_tenancy_inventory.sql +329 -0
  132. package/drizzle/0286_widen_task_note_expiry_ceiling.sql +391 -0
  133. package/drizzle/0287_open_suffix_pending_tool_calls.sql +18 -0
  134. package/drizzle/0288_attached_browser_reenrollment.sql +64 -0
  135. package/drizzle/0289_session_composer_policy_authority.sql +597 -0
  136. package/drizzle/0290_organization_membership_backfill.sql +268 -0
  137. package/drizzle/0291_resource_authority_classification_assertion.sql +371 -0
  138. package/drizzle/0292_truthful_tenancy_inventory_counters.sql +291 -0
  139. package/drizzle/0293_confirm_time_rule_rebaseline.sql +615 -0
  140. package/drizzle/0294_preference_activation_authority.sql +237 -0
  141. package/drizzle/0295_retire_legacy_standing_memory_mode.sql +476 -0
  142. package/drizzle/0296_force_rls_backfill_noop_repair.sql +215 -0
  143. package/drizzle/0297_session_ownership_classification_and_backfill.sql +752 -0
  144. package/drizzle/0298_organization_tenancy_parity.sql +609 -0
  145. package/drizzle/0299_organization_membership_lock_order.sql +291 -0
  146. package/drizzle/0300_tenancy_backfill_ledger.sql +459 -0
  147. package/drizzle/0301_session_snapshot_and_pin_visibility.sql +181 -0
  148. package/drizzle/0302_personal_workspace_session_ownership.sql +303 -0
  149. package/drizzle/0303_session_tenancy_product_activation.sql +919 -0
  150. package/drizzle/0304_personal_workspace_private_session_reads.sql +97 -0
  151. package/drizzle/0305_personal_resource_grant_management.sql +584 -0
  152. package/drizzle/0306_atomic_personal_resource_attachments.sql +1374 -0
  153. package/drizzle/0307_session_attention_state.sql +51 -0
  154. package/drizzle/0308_session_archives.sql +35 -0
  155. package/drizzle/0309_channel_project_pins.sql +6 -0
  156. package/drizzle/0310_channel_project_order.sql +27 -0
  157. package/drizzle/0311_company_scope_and_private_session_create.sql +656 -0
  158. package/drizzle/0312_quiescent_session_tree_deletion.sql +39 -0
  159. package/drizzle/0313_private_child_session_authority.sql +365 -0
  160. package/drizzle/0314_unregistered_organization_invitations.sql +606 -0
  161. package/drizzle/0315_personal_github_repository_selection.sql +624 -0
  162. package/drizzle/0316_human_confirmed_activation_resumed_generation.sql +869 -0
  163. package/drizzle/0317_session_goal_continuation_hold.sql +64 -0
  164. package/drizzle/0318_session_turn_startup_milestones.sql +115 -0
  165. package/drizzle/0319_event_triggered_automations.sql +254 -0
  166. package/drizzle/0320_pr_review_pack.sql +113 -0
  167. package/drizzle/0321_slack_bot_environment_display_name.sql +15 -0
  168. package/drizzle/0322_session_turns_unclaimed_prompt_trigger_index.sql +5 -0
  169. package/drizzle/0323_organization_private_session_enablement.sql +489 -0
  170. package/drizzle/0324_human_confirmed_company_profile_agent_admin.sql +856 -0
  171. package/drizzle/0325_child_lifecycle_notices.sql +44 -0
  172. package/drizzle/0326_interaction_operation_error_codes.sql +62 -0
  173. package/drizzle/0327_slack_first_task_hint.sql +29 -0
  174. package/drizzle/0328_session_background_commands.sql +590 -0
  175. package/drizzle/0329_slack_orchestration_delivery_events.sql +91 -0
  176. package/drizzle/0330_api_key_descriptions.sql +20 -0
  177. package/drizzle/0331_managed_organization_creation.sql +163 -0
  178. package/drizzle/0332_organization_shared_workspace_control_plane.sql +539 -0
  179. package/drizzle/0333_session_turn_prompt_routing.sql +45 -0
  180. package/drizzle/0334_connected_machine_workspace_root.sql +99 -0
  181. package/drizzle/0335_slack_workspace_routing.sql +460 -0
  182. package/drizzle/0336_atomic_session_fork_visibility.sql +667 -0
  183. package/drizzle/0337_slack_routed_action_handles.sql +189 -0
  184. package/drizzle/0338_atomic_connected_machine_attachments.sql +410 -0
  185. package/drizzle/0339_document_authority_reclassification.sql +1153 -0
  186. package/drizzle/0340_tenancy_backfill_activation_evidence.sql +1347 -0
  187. package/drizzle/0341_slack_routing_probe_organization_fence.sql +109 -0
  188. package/drizzle/0342_slack_route_prompt_single_pending.sql +32 -0
  189. package/drizzle/0343_personal_document_force_rls_lock_repair.sql +146 -0
  190. package/drizzle/0344_private_session_visibility_transition_gate.sql +85 -0
  191. package/drizzle/0345_tenant_scoped_session_tenancy_fence.sql +2839 -0
  192. package/drizzle/0346_document_migration_audit_surface.sql +454 -0
  193. package/drizzle/0347_connection_authority_convergence_evidence.sql +396 -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 +167 -0
  212. package/src/connection-token-resolver.ts +263 -31
  213. package/src/database.ts +87 -2
  214. package/src/editable-artifacts-schema.ts +10 -5
  215. package/src/editable-artifacts.ts +21 -11
  216. package/src/governed-learning-activation-schema.ts +121 -0
  217. package/src/governed-learning-activation.ts +588 -0
  218. package/src/governed-learning-evaluator-schema.ts +72 -0
  219. package/src/governed-learning-evaluator.ts +217 -0
  220. package/src/index.ts +11676 -1550
  221. package/src/insights.ts +107 -0
  222. package/src/integration-bindings.ts +88 -6
  223. package/src/integration-facets.ts +287 -84
  224. package/src/interaction-placement-loss.ts +234 -0
  225. package/src/managed-human-provisioning.ts +116 -0
  226. package/src/memory-domain.ts +27 -32
  227. package/src/migrate.ts +77 -1
  228. package/src/new-session-drafts.ts +229 -35
  229. package/src/organization-membership-backfill.ts +735 -0
  230. package/src/organization-membership-lifecycle.ts +995 -0
  231. package/src/pr-review.ts +890 -0
  232. package/src/preference-registry.ts +31 -1
  233. package/src/provision-roles.ts +905 -6
  234. package/src/runtime-posture-cli.ts +2 -0
  235. package/src/runtime-posture.ts +1317 -72
  236. package/src/schema.ts +3316 -428
  237. package/src/scoped-knowledge-schema.ts +16 -8
  238. package/src/scoped-knowledge.ts +1 -1
  239. package/src/session-background-commands.ts +759 -0
  240. package/src/session-control.ts +640 -74
  241. package/src/session-goal-pacing.ts +126 -0
  242. package/src/session-queue-commands.ts +441 -85
  243. package/src/session-realtime-context.ts +4 -6
  244. package/src/session-realtime-ledger.ts +28 -14
  245. package/src/session-realtime-mirror.ts +1 -1
  246. package/src/session-tenancy.ts +410 -49
  247. package/src/session-tool-call-settlement.ts +38 -29
  248. package/src/slack-routing-personal-workspace.ts +67 -0
  249. package/src/slack-routing.ts +867 -0
  250. package/src/slack-task-policy-schema.ts +5 -0
  251. package/src/slack-task-policy.ts +18 -0
  252. package/src/slack-user-link-access.ts +138 -11
  253. package/src/task-notes-schema.ts +74 -0
  254. package/src/task-notes.ts +124 -2
  255. package/src/turn-initiator.ts +8 -0
  256. package/src/user-resource-authority.ts +377 -0
  257. package/src/workspace-authority.ts +160 -0
  258. package/src/workspace-instruction-policies-schema.ts +53 -1
  259. package/src/workspace-instruction-policies.ts +528 -77
  260. package/src/workspace-learning-policy.ts +21 -5
  261. package/src/workspace-membership-permissions.ts +9 -0
  262. package/dist/chunk-4SR4HKKA.js.map +0 -1
  263. package/dist/chunk-6ZYKCRFO.js.map +0 -1
  264. package/dist/chunk-NXAFLCQX.js +0 -2468
  265. package/dist/chunk-NXAFLCQX.js.map +0 -1
  266. package/dist/chunk-SK7YYHBI.js.map +0 -1
  267. package/dist/chunk-WD5ROSLL.js +0 -117
  268. package/dist/chunk-WD5ROSLL.js.map +0 -1
  269. package/dist/chunk-ZWREYEWA.js.map +0 -1
  270. /package/dist/{chunk-CUPM3FGB.js.map → chunk-2PRS4J5Q.js.map} +0 -0
  271. /package/dist/{chunk-LTG3S6ZY.js.map → chunk-E6CLMKEE.js.map} +0 -0
@@ -0,0 +1,396 @@
1
+ -- deployment-mode: rolling
2
+ -- Bounded, tenant-fenced, actionable evidence for every connection
3
+ -- authority row that has not reached one of migration 0340's terminal shapes.
4
+
5
+ SET LOCAL lock_timeout = '5s';
6
+ SET LOCAL statement_timeout = '10min';
7
+
8
+ -- The inspector needs owner visibility through FORCE RLS, but it must not
9
+ -- reuse 0340's write-capable backfill capability. A target-schema-local token
10
+ -- also prevents one OpenGeni schema from authorizing another schema in the
11
+ -- same database. The token is exact to backend, transaction, organization,
12
+ -- and invocation, and the runtime role has no table privileges.
13
+ CREATE TABLE connection_authority_convergence_audit_capabilities (
14
+ capability_id uuid PRIMARY KEY,
15
+ backend_pid integer NOT NULL,
16
+ transaction_id xid8 NOT NULL,
17
+ account_id uuid NOT NULL,
18
+ created_at timestamptz NOT NULL DEFAULT pg_catalog.clock_timestamp()
19
+ );
20
+ REVOKE ALL ON TABLE connection_authority_convergence_audit_capabilities FROM PUBLIC;
21
+
22
+ CREATE FUNCTION connection_authority_convergence_audit_capability_active(
23
+ p_account_id uuid
24
+ ) RETURNS boolean
25
+ LANGUAGE sql STABLE SECURITY DEFINER
26
+ SET search_path FROM CURRENT
27
+ AS $capability$
28
+ SELECT EXISTS (
29
+ SELECT 1
30
+ FROM connection_authority_convergence_audit_capabilities capability
31
+ WHERE capability.capability_id::text = nullif(pg_catalog.current_setting(
32
+ 'opengeni.connection_authority_convergence_audit_token', true
33
+ ), '')
34
+ AND capability.backend_pid = pg_catalog.pg_backend_pid()
35
+ AND capability.transaction_id = pg_catalog.pg_current_xact_id_if_assigned()
36
+ AND capability.account_id = p_account_id
37
+ )
38
+ $capability$;
39
+ REVOKE ALL ON FUNCTION
40
+ connection_authority_convergence_audit_capability_active(uuid) FROM PUBLIC;
41
+ -- These policies protect shared tables whose owners and SECURITY DEFINER
42
+ -- callers are not all known when this migration runs. The predicate exposes
43
+ -- only a boolean and cannot create or inspect the backend/xid/token-bound
44
+ -- capability, so every policy-evaluating role may execute it safely.
45
+ GRANT EXECUTE ON FUNCTION
46
+ connection_authority_convergence_audit_capability_active(uuid) TO PUBLIC;
47
+
48
+ DO $connection_authority_convergence_audit_policies$
49
+ DECLARE
50
+ data_schema text := pg_catalog.current_schema();
51
+ migration_owner text := current_user;
52
+ table_name text;
53
+ BEGIN
54
+ FOREACH table_name IN ARRAY ARRAY[
55
+ 'connections',
56
+ 'organization_memberships',
57
+ 'organization_user_resource_authorities'
58
+ ] LOOP
59
+ EXECUTE pg_catalog.format(
60
+ 'CREATE POLICY connection_authority_convergence_audit_read ON %I.%I '
61
+ || 'FOR SELECT USING (current_user = %L AND '
62
+ || '%I.connection_authority_convergence_audit_capability_active(account_id))',
63
+ data_schema, table_name, migration_owner, data_schema
64
+ );
65
+ END LOOP;
66
+ END
67
+ $connection_authority_convergence_audit_policies$;
68
+
69
+ CREATE FUNCTION inspect_organization_connection_authority_convergence(
70
+ p_account_id uuid,
71
+ p_limit integer DEFAULT 100,
72
+ p_after_connection_id uuid DEFAULT NULL
73
+ ) RETURNS jsonb
74
+ LANGUAGE plpgsql SECURITY DEFINER
75
+ SET search_path FROM CURRENT
76
+ SET statement_timeout = '1min'
77
+ AS $inspection$
78
+ DECLARE
79
+ audit_capability_id uuid := pg_catalog.gen_random_uuid();
80
+ previous_audit_token text := pg_catalog.current_setting(
81
+ 'opengeni.connection_authority_convergence_audit_token', true
82
+ );
83
+ report jsonb;
84
+ BEGIN
85
+ IF p_account_id IS NULL THEN
86
+ RAISE EXCEPTION 'connection convergence inspection requires an organization id'
87
+ USING ERRCODE = '22004';
88
+ END IF;
89
+ IF p_account_id IS DISTINCT FROM nullif(
90
+ pg_catalog.current_setting('opengeni.account_id', true), ''
91
+ )::uuid THEN
92
+ RAISE EXCEPTION 'connection convergence inspection scope mismatch'
93
+ USING ERRCODE = '42501';
94
+ END IF;
95
+ IF p_limit IS NULL OR p_limit NOT BETWEEN 1 AND 100 THEN
96
+ RAISE EXCEPTION 'connection convergence inspection limit must be 1..100'
97
+ USING ERRCODE = '22023';
98
+ END IF;
99
+
100
+ INSERT INTO connection_authority_convergence_audit_capabilities (
101
+ capability_id, backend_pid, transaction_id, account_id
102
+ ) VALUES (
103
+ audit_capability_id, pg_catalog.pg_backend_pid(),
104
+ pg_catalog.pg_current_xact_id(), p_account_id
105
+ );
106
+ PERFORM pg_catalog.set_config(
107
+ 'opengeni.connection_authority_convergence_audit_token',
108
+ audit_capability_id::text,
109
+ true
110
+ );
111
+
112
+ -- A cursor is an organization-scoped persisted identifier, not an arbitrary
113
+ -- UUID that may be used as a cross-tenant ordering oracle.
114
+ IF p_after_connection_id IS NOT NULL AND NOT EXISTS (
115
+ SELECT 1
116
+ FROM connections connection_row
117
+ WHERE connection_row.account_id = p_account_id
118
+ AND connection_row.id = p_after_connection_id
119
+ ) THEN
120
+ RAISE EXCEPTION 'connection convergence inspection cursor is invalid'
121
+ USING ERRCODE = '22023';
122
+ END IF;
123
+
124
+ WITH classified AS MATERIALIZED (
125
+ SELECT
126
+ connection_row.id AS connection_id,
127
+ connection_row.subject_id,
128
+ CASE
129
+ -- These are migration 0340's two terminal shapes. Exact terminal rows
130
+ -- never appear in residual evidence.
131
+ WHEN connection_row.authority_scope = 'workspace'
132
+ AND connection_row.subject_id IS NULL
133
+ AND connection_row.authority_id IS NULL
134
+ AND connection_row.owner_organization_membership_id IS NULL
135
+ AND connection_row.origin_workspace_id = connection_row.workspace_id
136
+ THEN NULL
137
+ WHEN connection_row.authority_scope = 'user'
138
+ AND connection_row.subject_id IS NOT NULL
139
+ AND authority.id = connection_row.authority_id
140
+ AND authority.resource_kind = 'connection'
141
+ AND authority.resource_id = connection_row.id
142
+ AND authority.organization_membership_id
143
+ = connection_row.owner_organization_membership_id
144
+ AND authority.origin_workspace_id = connection_row.origin_workspace_id
145
+ AND authority.status = 'active'
146
+ AND authority.revoked_at IS NULL
147
+ AND owner_membership.id = connection_row.owner_organization_membership_id
148
+ AND owner_membership.subject_id = connection_row.subject_id
149
+ AND owner_membership.status = 'active'
150
+ AND owner_membership.revoked_at IS NULL
151
+ THEN NULL
152
+
153
+ -- Only the exact legacy shape is eligible for an automated 0340
154
+ -- transition. Malformed user or legacy rows need incident repair.
155
+ WHEN connection_row.authority_scope = 'legacy_user'
156
+ AND connection_row.authority_id IS NULL
157
+ AND connection_row.owner_organization_membership_id IS NULL
158
+ AND live_membership.id IS NOT NULL
159
+ THEN 'connection_backfill_ready'
160
+ WHEN connection_row.authority_scope = 'legacy_user'
161
+ AND connection_row.authority_id IS NULL
162
+ AND connection_row.owner_organization_membership_id IS NULL
163
+ AND terminal_membership.id IS NOT NULL
164
+ THEN 'membership_lifecycle_review_required'
165
+ WHEN connection_row.authority_scope = 'legacy_user'
166
+ AND connection_row.authority_id IS NULL
167
+ AND connection_row.owner_organization_membership_id IS NULL
168
+ AND (connection_row.subject_id IS NULL
169
+ OR connection_row.subject_id NOT LIKE 'user:%')
170
+ THEN 'external_subject_requires_classification'
171
+ WHEN connection_row.authority_scope = 'legacy_user'
172
+ AND connection_row.authority_id IS NULL
173
+ AND connection_row.owner_organization_membership_id IS NULL
174
+ AND login.id IS NULL
175
+ THEN 'missing_login_identity'
176
+ WHEN connection_row.authority_scope = 'legacy_user'
177
+ AND connection_row.authority_id IS NULL
178
+ AND connection_row.owner_organization_membership_id IS NULL
179
+ AND (
180
+ account.external_source IS DISTINCT FROM 'better-auth:user'
181
+ OR account.external_id IS DISTINCT FROM substring(
182
+ connection_row.subject_id FROM 6
183
+ )
184
+ )
185
+ THEN 'organization_identity_mismatch'
186
+ WHEN connection_row.authority_scope = 'legacy_user'
187
+ AND connection_row.authority_id IS NULL
188
+ AND connection_row.owner_organization_membership_id IS NULL
189
+ AND owner_access.id IS NULL
190
+ THEN 'missing_owner_workspace_membership'
191
+ WHEN connection_row.authority_scope = 'legacy_user'
192
+ AND connection_row.authority_id IS NULL
193
+ AND connection_row.owner_organization_membership_id IS NULL
194
+ THEN 'membership_backfill_eligible'
195
+ WHEN connection_row.authority_scope = 'user'
196
+ THEN 'conflicting_authority_rows'
197
+ ELSE 'legacy_shape_unrecognized'
198
+ END AS classification
199
+ FROM connections connection_row
200
+ JOIN managed_accounts account ON account.id = connection_row.account_id
201
+ LEFT JOIN organization_memberships live_membership
202
+ ON live_membership.account_id = connection_row.account_id
203
+ AND live_membership.subject_id = connection_row.subject_id
204
+ AND live_membership.status = 'active'
205
+ AND live_membership.revoked_at IS NULL
206
+ LEFT JOIN organization_memberships owner_membership
207
+ ON owner_membership.id = connection_row.owner_organization_membership_id
208
+ AND owner_membership.account_id = connection_row.account_id
209
+ LEFT JOIN LATERAL (
210
+ SELECT membership.id
211
+ FROM organization_memberships membership
212
+ WHERE membership.account_id = connection_row.account_id
213
+ AND membership.subject_id = connection_row.subject_id
214
+ AND (
215
+ membership.status IN ('suspended', 'revoked')
216
+ OR membership.revoked_at IS NOT NULL
217
+ )
218
+ ORDER BY membership.id
219
+ LIMIT 1
220
+ ) terminal_membership ON true
221
+ LEFT JOIN organization_user_resource_authorities authority
222
+ ON authority.id = connection_row.authority_id
223
+ AND authority.account_id = connection_row.account_id
224
+ LEFT JOIN auth_users login
225
+ ON connection_row.subject_id LIKE 'user:%'
226
+ AND login.id = substring(connection_row.subject_id FROM 6)
227
+ LEFT JOIN LATERAL (
228
+ SELECT access.id
229
+ FROM workspace_memberships access
230
+ JOIN workspaces workspace
231
+ ON workspace.id = access.workspace_id
232
+ AND workspace.account_id = access.account_id
233
+ WHERE access.account_id = connection_row.account_id
234
+ AND access.subject_id = connection_row.subject_id
235
+ AND access.role = 'owner'
236
+ ORDER BY access.id
237
+ LIMIT 1
238
+ ) owner_access ON true
239
+ WHERE connection_row.account_id = p_account_id
240
+ ), residual AS MATERIALIZED (
241
+ SELECT
242
+ connection_id,
243
+ subject_id,
244
+ classification,
245
+ CASE classification
246
+ WHEN 'connection_backfill_ready'
247
+ THEN 'run_connection_backfill'
248
+ WHEN 'membership_backfill_eligible'
249
+ THEN 'run_membership_backfill_then_connection_backfill'
250
+ WHEN 'membership_lifecycle_review_required'
251
+ THEN 'review_membership_lifecycle_do_not_reactivate_automatically'
252
+ WHEN 'external_subject_requires_classification'
253
+ THEN 'classify_external_subject_then_migrate_via_authorized_connection_lifecycle'
254
+ WHEN 'missing_login_identity'
255
+ THEN 'restore_login_identity_then_recheck'
256
+ WHEN 'organization_identity_mismatch'
257
+ THEN 'correct_organization_identity_through_supported_account_lifecycle_then_recheck'
258
+ WHEN 'missing_owner_workspace_membership'
259
+ THEN 'establish_owner_workspace_membership_through_supported_membership_lifecycle_then_recheck'
260
+ WHEN 'conflicting_authority_rows'
261
+ THEN 'repair_conflicting_connection_authority_rows_under_incident_procedure'
262
+ ELSE 'repair_unrecognized_connection_authority_shape_under_incident_procedure'
263
+ END AS action
264
+ FROM classified
265
+ WHERE classification IS NOT NULL
266
+ ), page_candidates AS MATERIALIZED (
267
+ SELECT *
268
+ FROM residual
269
+ WHERE p_after_connection_id IS NULL
270
+ OR connection_id > p_after_connection_id
271
+ ORDER BY connection_id
272
+ LIMIT p_limit + 1
273
+ ), page AS MATERIALIZED (
274
+ SELECT * FROM page_candidates ORDER BY connection_id LIMIT p_limit
275
+ ), aggregate AS (
276
+ SELECT
277
+ (SELECT coalesce(pg_catalog.jsonb_agg(pg_catalog.jsonb_build_object(
278
+ 'connectionId', page.connection_id,
279
+ 'subjectId', page.subject_id,
280
+ 'classification', page.classification,
281
+ 'action', page.action
282
+ ) ORDER BY page.connection_id), '[]'::jsonb) FROM page) AS items,
283
+ (SELECT count(*)::int FROM page) AS returned,
284
+ (SELECT count(*) > p_limit FROM page_candidates) AS has_more,
285
+ (SELECT connection_id FROM page ORDER BY connection_id DESC LIMIT 1) AS next_id,
286
+ count(*)::int AS remaining_total,
287
+ count(*) FILTER (WHERE classification IN (
288
+ 'connection_backfill_ready', 'membership_backfill_eligible'
289
+ ))::int AS auto_remediable,
290
+ count(*) FILTER (WHERE classification NOT IN (
291
+ 'connection_backfill_ready', 'membership_backfill_eligible'
292
+ ))::int AS manual_review,
293
+ pg_catalog.jsonb_build_object(
294
+ 'connectionBackfillReady', count(*) FILTER (
295
+ WHERE classification = 'connection_backfill_ready'
296
+ )::int,
297
+ 'membershipBackfillEligible', count(*) FILTER (
298
+ WHERE classification = 'membership_backfill_eligible'
299
+ )::int,
300
+ 'membershipLifecycleReviewRequired', count(*) FILTER (
301
+ WHERE classification = 'membership_lifecycle_review_required'
302
+ )::int,
303
+ 'externalSubjectRequiresClassification', count(*) FILTER (
304
+ WHERE classification = 'external_subject_requires_classification'
305
+ )::int,
306
+ 'missingLoginIdentity', count(*) FILTER (
307
+ WHERE classification = 'missing_login_identity'
308
+ )::int,
309
+ 'organizationIdentityMismatch', count(*) FILTER (
310
+ WHERE classification = 'organization_identity_mismatch'
311
+ )::int,
312
+ 'missingOwnerWorkspaceMembership', count(*) FILTER (
313
+ WHERE classification = 'missing_owner_workspace_membership'
314
+ )::int,
315
+ 'conflictingAuthorityRows', count(*) FILTER (
316
+ WHERE classification = 'conflicting_authority_rows'
317
+ )::int,
318
+ 'legacyShapeUnrecognized', count(*) FILTER (
319
+ WHERE classification = 'legacy_shape_unrecognized'
320
+ )::int
321
+ ) AS by_classification
322
+ FROM residual
323
+ )
324
+ SELECT pg_catalog.jsonb_build_object(
325
+ 'schemaVersion', 1,
326
+ 'organizationId', p_account_id,
327
+ 'limit', p_limit,
328
+ 'afterConnectionId', p_after_connection_id,
329
+ 'items', aggregate.items,
330
+ 'returned', aggregate.returned,
331
+ 'hasMore', aggregate.has_more,
332
+ 'nextCursor', CASE WHEN aggregate.has_more THEN aggregate.next_id ELSE NULL END,
333
+ 'remaining', pg_catalog.jsonb_build_object(
334
+ 'total', aggregate.remaining_total,
335
+ 'autoRemediable', aggregate.auto_remediable,
336
+ 'manualReview', aggregate.manual_review,
337
+ 'byClassification', aggregate.by_classification
338
+ )
339
+ ) INTO report
340
+ FROM aggregate;
341
+
342
+ DELETE FROM connection_authority_convergence_audit_capabilities
343
+ WHERE capability_id = audit_capability_id;
344
+ PERFORM pg_catalog.set_config(
345
+ 'opengeni.connection_authority_convergence_audit_token',
346
+ coalesce(previous_audit_token, ''),
347
+ true
348
+ );
349
+ RETURN report;
350
+ EXCEPTION WHEN OTHERS THEN
351
+ DELETE FROM connection_authority_convergence_audit_capabilities
352
+ WHERE capability_id = audit_capability_id;
353
+ PERFORM pg_catalog.set_config(
354
+ 'opengeni.connection_authority_convergence_audit_token',
355
+ coalesce(previous_audit_token, ''),
356
+ true
357
+ );
358
+ RAISE;
359
+ END
360
+ $inspection$;
361
+ REVOKE ALL ON FUNCTION inspect_organization_connection_authority_convergence(
362
+ uuid, integer, uuid
363
+ ) FROM PUBLIC;
364
+
365
+ DO $connection_authority_convergence_audit_hardening$
366
+ DECLARE
367
+ data_schema text := pg_catalog.current_schema();
368
+ BEGIN
369
+ EXECUTE pg_catalog.format(
370
+ 'ALTER FUNCTION %I.connection_authority_convergence_audit_capability_active(uuid) '
371
+ || 'SET search_path = pg_catalog, %I, pg_temp',
372
+ data_schema, data_schema
373
+ );
374
+ EXECUTE pg_catalog.format(
375
+ 'ALTER FUNCTION %I.inspect_organization_connection_authority_convergence(uuid,integer,uuid) '
376
+ || 'SET search_path = pg_catalog, %I, pg_temp',
377
+ data_schema, data_schema
378
+ );
379
+
380
+ IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'opengeni_app') THEN
381
+ EXECUTE pg_catalog.format(
382
+ 'GRANT EXECUTE ON FUNCTION %I.inspect_organization_connection_authority_convergence(uuid,integer,uuid) TO opengeni_app',
383
+ data_schema
384
+ );
385
+ END IF;
386
+ END
387
+ $connection_authority_convergence_audit_hardening$;
388
+
389
+ COMMENT ON TABLE connection_authority_convergence_audit_capabilities IS
390
+ 'Invocation-scoped, target-local read capability for connection convergence evidence.';
391
+ COMMENT ON FUNCTION connection_authority_convergence_audit_capability_active(uuid) IS
392
+ 'True only for the exact backend, transaction, organization, and opaque convergence-audit token.';
393
+ COMMENT ON FUNCTION inspect_organization_connection_authority_convergence(
394
+ uuid, integer, uuid
395
+ ) IS
396
+ 'Bounded tenant-fenced residual connection evidence with global remaining counts and fixed remediation actions. Never writes authority.';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/db",
3
- "version": "1.0.1",
3
+ "version": "3.2.0-canary.0",
4
4
  "description": "OpenGeni persistence: Drizzle schema, RLS-scoped query layer, the SQL migration runner, and role provisioning.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -54,6 +54,10 @@
54
54
  "./session-tenancy": {
55
55
  "types": "./dist/session-tenancy.d.ts",
56
56
  "import": "./dist/session-tenancy.js"
57
+ },
58
+ "./session-background-commands": {
59
+ "types": "./dist/session-background-commands.d.ts",
60
+ "import": "./dist/session-background-commands.js"
57
61
  }
58
62
  },
59
63
  "publishConfig": {
@@ -70,11 +74,11 @@
70
74
  "prepublishOnly": "bash ../../scripts/prepublish-guard"
71
75
  },
72
76
  "dependencies": {
73
- "@opengeni/codemode": "^0.4.4",
74
- "@opengeni/codex": "^0.2.17",
75
- "@opengeni/config": "^0.16.4",
76
- "@opengeni/contracts": "^1.0.1",
77
- "@opengeni/network": "^0.2.2",
77
+ "@opengeni/codemode": "^0.4.13-canary.0",
78
+ "@opengeni/codex": "^0.2.19-canary.0",
79
+ "@opengeni/config": "^0.19.1-canary.0",
80
+ "@opengeni/contracts": "^2.3.0-canary.0",
81
+ "@opengeni/network": "^0.2.3-canary.0",
78
82
  "drizzle-orm": "^0.45.2",
79
83
  "postgres": "^3.4.7"
80
84
  },