@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
@@ -7,12 +7,11 @@
7
7
  * a client path) and reads the MAIN project checkout — worktrees follow it once
8
8
  * the change is committed and merged. Writes go only to `.agents/` and the
9
9
  * managed block of `AGENTS.md` (see `backend/artifacts/project/edit.ts`).
10
- * Admin-only: see ADMIN_ONLY_ROUTES.
11
10
  */
12
11
 
13
12
  import { t } from 'elysia';
14
13
  import { createRouter } from '$shared/utils/ws-server';
15
- import type { WSConnection } from '$shared/utils/ws-server';
14
+
16
15
  import { debug } from '$shared/utils/logger';
17
16
  import { ws } from '$backend/utils/ws';
18
17
  import { requireProjectAccess } from '../access';
@@ -86,15 +85,15 @@ const SAVED = t.Object({ slug: t.String(), path: t.String() });
86
85
 
87
86
  const AGENTS_MD = t.Object({ exists: t.Boolean(), content: t.String() });
88
87
 
89
- /** Project row + repository root for a request, with the caller's access checked. */
90
- function projectRoot(conn: WSConnection, projectId: string): { root: string; projectId: string } {
91
- const project = requireProjectAccess(conn, projectId);
88
+ /** Project row + repository root for a request, with the project checked. */
89
+ function projectRoot(projectId: string): { root: string; projectId: string } {
90
+ const project = requireProjectAccess(projectId);
92
91
  if (!project.path) throw new Error('Project has no path on disk');
93
92
  return { root: project.path, projectId };
94
93
  }
95
94
 
96
- async function scanFor(conn: WSConnection, projectId: string) {
97
- const { root } = projectRoot(conn, projectId);
95
+ async function scanFor(projectId: string) {
96
+ const { root } = projectRoot(projectId);
98
97
  const scan = await scanProject(root, hash => projectMcpTrustQueries.isTrusted(projectId, hash));
99
98
  const trust = projectMcpTrustQueries.get(projectId);
100
99
  return {
@@ -107,16 +106,16 @@ export const projectArtifactsRouter = createRouter()
107
106
  .http('project-artifacts:scan', {
108
107
  data: t.Object({ projectId: t.String() }),
109
108
  response: SCAN
110
- }, async ({ data, conn }) => {
109
+ }, async ({ data }) => {
111
110
  debug.log('path', `project-artifacts:scan ${data.projectId}`);
112
- return scanFor(conn, data.projectId);
111
+ return scanFor(data.projectId);
113
112
  })
114
113
 
115
114
  .http('project-artifacts:read', {
116
115
  data: t.Object({ projectId: t.String(), path: t.String() }),
117
116
  response: t.Object({ content: t.String() })
118
- }, async ({ data, conn }) => {
119
- const { root } = projectRoot(conn, data.projectId);
117
+ }, async ({ data }) => {
118
+ const { root } = projectRoot(data.projectId);
120
119
  return { content: await readProjectFile(root, data.path) };
121
120
  })
122
121
 
@@ -130,17 +129,17 @@ export const projectArtifactsRouter = createRouter()
130
129
  body: t.String()
131
130
  }),
132
131
  response: SAVED
133
- }, async ({ data, conn }) => {
132
+ }, async ({ data }) => {
134
133
  debug.log('path', `project-artifacts:save-skill ${data.projectId} ${data.name}`);
135
- const { root } = projectRoot(conn, data.projectId);
134
+ const { root } = projectRoot(data.projectId);
136
135
  return saveProjectSkill(root, data);
137
136
  })
138
137
  .http('project-artifacts:delete-skill', {
139
138
  data: t.Object({ projectId: t.String(), slug: t.String() }),
140
139
  response: t.Object({ success: t.Boolean() })
141
- }, async ({ data, conn }) => {
140
+ }, async ({ data }) => {
142
141
  debug.log('path', `project-artifacts:delete-skill ${data.projectId} ${data.slug}`);
143
- const { root } = projectRoot(conn, data.projectId);
142
+ const { root } = projectRoot(data.projectId);
144
143
  await deleteProjectSkill(root, data.slug);
145
144
  return { success: true };
146
145
  })
@@ -157,17 +156,17 @@ export const projectArtifactsRouter = createRouter()
157
156
  body: t.String()
158
157
  }),
159
158
  response: SAVED
160
- }, async ({ data, conn }) => {
159
+ }, async ({ data }) => {
161
160
  debug.log('path', `project-artifacts:save-subagent ${data.projectId} ${data.name}`);
162
- const { root } = projectRoot(conn, data.projectId);
161
+ const { root } = projectRoot(data.projectId);
163
162
  return saveProjectSubagent(root, data);
164
163
  })
165
164
  .http('project-artifacts:delete-subagent', {
166
165
  data: t.Object({ projectId: t.String(), slug: t.String() }),
167
166
  response: t.Object({ success: t.Boolean() })
168
- }, async ({ data, conn }) => {
167
+ }, async ({ data }) => {
169
168
  debug.log('path', `project-artifacts:delete-subagent ${data.projectId} ${data.slug}`);
170
- const { root } = projectRoot(conn, data.projectId);
169
+ const { root } = projectRoot(data.projectId);
171
170
  await deleteProjectSubagent(root, data.slug);
172
171
  return { success: true };
173
172
  })
@@ -175,9 +174,9 @@ export const projectArtifactsRouter = createRouter()
175
174
  .http('project-artifacts:copy-to-agents', {
176
175
  data: t.Object({ projectId: t.String(), kind: t.Union([t.Literal('skill'), t.Literal('subagent')]), path: t.String() }),
177
176
  response: SAVED
178
- }, async ({ data, conn }) => {
177
+ }, async ({ data }) => {
179
178
  debug.log('path', `project-artifacts:copy-to-agents ${data.projectId} ${data.path}`);
180
- const { root } = projectRoot(conn, data.projectId);
179
+ const { root } = projectRoot(data.projectId);
181
180
  return copyToAgents(root, data.kind, data.path);
182
181
  })
183
182
 
@@ -185,16 +184,16 @@ export const projectArtifactsRouter = createRouter()
185
184
  .http('project-artifacts:get-agents-md', {
186
185
  data: t.Object({ projectId: t.String() }),
187
186
  response: AGENTS_MD
188
- }, async ({ data, conn }) => {
189
- const { root } = projectRoot(conn, data.projectId);
187
+ }, async ({ data }) => {
188
+ const { root } = projectRoot(data.projectId);
190
189
  return readAgentsMd(root);
191
190
  })
192
191
  .http('project-artifacts:save-agents-md', {
193
192
  data: t.Object({ projectId: t.String(), content: t.String() }),
194
193
  response: AGENTS_MD
195
- }, async ({ data, conn }) => {
194
+ }, async ({ data }) => {
196
195
  debug.log('path', `project-artifacts:save-agents-md ${data.projectId}`);
197
- const { root } = projectRoot(conn, data.projectId);
196
+ const { root } = projectRoot(data.projectId);
198
197
  return saveAgentsMd(root, data.content);
199
198
  })
200
199
 
@@ -202,8 +201,8 @@ export const projectArtifactsRouter = createRouter()
202
201
  .http('project-artifacts:get-mcp', {
203
202
  data: t.Object({ projectId: t.String() }),
204
203
  response: t.Object({ path: t.String(), content: t.String() })
205
- }, async ({ data, conn }) => {
206
- const { root } = projectRoot(conn, data.projectId);
204
+ }, async ({ data }) => {
205
+ const { root } = projectRoot(data.projectId);
207
206
  return { path: PROJECT_WRITE_PATHS.mcp, content: readProjectMcpFile(root) ?? '' };
208
207
  })
209
208
  .http('project-artifacts:save-mcp', {
@@ -211,9 +210,9 @@ export const projectArtifactsRouter = createRouter()
211
210
  response: t.Object({ hash: t.String() })
212
211
  }, async ({ data, conn }) => {
213
212
  debug.log('path', `project-artifacts:save-mcp ${data.projectId}`);
214
- const { root, projectId } = projectRoot(conn, data.projectId);
213
+ const { root, projectId } = projectRoot(data.projectId);
215
214
  const hash = await saveProjectMcp(root, data.content);
216
- // An admin writing the file from Settings IS the approval: they authored
215
+ // Writing the file from Settings IS the approval: the owner authored
217
216
  // exactly this content. Edits from anywhere else still need approving.
218
217
  if (hash) projectMcpTrustQueries.approve(projectId, hash, ws.getUserId(conn));
219
218
  else projectMcpTrustQueries.revoke(projectId);
@@ -224,9 +223,9 @@ export const projectArtifactsRouter = createRouter()
224
223
  response: t.Object({ success: t.Boolean() })
225
224
  }, async ({ data, conn }) => {
226
225
  debug.log('path', `project-artifacts:approve-mcp ${data.projectId}`);
227
- const { root, projectId } = projectRoot(conn, data.projectId);
226
+ const { root, projectId } = projectRoot(data.projectId);
228
227
  const raw = readProjectMcpFile(root);
229
- // Approve only what the admin actually reviewed: the hash they saw must
228
+ // Approve only what was actually reviewed: the hash shown must
230
229
  // still be the file on disk.
231
230
  if (raw == null || hashContent(raw) !== data.hash) {
232
231
  throw new Error('.agents/mcp.json changed since it was shown — review it again before approving');
@@ -2,11 +2,11 @@
2
2
  * Projects CRUD Operations
3
3
  *
4
4
  * HTTP endpoints for project management:
5
- * - List all projects (per-user)
6
- * - Create new project (or return an existing project already joined by the user)
5
+ * - List projects in the workspace
6
+ * - Create new project (or re-list an existing one at the same path)
7
7
  * - Get project by ID
8
8
  * - Update project info
9
- * - Delete project (remove user association, cleanup if orphaned)
9
+ * - Delete project (remove from the list, or delete it with its chats)
10
10
  */
11
11
 
12
12
  import { t } from 'elysia';
@@ -23,40 +23,43 @@ import { debug } from '$shared/utils/logger';
23
23
  import { requireProjectAccess } from '../access';
24
24
  import { runProjectCleanups } from '../../projects/project-cleanup-registry';
25
25
  import '../../projects/project-cleanup';
26
+ import { ensureHomeProject } from '../../projects/home';
27
+ import { homeFirst, isHomeProject } from '$shared/utils/home-project';
26
28
 
27
29
  export const crudHandler = createRouter()
28
- // List all projects for the current user
30
+ // List projects in the workspace
29
31
  .http('projects:list', {
30
32
  data: t.Object({}),
31
33
  response: t.Array(t.Any())
32
- }, async ({ conn }) => {
34
+ }, async () => {
33
35
  await initializeDatabase();
34
- const userId = ws.getUserId(conn);
35
- const projects = projectQueries.getAllForUser(userId);
36
- return projects;
36
+ // Home is always there, listed first — the place a chat with no project
37
+ // selected lives, and where a fresh install lands.
38
+ ensureHomeProject();
39
+ return homeFirst(projectQueries.getListed());
37
40
  })
38
41
 
39
- // Create new project (or return an existing project already joined by the user)
42
+ // Create new project (or re-list an existing project at the same path)
40
43
  .http('projects:create', {
41
44
  data: t.Object({
42
45
  name: t.String({ minLength: 1 }),
43
46
  path: t.String({ minLength: 1 })
44
47
  }),
45
48
  response: t.Any()
46
- }, async ({ data, conn }) => {
49
+ }, async ({ data }) => {
47
50
  await initializeDatabase();
48
- const userId = ws.getUserId(conn);
49
51
  const { name, path } = data;
50
52
 
51
- // Check if project with this path already exists. If so, ensure the
52
- // current user is joined to it and return the existing record. This
53
- // covers re-adding a project that was previously removed (mode='remove')
54
- // which preserves the project row for session restoration.
53
+ // Check if project with this path already exists. If so, put it back in
54
+ // the list and return the existing record. This covers re-adding a
55
+ // project that was previously removed (mode='remove'), which preserves
56
+ // the project row for session restoration.
55
57
  const existing = projectQueries.getByPath(path);
58
+ // Home is already listed, as Home; a second entry for its folder would
59
+ // be the same workspace twice.
60
+ if (existing && isHomeProject(existing)) throw new Error('That folder is the Home workspace and cannot be added as a project');
56
61
  if (existing) {
57
- if (!projectQueries.userHasProject(userId, existing.id)) {
58
- projectQueries.addUserProject(userId, existing.id);
59
- }
62
+ projectQueries.list(existing.id);
60
63
  return existing;
61
64
  }
62
65
 
@@ -68,8 +71,7 @@ export const crudHandler = createRouter()
68
71
  last_opened_at: now
69
72
  });
70
73
 
71
- // Associate the project with the creating user
72
- projectQueries.addUserProject(userId, project.id);
74
+ projectQueries.list(project.id);
73
75
 
74
76
  return project;
75
77
  })
@@ -80,8 +82,8 @@ export const crudHandler = createRouter()
80
82
  id: t.String({ minLength: 1 })
81
83
  }),
82
84
  response: t.Any()
83
- }, async ({ data, conn }) => {
84
- requireProjectAccess(conn, data.id);
85
+ }, async ({ data }) => {
86
+ requireProjectAccess(data.id);
85
87
 
86
88
  // Update last_opened_at when getting project
87
89
  projectQueries.updateLastOpened(data.id);
@@ -100,9 +102,9 @@ export const crudHandler = createRouter()
100
102
  id: t.String(),
101
103
  deleted: t.Boolean()
102
104
  })
103
- }, async ({ data, conn }) => {
104
- const userId = ws.getUserId(conn);
105
- requireProjectAccess(conn, data.id);
105
+ }, async ({ data }) => {
106
+ const target = requireProjectAccess(data.id);
107
+ if (isHomeProject(target)) throw new Error('Home cannot be removed');
106
108
 
107
109
  const mode = data.mode ?? 'remove';
108
110
 
@@ -159,17 +161,13 @@ export const crudHandler = createRouter()
159
161
  }
160
162
  }
161
163
 
162
- // Remove user's association with the project
163
- projectQueries.removeUserProject(userId, data.id);
164
-
165
- // In full mode, delete the project record if no users remain
166
- // In remove mode, keep the project record so sessions can be restored
164
+ // In full mode, delete the project record.
165
+ // In remove mode, keep the project record so sessions can be restored.
167
166
  if (mode === 'full') {
168
- const remainingUsers = projectQueries.getUserCountForProject(data.id);
169
- if (remainingUsers === 0) {
170
- await runProjectCleanups(data.id);
171
- projectQueries.deleteProject(data.id);
172
- }
167
+ await runProjectCleanups(data.id);
168
+ projectQueries.deleteProject(data.id);
169
+ } else {
170
+ projectQueries.unlist(data.id);
173
171
  }
174
172
 
175
173
  broadcastPresence().catch((err) => {
@@ -5,15 +5,13 @@
5
5
  *
6
6
  * Structure:
7
7
  * - crud.ts: HTTP endpoints for CRUD operations (list, create, get, update, delete)
8
- * - status.ts: Real-time status updates and watching (get-status, watch, unwatch, events)
9
- * - presence.ts: User presence management (update-presence with broadcast)
8
+ * - status.ts: Live chat-stream status of every project (get-status, join, broadcast)
10
9
  * - overview.ts: Per-project resource usage for every project (projects:overview)
11
10
  */
12
11
 
13
12
  import { createRouter } from '$shared/utils/ws-server';
14
13
  import { crudHandler } from './crud';
15
14
  import { statusHandler } from './status';
16
- import { presenceHandler } from './presence';
17
15
  import { infoHandler } from './info';
18
16
  import { overviewHandler } from './overview';
19
17
 
@@ -21,14 +19,11 @@ export const projectsRouter = createRouter()
21
19
  // CRUD Operations (HTTP)
22
20
  .merge(crudHandler)
23
21
 
24
- // Status & Watching (HTTP + Events)
22
+ // Live stream status (HTTP + Events)
25
23
  .merge(statusHandler)
26
24
 
27
- // Presence Management (HTTP + Broadcast)
28
- .merge(presenceHandler)
29
-
30
25
  // Per-project resource info (storage + process-isolated CPU/RAM)
31
26
  .merge(infoHandler)
32
27
 
33
- // Per-project resource usage across every project the caller can see
28
+ // Per-project resource usage across every project
34
29
  .merge(overviewHandler);
@@ -4,7 +4,7 @@
4
4
  * Storage is a bounded walk of the project folder, nothing excluded. CPU and
5
5
  * RAM come from the shared host probe in `backend/host/metrics.ts`, narrowed to
6
6
  * the project's PTY shells and their descendants, so they sit on the same basis
7
- * Settings → Device reports for the whole machine. Engine processes Clopen runs
7
+ * Settings → Machine reports for the whole machine. Engine processes Clopen runs
8
8
  * outside a terminal are not shells and do not appear here.
9
9
  */
10
10
 
@@ -431,8 +431,8 @@ export const infoHandler = createRouter().http(
431
431
  })
432
432
  })
433
433
  },
434
- async ({ data, conn }) => {
435
- requireProjectAccess(conn, data.id);
434
+ async ({ data }) => {
435
+ requireProjectAccess(data.id);
436
436
  const project = projectQueries.getById(data.id);
437
437
  if (!project) {
438
438
  throw new Error('Project not found');
@@ -2,7 +2,7 @@
2
2
  * Projects Overview — per-project resource usage for every project at once.
3
3
  *
4
4
  * Settings -> Device already describes the machine; this is the same question
5
- * asked per project, so an admin can see where the machine's CPU, RAM and disk
5
+ * asked per project, so it is clear where the machine's CPU, RAM and disk
6
6
  * actually went without opening Project Info once per project.
7
7
  *
8
8
  * Separate from `system:device-info` (host hardware) and from `projects:info`
@@ -15,23 +15,18 @@
15
15
  * - idle = `projectShellPids(projectId).length === 0` (no active PTY shell)
16
16
  * - running = at least one active shell
17
17
  *
18
- * Access: scoped to the caller. Admins see every project, everyone else sees
19
- * only the projects they are assigned to — the same rule `projects:info`
20
- * enforces per project through `requireProjectAccess`.
21
- *
22
18
  * Cost control:
23
19
  * - no port scan and no per-process list here, only the summed CPU/RAM
24
20
  * - storage is read from cache and never awaited: a cold folder reports
25
21
  * `measuring` and fills in on a later poll, so this handler's latency is
26
22
  * the process-table probe, not a filesystem walk
27
- * - one snapshot per scope is cached for `OVERVIEW_CACHE_TTL_MS` and
23
+ * - one snapshot is cached for `OVERVIEW_CACHE_TTL_MS` and
28
24
  * single-flighted, and the process table underneath has its own 2s cache,
29
25
  * so a fast poll costs at most one probe every couple of seconds
30
26
  */
31
27
 
32
28
  import { t } from 'elysia';
33
29
  import { createRouter } from '$shared/utils/ws-server';
34
- import { ws } from '$backend/utils/ws';
35
30
  import { projectQueries } from '../../database/queries';
36
31
  import { projectShellPids } from '../../projects/shell-ownership';
37
32
  import { getHostFacts } from '../../host/metrics';
@@ -217,34 +212,32 @@ async function buildOverview(projects: Project[]): Promise<ProjectsOverview> {
217
212
  };
218
213
  }
219
214
 
220
- /** One snapshot per access scope. Kept below the frontend heartbeat so a poll
221
- * is never answered with the payload it already has, while burst opens and
222
- * rapid tab switches still collapse onto a single build. */
215
+ /** One snapshot, kept below the frontend heartbeat so a poll is never
216
+ * answered with the payload it already has, while burst opens and rapid tab
217
+ * switches still collapse onto a single build. */
223
218
  const OVERVIEW_CACHE_TTL_MS = 1_500;
224
- const cachedOverviews = new Map<string, { payload: ProjectsOverview; at: number }>();
225
- const inFlightOverviews = new Map<string, Promise<ProjectsOverview>>();
219
+ let cachedOverview: { payload: ProjectsOverview; at: number } | null = null;
220
+ let inFlightOverview: Promise<ProjectsOverview> | null = null;
226
221
 
227
- function getOverview(scope: string, projects: Project[]): Promise<ProjectsOverview> {
228
- const cached = cachedOverviews.get(scope);
229
- if (cached && Date.now() - cached.at < OVERVIEW_CACHE_TTL_MS) {
230
- return Promise.resolve(cached.payload);
222
+ function getOverview(projects: Project[]): Promise<ProjectsOverview> {
223
+ if (cachedOverview && Date.now() - cachedOverview.at < OVERVIEW_CACHE_TTL_MS) {
224
+ return Promise.resolve(cachedOverview.payload);
231
225
  }
232
226
 
233
- const inFlight = inFlightOverviews.get(scope);
234
- if (inFlight) return inFlight;
227
+ if (inFlightOverview) return inFlightOverview;
235
228
 
236
229
  const build = buildOverview(projects).then((payload) => {
237
- cachedOverviews.set(scope, { payload, at: Date.now() });
238
- inFlightOverviews.delete(scope);
230
+ cachedOverview = { payload, at: Date.now() };
231
+ inFlightOverview = null;
239
232
  return payload;
240
233
  });
241
234
  // A failed build must not pin the single-flight slot: storage failures are
242
235
  // already folded into `unavailable`, so a rejection here is unexpected
243
236
  // (e.g. the process table is unreadable) and the next poll should retry.
244
237
  build.catch(() => {
245
- inFlightOverviews.delete(scope);
238
+ inFlightOverview = null;
246
239
  });
247
- inFlightOverviews.set(scope, build);
240
+ inFlightOverview = build;
248
241
  return build;
249
242
  }
250
243
 
@@ -288,13 +281,9 @@ export const overviewHandler = createRouter().http(
288
281
  generatedAt: t.String()
289
282
  })
290
283
  },
291
- async ({ conn }) => {
292
- // A project's name and absolute path are not public: every other
293
- // project-scoped handler goes through `requireProjectAccess`, and a
294
- // list endpoint has to apply the same rule to the whole list.
295
- const userId = ws.getUserId(conn);
296
- const isAdmin = ws.getRole(conn) === 'admin';
297
- const projects = isAdmin ? projectQueries.getAll() : projectQueries.getAllForUser(userId);
298
- return getOverview(isAdmin ? 'admin' : `user:${userId}`, projects);
284
+ async () => {
285
+ // Every project on disk, including one removed from the list: it still
286
+ // takes up storage and can still run processes.
287
+ return getOverview(projectQueries.getAll());
299
288
  }
300
289
  );
@@ -1,25 +1,22 @@
1
1
  /**
2
- * Projects Status & Presence
2
+ * Projects Status
3
3
  *
4
- * Real-time presence tracking:
5
- * - projects:get-status (HTTP) - Get project status
6
- * - projects:join (Event) - User joins a project
7
- * - projects:leave (Event) - User leaves a project
8
- * - projects:presence-updated (Broadcast) - Full presence state
9
- *
10
- * Single broadcast event: `projects:presence-updated` contains full state.
4
+ * Live chat-stream status of every project, mirrored on every device so busy
5
+ * and waiting-for-input indicators stay in sync:
6
+ * - projects:get-status (HTTP) - Status of the current project
7
+ * - projects:join (Event) - A device opened a project; replies with every project's status
8
+ * - projects:presence-updated (Broadcast) - Full status of all projects
11
9
  */
12
10
 
13
11
  import { t } from 'elysia';
14
12
  import { createRouter } from '$shared/utils/ws-server';
15
- import { getProjectStatusData, updateUserPresence } from '../../project/status-manager';
13
+ import { getProjectStatusData } from '../../project/status-manager';
16
14
  import { streamManager } from '../../chat/stream-manager';
17
15
  import { ws } from '$backend/utils/ws';
18
16
  import { debug } from '$shared/utils/logger';
19
- import { requireProjectAccess } from '../access';
20
17
 
21
18
  /**
22
- * Broadcast full presence state of all projects to all connected clients
19
+ * Broadcast the full status of all projects to all connected clients
23
20
  */
24
21
  export async function broadcastPresence() {
25
22
  const statuses = await getProjectStatusData();
@@ -40,17 +37,15 @@ export const statusHandler = createRouter()
40
37
  return await getProjectStatusData(projectId);
41
38
  })
42
39
 
43
- // User joins a project
40
+ // A device opened a project
44
41
  .on('projects:join', {
45
- data: t.Object({
46
- userName: t.Optional(t.String())
47
- })
48
- }, async ({ data, conn }) => {
42
+ data: t.Object({})
43
+ }, async ({ conn }) => {
49
44
  const projectId = ws.getProjectId(conn);
50
45
  const userId = ws.getUserId(conn);
51
46
 
52
47
  try {
53
- // Send initial presence for ALL projects
48
+ // Send initial status for ALL projects
54
49
  const allStatuses = await getProjectStatusData();
55
50
  ws.emit.user(userId, 'projects:presence-updated', {
56
51
  type: 'presence-updated',
@@ -58,28 +53,13 @@ export const statusHandler = createRouter()
58
53
  data: allStatuses
59
54
  });
60
55
 
61
- if (data.userName) {
62
- updateUserPresence(projectId, userId, data.userName, 'join');
63
-
64
- try {
65
- streamManager.cleanupProjectStreams(projectId);
66
- } catch (cleanupError) {
67
- debug.error('project', 'Error cleaning up project streams:', cleanupError);
68
- }
69
-
70
- // Auto-cleanup on connection close (tab close, network drop)
71
- ws.addCleanup(conn, () => {
72
- updateUserPresence(projectId, userId, '', 'leave');
73
- debug.log('project', `Auto-cleaned presence for ${userId} from project ${projectId}`);
74
- broadcastPresence().catch((err) => {
75
- debug.warn('project', `Presence broadcast error after auto-cleanup for ${userId}:`, err);
76
- });
77
- });
78
-
79
- await broadcastPresence();
56
+ try {
57
+ streamManager.cleanupProjectStreams(projectId);
58
+ } catch (cleanupError) {
59
+ debug.error('project', 'Error cleaning up project streams:', cleanupError);
80
60
  }
81
61
 
82
- debug.log('project', `User ${userId} joined project ${projectId}`);
62
+ debug.log('project', `Device joined project ${projectId}`);
83
63
  } catch (error) {
84
64
  debug.error('project', 'Error joining project:', error);
85
65
  ws.emit.user(userId, 'projects:error', {
@@ -88,26 +68,6 @@ export const statusHandler = createRouter()
88
68
  }
89
69
  })
90
70
 
91
- // User leaves a project
92
- .on('projects:leave', {
93
- data: t.Object({
94
- projectId: t.Optional(t.String())
95
- })
96
- }, async ({ data, conn }) => {
97
- // Use explicit projectId from client (avoids race condition when switching projects)
98
- const projectId = data.projectId || ws.getProjectId(conn);
99
- const userId = ws.getUserId(conn);
100
- requireProjectAccess(conn, projectId);
101
-
102
- try {
103
- updateUserPresence(projectId, userId, '', 'leave');
104
- await broadcastPresence();
105
- debug.log('project', `User ${userId} left project ${projectId}`);
106
- } catch (error) {
107
- debug.error('project', 'Error leaving project:', error);
108
- }
109
- })
110
-
111
71
  // Event declarations
112
72
  .emit('projects:presence-updated', t.Object({
113
73
  type: t.Literal('presence-updated'),