@myrialabs/clopen 0.4.47 → 0.4.48

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 (325) hide show
  1. package/README.md +11 -11
  2. package/backend/artifacts/project/sources.ts +1 -1
  3. package/backend/auth/auth-service.ts +52 -358
  4. package/backend/auth/onboarding.test.ts +2 -3
  5. package/backend/auth/permissions.test.ts +10 -20
  6. package/backend/auth/permissions.ts +4 -290
  7. package/backend/auth/rate-limiter.test.ts +8 -9
  8. package/backend/auth/rate-limiter.ts +0 -2
  9. package/backend/auth/tokens.ts +1 -8
  10. package/backend/bootstrap.ts +7 -0
  11. package/backend/chat/attachments.test.ts +88 -0
  12. package/backend/chat/attachments.ts +159 -0
  13. package/backend/chat/engine-handoff.test.ts +0 -2
  14. package/backend/chat/stream-manager.ts +62 -62
  15. package/backend/chat/turn-answer.test.ts +64 -0
  16. package/backend/chat/turn-answer.ts +125 -0
  17. package/backend/chat-apps/awaiting.test.ts +39 -0
  18. package/backend/chat-apps/awaiting.ts +49 -0
  19. package/backend/chat-apps/conversation.ts +746 -0
  20. package/backend/chat-apps/inbound.ts +324 -0
  21. package/backend/chat-apps/index.ts +309 -0
  22. package/backend/chat-apps/link-events.ts +20 -0
  23. package/backend/chat-apps/media.test.ts +62 -0
  24. package/backend/chat-apps/media.ts +208 -0
  25. package/backend/chat-apps/messages.test.ts +229 -0
  26. package/backend/chat-apps/messages.ts +365 -0
  27. package/backend/chat-apps/outbound.ts +243 -0
  28. package/backend/chat-apps/pairing.test.ts +45 -0
  29. package/backend/chat-apps/pairing.ts +74 -0
  30. package/backend/chat-apps/platforms/index.ts +20 -0
  31. package/backend/chat-apps/platforms/telegram.test.ts +35 -0
  32. package/backend/chat-apps/platforms/telegram.ts +191 -0
  33. package/backend/chat-apps/platforms/types.ts +114 -0
  34. package/backend/chat-apps/questions.ts +133 -0
  35. package/backend/chat-apps/runtime.ts +572 -0
  36. package/backend/chat-apps/storage.test.ts +201 -0
  37. package/backend/chat-apps/turns.test.ts +45 -0
  38. package/backend/chat-apps/turns.ts +208 -0
  39. package/backend/containers/pty.ts +3 -11
  40. package/backend/control/actions/accounts.ts +89 -0
  41. package/backend/control/actions/files.ts +116 -0
  42. package/backend/control/actions/models.ts +188 -0
  43. package/backend/control/actions/projects.ts +272 -0
  44. package/backend/control/actions/sessions.ts +280 -0
  45. package/backend/control/actions/skills.ts +111 -0
  46. package/backend/control/control.test.ts +169 -0
  47. package/backend/control/define.ts +20 -0
  48. package/backend/control/folders.test.ts +67 -0
  49. package/backend/control/index.ts +213 -0
  50. package/backend/control/invoke.ts +44 -0
  51. package/backend/control/links.ts +35 -0
  52. package/backend/control/paging.ts +26 -0
  53. package/backend/control/types.ts +117 -0
  54. package/backend/control/workspace.ts +127 -0
  55. package/backend/database/migrations/084_create_channel_links.ts +71 -0
  56. package/backend/database/migrations/085_add_home_projects.ts +36 -0
  57. package/backend/database/migrations/086_single_owner.test.ts +170 -0
  58. package/backend/database/migrations/086_single_owner.ts +418 -0
  59. package/backend/database/migrations/index.ts +21 -0
  60. package/backend/database/queries/auth-queries.ts +7 -85
  61. package/backend/database/queries/channel-queries.ts +270 -0
  62. package/backend/database/queries/db-client-connection-queries.ts +18 -56
  63. package/backend/database/queries/file-share-queries.ts +5 -23
  64. package/backend/database/queries/git-identity-queries.ts +31 -42
  65. package/backend/database/queries/graph-queries.ts +1 -1
  66. package/backend/database/queries/index.ts +13 -1
  67. package/backend/database/queries/message-queries.test.ts +146 -0
  68. package/backend/database/queries/message-queries.ts +42 -1
  69. package/backend/database/queries/permission-set-queries.ts +1 -1
  70. package/backend/database/queries/profile-queries.ts +1 -1
  71. package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
  72. package/backend/database/queries/project-queries.ts +50 -63
  73. package/backend/database/queries/session-queries.ts +28 -56
  74. package/backend/database/queries/ssh-connection-queries.ts +18 -41
  75. package/backend/db-client/integrations/projector.ts +0 -5
  76. package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
  77. package/backend/engine/adapters/claude/message-converter.ts +25 -2
  78. package/backend/engine/adapters/cline/message-converter.ts +0 -1
  79. package/backend/engine/adapters/cline/stream.ts +11 -15
  80. package/backend/engine/adapters/codex/message-converter.ts +0 -2
  81. package/backend/engine/adapters/copilot/message-converter.ts +1 -2
  82. package/backend/engine/adapters/cursor/message-converter.ts +0 -1
  83. package/backend/engine/adapters/opencode/message-converter.ts +2 -4
  84. package/backend/engine/adapters/opencode/stream.ts +11 -0
  85. package/backend/engine/adapters/parent-scope.test.ts +38 -0
  86. package/backend/engine/adapters/parent-scope.ts +44 -0
  87. package/backend/engine/adapters/pi/message-converter.ts +0 -1
  88. package/backend/engine/adapters/pi/stream.ts +4 -5
  89. package/backend/engine/adapters/qwen/message-converter.ts +0 -2
  90. package/backend/engine/bootstrap-default-engine.ts +2 -2
  91. package/backend/engine/docs/adapter-contract.md +8 -1
  92. package/backend/engine/install-runner.ts +8 -17
  93. package/backend/files/file-shares.ts +20 -44
  94. package/backend/files/file-size-limit.ts +3 -3
  95. package/backend/files/image-processing.ts +1 -1
  96. package/backend/files/os-clipboard.ts +2 -2
  97. package/backend/git/git-executor.ts +25 -5
  98. package/backend/git/git-service.ts +420 -19
  99. package/backend/git/identity/credential-helper.test.ts +2 -7
  100. package/backend/git/identity/import-local.test.ts +11 -16
  101. package/backend/git/identity/import-local.ts +12 -12
  102. package/backend/git/identity/index.ts +10 -24
  103. package/backend/git/identity/resolve.ts +13 -14
  104. package/backend/git/identity/scope-config.ts +33 -28
  105. package/backend/git/identity/service.ts +44 -47
  106. package/backend/git/op-lock.test.ts +111 -0
  107. package/backend/git/op-lock.ts +180 -0
  108. package/backend/git/remote-sync.test.ts +249 -0
  109. package/backend/host/metrics.ts +1 -1
  110. package/backend/http/bearer-auth.ts +1 -2
  111. package/backend/http/files-download.test.ts +8 -9
  112. package/backend/http/files-download.ts +2 -2
  113. package/backend/http/files-shared.test.ts +62 -89
  114. package/backend/http/files-shared.ts +2 -2
  115. package/backend/http/files-upload.test.ts +3 -7
  116. package/backend/http/files-upload.ts +3 -3
  117. package/backend/http/notes-images.test.ts +15 -38
  118. package/backend/http/notes-images.ts +6 -8
  119. package/backend/http/ssh-sftp.ts +5 -10
  120. package/backend/index.ts +21 -7
  121. package/backend/integrations/accounts.ts +61 -3
  122. package/backend/integrations/index.ts +2 -2
  123. package/backend/integrations/registry/define.ts +15 -0
  124. package/backend/integrations/registry/index.ts +2 -0
  125. package/backend/integrations/registry/providers/telegram.ts +54 -0
  126. package/backend/integrations/registry/types.ts +21 -1
  127. package/backend/integrations/webhooks/gateway.ts +7 -6
  128. package/backend/integrations/webhooks/verify.test.ts +30 -0
  129. package/backend/integrations/webhooks/verify.ts +4 -0
  130. package/backend/mcp/external/project.ts +1 -1
  131. package/backend/mcp/internal/remote-server.test.ts +1 -3
  132. package/backend/mcp/internal/remote-server.ts +4 -4
  133. package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
  134. package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
  135. package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
  136. package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
  137. package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
  138. package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
  139. package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
  140. package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
  141. package/backend/memory/redact.ts +1 -1
  142. package/backend/notes/access.test.ts +28 -29
  143. package/backend/notes/access.ts +6 -11
  144. package/backend/permissions/service.ts +1 -1
  145. package/backend/preview/browser/browser-clipboard.test.ts +46 -0
  146. package/backend/preview/browser/browser-clipboard.ts +67 -0
  147. package/backend/preview/browser/browser-dialog-handler.ts +95 -6
  148. package/backend/preview/browser/browser-host-bridge.ts +9 -0
  149. package/backend/preview/browser/browser-interaction-handler.ts +316 -86
  150. package/backend/preview/browser/browser-mcp-control.ts +34 -0
  151. package/backend/preview/browser/browser-pool.ts +67 -6
  152. package/backend/preview/browser/browser-preview-service.ts +361 -25
  153. package/backend/preview/browser/browser-tab-manager.ts +66 -23
  154. package/backend/preview/browser/browser-video-capture.ts +92 -5
  155. package/backend/preview/browser/element-locator.ts +190 -17
  156. package/backend/preview/browser/keyboard-chords.test.ts +68 -0
  157. package/backend/preview/browser/keyboard-chords.ts +132 -0
  158. package/backend/preview/browser/paste.ts +81 -0
  159. package/backend/preview/browser/process-usage.ts +142 -0
  160. package/backend/preview/browser/profile-lock.ts +209 -0
  161. package/backend/preview/browser/scripts/host-bridge.ts +59 -0
  162. package/backend/preview/browser/scripts/video-stream.ts +58 -0
  163. package/backend/preview/browser/types.ts +40 -2
  164. package/backend/preview/browser/viewport.test.ts +45 -0
  165. package/backend/preview/browser/viewport.ts +96 -0
  166. package/backend/profiles/service.ts +2 -2
  167. package/backend/project/status-manager.ts +43 -172
  168. package/backend/projects/home.ts +61 -0
  169. package/backend/projects/project-cleanup.integration.test.ts +2 -2
  170. package/backend/projects/project-cleanup.ts +0 -8
  171. package/backend/skills/service.ts +2 -3
  172. package/backend/snapshot/helpers.ts +0 -1
  173. package/backend/snapshot/restore.ts +252 -0
  174. package/backend/ssh/ptykit.ts +1 -2
  175. package/backend/terminal/ptykit.ts +5 -8
  176. package/backend/tunnel/public-origin.ts +31 -20
  177. package/backend/utils/user-helpers.ts +0 -55
  178. package/backend/utils/ws.ts +61 -154
  179. package/backend/worktrees/branching/engine.ts +3 -16
  180. package/backend/worktrees/branching/index.ts +1 -1
  181. package/backend/worktrees/branching/projector.ts +1 -1
  182. package/backend/worktrees/branching/service.ts +13 -25
  183. package/backend/ws/access.ts +12 -21
  184. package/backend/ws/artifacts/generate.ts +2 -2
  185. package/backend/ws/auth/device.ts +16 -71
  186. package/backend/ws/auth/index.ts +4 -22
  187. package/backend/ws/auth/login.test.ts +14 -60
  188. package/backend/ws/auth/login.ts +24 -124
  189. package/backend/ws/auth/status.ts +0 -1
  190. package/backend/ws/chat/composer.ts +118 -118
  191. package/backend/ws/chat/stream.ts +64 -47
  192. package/backend/ws/chat-apps/index.ts +117 -0
  193. package/backend/ws/containers/actions.ts +11 -25
  194. package/backend/ws/containers/index.ts +3 -4
  195. package/backend/ws/containers/list.ts +10 -36
  196. package/backend/ws/containers/logs.ts +2 -2
  197. package/backend/ws/containers/tunnel.ts +1 -2
  198. package/backend/ws/db-client/access.ts +2 -16
  199. package/backend/ws/db-client/accounts.ts +5 -15
  200. package/backend/ws/db-client/connections.ts +17 -25
  201. package/backend/ws/db-client/context.ts +1 -1
  202. package/backend/ws/db-client/env.ts +7 -10
  203. package/backend/ws/db-client/index.ts +2 -2
  204. package/backend/ws/db-client/io.ts +5 -5
  205. package/backend/ws/db-client/query-history-retention.test.ts +8 -8
  206. package/backend/ws/db-client/query.ts +18 -17
  207. package/backend/ws/db-client/schema.ts +13 -13
  208. package/backend/ws/db-client/structure.ts +35 -35
  209. package/backend/ws/db-client/supabase.ts +4 -21
  210. package/backend/ws/deployments/context.ts +1 -1
  211. package/backend/ws/deployments/crud.ts +0 -5
  212. package/backend/ws/engine/access.ts +7 -20
  213. package/backend/ws/engine/claude/accounts.ts +4 -4
  214. package/backend/ws/engine/cline/accounts.ts +5 -5
  215. package/backend/ws/engine/codex/accounts.ts +3 -3
  216. package/backend/ws/engine/pi/accounts.ts +5 -5
  217. package/backend/ws/files/clipboard.ts +8 -27
  218. package/backend/ws/files/image-edit.ts +6 -6
  219. package/backend/ws/files/index.ts +1 -1
  220. package/backend/ws/files/path-access.test.ts +32 -131
  221. package/backend/ws/files/path-access.ts +8 -87
  222. package/backend/ws/files/read.ts +15 -19
  223. package/backend/ws/files/reveal.ts +3 -3
  224. package/backend/ws/files/search.ts +7 -7
  225. package/backend/ws/files/share.ts +9 -13
  226. package/backend/ws/files/state.ts +9 -12
  227. package/backend/ws/files/watch.ts +3 -3
  228. package/backend/ws/files/write.ts +30 -31
  229. package/backend/ws/git/branch.ts +80 -59
  230. package/backend/ws/git/commit.ts +63 -44
  231. package/backend/ws/git/conflict.ts +16 -18
  232. package/backend/ws/git/identity-context.ts +8 -17
  233. package/backend/ws/git/identity.ts +17 -27
  234. package/backend/ws/git/index.ts +3 -1
  235. package/backend/ws/git/op-state.ts +139 -0
  236. package/backend/ws/git/remote.ts +241 -141
  237. package/backend/ws/git/repo-context.ts +67 -0
  238. package/backend/ws/git/staging.ts +18 -28
  239. package/backend/ws/git/status.ts +5 -2
  240. package/backend/ws/index.ts +5 -1
  241. package/backend/ws/instructions/crud.ts +1 -1
  242. package/backend/ws/integrations/crud.ts +1 -3
  243. package/backend/ws/mcp/crud.ts +3 -5
  244. package/backend/ws/mcp/tools.ts +1 -1
  245. package/backend/ws/memory/crud.ts +14 -46
  246. package/backend/ws/memory/index.ts +2 -2
  247. package/backend/ws/messages/crud.ts +29 -8
  248. package/backend/ws/notes/index.ts +33 -39
  249. package/backend/ws/permissions/crud.ts +3 -4
  250. package/backend/ws/ports/index.ts +1 -2
  251. package/backend/ws/ports/kill.ts +5 -10
  252. package/backend/ws/ports/list.ts +4 -10
  253. package/backend/ws/preview/access.ts +1 -1
  254. package/backend/ws/preview/browser/interact.ts +52 -79
  255. package/backend/ws/preview/browser/native-ui.ts +24 -0
  256. package/backend/ws/preview/browser/stats.ts +98 -1
  257. package/backend/ws/preview/browser/tab-info.ts +15 -0
  258. package/backend/ws/preview/browser/tab.ts +19 -4
  259. package/backend/ws/preview/index.ts +27 -0
  260. package/backend/ws/profiles/crud.ts +6 -8
  261. package/backend/ws/project-artifacts/index.ts +30 -31
  262. package/backend/ws/projects/crud.ts +33 -35
  263. package/backend/ws/projects/index.ts +3 -8
  264. package/backend/ws/projects/info.ts +3 -3
  265. package/backend/ws/projects/overview.ts +19 -30
  266. package/backend/ws/projects/status.ts +17 -57
  267. package/backend/ws/sessions/crud.ts +34 -45
  268. package/backend/ws/sessions/index.ts +1 -1
  269. package/backend/ws/settings/crud.ts +1 -1
  270. package/backend/ws/skills/crud.ts +3 -4
  271. package/backend/ws/skills/index.ts +1 -1
  272. package/backend/ws/snapshot/changes.ts +7 -7
  273. package/backend/ws/snapshot/restore.ts +11 -295
  274. package/backend/ws/snapshot/timeline.ts +2 -4
  275. package/backend/ws/ssh/access.ts +6 -21
  276. package/backend/ws/ssh/connections.ts +21 -31
  277. package/backend/ws/ssh/forwards.ts +12 -12
  278. package/backend/ws/ssh/sftp.ts +34 -34
  279. package/backend/ws/ssh/tunnel.ts +1 -2
  280. package/backend/ws/stack/install.ts +7 -17
  281. package/backend/ws/subagents/crud.ts +1 -1
  282. package/backend/ws/tunnel/share.ts +0 -2
  283. package/backend/ws/user/crud.ts +1 -59
  284. package/backend/ws/user/index.ts +1 -1
  285. package/backend/ws/work/context.ts +1 -1
  286. package/backend/ws/work/crud.ts +0 -5
  287. package/backend/ws/workspace/state.ts +10 -13
  288. package/backend/ws/worktrees/branching.ts +7 -36
  289. package/backend/ws/worktrees/crud.ts +2 -2
  290. package/bin/clopen.ts +10 -11
  291. package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
  292. package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
  293. package/dist/assets/main-BUiUL3eZ.css +1 -0
  294. package/dist/assets/main-nBOb9YOA.js +1240 -0
  295. package/dist/index.html +2 -2
  296. package/package.json +2 -1
  297. package/shared/constants/attachments.ts +14 -0
  298. package/shared/constants/engine-tools.ts +1 -1
  299. package/shared/constants/preview.test.ts +259 -0
  300. package/shared/constants/preview.ts +1018 -57
  301. package/shared/constants/tool-icons.ts +5 -0
  302. package/shared/types/containers/container.ts +1 -1
  303. package/shared/types/database/schema.ts +9 -6
  304. package/shared/types/git-identity.ts +1 -1
  305. package/shared/types/git.ts +116 -0
  306. package/shared/types/integrations.ts +7 -0
  307. package/shared/types/stores/settings.ts +1 -1
  308. package/shared/types/unified/index.ts +1 -1
  309. package/shared/types/unified/message.ts +0 -7
  310. package/shared/types/unified/stream.ts +2 -4
  311. package/shared/types/unified/tool.ts +15 -1
  312. package/shared/utils/ask-user-question.test.ts +319 -0
  313. package/shared/utils/ask-user-question.ts +154 -0
  314. package/shared/utils/home-project.ts +25 -0
  315. package/shared/utils/logger.ts +2 -0
  316. package/shared/utils/ws-server.ts +32 -7
  317. package/backend/auth/session-invalidation.test.ts +0 -112
  318. package/backend/auth/session-invalidation.ts +0 -77
  319. package/backend/project/status-manager.test.ts +0 -32
  320. package/backend/ws/auth/invites.ts +0 -94
  321. package/backend/ws/auth/users.ts +0 -112
  322. package/backend/ws/projects/presence.ts +0 -46
  323. package/backend/ws/stack/access.ts +0 -31
  324. package/dist/assets/main-BiDNMWb3.css +0 -1
  325. package/dist/assets/main-BlhKWz2B.js +0 -1241
@@ -17,23 +17,17 @@ import { portMonitor } from '../../ports/monitor';
17
17
  import { sshConnectionQueries } from '../../database/queries';
18
18
  import { ws } from '../../utils/ws';
19
19
 
20
- /**
21
- * A member may only watch an SSH host they can already reach. The local
22
- * machine is watchable by anyone signed in — it is the machine they are
23
- * already using Clopen on.
24
- */
25
- function requireHostAccess(conn: Parameters<typeof ws.getUserId>[0], hostId: string): void {
20
+ /** The local machine, or a saved SSH host that still exists. */
21
+ function requireHost(hostId: string): void {
26
22
  if (hostId === LOCAL_PORT_HOST) return;
27
- const userId = ws.getUserId(conn);
28
- const isAdmin = ws.getRole(conn) === 'admin';
29
- sshConnectionQueries.ensureAccess(hostId, userId, isAdmin);
23
+ sshConnectionQueries.require(hostId);
30
24
  }
31
25
 
32
26
  const hostSchema = t.Object({ hostId: t.String({ minLength: 1 }) });
33
27
 
34
28
  export const portsListHandler = createRouter()
35
29
  .http('ports:watch', { data: hostSchema, response: t.Any() }, async ({ data, conn }) => {
36
- requireHostAccess(conn, data.hostId);
30
+ requireHost(data.hostId);
37
31
  const userId = ws.getUserId(conn);
38
32
 
39
33
  const result = await portMonitor.watch(data.hostId, userId);
@@ -48,7 +48,7 @@ export function requireBrowserPreviewAccessFor(
48
48
  // The caller passes a workspace scope key; membership is always decided on
49
49
  // the project it belongs to.
50
50
  const projectId = scopeProjectId(scopeKey);
51
- requireProjectAccess(conn, projectId); // throws if the caller isn't a member
51
+ requireProjectAccess(projectId); // throws if the caller isn't a member
52
52
  const userId = ws.getUserId(conn);
53
53
  const previewService = browserPreviewServiceManager.getService(scopeKey);
54
54
  return { userId, projectId, previewService };
@@ -12,6 +12,9 @@ import { debug } from '$shared/utils/logger';
12
12
  import { sleep } from '$shared/utils/async';
13
13
  import { requireBrowserPreviewAccess, requireBrowserTabAccess } from '../access';
14
14
  import { resolveFrameTarget } from '$backend/preview/browser/frame-targeting';
15
+ import { isPasteChord, pressChord, selectAll, type Modifier } from '$backend/preview/browser/keyboard-chords';
16
+ import { pasteText } from '$backend/preview/browser/paste';
17
+ import { isDeviceSize } from '$shared/constants/preview';
15
18
 
16
19
  // Throttle cursor detection evaluate calls per session (100ms = ~10/sec is plenty)
17
20
  const lastCursorEvalTime = new Map<string, number>();
@@ -27,6 +30,16 @@ function isNavigationError(error: Error): boolean {
27
30
  msg.includes('cannot find context');
28
31
  }
29
32
 
33
+ /** The held modifiers of a forwarded key event, in press order. */
34
+ function modifiersOf(action: { ctrlKey?: boolean; metaKey?: boolean; altKey?: boolean; shiftKey?: boolean }): Modifier[] {
35
+ const modifiers: Modifier[] = [];
36
+ if (action.ctrlKey) modifiers.push('Control');
37
+ if (action.metaKey) modifiers.push('Meta');
38
+ if (action.altKey) modifiers.push('Alt');
39
+ if (action.shiftKey) modifiers.push('Shift');
40
+ return modifiers;
41
+ }
42
+
30
43
  export const interactPreviewHandler = createRouter()
31
44
  // Action: Client requests browser interaction
32
45
  .on('preview:browser-interact', {
@@ -61,7 +74,8 @@ export const interactPreviewHandler = createRouter()
61
74
  width: t.Optional(t.Number()),
62
75
  height: t.Optional(t.Number()),
63
76
  deviceSize: t.Optional(t.String()),
64
- rotation: t.Optional(t.String())
77
+ rotation: t.Optional(t.String()),
78
+ deviceModel: t.Optional(t.String())
65
79
  }),
66
80
  /**
67
81
  * The tab the viewer is looking at.
@@ -207,10 +221,9 @@ export const interactPreviewHandler = createRouter()
207
221
  const shouldClear = action.clearFirst === true; // default false for user
208
222
 
209
223
  if (shouldClear) {
210
- // Select all text first (Ctrl+A), then type will overwrite
211
- await session.page.keyboard.down('Control');
212
- await session.page.keyboard.press('KeyA');
213
- await session.page.keyboard.up('Control');
224
+ // Select all, then typing overwrites it. Platform-aware: a
225
+ // bare Ctrl+A selects nothing on a macOS host.
226
+ await selectAll(session.page);
214
227
  await sleep(50); // Small delay for selection
215
228
  }
216
229
 
@@ -230,23 +243,16 @@ export const interactPreviewHandler = createRouter()
230
243
  case 'key':
231
244
  if (action.key) {
232
245
  try {
233
- // Handle modifier keys (Ctrl+C, Ctrl+V, etc.)
234
- const modifiers: string[] = [];
235
- if (action.ctrlKey) modifiers.push('Control');
236
- if (action.metaKey) modifiers.push('Meta');
237
- if (action.altKey) modifiers.push('Alt');
238
- if (action.shiftKey) modifiers.push('Shift');
246
+ const modifiers = modifiersOf(action);
239
247
 
240
248
  if (modifiers.length > 0) {
241
- // Press modifiers first
242
- for (const mod of modifiers) {
243
- await session.page.keyboard.down(mod as KeyInput);
244
- }
245
- // Press the main key
246
- await session.page.keyboard.press(action.key as KeyInput);
247
- // Release modifiers in reverse order
248
- for (const mod of modifiers.reverse()) {
249
- await session.page.keyboard.up(mod as KeyInput);
249
+ if (isPasteChord(modifiers, action.key)) {
250
+ // Never the headless clipboard: paste what the workspace holds.
251
+ await pasteText(session.page, previewService.getClipboardText());
252
+ } else {
253
+ // Editing shortcuts carry their command where the host
254
+ // would otherwise ignore them (⌘A on macOS).
255
+ await pressChord(session.page, modifiers, action.key);
250
256
  }
251
257
  } else {
252
258
  // No modifiers, just press the key
@@ -312,39 +318,13 @@ export const interactPreviewHandler = createRouter()
312
318
  break;
313
319
 
314
320
  case 'paste':
315
- // Insert into whatever holds focus, in whichever frame that
316
- // is. Synthesising Ctrl+V would paste the *headless* browser's
317
- // clipboard, which is not the one the user copied into.
321
+ // What the user pasted is what their device's clipboard holds,
322
+ // so the workspace clipboard learns it too. The paste itself
323
+ // raises a real `paste` event first — spreadsheets and rich
324
+ // editors only listen for that.
318
325
  if (typeof action.text === 'string') {
319
- for (const frame of session.page.frames()) {
320
- try {
321
- const inserted = await frame.evaluate((text: string) => {
322
- const active = document.activeElement as HTMLElement | null;
323
- if (!active) return false;
324
-
325
- const isField = active.tagName === 'INPUT' || active.tagName === 'TEXTAREA';
326
- if (!isField && !active.isContentEditable) return false;
327
-
328
- if (isField) {
329
- const field = active as HTMLInputElement | HTMLTextAreaElement;
330
- const start = field.selectionStart ?? field.value.length;
331
- const end = field.selectionEnd ?? field.value.length;
332
- field.value = field.value.slice(0, start) + text + field.value.slice(end);
333
- const caret = start + text.length;
334
- field.setSelectionRange(caret, caret);
335
- } else {
336
- document.execCommand('insertText', false, text);
337
- }
338
-
339
- active.dispatchEvent(new Event('input', { bubbles: true }));
340
- active.dispatchEvent(new Event('change', { bubbles: true }));
341
- return true;
342
- }, action.text);
343
- if (inserted) break;
344
- } catch {
345
- // Frame detached mid-paste; try the next one.
346
- }
347
- }
326
+ previewService.setClipboardText(action.text, 'device');
327
+ await pasteText(session.page, action.text);
348
328
  }
349
329
  break;
350
330
 
@@ -450,20 +430,10 @@ export const interactPreviewHandler = createRouter()
450
430
 
451
431
  case 'keynav':
452
432
  if (action.key) {
453
- const modifiers: string[] = [];
454
- if (action.ctrlKey) modifiers.push('Control');
455
- if (action.metaKey) modifiers.push('Meta');
456
- if (action.altKey) modifiers.push('Alt');
457
- if (action.shiftKey) modifiers.push('Shift');
433
+ const modifiers = modifiersOf(action);
458
434
 
459
435
  if (modifiers.length > 0) {
460
- for (const mod of modifiers) {
461
- await session.page.keyboard.down(mod as KeyInput);
462
- }
463
- await session.page.keyboard.press(action.key as KeyInput);
464
- for (const mod of modifiers.reverse()) {
465
- await session.page.keyboard.up(mod as KeyInput);
466
- }
436
+ await pressChord(session.page, modifiers, action.key);
467
437
  } else {
468
438
  await session.page.keyboard.press(action.key as KeyInput);
469
439
  }
@@ -555,7 +525,7 @@ export const interactPreviewHandler = createRouter()
555
525
  break;
556
526
 
557
527
  case 'viewport-update':
558
- // Handle viewport change (device/rotation) without reconnection
528
+ // Handle viewport change (device/rotation/exact size) without reconnection
559
529
  if (action.width && action.height && action.scale && action.scale > 0 && action.scale <= 1) {
560
530
  session.scale = action.scale;
561
531
 
@@ -567,22 +537,25 @@ export const interactPreviewHandler = createRouter()
567
537
  // the tab's metadata — which nothing told them had changed.
568
538
  // So a phone switched to Tablet from a laptop went on
569
539
  // drawing a laptop frame around a tablet-shaped picture.
570
- if (action.deviceSize || action.rotation) {
571
- await previewService.setViewport(
572
- session.id,
573
- (action.deviceSize as any) ?? session.deviceSize,
574
- (action.rotation as any) ?? session.rotation
575
- );
576
- }
540
+ //
541
+ // The width and height are the tab's exact size now, not a
542
+ // restatement of the device class — a preset or a drag can
543
+ // put any size on any class. The service also rebuilds the
544
+ // capture around it.
545
+ const deviceSize = isDeviceSize(action.deviceSize) ? action.deviceSize : session.deviceSize;
546
+ const rotation =
547
+ action.rotation === 'portrait' || action.rotation === 'landscape'
548
+ ? action.rotation
549
+ : session.rotation;
550
+
551
+ const updated = await previewService.setViewport(session.id, {
552
+ deviceSize,
553
+ rotation,
554
+ size: { width: action.width, height: action.height },
555
+ deviceModel: action.deviceModel
556
+ });
577
557
 
578
558
  debug.log('preview', `📱 Viewport updated for tab ${tabId}: ${action.width}x${action.height}`);
579
-
580
- // The hot-swap recomputes capture geometry from the new
581
- // viewport and the viewers' own display metrics, which
582
- // each of them reports separately.
583
-
584
- // Hot-swap viewport without reconnection
585
- const updated = await previewService.updateWebCodecsViewport(session.id, action.width, action.height);
586
559
  if (!updated) {
587
560
  debug.warn('preview', `⚠️ Viewport hot-swap failed`);
588
561
  }
@@ -37,6 +37,22 @@ export const nativeUIPreviewHandler = createRouter()
37
37
  return { success };
38
38
  })
39
39
 
40
+ /**
41
+ * The device's clipboard, as the viewer just read it.
42
+ *
43
+ * Sent on focus and on every copy or paste the user makes, so a paste in
44
+ * the preview — by the user or by an agent — pastes what the user last
45
+ * copied anywhere, not what the headless browser happens to hold.
46
+ */
47
+ .on('preview:browser-clipboard-set', {
48
+ data: t.Object({
49
+ text: t.String()
50
+ })
51
+ }, async ({ data, conn }) => {
52
+ const { previewService } = requireBrowserPreviewAccess(conn);
53
+ previewService.setClipboardText(data.text, 'device');
54
+ })
55
+
40
56
  // Action: Client responds to a dialog (alert, confirm, prompt)
41
57
  .on('preview:browser-dialog-input', {
42
58
  data: t.Object({
@@ -250,6 +266,14 @@ export const nativeUIPreviewHandler = createRouter()
250
266
  text: t.String()
251
267
  }))
252
268
 
269
+ // The workspace clipboard changed somewhere other than this device.
270
+ .emit('preview:browser-clipboard-sync', t.Object({
271
+ text: t.String(),
272
+ source: t.String(),
273
+ timestamp: t.Number(),
274
+ projectId: t.String()
275
+ }))
276
+
253
277
  .emit('preview:browser-open-url-new-tab', t.Object({
254
278
  url: t.String()
255
279
  }))
@@ -5,8 +5,11 @@
5
5
  */
6
6
 
7
7
  import { t } from 'elysia';
8
+ import { cpus, freemem, loadavg, totalmem } from 'os';
8
9
  import { createRouter } from '$shared/utils/ws-server';
9
- import { requireBrowserTabAccess } from '../access';
10
+ import { requireBrowserPreviewAccess, requireBrowserTabAccess } from '../access';
11
+ import { browserPool } from '$backend/preview/browser/browser-pool';
12
+ import { availableMemoryBytes, measureProcessTrees } from '$backend/preview/browser/process-usage';
10
13
 
11
14
  export const statsPreviewHandler = createRouter()
12
15
  .http('preview:browser-tab-stats', {
@@ -42,4 +45,98 @@ export const statsPreviewHandler = createRouter()
42
45
  stats: stats ?? null,
43
46
  timestamp: new Date().toISOString()
44
47
  };
48
+ })
49
+
50
+ /**
51
+ * Everything the diagnostics panel shows: what the host has left, what
52
+ * every preview Chrome costs, and what each of this workspace's tabs is
53
+ * doing. Polled only while the panel is open.
54
+ */
55
+ .http('preview:browser-diagnostics', {
56
+ data: t.Object({}),
57
+ response: t.Object({
58
+ host: t.Object({
59
+ platform: t.String(),
60
+ cpuCount: t.Number(),
61
+ loadAverage: t.Array(t.Number()),
62
+ totalMemBytes: t.Number(),
63
+ availableMemBytes: t.Number()
64
+ }),
65
+ browsers: t.Array(t.Object({
66
+ current: t.Boolean(),
67
+ tabs: t.Number(),
68
+ pid: t.Union([t.Number(), t.Null()]),
69
+ processes: t.Number(),
70
+ rssBytes: t.Number(),
71
+ cpuPercent: t.Union([t.Number(), t.Null()])
72
+ })),
73
+ tabs: t.Array(t.Object({
74
+ id: t.String(),
75
+ title: t.String(),
76
+ url: t.String(),
77
+ state: t.Union([t.Literal('active'), t.Literal('frozen')]),
78
+ watched: t.Boolean(),
79
+ isLoading: t.Boolean(),
80
+ openedBy: t.Union([t.Literal('agent'), t.Literal('user')]),
81
+ agentHeld: t.Boolean(),
82
+ dialog: t.Union([t.Object({ type: t.String(), message: t.String() }), t.Null()]),
83
+ createdAt: t.Number(),
84
+ lastAccessedAt: t.Number(),
85
+ jsHeapUsedBytes: t.Union([t.Number(), t.Null()]),
86
+ domNodes: t.Union([t.Number(), t.Null()]),
87
+ stream: t.Union([
88
+ t.Object({
89
+ videoBytesSent: t.Number(),
90
+ videoFramesEncoded: t.Number(),
91
+ connectionState: t.String()
92
+ }),
93
+ t.Null()
94
+ ])
95
+ })),
96
+ clipboard: t.Object({
97
+ length: t.Number(),
98
+ source: t.Union([t.String(), t.Null()]),
99
+ updatedAt: t.Number()
100
+ }),
101
+ timestamp: t.Number()
102
+ })
103
+ }, async ({ conn }) => {
104
+ const { previewService } = requireBrowserPreviewAccess(conn);
105
+ const scope = previewService.getProjectId();
106
+
107
+ const running = browserPool.getRunningBrowsers();
108
+ const usage = measureProcessTrees(running.map((entry) => entry.pid).filter((pid): pid is number => pid !== null));
109
+
110
+ // Other workspaces' Chromes are reported without naming them: the cost is
111
+ // shared by the machine, but which projects they belong to is not this
112
+ // viewer's business.
113
+ const browsers = running
114
+ .map((entry) => {
115
+ const tree = entry.pid !== null ? usage.get(entry.pid) : undefined;
116
+ return {
117
+ current: entry.profileKey === scope,
118
+ tabs: entry.sessions,
119
+ pid: entry.pid,
120
+ processes: tree?.processes ?? 0,
121
+ rssBytes: tree?.rssBytes ?? 0,
122
+ cpuPercent: tree?.cpuPercent ?? null
123
+ };
124
+ })
125
+ .sort((a, b) => Number(b.current) - Number(a.current) || b.rssBytes - a.rssBytes);
126
+
127
+ const { tabs, clipboard } = await previewService.getDiagnostics();
128
+
129
+ return {
130
+ host: {
131
+ platform: process.platform,
132
+ cpuCount: cpus().length,
133
+ loadAverage: loadavg(),
134
+ totalMemBytes: totalmem(),
135
+ availableMemBytes: availableMemoryBytes(freemem())
136
+ },
137
+ browsers,
138
+ tabs,
139
+ clipboard,
140
+ timestamp: Date.now()
141
+ };
45
142
  });
@@ -25,6 +25,15 @@ export const tabInfoPreviewHandler = createRouter()
25
25
  isStreaming: t.Boolean(),
26
26
  deviceSize: t.String(),
27
27
  rotation: t.String(),
28
+ width: t.Number(),
29
+ height: t.Number(),
30
+ deviceModel: t.Union([t.String(), t.Null()]),
31
+ emulation: t.Object({
32
+ touch: t.Optional(t.Boolean()),
33
+ mobile: t.Optional(t.Boolean()),
34
+ colorScheme: t.Optional(t.String()),
35
+ reducedMotion: t.Optional(t.String())
36
+ }),
28
37
  isActive: t.Boolean(),
29
38
  canGoBack: t.Boolean(),
30
39
  canGoForward: t.Boolean(),
@@ -61,6 +70,9 @@ export const tabInfoPreviewHandler = createRouter()
61
70
  isStreaming: t.Boolean(),
62
71
  deviceSize: t.String(),
63
72
  rotation: t.String(),
73
+ width: t.Number(),
74
+ height: t.Number(),
75
+ deviceModel: t.Union([t.String(), t.Null()]),
64
76
  isActive: t.Boolean(),
65
77
  canGoBack: t.Boolean(),
66
78
  canGoForward: t.Boolean(),
@@ -123,6 +135,9 @@ export const tabInfoPreviewHandler = createRouter()
123
135
  isStreaming: tab.isStreaming,
124
136
  deviceSize: tab.deviceSize,
125
137
  rotation: tab.rotation,
138
+ width: tab.width,
139
+ height: tab.height,
140
+ deviceModel: tab.deviceModel,
126
141
  isActive: tab.isActive,
127
142
  canGoBack: tab.canGoBack,
128
143
  canGoForward: tab.canGoForward,
@@ -22,12 +22,22 @@ export const tabPreviewHandler = createRouter()
22
22
  t.Literal('desktop'),
23
23
  t.Literal('laptop'),
24
24
  t.Literal('tablet'),
25
- t.Literal('mobile')
25
+ t.Literal('mobile'),
26
+ t.Literal('responsive')
26
27
  ])),
27
28
  rotation: t.Optional(t.Union([
28
29
  t.Literal('portrait'),
29
30
  t.Literal('landscape')
30
31
  ])),
32
+ /**
33
+ * Exact viewport size, when the tab was given one (a preset that is
34
+ * not its class's default, or a responsive size). The class default
35
+ * when omitted.
36
+ */
37
+ width: t.Optional(t.Number()),
38
+ height: t.Optional(t.Number()),
39
+ /** The device model; the class default when omitted. */
40
+ deviceModel: t.Optional(t.String()),
31
41
  /**
32
42
  * Client-minted name for this launch.
33
43
  *
@@ -60,6 +70,9 @@ export const tabPreviewHandler = createRouter()
60
70
  url,
61
71
  deviceSize = 'laptop',
62
72
  rotation = 'portrait',
73
+ width,
74
+ height,
75
+ deviceModel,
63
76
  launchId
64
77
  } = data;
65
78
 
@@ -68,9 +81,11 @@ export const tabPreviewHandler = createRouter()
68
81
  // Create browser tab
69
82
  const tabPromise = previewService.createTab(
70
83
  url, // Can be undefined for blank tab
71
- deviceSize as 'desktop' | 'laptop' | 'tablet' | 'mobile',
72
- rotation as 'portrait' | 'landscape',
73
- launchId
84
+ deviceSize,
85
+ rotation,
86
+ launchId,
87
+ width && height ? { width, height } : null,
88
+ { deviceModel }
74
89
  );
75
90
  const timeoutPromise = new Promise((_, reject) => {
76
91
  setTimeout(() => reject(new Error('Browser tab open timeout - took longer than 60 seconds')), OPEN_TIMEOUT);
@@ -79,6 +79,11 @@ export const previewRouter = createRouter()
79
79
  url: t.String(),
80
80
  title: t.String(),
81
81
  isActive: t.Boolean(),
82
+ deviceSize: t.Optional(t.String()),
83
+ rotation: t.Optional(t.String()),
84
+ width: t.Optional(t.Number()),
85
+ height: t.Optional(t.Number()),
86
+ deviceModel: t.Optional(t.Union([t.String(), t.Null()])),
82
87
  /**
83
88
  * The launch this tab came from, when a client started it. Absent for
84
89
  * tabs the backend opened on its own (an agent, a popup).
@@ -188,6 +193,18 @@ export const previewRouter = createRouter()
188
193
  timestamp: t.Number(),
189
194
  source: t.Literal('mcp')
190
195
  }))
196
+ // A whole pointer movement, animated by the viewer — see publishGlide.
197
+ .emit('preview:browser-mcp-cursor-glide', t.Object({
198
+ sessionId: t.String(),
199
+ from: t.Object({ x: t.Number(), y: t.Number() }),
200
+ control: t.Object({ x: t.Number(), y: t.Number() }),
201
+ to: t.Object({ x: t.Number(), y: t.Number() }),
202
+ durationMs: t.Number(),
203
+ pressed: t.Boolean(),
204
+ easing: t.Union([t.Literal('out'), t.Literal('linear')]),
205
+ timestamp: t.Number(),
206
+ source: t.Literal('mcp')
207
+ }))
191
208
  .emit('preview:browser-mcp-cursor-click', t.Object({
192
209
  sessionId: t.String(),
193
210
  x: t.Number(),
@@ -217,6 +234,16 @@ export const previewRouter = createRouter()
217
234
  rotation: t.String(),
218
235
  width: t.Number(),
219
236
  height: t.Number(),
237
+ deviceModel: t.Optional(t.Union([t.String(), t.Null()])),
238
+ timestamp: t.Number()
239
+ }))
240
+ // The colours a phone or tablet page asks to be framed in — its
241
+ // theme-color and background — for the system bands drawn around it.
242
+ .emit('preview:browser-page-colors', t.Object({
243
+ projectId: t.String(),
244
+ tabId: t.String(),
245
+ statusBar: t.String(),
246
+ background: t.String(),
220
247
  timestamp: t.Number()
221
248
  }))
222
249
  // Live tab metadata: the page's own title and favicon plus whether
@@ -1,16 +1,14 @@
1
1
  /**
2
2
  * Profiles Handlers (Settings → Profiles) + per-session picker + project default.
3
3
  *
4
- * - profiles:list / get / inventory / create / update / delete (admin)
5
- * - profiles:get-permissions / save-permissions (admin, Fase 3)
6
- * - profiles:set-project-default (admin)
7
- * - profiles:available / project-default (non-admin)
4
+ * - profiles:list / get / inventory / create / update / delete
5
+ * - profiles:get-permissions / save-permissions
6
+ * - profiles:set-project-default
7
+ * - profiles:available / project-default
8
8
  *
9
9
  * A Profile bundles references to existing artifacts (Skills, Commands,
10
10
  * Subagents, Integrations) by slug plus an optional per-engine allow/deny
11
- * overlay. Nothing is duplicated — see `backend/profiles`. Admin gating lives in
12
- * `backend/auth/permissions.ts`; the picker/default-read routes stay non-admin
13
- * (choosing a profile for a session is a run choice like the model).
11
+ * overlay. Nothing is duplicated — see `backend/profiles`.
14
12
  */
15
13
 
16
14
  import { t } from 'elysia';
@@ -129,7 +127,7 @@ export const profilesCrudHandler = createRouter()
129
127
  return { success: true };
130
128
  })
131
129
 
132
- // ── Non-admin: per-session picker + default read ───────────────────────────
130
+ // ── Per-session picker + default read ──────────────────────────────────────
133
131
  .http('profiles:available', {
134
132
  data: t.Object({}),
135
133
  response: t.Object({