@clagentic/console 1.12.0 → 1.13.0-beta.1

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 (243) hide show
  1. package/README.md +7 -1
  2. package/bin/cli.js +18 -15
  3. package/lib/agent-roster-ws.js +38 -13
  4. package/lib/agent-roster.js +111 -12
  5. package/lib/agents.js +68 -33
  6. package/lib/atomic-install.js +334 -0
  7. package/lib/build-changes.js +33 -4
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-offer.js +12 -0
  10. package/lib/chat-width.js +31 -0
  11. package/lib/cli/agent-usage.js +126 -0
  12. package/lib/cli/arg-validation.js +1 -1
  13. package/lib/cli/compact-output.js +69 -0
  14. package/lib/cli/ipc-subcommands.js +92 -67
  15. package/lib/cli/output.js +28 -0
  16. package/lib/cli/restart-verb.js +132 -0
  17. package/lib/cli/schedule-input-subcommands.js +45 -8
  18. package/lib/cli/session-subcommands.js +37 -11
  19. package/lib/cli/settings-subcommands.js +74 -0
  20. package/lib/cli-transcript-title.js +56 -3
  21. package/lib/client-files.js +79 -0
  22. package/lib/daemon.js +100 -28
  23. package/lib/default-avatar-color.js +4 -0
  24. package/lib/drain.js +58 -10
  25. package/lib/mcp-tool-input.js +2 -2
  26. package/lib/model-families.js +49 -1
  27. package/lib/notify/type-registry.js +4 -0
  28. package/lib/notify/types.js +7 -4
  29. package/lib/pages.js +13 -63
  30. package/lib/permission-summary.js +12 -16
  31. package/lib/plan-usage-reader.js +70 -0
  32. package/lib/project-connection.js +4 -2
  33. package/lib/project-filesystem.js +6 -7
  34. package/lib/project-notifications.js +55 -8
  35. package/lib/project-prompt-expiry-settings.js +42 -0
  36. package/lib/project-sessions.js +52 -0
  37. package/lib/project-settings-gate.js +98 -0
  38. package/lib/project-user-mention.js +3 -2
  39. package/lib/project.js +1 -1
  40. package/lib/prompt-expiry-settings.js +49 -0
  41. package/lib/prompt-expiry.js +24 -3
  42. package/lib/prompt-kinds/codecs.js +6 -2
  43. package/lib/public/app.js +36 -36
  44. package/lib/public/css/admin.css +156 -170
  45. package/lib/public/css/agent-messages.css +24 -24
  46. package/lib/public/css/agent-picker.css +90 -38
  47. package/lib/public/css/agent-roster.css +61 -27
  48. package/lib/public/css/at-agents.css +10 -10
  49. package/lib/public/css/base.css +207 -184
  50. package/lib/public/css/chat-layout.css +228 -0
  51. package/lib/public/css/command-palette.css +86 -88
  52. package/lib/public/css/diagnostics.css +78 -204
  53. package/lib/public/css/diff.css +10 -10
  54. package/lib/public/css/filebrowser.css +32 -60
  55. package/lib/public/css/home-hub.css +100 -100
  56. package/lib/public/css/icon-strip.css +195 -238
  57. package/lib/public/css/input.css +191 -212
  58. package/lib/public/css/login-panel.css +16 -16
  59. package/lib/public/css/loop.css +96 -187
  60. package/lib/public/css/mention.css +49 -110
  61. package/lib/public/css/menus.css +162 -169
  62. package/lib/public/css/messages.css +49 -123
  63. package/lib/public/css/mobile-nav.css +207 -264
  64. package/lib/public/css/notifications-center.css +45 -124
  65. package/lib/public/css/overlay.css +269 -0
  66. package/lib/public/css/overlays.css +134 -156
  67. package/lib/public/css/playbook.css +41 -41
  68. package/lib/public/css/profile.css +43 -112
  69. package/lib/public/css/rewind.css +112 -112
  70. package/lib/public/css/scheduler-modal.css +27 -135
  71. package/lib/public/css/scheduler.css +204 -210
  72. package/lib/public/css/server-settings.css +173 -239
  73. package/lib/public/css/session-search.css +20 -20
  74. package/lib/public/css/settings-nav.css +197 -0
  75. package/lib/public/css/sidebar.css +213 -304
  76. package/lib/public/css/skills.css +121 -135
  77. package/lib/public/css/sticky-notes.css +114 -200
  78. package/lib/public/css/stt.css +17 -26
  79. package/lib/public/css/team-panel.css +36 -36
  80. package/lib/public/css/team-view.css +9 -9
  81. package/lib/public/css/title-bar.css +83 -100
  82. package/lib/public/css/tooltip.css +10 -10
  83. package/lib/public/css/user-settings.css +78 -131
  84. package/lib/public/css/user-shell.css +125 -29
  85. package/lib/public/index.html +178 -177
  86. package/lib/public/manifest.json +0 -2
  87. package/lib/public/modules/admin.js +54 -92
  88. package/lib/public/modules/agent-avatar.js +134 -3
  89. package/lib/public/modules/agent-messages.js +2 -1
  90. package/lib/public/modules/agent-picker.js +23 -21
  91. package/lib/public/modules/agent-roster-groups.js +128 -0
  92. package/lib/public/modules/agent-roster.js +40 -11
  93. package/lib/public/modules/app-connection.js +13 -1
  94. package/lib/public/modules/app-cursors.js +9 -9
  95. package/lib/public/modules/app-favicon.js +8 -16
  96. package/lib/public/modules/app-header.js +28 -19
  97. package/lib/public/modules/app-history-replay.js +67 -4
  98. package/lib/public/modules/app-home-hub.js +15 -0
  99. package/lib/public/modules/app-loop-ui.js +41 -47
  100. package/lib/public/modules/app-loop-wizard.js +9 -10
  101. package/lib/public/modules/app-messages.js +32 -36
  102. package/lib/public/modules/app-misc.js +22 -92
  103. package/lib/public/modules/app-modals.js +98 -0
  104. package/lib/public/modules/app-notifications.js +124 -135
  105. package/lib/public/modules/app-panels.js +28 -32
  106. package/lib/public/modules/app-projects.js +30 -40
  107. package/lib/public/modules/app-rate-limit.js +26 -9
  108. package/lib/public/modules/app-rendering.js +128 -110
  109. package/lib/public/modules/app-skills-install.js +6 -4
  110. package/lib/public/modules/assistant-identity.js +55 -0
  111. package/lib/public/modules/at-agents.js +3 -0
  112. package/lib/public/modules/build-guard.js +25 -11
  113. package/lib/public/modules/chat-width-choice.js +75 -0
  114. package/lib/public/modules/chat-width-prefs.js +52 -0
  115. package/lib/public/modules/chat-width.js +102 -0
  116. package/lib/public/modules/collapsible-text.js +36 -4
  117. package/lib/public/modules/command-palette.js +28 -34
  118. package/lib/public/modules/context-sources.js +3 -5
  119. package/lib/public/modules/diagnostics.js +130 -129
  120. package/lib/public/modules/info-panel.js +31 -0
  121. package/lib/public/modules/injected-identity.js +8 -8
  122. package/lib/public/modules/input-list-menu.js +39 -0
  123. package/lib/public/modules/input.js +22 -21
  124. package/lib/public/modules/markdown.js +10 -11
  125. package/lib/public/modules/mcp-ui.js +4 -14
  126. package/lib/public/modules/mention.js +100 -229
  127. package/lib/public/modules/message-header.js +80 -0
  128. package/lib/public/modules/message-participants.js +39 -0
  129. package/lib/public/modules/mobile-action-sheet.js +46 -0
  130. package/lib/public/modules/mobile-nav-sheet.js +104 -0
  131. package/lib/public/modules/model-families.js +41 -4
  132. package/lib/public/modules/note-order.js +39 -0
  133. package/lib/public/modules/notifications.js +35 -52
  134. package/lib/public/modules/overlay-history.js +73 -19
  135. package/lib/public/modules/overlay-menu.js +123 -0
  136. package/lib/public/modules/overlay-modal.js +186 -0
  137. package/lib/public/modules/overlay-registry.js +392 -0
  138. package/lib/public/modules/overlay-stack.js +110 -0
  139. package/lib/public/modules/overlay.js +117 -0
  140. package/lib/public/modules/popover-position.js +18 -2
  141. package/lib/public/modules/preference-sync.js +28 -0
  142. package/lib/public/modules/profile.js +24 -49
  143. package/lib/public/modules/project-settings.js +27 -172
  144. package/lib/public/modules/prompt-expiry-controls.js +46 -0
  145. package/lib/public/modules/prompt-kinds/command-summary.js +149 -0
  146. package/lib/public/modules/prompt-kinds/permission.js +70 -92
  147. package/lib/public/modules/prompts.js +1 -2
  148. package/lib/public/modules/qrcode.js +6 -21
  149. package/lib/public/modules/queued-button.js +15 -2
  150. package/lib/public/modules/rewind.js +9 -3
  151. package/lib/public/modules/schedule-time.js +32 -7
  152. package/lib/public/modules/scheduled-outbox.js +51 -18
  153. package/lib/public/modules/scheduler-config.js +87 -127
  154. package/lib/public/modules/scheduler.js +29 -26
  155. package/lib/public/modules/serialized-save.js +79 -0
  156. package/lib/public/modules/server-settings.js +75 -65
  157. package/lib/public/modules/session-grants.js +16 -19
  158. package/lib/public/modules/session-list-avatars.js +98 -0
  159. package/lib/public/modules/session-vendor-state.js +86 -0
  160. package/lib/public/modules/settings-access.js +35 -0
  161. package/lib/public/modules/settings-hub.js +125 -0
  162. package/lib/public/modules/settings-nav.js +182 -0
  163. package/lib/public/modules/shell-line.js +24 -0
  164. package/lib/public/modules/sidebar-mobile.js +151 -195
  165. package/lib/public/modules/sidebar-projects.js +88 -129
  166. package/lib/public/modules/sidebar-sessions.js +66 -34
  167. package/lib/public/modules/sidebar.js +2 -2
  168. package/lib/public/modules/skills.js +11 -26
  169. package/lib/public/modules/sticky-notes.js +19 -16
  170. package/lib/public/modules/stt.js +9 -23
  171. package/lib/public/modules/terminal.js +86 -90
  172. package/lib/public/modules/theme-choice.js +126 -0
  173. package/lib/public/modules/theme-colors.js +19 -0
  174. package/lib/public/modules/theme-prefs.js +121 -0
  175. package/lib/public/modules/theme.js +227 -605
  176. package/lib/public/modules/tool-palette.js +7 -17
  177. package/lib/public/modules/tools.js +8 -10
  178. package/lib/public/modules/user-settings.js +59 -115
  179. package/lib/public/modules/user-shell.js +9 -2
  180. package/lib/public/modules/utils.js +10 -12
  181. package/lib/public/modules/vendor-picker.js +4 -2
  182. package/lib/public/modules/vendor-registry.js +1 -2
  183. package/lib/public/style.css +3 -1
  184. package/lib/public/sw.js +9 -2
  185. package/lib/public/theme-core.js +411 -0
  186. package/lib/request-body.js +70 -0
  187. package/lib/sdk-bridge.js +227 -88
  188. package/lib/sdk-message-processor.js +44 -16
  189. package/lib/server-admin.js +198 -200
  190. package/lib/server-auth.js +16 -13
  191. package/lib/server-dm.js +4 -3
  192. package/lib/server-settings.js +177 -130
  193. package/lib/server.js +87 -36
  194. package/lib/session-background-tasks.js +79 -0
  195. package/lib/session-directory.js +138 -13
  196. package/lib/session-input-ipc.js +2 -0
  197. package/lib/session-input.js +39 -5
  198. package/lib/session-list-avatars.js +16 -0
  199. package/lib/session-reclaim.js +37 -25
  200. package/lib/session-vendor.js +37 -0
  201. package/lib/sessions.js +99 -34
  202. package/lib/settings-ipc.js +60 -0
  203. package/lib/settings-registry.js +86 -0
  204. package/lib/terminal-manager.js +17 -5
  205. package/lib/theme-files.js +132 -0
  206. package/lib/theme-seed.js +136 -0
  207. package/lib/themes/clagentic-dark.json +13 -6
  208. package/lib/themes/clagentic-light.json +12 -5
  209. package/lib/updater.js +6 -4
  210. package/lib/usage-store.js +97 -10
  211. package/lib/users-preferences.js +118 -19
  212. package/lib/users.js +19 -10
  213. package/lib/vendor-catalog.js +130 -0
  214. package/lib/ws-schema.js +4 -2
  215. package/lib/yoke/adapters/claude.js +81 -1
  216. package/lib/yoke/adapters/codex-user-shell.js +87 -23
  217. package/lib/yoke/adapters/codex.js +89 -5
  218. package/lib/yoke/codex-binary.js +59 -0
  219. package/package.json +1 -1
  220. package/scripts/check-test-count.js +5 -0
  221. package/scripts/install-local-test.js +50 -9
  222. package/scripts/write-build-sha.js +18 -2
  223. package/lib/public/css/channel-layout.css +0 -329
  224. package/lib/themes/ayu-light.json +0 -9
  225. package/lib/themes/catppuccin-latte.json +0 -9
  226. package/lib/themes/catppuccin-mocha.json +0 -9
  227. package/lib/themes/dracula.json +0 -9
  228. package/lib/themes/everforest-light.json +0 -9
  229. package/lib/themes/everforest.json +0 -9
  230. package/lib/themes/github-light.json +0 -9
  231. package/lib/themes/gruvbox-dark.json +0 -9
  232. package/lib/themes/gruvbox-light.json +0 -9
  233. package/lib/themes/monokai.json +0 -9
  234. package/lib/themes/nord-light.json +0 -9
  235. package/lib/themes/nord.json +0 -9
  236. package/lib/themes/one-dark.json +0 -9
  237. package/lib/themes/one-light.json +0 -9
  238. package/lib/themes/rose-pine-dawn.json +0 -9
  239. package/lib/themes/rose-pine.json +0 -9
  240. package/lib/themes/solarized-dark.json +0 -9
  241. package/lib/themes/solarized-light.json +0 -9
  242. package/lib/themes/tokyo-night-light.json +0 -9
  243. package/lib/themes/tokyo-night.json +0 -9
@@ -2,6 +2,9 @@
2
2
  // Extracted from server.js
3
3
 
4
4
  var audit = require("./audit");
5
+ var requestBody = require("./request-body");
6
+ var readJsonObjectBody = requestBody.readJsonObjectBody;
7
+ var respondPersistFailure = requestBody.respondPersistFailure;
5
8
 
6
9
  function attachAdmin(ctx) {
7
10
  var users = ctx.users;
@@ -95,56 +98,63 @@ function attachAdmin(ctx) {
95
98
  res.end('{"error":"Admin access required"}');
96
99
  return true;
97
100
  }
98
- var body = "";
99
- req.on("data", function (chunk) { body += chunk; });
100
- req.on("end", function () {
101
+ readJsonObjectBody(req, res, function (data) {
102
+ if (!data.username || typeof data.username !== "string" || data.username.trim().length < 1) {
103
+ res.writeHead(400, { "Content-Type": "application/json" });
104
+ res.end('{"error":"Username is required"}');
105
+ return;
106
+ }
107
+ // A non-string name or email used to throw inside the combined try and
108
+ // answer 400; it is still a client error, so it is checked up front.
109
+ if ((data.displayName && typeof data.displayName !== "string") || (data.email && typeof data.email !== "string")) {
110
+ res.writeHead(400, { "Content-Type": "application/json" });
111
+ res.end('{"error":"Invalid request"}');
112
+ return;
113
+ }
114
+ var result;
101
115
  try {
102
- var data = JSON.parse(body);
103
- if (!data.username || typeof data.username !== "string" || data.username.trim().length < 1) {
104
- res.writeHead(400, { "Content-Type": "application/json" });
105
- res.end('{"error":"Username is required"}');
106
- return;
107
- }
108
- var result = users.createUserByAdmin({
116
+ result = users.createUserByAdmin({
109
117
  username: data.username.trim(),
110
118
  displayName: data.displayName ? data.displayName.trim() : data.username.trim(),
111
119
  email: data.email ? data.email.trim() : null,
112
120
  role: data.role === "admin" ? "admin" : "user",
113
121
  });
114
- if (result.error) {
115
- res.writeHead(400, { "Content-Type": "application/json" });
116
- res.end(JSON.stringify({ error: result.error }));
117
- return;
118
- }
119
- // Auto-provision Linux account if OS users mode is enabled
120
- if (osUsers && !result.user.linuxUser) {
121
- var provision = provisionLinuxUser(result.user.username);
122
- if (provision.ok) {
123
- users.updateLinuxUser(result.user.id, provision.linuxUser);
124
- if (onUserProvisioned) onUserProvisioned(result.user.id, provision.linuxUser);
122
+ if (!result.error) {
123
+ // Auto-provision Linux account if OS users mode is enabled
124
+ if (osUsers && !result.user.linuxUser) {
125
+ var provision = provisionLinuxUser(result.user.username);
126
+ if (provision.ok) {
127
+ users.updateLinuxUser(result.user.id, provision.linuxUser);
128
+ if (onUserProvisioned) onUserProvisioned(result.user.id, provision.linuxUser);
129
+ }
125
130
  }
131
+ audit.log("user.create", {
132
+ actorId: mu.id,
133
+ actorName: mu.username,
134
+ target: result.user.id,
135
+ metadata: { username: result.user.username, role: result.user.role },
136
+ });
126
137
  }
127
- audit.log("user.create", {
128
- actorId: mu.id,
129
- actorName: mu.username,
130
- target: result.user.id,
131
- metadata: { username: result.user.username, role: result.user.role },
132
- });
133
- res.writeHead(200, { "Content-Type": "application/json" });
134
- res.end(JSON.stringify({
135
- ok: true,
136
- user: {
137
- id: result.user.id,
138
- username: result.user.username,
139
- displayName: result.user.displayName,
140
- role: result.user.role,
141
- },
142
- tempPin: result.tempPin,
143
- }));
144
138
  } catch (e) {
139
+ respondPersistFailure(res, "user", e);
140
+ return;
141
+ }
142
+ if (result.error) {
145
143
  res.writeHead(400, { "Content-Type": "application/json" });
146
- res.end('{"error":"Invalid request"}');
144
+ res.end(JSON.stringify({ error: result.error }));
145
+ return;
147
146
  }
147
+ res.writeHead(200, { "Content-Type": "application/json" });
148
+ res.end(JSON.stringify({
149
+ ok: true,
150
+ user: {
151
+ id: result.user.id,
152
+ username: result.user.username,
153
+ displayName: result.user.displayName,
154
+ role: result.user.role,
155
+ },
156
+ tempPin: result.tempPin,
157
+ }));
148
158
  });
149
159
  return true;
150
160
  }
@@ -202,22 +212,20 @@ function attachAdmin(ctx) {
202
212
  }
203
213
  var urlParts = fullUrl.split("/");
204
214
  var targetUserId = urlParts[4]; // /api/admin/users/{userId}/linux-user
205
- var body = "";
206
- req.on("data", function(chunk) { body += chunk; });
207
- req.on("end", function() {
215
+ readJsonObjectBody(req, res, function (parsed) {
216
+ var result;
208
217
  try {
209
- var parsed = JSON.parse(body);
210
- var result = users.updateLinuxUser(targetUserId, parsed.linuxUser || null);
211
- if (result.error) {
212
- res.writeHead(400, { "Content-Type": "application/json" });
213
- res.end(JSON.stringify({ error: result.error }));
214
- } else {
215
- res.writeHead(200, { "Content-Type": "application/json" });
216
- res.end('{"ok":true}');
217
- }
218
+ result = users.updateLinuxUser(targetUserId, parsed.linuxUser || null);
218
219
  } catch (e) {
220
+ respondPersistFailure(res, "linux user", e);
221
+ return;
222
+ }
223
+ if (result.error) {
219
224
  res.writeHead(400, { "Content-Type": "application/json" });
220
- res.end('{"error":"Invalid request body"}');
225
+ res.end(JSON.stringify({ error: result.error }));
226
+ } else {
227
+ res.writeHead(200, { "Content-Type": "application/json" });
228
+ res.end('{"ok":true}');
221
229
  }
222
230
  });
223
231
  return true;
@@ -233,22 +241,20 @@ function attachAdmin(ctx) {
233
241
  }
234
242
  var urlParts = fullUrl.split("/");
235
243
  var targetUserId = urlParts[4]; // /api/admin/users/{userId}/permissions
236
- var body = "";
237
- req.on("data", function(chunk) { body += chunk; });
238
- req.on("end", function() {
244
+ readJsonObjectBody(req, res, function (parsed) {
245
+ var result;
239
246
  try {
240
- var parsed = JSON.parse(body);
241
- var result = users.updateUserPermissions(targetUserId, parsed.permissions || {});
242
- if (result.error) {
243
- res.writeHead(400, { "Content-Type": "application/json" });
244
- res.end(JSON.stringify({ error: result.error }));
245
- } else {
246
- res.writeHead(200, { "Content-Type": "application/json" });
247
- res.end(JSON.stringify({ ok: true, permissions: result.permissions }));
248
- }
247
+ result = users.updateUserPermissions(targetUserId, parsed.permissions || {});
249
248
  } catch (e) {
249
+ respondPersistFailure(res, "permissions", e);
250
+ return;
251
+ }
252
+ if (result.error) {
250
253
  res.writeHead(400, { "Content-Type": "application/json" });
251
- res.end('{"error":"Invalid request body"}');
254
+ res.end(JSON.stringify({ error: result.error }));
255
+ } else {
256
+ res.writeHead(200, { "Content-Type": "application/json" });
257
+ res.end(JSON.stringify({ ok: true, permissions: result.permissions }));
252
258
  }
253
259
  });
254
260
  return true;
@@ -322,31 +328,29 @@ function attachAdmin(ctx) {
322
328
  res.end('{"error":"Admin access required"}');
323
329
  return true;
324
330
  }
325
- var body = "";
326
- req.on("data", function (chunk) { body += chunk; });
327
- req.on("end", function () {
331
+ readJsonObjectBody(req, res, function (data) {
332
+ if (!data.email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email)) {
333
+ res.writeHead(400, { "Content-Type": "application/json" });
334
+ res.end('{"error":"Valid email is required"}');
335
+ return;
336
+ }
337
+ var invite;
328
338
  try {
329
- var data = JSON.parse(body);
330
- if (!data.email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email)) {
331
- res.writeHead(400, { "Content-Type": "application/json" });
332
- res.end('{"error":"Valid email is required"}');
333
- return;
334
- }
335
- var invite = users.createInvite(mu.id, data.email);
336
- var proto = tlsOptions ? "https" : "http";
337
- var host = req.headers.host || ("localhost:" + portNum);
338
- var inviteUrl = proto + "://" + host + "/invite/" + invite.code;
339
- smtp.sendInviteEmail(data.email, inviteUrl, mu.displayName || mu.username).then(function () {
340
- res.writeHead(200, { "Content-Type": "application/json" });
341
- res.end(JSON.stringify({ ok: true, invite: invite, url: inviteUrl }));
342
- }).catch(function (err) {
343
- res.writeHead(500, { "Content-Type": "application/json" });
344
- res.end(JSON.stringify({ error: "Failed to send email: " + (err.message || "unknown error") }));
345
- });
339
+ invite = users.createInvite(mu.id, data.email);
346
340
  } catch (e) {
347
- res.writeHead(400, { "Content-Type": "application/json" });
348
- res.end('{"error":"Invalid request"}');
341
+ respondPersistFailure(res, "invite", e);
342
+ return;
349
343
  }
344
+ var proto = tlsOptions ? "https" : "http";
345
+ var host = req.headers.host || ("localhost:" + portNum);
346
+ var inviteUrl = proto + "://" + host + "/invite/" + invite.code;
347
+ smtp.sendInviteEmail(data.email, inviteUrl, mu.displayName || mu.username).then(function () {
348
+ res.writeHead(200, { "Content-Type": "application/json" });
349
+ res.end(JSON.stringify({ ok: true, invite: invite, url: inviteUrl }));
350
+ }).catch(function (err) {
351
+ res.writeHead(500, { "Content-Type": "application/json" });
352
+ res.end(JSON.stringify({ error: "Failed to send email: " + (err.message || "unknown error") }));
353
+ });
350
354
  });
351
355
  return true;
352
356
  }
@@ -378,28 +382,30 @@ function attachAdmin(ctx) {
378
382
  res.end('{"error":"Admin access required"}');
379
383
  return true;
380
384
  }
381
- var body = "";
382
- req.on("data", function (chunk) { body += chunk; });
383
- req.on("end", function () {
384
- try {
385
- var data = JSON.parse(body);
386
- // Allow clearing SMTP config by sending empty fields
387
- if (!data.host && !data.user && !data.pass && !data.from) {
385
+ readJsonObjectBody(req, res, function (data) {
386
+ // Allow clearing SMTP config by sending empty fields
387
+ if (!data.host && !data.user && !data.pass && !data.from) {
388
+ try {
388
389
  smtp.saveSmtpConfig(null);
389
390
  audit.log("settings.smtp.update", {
390
391
  actorId: mu.id,
391
392
  actorName: mu.username,
392
393
  metadata: { cleared: true },
393
394
  });
394
- res.writeHead(200, { "Content-Type": "application/json" });
395
- res.end('{"ok":true}');
396
- return;
397
- }
398
- if (!data.host || !data.user || !data.pass || !data.from) {
399
- res.writeHead(400, { "Content-Type": "application/json" });
400
- res.end('{"error":"Host, user, password, and from address are required"}');
395
+ } catch (e) {
396
+ respondPersistFailure(res, "smtp config", e);
401
397
  return;
402
398
  }
399
+ res.writeHead(200, { "Content-Type": "application/json" });
400
+ res.end('{"ok":true}');
401
+ return;
402
+ }
403
+ if (!data.host || !data.user || !data.pass || !data.from) {
404
+ res.writeHead(400, { "Content-Type": "application/json" });
405
+ res.end('{"error":"Host, user, password, and from address are required"}');
406
+ return;
407
+ }
408
+ try {
403
409
  // If password is masked, keep existing
404
410
  var existingCfg = smtp.getSmtpConfig();
405
411
  var pass = data.pass;
@@ -421,12 +427,12 @@ function attachAdmin(ctx) {
421
427
  // Log field names only — never log host credentials, passwords, or secrets.
422
428
  metadata: { fieldsUpdated: ["host", "port", "secure", "user", "from", "emailLoginEnabled"] },
423
429
  });
424
- res.writeHead(200, { "Content-Type": "application/json" });
425
- res.end('{"ok":true}');
426
430
  } catch (e) {
427
- res.writeHead(400, { "Content-Type": "application/json" });
428
- res.end('{"error":"Invalid request"}');
431
+ respondPersistFailure(res, "smtp config", e);
432
+ return;
429
433
  }
434
+ res.writeHead(200, { "Content-Type": "application/json" });
435
+ res.end('{"ok":true}');
430
436
  });
431
437
  return true;
432
438
  }
@@ -439,42 +445,41 @@ function attachAdmin(ctx) {
439
445
  res.end('{"error":"Admin access required"}');
440
446
  return true;
441
447
  }
442
- var body = "";
443
- req.on("data", function (chunk) { body += chunk; });
444
- req.on("end", function () {
448
+ readJsonObjectBody(req, res, function (data) {
449
+ // Use provided config or fall back to saved
450
+ var existingCfg;
445
451
  try {
446
- var data = JSON.parse(body);
447
- // Use provided config or fall back to saved
448
- var existingCfg = smtp.getSmtpConfig();
449
- var pass = data.pass;
450
- if (pass === "••••••••" && existingCfg) {
451
- pass = existingCfg.pass;
452
- }
453
- var cfg = {
454
- host: data.host || (existingCfg && existingCfg.host),
455
- port: parseInt(data.port, 10) || (existingCfg && existingCfg.port) || 587,
456
- secure: data.secure !== undefined ? !!data.secure : (existingCfg && !!existingCfg.secure),
457
- user: data.user || (existingCfg && existingCfg.user),
458
- pass: pass || (existingCfg && existingCfg.pass),
459
- from: data.from || (existingCfg && existingCfg.from),
460
- };
461
- if (!cfg.host || !cfg.user || !cfg.pass || !cfg.from) {
462
- res.writeHead(400, { "Content-Type": "application/json" });
463
- res.end('{"error":"SMTP configuration is incomplete"}');
464
- return;
465
- }
466
- var testTo = mu.email || cfg.from;
467
- smtp.sendTestEmail(cfg, testTo).then(function (result) {
468
- res.writeHead(200, { "Content-Type": "application/json" });
469
- res.end(JSON.stringify({ ok: true, message: "Test email sent to " + testTo }));
470
- }).catch(function (err) {
471
- res.writeHead(500, { "Content-Type": "application/json" });
472
- res.end(JSON.stringify({ ok: false, error: err.message || "Connection failed" }));
473
- });
452
+ existingCfg = smtp.getSmtpConfig();
474
453
  } catch (e) {
454
+ respondPersistFailure(res, "smtp config read", e);
455
+ return;
456
+ }
457
+ var pass = data.pass;
458
+ if (pass === "••••••••" && existingCfg) {
459
+ pass = existingCfg.pass;
460
+ }
461
+ var cfg = {
462
+ host: data.host || (existingCfg && existingCfg.host),
463
+ port: parseInt(data.port, 10) || (existingCfg && existingCfg.port) || 587,
464
+ secure: data.secure !== undefined ? !!data.secure : (existingCfg && !!existingCfg.secure),
465
+ user: data.user || (existingCfg && existingCfg.user),
466
+ pass: pass || (existingCfg && existingCfg.pass),
467
+ from: data.from || (existingCfg && existingCfg.from),
468
+ };
469
+ if (!cfg.host || !cfg.user || !cfg.pass || !cfg.from) {
475
470
  res.writeHead(400, { "Content-Type": "application/json" });
476
- res.end('{"error":"Invalid request"}');
471
+ res.end('{"error":"SMTP configuration is incomplete"}');
472
+ return;
477
473
  }
474
+ var testTo = mu.email || cfg.from;
475
+ // A failed test send is an external call, not persistence: it keeps its own answer.
476
+ smtp.sendTestEmail(cfg, testTo).then(function (result) {
477
+ res.writeHead(200, { "Content-Type": "application/json" });
478
+ res.end(JSON.stringify({ ok: true, message: "Test email sent to " + testTo }));
479
+ }).catch(function (err) {
480
+ res.writeHead(500, { "Content-Type": "application/json" });
481
+ res.end(JSON.stringify({ ok: false, error: err.message || "Connection failed" }));
482
+ });
478
483
  });
479
484
  return true;
480
485
  }
@@ -498,33 +503,31 @@ function attachAdmin(ctx) {
498
503
  res.end('{"error":"Worktree projects inherit parent visibility"}');
499
504
  return true;
500
505
  }
501
- var body = "";
502
- req.on("data", function (chunk) { body += chunk; });
503
- req.on("end", function () {
506
+ readJsonObjectBody(req, res, function (data) {
507
+ if (data.visibility !== "public" && data.visibility !== "private") {
508
+ res.writeHead(400, { "Content-Type": "application/json" });
509
+ res.end('{"error":"Visibility must be public or private"}');
510
+ return;
511
+ }
512
+ if (!onSetProjectVisibility) {
513
+ res.writeHead(500, { "Content-Type": "application/json" });
514
+ res.end('{"error":"Visibility handler not configured"}');
515
+ return;
516
+ }
517
+ var result;
504
518
  try {
505
- var data = JSON.parse(body);
506
- if (data.visibility !== "public" && data.visibility !== "private") {
507
- res.writeHead(400, { "Content-Type": "application/json" });
508
- res.end('{"error":"Visibility must be public or private"}');
509
- return;
510
- }
511
- if (!onSetProjectVisibility) {
512
- res.writeHead(500, { "Content-Type": "application/json" });
513
- res.end('{"error":"Visibility handler not configured"}');
514
- return;
515
- }
516
- var result = onSetProjectVisibility(projSlug, data.visibility);
517
- if (result && result.error) {
518
- res.writeHead(404, { "Content-Type": "application/json" });
519
- res.end(JSON.stringify({ error: result.error }));
520
- return;
521
- }
522
- res.writeHead(200, { "Content-Type": "application/json" });
523
- res.end('{"ok":true}');
519
+ result = onSetProjectVisibility(projSlug, data.visibility);
524
520
  } catch (e) {
525
- res.writeHead(400, { "Content-Type": "application/json" });
526
- res.end('{"error":"Invalid request"}');
521
+ respondPersistFailure(res, "project visibility", e);
522
+ return;
527
523
  }
524
+ if (result && result.error) {
525
+ res.writeHead(404, { "Content-Type": "application/json" });
526
+ res.end(JSON.stringify({ error: result.error }));
527
+ return;
528
+ }
529
+ res.writeHead(200, { "Content-Type": "application/json" });
530
+ res.end('{"ok":true}');
528
531
  });
529
532
  return true;
530
533
  }
@@ -543,18 +546,15 @@ function attachAdmin(ctx) {
543
546
  res.end('{"error":"Worktree projects inherit parent settings"}');
544
547
  return true;
545
548
  }
546
- var body = "";
547
- req.on("data", function (chunk) { body += chunk; });
548
- req.on("end", function () {
549
+ readJsonObjectBody(req, res, function (data) {
550
+ var targetCtx = projects.get(projSlug);
551
+ if (!targetCtx) {
552
+ res.writeHead(404, { "Content-Type": "application/json" });
553
+ res.end('{"error":"Project not found"}');
554
+ return;
555
+ }
556
+ var ownerId = data.userId || null;
549
557
  try {
550
- var data = JSON.parse(body);
551
- var targetCtx = projects.get(projSlug);
552
- if (!targetCtx) {
553
- res.writeHead(404, { "Content-Type": "application/json" });
554
- res.end('{"error":"Project not found"}');
555
- return;
556
- }
557
- var ownerId = data.userId || null;
558
558
  targetCtx.setProjectOwner(ownerId);
559
559
  if (onProjectOwnerChanged) {
560
560
  onProjectOwnerChanged(projSlug, ownerId);
@@ -566,12 +566,12 @@ function attachAdmin(ctx) {
566
566
  ownerName = ownerUser ? (ownerUser.displayName || ownerUser.username) : ownerId;
567
567
  }
568
568
  targetCtx.send({ type: "project_owner_changed", ownerId: ownerId, ownerName: ownerName });
569
- res.writeHead(200, { "Content-Type": "application/json" });
570
- res.end('{"ok":true}');
571
569
  } catch (e) {
572
- res.writeHead(400, { "Content-Type": "application/json" });
573
- res.end('{"error":"Invalid request"}');
570
+ respondPersistFailure(res, "project owner", e);
571
+ return;
574
572
  }
573
+ res.writeHead(200, { "Content-Type": "application/json" });
574
+ res.end('{"ok":true}');
575
575
  });
576
576
  return true;
577
577
  }
@@ -593,33 +593,31 @@ function attachAdmin(ctx) {
593
593
  res.end('{"error":"Worktree projects inherit parent settings"}');
594
594
  return true;
595
595
  }
596
- var body = "";
597
- req.on("data", function (chunk) { body += chunk; });
598
- req.on("end", function () {
596
+ readJsonObjectBody(req, res, function (data) {
597
+ if (!Array.isArray(data.allowedUsers)) {
598
+ res.writeHead(400, { "Content-Type": "application/json" });
599
+ res.end('{"error":"allowedUsers must be an array"}');
600
+ return;
601
+ }
602
+ if (!onSetProjectAllowedUsers) {
603
+ res.writeHead(500, { "Content-Type": "application/json" });
604
+ res.end('{"error":"AllowedUsers handler not configured"}');
605
+ return;
606
+ }
607
+ var result;
599
608
  try {
600
- var data = JSON.parse(body);
601
- if (!Array.isArray(data.allowedUsers)) {
602
- res.writeHead(400, { "Content-Type": "application/json" });
603
- res.end('{"error":"allowedUsers must be an array"}');
604
- return;
605
- }
606
- if (!onSetProjectAllowedUsers) {
607
- res.writeHead(500, { "Content-Type": "application/json" });
608
- res.end('{"error":"AllowedUsers handler not configured"}');
609
- return;
610
- }
611
- var result = onSetProjectAllowedUsers(projSlug, data.allowedUsers);
612
- if (result && result.error) {
613
- res.writeHead(404, { "Content-Type": "application/json" });
614
- res.end(JSON.stringify({ error: result.error }));
615
- return;
616
- }
617
- res.writeHead(200, { "Content-Type": "application/json" });
618
- res.end('{"ok":true}');
609
+ result = onSetProjectAllowedUsers(projSlug, data.allowedUsers);
619
610
  } catch (e) {
620
- res.writeHead(400, { "Content-Type": "application/json" });
621
- res.end('{"error":"Invalid request"}');
611
+ respondPersistFailure(res, "project allowed users", e);
612
+ return;
613
+ }
614
+ if (result && result.error) {
615
+ res.writeHead(404, { "Content-Type": "application/json" });
616
+ res.end(JSON.stringify({ error: result.error }));
617
+ return;
622
618
  }
619
+ res.writeHead(200, { "Content-Type": "application/json" });
620
+ res.end('{"ok":true}');
623
621
  });
624
622
  return true;
625
623
  }
@@ -1,6 +1,8 @@
1
1
  var crypto = require("crypto");
2
2
  var fs = require("fs");
3
3
  var path = require("path");
4
+ var { DEFAULT_AVATAR_COLOR } = require("./default-avatar-color");
5
+ var themeSeed = require("./theme-seed");
4
6
  var { CONFIG_DIR } = require("./config");
5
7
  var _isDevMode = require("./config").isDevMode;
6
8
  var store = require("./store");
@@ -279,19 +281,20 @@ function attachAuth(ctx) {
279
281
  return '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">'
280
282
  + '<title>Admin Password Recovery</title>'
281
283
  + '<style>'
284
+ + themeSeed.systemVarsCss()
282
285
  + '*{margin:0;padding:0;box-sizing:border-box}'
283
- + 'body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;background:#0a0a0a;color:#e5e5e5;display:flex;align-items:center;justify-content:center;min-height:100vh}'
284
- + '.card{background:#171717;border:1px solid #262626;border-radius:12px;padding:32px;width:100%;max-width:380px}'
286
+ + 'body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;background:var(--bg);color:var(--text-secondary);display:flex;align-items:center;justify-content:center;min-height:100vh}'
287
+ + '.card{background:var(--bg-alt);border:1px solid var(--border);border-radius:12px;padding:32px;width:100%;max-width:380px}'
285
288
  + 'h1{font-size:18px;font-weight:600;margin-bottom:4px}'
286
- + '.sub{font-size:13px;color:#737373;margin-bottom:24px}'
287
- + 'label{display:block;font-size:13px;color:#a3a3a3;margin-bottom:6px}'
288
- + 'input{width:100%;padding:10px 12px;background:#0a0a0a;border:1px solid #333;border-radius:8px;color:#e5e5e5;font-size:14px;outline:none;margin-bottom:16px}'
289
- + 'input:focus{border-color:#7c3aed}'
290
- + 'button{width:100%;padding:10px;background:#7c3aed;color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}'
291
- + 'button:hover{background:#6d28d9}'
289
+ + '.sub{font-size:13px;color:var(--text-muted);margin-bottom:24px}'
290
+ + 'label{display:block;font-size:13px;color:var(--text-muted);margin-bottom:6px}'
291
+ + 'input{width:100%;padding:10px 12px;background:var(--input-bg);border:1px solid var(--border-strong);border-radius:8px;color:var(--text);font-size:14px;outline:none;margin-bottom:16px}'
292
+ + 'input:focus{border-color:var(--accent)}'
293
+ + 'button{width:100%;padding:10px;background:var(--accent);color:var(--on-accent);border:none;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer}'
294
+ + 'button:hover{background:var(--accent-hover)}'
292
295
  + 'button:disabled{opacity:.5;cursor:not-allowed}'
293
- + '.error{color:#ef4444;font-size:13px;margin-bottom:12px;display:none}'
294
- + '.success{text-align:center;color:#22c55e;font-size:15px}'
296
+ + '.error{color:var(--error);font-size:13px;margin-bottom:12px;display:none}'
297
+ + '.success{text-align:center;color:var(--success);font-size:15px}'
295
298
  + '.hidden{display:none}'
296
299
  + '</style></head><body>'
297
300
  + '<div class="card">'
@@ -463,7 +466,7 @@ function attachAuth(ctx) {
463
466
  adminProfile = {
464
467
  name: data.displayName || data.username,
465
468
  lang: existingProfile.lang || "en-US",
466
- avatarColor: existingProfile.avatarColor || "#7c3aed",
469
+ avatarColor: existingProfile.avatarColor || DEFAULT_AVATAR_COLOR,
467
470
  avatarStyle: existingProfile.avatarStyle || "thumbs",
468
471
  avatarSeed: existingProfile.avatarSeed || crypto.randomBytes(4).toString("hex"),
469
472
  };
@@ -762,8 +765,8 @@ function attachAuth(ctx) {
762
765
  if (!validation.valid) {
763
766
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
764
767
  res.end('<!DOCTYPE html><html><head><title>Clagentic: Console</title>' +
765
- '<style>body{background:#2F2E2B;color:#E8E5DE;font-family:system-ui;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0}' +
766
- '.c{text-align:center;max-width:360px;padding:20px}h1{color:#DA7756;margin-bottom:16px}p{color:#908B81}</style></head>' +
768
+ '<style>' + themeSeed.systemVarsCss() + 'body{background:var(--bg);color:var(--text);font-family:system-ui;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0}' +
769
+ '.c{text-align:center;max-width:360px;padding:20px}h1{color:var(--accent);margin-bottom:16px}p{color:var(--text-muted)}</style></head>' +
767
770
  '<body><div class="c"><h1>Clagentic: Console</h1><p>' + (validation.error === "Invite expired" ? "This invite link has expired." : validation.error === "Invite already used" ? "This invite link has already been used." : "Invalid invite link.") + '</p></div></body></html>');
768
771
  return true;
769
772
  }
package/lib/server-dm.js CHANGED
@@ -1,4 +1,5 @@
1
1
  var { notifyFor } = require("./notify");
2
+ var { DEFAULT_AVATAR_COLOR } = require("./default-avatar-color");
2
3
 
3
4
  // Strict allow-list for client-supplied dmKey values.
4
5
  // Accepts exactly two segments separated by a single colon, each containing
@@ -33,7 +34,7 @@ function attachDm(ctx) {
33
34
  username: otherUser.username,
34
35
  avatarStyle: p.avatarStyle || "thumbs",
35
36
  avatarSeed: p.avatarSeed || otherUser.username,
36
- avatarColor: p.avatarColor || "#7c3aed",
37
+ avatarColor: p.avatarColor || DEFAULT_AVATAR_COLOR,
37
38
  avatarCustom: p.avatarCustom || "",
38
39
  };
39
40
  }
@@ -58,7 +59,7 @@ function attachDm(ctx) {
58
59
  username: targetUser.username,
59
60
  avatarStyle: tp.avatarStyle || "thumbs",
60
61
  avatarSeed: tp.avatarSeed || targetUser.username,
61
- avatarColor: tp.avatarColor || "#7c3aed",
62
+ avatarColor: tp.avatarColor || DEFAULT_AVATAR_COLOR,
62
63
  avatarCustom: tp.avatarCustom || "",
63
64
  } : null,
64
65
  }));
@@ -138,7 +139,7 @@ function attachDm(ctx) {
138
139
  role: u.role,
139
140
  avatarStyle: p.avatarStyle || "thumbs",
140
141
  avatarSeed: p.avatarSeed || u.username,
141
- avatarColor: p.avatarColor || "#7c3aed",
142
+ avatarColor: p.avatarColor || DEFAULT_AVATAR_COLOR,
142
143
  avatarCustom: p.avatarCustom || "",
143
144
  };
144
145
  });