@myrialabs/clopen 0.4.37 → 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 (193) hide show
  1. package/README.md +2 -2
  2. package/backend/auth/permissions.ts +39 -0
  3. package/backend/bootstrap.ts +16 -0
  4. package/backend/chat/stream-manager.ts +1 -1
  5. package/backend/database/crypto/envelope.test.ts +93 -0
  6. package/backend/database/crypto/envelope.ts +127 -0
  7. package/backend/database/crypto/index.ts +22 -0
  8. package/backend/database/crypto/master-key.ts +129 -0
  9. package/backend/database/crypto/secret-columns.ts +151 -0
  10. package/backend/database/migrations/071_create_notes_tables.ts +90 -0
  11. package/backend/database/migrations/072_encrypt_stored_secrets.ts +107 -0
  12. package/backend/database/migrations/073_create_integration_tables.ts +119 -0
  13. package/backend/database/migrations/074_create_work_tables.ts +94 -0
  14. package/backend/database/migrations/075_create_deploy_bindings.ts +54 -0
  15. package/backend/database/migrations/076_remove_memory_code_graph.ts +229 -0
  16. package/backend/database/migrations/077_create_integration_db_links.ts +150 -0
  17. package/backend/database/migrations/index.ts +49 -0
  18. package/backend/database/queries/db-client-connection-queries.ts +42 -12
  19. package/backend/database/queries/deploy-queries.ts +124 -0
  20. package/backend/database/queries/engine-queries.ts +23 -10
  21. package/backend/database/queries/graph-queries.ts +291 -247
  22. package/backend/database/queries/index.ts +10 -1
  23. package/backend/database/queries/integration-db-link-queries.ts +168 -0
  24. package/backend/database/queries/integration-queries.ts +325 -0
  25. package/backend/database/queries/mcp-server-queries.ts +38 -11
  26. package/backend/database/queries/note-queries.test.ts +190 -0
  27. package/backend/database/queries/note-queries.ts +269 -0
  28. package/backend/database/queries/profile-queries.ts +1 -1
  29. package/backend/database/queries/ssh-connection-queries.ts +19 -8
  30. package/backend/database/queries/work-queries.ts +210 -0
  31. package/backend/db-client/integrations/index.ts +37 -0
  32. package/backend/db-client/integrations/links.ts +533 -0
  33. package/backend/db-client/integrations/projector.test.ts +280 -0
  34. package/backend/db-client/integrations/projector.ts +256 -0
  35. package/backend/db-client/integrations/supabase-service.ts +266 -0
  36. package/backend/db-client/providers/registry.ts +27 -0
  37. package/backend/db-client/providers/supabase/adapter.ts +500 -0
  38. package/backend/db-client/providers/supabase/api-types.ts +92 -0
  39. package/backend/db-client/providers/supabase/apply-migration.ts +104 -0
  40. package/backend/db-client/providers/supabase/client.ts +259 -0
  41. package/backend/db-client/providers/supabase/features.ts +502 -0
  42. package/backend/db-client/providers/supabase/local.test.ts +78 -0
  43. package/backend/db-client/providers/supabase/local.ts +137 -0
  44. package/backend/db-client/providers/types.ts +137 -0
  45. package/backend/deployments/bindings.test.ts +43 -0
  46. package/backend/deployments/bindings.ts +216 -0
  47. package/backend/deployments/index.ts +53 -0
  48. package/backend/deployments/log-streams.ts +214 -0
  49. package/backend/deployments/prompts.ts +70 -0
  50. package/backend/deployments/providers/vercel/adapter.ts +757 -0
  51. package/backend/deployments/providers/vercel/build-logs.test.ts +80 -0
  52. package/backend/deployments/providers/vercel/build-logs.ts +211 -0
  53. package/backend/deployments/providers/vercel/client.ts +203 -0
  54. package/backend/deployments/providers/vercel/list.test.ts +624 -0
  55. package/backend/deployments/providers/vercel/normalise.test.ts +115 -0
  56. package/backend/deployments/providers/vercel/normalise.ts +113 -0
  57. package/backend/deployments/providers/vercel/types.ts +104 -0
  58. package/backend/deployments/registry.ts +27 -0
  59. package/backend/deployments/service.ts +458 -0
  60. package/backend/deployments/types.ts +278 -0
  61. package/backend/engine/docs/artifacts.md +22 -9
  62. package/backend/files/os-clipboard.test.ts +209 -0
  63. package/backend/files/os-clipboard.ts +567 -0
  64. package/backend/http/integration-hooks.ts +42 -0
  65. package/backend/http/notes-images.test.ts +228 -0
  66. package/backend/http/notes-images.ts +196 -0
  67. package/backend/index.ts +13 -0
  68. package/backend/integrations/accounts.ts +229 -0
  69. package/backend/integrations/health.ts +146 -0
  70. package/backend/integrations/index.ts +36 -0
  71. package/backend/integrations/projections/index.ts +0 -0
  72. package/backend/integrations/projections/mcp-projector.test.ts +204 -0
  73. package/backend/integrations/projections/mcp-projector.ts +163 -0
  74. package/backend/integrations/projections/types.ts +63 -0
  75. package/backend/integrations/registry/define.ts +38 -0
  76. package/backend/integrations/registry/index.ts +60 -0
  77. package/backend/integrations/registry/providers/context7.ts +44 -0
  78. package/backend/integrations/registry/providers/firecrawl.ts +41 -0
  79. package/backend/integrations/registry/providers/github.ts +78 -0
  80. package/backend/integrations/registry/providers/supabase.ts +61 -0
  81. package/backend/integrations/registry/providers/vercel.ts +46 -0
  82. package/backend/integrations/registry/types.ts +96 -0
  83. package/backend/integrations/webhooks/gateway.ts +160 -0
  84. package/backend/integrations/webhooks/verify.ts +65 -0
  85. package/backend/mcp/README.md +25 -3
  86. package/backend/mcp/external/config.ts +35 -1
  87. package/backend/mcp/index.ts +1 -1
  88. package/backend/mcp/internal/config.ts +1 -1
  89. package/backend/mcp/internal/servers/memory-graph/description.ts +3 -3
  90. package/backend/mcp/internal/servers/memory-graph/runner.ts +4 -9
  91. package/backend/mcp/internal/servers/memory-graph/schema.ts +0 -4
  92. package/backend/memory/README.md +57 -34
  93. package/backend/memory/compose.test.ts +3 -3
  94. package/backend/memory/compose.ts +6 -9
  95. package/backend/memory/config.ts +0 -5
  96. package/backend/memory/consolidate.ts +1 -2
  97. package/backend/memory/context.test.ts +8 -54
  98. package/backend/memory/context.ts +19 -25
  99. package/backend/memory/extract/episodic.ts +10 -12
  100. package/backend/memory/extract/index.ts +23 -52
  101. package/backend/memory/extract/scheduler.ts +3 -6
  102. package/backend/memory/index.ts +6 -5
  103. package/backend/memory/invalidate.ts +36 -48
  104. package/backend/memory/layout.ts +319 -130
  105. package/backend/memory/retention.ts +12 -42
  106. package/backend/memory/retrieval.eval.test.ts +2 -2
  107. package/backend/memory/retrieval.test.ts +228 -183
  108. package/backend/memory/retrieval.ts +22 -21
  109. package/backend/memory/revise.test.ts +62 -116
  110. package/backend/memory/revise.ts +0 -1
  111. package/backend/memory/view.ts +8 -5
  112. package/backend/notes/access.test.ts +82 -0
  113. package/backend/notes/access.ts +27 -0
  114. package/backend/notes/storage.test.ts +77 -0
  115. package/backend/notes/storage.ts +114 -0
  116. package/backend/permissions/service.ts +2 -2
  117. package/backend/profiles/service.ts +1 -1
  118. package/backend/projects/project-cleanup.ts +6 -0
  119. package/backend/snapshot/helpers.ts +35 -41
  120. package/backend/snapshot/snapshot-service.ts +90 -0
  121. package/backend/snapshot/turn-changes.test.ts +163 -0
  122. package/backend/snapshot/turn-changes.ts +131 -0
  123. package/backend/work/bindings.ts +124 -0
  124. package/backend/work/index.ts +42 -0
  125. package/backend/work/prompts.ts +150 -0
  126. package/backend/work/providers/github/actions-logs.ts +180 -0
  127. package/backend/work/providers/github/adapter.test.ts +88 -0
  128. package/backend/work/providers/github/adapter.ts +1255 -0
  129. package/backend/work/providers/github/client.ts +280 -0
  130. package/backend/work/providers/github/list-range.test.ts +158 -0
  131. package/backend/work/providers/github/token-kind.test.ts +42 -0
  132. package/backend/work/pull-requests.ts +242 -0
  133. package/backend/work/registry.ts +27 -0
  134. package/backend/work/service.ts +436 -0
  135. package/backend/work/start-work.test.ts +71 -0
  136. package/backend/work/start-work.ts +232 -0
  137. package/backend/work/types.ts +180 -0
  138. package/backend/ws/db-client/accounts.ts +225 -0
  139. package/backend/ws/db-client/connections.ts +34 -3
  140. package/backend/ws/db-client/context.ts +37 -0
  141. package/backend/ws/db-client/index.ts +20 -1
  142. package/backend/ws/db-client/supabase.ts +188 -0
  143. package/backend/ws/deployments/actions.ts +360 -0
  144. package/backend/ws/deployments/context.ts +43 -0
  145. package/backend/ws/deployments/crud.ts +152 -0
  146. package/backend/ws/deployments/index.ts +15 -0
  147. package/backend/ws/deployments/schemas.ts +183 -0
  148. package/backend/ws/files/clipboard.ts +78 -0
  149. package/backend/ws/files/index.ts +5 -0
  150. package/backend/ws/git/diff-budget.ts +70 -11
  151. package/backend/ws/index.ts +16 -2
  152. package/backend/ws/integrations/crud.ts +219 -0
  153. package/backend/ws/integrations/index.ts +22 -0
  154. package/backend/ws/mcp/crud.ts +25 -1
  155. package/backend/ws/memory/crud.ts +4 -16
  156. package/backend/ws/notes/index.ts +278 -0
  157. package/backend/ws/profiles/crud.ts +1 -1
  158. package/backend/ws/snapshot/changes.ts +279 -0
  159. package/backend/ws/snapshot/index.ts +4 -3
  160. package/backend/ws/work/actions.ts +206 -0
  161. package/backend/ws/work/context.ts +51 -0
  162. package/backend/ws/work/crud.ts +347 -0
  163. package/backend/ws/work/index.ts +17 -0
  164. package/backend/ws/work/pull-requests.ts +177 -0
  165. package/backend/ws/work/schemas.ts +226 -0
  166. package/dist/assets/{index-sJmS_CCm.js → index-BrF6nqld.js} +1 -1
  167. package/dist/assets/{index-Bik9TCBi.js → index-C8Gi-b6U.js} +1 -1
  168. package/dist/assets/main-Bd3gb79F.css +1 -0
  169. package/dist/assets/main-Bo1hD7mt.js +1191 -0
  170. package/dist/index.html +2 -2
  171. package/package.json +1 -1
  172. package/shared/constants/engine-tools.ts +1 -1
  173. package/shared/constants/tool-icons.ts +42 -0
  174. package/shared/types/database/schema.ts +41 -0
  175. package/shared/types/db-client/connection.ts +6 -0
  176. package/shared/types/db-client/index.ts +2 -0
  177. package/shared/types/db-client/integrations.ts +174 -0
  178. package/shared/types/db-client/supabase.ts +131 -0
  179. package/shared/types/deployments.ts +382 -0
  180. package/shared/types/integrations.ts +140 -0
  181. package/shared/types/memory.ts +34 -51
  182. package/shared/types/stores/settings.ts +8 -0
  183. package/shared/types/ui/components.ts +1 -1
  184. package/shared/types/work.ts +426 -0
  185. package/shared/utils/diff-calculator.test.ts +89 -0
  186. package/shared/utils/diff-calculator.ts +30 -65
  187. package/shared/utils/logger.ts +4 -0
  188. package/backend/memory/extract/languages.ts +0 -176
  189. package/backend/memory/extract/structural.test.ts +0 -215
  190. package/backend/memory/extract/structural.ts +0 -364
  191. package/backend/ws/snapshot/content.ts +0 -85
  192. package/dist/assets/main-DLqolBI2.css +0 -1
  193. package/dist/assets/main-Df1I3hnw.js +0 -1096
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Issues & PRs surface queries — bindings and work links.
3
+ *
4
+ * Neither table holds a secret, so nothing here goes through the crypto layer:
5
+ * a locator is `owner/repo` and the config is a behaviour flag. The credential
6
+ * that reaches the provider always comes from `integration_accounts`.
7
+ *
8
+ * Nothing about a work item itself is stored. See migration 074 for why: the
9
+ * provider is the truthful answer for titles, bodies and comments, and the only
10
+ * fact that cannot be re-derived is which worktree someone opened for it.
11
+ */
12
+
13
+ import { getDatabase } from '../index';
14
+ import type { WorkBindingConfig, WorkItemKind } from '$shared/types/work';
15
+ import { DEFAULT_BINDING_CONFIG } from '$shared/types/work';
16
+
17
+ export interface WorkBindingRow {
18
+ project_id: string;
19
+ account_id: string;
20
+ locator: string;
21
+ detected: number;
22
+ default_branch: string | null;
23
+ config_json: string;
24
+ created_at: string;
25
+ updated_at: string;
26
+ }
27
+
28
+ export interface WorkLinkRow {
29
+ id: string;
30
+ project_id: string;
31
+ account_id: string;
32
+ item_kind: WorkItemKind;
33
+ item_identifier: string;
34
+ item_title: string | null;
35
+ item_url: string | null;
36
+ worktree_id: string | null;
37
+ session_id: string | null;
38
+ branch: string | null;
39
+ created_at: string;
40
+ }
41
+
42
+ /**
43
+ * Parse the stored config over the defaults.
44
+ *
45
+ * Merging rather than replacing is deliberate: a config written before a new
46
+ * option existed must not read back with that option `undefined`, because the
47
+ * two places that consume it (`transitionOnStartWork`, `branchTemplate`) treat
48
+ * undefined and null differently and one of them would start naming branches
49
+ * `undefined-...`.
50
+ */
51
+ export function parseBindingConfig(raw: string | null): WorkBindingConfig {
52
+ if (!raw) return { ...DEFAULT_BINDING_CONFIG };
53
+ try {
54
+ const parsed = JSON.parse(raw) as Partial<WorkBindingConfig> | null;
55
+ return { ...DEFAULT_BINDING_CONFIG, ...(parsed ?? {}) };
56
+ } catch {
57
+ return { ...DEFAULT_BINDING_CONFIG };
58
+ }
59
+ }
60
+
61
+ export const workBindingQueries = {
62
+ getForProject(projectId: string): WorkBindingRow[] {
63
+ const db = getDatabase();
64
+ return db.prepare(
65
+ `SELECT * FROM work_bindings WHERE project_id = ?`
66
+ ).all(projectId) as WorkBindingRow[];
67
+ },
68
+
69
+ get(projectId: string, accountId: string): WorkBindingRow | null {
70
+ const db = getDatabase();
71
+ return db.prepare(
72
+ `SELECT * FROM work_bindings WHERE project_id = ? AND account_id = ?`
73
+ ).get(projectId, accountId) as WorkBindingRow | null;
74
+ },
75
+
76
+ upsert(input: {
77
+ projectId: string;
78
+ accountId: string;
79
+ locator: string;
80
+ detected: boolean;
81
+ defaultBranch?: string | null;
82
+ config?: WorkBindingConfig;
83
+ }): WorkBindingRow {
84
+ const db = getDatabase();
85
+ const now = new Date().toISOString();
86
+ const existing = this.get(input.projectId, input.accountId);
87
+
88
+ db.prepare(`
89
+ INSERT INTO work_bindings (
90
+ project_id, account_id, locator, detected, default_branch, config_json, created_at, updated_at
91
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
92
+ ON CONFLICT (project_id, account_id) DO UPDATE SET
93
+ locator = excluded.locator,
94
+ detected = excluded.detected,
95
+ default_branch = excluded.default_branch,
96
+ config_json = excluded.config_json,
97
+ updated_at = excluded.updated_at
98
+ `).run(
99
+ input.projectId,
100
+ input.accountId,
101
+ input.locator,
102
+ input.detected ? 1 : 0,
103
+ input.defaultBranch ?? existing?.default_branch ?? null,
104
+ JSON.stringify(input.config ?? parseBindingConfig(existing?.config_json ?? null)),
105
+ existing?.created_at ?? now,
106
+ now
107
+ );
108
+
109
+ return this.get(input.projectId, input.accountId)!;
110
+ },
111
+
112
+ /**
113
+ * Cache the default branch discovered by an API call.
114
+ *
115
+ * Separate from `upsert` so a background lookup cannot clobber a locator the
116
+ * user changed while it was in flight.
117
+ */
118
+ setDefaultBranch(projectId: string, accountId: string, branch: string): void {
119
+ const db = getDatabase();
120
+ db.prepare(
121
+ `UPDATE work_bindings SET default_branch = ?, updated_at = ? WHERE project_id = ? AND account_id = ?`
122
+ ).run(branch, new Date().toISOString(), projectId, accountId);
123
+ },
124
+
125
+ remove(projectId: string, accountId: string): void {
126
+ const db = getDatabase();
127
+ db.prepare(
128
+ `DELETE FROM work_bindings WHERE project_id = ? AND account_id = ?`
129
+ ).run(projectId, accountId);
130
+ }
131
+ };
132
+
133
+ export const workLinkQueries = {
134
+ getForProject(projectId: string): WorkLinkRow[] {
135
+ const db = getDatabase();
136
+ return db.prepare(
137
+ `SELECT * FROM work_links WHERE project_id = ? ORDER BY created_at DESC`
138
+ ).all(projectId) as WorkLinkRow[];
139
+ },
140
+
141
+ getByItem(
142
+ projectId: string,
143
+ accountId: string,
144
+ itemKind: WorkItemKind,
145
+ itemIdentifier: string
146
+ ): WorkLinkRow | null {
147
+ const db = getDatabase();
148
+ return db.prepare(`
149
+ SELECT * FROM work_links
150
+ WHERE project_id = ? AND account_id = ? AND item_kind = ? AND item_identifier = ?
151
+ `).get(projectId, accountId, itemKind, itemIdentifier) as WorkLinkRow | null;
152
+ },
153
+
154
+ /** Which item this branch was started from. The PR composer's whole lookup. */
155
+ getByBranch(projectId: string, branch: string): WorkLinkRow | null {
156
+ const db = getDatabase();
157
+ return db.prepare(`
158
+ SELECT * FROM work_links
159
+ WHERE project_id = ? AND branch = ?
160
+ ORDER BY created_at DESC LIMIT 1
161
+ `).get(projectId, branch) as WorkLinkRow | null;
162
+ },
163
+
164
+ upsert(input: {
165
+ projectId: string;
166
+ accountId: string;
167
+ itemKind: WorkItemKind;
168
+ itemIdentifier: string;
169
+ itemTitle?: string | null;
170
+ itemUrl?: string | null;
171
+ worktreeId?: string | null;
172
+ sessionId?: string | null;
173
+ branch?: string | null;
174
+ }): WorkLinkRow {
175
+ const db = getDatabase();
176
+ const now = new Date().toISOString();
177
+
178
+ db.prepare(`
179
+ INSERT INTO work_links (
180
+ id, project_id, account_id, item_kind, item_identifier,
181
+ item_title, item_url, worktree_id, session_id, branch, created_at
182
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
183
+ ON CONFLICT (project_id, account_id, item_kind, item_identifier) DO UPDATE SET
184
+ item_title = excluded.item_title,
185
+ item_url = excluded.item_url,
186
+ worktree_id = excluded.worktree_id,
187
+ session_id = excluded.session_id,
188
+ branch = excluded.branch
189
+ `).run(
190
+ crypto.randomUUID(),
191
+ input.projectId,
192
+ input.accountId,
193
+ input.itemKind,
194
+ input.itemIdentifier,
195
+ input.itemTitle ?? null,
196
+ input.itemUrl ?? null,
197
+ input.worktreeId ?? null,
198
+ input.sessionId ?? null,
199
+ input.branch ?? null,
200
+ now
201
+ );
202
+
203
+ return this.getByItem(input.projectId, input.accountId, input.itemKind, input.itemIdentifier)!;
204
+ },
205
+
206
+ remove(id: string): void {
207
+ const db = getDatabase();
208
+ db.prepare(`DELETE FROM work_links WHERE id = ?`).run(id);
209
+ }
210
+ };
@@ -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';