@myrialabs/clopen 0.4.38 → 0.4.39

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 (114) hide show
  1. package/backend/auth/permissions.ts +25 -0
  2. package/backend/chat/stream-manager.ts +1 -1
  3. package/backend/database/crypto/secret-columns.ts +5 -1
  4. package/backend/database/migrations/075_create_deploy_bindings.ts +54 -0
  5. package/backend/database/migrations/076_remove_memory_code_graph.ts +229 -0
  6. package/backend/database/migrations/077_create_integration_db_links.ts +150 -0
  7. package/backend/database/migrations/index.ts +21 -0
  8. package/backend/database/queries/db-client-connection-queries.ts +19 -0
  9. package/backend/database/queries/deploy-queries.ts +124 -0
  10. package/backend/database/queries/graph-queries.ts +291 -247
  11. package/backend/database/queries/index.ts +4 -0
  12. package/backend/database/queries/integration-db-link-queries.ts +168 -0
  13. package/backend/database/queries/integration-queries.ts +34 -6
  14. package/backend/db-client/integrations/index.ts +37 -0
  15. package/backend/db-client/integrations/links.ts +533 -0
  16. package/backend/db-client/integrations/projector.test.ts +280 -0
  17. package/backend/db-client/integrations/projector.ts +256 -0
  18. package/backend/db-client/integrations/supabase-service.ts +266 -0
  19. package/backend/db-client/providers/registry.ts +27 -0
  20. package/backend/db-client/providers/supabase/adapter.ts +500 -0
  21. package/backend/db-client/providers/supabase/api-types.ts +92 -0
  22. package/backend/db-client/providers/supabase/apply-migration.ts +104 -0
  23. package/backend/db-client/providers/supabase/client.ts +259 -0
  24. package/backend/db-client/providers/supabase/features.ts +502 -0
  25. package/backend/db-client/providers/supabase/local.test.ts +78 -0
  26. package/backend/db-client/providers/supabase/local.ts +137 -0
  27. package/backend/db-client/providers/types.ts +137 -0
  28. package/backend/deployments/bindings.test.ts +43 -0
  29. package/backend/deployments/bindings.ts +216 -0
  30. package/backend/deployments/index.ts +53 -0
  31. package/backend/deployments/log-streams.ts +214 -0
  32. package/backend/deployments/prompts.ts +70 -0
  33. package/backend/deployments/providers/vercel/adapter.ts +757 -0
  34. package/backend/deployments/providers/vercel/build-logs.test.ts +80 -0
  35. package/backend/deployments/providers/vercel/build-logs.ts +211 -0
  36. package/backend/deployments/providers/vercel/client.ts +203 -0
  37. package/backend/deployments/providers/vercel/list.test.ts +624 -0
  38. package/backend/deployments/providers/vercel/normalise.test.ts +115 -0
  39. package/backend/deployments/providers/vercel/normalise.ts +113 -0
  40. package/backend/deployments/providers/vercel/types.ts +104 -0
  41. package/backend/deployments/registry.ts +27 -0
  42. package/backend/deployments/service.ts +458 -0
  43. package/backend/deployments/types.ts +278 -0
  44. package/backend/index.ts +4 -0
  45. package/backend/integrations/projections/index.ts +0 -0
  46. package/backend/integrations/projections/mcp-projector.ts +7 -3
  47. package/backend/integrations/projections/types.ts +21 -9
  48. package/backend/integrations/registry/index.ts +5 -1
  49. package/backend/integrations/registry/providers/supabase.ts +61 -0
  50. package/backend/integrations/registry/providers/vercel.ts +46 -0
  51. package/backend/mcp/internal/servers/memory-graph/description.ts +3 -3
  52. package/backend/mcp/internal/servers/memory-graph/runner.ts +4 -9
  53. package/backend/mcp/internal/servers/memory-graph/schema.ts +0 -4
  54. package/backend/memory/README.md +57 -34
  55. package/backend/memory/compose.test.ts +3 -3
  56. package/backend/memory/compose.ts +6 -9
  57. package/backend/memory/config.ts +0 -5
  58. package/backend/memory/consolidate.ts +1 -2
  59. package/backend/memory/context.test.ts +8 -54
  60. package/backend/memory/context.ts +19 -25
  61. package/backend/memory/extract/episodic.ts +10 -12
  62. package/backend/memory/extract/index.ts +23 -52
  63. package/backend/memory/extract/scheduler.ts +3 -6
  64. package/backend/memory/index.ts +6 -5
  65. package/backend/memory/invalidate.ts +36 -48
  66. package/backend/memory/layout.ts +319 -130
  67. package/backend/memory/retention.ts +12 -42
  68. package/backend/memory/retrieval.eval.test.ts +2 -2
  69. package/backend/memory/retrieval.test.ts +228 -183
  70. package/backend/memory/retrieval.ts +22 -21
  71. package/backend/memory/revise.test.ts +62 -116
  72. package/backend/memory/revise.ts +0 -1
  73. package/backend/memory/view.ts +8 -5
  74. package/backend/snapshot/helpers.ts +35 -41
  75. package/backend/snapshot/snapshot-service.ts +90 -0
  76. package/backend/snapshot/turn-changes.test.ts +163 -0
  77. package/backend/snapshot/turn-changes.ts +131 -0
  78. package/backend/ws/db-client/accounts.ts +225 -0
  79. package/backend/ws/db-client/connections.ts +34 -3
  80. package/backend/ws/db-client/context.ts +37 -0
  81. package/backend/ws/db-client/index.ts +20 -1
  82. package/backend/ws/db-client/supabase.ts +188 -0
  83. package/backend/ws/deployments/actions.ts +360 -0
  84. package/backend/ws/deployments/context.ts +43 -0
  85. package/backend/ws/deployments/crud.ts +152 -0
  86. package/backend/ws/deployments/index.ts +15 -0
  87. package/backend/ws/deployments/schemas.ts +183 -0
  88. package/backend/ws/index.ts +6 -2
  89. package/backend/ws/memory/crud.ts +4 -16
  90. package/backend/ws/snapshot/changes.ts +279 -0
  91. package/backend/ws/snapshot/index.ts +4 -3
  92. package/dist/assets/{index-CyH7fSbR.js → index-BrF6nqld.js} +1 -1
  93. package/dist/assets/{index-DSHIANSy.js → index-C8Gi-b6U.js} +1 -1
  94. package/dist/assets/main-Bd3gb79F.css +1 -0
  95. package/dist/assets/main-Bo1hD7mt.js +1191 -0
  96. package/dist/index.html +2 -2
  97. package/package.json +1 -1
  98. package/shared/constants/tool-icons.ts +9 -0
  99. package/shared/types/db-client/connection.ts +6 -0
  100. package/shared/types/db-client/index.ts +2 -0
  101. package/shared/types/db-client/integrations.ts +174 -0
  102. package/shared/types/db-client/supabase.ts +131 -0
  103. package/shared/types/deployments.ts +382 -0
  104. package/shared/types/memory.ts +34 -51
  105. package/shared/types/ui/components.ts +1 -1
  106. package/shared/utils/diff-calculator.test.ts +89 -0
  107. package/shared/utils/diff-calculator.ts +30 -65
  108. package/shared/utils/logger.ts +1 -0
  109. package/backend/memory/extract/languages.ts +0 -176
  110. package/backend/memory/extract/structural.test.ts +0 -215
  111. package/backend/memory/extract/structural.ts +0 -364
  112. package/backend/ws/snapshot/content.ts +0 -85
  113. package/dist/assets/main-D2IOjftb.css +0 -1
  114. package/dist/assets/main-DM-tHKbW.js +0 -1152
@@ -35,5 +35,9 @@ export type { ProfileRow, ProfileItemRow, ProfileInput, ProfileItemInput, Profil
35
35
  export { noteQueries, noteCollectionQueries, noteImageQueries } from './note-queries';
36
36
  export { integrationAccountQueries, integrationProjectionQueries, integrationWebhookQueries } from './integration-queries';
37
37
  export type { IntegrationAccountRow, IntegrationAccountInput, IntegrationProjectionRow } from './integration-queries';
38
+ export { integrationDbLinkQueries } from './integration-db-link-queries';
39
+ export type { IntegrationDbLinkRow, IntegrationDbLinkInput } from './integration-db-link-queries';
38
40
  export { workBindingQueries, workLinkQueries, parseBindingConfig } from './work-queries';
39
41
  export type { WorkBindingRow, WorkLinkRow } from './work-queries';
42
+ export { deployBindingQueries, parseDeployConfig } from './deploy-queries';
43
+ export type { DeployBindingRow } from './deploy-queries';
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Which remote databases an account brought into DB Client.
3
+ *
4
+ * A link is the answer to "which one", asked once per database rather than once
5
+ * per credential. It is the database counterpart of `deploy_bindings`: the
6
+ * account holds the token, and everything that varies per remote database —
7
+ * which project, which connection mode, and the password the provider will not
8
+ * hand back — lives here.
9
+ *
10
+ * `secrets` is sealed at rest by the crypto layer, so callers here hand in and
11
+ * receive a plain object and never see an envelope. A blob that the active key
12
+ * cannot open reads as `{}`, which the projector treats exactly as it treats a
13
+ * link whose password was never entered: it projects a connection that cannot
14
+ * log in and says so, rather than throwing on every read path.
15
+ */
16
+
17
+ import { getDatabase } from '../index';
18
+ import { openRow, sealFor } from '../crypto';
19
+ import type { DbDriver } from '$shared/types/db-client';
20
+
21
+ const TABLE = 'integration_db_links';
22
+
23
+ export interface IntegrationDbLinkRow {
24
+ id: string;
25
+ account_id: string;
26
+ /** The provider's own id for the database — a Supabase project ref. */
27
+ remote_ref: string;
28
+ label: string;
29
+ driver: DbDriver;
30
+ mode: string;
31
+ /** Sealed on disk, plain JSON string here. Null when the key could not open it. */
32
+ secrets: string | null;
33
+ config_json: string;
34
+ detected: number;
35
+ created_at: string;
36
+ updated_at: string;
37
+ }
38
+
39
+ export interface IntegrationDbLinkInput {
40
+ accountId: string;
41
+ remoteRef: string;
42
+ label: string;
43
+ driver: DbDriver;
44
+ mode: string;
45
+ secrets: Record<string, string>;
46
+ config: Record<string, unknown>;
47
+ detected?: boolean;
48
+ }
49
+
50
+ function parse<T>(raw: string | null, fallback: T): T {
51
+ if (!raw) return fallback;
52
+ try {
53
+ const parsed = JSON.parse(raw);
54
+ return (parsed ?? fallback) as T;
55
+ } catch {
56
+ return fallback;
57
+ }
58
+ }
59
+
60
+ function openLink<T extends IntegrationDbLinkRow | null>(row: T): T {
61
+ return (row ? openRow(TABLE, row) : row) as T;
62
+ }
63
+
64
+ export const integrationDbLinkQueries = {
65
+ getForAccount(accountId: string): IntegrationDbLinkRow[] {
66
+ const db = getDatabase();
67
+ return (db.prepare(
68
+ `SELECT * FROM integration_db_links WHERE account_id = ? ORDER BY label ASC`
69
+ ).all(accountId) as IntegrationDbLinkRow[]).map((row) => openLink(row));
70
+ },
71
+
72
+ getById(id: string): IntegrationDbLinkRow | null {
73
+ const db = getDatabase();
74
+ return openLink(
75
+ db.prepare(`SELECT * FROM integration_db_links WHERE id = ?`).get(id) as IntegrationDbLinkRow | null
76
+ );
77
+ },
78
+
79
+ getByRef(accountId: string, remoteRef: string): IntegrationDbLinkRow | null {
80
+ const db = getDatabase();
81
+ return openLink(
82
+ db.prepare(
83
+ `SELECT * FROM integration_db_links WHERE account_id = ? AND remote_ref = ?`
84
+ ).get(accountId, remoteRef) as IntegrationDbLinkRow | null
85
+ );
86
+ },
87
+
88
+ secretsOf(row: IntegrationDbLinkRow): Record<string, string> {
89
+ return parse<Record<string, string>>(row.secrets, {});
90
+ },
91
+
92
+ configOf<T = Record<string, unknown>>(row: IntegrationDbLinkRow): T {
93
+ return parse<T>(row.config_json, {} as T);
94
+ },
95
+
96
+ create(input: IntegrationDbLinkInput): IntegrationDbLinkRow {
97
+ const db = getDatabase();
98
+ const id = crypto.randomUUID();
99
+ const now = new Date().toISOString();
100
+
101
+ db.prepare(`
102
+ INSERT INTO integration_db_links (
103
+ id, account_id, remote_ref, label, driver, mode,
104
+ secrets, config_json, detected, created_at, updated_at
105
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
106
+ `).run(
107
+ id,
108
+ input.accountId,
109
+ input.remoteRef,
110
+ input.label,
111
+ input.driver,
112
+ input.mode,
113
+ sealFor(TABLE, 'secrets', JSON.stringify(input.secrets)),
114
+ JSON.stringify(input.config),
115
+ input.detected ? 1 : 0,
116
+ now,
117
+ now
118
+ );
119
+
120
+ return this.getById(id)!;
121
+ },
122
+
123
+ /**
124
+ * Patch a link.
125
+ *
126
+ * `secrets` is REPLACED rather than merged, and the caller merges — an empty
127
+ * password field means "not re-typed", not "clear it", the same rule the
128
+ * db-client and SSH forms already use.
129
+ */
130
+ update(
131
+ id: string,
132
+ patch: { label?: string; mode?: string; secrets?: Record<string, string>; config?: Record<string, unknown> }
133
+ ): IntegrationDbLinkRow | null {
134
+ const db = getDatabase();
135
+ const sets: string[] = [];
136
+ const values: unknown[] = [];
137
+
138
+ if (patch.label !== undefined) {
139
+ sets.push('label = ?');
140
+ values.push(patch.label);
141
+ }
142
+ if (patch.mode !== undefined) {
143
+ sets.push('mode = ?');
144
+ values.push(patch.mode);
145
+ }
146
+ if (patch.secrets !== undefined) {
147
+ sets.push('secrets = ?');
148
+ values.push(sealFor(TABLE, 'secrets', JSON.stringify(patch.secrets)));
149
+ }
150
+ if (patch.config !== undefined) {
151
+ sets.push('config_json = ?');
152
+ values.push(JSON.stringify(patch.config));
153
+ }
154
+
155
+ if (sets.length === 0) return this.getById(id);
156
+
157
+ sets.push('updated_at = ?');
158
+ values.push(new Date().toISOString(), id);
159
+
160
+ db.prepare(`UPDATE integration_db_links SET ${sets.join(', ')} WHERE id = ?`).run(...values);
161
+ return this.getById(id);
162
+ },
163
+
164
+ remove(id: string): void {
165
+ const db = getDatabase();
166
+ db.prepare(`DELETE FROM integration_db_links WHERE id = ?`).run(id);
167
+ }
168
+ };
@@ -231,6 +231,20 @@ export const integrationProjectionQueries = {
231
231
  ).get(targetKind, targetId) as IntegrationProjectionRow | null;
232
232
  },
233
233
 
234
+ /**
235
+ * Every projection of one kind, keyed by target id.
236
+ *
237
+ * The badge on a db-client connection needs to answer "is this row managed,
238
+ * and by whom" for a whole list at once. Asking `getByTarget` per row would
239
+ * be one statement per connection on every list call.
240
+ */
241
+ getAllByKind(targetKind: IntegrationTargetKind): IntegrationProjectionRow[] {
242
+ const db = getDatabase();
243
+ return db.prepare(
244
+ `SELECT * FROM integration_projections WHERE target_kind = ?`
245
+ ).all(targetKind) as IntegrationProjectionRow[];
246
+ },
247
+
234
248
  upsert(input: {
235
249
  accountId: string;
236
250
  capability: IntegrationCapability;
@@ -240,12 +254,20 @@ export const integrationProjectionQueries = {
240
254
  restore: unknown | null;
241
255
  }): void {
242
256
  const db = getDatabase();
257
+ // The conflict target is the full key: one account can own SEVERAL rows of
258
+ // the same kind for the same capability (a database account with two
259
+ // linked projects), so `target_id` identifies the row rather than being
260
+ // something an upsert overwrites.
261
+ //
262
+ // `restore_json` is deliberately NOT updated on conflict. It is the
263
+ // snapshot of what the row looked like before we adopted it, and
264
+ // re-projecting must never replace it with a picture of our own
265
+ // credential — that is the bug the MCP projector's comment describes.
243
266
  db.prepare(`
244
267
  INSERT INTO integration_projections (account_id, capability, target_kind, target_id, adopted, restore_json, created_at)
245
268
  VALUES (?, ?, ?, ?, ?, ?, ?)
246
- ON CONFLICT (account_id, capability, target_kind) DO UPDATE SET
247
- target_id = excluded.target_id,
248
- adopted = excluded.adopted
269
+ ON CONFLICT (account_id, capability, target_kind, target_id) DO UPDATE SET
270
+ adopted = excluded.adopted
249
271
  `).run(
250
272
  input.accountId,
251
273
  input.capability,
@@ -257,11 +279,17 @@ export const integrationProjectionQueries = {
257
279
  );
258
280
  },
259
281
 
260
- remove(accountId: string, capability: IntegrationCapability, targetKind: IntegrationTargetKind): void {
282
+ remove(
283
+ accountId: string,
284
+ capability: IntegrationCapability,
285
+ targetKind: IntegrationTargetKind,
286
+ targetId: string
287
+ ): void {
261
288
  const db = getDatabase();
262
289
  db.prepare(
263
- `DELETE FROM integration_projections WHERE account_id = ? AND capability = ? AND target_kind = ?`
264
- ).run(accountId, capability, targetKind);
290
+ `DELETE FROM integration_projections
291
+ WHERE account_id = ? AND capability = ? AND target_kind = ? AND target_id = ?`
292
+ ).run(accountId, capability, targetKind, targetId);
265
293
  },
266
294
 
267
295
  /** The snapshot taken when an existing row was adopted, or null. */
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Account-backed connections in DB Client.
3
+ *
4
+ * Importing this module is what wires the `database` capability up, so it must
5
+ * be imported for its side effects before any account is connected —
6
+ * `backend/ws/db-client/` does that, the same way the Deployments router is
7
+ * what makes Vercel exist.
8
+ *
9
+ * projector.ts link → `db_client_connections` row
10
+ * links.ts choosing which remote databases to bring in
11
+ * supabase-service.ts the Supabase surface, resolved against a connection
12
+ *
13
+ * Unlike Issues and Deployments this registers a PROJECTOR rather than an
14
+ * adapter, because DB Client owns a table. A connection is a real row that the
15
+ * drivers, the schema tree and the query console read without knowing where it
16
+ * came from; only the badge and the read-only form know, and they learn it from
17
+ * `integration_projections` rather than from a column on the connection.
18
+ */
19
+
20
+ import { registerAccountProbe, registerProjector } from '$backend/integrations';
21
+ import { registerDbProvider } from '../providers/registry';
22
+ import { supabaseDbAdapter } from '../providers/supabase/adapter';
23
+ import { dbConnectionProjector } from './projector';
24
+ import { dbLinks } from './links';
25
+
26
+ registerProjector(dbConnectionProjector);
27
+ registerDbProvider(supabaseDbAdapter);
28
+
29
+ // Health for an account whose capability projects no MCP row. Without this the
30
+ // hub reports "Nothing to probe yet" forever for a Supabase account — the same
31
+ // gap the Issues surface found and the Deployments surface closed the same way.
32
+ registerAccountProbe('supabase', (accountId) => dbLinks.probe(accountId));
33
+
34
+ export { dbLinks } from './links';
35
+ export { dbConnectionProjector } from './projector';
36
+ export { resolveSupabaseScope, supabaseSurface } from './supabase-service';
37
+ export type { SupabaseScope } from './supabase-service';