clay-server 5.2.0-beta.3 → 5.2.0-beta.5

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 (339) hide show
  1. package/lib/account-auth-socket.js +1 -0
  2. package/lib/builtin-mates.js +19 -16
  3. package/lib/bundled-skills/clay-agent-browser/SKILL.md +6 -2
  4. package/lib/canonical-clay-record-authority.js +15 -0
  5. package/lib/canonical-clay-scheduling-authority.js +19 -0
  6. package/lib/claude-hook-installer.js +28 -0
  7. package/lib/clay-mate-chat-receipts.js +26 -0
  8. package/lib/clay-mate-chat.js +87 -0
  9. package/lib/clay-mate-knowledge-input.js +26 -0
  10. package/lib/clay-mate-knowledge.js +95 -0
  11. package/lib/clay-mate-lifecycle.js +95 -0
  12. package/lib/clay-product-control-input.js +33 -0
  13. package/lib/clay-product-control-tools.js +51 -0
  14. package/lib/clay-product-control.js +237 -0
  15. package/lib/clay-project-lifecycle.js +154 -0
  16. package/lib/clay-project-record-input.js +44 -0
  17. package/lib/clay-project-records.js +83 -0
  18. package/lib/clay-scheduling-input.js +21 -0
  19. package/lib/clay-scheduling-receipts.js +26 -0
  20. package/lib/clay-scheduling.js +119 -0
  21. package/lib/clay-screen-controls.js +96 -0
  22. package/lib/clay-workspace-controls.js +83 -0
  23. package/lib/clay-workspace-input.js +17 -0
  24. package/lib/clay-workspace-receipts.js +26 -0
  25. package/lib/daemon-project-access.js +11 -0
  26. package/lib/daemon-project-lifecycle-callbacks.js +15 -0
  27. package/lib/daemon-project-lifecycle.js +262 -0
  28. package/lib/daemon-projects.js +1 -1
  29. package/lib/daemon.js +73 -221
  30. package/lib/issues-service.js +29 -15
  31. package/lib/knowledge-db-import.js +5 -4
  32. package/lib/knowledge-db-service.js +9 -6
  33. package/lib/knowledge-document-index.js +2 -1
  34. package/lib/knowledge-file-store.js +7 -1
  35. package/lib/knowledge-product-operations.js +46 -0
  36. package/lib/mate-avatar-catalog.js +12 -0
  37. package/lib/mate-avatar-migration.js +41 -0
  38. package/lib/mate-creation-mcp-server.js +2 -0
  39. package/lib/mate-knowledge-canonical-access.js +10 -0
  40. package/lib/mate-knowledge-service.js +7 -4
  41. package/lib/mate-lifecycle-service.js +94 -0
  42. package/lib/mate-message-delivery.js +43 -0
  43. package/lib/mate-ready-creation.js +9 -1
  44. package/lib/mate-schedule-input.js +29 -0
  45. package/lib/mate-schedule-lifecycle.js +151 -0
  46. package/lib/mate-scheduling.js +103 -0
  47. package/lib/mates.js +18 -6
  48. package/lib/mcp-agent-tools.js +117 -0
  49. package/lib/mcp-connection-store.js +119 -15
  50. package/lib/mcp-import-credentials.js +31 -0
  51. package/lib/mcp-local-transport.js +13 -0
  52. package/lib/mcp-oauth.js +8 -6
  53. package/lib/mcp-query-bridge.js +30 -0
  54. package/lib/mcp-remote-connections.js +74 -20
  55. package/lib/mcp-source-adapters.js +91 -0
  56. package/lib/mcp-source-context.js +42 -0
  57. package/lib/mcp-source-discovery.js +169 -0
  58. package/lib/mcp-source-plugins.js +68 -0
  59. package/lib/mcp-source-restrictions.js +47 -0
  60. package/lib/mcp-tool-policy.js +34 -0
  61. package/lib/notes-checklist.js +50 -0
  62. package/lib/notes.js +49 -3
  63. package/lib/os-users.js +20 -5
  64. package/lib/project-admin-overview.js +51 -0
  65. package/lib/project-ask-user.js +8 -4
  66. package/lib/project-debate.js +1 -0
  67. package/lib/project-delegated-follow-up.js +2 -1
  68. package/lib/project-directory-claim.js +65 -0
  69. package/lib/project-file-operations.js +61 -0
  70. package/lib/project-filesystem.js +13 -87
  71. package/lib/project-full-access.js +23 -2
  72. package/lib/project-knowledge.js +32 -18
  73. package/lib/project-lifecycle-operations.js +98 -0
  74. package/lib/project-lifecycle-process-witness.js +32 -0
  75. package/lib/project-lifecycle-runtime.js +50 -0
  76. package/lib/project-linux-access.js +22 -0
  77. package/lib/project-logs-canonical-clay.js +27 -0
  78. package/lib/project-logs-clay-query.js +16 -0
  79. package/lib/project-logs-schema.js +4 -2
  80. package/lib/project-logs-service.js +8 -7
  81. package/lib/project-logs.js +1 -0
  82. package/lib/project-loop.js +1 -0
  83. package/lib/project-mate-chat-control.js +55 -0
  84. package/lib/project-mate-creation-proposal.js +18 -3
  85. package/lib/project-mate-interaction.js +8 -0
  86. package/lib/project-mcp.js +54 -16
  87. package/lib/project-models.js +14 -31
  88. package/lib/project-notifications.js +74 -16
  89. package/lib/project-ownership.js +77 -0
  90. package/lib/project-pair-result-delivery.js +14 -3
  91. package/lib/project-pending-message-queue.js +1 -0
  92. package/lib/project-product-control.js +87 -0
  93. package/lib/project-product-session-queue.js +46 -0
  94. package/lib/project-push-access.js +28 -0
  95. package/lib/project-scheduled-message-queue.js +30 -0
  96. package/lib/project-scheduled-messages.js +63 -64
  97. package/lib/project-scheduled-task-control.js +83 -0
  98. package/lib/project-scheduled-tasks.js +13 -2
  99. package/lib/project-scheduling-access.js +10 -0
  100. package/lib/project-session-actions.js +65 -0
  101. package/lib/project-session-delete.js +8 -1
  102. package/lib/project-session-document.js +8 -3
  103. package/lib/project-session-github.js +63 -19
  104. package/lib/project-session-history-actions.js +165 -0
  105. package/lib/project-session-linear.js +14 -6
  106. package/lib/project-session-notes.js +7 -3
  107. package/lib/project-session-runtime-actions.js +63 -0
  108. package/lib/project-session-vendor.js +54 -0
  109. package/lib/project-sessions.js +68 -241
  110. package/lib/project-shared-browser.js +56 -12
  111. package/lib/project-user-message.js +30 -1
  112. package/lib/project-workspace-operations.js +126 -0
  113. package/lib/project-workspace-query.js +9 -2
  114. package/lib/project.js +144 -37
  115. package/lib/public/app.js +5 -0
  116. package/lib/public/appearance-bootstrap.js +14 -0
  117. package/lib/public/css/clay-tool-activity.css +51 -0
  118. package/lib/public/css/clay-workspace.css +29 -0
  119. package/lib/public/css/home-debate-planning.css +2 -0
  120. package/lib/public/css/home-mate-creation.css +5 -0
  121. package/lib/public/css/mate-avatar-gallery.css +12 -0
  122. package/lib/public/css/mate-conversation.css +10 -5
  123. package/lib/public/css/overlays.css +4 -2
  124. package/lib/public/css/project-admin-overview.css +13 -0
  125. package/lib/public/css/session-folders.css +11 -0
  126. package/lib/public/css/session-github.css +46 -1
  127. package/lib/public/css/shared-browser.css +35 -1
  128. package/lib/public/css/sticky-notes.css +61 -1
  129. package/lib/public/index.html +11 -5
  130. package/lib/public/mate-avatars/B01.png +0 -0
  131. package/lib/public/mate-avatars/B02.png +0 -0
  132. package/lib/public/mate-avatars/B03.png +0 -0
  133. package/lib/public/mate-avatars/B04.png +0 -0
  134. package/lib/public/mate-avatars/B05.png +0 -0
  135. package/lib/public/mate-avatars/B06.png +0 -0
  136. package/lib/public/mate-avatars/B07.png +0 -0
  137. package/lib/public/mate-avatars/B08.png +0 -0
  138. package/lib/public/mate-avatars/B09.png +0 -0
  139. package/lib/public/mate-avatars/B10.png +0 -0
  140. package/lib/public/mate-avatars/B11.png +0 -0
  141. package/lib/public/mate-avatars/B12.png +0 -0
  142. package/lib/public/mate-avatars/B13.png +0 -0
  143. package/lib/public/mate-avatars/B14.png +0 -0
  144. package/lib/public/mate-avatars/B15.png +0 -0
  145. package/lib/public/mate-avatars/B16.png +0 -0
  146. package/lib/public/mate-avatars/B17.png +0 -0
  147. package/lib/public/mate-avatars/B18.png +0 -0
  148. package/lib/public/mate-avatars/B19.png +0 -0
  149. package/lib/public/mate-avatars/B20.png +0 -0
  150. package/lib/public/mate-avatars/B21.png +0 -0
  151. package/lib/public/mate-avatars/B22.png +0 -0
  152. package/lib/public/mate-avatars/B23.png +0 -0
  153. package/lib/public/mate-avatars/B24.png +0 -0
  154. package/lib/public/mate-avatars/B25.png +0 -0
  155. package/lib/public/mate-avatars/B26.png +0 -0
  156. package/lib/public/mate-avatars/B27.png +0 -0
  157. package/lib/public/mate-avatars/B28.png +0 -0
  158. package/lib/public/mate-avatars/B29.png +0 -0
  159. package/lib/public/mate-avatars/B30.png +0 -0
  160. package/lib/public/mate-avatars/B31.png +0 -0
  161. package/lib/public/mate-avatars/B32.png +0 -0
  162. package/lib/public/mate-avatars/B33.png +0 -0
  163. package/lib/public/mate-avatars/B34.png +0 -0
  164. package/lib/public/mate-avatars/B35.png +0 -0
  165. package/lib/public/mate-avatars/B36.png +0 -0
  166. package/lib/public/mate-avatars/B37.png +0 -0
  167. package/lib/public/mate-avatars/B38.png +0 -0
  168. package/lib/public/mate-avatars/B39.png +0 -0
  169. package/lib/public/mate-avatars/B40.png +0 -0
  170. package/lib/public/mate-avatars/B41.png +0 -0
  171. package/lib/public/mate-avatars/B42.png +0 -0
  172. package/lib/public/mate-avatars/B43.png +0 -0
  173. package/lib/public/mate-avatars/B44.png +0 -0
  174. package/lib/public/mate-avatars/B45.png +0 -0
  175. package/lib/public/mate-avatars/B46.png +0 -0
  176. package/lib/public/mate-avatars/B47.png +0 -0
  177. package/lib/public/mate-avatars/B48.png +0 -0
  178. package/lib/public/mate-avatars/C01.png +0 -0
  179. package/lib/public/mate-avatars/C02.png +0 -0
  180. package/lib/public/mate-avatars/C03.png +0 -0
  181. package/lib/public/mate-avatars/C04.png +0 -0
  182. package/lib/public/mate-avatars/C05.png +0 -0
  183. package/lib/public/mate-avatars/C06.png +0 -0
  184. package/lib/public/mate-avatars/C07.png +0 -0
  185. package/lib/public/mate-avatars/C08.png +0 -0
  186. package/lib/public/mate-avatars/C09.png +0 -0
  187. package/lib/public/mate-avatars/C10.png +0 -0
  188. package/lib/public/mate-avatars/C11.png +0 -0
  189. package/lib/public/mate-avatars/C12.png +0 -0
  190. package/lib/public/mate-avatars/C13.png +0 -0
  191. package/lib/public/mate-avatars/C14.png +0 -0
  192. package/lib/public/mate-avatars/C15.png +0 -0
  193. package/lib/public/mate-avatars/C16.png +0 -0
  194. package/lib/public/mate-avatars/C17.png +0 -0
  195. package/lib/public/mate-avatars/C18.png +0 -0
  196. package/lib/public/mate-avatars/C19.png +0 -0
  197. package/lib/public/mate-avatars/C20.png +0 -0
  198. package/lib/public/mate-avatars/C21.png +0 -0
  199. package/lib/public/mate-avatars/C22.png +0 -0
  200. package/lib/public/mate-avatars/C23.png +0 -0
  201. package/lib/public/mate-avatars/C24.png +0 -0
  202. package/lib/public/mate-avatars/C25.png +0 -0
  203. package/lib/public/mate-avatars/C26.png +0 -0
  204. package/lib/public/mate-avatars/C27.png +0 -0
  205. package/lib/public/mate-avatars/C28.png +0 -0
  206. package/lib/public/mate-avatars/C29.png +0 -0
  207. package/lib/public/mate-avatars/C30.png +0 -0
  208. package/lib/public/mate-avatars/C31.png +0 -0
  209. package/lib/public/mate-avatars/C32.png +0 -0
  210. package/lib/public/mate-avatars/C33.png +0 -0
  211. package/lib/public/mate-avatars/C34.png +0 -0
  212. package/lib/public/mate-avatars/C35.png +0 -0
  213. package/lib/public/mate-avatars/C36.png +0 -0
  214. package/lib/public/mate-avatars/C37.png +0 -0
  215. package/lib/public/mate-avatars/C38.png +0 -0
  216. package/lib/public/mate-avatars/C39.png +0 -0
  217. package/lib/public/mate-avatars/C40.png +0 -0
  218. package/lib/public/mate-avatars/C41.png +0 -0
  219. package/lib/public/mate-avatars/C42.png +0 -0
  220. package/lib/public/mate-avatars/C43.png +0 -0
  221. package/lib/public/mate-avatars/C44.png +0 -0
  222. package/lib/public/mate-avatars/C45.png +0 -0
  223. package/lib/public/mate-avatars/C46.png +0 -0
  224. package/lib/public/mate-avatars/C47.png +0 -0
  225. package/lib/public/mate-avatars/C48.png +0 -0
  226. package/lib/public/mate-avatars/catalog.json +482 -0
  227. package/lib/public/mate-avatars/lead-clay.png +0 -0
  228. package/lib/public/modules/admin-settings-projects.js +6 -2
  229. package/lib/public/modules/app-connection.js +8 -1
  230. package/lib/public/modules/app-message-router.js +4 -0
  231. package/lib/public/modules/app-messages.js +31 -5
  232. package/lib/public/modules/app-projects.js +5 -0
  233. package/lib/public/modules/app-rendering.js +1 -1
  234. package/lib/public/modules/avatar.js +15 -41
  235. package/lib/public/modules/chat-render-runtime.js +10 -1
  236. package/lib/public/modules/clay-browser-links.js +47 -0
  237. package/lib/public/modules/clay-log-links.js +1 -1
  238. package/lib/public/modules/clay-owner-navigation.js +27 -0
  239. package/lib/public/modules/clay-tool-activity.js +140 -0
  240. package/lib/public/modules/clay-tool-presentation.js +338 -0
  241. package/lib/public/modules/command-palette.js +2 -2
  242. package/lib/public/modules/debate.js +1 -0
  243. package/lib/public/modules/default-ai.js +11 -3
  244. package/lib/public/modules/history-replay-batch.js +5 -1
  245. package/lib/public/modules/home-debate-live.js +2 -0
  246. package/lib/public/modules/home-debate-planning.js +7 -7
  247. package/lib/public/modules/home-mate-avatar-editor.js +127 -208
  248. package/lib/public/modules/home-mate-chat.js +8 -6
  249. package/lib/public/modules/home-mate-creation.js +73 -1
  250. package/lib/public/modules/home-mate-settings.js +19 -12
  251. package/lib/public/modules/markdown.js +4 -0
  252. package/lib/public/modules/mate-avatar-catalog.js +97 -0
  253. package/lib/public/modules/mate-management.js +40 -7
  254. package/lib/public/modules/mcp-connection-view.js +31 -13
  255. package/lib/public/modules/mcp-discovery-view.js +31 -0
  256. package/lib/public/modules/mcp-ui.js +23 -4
  257. package/lib/public/modules/mention.js +3 -0
  258. package/lib/public/modules/pane-browser-bridge.js +20 -0
  259. package/lib/public/modules/personal-settings-dialog.js +7 -1
  260. package/lib/public/modules/profile.js +1 -238
  261. package/lib/public/modules/project-access-recovery.js +17 -0
  262. package/lib/public/modules/project-admin-overview.js +21 -0
  263. package/lib/public/modules/project-mate-navigation.js +99 -14
  264. package/lib/public/modules/search-clay-chat.js +16 -2
  265. package/lib/public/modules/session-folder-layout.js +1 -1
  266. package/lib/public/modules/session-folder-view-menu.js +9 -0
  267. package/lib/public/modules/session-github.js +85 -14
  268. package/lib/public/modules/session-work-primary.js +51 -0
  269. package/lib/public/modules/shared-browser-settings.js +112 -0
  270. package/lib/public/modules/shared-browser-tabs.js +13 -3
  271. package/lib/public/modules/shared-browser.js +27 -6
  272. package/lib/public/modules/sidebar-session-folders-ui.js +1 -1
  273. package/lib/public/modules/split-view.js +2 -0
  274. package/lib/public/modules/sticky-note-markdown.js +72 -6
  275. package/lib/public/modules/sticky-notes-actions.js +30 -0
  276. package/lib/public/modules/sticky-notes-browser.js +9 -2
  277. package/lib/public/modules/sticky-notes-card.js +23 -7
  278. package/lib/public/modules/sticky-notes-checklist.js +71 -0
  279. package/lib/public/modules/sticky-notes-editor.js +108 -44
  280. package/lib/public/modules/sticky-notes-shared.js +50 -2
  281. package/lib/public/modules/sticky-notes-state.js +66 -0
  282. package/lib/public/modules/sticky-notes.js +34 -51
  283. package/lib/public/modules/theme.js +8 -1
  284. package/lib/public/modules/thinking-lifecycle.js +33 -3
  285. package/lib/public/modules/thinking-view.js +23 -1
  286. package/lib/public/modules/tools.js +36 -7
  287. package/lib/public/modules/user-settings-appearance.js +10 -3
  288. package/lib/public/modules/user-settings-editors.js +1 -1
  289. package/lib/public/modules/user-settings-layout.js +11 -2
  290. package/lib/public/modules/user-settings-preferences.js +6 -2
  291. package/lib/public/modules/user-settings-profile.js +12 -2
  292. package/lib/public/modules/user-settings.js +3 -2
  293. package/lib/public/style.css +3 -0
  294. package/lib/public/sw.js +3 -1
  295. package/lib/scheduled-task-records.js +3 -1
  296. package/lib/scheduler.js +2 -0
  297. package/lib/sdk-bridge.js +228 -23
  298. package/lib/sdk-message-processor.js +2 -0
  299. package/lib/sdk-response-recovery.js +155 -0
  300. package/lib/server-admin.js +63 -16
  301. package/lib/server-appearance-settings.js +13 -1
  302. package/lib/server-dm.js +2 -1
  303. package/lib/server-global-ws.js +10 -20
  304. package/lib/server-home-chat-events.js +18 -4
  305. package/lib/server-home-chat.js +12 -16
  306. package/lib/server-home-mate-creation.js +1 -0
  307. package/lib/server-home-mcp-consent.js +14 -0
  308. package/lib/server-mates.js +25 -62
  309. package/lib/server-owner-ui.js +77 -0
  310. package/lib/server-path-access.js +38 -0
  311. package/lib/server-project-removal.js +22 -0
  312. package/lib/server-settings.js +4 -1
  313. package/lib/server.js +144 -41
  314. package/lib/session-config-transition.js +45 -0
  315. package/lib/session-folders.js +7 -2
  316. package/lib/session-github.js +9 -2
  317. package/lib/session-visibility.js +5 -2
  318. package/lib/session-work-primary.js +50 -0
  319. package/lib/sessions.js +13 -0
  320. package/lib/shared-browser-cookie-sync.js +32 -0
  321. package/lib/shared-browser-cookies.js +79 -0
  322. package/lib/shared-browser-runtime.js +25 -9
  323. package/lib/shared-browser-storage-sync.js +43 -0
  324. package/lib/shared-browser-storage.js +101 -0
  325. package/lib/shared-browser-tools.js +2 -1
  326. package/lib/shared-browser-worker.js +46 -10
  327. package/lib/terminal-manager.js +52 -0
  328. package/lib/users-permissions.js +2 -8
  329. package/lib/users.js +4 -0
  330. package/lib/workspace-query-access.js +4 -1
  331. package/lib/ws-schema.js +8 -2
  332. package/lib/yoke/acp-agent-profiles.js +2 -2
  333. package/lib/yoke/adapters/claude.js +47 -8
  334. package/lib/yoke/adapters/codex.js +52 -111
  335. package/lib/yoke/claude-worker-startup.js +28 -0
  336. package/lib/yoke/codex-idle-recovery.js +81 -1
  337. package/lib/yoke/codex-recovery-admission.js +164 -0
  338. package/lib/yoke/session-tool-transport.js +3 -0
  339. package/package.json +5 -1
@@ -154,6 +154,20 @@ function attachNotifications(ctx) {
154
154
  return notifications.length;
155
155
  }
156
156
 
157
+ function visible(ws) {
158
+ return notifications.filter(function (notification) { return !ctx.canView || ctx.canView(ws, notification); });
159
+ }
160
+
161
+ function publish(payload) {
162
+ if (!ctx.forEachClient) return broadcastAll(payload);
163
+ ctx.forEachClient(function (ws) {
164
+ if (ws.readyState !== 1) return;
165
+ if (payload.notification && !ctx.canView(ws, payload.notification)) return;
166
+ var list = visible(ws);
167
+ ws.send(JSON.stringify(Object.assign({}, payload, { unreadCount: list.length })));
168
+ });
169
+ }
170
+
157
171
  // --- Core API ---
158
172
 
159
173
  function notify(event, data) {
@@ -186,9 +200,10 @@ function attachNotifications(ctx) {
186
200
  notification: notif,
187
201
  unreadCount: getUnreadCount(),
188
202
  };
189
- // If targeted at a specific user, deliver only to that user's connections.
190
- // Otherwise broadcast to everyone (existing behavior).
191
- if (notif.targetUserId && typeof sendToUser === "function") {
203
+ // Project/session previews are projected for each authenticated viewer.
204
+ if (ctx.forEachClient) {
205
+ publish(payload);
206
+ } else if (notif.targetUserId && typeof sendToUser === "function") {
192
207
  sendToUser(notif.targetUserId, payload);
193
208
  } else {
194
209
  broadcastAll(payload);
@@ -196,12 +211,14 @@ function attachNotifications(ctx) {
196
211
  return notif;
197
212
  }
198
213
 
199
- function dismiss(ids) {
214
+ function dismiss(ids, ws) {
215
+ var permitted = visible(ws).map(function (notification) { return notification.id; });
216
+ ids = ids.filter(function (id) { return permitted.indexOf(id) !== -1; });
200
217
  var before = notifications.length;
201
218
  notifications = notifications.filter(function(n) { return ids.indexOf(n.id) === -1; });
202
219
  if (notifications.length !== before) {
203
220
  saveNotifications();
204
- broadcastAll({
221
+ publish({
205
222
  type: "notification_dismissed",
206
223
  ids: ids,
207
224
  unreadCount: getUnreadCount(),
@@ -209,12 +226,41 @@ function attachNotifications(ctx) {
209
226
  }
210
227
  }
211
228
 
212
- function dismissAll() {
213
- if (notifications.length > 0) {
214
- notifications = [];
215
- saveNotifications();
216
- broadcastAll({ type: "notification_dismissed_all", unreadCount: 0 });
217
- }
229
+ function canReadOwned(principal, item) {
230
+ var owner = principal.userId || null;
231
+ return (owner ? (item.targetUserId === owner || item.ownerId === owner) && (!item.targetUserId || item.targetUserId === owner) : !item.ownerId && !item.targetUserId) &&
232
+ (!ctx.canViewPrincipal || ctx.canViewPrincipal(principal, item));
233
+ }
234
+ function authorizeOwned(principal, items) {
235
+ if (items.some(function (item) { return !canReadOwned(principal, item); })) throw new Error('Owned notification access changed.');
236
+ }
237
+ function listOwned(principal) {
238
+ return notifications.filter(function (item) { return canReadOwned(principal, item); }).slice(0, 100).map(function (item) { return JSON.parse(JSON.stringify(item)); });
239
+ }
240
+ function inspectOwned(principal, ids) {
241
+ var owned = listOwned(principal);
242
+ return ids.map(function (id) {
243
+ var item = owned.find(function (entry) { return entry.id === id; });
244
+ if (!item) throw new Error('The exact owned notification is absent or inaccessible.');
245
+ return item;
246
+ });
247
+ }
248
+ function dismissOwned(principal, ids, revalidate) {
249
+ revalidate(); inspectOwned(principal, ids);
250
+ var previous = notifications;
251
+ notifications = notifications.filter(function (item) { return ids.indexOf(item.id) < 0; });
252
+ var tmp = NOTIF_FILE + '.tmp';
253
+ try { fs.writeFileSync(tmp, JSON.stringify(notifications, null, 2)); fs.renameSync(tmp, NOTIF_FILE); }
254
+ catch (error) { notifications = previous; throw error; }
255
+ // Use the ordinary per-viewer notification state; no private IDs are broadcast.
256
+ var published = true;
257
+ if (ctx.forEachClient) ctx.forEachClient(function (ws) { try { sendConnectionState(ws, function (client, payload) { if (client.readyState === 1) client.send(JSON.stringify(payload)); }); } catch (error) { published = false; } });
258
+ try { revalidate(); } catch (error) { return { status: 'failed', persisted: true, dismissedIds: ids, error: error.message, retrySafe: false }; }
259
+ return { status: published ? 'completed' : 'failed', persisted: true, dismissedIds: ids, viewerPublication: published ? 'sent' : 'partial', retrySafe: false };
260
+ }
261
+
262
+ function dismissAll(ws) {
263
+ dismiss(visible(ws).map(function (notification) { return notification.id; }), ws);
218
264
  }
219
265
 
220
266
  // --- Periodic reminder ---
@@ -222,8 +268,15 @@ function attachNotifications(ctx) {
222
268
  function startReminder() {
223
269
  if (reminderTimer) return;
224
270
  reminderTimer = setInterval(function () {
271
+ if (ctx.canView && ctx.getUsers && pushModule && pushModule.sendPushToUser) {
272
+ ctx.getUsers().forEach(function (user) {
273
+ var count = visible({ _clayUser: user }).length;
274
+ if (count) pushModule.sendPushToUser(user.id, { type: "reminder", title: "Clay", body: count + " unread notification" + (count > 1 ? "s" : ""), tag: "clay-notif-reminder" });
275
+ });
276
+ return;
277
+ }
225
278
  var count = getUnreadCount();
226
- if (count > 0 && pushModule) {
279
+ if (count > 0 && pushModule && !ctx.canView) {
227
280
  pushModule.sendPush({
228
281
  type: "reminder",
229
282
  title: "Clay",
@@ -244,10 +297,11 @@ function attachNotifications(ctx) {
244
297
 
245
298
  function sendConnectionState(ws, sendTo) {
246
299
  if (!sendTo) return;
300
+ var list = visible(ws);
247
301
  sendTo(ws, {
248
302
  type: "notifications_state",
249
- notifications: notifications,
250
- unreadCount: getUnreadCount(),
303
+ notifications: list,
304
+ unreadCount: list.length,
251
305
  });
252
306
  }
253
307
 
@@ -255,17 +309,21 @@ function attachNotifications(ctx) {
255
309
 
256
310
  function handleNotificationMessage(ws, msg) {
257
311
  if (msg.type === "notification_dismiss") {
258
- dismiss(msg.ids || []);
312
+ dismiss(msg.ids || [], ws);
259
313
  return true;
260
314
  }
261
315
  if (msg.type === "notification_dismiss_all") {
262
- dismissAll();
316
+ dismissAll(ws);
263
317
  return true;
264
318
  }
265
319
  return false;
266
320
  }
267
321
 
268
322
  return {
323
+ authorizeOwned: authorizeOwned,
324
+ listOwned: listOwned,
325
+ inspectOwned: inspectOwned,
326
+ dismissOwned: dismissOwned,
269
327
  notify: notify,
270
328
  getUnreadCount: getUnreadCount,
271
329
  sendConnectionState: sendConnectionState,
@@ -0,0 +1,77 @@
1
+ // Ownership recovery changes project metadata only; session owners stay intact.
2
+ var fs = require("fs");
3
+ var path = require("path");
4
+
5
+ function isPersonal(project) {
6
+ return project.isMate === true || /^mate-/.test(project.slug || "");
7
+ }
8
+
9
+ function verifiedPrivateOwner(project, accounts, resolveIdentity) {
10
+ var root;
11
+ var stat;
12
+ try {
13
+ root = fs.realpathSync(project.path);
14
+ if (root !== path.resolve(project.path)) return null;
15
+ stat = fs.statSync(root);
16
+ } catch (e) { return null; }
17
+ var matches = [];
18
+ var identities = [];
19
+ for (var i = 0; i < accounts.length; i++) {
20
+ var account = accounts[i];
21
+ if (!account.linuxUser) continue;
22
+ try {
23
+ var identity = resolveIdentity(account.linuxUser);
24
+ var home = fs.realpathSync(identity.home);
25
+ if (!Number.isInteger(identity.uid) || identity.uid < 0 || fs.statSync(home).uid !== identity.uid || home !== path.resolve(identity.home) || home === path.parse(home).root) continue;
26
+ identities.push({ account: account, uid: identity.uid, home: home });
27
+ } catch (e) { return null; }
28
+ }
29
+ for (var j = 0; j < identities.length; j++) {
30
+ var candidate = identities[j];
31
+ var relative = path.relative(candidate.home, root);
32
+ if (candidate.uid !== stat.uid || relative === ".." || relative.indexOf(".." + path.sep) === 0 || path.isAbsolute(relative)) continue;
33
+ // A shared UID or overlapping home is never authoritative evidence.
34
+ var ambiguous = identities.some(function (other) {
35
+ if (other === candidate) return false;
36
+ var overlap = path.relative(other.home, root);
37
+ return other.uid === candidate.uid || (!path.isAbsolute(overlap) && overlap !== ".." && overlap.indexOf(".." + path.sep) !== 0);
38
+ });
39
+ if (!ambiguous) matches.push(candidate.account.id);
40
+ }
41
+ return matches.length === 1 ? matches[0] : null;
42
+ }
43
+
44
+ function repair(config, accounts, persist, resolveIdentity) {
45
+ var next = JSON.parse(JSON.stringify(config));
46
+ var valid = Object.create(null);
47
+ accounts.forEach(function (user) { if (typeof user.id === "string" && user.id) valid[user.id] = user; });
48
+ if (!accounts.length) return config; // Pre-account setup is repaired after bootstrap.
49
+ var admins = accounts.filter(function (user) { return user.role === "admin" && valid[user.id]; }).sort(function (a, b) { return a.id.localeCompare(b.id); });
50
+ var preferred = next.ownershipRecoveryAdminId || next.singleUserMigratedUserId;
51
+ var designated = valid[preferred] && valid[preferred].role === "admin" ? preferred : (admins[0] && admins[0].id);
52
+ if (designated) next.ownershipRecoveryAdminId = designated;
53
+ (next.projects || []).forEach(function (project) {
54
+ if (isPersonal(project) || project.slug.indexOf("--") !== -1) return;
55
+ if (valid[project.ownerId]) { delete project.ownershipRecovery; return; }
56
+ var visibility = project.visibility || (next.osUsers ? "private" : "public");
57
+ var recovered = visibility === "public" ? designated : verifiedPrivateOwner(project, accounts, resolveIdentity);
58
+ if (recovered) {
59
+ project.ownerId = recovered;
60
+ delete project.ownershipRecovery;
61
+ } else project.ownershipRecovery = "required";
62
+ });
63
+ if (JSON.stringify(next) === JSON.stringify(config)) return config;
64
+ persist(next); // Publish only after atomic persistence succeeds; failures abort boot.
65
+ return next;
66
+ }
67
+
68
+ function register(config, project, accounts, persist, resolveIdentity) {
69
+ var next = JSON.parse(JSON.stringify(config));
70
+ if (!next.projects) next.projects = [];
71
+ next.projects.push(project);
72
+ next = repair(next, accounts, function () {}, resolveIdentity);
73
+ persist(next);
74
+ return next;
75
+ }
76
+
77
+ module.exports = { repair: repair, register: register, verifiedPrivateOwner: verifiedPrivateOwner, isPersonal: isPersonal };
@@ -113,15 +113,26 @@ function attachPairResultDelivery(ctx) {
113
113
  if (sdk.pushMessage(caller, message) === true) {
114
114
  return accepted(caller, partner, token, attemptId);
115
115
  }
116
- return retry(caller, partner, token, attemptId, "Driver query rejected the result");
116
+ // The production bridge clears a stale input on false. Resume in this
117
+ // attempt instead of spending the bounded retries on a dead handle.
118
+ if (caller.queryInstance || caller._queryStarting) return retry(caller, partner, token, attemptId, "Driver query rejected the result");
117
119
  }
118
120
  token._deliveryStartupAttemptId = attemptId;
119
121
  var beforePush = function () { return token._deliveryStartupAttemptId === attemptId && currentAttempt(caller, partner, token, attemptId); };
120
122
  var onAccepted = function () { accepted(caller, partner, token, attemptId); };
121
123
  var timeoutMs = Number(ctx.acceptanceTimeoutMs || DEFAULT_ACCEPTANCE_TIMEOUT_MS);
122
- token._deliveryTimer = { attemptId: attemptId, timer: setTimeout(function () {
124
+ function acceptanceTimeout() {
125
+ if (!currentAttempt(caller, partner, token, attemptId)) return;
126
+ // A known, cancellable provider admission wait has not sent input.
127
+ // Keep the correlated completion eligible until admission or Stop.
128
+ if (caller._queryStarting && Number(caller._codexRecoveryWaiting) > 0
129
+ && caller._codexRecoveryWaiting === caller._sdkQueryGeneration) {
130
+ token._deliveryTimer = { attemptId: attemptId, timer: setTimeout(acceptanceTimeout, timeoutMs) };
131
+ return;
132
+ }
123
133
  uncertain(caller, partner, token, attemptId, "delivery acceptance timed out");
124
- }, timeoutMs) };
134
+ }
135
+ token._deliveryTimer = { attemptId: attemptId, timer: setTimeout(acceptanceTimeout, timeoutMs) };
125
136
  var startup = sdk.startQuery(caller, message, undefined, ctx.getLinuxUserForSession(caller), beforePush, onAccepted);
126
137
  Promise.resolve(startup).then(function (result) {
127
138
  if (!currentAttempt(caller, partner, token, attemptId)) return;
@@ -141,6 +141,7 @@ function createPendingMessageQueue(opts) {
141
141
  delete item.message._scheduledJobId;
142
142
  delete item.message._scheduledRevision;
143
143
  delete item.message._scheduledNotBefore;
144
+ if (session._pendingMessageDrainPaused || session.taskStopRequested) data.paused[targetKey(session)] = true;
144
145
  data.items.push(item);
145
146
  data.revision++;
146
147
  try { persist(); } catch (e) { restore(before); return result(false, "Queue storage failed", session, actor); }
@@ -0,0 +1,87 @@
1
+ var userInput = require("./yoke/user-input");
2
+ var provenance = require("./session-provenance");
3
+ var deletion = require("./project-session-delete");
4
+ function attachProjectProductControl(ctx) {
5
+ var queues = require("./project-product-session-queue").attachProductSessionQueue({ queue: ctx.queue, sm: ctx.sm, users: ctx.users, requestDrain: ctx.requestQueueDrain });
6
+ function inspectQueue(principal, session) {
7
+ owned(principal, session);
8
+ if (ctx.isMate || provenance.isWorker(session) || session.spawn || ctx.isDriverOperatedSession(session)) throw new Error("Queues are controlled through their project Driver.");
9
+ return queues.inspect(principal, session);
10
+ }
11
+ function owned(principal, session) {
12
+ if (!session || ctx.sm.sessions.get(session.localId) !== session) throw new Error("Target session was deleted or replaced.");
13
+ if (ctx.users.isMultiUser()) {
14
+ var user = ctx.users.findUserById(principal.userId);
15
+ if (!user || session.ownerId !== user.id || !ctx.users.canAccessProject(user.id, ctx.getProjectAccess())) throw new Error("Live target ownership or access denied.");
16
+ return user;
17
+ }
18
+ if (session.ownerId && session.ownerId !== principal.singleUserOwnerId) throw new Error("Live target ownership denied.");
19
+ return null;
20
+ }
21
+ function review(session, question, revalidate) {
22
+ var owner = session.ownerId || null;
23
+ return userInput.dispatchUserInput(function (request, respond) {
24
+ request.authorizeResponse = function (ws) {
25
+ try {
26
+ revalidate();
27
+ if (ctx.users.isMultiUser() && (!ws || !ws._clayUser || ws._clayUser.id !== owner || !ctx.users.findUserById(owner))) return false;
28
+ var tap = ws && ws._homeChatTap;
29
+ return !!ws && ((ctx.clients.has(ws) && ws._clayActiveSession === session.localId) || (tap && tap.mateSlug === ctx.slug && tap.sessionId === session.localId));
30
+ } catch (error) { return false; }
31
+ };
32
+ ctx.userInput(session)(request, respond);
33
+ }, { questions: [{ id: "control", header: "Review change", question: question, options: [{ label: "Keep unchanged" }, { label: "Apply exact change" }], allowOther: false }] }, { source: "product-control", signal: session.abortController && session.abortController.signal });
34
+ }
35
+ async function apply(principal, session, action, value, revalidate, control) {
36
+ var user = owned(principal, session);
37
+ function current() {
38
+ owned(principal, session);
39
+ if (typeof revalidate !== "function") throw new Error("An exact product control revision is required.");
40
+ revalidate();
41
+ }
42
+ current();
43
+ if (ctx.isMate || provenance.isWorker(session) || session.spawn || ctx.isDriverOperatedSession(session)) throw new Error("This target is not a project Driver.");
44
+ if (action.indexOf("queue_") === 0) return queues.apply(principal, session, control.args, current, control.requestKey);
45
+ if (action === "vendor") return ctx.vendor.setVendor(session, value, current);
46
+ if (action === "vendor_new_session") return ctx.vendor.newSession(session, value, current);
47
+ if (action === "runtime") return ctx.runtime.change(session, value, current);
48
+ if (action === "rename") return ctx.actions.rename(session, value);
49
+ if (action === "stop") return ctx.actions.stop(session, user);
50
+ if (session.taskStopRequested && action !== "delete") throw new Error("Target was stopped; explicit Driver resumption is required.");
51
+ if (action === "model") {
52
+ var models = (ctx.sm.modelsByVendor || {})[session.vendor || ctx.sm.defaultVendor || "claude"] || [];
53
+ if (!models.length) throw new Error("Provider model catalog is unavailable; no model was changed.");
54
+ var result = await ctx.selectModel(session, value, { revalidate: current });
55
+ if (!result) throw new Error("Model change failed.");
56
+ if (result.ok !== true && result.status !== "failed") throw new Error(result.error || "Model change failed.");
57
+ return result;
58
+ }
59
+ if (action === "effort") return ctx.actions.effort(session, value, current);
60
+ if (action === "permission") return ctx.actions.permission(session, value, null, current);
61
+ if (action === "fork" || action === "rewind") {
62
+ if (session.isProcessing || session._queryStarting || Object.keys(session.pendingPermissions || {}).length || Object.keys(session.pendingAskUser || {}).length) throw new Error("History changes require an idle Driver without pending approvals.");
63
+ if (!session.cliSessionId || !(session.messageUUIDs || []).some(function (entry) { return entry.uuid === value; })) throw new Error("Choose an exact recorded checkpoint from inspection.");
64
+ var vendor = session.vendor || ctx.sm.defaultVendor || "claude";
65
+ var caps = (ctx.sm.capabilitiesByVendor || {})[vendor] || {};
66
+ if (action === "fork" && !caps.fork || action === "rewind" && !caps.rollback && !caps.rewind) throw new Error("This provider does not support that history operation.");
67
+ if (action === "fork") {
68
+ var forked = await ctx.history.fork(session, value, null, revalidate);
69
+ if (!forked) throw new Error("The provider did not produce a forked session.");
70
+ return { forkedSessionRef: require("./workspace-query-service").sessionRef(ctx.slug, forked) };
71
+ }
72
+ return ctx.history.rewind(session, value, "chat", null, revalidate);
73
+ }
74
+ if (action === "delete") {
75
+ if (user && !ctx.users.getEffectivePermissions(user, ctx.osUsers).sessionDelete) throw new Error("You do not have permission to delete sessions.");
76
+ var plan = deletion.resolveDeletionScope(ctx.sm.sessions, [session], function (candidate) { return (candidate.ownerId || null) === (session.ownerId || null); });
77
+ if (!plan.ok) throw new Error(plan.error);
78
+ // A live Driver or Worker must be stopped and settled before deletion.
79
+ if (plan.ids.some(function (id) { var item = ctx.sm.sessions.get(id); return item.isProcessing || item._queryStarting; })) throw new Error("Stop the Driver and its Workers and wait for completion before deleting them.");
80
+ ctx.deletePlan(plan);
81
+ return { deletedCount: plan.ids.length };
82
+ }
83
+ throw new Error("Unsupported product control action.");
84
+ }
85
+ return { requestProductControlReview: review, applyProductSessionAction: apply, inspectProductSessionQueue: inspectQueue };
86
+ }
87
+ module.exports = { attachProjectProductControl: attachProjectProductControl };
@@ -0,0 +1,46 @@
1
+ var crypto = require('crypto');
2
+ function attachProductSessionQueue(ctx) {
3
+ var queue = ctx.queue;
4
+ function actor(principal) {
5
+ if (!ctx.users.isMultiUser()) return null;
6
+ var user = ctx.users.findUserById(principal.userId);
7
+ if (!user) throw new Error('Queue owner is no longer available.');
8
+ return user;
9
+ }
10
+ function inspect(principal, session) {
11
+ var user = actor(principal), state = queue.hydrate(session, user);
12
+ if (!state.ok) throw new Error(state.error || 'Queue inspection failed.');
13
+ return { revision: state.revision, paused: state.paused || !!session._pendingMessageDrainPaused || !!session.taskStopRequested,
14
+ items: state.items.filter(function (item) { return item.actorId === (user ? user.id : 'default'); }).filter(function (item, index, all) { return item.state === 'pending' || item.state === 'claimed' || index >= all.length - 20; }).map(function (item) {
15
+ return { id: item.id, state: item.state, text: String(item.message.text || '').slice(0, 1600), textTruncated: String(item.message.text || '').length > 1600,
16
+ imageCount: (item.message.images || []).length, pasteCount: (item.message.pastes || []).length, scheduled: !!item.schedule, failure: item.failure ? String(item.failure).slice(0, 500) : null };
17
+ }) };
18
+ }
19
+ function apply(principal, session, args, revalidate, requestKey) {
20
+ revalidate();
21
+ var user = actor(principal), before = queue.getRevision(), result;
22
+ try {
23
+ if (args.action === 'queue_add') {
24
+ var clientId = 'clay-control:' + crypto.createHash('sha256').update(requestKey).digest('hex');
25
+ var existing = queue.inspect(session, user, clientId);
26
+ var digest = crypto.createHash('sha256').update(args.text).digest('hex');
27
+ if (existing && (existing.message._clayControlDigest || crypto.createHash('sha256').update(existing.message.text).digest('hex')) !== digest) throw new Error('This requestId already identifies a different durable queue message.');
28
+ result = queue.admit(session, { type: 'message', text: args.text, clientMessageId: clientId, _clayControlDigest: digest }, user);
29
+ } else if (args.action === 'queue_edit') result = queue.edit(session, user, args.messageId, before, session.localId, { text: args.text });
30
+ else if (args.action === 'queue_cancel') result = queue.cancel(session, user, args.messageId, before, session.localId);
31
+ else if (args.action === 'queue_reorder') result = queue.reorder(session, user, args.ids, before, session.localId);
32
+ else throw new Error('Unsupported queue action.');
33
+ } catch (error) {
34
+ return { status: 'failed', outcome: queue.getRevision() !== before ? 'partial' : 'failed', persisted: queue.getRevision() !== before, error: error.message, queue: inspect(principal, session) };
35
+ }
36
+ if (!result || !result.ok) return { status: 'failed', persisted: false, error: result && result.error || 'Queue operation failed.', messageId: result && result.item && result.item.id, deliveryState: result && result.item && result.item.state, queue: inspect(principal, session) };
37
+ var state = inspect(principal, session);
38
+ if (args.action === 'queue_add') {
39
+ if (result.item && result.item.state === 'pending' && !state.paused) setImmediate(function () { if (ctx.sm.sessions.get(session.localId) === session) ctx.requestDrain(session); });
40
+ return { status: result.item && result.item.state === 'consumed' ? 'completed' : 'queued', persisted: true, messageId: result.item && result.item.id, deliveryState: result.item && result.item.state, queue: state };
41
+ }
42
+ return { status: 'completed', persisted: true, queue: state };
43
+ }
44
+ return { inspect: inspect, apply: apply };
45
+ }
46
+ module.exports = { attachProductSessionQueue: attachProductSessionQueue };
@@ -0,0 +1,28 @@
1
+ // Project push payloads carry session content and use the same live authority
2
+ // as HTTP and WebSocket snapshots. Unscoped account/system pushes stay separate.
3
+ function scopedPush(push, ctx) {
4
+ if (!push) return null;
5
+ function permitted(userId, payload) {
6
+ var data = payload.data || payload;
7
+ var slug = data.slug || ctx.slug;
8
+ var project = ctx.getProject(slug);
9
+ if (!project || !data.sessionId || !ctx.canAccessProject(userId, slug)) return false;
10
+ var session = project.getSessionManager().sessions.get(data.sessionId);
11
+ var status = project.getStatus();
12
+ var access = status.isMate ? { isMate: true, visibility: "private", ownerId: status.projectOwnerId } : ctx.getAccess(slug);
13
+ return !!session && ctx.users.canAccessSession(userId, session, access);
14
+ }
15
+ return Object.assign({}, push, {
16
+ sendPush: function (payload) {
17
+ if (!ctx.users.isMultiUser()) return push.sendPush(payload);
18
+ if (!push.sendPushToUser) return;
19
+ ctx.users.getAllUsers().forEach(function (user) {
20
+ if (permitted(user.id, payload)) push.sendPushToUser(user.id, payload);
21
+ });
22
+ },
23
+ sendPushToUser: function (userId, payload) {
24
+ if ((!ctx.users.isMultiUser() || permitted(userId, payload)) && push.sendPushToUser) push.sendPushToUser(userId, payload);
25
+ },
26
+ });
27
+ }
28
+ module.exports = { scopedPush: scopedPush };
@@ -0,0 +1,30 @@
1
+ function attachScheduledMessageQueue(ctx) {
2
+ var users = ctx.users;
3
+ var pendingMessageQueue = ctx.pendingMessageQueue;
4
+ function queueActor(actorId) {
5
+ return users.isMultiUser() ? users.findUserById(actorId) : { id: "default" };
6
+ }
7
+ function queueItemForJob(session, job, actorId) {
8
+ if (!pendingMessageQueue || !session || !job) return null;
9
+ var actor = queueActor(actorId || (job.payload && job.payload.actorId));
10
+ var items = pendingMessageQueue.list(session, actor);
11
+ for (var i = 0; i < items.length; i++) {
12
+ if (items[i].schedule && items[i].schedule.jobId === job.id && items[i].schedule.revision === job.payload.revision) return items[i];
13
+ }
14
+ return null;
15
+ }
16
+ function validateQueueControl(session, job, actorId, correlation, requireQueueRevision) {
17
+ if (!pendingMessageQueue) return null;
18
+ if (requireQueueRevision && (!correlation || correlation.queueRevision == null || Number(correlation.queueRevision) !== pendingMessageQueue.getRevision())) {
19
+ throw new Error("The scheduled-message queue is stale.");
20
+ }
21
+ var actor = queueActor(actorId || (job.payload && job.payload.actorId));
22
+ var item = queueItemForJob(session, job, actorId);
23
+ if (!item || item.actorId !== actor.id || ["cancelled", "consumed", "failed"].indexOf(item.state) >= 0) {
24
+ throw new Error("The scheduled queue item is no longer available.");
25
+ }
26
+ return item;
27
+ }
28
+ return { actor: queueActor, item: queueItemForJob, validate: validateQueueControl };
29
+ }
30
+ module.exports = { attachScheduledMessageQueue: attachScheduledMessageQueue };