@myrialabs/clopen 0.4.39 → 0.4.41

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 (173) hide show
  1. package/.env.example +1 -1
  2. package/backend/artifacts/detect.ts +15 -3
  3. package/backend/artifacts/generate.ts +2 -2
  4. package/backend/artifacts/index.ts +12 -4
  5. package/backend/artifacts/markers.ts +24 -1
  6. package/backend/artifacts/matrix.ts +47 -3
  7. package/backend/artifacts/sync.test.ts +3 -3
  8. package/backend/artifacts/sync.ts +8 -20
  9. package/backend/artifacts/types.ts +9 -3
  10. package/backend/auth/permissions.ts +29 -11
  11. package/backend/auth/session-cleanup.ts +10 -1
  12. package/backend/auth/tokens.ts +9 -1
  13. package/backend/chat/stream-manager.ts +42 -0
  14. package/backend/database/crypto/secret-columns.ts +5 -1
  15. package/backend/database/migrations/078_create_worktree_branch_tables.ts +158 -0
  16. package/backend/database/migrations/079_merge_commands_into_skills.ts +222 -0
  17. package/backend/database/migrations/080_create_file_shares.ts +111 -0
  18. package/backend/database/migrations/081_create_push_subscriptions.ts +32 -0
  19. package/backend/database/migrations/index.ts +28 -0
  20. package/backend/database/queries/file-share-queries.ts +163 -0
  21. package/backend/database/queries/index.ts +12 -4
  22. package/backend/database/queries/profile-queries.ts +5 -3
  23. package/backend/database/queries/push-subscription-queries.test.ts +90 -0
  24. package/backend/database/queries/push-subscription-queries.ts +99 -0
  25. package/backend/database/queries/skill-queries.ts +96 -18
  26. package/backend/database/queries/worktree-branch-queries.ts +331 -0
  27. package/backend/db-client/cloning.test.ts +161 -0
  28. package/backend/db-client/cloning.ts +672 -0
  29. package/backend/db-client/connection-url.test.ts +117 -0
  30. package/backend/db-client/connection-url.ts +126 -0
  31. package/backend/db-client/drivers/mongodb.ts +2 -14
  32. package/backend/db-client/drivers/mysql.ts +2 -8
  33. package/backend/db-client/drivers/postgres.ts +10 -13
  34. package/backend/db-client/drivers/redis.ts +2 -6
  35. package/backend/db-client/env/detect.ts +438 -0
  36. package/backend/db-client/env/diff.ts +94 -0
  37. package/backend/db-client/env/env.test.ts +574 -0
  38. package/backend/db-client/env/index.ts +15 -0
  39. package/backend/db-client/env/naming.ts +202 -0
  40. package/backend/db-client/env/service.ts +487 -0
  41. package/backend/db-client/integrations/index.ts +7 -0
  42. package/backend/db-client/integrations/links.ts +41 -10
  43. package/backend/db-client/providers/neon/adapter.ts +522 -0
  44. package/backend/db-client/providers/neon/api-types.ts +182 -0
  45. package/backend/db-client/providers/neon/client.ts +298 -0
  46. package/backend/db-client/providers/neon/endpoints.test.ts +201 -0
  47. package/backend/db-client/providers/neon/endpoints.ts +314 -0
  48. package/backend/db-client/providers/neon/list.test.ts +181 -0
  49. package/backend/db-client/providers/supabase/adapter.ts +25 -2
  50. package/backend/db-client/providers/types.ts +57 -0
  51. package/backend/engine/adapters/claude/stream.ts +2 -1
  52. package/backend/engine/adapters/cline/stream.ts +3 -3
  53. package/backend/engine/adapters/codex/stream.ts +3 -3
  54. package/backend/engine/adapters/copilot/stream.ts +3 -3
  55. package/backend/engine/adapters/cursor/stream.ts +25 -3
  56. package/backend/engine/adapters/opencode/stream.ts +4 -6
  57. package/backend/engine/adapters/pi/stream.ts +2 -2
  58. package/backend/engine/adapters/qwen/stream.ts +2 -2
  59. package/backend/engine/artifact-sync.ts +26 -20
  60. package/backend/engine/docs/artifacts.md +81 -22
  61. package/backend/engine/docs/quick-reference.md +2 -1
  62. package/backend/engine/resolve-model.test.ts +108 -0
  63. package/backend/engine/resolve-model.ts +53 -10
  64. package/backend/engine/structured-helpers.ts +22 -0
  65. package/backend/env-files/discovery.ts +48 -0
  66. package/backend/env-files/edit.ts +213 -0
  67. package/backend/env-files/env-files.test.ts +515 -0
  68. package/backend/env-files/git.ts +27 -0
  69. package/backend/env-files/index.ts +44 -0
  70. package/backend/env-files/keys.ts +69 -0
  71. package/backend/env-files/parse.ts +157 -0
  72. package/backend/env-files/write.ts +229 -0
  73. package/backend/files/file-shares.ts +369 -0
  74. package/backend/files/path-browsing.ts +27 -21
  75. package/backend/http/files-shared.test.ts +505 -0
  76. package/backend/http/files-shared.ts +351 -0
  77. package/backend/http/push.ts +150 -0
  78. package/backend/index.ts +8 -0
  79. package/backend/instructions/index.ts +1 -1
  80. package/backend/instructions/sync.ts +30 -6
  81. package/backend/integrations/health.ts +18 -4
  82. package/backend/integrations/projections/types.ts +9 -2
  83. package/backend/integrations/registry/index.ts +3 -0
  84. package/backend/integrations/registry/providers/context7.ts +1 -0
  85. package/backend/integrations/registry/providers/firecrawl.ts +1 -0
  86. package/backend/integrations/registry/providers/github.ts +1 -0
  87. package/backend/integrations/registry/providers/neon.ts +55 -0
  88. package/backend/integrations/registry/providers/supabase.ts +1 -0
  89. package/backend/integrations/registry/providers/vercel.ts +1 -0
  90. package/backend/integrations/registry/types.ts +2 -0
  91. package/backend/memory/compose.ts +2 -2
  92. package/backend/memory/consolidate.ts +2 -2
  93. package/backend/memory/extract/episodic.ts +2 -2
  94. package/backend/memory/judge.ts +2 -2
  95. package/backend/profiles/service.ts +7 -6
  96. package/backend/push/sender.ts +172 -0
  97. package/backend/push/tags.ts +25 -0
  98. package/backend/push/vapid-keys.ts +77 -0
  99. package/backend/push/webpush-crypto.test.ts +200 -0
  100. package/backend/push/webpush-crypto.ts +231 -0
  101. package/backend/skills/detect.ts +28 -0
  102. package/backend/skills/index.ts +22 -4
  103. package/backend/skills/invoke.test.ts +114 -0
  104. package/backend/skills/invoke.ts +222 -0
  105. package/backend/skills/service.ts +194 -44
  106. package/backend/skills/spec.ts +35 -0
  107. package/backend/skills/sync.ts +85 -55
  108. package/backend/subagents/detect.ts +2 -3
  109. package/backend/subagents/sync.ts +15 -8
  110. package/backend/work/pull-requests.ts +2 -2
  111. package/backend/work/start-work.ts +4 -0
  112. package/backend/worktrees/branching/engine.ts +557 -0
  113. package/backend/worktrees/branching/index.ts +56 -0
  114. package/backend/worktrees/branching/naming.test.ts +118 -0
  115. package/backend/worktrees/branching/naming.ts +97 -0
  116. package/backend/worktrees/branching/projector.test.ts +229 -0
  117. package/backend/worktrees/branching/projector.ts +139 -0
  118. package/backend/worktrees/branching/providers/neon.ts +220 -0
  119. package/backend/worktrees/branching/registry.ts +27 -0
  120. package/backend/worktrees/branching/service.ts +620 -0
  121. package/backend/worktrees/branching/suggest.test.ts +154 -0
  122. package/backend/worktrees/branching/suggest.ts +202 -0
  123. package/backend/worktrees/branching/types.ts +88 -0
  124. package/backend/worktrees/index.ts +7 -0
  125. package/backend/worktrees/service.ts +48 -1
  126. package/backend/ws/chat/stream.ts +100 -8
  127. package/backend/ws/db-client/env.ts +142 -0
  128. package/backend/ws/db-client/index.ts +2 -0
  129. package/backend/ws/files/index.ts +4 -0
  130. package/backend/ws/files/share.ts +95 -0
  131. package/backend/ws/git/branch-name.ts +2 -2
  132. package/backend/ws/git/commit-message.ts +2 -2
  133. package/backend/ws/index.ts +3 -4
  134. package/backend/ws/profiles/crud.ts +2 -3
  135. package/backend/ws/projects/index.ts +6 -1
  136. package/backend/ws/projects/info.ts +70 -6
  137. package/backend/ws/projects/overview.test.ts +108 -0
  138. package/backend/ws/projects/overview.ts +300 -0
  139. package/backend/ws/skills/catalog.ts +5 -1
  140. package/backend/ws/skills/crud.ts +128 -22
  141. package/backend/ws/skills/index.ts +4 -1
  142. package/backend/ws/system/device-info.ts +307 -76
  143. package/backend/ws/user/crud.ts +12 -3
  144. package/backend/ws/worktrees/branching.ts +212 -0
  145. package/backend/ws/worktrees/crud.ts +33 -7
  146. package/backend/ws/worktrees/index.ts +14 -0
  147. package/dist/assets/{index-C8Gi-b6U.js → index-CeNKKSDR.js} +1 -1
  148. package/dist/assets/{index-BrF6nqld.js → index-DW89566K.js} +1 -1
  149. package/dist/assets/main-Cy5DXWPT.js +1207 -0
  150. package/dist/assets/main-DJKj_4By.css +1 -0
  151. package/dist/index.html +7 -2
  152. package/dist/sw.js +112 -0
  153. package/package.json +1 -1
  154. package/shared/constants/engine-tools.ts +31 -6
  155. package/shared/constants/notification-messages.ts +142 -0
  156. package/shared/constants/tool-icons.ts +6 -2
  157. package/shared/types/db-client/env.ts +192 -0
  158. package/shared/types/db-client/index.ts +1 -0
  159. package/shared/types/db-client/integrations.ts +30 -0
  160. package/shared/types/integrations.ts +9 -0
  161. package/shared/types/unified/stream.ts +7 -0
  162. package/shared/types/worktree-branching.ts +315 -0
  163. package/shared/utils/logger.ts +1 -0
  164. package/backend/commands/detect.ts +0 -25
  165. package/backend/commands/index.ts +0 -9
  166. package/backend/commands/service.ts +0 -178
  167. package/backend/commands/store.ts +0 -45
  168. package/backend/commands/sync.ts +0 -94
  169. package/backend/database/queries/command-queries.ts +0 -82
  170. package/backend/ws/commands/crud.ts +0 -157
  171. package/backend/ws/commands/index.ts +0 -8
  172. package/dist/assets/main-Bd3gb79F.css +0 -1
  173. package/dist/assets/main-Bo1hD7mt.js +0 -1191
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Neon as a worktree-branching provider.
3
+ *
4
+ * The Neon API client and everything that knows how Neon answers live with the
5
+ * DATABASE adapter, in `backend/db-client/providers/neon/` — one credential,
6
+ * one client, one place a 403 is explained. This file is the thin part: the
7
+ * shape the worktree manager asks for, expressed in calls that module already
8
+ * makes. The alternative, a second Neon client under `worktrees/`, would give
9
+ * one account two independent views of its own rate budget and two places to
10
+ * fix the same error message.
11
+ *
12
+ * Two facts from the OpenAPI document decide the create call below:
13
+ *
14
+ * - `endpoints: [{ type: 'read_write' }]` is MANDATORY. A branch created
15
+ * without it has no compute at all — it exists, it costs storage, and it
16
+ * refuses every connection.
17
+ * - `connection_uris` in the response is OPTIONAL. The document says a branch
18
+ * cut from a parent with more than one role or database comes back without
19
+ * one, so the fallback is a correctness requirement rather than an
20
+ * optimisation: it is the established projects, the ones this feature is
21
+ * most useful for, that take that path.
22
+ *
23
+ * `expires_at` is NOT sent even though it would be the perfect leak guard. It
24
+ * is Early Access only, so sending it would fail for most accounts — orphan
25
+ * detection is Clopen's own job instead.
26
+ */
27
+
28
+ import type {
29
+ BranchParent,
30
+ BranchProviderInfo,
31
+ CreatedBranch,
32
+ RemoteBranch
33
+ } from '$shared/types/worktree-branching';
34
+ import type { IntegrationStatus } from '$shared/types/integrations';
35
+ import type { BranchProviderAdapter, BranchProviderContext } from '../types';
36
+ import {
37
+ NEON_PROVIDER_ID,
38
+ listNeonProjects,
39
+ neonCredentialsOf
40
+ } from '$backend/db-client/providers/neon/adapter';
41
+ import {
42
+ NeonError,
43
+ neonRequest,
44
+ type NeonCredentials
45
+ } from '$backend/db-client/providers/neon/client';
46
+ import {
47
+ connectionFromCreateResponse,
48
+ listBranches,
49
+ resolveBranchConnection
50
+ } from '$backend/db-client/providers/neon/endpoints';
51
+ import type { NeonApiCreatedBranch } from '$backend/db-client/providers/neon/api-types';
52
+ import { debug } from '$shared/utils/logger';
53
+
54
+ /**
55
+ * The db-client adapter's context and this one's are structurally identical —
56
+ * an account id and its decoded credentials. Reusing its credential reader
57
+ * keeps the "reconnect it in Settings" message written once.
58
+ */
59
+ function credentialsOf(context: BranchProviderContext): NeonCredentials {
60
+ return neonCredentialsOf({ accountId: context.accountId, credentials: context.credentials });
61
+ }
62
+
63
+ export const neonBranchAdapter: BranchProviderAdapter = {
64
+ provider: NEON_PROVIDER_ID,
65
+
66
+ info(): BranchProviderInfo {
67
+ return {
68
+ id: NEON_PROVIDER_ID,
69
+ name: 'Neon',
70
+ noun: 'branch',
71
+ parentLabel: 'Neon project',
72
+ description:
73
+ 'Every new worktree gets its own copy-on-write branch of this project, and its connection string.',
74
+ // Names the consequence rather than asking "are you sure" — the rule
75
+ // `Task 3` settled on for outward-facing actions. A branch is cheap but
76
+ // it is not free, and the cap that stops it being created is a plan
77
+ // limit the user can only discover here.
78
+ notice:
79
+ "Each worktree cuts a real Neon branch and deleting the worktree deletes it. Branches count against the project's branch limit.",
80
+ supportsPooled: true
81
+ };
82
+ },
83
+
84
+ async listParents(context: BranchProviderContext): Promise<BranchParent[]> {
85
+ const projects = await listNeonProjects(credentialsOf(context));
86
+ return projects.map((project) => ({
87
+ ref: project.id,
88
+ name: project.name || project.id,
89
+ detail: project.region_id ?? null,
90
+ group: project.org_name ?? null,
91
+ // A Neon project has no state of its own and a suspended compute wakes
92
+ // on connection, so every listed project can be branched from. Claiming
93
+ // otherwise would disable rows that work.
94
+ isReady: true
95
+ }));
96
+ },
97
+
98
+ async createBranch(
99
+ context: BranchProviderContext,
100
+ input: { parentRef: string; name: string; pooled: boolean }
101
+ ): Promise<CreatedBranch> {
102
+ const credentials = credentialsOf(context);
103
+
104
+ const created = await neonRequest<NeonApiCreatedBranch>(
105
+ credentials,
106
+ `/projects/${encodeURIComponent(input.parentRef)}/branches`,
107
+ {
108
+ method: 'POST',
109
+ body: {
110
+ branch: {
111
+ name: input.name,
112
+ // `parent_id` is OMITTED, which means "the project's default
113
+ // branch" — exactly what is wanted, and one fewer request than
114
+ // looking the default up in order to name it.
115
+ //
116
+ // `init_source` is omitted too, so the default `parent-data`
117
+ // applies: schema AND data. A schema-only branch would be cheaper
118
+ // and would defeat the point, since migrating against an empty
119
+ // database tells you nothing about whether the migration is safe
120
+ // for the data that exists.
121
+ },
122
+ // Mandatory. Without a compute the branch cannot be connected to.
123
+ endpoints: [{ type: 'read_write' }]
124
+ }
125
+ }
126
+ );
127
+
128
+ const branch = created?.branch;
129
+ if (!branch?.id) {
130
+ throw new NeonError(
131
+ 'Neon accepted the branch but did not report its id, so it cannot be tracked or cleaned up. Check the project in the Neon console.',
132
+ 502,
133
+ 'error'
134
+ );
135
+ }
136
+
137
+ // Use what the create call already returned when it returned it, and fall
138
+ // back when it did not. Both paths are real: see the file header.
139
+ const inline = connectionFromCreateResponse(created?.connection_uris, input.pooled);
140
+ const connection = inline
141
+ ?? await resolveBranchConnection(credentials, {
142
+ projectId: input.parentRef,
143
+ branchId: branch.id,
144
+ pooled: input.pooled
145
+ });
146
+
147
+ debug.log(
148
+ 'worktree',
149
+ `Cut Neon branch ${branch.name} (${branch.id}) from ${input.parentRef}${inline ? '' : ' — connection resolved separately'}`
150
+ );
151
+
152
+ return {
153
+ ref: branch.id,
154
+ // What Neon ACTUALLY called it, not what was asked for. Neon does not
155
+ // rewrite branch names today, but recording the requested name as
156
+ // though it were the real one is how an orphan sweep starts missing
157
+ // branches the day a provider starts truncating.
158
+ name: branch.name || input.name,
159
+ connection
160
+ };
161
+ },
162
+
163
+ async deleteBranch(
164
+ context: BranchProviderContext,
165
+ input: { parentRef: string; branchRef: string }
166
+ ): Promise<void> {
167
+ try {
168
+ await neonRequest(
169
+ credentialsOf(context),
170
+ `/projects/${encodeURIComponent(input.parentRef)}/branches/${encodeURIComponent(input.branchRef)}`,
171
+ { method: 'DELETE' }
172
+ );
173
+ } catch (error) {
174
+ // A branch that is already gone is a SUCCESS. The caller is deleting a
175
+ // worktree, and turning "it was deleted already" into a failure would
176
+ // file a perfectly clean deletion in the orphan list forever.
177
+ if (error instanceof NeonError && error.status === 404) {
178
+ debug.log('worktree', `Neon branch ${input.branchRef} was already gone`);
179
+ return;
180
+ }
181
+ throw error;
182
+ }
183
+ },
184
+
185
+ async listBranches(context: BranchProviderContext, parentRef: string): Promise<RemoteBranch[]> {
186
+ const branches = await listBranches(credentialsOf(context), parentRef);
187
+ return branches.map((branch) => ({
188
+ ref: branch.id,
189
+ name: branch.name,
190
+ createdAt: branch.created_at ?? null,
191
+ // A protected branch counts as default here too: neither can be deleted,
192
+ // and offering a button that the provider will refuse is worse than not
193
+ // offering one.
194
+ isDefault: branch.default === true || branch.protected === true,
195
+ sizeBytes: typeof branch.logical_size === 'number' ? branch.logical_size : null
196
+ }));
197
+ },
198
+
199
+ async probe(context: BranchProviderContext): Promise<{ status: IntegrationStatus; detail: string | null }> {
200
+ try {
201
+ const projects = await listNeonProjects(credentialsOf(context));
202
+ if (projects.length === 0) {
203
+ return {
204
+ status: 'needs_config',
205
+ detail: 'The key works but reaches no projects to branch from — check which Neon account it belongs to.'
206
+ };
207
+ }
208
+ const plural = projects.length === 1 ? 'project' : 'projects';
209
+ return { status: 'ok', detail: `${projects.length} ${plural} can be branched` };
210
+ } catch (error) {
211
+ if (error instanceof NeonError) {
212
+ const status: IntegrationStatus = error.kind === 'auth'
213
+ ? 'needs_auth'
214
+ : error.kind === 'config' || error.kind === 'quota' ? 'needs_config' : 'error';
215
+ return { status, detail: error.message };
216
+ }
217
+ return { status: 'error', detail: error instanceof Error ? error.message : String(error) };
218
+ }
219
+ }
220
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Adapter registry for worktree database branching.
3
+ *
4
+ * Deliberately dumb, and deliberately the same shape as the Issues, Deployments
5
+ * and DB Client registries: a map from provider id to adapter, filled at module
6
+ * load. Adding Turso is one file in `providers/` plus one line in `index.ts` —
7
+ * one thing to learn rather than four.
8
+ */
9
+
10
+ import type { BranchProviderAdapter } from './types';
11
+
12
+ const adapters = new Map<string, BranchProviderAdapter>();
13
+
14
+ export function registerBranchProvider(adapter: BranchProviderAdapter): void {
15
+ if (adapters.has(adapter.provider)) {
16
+ throw new Error(`A branch adapter for "${adapter.provider}" is already registered`);
17
+ }
18
+ adapters.set(adapter.provider, adapter);
19
+ }
20
+
21
+ export function getBranchProvider(provider: string): BranchProviderAdapter | null {
22
+ return adapters.get(provider) ?? null;
23
+ }
24
+
25
+ export function listBranchProviders(): BranchProviderAdapter[] {
26
+ return [...adapters.values()];
27
+ }