@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,278 @@
1
+ /**
2
+ * Deploy-provider adapter contract.
3
+ *
4
+ * This is the interface `Task 3` exists to build. Vercel is the first provider
5
+ * behind it; Netlify, Railway, Fly.io, Render, Coolify/Dokploy and Cloudflare
6
+ * Pages are meant to land as another directory in `providers/` and one line in
7
+ * the registry. If any of them needs a change to the PANEL, this interface is
8
+ * what was wrong.
9
+ *
10
+ * Note what this is NOT: a projector. A projection derives a row on a surface
11
+ * that already has its own table — `mcp_servers` for agent tools,
12
+ * `db_client_connections` for a database. Deployments are never copied locally
13
+ * (see migration 075), so there is no derived row to keep in step. A deploy
14
+ * provider registers CODE here, and the account row itself is what makes it
15
+ * appear in the panel. That is the same conclusion the Issues surface reached.
16
+ *
17
+ * Every optional method is paired with a flag in `capabilities`. A caller must
18
+ * read the flag rather than probe for the method, because the panel renders its
19
+ * controls before any call is made.
20
+ */
21
+
22
+ import type {
23
+ BuildLogBundle,
24
+ Deployment,
25
+ DeploymentDetail,
26
+ DeploymentDraft,
27
+ DeploymentPage,
28
+ DeployBindingConfig,
29
+ DeployInfo,
30
+ DeployProjectStatus,
31
+ DeployProviderCapabilities,
32
+ DeployTarget,
33
+ NewProjectDraft
34
+ } from '$shared/types/deployments';
35
+ import type { IntegrationAccountRow } from '$backend/database/queries';
36
+
37
+ /**
38
+ * What an adapter can say about deployability.
39
+ *
40
+ * The client-facing `DeployInfo` also carries facts read from the LOCAL working
41
+ * tree — the suggested repository, the checked-out branch — which an adapter
42
+ * has no business knowing about, and the readiness verdict, which the route
43
+ * composes. This is deliberately the shared shape minus those rather than a
44
+ * second declaration that could drift.
45
+ */
46
+ export type AdapterDeployInfo = Omit<
47
+ DeployInfo,
48
+ 'suggestedRepo' | 'connectState' | 'connectHint' | 'connectUrl' | 'currentBranch'
49
+ >;
50
+
51
+ /**
52
+ * Whether a specific repository could be attached, and what to do if not.
53
+ *
54
+ * `unknown` is a first-class answer rather than an optimistic `true`: a check
55
+ * we could not read must not present itself as a green light, because the cost
56
+ * of being wrong is the exact failure the check exists to prevent.
57
+ */
58
+ export interface RepositoryAccess {
59
+ state: 'ready' | 'blocked' | 'unknown';
60
+ reason: string | null;
61
+ /** Provider settings page that fixes it, when there is one. */
62
+ actionUrl: string | null;
63
+ }
64
+
65
+ /** The remote project one account is pointed at, for one Clopen project. */
66
+ export interface ResolvedDeployBinding {
67
+ locator: string;
68
+ displayName: string;
69
+ detected: boolean;
70
+ teamId: string | null;
71
+ config: DeployBindingConfig;
72
+ }
73
+
74
+ /**
75
+ * Everything an adapter call needs.
76
+ *
77
+ * `credentials` is already decoded. It is assembled by the service from the
78
+ * account row and never leaves the backend — no route serialises it, and the
79
+ * adapter must not put it anywhere a `Deployment` can carry it back out.
80
+ */
81
+ export interface DeployContext {
82
+ projectId: string;
83
+ account: IntegrationAccountRow;
84
+ credentials: Record<string, string>;
85
+ binding: ResolvedDeployBinding;
86
+ }
87
+
88
+ /** Same, before a binding exists — the only calls that can run unbound. */
89
+ export interface UnboundDeployContext {
90
+ projectId: string;
91
+ account: IntegrationAccountRow;
92
+ credentials: Record<string, string>;
93
+ }
94
+
95
+ /** How the list is narrowed. Everything optional is "not set", never a default. */
96
+ export interface DeploymentQuery {
97
+ environment: 'production' | 'preview' | 'custom' | 'all';
98
+ branch?: string;
99
+ /** Opaque cursor from the previous page. */
100
+ cursor?: string;
101
+ limit?: number;
102
+ }
103
+
104
+ /** A live log follow, as the stream manager drives it. */
105
+ export interface LogStreamHandle {
106
+ /** Stop the follow and release whatever socket is behind it. */
107
+ stop: () => void;
108
+ }
109
+
110
+ export interface LogStreamCallbacks {
111
+ onChunk: (text: string) => void;
112
+ /**
113
+ * The build moved to a new stage.
114
+ *
115
+ * Separate from the log text because it answers a different question. A log
116
+ * says what a command printed; this says what the provider is DOING — and
117
+ * during the long quiet stretches of a build (uploading, provisioning,
118
+ * assigning domains) the log prints nothing at all, which is exactly when a
119
+ * watcher most needs to know it has not stalled.
120
+ */
121
+ onPhase?: (phase: string) => void;
122
+ /** Called exactly once, with a message when the follow ended badly. */
123
+ onEnd: (error: string | null) => void;
124
+ }
125
+
126
+ export interface DeployProviderAdapter {
127
+ /** Must match the `IntegrationProvider.id` this adapter serves. */
128
+ provider: string;
129
+ capabilities: DeployProviderCapabilities;
130
+
131
+ /**
132
+ * Read the provider's own CLI config out of the project, if it left one.
133
+ *
134
+ * This is what makes binding automatic for a project someone has already
135
+ * linked: `.vercel/project.json` names the project and the team, and asking
136
+ * the user to pick it from a dropdown would be asking them to retype a file
137
+ * that is sitting in their repository.
138
+ *
139
+ * Returns null when there is no such file, which is the ordinary case and
140
+ * not an error.
141
+ */
142
+ detectFromProject?(projectRoot: string): Promise<{ locator: string; teamId: string | null } | null>;
143
+
144
+ /**
145
+ * Remote projects this credential can reach.
146
+ *
147
+ * Used for the binding picker, and for the second detection pass: each
148
+ * target carries the git repository it is connected to, so a project whose
149
+ * `origin` matches one of them can be bound without the user choosing.
150
+ */
151
+ listTargets(context: UnboundDeployContext): Promise<DeployTarget[]>;
152
+
153
+ /** Resolve one target, so a stored locator can be given a display name. */
154
+ describeTarget(context: UnboundDeployContext, locator: string, teamId: string | null): Promise<DeployTarget | null>;
155
+
156
+ /**
157
+ * Is this credential good, and does it reach the bound project?
158
+ *
159
+ * Runs at connect time and from the hub's health button. A token that is
160
+ * valid but cannot see the bound project must fail HERE, naming which of the
161
+ * two it is — not later as an empty list that looks like "no deployments".
162
+ */
163
+ probe(context: UnboundDeployContext, binding: ResolvedDeployBinding | null): Promise<{
164
+ status: 'ok' | 'needs_auth' | 'needs_config' | 'error';
165
+ detail: string | null;
166
+ }>;
167
+
168
+ list(context: DeployContext, query: DeploymentQuery): Promise<DeploymentPage>;
169
+ get(context: DeployContext, id: string): Promise<DeploymentDetail>;
170
+
171
+ /** Build logs as one budgeted bundle — what the chat prompt is built from. */
172
+ fetchLogs?(context: DeployContext, id: string): Promise<BuildLogBundle>;
173
+
174
+ /**
175
+ * Follow a running build's logs.
176
+ *
177
+ * Only called when `capabilities.streamLogs` is set. The handle must stop
178
+ * the underlying request: the stream manager closes it when the last viewer
179
+ * leaves, and a follow nobody aborts is an open socket for the life of the
180
+ * process.
181
+ */
182
+ streamLogs?(context: DeployContext, id: string, callbacks: LogStreamCallbacks): Promise<LogStreamHandle>;
183
+
184
+ /**
185
+ * Outward-facing actions. Each is gated by its capability flag, and the
186
+ * caller has already confirmed with the user before any of these run.
187
+ *
188
+ * `rollback` and `promote` return `pending` rather than `done` when the
189
+ * provider moves traffic asynchronously, which Vercel does — reporting them
190
+ * as complete would tell someone their incident was over before it was.
191
+ */
192
+ redeploy?(context: DeployContext, id: string): Promise<{ deploymentId: string | null; message: string }>;
193
+ cancel?(context: DeployContext, id: string): Promise<{ message: string }>;
194
+ rollback?(context: DeployContext, id: string): Promise<{ status: 'done' | 'pending'; message: string }>;
195
+ promote?(context: DeployContext, id: string): Promise<{ status: 'done' | 'pending'; message: string }>;
196
+
197
+ /**
198
+ * What starting a build from here would need, and whether it is possible.
199
+ *
200
+ * Answered before the deploy dialog opens so the dialog can prefill the
201
+ * branch and refuse honestly, rather than offering a button whose failure is
202
+ * only discovered after someone presses it.
203
+ */
204
+ deployInfo?(context: DeployContext): Promise<AdapterDeployInfo>;
205
+
206
+ /**
207
+ * Start a NEW build from a branch.
208
+ *
209
+ * Distinct from `redeploy`, which copies an existing deployment: this is the
210
+ * only path available to a project that has never been deployed. Outward
211
+ * facing — the caller has confirmed first.
212
+ */
213
+ createDeployment?(
214
+ context: DeployContext,
215
+ draft: DeploymentDraft
216
+ ): Promise<{ deploymentId: string | null; message: string }>;
217
+
218
+ /**
219
+ * Create a remote project.
220
+ *
221
+ * Unbound on purpose: this is what a Clopen project with nothing to point at
222
+ * does, so there is no binding yet. The caller binds to the result.
223
+ */
224
+ createProject?(context: UnboundDeployContext, draft: NewProjectDraft): Promise<DeployTarget>;
225
+
226
+ /**
227
+ * Can this repository be attached, and if not, what would fix it.
228
+ *
229
+ * Asked before `connectRepository` is offered, and also before the new-project
230
+ * form offers to connect a repository to something that does not exist yet —
231
+ * which is why it takes an UNBOUND context. It reads a property of the
232
+ * account, not of any particular project.
233
+ *
234
+ * Attaching a repository needs the ACCOUNT to have git access of its own,
235
+ * established on the provider's site and impossible with an API token — the
236
+ * one prerequisite Clopen can detect but not satisfy. Naming it beats a
237
+ * button that fails.
238
+ */
239
+ repositoryAccess?(context: UnboundDeployContext, gitRepo: string): Promise<RepositoryAccess>;
240
+
241
+ /**
242
+ * Attach a git repository to the bound remote project.
243
+ *
244
+ * The escape hatch from "this project is not connected to a git repository,
245
+ * so it cannot be deployed from here" — which is otherwise a dead end that
246
+ * sends the user to the provider's dashboard.
247
+ */
248
+ connectRepository?(
249
+ context: DeployContext,
250
+ repo: { gitRepo: string; gitProvider: string }
251
+ ): Promise<void>;
252
+
253
+ /**
254
+ * Delete a deployment outright.
255
+ *
256
+ * Outward-facing and irreversible — the build, its logs and its URLs all go.
257
+ * The caller confirms, and must not offer it for whatever is currently
258
+ * serving production.
259
+ */
260
+ deleteDeployment?(context: DeployContext, id: string): Promise<{ message: string }>;
261
+
262
+ /**
263
+ * State that belongs to the target, not to any one build.
264
+ *
265
+ * Also carries the outcome of a rollback or promotion still in flight, which
266
+ * is the only way to turn the `pending` those actions return into an answer.
267
+ */
268
+ projectStatus?(context: DeployContext): Promise<DeployProjectStatus>;
269
+
270
+ /** Who the stored credential belongs to. Shown beside the account label. */
271
+ viewer?(context: UnboundDeployContext): Promise<string | null>;
272
+
273
+ /**
274
+ * The deployment currently serving production traffic, if the provider can
275
+ * answer it directly rather than by inference from the list.
276
+ */
277
+ currentProduction?(context: DeployContext): Promise<Deployment | null>;
278
+ }
@@ -5,7 +5,7 @@
5
5
  The adapters stream chat; **artifacts** are the reusable "extensions" the user
6
6
  manages in **Settings → Artifacts & Access** that shape what each engine sees and
7
7
  may do during that stream — Skills, Commands, Subagents, Instructions,
8
- Permissions, Profiles, and Connectors (MCP).
8
+ Permissions, Profiles, and Integrations (MCP).
9
9
 
10
10
  They are a **separate subsystem** (`backend/artifacts/` + one module per feature)
11
11
  that meets the adapter layer at exactly one seam: `backend/engine/artifact-sync.ts`,
@@ -21,7 +21,7 @@ each exposes a different native surface.
21
21
 
22
22
  | Menu (UI) | Backend module | WS router | Materialized as |
23
23
  |------------------|-------------------------|----------------------------|-----------------|
24
- | Connectors (MCP) | `backend/mcp/` | `backend/ws/mcp/` | config object + `/mcp/ext/<slug>` bridge — **not** a file artifact (see §8.5) |
24
+ | Integrations | `backend/mcp/` + `backend/integrations/` | `backend/ws/mcp/` + `backend/ws/integrations/` | config object + `/mcp/ext/<slug>` bridge — **not** a file artifact (see §8.5) |
25
25
  | Skills | `backend/skills/` | `backend/ws/skills/` | `folder-md` in a native dir, or synthetic preamble |
26
26
  | Commands | `backend/commands/` | `backend/ws/commands/` | `single-md` in a native dir, or synthetic preamble |
27
27
  | Subagents | `backend/subagents/` | `backend/ws/subagents/` | `single-md` in a native dir, or synthetic preamble |
@@ -101,14 +101,27 @@ reliably re-read per turn — the prompt is the one genuinely per-session channe
101
101
  | **Permissions** (`backend/permissions/`) | per-engine tool allow/deny | global, project | **enforcement is a runtime check** (`resolvePermissionsFromDb` + `isToolAllowed`) each adapter runs at whichever surface fires for every tool call — for Claude a `PreToolUse` hook, since `bypassPermissions` auto-approves before `canUseTool` is consulted. The matrix only describes the optional on-disk file, which today only Claude reads (a managed `permissions` key merged into its isolated `settings.json`); its `deny` rules do bite even under `bypassPermissions`, an allowlist has no on-disk equivalent |
102
102
  | **Profiles** (`backend/profiles/`) | a named bundle of slugs | per session | not materialized. Narrows which instance-global artifacts are active: effective profile = `chat_sessions.profile_id ?? projects.default_profile_id`, resolved once at stream start and threaded down as `profileId`. Only constrains the types it references (`artifactFilter` → `null` = unconstrained), so a Commands-only profile never disables every Skill |
103
103
 
104
- ### 8.5 Connectors (MCP)
104
+ ### 8.5 Integrations (MCP + connected accounts)
105
105
 
106
- MCP is part of Artifacts & Access in the UI but is **not** part of this file
107
- framework — it has its own subsystem. MCP servers are config objects composed
108
- per engine and proxied through the `/mcp/ext/<slug>` bridge, so forcing them
109
- through a file writer/detector would be a mis-fit; the `'mcp'` slot in
110
- `ArtifactType` exists only for future extensibility. Profiles can still reference
111
- MCP connectors as bundle items (§8.4).
106
+ Integrations sit under Artifacts & Access in the UI but are **not** part of this
107
+ file framework — they have their own subsystem. MCP servers are config objects
108
+ composed per engine and proxied through the `/mcp/ext/<slug>` bridge, so forcing
109
+ them through a file writer/detector would be a mis-fit; the `'mcp'` slot in
110
+ `ArtifactType` exists only for future extensibility. Profiles can still
111
+ reference connectors as bundle items (§8.4).
112
+
113
+ Two modules, one menu:
114
+
115
+ - `backend/mcp/` — the protocol: install, proxy, per-engine tool exposure,
116
+ MCP-level OAuth.
117
+ - `backend/integrations/` — the connected account and its credential (sealed at
118
+ rest, see `backend/database/crypto/`). An account with the `agent-tools`
119
+ capability **projects** an `mcp_servers` row; other capabilities project onto
120
+ other surfaces, or onto none yet.
121
+
122
+ Nothing on the adapter path can tell a projected row from a hand-installed one,
123
+ which is the point: this layer stays off the path MCP config already flows
124
+ through.
112
125
 
113
126
  For MCP's own architecture — internal `defineServer()` tools, the OAuth client,
114
127
  the remote HTTP bridge, per-engine config, and tool overrides — see
@@ -0,0 +1,209 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+
3
+ import {
4
+ buildGnomeCopiedFilesPayload,
5
+ buildMacClipboardReadScriptLines,
6
+ buildMacClipboardWriteScriptLines,
7
+ buildOsClipboardPsScript,
8
+ buildOsClipboardReadPsScript,
9
+ copyPathsToOsClipboard,
10
+ decodeOsClipboardPayload,
11
+ encodeOsClipboardPayload,
12
+ OS_CLIPBOARD_ENV_VAR,
13
+ parseFileDropLines,
14
+ parseGnomeCopiedFiles,
15
+ parseTextUriList,
16
+ pathToFileUri
17
+ } from './os-clipboard';
18
+
19
+ describe('os-clipboard payload encoding', () => {
20
+ test('round-trips paths with spaces, unicode, quotes and ampersands', () => {
21
+ const paths = [
22
+ 'C:\\Users\\Test\\Report 2026\\Attendance Log.docx',
23
+ 'C:\\Users\\Test\\Weekly Journal (1).docx',
24
+ 'C:\\Users\\Test\\a&b\'c"d;e|.txt'
25
+ ];
26
+ expect(decodeOsClipboardPayload(encodeOsClipboardPayload(paths))).toEqual(paths);
27
+ });
28
+
29
+ test('round-trips folder paths', () => {
30
+ const paths = ['C:\\Users\\Test\\Report 2026'];
31
+ expect(decodeOsClipboardPayload(encodeOsClipboardPayload(paths))).toEqual(paths);
32
+ });
33
+ });
34
+
35
+ describe('os-clipboard PowerShell script', () => {
36
+ test('publishes a FileDropList with explicit COPY effect', () => {
37
+ const script = buildOsClipboardPsScript();
38
+ expect(script).toContain('System.Windows.Forms');
39
+ expect(script).toContain('SetFileDropList');
40
+ expect(script).toContain('Preferred DropEffect');
41
+ expect(script).toContain('SetDataObject');
42
+ // DROPEFFECT_COPY (1) — never MOVE, so COPY sources are never deleted.
43
+ expect(script).toContain('GetBytes(1)');
44
+ expect(script).not.toContain('GetBytes(2)');
45
+ expect(script).toContain(OS_CLIPBOARD_ENV_VAR);
46
+ });
47
+
48
+ test('publishes DROPEFFECT_MOVE for cut so Explorer moves the sources', () => {
49
+ const script = buildOsClipboardPsScript('move');
50
+ expect(script).toContain('SetFileDropList');
51
+ expect(script).toContain('Preferred DropEffect');
52
+ // DROPEFFECT_MOVE (2) — only CUT publishes this; Explorer itself
53
+ // performs the move, Clopen never deletes the sources.
54
+ expect(script).toContain('GetBytes(2)');
55
+ expect(script).not.toContain('GetBytes(1)');
56
+ });
57
+
58
+ test('never interpolates paths (injection-safe transport via env var)', () => {
59
+ const script = buildOsClipboardPsScript();
60
+ expect(script).not.toContain('Attendance');
61
+ expect(script).not.toContain('C:\\');
62
+ });
63
+ });
64
+
65
+ describe('copyPathsToOsClipboard validation', () => {
66
+ test('rejects an unknown effect', async () => {
67
+ await expect(
68
+ // @ts-expect-error runtime guard must reject invalid effects
69
+ copyPathsToOsClipboard(['C:\\tmp\\a.txt'], 'delete')
70
+ ).rejects.toThrow(/Unknown clipboard effect/);
71
+ });
72
+
73
+ test('rejects an empty path list', async () => {
74
+ await expect(copyPathsToOsClipboard([])).rejects.toThrow(
75
+ /At least one path|not supported on this platform/
76
+ );
77
+ });
78
+
79
+ test('rejects non-existent paths on Windows', async () => {
80
+ if (process.platform !== 'win32') return;
81
+ await expect(
82
+ copyPathsToOsClipboard(['C:\\definitely\\not\\here\\missing.docx'])
83
+ ).rejects.toThrow(/does not exist/);
84
+ });
85
+ });
86
+
87
+ describe('os-clipboard read helpers', () => {
88
+ test('parseFileDropLines splits CRLF/LF output and drops blanks', () => {
89
+ expect(
90
+ parseFileDropLines('C:\\A\\f.txt\r\nD:\\B Folder\\\r\n\r\n \nC:\\C.docx\n')
91
+ ).toEqual(['C:\\A\\f.txt', 'D:\\B Folder\\', 'C:\\C.docx']);
92
+ });
93
+
94
+ test('parseFileDropLines returns [] for empty clipboard output', () => {
95
+ expect(parseFileDropLines('')).toEqual([]);
96
+ expect(parseFileDropLines('\r\n \r\n')).toEqual([]);
97
+ });
98
+
99
+ test('parseTextUriList decodes file URIs and skips comments', () => {
100
+ expect(
101
+ parseTextUriList(
102
+ '# comment\nfile:///home/user/Report%202026\nfile://host/tmp/a&b.txt\n'
103
+ )
104
+ ).toEqual(['/home/user/Report 2026', '/tmp/a&b.txt']);
105
+ });
106
+
107
+ test('read PowerShell script prints the FileDropList line by line', () => {
108
+ const script = buildOsClipboardReadPsScript();
109
+ expect(script).toContain('GetFileDropList');
110
+ expect(script).toContain('Write-Output');
111
+ expect(script).not.toContain('SetDataObject');
112
+ });
113
+ });
114
+
115
+ describe('mac clipboard write script', () => {
116
+ const lines = buildMacClipboardWriteScriptLines();
117
+ const script = lines.join('\n');
118
+
119
+ test('publishes onto the general pasteboard as a file-name list', () => {
120
+ expect(script).toContain('NSPasteboard');
121
+ expect(script).toContain('NSFilenamesPboardType');
122
+ expect(script).toContain("pb's clearContents()");
123
+ });
124
+
125
+ test('writes the list eagerly instead of through writeObjects:', () => {
126
+ // writeObjects: hands the pasteboard server one lazily-provided item
127
+ // per URL. osascript exits before they are all pulled, so the entries
128
+ // that actually land are a race — the same four paths arrived as 1, 3
129
+ // or 4 items across identical runs, which is how a multi-select copy
130
+ // turned into a single pasted file.
131
+ expect(script).toContain('setPropertyList:paths');
132
+ expect(script).toContain('declareTypes:');
133
+ expect(script).not.toContain('writeObjects');
134
+ });
135
+
136
+ test('confirms the write landed before the process exits', () => {
137
+ // An eager write is still not guaranteed to be visible to other
138
+ // processes the instant the writer dies; reading it back is what makes
139
+ // the result deterministic.
140
+ expect(script).toContain('propertyListForType:');
141
+ expect(script).toContain('repeat 50 times');
142
+ expect(script).toContain('exit repeat');
143
+ expect(lines).toContain('use scripting additions');
144
+ });
145
+
146
+ test('collects the paths in a plain AppleScript list', () => {
147
+ expect(script).toContain('set paths to {}');
148
+ expect(script).toContain('set end of paths to');
149
+ expect(script).not.toContain('NSMutableArray');
150
+ });
151
+
152
+ test('takes paths from argv so nothing is interpolated into the script', () => {
153
+ expect(lines).toContain('on run argv');
154
+ expect(script).toContain('repeat with p in argv');
155
+ });
156
+ });
157
+
158
+ describe('mac clipboard read script', () => {
159
+ const lines = buildMacClipboardReadScriptLines();
160
+ const script = lines.join('\n');
161
+
162
+ test('targets pasteboard file URLs', () => {
163
+ expect(script).toContain('NSPasteboard');
164
+ expect(script).toContain('readObjectsForClasses');
165
+ });
166
+
167
+ test('opens the if as a block instead of a one-line if/then/repeat', () => {
168
+ // `if ... then repeat ...` on one line is an AppleScript syntax error,
169
+ // which made every Finder read fail with "not available on this Mac".
170
+ expect(lines).toContain('if urls is not missing value then');
171
+ expect(lines).toContain('end if');
172
+ expect(script).not.toMatch(/then repeat/);
173
+ });
174
+
175
+ test('filters file URLs with isFileURL, not a reading-options dictionary', () => {
176
+ // The ASObjC bridge cannot resolve NSURLReadingFileURLsOnly and aborts
177
+ // with "Can't continue", so the filter has to be an explicit test.
178
+ expect(script).toContain('isFileURL');
179
+ expect(script).toContain('options:(missing value)');
180
+ expect(script).not.toContain('NSURLReadingFileURLsOnly');
181
+ });
182
+ });
183
+
184
+ describe('linux clipboard payloads', () => {
185
+ test('pathToFileUri percent-encodes each segment and keeps separators', () => {
186
+ expect(pathToFileUri('/home/user/Report 2026/a&b;c.txt')).toBe(
187
+ 'file:///home/user/Report%202026/a%26b%3Bc.txt'
188
+ );
189
+ });
190
+
191
+ test('gnome-copied-files leads with the action line', () => {
192
+ expect(buildGnomeCopiedFilesPayload(['/tmp/a.txt'])).toBe('copy\nfile:///tmp/a.txt');
193
+ expect(buildGnomeCopiedFilesPayload(['/tmp/a.txt'], 'move')).toBe('cut\nfile:///tmp/a.txt');
194
+ });
195
+
196
+ test('round-trips through parseGnomeCopiedFiles for both actions', () => {
197
+ const paths = ['/home/user/Report 2026', '/home/user/a&b.txt'];
198
+ for (const effect of ['copy', 'move'] as const) {
199
+ expect(parseGnomeCopiedFiles(buildGnomeCopiedFilesPayload(paths, effect))).toEqual(paths);
200
+ }
201
+ });
202
+
203
+ test('parseGnomeCopiedFiles tolerates a payload with no action line', () => {
204
+ expect(parseGnomeCopiedFiles('file:///tmp/a.txt\nfile:///tmp/b.txt')).toEqual([
205
+ '/tmp/a.txt',
206
+ '/tmp/b.txt'
207
+ ]);
208
+ });
209
+ });