@lobu/cli 6.0.0 → 6.1.1

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 (222) hide show
  1. package/README.md +20 -27
  2. package/dist/bundled-skills/lobu/SKILL.md +12 -12
  3. package/dist/commands/_lib/apply/apply-cmd.d.ts +2 -0
  4. package/dist/commands/_lib/apply/apply-cmd.d.ts.map +1 -1
  5. package/dist/commands/_lib/apply/apply-cmd.js +26 -0
  6. package/dist/commands/_lib/apply/apply-cmd.js.map +1 -1
  7. package/dist/commands/_lib/apply/client.d.ts +1 -1
  8. package/dist/commands/_lib/apply/client.d.ts.map +1 -1
  9. package/dist/commands/_lib/apply/desired-state.js +6 -6
  10. package/dist/commands/_lib/apply/desired-state.js.map +1 -1
  11. package/dist/commands/agent.d.ts +7 -0
  12. package/dist/commands/agent.d.ts.map +1 -1
  13. package/dist/commands/agent.js +65 -1
  14. package/dist/commands/agent.js.map +1 -1
  15. package/dist/commands/chat.d.ts +12 -9
  16. package/dist/commands/chat.d.ts.map +1 -1
  17. package/dist/commands/chat.js +117 -56
  18. package/dist/commands/chat.js.map +1 -1
  19. package/dist/commands/dev.d.ts +15 -7
  20. package/dist/commands/dev.d.ts.map +1 -1
  21. package/dist/commands/dev.js +79 -44
  22. package/dist/commands/dev.js.map +1 -1
  23. package/dist/commands/doctor.d.ts +1 -0
  24. package/dist/commands/doctor.d.ts.map +1 -1
  25. package/dist/commands/doctor.js +136 -0
  26. package/dist/commands/doctor.js.map +1 -1
  27. package/dist/commands/eval.d.ts +8 -0
  28. package/dist/commands/eval.d.ts.map +1 -1
  29. package/dist/commands/eval.js +56 -1
  30. package/dist/commands/eval.js.map +1 -1
  31. package/dist/commands/init.d.ts +20 -5
  32. package/dist/commands/init.d.ts.map +1 -1
  33. package/dist/commands/init.js +332 -183
  34. package/dist/commands/init.js.map +1 -1
  35. package/dist/commands/link.d.ts +11 -0
  36. package/dist/commands/link.d.ts.map +1 -0
  37. package/dist/commands/link.js +28 -0
  38. package/dist/commands/link.js.map +1 -0
  39. package/dist/commands/login.d.ts.map +1 -1
  40. package/dist/commands/login.js +14 -2
  41. package/dist/commands/login.js.map +1 -1
  42. package/dist/commands/memory/_lib/browser-auth-cmd.d.ts.map +1 -1
  43. package/dist/commands/memory/_lib/browser-auth-cmd.js +4 -4
  44. package/dist/commands/memory/_lib/browser-auth-cmd.js.map +1 -1
  45. package/dist/commands/memory/_lib/install-targets.d.ts.map +1 -1
  46. package/dist/commands/memory/_lib/install-targets.js +1 -5
  47. package/dist/commands/memory/_lib/install-targets.js.map +1 -1
  48. package/dist/commands/memory/_lib/mcp.d.ts +2 -2
  49. package/dist/commands/memory/_lib/mcp.d.ts.map +1 -1
  50. package/dist/commands/memory/_lib/mcp.js +24 -12
  51. package/dist/commands/memory/_lib/mcp.js.map +1 -1
  52. package/dist/commands/memory/_lib/openclaw-auth.d.ts +1 -0
  53. package/dist/commands/memory/_lib/openclaw-auth.d.ts.map +1 -1
  54. package/dist/commands/memory/_lib/openclaw-auth.js +14 -3
  55. package/dist/commands/memory/_lib/openclaw-auth.js.map +1 -1
  56. package/dist/commands/memory/_lib/openclaw-cmd.js +1 -1
  57. package/dist/commands/memory/_lib/openclaw-cmd.js.map +1 -1
  58. package/dist/commands/memory/_lib/schema.d.ts +2 -2
  59. package/dist/commands/memory/_lib/schema.d.ts.map +1 -1
  60. package/dist/commands/memory/_lib/schema.js +3 -3
  61. package/dist/commands/memory/_lib/schema.js.map +1 -1
  62. package/dist/commands/memory/_lib/seed-cmd.d.ts.map +1 -1
  63. package/dist/commands/memory/_lib/seed-cmd.js +5 -6
  64. package/dist/commands/memory/_lib/seed-cmd.js.map +1 -1
  65. package/dist/commands/memory/run.d.ts.map +1 -1
  66. package/dist/commands/memory/run.js +2 -2
  67. package/dist/commands/memory/run.js.map +1 -1
  68. package/dist/commands/platforms/platform-prompts.d.ts +0 -1
  69. package/dist/commands/platforms/platform-prompts.d.ts.map +1 -1
  70. package/dist/commands/platforms/platform-prompts.js +54 -8
  71. package/dist/commands/platforms/platform-prompts.js.map +1 -1
  72. package/dist/commands/telemetry.d.ts +10 -0
  73. package/dist/commands/telemetry.d.ts.map +1 -0
  74. package/dist/commands/telemetry.js +68 -0
  75. package/dist/commands/telemetry.js.map +1 -0
  76. package/dist/commands/whoami.d.ts.map +1 -1
  77. package/dist/commands/whoami.js +1 -1
  78. package/dist/commands/whoami.js.map +1 -1
  79. package/dist/connectors/README.md +534 -0
  80. package/dist/connectors/__tests__/browser-scraper-utils.test.ts +186 -0
  81. package/dist/connectors/browser-scraper-utils.ts +214 -0
  82. package/dist/connectors/capterra.ts +273 -0
  83. package/dist/connectors/g2.ts +286 -0
  84. package/dist/connectors/github.ts +1553 -0
  85. package/dist/connectors/glassdoor.ts +291 -0
  86. package/dist/connectors/gmaps.ts +197 -0
  87. package/dist/connectors/google_calendar.ts +631 -0
  88. package/dist/connectors/google_gmail.ts +751 -0
  89. package/dist/connectors/google_photos.ts +776 -0
  90. package/dist/connectors/google_play.ts +342 -0
  91. package/dist/connectors/hackernews.ts +471 -0
  92. package/dist/connectors/index.ts +23 -0
  93. package/dist/connectors/ios_appstore.ts +226 -0
  94. package/dist/connectors/linkedin.ts +471 -0
  95. package/dist/connectors/microsoft_outlook.ts +410 -0
  96. package/dist/connectors/producthunt.ts +471 -0
  97. package/dist/connectors/reddit.ts +600 -0
  98. package/dist/connectors/rss.ts +448 -0
  99. package/dist/connectors/spotify.ts +590 -0
  100. package/dist/connectors/trustpilot.ts +199 -0
  101. package/dist/connectors/website.ts +629 -0
  102. package/dist/connectors/whatsapp.ts +1073 -0
  103. package/dist/connectors/x.ts +526 -0
  104. package/dist/connectors/youtube.ts +666 -0
  105. package/dist/db/migrations/00000000000000_baseline.sql +4867 -0
  106. package/dist/db/migrations/20260405193000_add_mcp_sessions.sql +33 -0
  107. package/dist/db/migrations/20260408120000_remove_system_connectors.sql +48 -0
  108. package/dist/db/migrations/20260408120001_optional_compiled_code.sql +6 -0
  109. package/dist/db/migrations/20260409110000_add_active_watcher_run_index.sql +9 -0
  110. package/dist/db/migrations/20260409130000_connector_default_config.sql +5 -0
  111. package/dist/db/migrations/20260410120000_add_agent_secrets.sql +25 -0
  112. package/dist/db/migrations/20260413170000_add_watcher_group_id.sql +67 -0
  113. package/dist/db/migrations/20260416120000_add_entity_wa_jid_index.sql +14 -0
  114. package/dist/db/migrations/20260417100000_add_entity_identities.sql +77 -0
  115. package/dist/db/migrations/20260418100000_add_auth_runs.sql +83 -0
  116. package/dist/db/migrations/20260418110000_add_runs_created_by_user.sql +18 -0
  117. package/dist/db/migrations/20260419120000_add_event_identity_indexes.sql +56 -0
  118. package/dist/db/migrations/20260420120000_extend_reserved_org_slugs.sql +56 -0
  119. package/dist/db/migrations/20260424030000_add_watcher_run_correlation.sql +52 -0
  120. package/dist/db/migrations/20260424130000_relax_events_client_id_fk.sql +47 -0
  121. package/dist/db/migrations/20260425100000_normalize_watcher_feedback.sql +91 -0
  122. package/dist/db/migrations/20260425120000_add_run_diagnostics.sql +20 -0
  123. package/dist/db/migrations/20260425130000_add_repair_agent_plumbing.sql +46 -0
  124. package/dist/db/migrations/20260426120000_entities_entity_type_fk.sql +101 -0
  125. package/dist/db/migrations/20260426130000_db_integrity_cleanup.sql +104 -0
  126. package/dist/db/migrations/20260426130001_db_integrity_cleanup_concurrent.sql +187 -0
  127. package/dist/db/migrations/20260427133000_events_created_by_nullable.sql +74 -0
  128. package/dist/db/migrations/20260427140000_identity_engine_indexes.sql +140 -0
  129. package/dist/db/migrations/20260427150000_drop_events_source_id.sql +177 -0
  130. package/dist/db/migrations/20260427160000_drop_dead_schema.sql +76 -0
  131. package/dist/db/migrations/20260427170000_market_founder_to_member.sql +364 -0
  132. package/dist/db/migrations/20260428040000_cascade_events_watchers_org_fk.sql +66 -0
  133. package/dist/db/migrations/20260428050000_add_runs_approved_input.sql +9 -0
  134. package/dist/db/migrations/20260429010000_auth_profile_tenant_scoped_fk.sql +79 -0
  135. package/dist/db/migrations/20260429060000_extend_runs_for_lobu_queue.sql +108 -0
  136. package/dist/db/migrations/20260429120000_agent_changed_notify.sql +97 -0
  137. package/dist/db/migrations/20260429120100_user_auth_profiles_and_model_prefs.sql +36 -0
  138. package/dist/db/migrations/20260429120200_fix_notify_old_keys.sql +130 -0
  139. package/dist/db/migrations/20260429130000_oauth_states_cli_sessions_rate_limits.sql +83 -0
  140. package/dist/db/migrations/20260429140000_phase8_grants_chat_connections_mcp_sessions.sql +84 -0
  141. package/dist/db/migrations/20260429140100_runs_priority_expires_at_retry_delay.sql +44 -0
  142. package/dist/db/migrations/20260429180000_drop_invalidatable_cache_triggers.sql +25 -0
  143. package/dist/db/migrations/20260430005614_agents_apply_fields.sql +21 -0
  144. package/dist/db/migrations/20260430022231_fix_connection_config_encryption.sql +69 -0
  145. package/dist/db/migrations/20260430151215_add_task_run_type.sql +77 -0
  146. package/dist/db/migrations/20260501000000_drop_cli_sessions.sql +27 -0
  147. package/dist/db/migrations/20260501133000_lobu_memory_mcp_id.sql +117 -0
  148. package/dist/db/migrations/20260502000000_drop_chat_connections.sql +60 -0
  149. package/dist/db/migrations/20260503000000_agent_secrets_org_scope.sql +56 -0
  150. package/dist/db/migrations/20260504000000_flatten_agents_drop_sandbox_model.sql +48 -0
  151. package/dist/index.d.ts.map +1 -1
  152. package/dist/index.js +147 -23
  153. package/dist/index.js.map +1 -1
  154. package/dist/internal/api-client.d.ts +4 -8
  155. package/dist/internal/api-client.d.ts.map +1 -1
  156. package/dist/internal/api-client.js +1 -1
  157. package/dist/internal/api-client.js.map +1 -1
  158. package/dist/internal/context.js +2 -2
  159. package/dist/internal/context.js.map +1 -1
  160. package/dist/internal/credentials.d.ts.map +1 -1
  161. package/dist/internal/credentials.js +6 -1
  162. package/dist/internal/credentials.js.map +1 -1
  163. package/dist/internal/index.d.ts +2 -3
  164. package/dist/internal/index.d.ts.map +1 -1
  165. package/dist/internal/index.js +2 -2
  166. package/dist/internal/index.js.map +1 -1
  167. package/dist/internal/oauth.d.ts +7 -6
  168. package/dist/internal/oauth.d.ts.map +1 -1
  169. package/dist/internal/oauth.js +3 -3
  170. package/dist/internal/project-link.d.ts +10 -0
  171. package/dist/internal/project-link.d.ts.map +1 -0
  172. package/dist/internal/project-link.js +48 -0
  173. package/dist/internal/project-link.js.map +1 -0
  174. package/dist/providers.json +2 -2
  175. package/dist/server.bundle.mjs +3173 -4404
  176. package/dist/start-local.bundle.mjs +71481 -0
  177. package/dist/templates/README.md.tmpl +10 -11
  178. package/package.json +14 -12
  179. package/dist/__tests__/chat.integration.test.d.ts +0 -2
  180. package/dist/__tests__/chat.integration.test.d.ts.map +0 -1
  181. package/dist/__tests__/chat.integration.test.js +0 -337
  182. package/dist/__tests__/chat.integration.test.js.map +0 -1
  183. package/dist/__tests__/dev.test.d.ts +0 -2
  184. package/dist/__tests__/dev.test.d.ts.map +0 -1
  185. package/dist/__tests__/dev.test.js +0 -25
  186. package/dist/__tests__/dev.test.js.map +0 -1
  187. package/dist/__tests__/init-memory.test.d.ts +0 -2
  188. package/dist/__tests__/init-memory.test.d.ts.map +0 -1
  189. package/dist/__tests__/init-memory.test.js +0 -45
  190. package/dist/__tests__/init-memory.test.js.map +0 -1
  191. package/dist/__tests__/token.test.d.ts +0 -2
  192. package/dist/__tests__/token.test.d.ts.map +0 -1
  193. package/dist/__tests__/token.test.js +0 -52
  194. package/dist/__tests__/token.test.js.map +0 -1
  195. package/dist/commands/_lib/apply/__tests__/client.test.d.ts +0 -2
  196. package/dist/commands/_lib/apply/__tests__/client.test.d.ts.map +0 -1
  197. package/dist/commands/_lib/apply/__tests__/client.test.js +0 -23
  198. package/dist/commands/_lib/apply/__tests__/client.test.js.map +0 -1
  199. package/dist/commands/_lib/apply/__tests__/desired-state.test.d.ts +0 -2
  200. package/dist/commands/_lib/apply/__tests__/desired-state.test.d.ts.map +0 -1
  201. package/dist/commands/_lib/apply/__tests__/desired-state.test.js +0 -140
  202. package/dist/commands/_lib/apply/__tests__/desired-state.test.js.map +0 -1
  203. package/dist/commands/_lib/apply/__tests__/diff.test.d.ts +0 -2
  204. package/dist/commands/_lib/apply/__tests__/diff.test.d.ts.map +0 -1
  205. package/dist/commands/_lib/apply/__tests__/diff.test.js +0 -378
  206. package/dist/commands/_lib/apply/__tests__/diff.test.js.map +0 -1
  207. package/dist/commands/apply.d.ts +0 -3
  208. package/dist/commands/apply.d.ts.map +0 -1
  209. package/dist/commands/apply.js +0 -5
  210. package/dist/commands/apply.js.map +0 -1
  211. package/dist/commands/memory/_lib/openclaw-auth.test.d.ts +0 -2
  212. package/dist/commands/memory/_lib/openclaw-auth.test.d.ts.map +0 -1
  213. package/dist/commands/memory/_lib/openclaw-auth.test.js +0 -9
  214. package/dist/commands/memory/_lib/openclaw-auth.test.js.map +0 -1
  215. package/dist/internal/__tests__/api-client.test.d.ts +0 -2
  216. package/dist/internal/__tests__/api-client.test.d.ts.map +0 -1
  217. package/dist/internal/__tests__/api-client.test.js +0 -95
  218. package/dist/internal/__tests__/api-client.test.js.map +0 -1
  219. package/dist/internal/__tests__/context.test.d.ts +0 -2
  220. package/dist/internal/__tests__/context.test.d.ts.map +0 -1
  221. package/dist/internal/__tests__/context.test.js +0 -77
  222. package/dist/internal/__tests__/context.test.js.map +0 -1
@@ -0,0 +1,140 @@
1
+ -- migrate:up
2
+
3
+ -- Identity-engine schema additions.
4
+ --
5
+ -- The follow-up identity engine writes connector-emitted facts as rows in
6
+ -- `events` with `semantic_type='identity_fact'` and stores derivation
7
+ -- provenance as metadata on `entity_relationships`. Auto-create rules live
8
+ -- as JSONB on `entity_relationship_types.metadata` (compiled from YAML by
9
+ -- the seeder). All three shapes need selective indexes so the hot paths
10
+ -- don't full-scan.
11
+ --
12
+ -- Pattern matches the existing per-namespace event metadata indexes added
13
+ -- in 20260419120000_add_event_identity_indexes.sql.
14
+
15
+ -- ── Rule storage on relationship types ─────────────────────────────────
16
+ -- The engine reads each relationship type's `metadata.autoCreateWhen[]` to
17
+ -- decide which rules to fire on each incoming fact. Adding the column up
18
+ -- front (NULL allowed) keeps the seeder change non-destructive.
19
+ ALTER TABLE public.entity_relationship_types
20
+ ADD COLUMN IF NOT EXISTS metadata jsonb;
21
+
22
+ CREATE INDEX IF NOT EXISTS idx_entity_relationship_types_has_auto_create
23
+ ON public.entity_relationship_types ((metadata->'autoCreateWhen'))
24
+ WHERE metadata ? 'autoCreateWhen' AND deleted_at IS NULL;
25
+
26
+ -- ── Identity lookup ─────────────────────────────────────────────────────
27
+ -- "Find the entity in catalog X whose normalized identity value matches
28
+ -- this fact's normalizedValue." Composite expression index keyed on the
29
+ -- (org, namespace, normalizedValue) tuple. Partial: only fact-typed events
30
+ -- get indexed, so total size scales with fact volume (small) not event
31
+ -- volume (huge).
32
+ CREATE INDEX IF NOT EXISTS idx_events_identity_fact_lookup
33
+ ON public.events (
34
+ organization_id,
35
+ (metadata->>'namespace'),
36
+ (metadata->>'normalizedValue')
37
+ )
38
+ WHERE semantic_type = 'identity_fact';
39
+
40
+ -- ── Per-account fact diff ───────────────────────────────────────────────
41
+ -- "Find every active fact for this provider account." Used by the engine
42
+ -- to diff prior facts vs current set on refresh — drops fall out of the
43
+ -- result and get superseded. Keyed on `providerStableId` (not
44
+ -- `sourceAccountId`): BetterAuth may issue a fresh account row on
45
+ -- reconnect; we want facts to chain across that boundary.
46
+ CREATE INDEX IF NOT EXISTS idx_events_identity_fact_account
47
+ ON public.events (
48
+ connector_key,
49
+ (metadata->>'providerStableId'),
50
+ (metadata->>'namespace')
51
+ )
52
+ WHERE semantic_type = 'identity_fact';
53
+
54
+ -- ── Provenance reverse-lookup ───────────────────────────────────────────
55
+ -- "Find every relationship derived from this fact event." Used at
56
+ -- revocation: when a fact is superseded, find auto-created relationships
57
+ -- that referenced its event_id and revoke them.
58
+ CREATE INDEX IF NOT EXISTS idx_entity_relationships_derived_from_event
59
+ ON public.entity_relationships (
60
+ ((metadata->'derivedFrom'->>'sourceEventId'))
61
+ )
62
+ WHERE metadata ? 'derivedFrom';
63
+
64
+ -- ── Rule-version drift detection ────────────────────────────────────────
65
+ -- "Find every relationship derived from this rule type at this version."
66
+ -- Used by reconcile when a rule changes — find derivations stamped with
67
+ -- an older version, revoke or refresh them.
68
+ CREATE INDEX IF NOT EXISTS idx_entity_relationships_derived_from_rule
69
+ ON public.entity_relationships (
70
+ ((metadata->'derivedFrom'->>'relationshipTypeId')),
71
+ ((metadata->'derivedFrom'->>'ruleVersion'))
72
+ )
73
+ WHERE metadata ? 'derivedFrom';
74
+
75
+ -- ── Idempotent derivation insert ────────────────────────────────────────
76
+ -- Pi P0.3 — even with the engine's advisory lock, this partial unique
77
+ -- constraint catches accidental double-inserts (e.g. when a different code
78
+ -- path tries to write the same auto-derived edge). ON CONFLICT DO NOTHING
79
+ -- in the engine relies on this index to fire.
80
+ --
81
+ -- Existing installs may already have duplicate live triples. Collapse those
82
+ -- first so adding the invariant is safe and deterministic.
83
+ WITH duplicate_live_triples AS (
84
+ SELECT id,
85
+ ROW_NUMBER() OVER (
86
+ PARTITION BY from_entity_id, to_entity_id, relationship_type_id
87
+ ORDER BY created_at ASC NULLS LAST, id ASC
88
+ ) AS rn
89
+ FROM public.entity_relationships
90
+ WHERE deleted_at IS NULL
91
+ )
92
+ UPDATE public.entity_relationships r
93
+ SET deleted_at = NOW(), updated_at = NOW()
94
+ FROM duplicate_live_triples d
95
+ WHERE r.id = d.id
96
+ AND d.rn > 1;
97
+
98
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_entity_relationships_live_triple
99
+ ON public.entity_relationships (from_entity_id, to_entity_id, relationship_type_id)
100
+ WHERE deleted_at IS NULL;
101
+
102
+ -- ── Per-namespace entity metadata indexes ───────────────────────────────
103
+ -- Pi P1.10 — the engine's findEntitiesByMetadataField does
104
+ -- `WHERE metadata->>$field = $value`. Without per-field expression indexes
105
+ -- this is a sequential scan on the entities table for every fact it
106
+ -- processes. Add the common identity namespaces here; future namespaces
107
+ -- get an entry in this same list when their first rule lands.
108
+ --
109
+ -- `idx_entities_metadata_domain` already exists in the baseline schema.
110
+
111
+ CREATE INDEX IF NOT EXISTS idx_entities_metadata_email
112
+ ON public.entities ((metadata->>'email'), organization_id)
113
+ WHERE (metadata->>'email') IS NOT NULL AND deleted_at IS NULL;
114
+
115
+ CREATE INDEX IF NOT EXISTS idx_entities_metadata_linkedin_url
116
+ ON public.entities ((metadata->>'linkedin_url'), organization_id)
117
+ WHERE (metadata->>'linkedin_url') IS NOT NULL AND deleted_at IS NULL;
118
+
119
+ CREATE INDEX IF NOT EXISTS idx_entities_metadata_github_handle
120
+ ON public.entities ((metadata->>'github_handle'), organization_id)
121
+ WHERE (metadata->>'github_handle') IS NOT NULL AND deleted_at IS NULL;
122
+
123
+ CREATE INDEX IF NOT EXISTS idx_entities_metadata_twitter_handle
124
+ ON public.entities ((metadata->>'twitter_handle'), organization_id)
125
+ WHERE (metadata->>'twitter_handle') IS NOT NULL AND deleted_at IS NULL;
126
+
127
+
128
+ -- migrate:down
129
+
130
+ DROP INDEX IF EXISTS public.idx_entities_metadata_twitter_handle;
131
+ DROP INDEX IF EXISTS public.idx_entities_metadata_github_handle;
132
+ DROP INDEX IF EXISTS public.idx_entities_metadata_linkedin_url;
133
+ DROP INDEX IF EXISTS public.idx_entities_metadata_email;
134
+ DROP INDEX IF EXISTS public.idx_entity_relationships_live_triple;
135
+ DROP INDEX IF EXISTS public.idx_entity_relationships_derived_from_rule;
136
+ DROP INDEX IF EXISTS public.idx_entity_relationships_derived_from_event;
137
+ DROP INDEX IF EXISTS public.idx_events_identity_fact_account;
138
+ DROP INDEX IF EXISTS public.idx_events_identity_fact_lookup;
139
+ DROP INDEX IF EXISTS public.idx_entity_relationship_types_has_auto_create;
140
+ ALTER TABLE public.entity_relationship_types DROP COLUMN IF EXISTS metadata;
@@ -0,0 +1,177 @@
1
+ -- migrate:up transaction:false
2
+
3
+ -- `events.source_id` is legacy and duplicates `events.connection_id`. New code
4
+ -- no longer writes or reads it, and scoring now partitions by connection_id.
5
+ -- This migration intentionally runs after that code is deployed.
6
+ SET lock_timeout = '5s';
7
+
8
+ DROP VIEW IF EXISTS public.event_thread_tree;
9
+ DROP VIEW IF EXISTS public.current_event_records;
10
+
11
+ DROP INDEX IF EXISTS public.idx_event_length;
12
+ DROP INDEX IF EXISTS public.idx_event_source_id;
13
+
14
+ ALTER TABLE public.events
15
+ DROP COLUMN IF EXISTS source_id;
16
+
17
+ DROP TRIGGER IF EXISTS normalize_event_created_by ON public.events;
18
+ DROP FUNCTION IF EXISTS public.normalize_event_created_by();
19
+
20
+ CREATE VIEW public.current_event_records AS
21
+ SELECT e.id,
22
+ e.organization_id,
23
+ e.entity_ids,
24
+ e.origin_id,
25
+ e.title,
26
+ e.payload_type,
27
+ e.payload_text,
28
+ e.payload_data,
29
+ e.payload_template,
30
+ e.attachments,
31
+ e.metadata,
32
+ e.score,
33
+ emb.embedding,
34
+ e.author_name,
35
+ e.source_url,
36
+ e.occurred_at,
37
+ e.created_at,
38
+ e.origin_parent_id,
39
+ COALESCE(length(e.payload_text), 0) AS content_length,
40
+ e.origin_type,
41
+ e.connector_key,
42
+ e.connection_id,
43
+ e.feed_key,
44
+ e.feed_id,
45
+ e.run_id,
46
+ e.semantic_type,
47
+ e.client_id,
48
+ e.created_by,
49
+ e.interaction_type,
50
+ e.interaction_status,
51
+ e.interaction_input_schema,
52
+ e.interaction_input,
53
+ e.interaction_output,
54
+ e.interaction_error,
55
+ e.supersedes_event_id
56
+ FROM (public.events e
57
+ LEFT JOIN public.event_embeddings emb ON ((emb.event_id = e.id)))
58
+ WHERE (NOT (EXISTS ( SELECT 1
59
+ FROM public.events newer
60
+ WHERE (newer.supersedes_event_id = e.id))));
61
+
62
+ CREATE VIEW public.event_thread_tree AS
63
+ SELECT e.id,
64
+ e.origin_id,
65
+ e.origin_parent_id,
66
+ e.occurred_at,
67
+ COALESCE(parent.origin_id, e.origin_id) AS root_origin_id,
68
+ COALESCE(parent.occurred_at, e.occurred_at) AS root_occurred_at,
69
+ COALESCE(parent.score, e.score) AS root_score,
70
+ CASE
71
+ WHEN (e.origin_parent_id IS NULL) THEN 0
72
+ ELSE 1
73
+ END AS depth,
74
+ ARRAY[(COALESCE(parent.occurred_at, e.occurred_at))::text, (e.id)::text] AS sort_path
75
+ FROM (public.current_event_records e
76
+ LEFT JOIN public.current_event_records parent ON (((e.origin_parent_id = parent.origin_id) AND (e.entity_ids && parent.entity_ids))));
77
+
78
+ -- migrate:down transaction:false
79
+
80
+ SET lock_timeout = '5s';
81
+
82
+ DROP VIEW IF EXISTS public.event_thread_tree;
83
+ DROP VIEW IF EXISTS public.current_event_records;
84
+
85
+ ALTER TABLE public.events
86
+ ADD COLUMN IF NOT EXISTS source_id integer;
87
+
88
+ UPDATE public.events
89
+ SET source_id = connection_id::integer
90
+ WHERE source_id IS NULL
91
+ AND connection_id IS NOT NULL
92
+ AND connection_id <= 2147483647;
93
+
94
+ CREATE INDEX IF NOT EXISTS idx_event_length
95
+ ON public.events (source_id, (COALESCE(length(payload_text), 0)));
96
+
97
+ CREATE INDEX IF NOT EXISTS idx_event_source_id
98
+ ON public.events (source_id);
99
+
100
+ CREATE OR REPLACE FUNCTION public.normalize_event_created_by()
101
+ RETURNS trigger
102
+ LANGUAGE plpgsql
103
+ AS $$
104
+ BEGIN
105
+ IF NEW.created_by IN ('system', 'api') AND NOT EXISTS (
106
+ SELECT 1 FROM public."user" u WHERE u.id = NEW.created_by
107
+ ) THEN
108
+ NEW.created_by := NULL;
109
+ END IF;
110
+ RETURN NEW;
111
+ END;
112
+ $$;
113
+
114
+ DROP TRIGGER IF EXISTS normalize_event_created_by ON public.events;
115
+ CREATE TRIGGER normalize_event_created_by
116
+ BEFORE INSERT OR UPDATE OF created_by ON public.events
117
+ FOR EACH ROW
118
+ EXECUTE FUNCTION public.normalize_event_created_by();
119
+
120
+ CREATE VIEW public.current_event_records AS
121
+ SELECT e.id,
122
+ e.organization_id,
123
+ e.entity_ids,
124
+ e.source_id,
125
+ e.origin_id,
126
+ e.title,
127
+ e.payload_type,
128
+ e.payload_text,
129
+ e.payload_data,
130
+ e.payload_template,
131
+ e.attachments,
132
+ e.metadata,
133
+ e.score,
134
+ emb.embedding,
135
+ e.author_name,
136
+ e.source_url,
137
+ e.occurred_at,
138
+ e.created_at,
139
+ e.origin_parent_id,
140
+ COALESCE(length(e.payload_text), 0) AS content_length,
141
+ e.origin_type,
142
+ e.connector_key,
143
+ e.connection_id,
144
+ e.feed_key,
145
+ e.feed_id,
146
+ e.run_id,
147
+ e.semantic_type,
148
+ e.client_id,
149
+ e.created_by,
150
+ e.interaction_type,
151
+ e.interaction_status,
152
+ e.interaction_input_schema,
153
+ e.interaction_input,
154
+ e.interaction_output,
155
+ e.interaction_error,
156
+ e.supersedes_event_id
157
+ FROM (public.events e
158
+ LEFT JOIN public.event_embeddings emb ON ((emb.event_id = e.id)))
159
+ WHERE (NOT (EXISTS ( SELECT 1
160
+ FROM public.events newer
161
+ WHERE (newer.supersedes_event_id = e.id))));
162
+
163
+ CREATE VIEW public.event_thread_tree AS
164
+ SELECT e.id,
165
+ e.origin_id,
166
+ e.origin_parent_id,
167
+ e.occurred_at,
168
+ COALESCE(parent.origin_id, e.origin_id) AS root_origin_id,
169
+ COALESCE(parent.occurred_at, e.occurred_at) AS root_occurred_at,
170
+ COALESCE(parent.score, e.score) AS root_score,
171
+ CASE
172
+ WHEN (e.origin_parent_id IS NULL) THEN 0
173
+ ELSE 1
174
+ END AS depth,
175
+ ARRAY[(COALESCE(parent.occurred_at, e.occurred_at))::text, (e.id)::text] AS sort_path
176
+ FROM (public.current_event_records e
177
+ LEFT JOIN public.current_event_records parent ON (((e.origin_parent_id = parent.origin_id) AND (e.entity_ids && parent.entity_ids))));
@@ -0,0 +1,76 @@
1
+ -- migrate:up
2
+
3
+ -- Drop schema objects that have no readers, writers, or references in the
4
+ -- TypeScript source tree (`packages/server/src` is the source of
5
+ -- truth — `lobu-cli/runtime` is a generated mirror).
6
+ --
7
+ -- Verification:
8
+ -- * Strict SQL grep across packages/{server,gateway,worker,
9
+ -- web,connector-sdk}/src for FROM/JOIN/INSERT/UPDATE/REFERENCES.
10
+ -- * `query_sql` allowlist (utils/table-schema.ts) does not list any of
11
+ -- the dropped tables, columns, or the view.
12
+ -- * better-auth `teams` is not enabled in src/auth/index.tsx, so the
13
+ -- `team` table and `member.teamId` are unused at runtime.
14
+ -- * `verification` is intentionally NOT dropped — better-auth's
15
+ -- magicLink and phoneNumber plugins write OTPs/tokens there.
16
+ --
17
+ -- Idempotent (DROP IF EXISTS) so it is safe whether the object exists or
18
+ -- was already removed out-of-band.
19
+
20
+ -- ---------------------------------------------------------------------------
21
+ -- Tables: empty in prod, no code paths reference them
22
+ -- ---------------------------------------------------------------------------
23
+
24
+ DROP TABLE IF EXISTS public.rate_limits;
25
+ DROP TABLE IF EXISTS public.workers;
26
+ DROP TABLE IF EXISTS public.source_type_auth_defaults;
27
+ DROP TABLE IF EXISTS public.workspace_settings;
28
+
29
+ -- `team` is referenced by `member.teamId`. Drop the inbound FK + column
30
+ -- first so the table drop does not depend on CASCADE behavior.
31
+ ALTER TABLE public.member DROP CONSTRAINT IF EXISTS "member_teamId_fkey";
32
+ ALTER TABLE public.member DROP COLUMN IF EXISTS "teamId";
33
+ DROP TABLE IF EXISTS public.team;
34
+
35
+ -- ---------------------------------------------------------------------------
36
+ -- Views: defined in baseline, not referenced anywhere in code
37
+ -- ---------------------------------------------------------------------------
38
+
39
+ DROP VIEW IF EXISTS public.event_thread_tree;
40
+
41
+ -- ---------------------------------------------------------------------------
42
+ -- Columns: always-NULL in prod, never read or written by any code path
43
+ -- ---------------------------------------------------------------------------
44
+
45
+ ALTER TABLE public.watchers
46
+ DROP COLUMN IF EXISTS lobu_schedule_id,
47
+ DROP COLUMN IF EXISTS registry_ref,
48
+ DROP COLUMN IF EXISTS registry_repo,
49
+ DROP COLUMN IF EXISTS registry_type;
50
+
51
+ -- watcher_versions.source_path is unused (the heavily-used `source_path`
52
+ -- column lives on connector_versions; same name, different table).
53
+ ALTER TABLE public.watcher_versions
54
+ DROP COLUMN IF EXISTS source_path,
55
+ DROP COLUMN IF EXISTS source_repository,
56
+ DROP COLUMN IF EXISTS source_ref,
57
+ DROP COLUMN IF EXISTS source_commit_sha,
58
+ DROP COLUMN IF EXISTS sources_schema;
59
+
60
+ ALTER TABLE public.connector_versions
61
+ DROP COLUMN IF EXISTS source_repository,
62
+ DROP COLUMN IF EXISTS source_ref,
63
+ DROP COLUMN IF EXISTS source_commit_sha;
64
+
65
+ ALTER TABLE public.event_embeddings
66
+ DROP COLUMN IF EXISTS model_key;
67
+
68
+
69
+ -- migrate:down
70
+
71
+ -- This cleanup is one-way. Re-creating these objects would require copying
72
+ -- DDL from the baseline migration (00000000000000_baseline.sql) and the
73
+ -- column definitions inferred from prior schema dumps. Down is intentionally
74
+ -- a no-op — recovery is via `git revert` of this migration plus manual DDL,
75
+ -- not via dbmate rollback.
76
+ SELECT 1;