@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
@@ -15,10 +15,39 @@ import { debug } from '$shared/utils/logger';
15
15
  import { trimSubAgentForWire } from '$shared/utils/subagent-wire-trim';
16
16
  import { ws } from '$backend/utils/ws';
17
17
  import { broadcastPresence } from '../projects/status';
18
- import { sessionQueries, messageQueries } from '../../database/queries';
18
+ import { projectQueries, sessionQueries, messageQueries } from '../../database/queries';
19
+ import { sendPushToUser } from '../../push/sender';
20
+ import { chatStreamPushTag, waitingInputPushTag } from '../../push/tags';
21
+ import {
22
+ chatNotificationMessage,
23
+ type ChatNotificationContext
24
+ } from '$shared/constants/notification-messages';
19
25
  import { requireSessionAccess } from '../access';
20
26
  import { resolveSessionPath } from '../../worktrees';
21
27
 
28
+ /**
29
+ * Where a notification-worthy event happened, resolved once on the server.
30
+ *
31
+ * The browser cannot do this itself: the sessions store only holds the project
32
+ * currently open, and these notifications exist precisely for the chats the
33
+ * user is *not* looking at. Shipping the resolved names in the event payload
34
+ * also keeps the tab's local toast worded identically to the server push that
35
+ * replaces it — they share a tag, so any difference would read as the
36
+ * notification rewriting itself.
37
+ *
38
+ * Missing rows yield `undefined`, never a placeholder: the composer drops an
39
+ * absent segment, which says more than the word "Unknown" did.
40
+ */
41
+ function resolveNotificationContext(
42
+ projectId: string,
43
+ chatSessionId: string | undefined
44
+ ): ChatNotificationContext {
45
+ return {
46
+ projectName: projectQueries.getById(projectId)?.name || undefined,
47
+ sessionTitle: chatSessionId ? sessionQueries.getById(chatSessionId)?.title || undefined : undefined
48
+ };
49
+ }
50
+
22
51
  /**
23
52
  * Broadcast presence + notify project members when a chat message may flip the
24
53
  * stream's waiting-for-input state (an AskUserQuestion tool_use arrives, or a
@@ -52,12 +81,31 @@ function handleWaitingInputChange(
52
81
 
53
82
  // Notify all project members when AskUserQuestion arrives (sound + push)
54
83
  if (askToolUse && projectId) {
84
+ const context = resolveNotificationContext(projectId, chatSessionId);
85
+
55
86
  ws.emit.projectMembers(projectId, 'chat:waiting-input', {
56
87
  projectId,
57
88
  chatSessionId,
58
89
  toolUseId: askToolUse.id,
59
- timestamp: event.data?.timestamp || new Date().toISOString()
90
+ timestamp: event.data?.timestamp || new Date().toISOString(),
91
+ ...context
60
92
  });
93
+
94
+ // Background route: reach the requester's devices even when Chrome is
95
+ // closed. Deterministic tag replaces (not stacks with) the local toast
96
+ // the open tab shows for the same question.
97
+ const requestedByUserId = streamManager.getSessionStream(
98
+ chatSessionId,
99
+ projectId
100
+ )?.requestedByUserId;
101
+ if (requestedByUserId) {
102
+ void sendPushToUser(requestedByUserId, {
103
+ ...chatNotificationMessage('waiting-input', context),
104
+ tag: waitingInputPushTag(askToolUse.id)
105
+ }).catch((error) => {
106
+ debug.warn('notification', 'Background waiting-input push failed:', error);
107
+ });
108
+ }
61
109
  }
62
110
  }
63
111
 
@@ -68,8 +116,8 @@ function handleWaitingInputChange(
68
116
  // exists (e.g., after browser refresh when user is on a different project).
69
117
  // Ensures cross-project notifications (presence update, sound, push) always work.
70
118
  // ============================================================================
71
- streamManager.on('stream:lifecycle', (event: { status: string; streamId: string; projectId?: string; chatSessionId?: string; timestamp: string; reason?: string }) => {
72
- const { status, projectId, chatSessionId, timestamp, reason } = event;
119
+ streamManager.on('stream:lifecycle', (event: { status: string; streamId: string; projectId?: string; chatSessionId?: string; requestedByUserId?: string; timestamp: string; reason?: string }) => {
120
+ const { status, streamId, projectId, chatSessionId, requestedByUserId, timestamp, reason } = event;
73
121
  if (!projectId) return;
74
122
 
75
123
  debug.log('chat', `Stream lifecycle: ${status} for project ${projectId} session ${chatSessionId}${reason ? ` (reason: ${reason})` : ''}`);
@@ -83,15 +131,39 @@ streamManager.on('stream:lifecycle', (event: { status: string; streamId: string;
83
131
  }
84
132
  }
85
133
 
134
+ // Resolved once and shared: the payload below carries it to the open tab,
135
+ // and the background push below that reuses the very same values, so the
136
+ // two copies of one event cannot word themselves differently.
137
+ const context = resolveNotificationContext(projectId, chatSessionId);
138
+
86
139
  // Notify all project members (cross-project notification for sound + push)
87
140
  ws.emit.projectMembers(projectId, 'chat:stream-finished', {
88
141
  projectId,
89
142
  chatSessionId: chatSessionId || '',
143
+ streamId,
90
144
  status: status as 'completed' | 'error' | 'cancelled',
91
145
  timestamp,
92
- reason
146
+ reason,
147
+ ...context
93
148
  });
94
149
 
150
+ // Background route: the open tab notifies locally via the WS event above;
151
+ // this reaches the requester's devices when Chrome is closed. The shared
152
+ // deterministic tag means an open tab's local toast is replaced, never
153
+ // duplicated. Never throws — chat completion must not depend on push.
154
+ if (requestedByUserId && reason !== 'session-deleted') {
155
+ // `cancelled` gets its own title. Filing it under a "complete" heading
156
+ // with an "interrupted" body made the notification contradict itself.
157
+ const notificationEvent =
158
+ status === 'error' ? 'error' : status === 'cancelled' ? 'cancelled' : 'completed';
159
+ void sendPushToUser(requestedByUserId, {
160
+ ...chatNotificationMessage(notificationEvent, context),
161
+ tag: chatStreamPushTag(streamId)
162
+ }).catch((error) => {
163
+ debug.warn('notification', 'Background stream-finished push failed:', error);
164
+ });
165
+ }
166
+
95
167
  // Broadcast updated presence (status indicators for all projects)
96
168
  broadcastPresence().catch((err) => {
97
169
  debug.warn('chat', 'Presence broadcast error after stream lifecycle:', err);
@@ -241,6 +313,16 @@ export const streamHandler = createRouter()
241
313
  workingRoot
242
314
  });
243
315
 
316
+ // The WS user id is server-trusted (unlike the client-supplied sender)
317
+ // and routes background Web Push to the requester's devices. Missing
318
+ // context must not break the stream — push is best-effort.
319
+ let requestedByUserId: string | undefined;
320
+ try {
321
+ requestedByUserId = ws.getUserId(conn);
322
+ } catch {
323
+ requestedByUserId = undefined;
324
+ }
325
+
244
326
  // Start background stream
245
327
  const streamId = await streamManager.startStream({
246
328
  projectPath: workingRoot,
@@ -250,7 +332,8 @@ export const streamHandler = createRouter()
250
332
  engine: data.engine,
251
333
  sender: data.sender,
252
334
  profileId: data.profileId,
253
- reasoningEffort: data.reasoningEffort
335
+ reasoningEffort: data.reasoningEffort,
336
+ requestedByUserId
254
337
  });
255
338
 
256
339
  debug.log('chat', 'Stream started with ID:', streamId);
@@ -1085,19 +1168,28 @@ export const streamHandler = createRouter()
1085
1168
  timestamp: t.String()
1086
1169
  }))
1087
1170
 
1171
+ // `projectName` / `sessionTitle` are resolved server-side and carried here
1172
+ // so the tab can word its local notification exactly like the background
1173
+ // push that replaces it. Optional because either row may be gone, and
1174
+ // because a tab left open across a server upgrade will not send them.
1088
1175
  .emit('chat:stream-finished', t.Object({
1089
1176
  projectId: t.String(),
1090
1177
  chatSessionId: t.String(),
1178
+ streamId: t.Optional(t.String()),
1091
1179
  status: t.Union([t.Literal('completed'), t.Literal('error'), t.Literal('cancelled')]),
1092
1180
  timestamp: t.String(),
1093
- reason: t.Optional(t.String())
1181
+ reason: t.Optional(t.String()),
1182
+ projectName: t.Optional(t.String()),
1183
+ sessionTitle: t.Optional(t.String())
1094
1184
  }))
1095
1185
 
1096
1186
  .emit('chat:waiting-input', t.Object({
1097
1187
  projectId: t.String(),
1098
1188
  chatSessionId: t.String(),
1099
1189
  toolUseId: t.String(),
1100
- timestamp: t.String()
1190
+ timestamp: t.String(),
1191
+ projectName: t.Optional(t.String()),
1192
+ sessionTitle: t.Optional(t.String())
1101
1193
  }))
1102
1194
 
1103
1195
  .emit('snapshot:captured', t.Object({
@@ -0,0 +1,142 @@
1
+ /**
2
+ * db-client — the connection as environment variables.
3
+ *
4
+ * THESE ROUTES HAND BACK A PASSWORD, which no other db-client route does:
5
+ * `db-client:list` redacts every secret before it crosses the wire. That is not
6
+ * an oversight being reversed, it is a different question — a connection string
7
+ * the user cannot copy solves nothing, and the whole feature is "put this into
8
+ * my project's `.env`". So the secret is gated at the ROUTE instead of stripped
9
+ * from the payload.
10
+ *
11
+ * Two gates, both already load-bearing elsewhere:
12
+ *
13
+ * - `requireDbClientConnectionAccess` is the owner-or-admin check the rest of
14
+ * the surface uses. A projected connection has NO owner, which in
15
+ * db-client's access model means only an admin can reach it — the same
16
+ * reason `db-client:link` is admin-only, arrived at without a second rule.
17
+ * - `requireProjectWorkspace` decides which tree a write lands in, and it is
18
+ * worktree-aware. A user looking at a worktree gets the worktree's `.env`,
19
+ * because that is the checkout their dev server is running from.
20
+ */
21
+
22
+ import { t } from 'elysia';
23
+ import { createRouter } from '$shared/utils/ws-server';
24
+ import type { WSConnection } from '$shared/utils/ws-server';
25
+ import { ws } from '$backend/utils/ws';
26
+ import { worktreeQueries } from '$backend/database/queries';
27
+ import { dbClientEnv, type EnvScope } from '../../db-client/env';
28
+ import type { DbEnvRequest } from '$shared/types/db-client';
29
+ import { requireProjectWorkspace } from '../access';
30
+ import { requireDbClientConnectionAccess } from './access';
31
+
32
+ const requestSchema = t.Object({
33
+ connectionId: t.String({ minLength: 1 }),
34
+ projectId: t.Optional(t.String()),
35
+ database: t.Optional(t.String()),
36
+ shape: t.Union([t.Literal('url'), t.Literal('split')]),
37
+ prefix: t.Optional(t.String()),
38
+ keyMap: t.Optional(t.Record(t.String(), t.String())),
39
+ fileName: t.Optional(t.String()),
40
+ includeAlternate: t.Optional(t.Boolean()),
41
+ allowTracked: t.Optional(t.Boolean())
42
+ });
43
+
44
+ /**
45
+ * The tree a write would land in, or null.
46
+ *
47
+ * Null rather than an error when no project is in scope: the panel still shows
48
+ * the variables and still lets them be copied, which is most of the value. A
49
+ * route that refused would turn "no project open" into "this feature is
50
+ * broken".
51
+ */
52
+ function resolveScope(conn: WSConnection, projectId?: string): EnvScope | null {
53
+ const target = (projectId ?? '').trim() || safeCurrentProject(conn);
54
+ if (!target) return null;
55
+
56
+ const { project, root, worktreeId } = requireProjectWorkspace(conn, target);
57
+ const worktree = worktreeId ? worktreeQueries.getById(worktreeId) : null;
58
+
59
+ return {
60
+ projectId: project.id,
61
+ // Named so the panel can say WHERE it is about to write. A worktree is a
62
+ // different checkout with its own dotenv file, and not saying so is how a
63
+ // user ends up looking for a variable in the main project.
64
+ projectName: worktree ? `${project.name} / ${worktree.name}` : project.name,
65
+ root
66
+ };
67
+ }
68
+
69
+ function safeCurrentProject(conn: WSConnection): string | null {
70
+ try {
71
+ return ws.getProjectId(conn);
72
+ } catch {
73
+ return null;
74
+ }
75
+ }
76
+
77
+ function requireScope(conn: WSConnection, projectId?: string): EnvScope {
78
+ const scope = resolveScope(conn, projectId);
79
+ if (!scope) throw new Error('Open a project before writing to its environment file.');
80
+ return scope;
81
+ }
82
+
83
+ export const envHandler = createRouter()
84
+ .http('db-client:env-state', {
85
+ data: t.Object({
86
+ connectionId: t.String({ minLength: 1 }),
87
+ projectId: t.Optional(t.String()),
88
+ database: t.Optional(t.String())
89
+ }),
90
+ response: t.Any()
91
+ }, async ({ data, conn }) => {
92
+ const connection = requireDbClientConnectionAccess(conn, data.connectionId);
93
+ return dbClientEnv.state(connection, resolveScope(conn, data.projectId), data.database);
94
+ })
95
+
96
+ .http('db-client:env-preview', {
97
+ data: requestSchema,
98
+ response: t.Any()
99
+ }, async ({ data, conn }) => {
100
+ const connection = requireDbClientConnectionAccess(conn, data.connectionId);
101
+ return dbClientEnv.plan(connection, resolveScope(conn, data.projectId), toRequest(data));
102
+ })
103
+
104
+ .http('db-client:env-apply', {
105
+ data: requestSchema,
106
+ response: t.Any()
107
+ }, async ({ data, conn }) => {
108
+ const connection = requireDbClientConnectionAccess(conn, data.connectionId);
109
+ return dbClientEnv.apply(connection, requireScope(conn, data.projectId), toRequest(data));
110
+ })
111
+
112
+ .http('db-client:env-remove', {
113
+ data: requestSchema,
114
+ response: t.Any()
115
+ }, async ({ data, conn }) => {
116
+ const connection = requireDbClientConnectionAccess(conn, data.connectionId);
117
+ return dbClientEnv.remove(connection, requireScope(conn, data.projectId), toRequest(data));
118
+ });
119
+
120
+ function toRequest(data: {
121
+ connectionId: string;
122
+ projectId?: string;
123
+ database?: string;
124
+ shape: string;
125
+ prefix?: string;
126
+ keyMap?: Record<string, string>;
127
+ fileName?: string;
128
+ includeAlternate?: boolean;
129
+ allowTracked?: boolean;
130
+ }): DbEnvRequest {
131
+ return {
132
+ connectionId: data.connectionId,
133
+ projectId: data.projectId,
134
+ database: data.database,
135
+ shape: data.shape as DbEnvRequest['shape'],
136
+ prefix: data.prefix ?? '',
137
+ keyMap: data.keyMap as DbEnvRequest['keyMap'],
138
+ fileName: data.fileName,
139
+ includeAlternate: data.includeAlternate,
140
+ allowTracked: data.allowTracked
141
+ };
142
+ }
@@ -18,6 +18,7 @@ import { structureHandler } from './structure';
18
18
  import { ioHandler } from './io';
19
19
  import { accountsHandler } from './accounts';
20
20
  import { supabaseHandler } from './supabase';
21
+ import { envHandler } from './env';
21
22
 
22
23
  export const dbClientRouter = createRouter()
23
24
  .merge(connectionsHandler)
@@ -27,6 +28,7 @@ export const dbClientRouter = createRouter()
27
28
  .merge(ioHandler)
28
29
  .merge(accountsHandler)
29
30
  .merge(supabaseHandler)
31
+ .merge(envHandler)
30
32
  /**
31
33
  * Broadcast when the connection list changes for a reason the requesting
32
34
  * client did not cause — a link created, a link dropped, an account
@@ -19,6 +19,7 @@ import { revealHandler } from './reveal';
19
19
  import { clipboardHandler } from './clipboard';
20
20
  import { imageEditHandler } from './image-edit';
21
21
  import { fileSearchHandler } from './search';
22
+ import { fileShareHandler } from './share';
22
23
  import { watchHandler } from './watch';
23
24
  import { filesStateHandler } from './state';
24
25
 
@@ -41,6 +42,9 @@ export const filesRouter = createRouter()
41
42
  // Search Operations (HTTP)
42
43
  .merge(fileSearchHandler)
43
44
 
45
+ // Single-file share links (HTTP)
46
+ .merge(fileShareHandler)
47
+
44
48
  // Watch Operations (Events)
45
49
  .merge(watchHandler)
46
50
 
@@ -0,0 +1,95 @@
1
+ /**
2
+ * File share-link WebSocket handlers (File Explorer → "Share Link…").
3
+ *
4
+ * - files:create-share — authenticated user mints a link for one file, with
5
+ * its one-time / deadline options. The raw token is embedded in the share
6
+ * URL; only its hash is stored, and the row id comes back alongside it so
7
+ * the link stays manageable afterwards.
8
+ * - files:list-shares — live links: every user's for an admin, your own
9
+ * otherwise. Carries no token material, so it can never rebuild a URL.
10
+ * - files:revoke-share — creator (or admin) invalidates a link by row id.
11
+ * - files:shares-changed — broadcast whenever that list moves, so every open
12
+ * management view reflects a mint, a revoke or an open without polling.
13
+ *
14
+ * Reachability (how another device can open the link) is NOT handled here —
15
+ * the frontend builds the URL against the Remote Access public origin
16
+ * (`share:ensure-origin`), reusing that system instead of a new one.
17
+ */
18
+
19
+ import { t } from 'elysia';
20
+ import { createRouter } from '$shared/utils/ws-server';
21
+ import { ws } from '$backend/utils/ws';
22
+ import {
23
+ createFileShareLink,
24
+ listFileShares,
25
+ revokeFileShareLink,
26
+ MAX_FILE_SHARE_TTL_MINUTES
27
+ } from '../../files/file-shares';
28
+
29
+ const shareSummary = t.Object({
30
+ id: t.String(),
31
+ filePath: t.String(),
32
+ fileName: t.String(),
33
+ projectName: t.Union([t.String(), t.Null()]),
34
+ worktreeName: t.Union([t.String(), t.Null()]),
35
+ relativePath: t.String(),
36
+ createdBy: t.String(),
37
+ createdByName: t.Union([t.String(), t.Null()]),
38
+ createdAt: t.String(),
39
+ oneTime: t.Boolean(),
40
+ expiresAt: t.Union([t.String(), t.Null()]),
41
+ openCount: t.Number(),
42
+ lastOpenedAt: t.Union([t.String(), t.Null()]),
43
+ consumedAt: t.Union([t.String(), t.Null()])
44
+ });
45
+
46
+ export const fileShareHandler = createRouter()
47
+ .http('files:create-share', {
48
+ data: t.Object({
49
+ file_path: t.String({ minLength: 1 }),
50
+ /** Burn on the first open. Defaults to true. */
51
+ oneTime: t.Optional(t.Boolean()),
52
+ /** Minutes until it lapses, or null for "until revoked". */
53
+ expiresInMinutes: t.Optional(
54
+ t.Union([t.Number({ minimum: 1, maximum: MAX_FILE_SHARE_TTL_MINUTES }), t.Null()])
55
+ )
56
+ }),
57
+ response: t.Object({
58
+ shareId: t.String(),
59
+ shareToken: t.String(),
60
+ oneTime: t.Boolean(),
61
+ expiresAt: t.Union([t.String(), t.Null()])
62
+ })
63
+ }, async ({ data, conn }) => {
64
+ const result = await createFileShareLink(data.file_path, ws.getRole(conn), ws.getUserId(conn), {
65
+ oneTime: data.oneTime,
66
+ expiresInMinutes: data.expiresInMinutes
67
+ });
68
+ ws.emit.global('files:shares-changed', { kind: 'created' });
69
+ return result;
70
+ })
71
+
72
+ .http('files:list-shares', {
73
+ data: t.Object({}),
74
+ response: t.Object({ shares: t.Array(shareSummary) })
75
+ }, async ({ conn }) => {
76
+ return { shares: listFileShares(ws.getRole(conn), ws.getUserId(conn)) };
77
+ })
78
+
79
+ .http('files:revoke-share', {
80
+ data: t.Object({
81
+ shareId: t.String({ minLength: 1 })
82
+ }),
83
+ response: t.Object({ success: t.Boolean() })
84
+ }, async ({ data, conn }) => {
85
+ const success = revokeFileShareLink(data.shareId, ws.getRole(conn), ws.getUserId(conn));
86
+ if (success) ws.emit.global('files:shares-changed', { kind: 'revoked' });
87
+ return { success };
88
+ })
89
+
90
+ // Broadcast-only: the payload says nothing about whose link moved, because
91
+ // every listener re-reads its own role-scoped list. A global ping cannot
92
+ // leak what a user is not allowed to see.
93
+ .emit('files:shares-changed', t.Object({
94
+ kind: t.String()
95
+ }));
@@ -9,7 +9,7 @@ import { createRouter } from '$shared/utils/ws-server';
9
9
  import { execGit } from '../../git/git-executor';
10
10
  import { buildBudgetedStagedDiff, BRANCH_NAME_BUDGET } from './diff-budget';
11
11
  import { initializeEngine } from '../../engine';
12
- import { resolveGenerationTarget } from '../../engine/resolve-model';
12
+ import { resolveGenerationTarget, GENERATION_SETTINGS } from '../../engine/resolve-model';
13
13
  import type { EngineType } from '$shared/types/unified';
14
14
  import type { GeneratedBranchName } from '$shared/types/git';
15
15
  import {
@@ -171,7 +171,7 @@ export const branchNameHandler = createRouter()
171
171
  const prompt = `${instructions}${extra ? `\n\nAdditional constraints:\n${extra}` : ''}\n\n${diff.text}`;
172
172
 
173
173
  // The caller's providerSlug/account can be stale (see resolve-model.ts).
174
- const target = await resolveGenerationTarget(engine, data.modelId, data.providerSlug);
174
+ const target = await resolveGenerationTarget(engine, data.modelId, data.providerSlug, GENERATION_SETTINGS.commit);
175
175
 
176
176
  debug.log('git', `Generating branch name via ${engineType}/${target.providerSlug}/${target.modelId}`);
177
177
 
@@ -8,7 +8,7 @@ import { t } from 'elysia';
8
8
  import { createRouter } from '$shared/utils/ws-server';
9
9
  import { buildBudgetedStagedDiff, COMMIT_MESSAGE_BUDGET } from './diff-budget';
10
10
  import { initializeEngine } from '../../engine';
11
- import { resolveGenerationTarget } from '../../engine/resolve-model';
11
+ import { resolveGenerationTarget, GENERATION_SETTINGS } from '../../engine/resolve-model';
12
12
  import type { EngineType } from '$shared/types/unified';
13
13
  import type { GeneratedCommitMessage } from '$shared/types/git';
14
14
  import { debug } from '$shared/utils/logger';
@@ -116,7 +116,7 @@ ${diff.text}`;
116
116
  : defaultPrompt;
117
117
 
118
118
  // The caller's providerSlug/account can be stale (see resolve-model.ts).
119
- const target = await resolveGenerationTarget(engine, data.modelId, data.providerSlug);
119
+ const target = await resolveGenerationTarget(engine, data.modelId, data.providerSlug, GENERATION_SETTINGS.commit);
120
120
 
121
121
  debug.log('git', `Generating commit message via ${engineType}/${target.providerSlug}/${target.modelId}`);
122
122
 
@@ -37,7 +37,6 @@ import { containersRouter } from './containers';
37
37
  import { mcpRouter } from './mcp';
38
38
  import { integrationsRouter } from './integrations';
39
39
  import { skillsRouter } from './skills';
40
- import { commandsRouter } from './commands';
41
40
  import { subagentsRouter } from './subagents';
42
41
  import { instructionsRouter } from './instructions';
43
42
  import { permissionsRouter } from './permissions';
@@ -104,11 +103,11 @@ export const wsRouter = createRouter()
104
103
  .merge(mcpRouter)
105
104
  .merge(integrationsRouter)
106
105
 
107
- // Agent Skills management (create, import, install from a marketplace)
106
+ // Agent Skills management — model-invoked skills AND user-invoked `/slash`
107
+ // prompts are one feature (create, import, install from a marketplace)
108
108
  .merge(skillsRouter)
109
109
 
110
- // Custom Commands, Subagents, and Project Instructions (artifact framework)
111
- .merge(commandsRouter)
110
+ // Subagents and Project Instructions (artifact framework)
112
111
  .merge(subagentsRouter)
113
112
  .merge(instructionsRouter)
114
113
  .merge(permissionsRouter)
@@ -24,7 +24,6 @@ import type { EngineType } from '$shared/types/unified';
24
24
 
25
25
  const ITEMS_SCHEMA = t.Object({
26
26
  skill: t.Array(t.String()),
27
- command: t.Array(t.String()),
28
27
  subagent: t.Array(t.String()),
29
28
  mcp: t.Array(t.String())
30
29
  });
@@ -41,7 +40,7 @@ const PROFILE_SCHEMA = t.Object({
41
40
  });
42
41
 
43
42
  const ITEM_INPUT_SCHEMA = t.Array(t.Object({
44
- artifactType: t.Union([t.Literal('skill'), t.Literal('command'), t.Literal('subagent'), t.Literal('mcp')]),
43
+ artifactType: t.Union([t.Literal('skill'), t.Literal('subagent'), t.Literal('mcp')]),
45
44
  ref: t.String()
46
45
  }));
47
46
 
@@ -72,7 +71,7 @@ export const profilesCrudHandler = createRouter()
72
71
  })
73
72
  .http('profiles:inventory', {
74
73
  data: t.Object({}),
75
- response: t.Object({ skill: INVENTORY_ENTRY, command: INVENTORY_ENTRY, subagent: INVENTORY_ENTRY, mcp: INVENTORY_ENTRY })
74
+ response: t.Object({ skill: INVENTORY_ENTRY, subagent: INVENTORY_ENTRY, mcp: INVENTORY_ENTRY })
76
75
  }, () => {
77
76
  debug.log('path', 'profiles:inventory');
78
77
  return profileService.inventory();
@@ -7,6 +7,7 @@
7
7
  * - crud.ts: HTTP endpoints for CRUD operations (list, create, get, update, delete)
8
8
  * - status.ts: Real-time status updates and watching (get-status, watch, unwatch, events)
9
9
  * - presence.ts: User presence management (update-presence with broadcast)
10
+ * - overview.ts: Per-project resource usage for every project (projects:overview)
10
11
  */
11
12
 
12
13
  import { createRouter } from '$shared/utils/ws-server';
@@ -14,6 +15,7 @@ import { crudHandler } from './crud';
14
15
  import { statusHandler } from './status';
15
16
  import { presenceHandler } from './presence';
16
17
  import { infoHandler } from './info';
18
+ import { overviewHandler } from './overview';
17
19
 
18
20
  export const projectsRouter = createRouter()
19
21
  // CRUD Operations (HTTP)
@@ -26,4 +28,7 @@ export const projectsRouter = createRouter()
26
28
  .merge(presenceHandler)
27
29
 
28
30
  // Per-project resource info (storage + process-isolated CPU/RAM)
29
- .merge(infoHandler);
31
+ .merge(infoHandler)
32
+
33
+ // Per-project resource usage across every project the caller can see
34
+ .merge(overviewHandler);