@clagentic/console 1.12.0-beta.3 → 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
@@ -1,7 +1,17 @@
1
1
  var fs = require("fs");
2
2
  var path = require("path");
3
+ var { DEFAULT_AVATAR_COLOR } = require("./default-avatar-color");
3
4
  var audit = require("./audit");
4
5
  var projectModule = require("./project");
6
+ var isValidThemeId = require("./theme-files").isValidThemeId;
7
+ var chatWidthModule = require("./chat-width");
8
+ var isChatWidth = chatWidthModule.isChatWidth;
9
+ var DEFAULT_CHAT_WIDTH = chatWidthModule.DEFAULT_CHAT_WIDTH;
10
+ var sessionListAvatarsModule = require("./session-list-avatars");
11
+ var isSessionListAvatars = sessionListAvatarsModule.isSessionListAvatars;
12
+ var requestBody = require("./request-body");
13
+ var readJsonObjectBody = requestBody.readJsonObjectBody;
14
+ var respondPersistFailure = requestBody.respondPersistFailure;
5
15
 
6
16
  // Action-string convention (see lib/audit.js and lib/server-admin.js):
7
17
  // "resource.verb", dot-separated. Logged on BOTH success and failure paths
@@ -41,6 +51,22 @@ function attachSettings(ctx) {
41
51
 
42
52
  var profilePath = path.join(CONFIG_DIR, "profile.json");
43
53
 
54
+ // The width a user with no saved choice gets: the daemon's `chatWidth` setting
55
+ // (`clagentic-console settings`), else the built-in default.
56
+ function serverDefaultChatWidth() {
57
+ var daemonConfig = opts && typeof opts.onGetDaemonConfig === "function" ? opts.onGetDaemonConfig() : null;
58
+ return daemonConfig && isChatWidth(daemonConfig.chatWidth) ? daemonConfig.chatWidth : DEFAULT_CHAT_WIDTH;
59
+ }
60
+
61
+ // What a user with no saved choice gets for "Avatars in session list": the
62
+ // daemon's `sessionListAvatars` setting, else on.
63
+ function serverDefaultSessionListAvatars() {
64
+ var daemonConfig = opts && typeof opts.onGetDaemonConfig === "function" ? opts.onGetDaemonConfig() : null;
65
+ return daemonConfig && isSessionListAvatars(daemonConfig.sessionListAvatars)
66
+ ? daemonConfig.sessionListAvatars
67
+ : sessionListAvatarsModule.DEFAULT_SESSION_LIST_AVATARS;
68
+ }
69
+
44
70
  function handleRequest(req, res, fullUrl) {
45
71
  // GET /api/profile
46
72
  if (req.method === "GET" && fullUrl === "/api/profile") {
@@ -50,15 +76,16 @@ function attachSettings(ctx) {
50
76
  res.end('{"error":"unauthorized"}');
51
77
  return true;
52
78
  }
53
- var profile = mu.profile || { name: "", lang: "en-US", avatarColor: "#7c3aed", avatarStyle: "thumbs", avatarSeed: "", avatarCustom: "" };
79
+ var profile = mu.profile || { name: "", lang: "en-US", avatarColor: DEFAULT_AVATAR_COLOR, avatarStyle: "thumbs", avatarSeed: "", avatarCustom: "" };
54
80
  profile.username = mu.username;
55
81
  profile.userId = mu.id;
56
82
  profile.role = mu.role;
57
83
  profile.pinEnabled = !!mu.pinHash;
58
84
  profile.autoContinueOnRateLimit = !!mu.autoContinueOnRateLimit;
59
- profile.chatLayout = mu.chatLayout || "channel";
85
+ profile.chatWidth = isChatWidth(mu.chatWidth) ? mu.chatWidth : serverDefaultChatWidth();
86
+ profile.sessionListAvatars = isSessionListAvatars(mu.sessionListAvatars) ? mu.sessionListAvatars : serverDefaultSessionListAvatars();
60
87
  profile.themeMode = mu.themeMode || null;
61
- profile.themeBrand = mu.themeBrand || null;
88
+ profile.themeId = isValidThemeId(mu.themeId) ? mu.themeId : null;
62
89
  res.writeHead(200, { "Content-Type": "application/json" });
63
90
  res.end(JSON.stringify(profile));
64
91
  return true;
@@ -66,38 +93,35 @@ function attachSettings(ctx) {
66
93
 
67
94
  // PUT /api/profile
68
95
  if (req.method === "PUT" && fullUrl === "/api/profile") {
69
- var body = "";
70
- req.on("data", function (chunk) { body += chunk; });
71
- req.on("end", function () {
96
+ readJsonObjectBody(req, res, function (data) {
97
+ var profile = {};
98
+ if (typeof data.name === "string") profile.name = data.name.substring(0, 50);
99
+ if (typeof data.lang === "string") profile.lang = data.lang.substring(0, 10);
100
+ if (typeof data.avatarColor === "string" && /^#[0-9a-fA-F]{6}$/.test(data.avatarColor)) {
101
+ profile.avatarColor = data.avatarColor;
102
+ }
103
+ if (typeof data.avatarStyle === "string") profile.avatarStyle = data.avatarStyle.substring(0, 30);
104
+ if (typeof data.avatarSeed === "string") profile.avatarSeed = data.avatarSeed.substring(0, 30);
105
+ if (typeof data.avatarCustom === "string") profile.avatarCustom = data.avatarCustom;
106
+ if (data.avatarCustom === null || data.avatarCustom === "") profile.avatarCustom = undefined;
107
+ var mu = getMultiUserFromReq(req);
108
+ if (!mu) {
109
+ res.writeHead(401, { "Content-Type": "application/json" });
110
+ res.end('{"error":"unauthorized"}');
111
+ return;
112
+ }
72
113
  try {
73
- var data = JSON.parse(body);
74
- var profile = {};
75
- if (typeof data.name === "string") profile.name = data.name.substring(0, 50);
76
- if (typeof data.lang === "string") profile.lang = data.lang.substring(0, 10);
77
- if (typeof data.avatarColor === "string" && /^#[0-9a-fA-F]{6}$/.test(data.avatarColor)) {
78
- profile.avatarColor = data.avatarColor;
79
- }
80
- if (typeof data.avatarStyle === "string") profile.avatarStyle = data.avatarStyle.substring(0, 30);
81
- if (typeof data.avatarSeed === "string") profile.avatarSeed = data.avatarSeed.substring(0, 30);
82
- if (typeof data.avatarCustom === "string") profile.avatarCustom = data.avatarCustom;
83
- if (data.avatarCustom === null || data.avatarCustom === "") profile.avatarCustom = undefined;
84
- var mu = getMultiUserFromReq(req);
85
- if (!mu) {
86
- res.writeHead(401, { "Content-Type": "application/json" });
87
- res.end('{"error":"unauthorized"}');
88
- return;
89
- }
90
114
  users.updateUserProfile(mu.id, profile);
91
115
  // Broadcast updated avatar/presence to all projects
92
116
  projects.forEach(function (pCtx) {
93
117
  pCtx.refreshUserProfile(mu.id);
94
118
  });
95
- res.writeHead(200, { "Content-Type": "application/json" });
96
- res.end(JSON.stringify(profile));
97
119
  } catch (e) {
98
- res.writeHead(400, { "Content-Type": "application/json" });
99
- res.end(JSON.stringify({ error: "Invalid request" }));
120
+ respondPersistFailure(res, "profile", e);
121
+ return;
100
122
  }
123
+ res.writeHead(200, { "Content-Type": "application/json" });
124
+ res.end(JSON.stringify(profile));
101
125
  });
102
126
  return true;
103
127
  }
@@ -198,45 +222,50 @@ function attachSettings(ctx) {
198
222
  res.end('{"error":"unauthorized"}');
199
223
  return true;
200
224
  }
201
- var body = "";
202
- req.on("data", function (chunk) { body += chunk; });
203
- req.on("end", function () {
204
- try {
205
- var data = JSON.parse(body);
206
- if (!data.newPin || typeof data.newPin !== "string" || !/^\d{6}$/.test(data.newPin)) {
225
+ readJsonObjectBody(req, res, function (data) {
226
+ if (!data.newPin || typeof data.newPin !== "string" || !/^\d{6}$/.test(data.newPin)) {
227
+ res.writeHead(400, { "Content-Type": "application/json" });
228
+ res.end('{"error":"PIN must be exactly 6 digits"}');
229
+ return;
230
+ }
231
+ // Forced PIN change after temporary PIN login: skip currentPin
232
+ // verification. The user authenticated with the temp PIN to
233
+ // establish this session, so requiring them to re-enter it adds
234
+ // friction without security benefit. The session cookie is the
235
+ // proof of possession.
236
+ if (mu.pinHash && !mu.mustChangePin) {
237
+ if (!data.currentPin || typeof data.currentPin !== "string" || !/^\d{6}$/.test(data.currentPin)) {
207
238
  res.writeHead(400, { "Content-Type": "application/json" });
208
- res.end('{"error":"PIN must be exactly 6 digits"}');
239
+ res.end('{"error":"Current PIN is required"}');
209
240
  return;
210
241
  }
211
- // Forced PIN change after temporary PIN login: skip currentPin
212
- // verification. The user authenticated with the temp PIN to
213
- // establish this session, so requiring them to re-enter it adds
214
- // friction without security benefit. The session cookie is the
215
- // proof of possession.
216
- if (mu.pinHash && !mu.mustChangePin) {
217
- if (!data.currentPin || typeof data.currentPin !== "string" || !/^\d{6}$/.test(data.currentPin)) {
218
- res.writeHead(400, { "Content-Type": "application/json" });
219
- res.end('{"error":"Current PIN is required"}');
220
- return;
221
- }
222
- if (!users.verifyPin(data.currentPin, mu.pinHash)) {
223
- res.writeHead(400, { "Content-Type": "application/json" });
224
- res.end('{"error":"Current PIN is incorrect"}');
225
- return;
226
- }
242
+ var pinMatches;
243
+ try {
244
+ pinMatches = users.verifyPin(data.currentPin, mu.pinHash);
245
+ } catch (e) {
246
+ respondPersistFailure(res, "pin", e);
247
+ return;
227
248
  }
228
- var result = users.updateUserPin(mu.id, data.newPin);
229
- if (result.error) {
249
+ if (!pinMatches) {
230
250
  res.writeHead(400, { "Content-Type": "application/json" });
231
- res.end(JSON.stringify({ error: result.error }));
251
+ res.end('{"error":"Current PIN is incorrect"}');
232
252
  return;
233
253
  }
234
- res.writeHead(200, { "Content-Type": "application/json" });
235
- res.end('{"ok":true}');
254
+ }
255
+ var result;
256
+ try {
257
+ result = users.updateUserPin(mu.id, data.newPin);
236
258
  } catch (e) {
259
+ respondPersistFailure(res, "pin", e);
260
+ return;
261
+ }
262
+ if (result.error) {
237
263
  res.writeHead(400, { "Content-Type": "application/json" });
238
- res.end('{"error":"Invalid request"}');
264
+ res.end(JSON.stringify({ error: result.error }));
265
+ return;
239
266
  }
267
+ res.writeHead(200, { "Content-Type": "application/json" });
268
+ res.end('{"ok":true}');
240
269
  });
241
270
  return true;
242
271
  }
@@ -249,52 +278,75 @@ function attachSettings(ctx) {
249
278
  res.end('{"error":"unauthorized"}');
250
279
  return true;
251
280
  }
252
- var body = "";
253
- req.on("data", function (chunk) { body += chunk; });
254
- req.on("end", function () {
281
+ readJsonObjectBody(req, res, function (data) {
282
+ var result;
255
283
  try {
256
- var data = JSON.parse(body);
257
- var result = users.setAutoContinue(mu.id, !!data.enabled);
258
- if (result.error) {
259
- res.writeHead(400, { "Content-Type": "application/json" });
260
- res.end(JSON.stringify({ error: result.error }));
261
- return;
262
- }
263
- res.writeHead(200, { "Content-Type": "application/json" });
264
- res.end(JSON.stringify({ ok: true, autoContinueOnRateLimit: result.autoContinueOnRateLimit }));
284
+ result = users.setAutoContinue(mu.id, !!data.enabled);
265
285
  } catch (e) {
286
+ respondPersistFailure(res, "auto-continue", e);
287
+ return;
288
+ }
289
+ if (result.error) {
266
290
  res.writeHead(400, { "Content-Type": "application/json" });
267
- res.end('{"error":"Invalid request"}');
291
+ res.end(JSON.stringify({ error: result.error }));
292
+ return;
268
293
  }
294
+ res.writeHead(200, { "Content-Type": "application/json" });
295
+ res.end(JSON.stringify({ ok: true, autoContinueOnRateLimit: result.autoContinueOnRateLimit }));
269
296
  });
270
297
  return true;
271
298
  }
272
299
 
273
- // PUT /api/user/chat-layout
274
- if (req.method === "PUT" && fullUrl === "/api/user/chat-layout") {
300
+ // PUT /api/user/chat-width
301
+ if (req.method === "PUT" && fullUrl === "/api/user/chat-width") {
275
302
  var mu = getMultiUserFromReq(req);
276
303
  if (!mu) {
277
304
  res.writeHead(401, { "Content-Type": "application/json" });
278
305
  res.end('{"error":"unauthorized"}');
279
306
  return true;
280
307
  }
281
- var body = "";
282
- req.on("data", function (chunk) { body += chunk; });
283
- req.on("end", function () {
308
+ readJsonObjectBody(req, res, function (data) {
309
+ var result;
284
310
  try {
285
- var data = JSON.parse(body);
286
- var result = users.setChatLayout(mu.id, data.layout);
287
- if (result.error) {
288
- res.writeHead(400, { "Content-Type": "application/json" });
289
- res.end(JSON.stringify({ error: result.error }));
290
- return;
291
- }
292
- res.writeHead(200, { "Content-Type": "application/json" });
293
- res.end(JSON.stringify({ ok: true, chatLayout: result.chatLayout }));
311
+ result = users.setChatWidth(mu.id, data.chatWidth);
294
312
  } catch (e) {
313
+ respondPersistFailure(res, "chat-width", e);
314
+ return;
315
+ }
316
+ if (result.error) {
295
317
  res.writeHead(400, { "Content-Type": "application/json" });
296
- res.end('{"error":"Invalid request"}');
318
+ res.end(JSON.stringify({ error: result.error }));
319
+ return;
320
+ }
321
+ res.writeHead(200, { "Content-Type": "application/json" });
322
+ res.end(JSON.stringify({ ok: true, chatWidth: result.chatWidth }));
323
+ });
324
+ return true;
325
+ }
326
+
327
+ // PUT /api/user/session-list-avatars
328
+ if (req.method === "PUT" && fullUrl === "/api/user/session-list-avatars") {
329
+ var mu = getMultiUserFromReq(req);
330
+ if (!mu) {
331
+ res.writeHead(401, { "Content-Type": "application/json" });
332
+ res.end('{"error":"unauthorized"}');
333
+ return true;
334
+ }
335
+ readJsonObjectBody(req, res, function (data) {
336
+ var result;
337
+ try {
338
+ result = users.setSessionListAvatars(mu.id, data.sessionListAvatars);
339
+ } catch (e) {
340
+ respondPersistFailure(res, "session-list-avatars", e);
341
+ return;
342
+ }
343
+ if (result.error) {
344
+ res.writeHead(400, { "Content-Type": "application/json" });
345
+ res.end(JSON.stringify({ error: result.error }));
346
+ return;
297
347
  }
348
+ res.writeHead(200, { "Content-Type": "application/json" });
349
+ res.end(JSON.stringify({ ok: true, sessionListAvatars: result.sessionListAvatars }));
298
350
  });
299
351
  return true;
300
352
  }
@@ -307,54 +359,54 @@ function attachSettings(ctx) {
307
359
  res.end('{"error":"unauthorized"}');
308
360
  return true;
309
361
  }
310
- var body = "";
311
- req.on("data", function (chunk) { body += chunk; });
312
- req.on("end", function () {
362
+ readJsonObjectBody(req, res, function (data) {
363
+ var mode = (data.themeMode === "light" || data.themeMode === "dark") ? data.themeMode : null;
364
+ var result;
313
365
  try {
314
- var data = JSON.parse(body);
315
- var mode = (data.themeMode === "light" || data.themeMode === "dark") ? data.themeMode : null;
316
- var result = users.setThemeMode(mu.id, mode);
317
- if (result.error) {
318
- res.writeHead(400, { "Content-Type": "application/json" });
319
- res.end(JSON.stringify({ error: result.error }));
320
- return;
321
- }
322
- res.writeHead(200, { "Content-Type": "application/json" });
323
- res.end(JSON.stringify({ ok: true, themeMode: result.themeMode }));
366
+ result = users.setThemeMode(mu.id, mode);
324
367
  } catch (e) {
368
+ respondPersistFailure(res, "theme-mode", e);
369
+ return;
370
+ }
371
+ if (result.error) {
325
372
  res.writeHead(400, { "Content-Type": "application/json" });
326
- res.end('{"error":"Invalid request"}');
373
+ res.end(JSON.stringify({ error: result.error }));
374
+ return;
327
375
  }
376
+ res.writeHead(200, { "Content-Type": "application/json" });
377
+ res.end(JSON.stringify({ ok: true, themeMode: result.themeMode }));
328
378
  });
329
379
  return true;
330
380
  }
331
381
 
332
- // PUT /api/user/theme-brand
333
- if (req.method === "PUT" && fullUrl === "/api/user/theme-brand") {
382
+ // PUT /api/user/theme-id (a custom theme file's id, or null to clear it)
383
+ if (req.method === "PUT" && fullUrl === "/api/user/theme-id") {
334
384
  var mu = getMultiUserFromReq(req);
335
385
  if (!mu) {
336
386
  res.writeHead(401, { "Content-Type": "application/json" });
337
387
  res.end('{"error":"unauthorized"}');
338
388
  return true;
339
389
  }
340
- var body = "";
341
- req.on("data", function (chunk) { body += chunk; });
342
- req.on("end", function () {
390
+ readJsonObjectBody(req, res, function (data) {
391
+ if (data.themeId !== null && !isValidThemeId(data.themeId)) {
392
+ res.writeHead(400, { "Content-Type": "application/json" });
393
+ res.end('{"error":"Invalid theme id"}');
394
+ return;
395
+ }
396
+ var result;
343
397
  try {
344
- var data = JSON.parse(body);
345
- var brand = (data.themeBrand === "classic" || data.themeBrand === "clagentic") ? data.themeBrand : null;
346
- var result = users.setThemeBrand(mu.id, brand);
347
- if (result.error) {
348
- res.writeHead(400, { "Content-Type": "application/json" });
349
- res.end(JSON.stringify({ error: result.error }));
350
- return;
351
- }
352
- res.writeHead(200, { "Content-Type": "application/json" });
353
- res.end(JSON.stringify({ ok: true, themeBrand: result.themeBrand }));
398
+ result = users.setThemeId(mu.id, data.themeId);
354
399
  } catch (e) {
400
+ respondPersistFailure(res, "theme-id", e);
401
+ return;
402
+ }
403
+ if (result.error) {
355
404
  res.writeHead(400, { "Content-Type": "application/json" });
356
- res.end('{"error":"Invalid request"}');
405
+ res.end(JSON.stringify({ error: result.error }));
406
+ return;
357
407
  }
408
+ res.writeHead(200, { "Content-Type": "application/json" });
409
+ res.end(JSON.stringify({ ok: true, themeId: result.themeId }));
358
410
  });
359
411
  return true;
360
412
  }
@@ -381,26 +433,21 @@ function attachSettings(ctx) {
381
433
  res.end('{"error":"unauthorized"}');
382
434
  return true;
383
435
  }
384
- var bodyTp = "";
385
- req.on("data", function (chunk) { bodyTp += chunk; });
386
- req.on("end", function () {
436
+ readJsonObjectBody(req, res, function (dataTp) {
437
+ var result;
387
438
  try {
388
- var dataTp = JSON.parse(bodyTp);
389
- var paletteName = dataTp.palette;
390
- var order = dataTp.order;
391
- var hidden = dataTp.hidden;
392
- var result = users.setToolPalette(muPut.id, paletteName, order, hidden);
393
- if (result && result.error) {
394
- res.writeHead(400, { "Content-Type": "application/json" });
395
- res.end(JSON.stringify({ error: result.error }));
396
- return;
397
- }
398
- res.writeHead(200, { "Content-Type": "application/json" });
399
- res.end(JSON.stringify(result));
439
+ result = users.setToolPalette(muPut.id, dataTp.palette, dataTp.order, dataTp.hidden);
400
440
  } catch (e) {
441
+ respondPersistFailure(res, "tool-palettes", e);
442
+ return;
443
+ }
444
+ if (result && result.error) {
401
445
  res.writeHead(400, { "Content-Type": "application/json" });
402
- res.end('{"error":"Invalid request"}');
446
+ res.end(JSON.stringify({ error: result.error }));
447
+ return;
403
448
  }
449
+ res.writeHead(200, { "Content-Type": "application/json" });
450
+ res.end(JSON.stringify(result));
404
451
  });
405
452
  return true;
406
453
  }
package/lib/server.js CHANGED
@@ -1,5 +1,6 @@
1
1
  var http = require("http");
2
2
  var fs = require("fs");
3
+ var { DEFAULT_AVATAR_COLOR } = require("./default-avatar-color");
3
4
  var path = require("path");
4
5
  var { WebSocketServer } = require("ws");
5
6
  var pages = require("./pages");
@@ -26,12 +27,17 @@ var { createProjectAccess } = require("./project-access");
26
27
  var { checkWsOrigin } = require("./ws-origin");
27
28
  var sessionReclaim = require("./session-reclaim");
28
29
  var clientBuildId = require("./client-build-id");
30
+ var themeFiles = require("./theme-files");
31
+ var clientFiles = require("./client-files");
32
+ var themeSeed = require("./theme-seed");
29
33
 
30
34
  var https = require("https");
31
35
  var pkg = require("../package.json");
32
36
 
33
- var publicDir = path.join(__dirname, "public");
34
- var bundledThemesDir = path.join(__dirname, "themes");
37
+ // Client files come from the set this process loaded at startup, never from the
38
+ // install directory at request time (lib/client-files.js).
39
+ var publicFiles = clientFiles.publicFiles;
40
+ var publicDir = publicFiles.root;
35
41
  var userThemesDir = path.join(CONFIG_DIR, "themes");
36
42
 
37
43
  // --- HTTP helpers (used by skills proxy and extension download) ---
@@ -70,16 +76,51 @@ var MIME_TYPES = {
70
76
  ".ico": "image/x-icon",
71
77
  };
72
78
 
79
+ // The first-paint stylesheet is built from the theme files on request, and the
80
+ // manifest takes its colours from them, so neither holds a colour of its own.
81
+ function serveThemed(urlPath, res) {
82
+ var body;
83
+ var mime;
84
+ try {
85
+ if (urlPath === "/theme-seed.css") {
86
+ body = themeSeed.firstPaintCss();
87
+ mime = "text/css";
88
+ } else if (urlPath === "/theme-core.js") {
89
+ body = themeSeed.themeCoreScript();
90
+ mime = "application/javascript";
91
+ } else if (urlPath === "/manifest.json") {
92
+ var manifestSource = publicFiles.read("manifest.json");
93
+ if (!manifestSource) throw new Error("manifest.json was not part of the client files loaded at startup");
94
+ body = themeSeed.stampManifest(manifestSource.toString("utf8"));
95
+ mime = "application/json";
96
+ } else {
97
+ return false;
98
+ }
99
+ } catch (e) {
100
+ // Fall through to normal static serving, but say why the themed route failed.
101
+ console.error("[server] themed route " + urlPath + " failed: " + (e && e.message));
102
+ return false;
103
+ }
104
+ res.writeHead(200, { "Content-Type": mime + "; charset=utf-8", "Cache-Control": "no-cache" });
105
+ res.end(body);
106
+ return true;
107
+ }
108
+
73
109
  function serveStatic(urlPath, res) {
74
110
  if (urlPath === "/") urlPath = "/index.html";
75
111
 
112
+ if (serveThemed(urlPath, res)) return true;
113
+
76
114
  // Special case: stamp the sw.js cache name with the build id at serve time.
77
115
  // The build id, not the package version: consecutive builds can share a
78
116
  // version, and the worker must change bytes on every restart onto a new build.
79
117
  if (urlPath === "/sw.js") {
80
- var swPath = path.join(publicDir, "sw.js");
81
118
  try {
82
- var swContent = clientBuildId.stampServiceWorker(fs.readFileSync(swPath, "utf8"), clientBuildId.get());
119
+ var swSource = publicFiles.read("sw.js");
120
+ if (!swSource) throw new Error("sw.js was not part of the client files loaded at startup");
121
+ var swContent = themeSeed.stampServiceWorker(
122
+ clientBuildId.stampServiceWorker(swSource.toString("utf8"), clientBuildId.get())
123
+ );
83
124
  res.writeHead(200, {
84
125
  "Content-Type": "application/javascript; charset=utf-8",
85
126
  "Cache-Control": "no-cache",
@@ -101,7 +142,8 @@ function serveStatic(urlPath, res) {
101
142
  }
102
143
 
103
144
  try {
104
- var content = fs.readFileSync(filePath);
145
+ var content = publicFiles.read(path.relative(publicDir, filePath).split(path.sep).join("/"));
146
+ if (content === null) return false;
105
147
  var ext = path.extname(filePath);
106
148
  var mime = MIME_TYPES[ext] || "application/octet-stream";
107
149
  var isImage = ext === ".png" || ext === ".jpg" || ext === ".jpeg" || ext === ".gif" || ext === ".svg" || ext === ".webp" || ext === ".ico";
@@ -271,6 +313,8 @@ function createServer(opts) {
271
313
  var onSetPermissionSettings = opts.onSetPermissionSettings || null;
272
314
  var onGetUserShellSettings = opts.onGetUserShellSettings || null;
273
315
  var onSetUserShellSettings = opts.onSetUserShellSettings || null;
316
+ var onGetPromptExpirySettings = opts.onGetPromptExpirySettings || null;
317
+ var onSetPromptExpirySettings = opts.onSetPromptExpirySettings || null;
274
318
  var onGetServerDefaultBetas = opts.onGetServerDefaultBetas || null;
275
319
  var onSetServerDefaultBetas = opts.onSetServerDefaultBetas || null;
276
320
  var onGetProjectDefaultBetas = opts.onGetProjectDefaultBetas || null;
@@ -327,6 +371,23 @@ function createServer(opts) {
327
371
  var isRequestAuthed = auth.isRequestAuthed;
328
372
  var parseCookies = auth.parseCookies;
329
373
 
374
+ // One-time rewrite of stored theme preferences (the retired Classic brand).
375
+ // A no-op, and no write, once every user is migrated.
376
+ try {
377
+ var themeMigration = users.migrateAllThemePrefs();
378
+ if (themeMigration.changed) console.log("[themes] migrated stored theme preferences for " + themeMigration.changed + " user(s)");
379
+ } catch (e) {
380
+ console.error("[themes] theme preference migration failed:", e && e.message);
381
+ }
382
+
383
+ // One-time rewrite of the retired bubble/channel choice into a chat width.
384
+ try {
385
+ var layoutMigration = users.migrateAllChatLayouts();
386
+ if (layoutMigration.changed) console.log("[chat-width] migrated stored chat layout for " + layoutMigration.changed + " user(s)");
387
+ } catch (e) {
388
+ console.error("[chat-width] chat layout migration failed:", e && e.message);
389
+ }
390
+
330
391
  var realVersion = require("../package.json").version;
331
392
  var currentVersion = debug ? "0.0.9" : realVersion;
332
393
 
@@ -464,11 +525,15 @@ function createServer(opts) {
464
525
  // console has seen, and the avatar chosen for it. A change is broadcast as a
465
526
  // content-free nudge; each connection then asks for the roster and gets only
466
527
  // the places in projects it may read (_agentRoster.visibleEntry).
467
- var _agentRosterNotifier = require("./team-traffic-ws").createNotifier({
528
+ var _agentRosterNotifier = require("./agent-roster-ws").createRosterNotifier({
468
529
  broadcast: function (msg) { broadcastAll(msg); },
469
- build: function () { return { type: require("./agent-roster-ws").CHANGED }; },
470
530
  });
531
+ // The vendor catalog (lib/vendor-catalog.js) groups the roster in the Team
532
+ // view; a vendor reporting a new model or helper nudges every client.
533
+ var _vendorCatalog = require("./vendor-catalog").defaultCatalog;
534
+ var _stopCatalogNudge = _vendorCatalog.subscribe(function () { _agentRosterNotifier.notify(); });
471
535
  var _agentRoster = require("./agent-roster").createAgentRoster({
536
+ catalog: _vendorCatalog,
472
537
  file: path.join(CONFIG_DIR, "agent-roster.json"),
473
538
  writeJson: function (file, value) { return require("./store").writeJsonAt(file, value); },
474
539
  onChange: _agentRosterNotifier.notify,
@@ -490,6 +555,7 @@ function createServer(opts) {
490
555
  outboundLedger: _announcingLedger,
491
556
  onAutomationInjected: _teamTrafficNotifier.notify,
492
557
  onAgentSeen: _agentRoster.observe,
558
+ readMemAvailableMB: require("./sdk-bridge").readMemAvailableMB,
493
559
  // Read when a session is opened, so a change needs no restart.
494
560
  getPermissionSettings: function () {
495
561
  return onGetPermissionSettings ? onGetPermissionSettings() : null;
@@ -713,36 +779,12 @@ function createServer(opts) {
713
779
  return;
714
780
  }
715
781
 
716
- // Theme list: bundled (lib/themes/) + user (~/.clagentic/themes/)
782
+ // Theme list: the console's own themes (lib/themes/) and the user's custom
783
+ // theme files (<console home>/themes/). Invalid files are left out.
717
784
  if (req.method === "GET" && fullUrl === "/api/themes") {
718
- var bundled = {};
719
- var custom = {};
720
- // Read bundled themes
721
- try {
722
- var bFiles = fs.readdirSync(bundledThemesDir);
723
- for (var i = 0; i < bFiles.length; i++) {
724
- if (!bFiles[i].endsWith(".json")) continue;
725
- try {
726
- var raw = fs.readFileSync(path.join(bundledThemesDir, bFiles[i]), "utf8");
727
- var id = bFiles[i].replace(/\.json$/, "");
728
- bundled[id] = JSON.parse(raw);
729
- } catch (e) {}
730
- }
731
- } catch (e) {}
732
- // Read user themes (override bundled if same id)
733
- try {
734
- var uFiles = fs.readdirSync(userThemesDir);
735
- for (var j = 0; j < uFiles.length; j++) {
736
- if (!uFiles[j].endsWith(".json")) continue;
737
- try {
738
- var uRaw = fs.readFileSync(path.join(userThemesDir, uFiles[j]), "utf8");
739
- var uid = uFiles[j].replace(/\.json$/, "");
740
- custom[uid] = JSON.parse(uRaw);
741
- } catch (e) {}
742
- }
743
- } catch (e) {}
785
+ var themeList = themeFiles.listThemes({ bundledPinned: themeSeed.pinnedBundledThemes(), customDir: userThemesDir });
744
786
  res.writeHead(200, { "Content-Type": "application/json" });
745
- res.end(JSON.stringify({ bundled: bundled, custom: custom }));
787
+ res.end(JSON.stringify({ bundled: themeList.bundled, custom: themeList.custom }));
746
788
  return;
747
789
  }
748
790
 
@@ -1580,6 +1622,12 @@ function createServer(opts) {
1580
1622
  onSetProjectFolder: onSetProjectFolder,
1581
1623
  onRenameProjectFolder: onRenameProjectFolder,
1582
1624
  onSetFolderIcon: onSetFolderIcon,
1625
+ // Folders are server-wide (a project's folderName), so the settings gate
1626
+ // reads every member regardless of who is asking.
1627
+ getFolderProjectSlugs: function (folderName) {
1628
+ return getProjects().filter(function (st) { return st.folderName === folderName; })
1629
+ .map(function (st) { return st.slug; });
1630
+ },
1583
1631
  // The daemon rewrites the project and folder references; agent avatar
1584
1632
  // choices that named the old slug follow it here.
1585
1633
  onRenameCustomIcon: onRenameCustomIcon ? function (oldSlug, newSlug) {
@@ -1604,6 +1652,8 @@ function createServer(opts) {
1604
1652
  onSetPermissionSettings: onSetPermissionSettings,
1605
1653
  onGetUserShellSettings: onGetUserShellSettings,
1606
1654
  onSetUserShellSettings: onSetUserShellSettings,
1655
+ onGetPromptExpirySettings: onGetPromptExpirySettings,
1656
+ onSetPromptExpirySettings: onSetPromptExpirySettings,
1607
1657
  onGetServerDefaultBetas: onGetServerDefaultBetas,
1608
1658
  onSetServerDefaultBetas: onSetServerDefaultBetas,
1609
1659
  onGetProjectDefaultBetas: onGetProjectDefaultBetas,
@@ -1779,7 +1829,7 @@ function createServer(opts) {
1779
1829
  role: u.role,
1780
1830
  avatarStyle: p.avatarStyle || "thumbs",
1781
1831
  avatarSeed: p.avatarSeed || u.username,
1782
- avatarColor: p.avatarColor || "#7c3aed",
1832
+ avatarColor: p.avatarColor || DEFAULT_AVATAR_COLOR,
1783
1833
  avatarCustom: p.avatarCustom || "",
1784
1834
  };
1785
1835
  });
@@ -1901,6 +1951,7 @@ function createServer(opts) {
1901
1951
  _promptReminders.stop();
1902
1952
  _outboundLedger.stop();
1903
1953
  _teamTrafficNotifier.stop();
1954
+ _stopCatalogNudge();
1904
1955
  _agentRosterNotifier.stop();
1905
1956
  _externalTrigger.stopWatcher();
1906
1957
  _scheduledInput.stop();