@clagentic/console 1.5.0-beta.2 → 1.5.0-beta.4

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 (54) hide show
  1. package/README.md +18 -14
  2. package/bin/cli.js +1 -0
  3. package/lib/cli-sessions.js +71 -18
  4. package/lib/config.js +80 -6
  5. package/lib/daemon-projects.js +1 -1
  6. package/lib/daemon.js +142 -26
  7. package/lib/pages.js +1 -42
  8. package/lib/project-connection.js +4 -8
  9. package/lib/project-external-trigger.js +62 -7
  10. package/lib/project-http.js +17 -1
  11. package/lib/project-loop.js +3 -2
  12. package/lib/project-notifications.js +3 -18
  13. package/lib/project-sessions.js +68 -27
  14. package/lib/project-team.js +417 -0
  15. package/lib/project-user-message.js +5 -10
  16. package/lib/project.js +53 -53
  17. package/lib/public/app.js +7 -15
  18. package/lib/public/css/home-hub.css +36 -0
  19. package/lib/public/css/icon-strip.css +28 -126
  20. package/lib/public/css/menus.css +2 -2
  21. package/lib/public/css/team-panel.css +149 -0
  22. package/lib/public/index.html +72 -15
  23. package/lib/public/modules/admin.js +1 -52
  24. package/lib/public/modules/agent-picker.js +11 -3
  25. package/lib/public/modules/app-cursors.js +43 -47
  26. package/lib/public/modules/app-home-hub.js +12 -0
  27. package/lib/public/modules/app-messages.js +18 -12
  28. package/lib/public/modules/app-rendering.js +1 -2
  29. package/lib/public/modules/server-settings.js +74 -5
  30. package/lib/public/modules/sidebar-mobile.js +9 -88
  31. package/lib/public/modules/sidebar-projects.js +1 -1
  32. package/lib/public/modules/sidebar-sessions.js +6 -2
  33. package/lib/public/modules/sidebar-users.js +37 -307
  34. package/lib/public/modules/team-panel.js +331 -0
  35. package/lib/public/modules/tools.js +3 -0
  36. package/lib/public/modules/user-settings.js +0 -3
  37. package/lib/public/style.css +1 -0
  38. package/lib/sdk-bridge.js +121 -8
  39. package/lib/sdk-message-processor.js +39 -4
  40. package/lib/sdk-worker.js +2 -2
  41. package/lib/server-admin.js +1 -86
  42. package/lib/server-auth.js +13 -124
  43. package/lib/server-dm.js +2 -7
  44. package/lib/server-palette.js +9 -20
  45. package/lib/server-settings.js +41 -243
  46. package/lib/server-skills.js +11 -13
  47. package/lib/server.js +37 -60
  48. package/lib/sessions.js +16 -50
  49. package/lib/terminal-manager.js +13 -15
  50. package/lib/users-auth.js +0 -38
  51. package/lib/users.js +14 -11
  52. package/lib/ws-schema.js +12 -0
  53. package/lib/yoke/adapters/claude.js +5 -0
  54. package/package.json +1 -1
@@ -73,10 +73,8 @@ function attachConnection(ctx) {
73
73
  if (s.cliSessionId && s.cliSessionId === storedPresence.sessionId) active = s;
74
74
  });
75
75
  }
76
- if (active && usersModule.isMultiUser() && wsUser) {
76
+ if (active && wsUser) {
77
77
  if (!usersModule.canAccessSession(wsUser.id, active, { visibility: "public" })) active = null;
78
- } else if (active && !usersModule.isMultiUser() && active.ownerId) {
79
- active = null;
80
78
  }
81
79
  }
82
80
  if (!active && allSessions.length > 0) {
@@ -121,12 +119,10 @@ function attachConnection(ctx) {
121
119
  var project = getProject();
122
120
  var ownerLocked = !!(osUsers && osUsers.length > 0 && /^\/home\/[^/]+\//.test(cwd));
123
121
  var allSessions = [].concat(Array.from(sm.sessions.values())).filter(function (s) { return !s.hidden; });
124
- if (usersModule.isMultiUser() && wsUser) {
122
+ if (wsUser) {
125
123
  allSessions = allSessions.filter(function (s) {
126
124
  return usersModule.canAccessSession(wsUser.id, s, { visibility: "public" });
127
125
  });
128
- } else if (!usersModule.isMultiUser()) {
129
- allSessions = allSessions.filter(function (s) { return !s.ownerId; });
130
126
  }
131
127
  var restoredState = findRestoredActiveSession(ws, wsUser, allSessions);
132
128
  var restoredActive = restoredState.active;
@@ -176,7 +172,7 @@ function attachConnection(ctx) {
176
172
  var autoCreated = false;
177
173
  if (!active) {
178
174
  var autoOpts = {};
179
- if (wsUser && usersModule.isMultiUser()) autoOpts.ownerId = wsUser.id;
175
+ if (wsUser) autoOpts.ownerId = wsUser.id;
180
176
  // TODO(lr-f311): defer createSession until first user message — every
181
177
  // network blip or browser reload creates an empty session file here.
182
178
  // The reconnect/presence path is subtle; fix deferred to a follow-up PR.
@@ -184,7 +180,7 @@ function attachConnection(ctx) {
184
180
  autoCreated = true;
185
181
  }
186
182
  if (active && !autoCreated) {
187
- if (!active.ownerId && wsUser && usersModule.isMultiUser()) {
183
+ if (!active.ownerId && wsUser) {
188
184
  active.ownerId = wsUser.id;
189
185
  sm.saveSessionFile(active);
190
186
  }
@@ -3,6 +3,8 @@ var path = require("path");
3
3
 
4
4
  // How long (ms) to keep processed trigger files before pruning on startup.
5
5
  var PROCESSED_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000; // 30 days
6
+ var POLL_INTERVAL_MS = 30 * 1000; // 30 s backstop scan
7
+ var WATCHER_REARM_INTERVAL_MS = 5 * 60 * 1000; // 5 min inotify rebind
6
8
 
7
9
  /**
8
10
  * External trigger watcher — global singleton.
@@ -35,6 +37,14 @@ var PROCESSED_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000; // 30 days
35
37
  * Daemon-down recovery: unprocessed files that predate the current process
36
38
  * start are picked up via a startup scan (scanExisting). No file is lost
37
39
  * if the daemon is restarted while triggers are pending.
40
+ *
41
+ * Watcher hardening (three layers):
42
+ * Layer 1 — 30 s polling backstop: scanExisting() on an interval so files
43
+ * are never permanently missed if fs.watch silently dies.
44
+ * Layer 2 — 5 min periodic re-arm: close and re-open the fs.watch binding
45
+ * so the inotify registration is never more than 5 min stale.
46
+ * Layer 3 — health export: getHealth() returns watcher liveness, last-event
47
+ * timestamp, and poll-interval presence for external monitoring.
38
48
  */
39
49
  function attachExternalTrigger(ctx) {
40
50
  var triggersDir = ctx.triggersDir;
@@ -47,6 +57,11 @@ function attachExternalTrigger(ctx) {
47
57
  // from the initial scan + watcher race.
48
58
  var dispatched = {};
49
59
 
60
+ // Hardening state
61
+ var pollInterval = null;
62
+ var rearmTimer = null;
63
+ var watcherLastEventMs = 0;
64
+
50
65
  // --- Directory setup ---
51
66
 
52
67
  function ensureDirs() {
@@ -231,12 +246,16 @@ function attachExternalTrigger(ctx) {
231
246
  }, 200);
232
247
  }
233
248
 
234
- function startWatcher() {
235
- ensureDirs();
236
- pruneOldProcessed();
237
- scanExisting(); // pick up files dropped while daemon was down
249
+ // --- Layer 2: periodic watcher re-arm ---
250
+
251
+ function armWatcher() {
252
+ if (watcher) {
253
+ try { watcher.close(); } catch (e) {}
254
+ watcher = null;
255
+ }
238
256
  try {
239
257
  watcher = fs.watch(triggersDir, function (eventType, filename) {
258
+ watcherLastEventMs = Date.now();
240
259
  if (filename && !filename.endsWith(".json")) return;
241
260
  onDirChange();
242
261
  });
@@ -244,18 +263,47 @@ function attachExternalTrigger(ctx) {
244
263
  console.error("[external-trigger] Watcher error:", e.message || e);
245
264
  stopWatcher();
246
265
  });
247
- console.log("[external-trigger] Watching:", triggersDir);
248
266
  } catch (e) {
249
- console.error("[external-trigger] Failed to start watcher:", e.message || e);
267
+ console.error("[external-trigger] Failed to arm watcher:", e.message || e);
250
268
  }
251
269
  }
252
270
 
271
+ function startWatcher() {
272
+ ensureDirs();
273
+ pruneOldProcessed();
274
+ scanExisting(); // pick up files dropped while daemon was down
275
+
276
+ armWatcher();
277
+ console.log("[external-trigger] Watching:", triggersDir);
278
+
279
+ // Layer 1: polling backstop — catches files if fs.watch silently dies
280
+ pollInterval = setInterval(function () {
281
+ scanExisting();
282
+ }, POLL_INTERVAL_MS);
283
+ pollInterval.unref();
284
+
285
+ // Layer 2: periodic re-arm — keeps inotify registration fresh
286
+ rearmTimer = setInterval(function () {
287
+ armWatcher();
288
+ console.log("[external-trigger] Watcher re-armed");
289
+ }, WATCHER_REARM_INTERVAL_MS);
290
+ rearmTimer.unref();
291
+ }
292
+
253
293
  function stopWatcher() {
254
294
  clearTimeout(debounce);
255
295
  if (watcher) {
256
296
  try { watcher.close(); } catch (e) {}
257
297
  watcher = null;
258
298
  }
299
+ if (pollInterval) {
300
+ clearInterval(pollInterval);
301
+ pollInterval = null;
302
+ }
303
+ if (rearmTimer) {
304
+ clearInterval(rearmTimer);
305
+ rearmTimer = null;
306
+ }
259
307
  }
260
308
 
261
309
  // --- Startup scan (daemon-down recovery) ---
@@ -289,8 +337,15 @@ function attachExternalTrigger(ctx) {
289
337
  return {
290
338
  startWatcher: startWatcher,
291
339
  stopWatcher: stopWatcher,
340
+ // Layer 3: health export for external monitoring
341
+ getHealth: function () {
342
+ return {
343
+ watcherAlive: !!watcher,
344
+ lastEventMs: watcherLastEventMs,
345
+ pollActive: !!pollInterval,
346
+ };
347
+ },
292
348
  };
293
349
  }
294
350
 
295
351
  module.exports = { attachExternalTrigger: attachExternalTrigger };
296
-
@@ -26,8 +26,24 @@ var MAX_UPLOAD_BYTES = 50 * 1024 * 1024; // 50 MB
26
26
  function parseJsonBody(req) {
27
27
  return new Promise(function (resolve, reject) {
28
28
  var body = "";
29
- req.on("data", function (chunk) { body += chunk; });
29
+ var bodyBytes = 0;
30
+ // Hard cap: enforce limit while buffering, not only after full accumulation.
31
+ // 1.4x headroom covers base64-encoded payloads (base64 expands by ~4/3).
32
+ var hardCap = MAX_UPLOAD_BYTES * 1.4;
33
+ var rejected = false;
34
+ req.on("data", function (chunk) {
35
+ if (rejected) return;
36
+ bodyBytes += Buffer.isBuffer(chunk) ? chunk.length : Buffer.byteLength(chunk);
37
+ if (bodyBytes > hardCap) {
38
+ rejected = true;
39
+ req.destroy();
40
+ reject(new Error("Request body too large"));
41
+ return;
42
+ }
43
+ body += chunk;
44
+ });
30
45
  req.on("end", function () {
46
+ if (rejected) return;
31
47
  try { resolve(JSON.parse(body)); }
32
48
  catch (e) { reject(e); }
33
49
  });
@@ -678,6 +678,7 @@ function attachLoop(ctx) {
678
678
  // Unlock the last coder session so users can continue interacting with it.
679
679
  // Capture owner before clearing state so push routing still works.
680
680
  var _loopOwnerUserId = null;
681
+ var _lastSessionId = loopState.currentSessionId;
681
682
  if (loopState.currentSessionId) {
682
683
  var lastCoderSession = sm.sessions.get(loopState.currentSessionId);
683
684
  if (lastCoderSession) {
@@ -724,7 +725,7 @@ function attachLoop(ctx) {
724
725
  type: "done", slug: slug, title: "Loop Complete", body: _finishBody, tag: "ralph-loop-done",
725
726
  };
726
727
  // Route to loop session owner only — body carries iteration status.
727
- if (usersModule.isMultiUser() && _loopOwnerUserId && pushModule.sendPushToUser) {
728
+ if (_loopOwnerUserId && pushModule.sendPushToUser) {
728
729
  pushModule.sendPushToUser(_loopOwnerUserId, _loopDonePayload);
729
730
  } else {
730
731
  pushModule.sendPush(_loopDonePayload);
@@ -737,7 +738,7 @@ function attachLoop(ctx) {
737
738
  name: loopState.name,
738
739
  iterations: loopState.iteration,
739
740
  maxIterations: loopState.maxIterations,
740
- sessionId: loopState.currentSessionId,
741
+ sessionId: _lastSessionId,
741
742
  });
742
743
  }
743
744
 
@@ -112,8 +112,6 @@ function attachNotifications(ctx) {
112
112
  var broadcastAll = ctx.broadcastAll;
113
113
  var sendToUser = ctx.sendToUser || null; // (userId, msg) -> void; iterates all project clients
114
114
  var pushModule = ctx.pushModule;
115
- var isMultiUser = ctx.isMultiUser || function () { return false; };
116
-
117
115
  var notifications = loadNotifications();
118
116
  var reminderTimer = null;
119
117
 
@@ -206,22 +204,9 @@ function attachNotifications(ctx) {
206
204
  // --- Periodic reminder ---
207
205
 
208
206
  function startReminder() {
209
- if (reminderTimer) return;
210
- reminderTimer = setInterval(function () {
211
- // In multi-user mode, skip the broadcast reminder push.
212
- // The body (unread count) is per-project state that would leak to all
213
- // push subscribers regardless of which user owns the notifications.
214
- if (isMultiUser()) return;
215
- var count = getUnreadCount();
216
- if (count > 0 && pushModule) {
217
- pushModule.sendPush({
218
- type: "reminder",
219
- title: "Clagentic:Console",
220
- body: count + " unread notification" + (count > 1 ? "s" : ""),
221
- tag: "clay-notif-reminder",
222
- });
223
- }
224
- }, REMINDER_INTERVAL);
207
+ // Reminder push is suppressed in multi-user mode: the unread count is
208
+ // per-project state that would leak to all push subscribers regardless of
209
+ // which user owns the notifications.
225
210
  }
226
211
 
227
212
  function stopReminder() {
@@ -132,7 +132,7 @@ function attachSessions(ctx) {
132
132
 
133
133
  if (msg.type === "new_session") {
134
134
  var sessionOpts = {};
135
- if (ws._clayUser && usersModule.isMultiUser()) sessionOpts.ownerId = ws._clayUser.id;
135
+ if (ws._clayUser) sessionOpts.ownerId = ws._clayUser.id;
136
136
  if (msg.sessionVisibility) sessionOpts.sessionVisibility = msg.sessionVisibility;
137
137
  if (msg.vendor) sessionOpts.vendor = msg.vendor;
138
138
  if (msg.agentName && typeof msg.agentName === "string") {
@@ -157,9 +157,7 @@ function attachSessions(ctx) {
157
157
  }
158
158
  var nsPresKey = ws._clayUser ? ws._clayUser.id : "_default";
159
159
  userPresence.setPresence(slug, nsPresKey, newSess.localId, null);
160
- if (usersModule.isMultiUser()) {
161
- broadcastPresence();
162
- }
160
+ broadcastPresence();
163
161
  return true;
164
162
  }
165
163
 
@@ -170,17 +168,55 @@ function attachSessions(ctx) {
170
168
  // Hidden client-side when active project is a Mate; we still answer here
171
169
  // because the daemon shouldn't make UX decisions that the client already
172
170
  // owns. UI gates the surface; daemon stays a data plane.
171
+ //
172
+ // Background refresh: respond immediately with the cached list, then kick
173
+ // off a refresh(). If the catalog changes, re-send to this client only.
174
+ // Cost is paid exactly when the user opens the agent picker — not on a timer.
173
175
  if (msg.type === "list_agents") {
174
176
  var favorites = [];
175
177
  var recents = [];
176
178
  try { favorites = agentsFavorites.listFavorites(); recents = agentsFavorites.listRecents(); }
177
179
  catch (e) { /* favorites are best-effort */ }
180
+ var cachedAgents = agentsModule.getAll();
178
181
  sendTo(ws, {
179
182
  type: "agents_list",
180
- agents: agentsModule.getAll(),
183
+ agents: cachedAgents,
181
184
  favorites: favorites,
182
185
  recents: recents,
183
186
  });
187
+ // Refresh in background; re-send only if the catalog changed.
188
+ var cachedJson = JSON.stringify(cachedAgents);
189
+ agentsModule.refresh().then(function () {
190
+ var freshAgents = agentsModule.getAll();
191
+ if (JSON.stringify(freshAgents) === cachedJson) return;
192
+ var favFresh = [];
193
+ var recFresh = [];
194
+ try { favFresh = agentsFavorites.listFavorites(); recFresh = agentsFavorites.listRecents(); }
195
+ catch (e) { /* best-effort */ }
196
+ sendTo(ws, { type: "agents_list", agents: freshAgents, favorites: favFresh, recents: recFresh });
197
+ }).catch(function (e) {
198
+ console.error("[project-sessions] background agent refresh failed:", e && e.message ? e.message : e);
199
+ });
200
+ return true;
201
+ }
202
+
203
+ // refresh_agents — explicit on-demand refresh triggered from the settings UI.
204
+ // Re-runs SDK discovery, then broadcasts the updated catalog to ALL connected
205
+ // clients. Responds immediately with ok:true (async broadcast follows).
206
+ if (msg.type === "refresh_agents") {
207
+ sendTo(ws, { type: "refresh_agents_result", ok: true });
208
+ agentsModule.refresh().then(function () {
209
+ var freshAgents = agentsModule.getAll();
210
+ var favFresh = [];
211
+ var recFresh = [];
212
+ try { favFresh = agentsFavorites.listFavorites(); recFresh = agentsFavorites.listRecents(); }
213
+ catch (e) { /* best-effort */ }
214
+ send({ type: "agents_list", agents: freshAgents, favorites: favFresh, recents: recFresh });
215
+ send({ type: "toast", level: "info", message: "Agent catalog refreshed — " + freshAgents.length + " agent" + (freshAgents.length === 1 ? "" : "s") + " found." });
216
+ }).catch(function (e) {
217
+ console.error("[project-sessions] refresh_agents failed:", e && e.message ? e.message : e);
218
+ send({ type: "toast", level: "error", message: "Agent catalog refresh failed." });
219
+ });
184
220
  return true;
185
221
  }
186
222
 
@@ -226,7 +262,7 @@ function attachSessions(ctx) {
226
262
  if (typeof msg.sessionId !== "number") return true;
227
263
  var agentTarget = sm.sessions.get(msg.sessionId);
228
264
  if (!agentTarget) return true;
229
- if (usersModule.isMultiUser() && ws._clayUser) {
265
+ if (ws._clayUser) {
230
266
  if (!usersModule.canAccessSession(ws._clayUser.id, agentTarget, { visibility: "public" })) return true;
231
267
  }
232
268
  var nextAgent = (msg.agentName && typeof msg.agentName === "string") ? msg.agentName : null;
@@ -245,7 +281,7 @@ function attachSessions(ctx) {
245
281
  if (typeof msg.sessionId === "number" && (msg.visibility === "shared" || msg.visibility === "private")) {
246
282
  var visTarget = sm.sessions.get(msg.sessionId);
247
283
  if (!visTarget) return true;
248
- if (usersModule.isMultiUser() && ws._clayUser) {
284
+ if (ws._clayUser) {
249
285
  if (!usersModule.canAccessSession(ws._clayUser.id, visTarget, { visibility: "public" })) return true;
250
286
  }
251
287
  sm.setSessionVisibility(msg.sessionId, msg.visibility);
@@ -257,7 +293,7 @@ function attachSessions(ctx) {
257
293
  if (typeof msg.sessionId === "number") {
258
294
  var bookmarkTarget = sm.sessions.get(msg.sessionId);
259
295
  if (!bookmarkTarget) return true;
260
- if (usersModule.isMultiUser() && ws._clayUser) {
296
+ if (ws._clayUser) {
261
297
  if (!usersModule.canAccessSession(ws._clayUser.id, bookmarkTarget, { visibility: "public" })) return true;
262
298
  }
263
299
  sm.setSessionBookmarked(msg.sessionId, !!msg.bookmarked);
@@ -270,7 +306,7 @@ function attachSessions(ctx) {
270
306
  var source = sm.sessions.get(msg.sourceId);
271
307
  var target = sm.sessions.get(msg.targetId);
272
308
  if (!source || !target) return true;
273
- if (usersModule.isMultiUser() && ws._clayUser) {
309
+ if (ws._clayUser) {
274
310
  if (!usersModule.canAccessSession(ws._clayUser.id, source, { visibility: "public" })) return true;
275
311
  if (!usersModule.canAccessSession(ws._clayUser.id, target, { visibility: "public" })) return true;
276
312
  }
@@ -287,7 +323,7 @@ function attachSessions(ctx) {
287
323
  if (typeof bulkId !== "number") continue;
288
324
  var bulkTarget = sm.sessions.get(bulkId);
289
325
  if (!bulkTarget) continue;
290
- if (usersModule.isMultiUser() && ws._clayUser) {
326
+ if (ws._clayUser) {
291
327
  if (!usersModule.canAccessSession(ws._clayUser.id, bulkTarget, { visibility: "public" })) continue;
292
328
  }
293
329
  deletableIds.push(bulkId);
@@ -441,17 +477,14 @@ function attachSessions(ctx) {
441
477
  sm.currentModel = "";
442
478
  }
443
479
  }
444
- // Check access in multi-user mode
445
- if (usersModule.isMultiUser() && ws._clayUser) {
480
+ // Check session access
481
+ if (ws._clayUser) {
446
482
  var switchTarget = sm.sessions.get(msg.id);
447
483
  if (!usersModule.canAccessSession(ws._clayUser.id, switchTarget, { visibility: "public" })) return true;
448
- ws._clayActiveSession = msg.id;
449
- sm.switchSession(msg.id, ws, hydrateImageRefs);
450
- broadcastPresence();
451
- } else {
452
- ws._clayActiveSession = msg.id;
453
- sm.switchSession(msg.id, ws, hydrateImageRefs);
454
484
  }
485
+ ws._clayActiveSession = msg.id;
486
+ sm.switchSession(msg.id, ws, hydrateImageRefs);
487
+ broadcastPresence();
455
488
  // Send per-session context sources
456
489
  if (typeof loadContextSources === "function") {
457
490
  var switchedSources = loadContextSources(slug, msg.id);
@@ -542,7 +575,7 @@ function attachSessions(ctx) {
542
575
  }
543
576
 
544
577
  if (msg.type === "update_now") {
545
- if (usersModule.isMultiUser() && (!ws._clayUser || ws._clayUser.role !== "admin")) return true;
578
+ if (!ws._clayUser || ws._clayUser.role !== "admin") return true;
546
579
  send({ type: "update_started", version: getLatestVersion() || "" });
547
580
  var _ipc = require("./ipc");
548
581
  var _config = require("./config");
@@ -606,7 +639,7 @@ function attachSessions(ctx) {
606
639
  if (msg.type === "kill_process") {
607
640
  // Restrict to admins in multi-user mode — any user could otherwise SIGTERM
608
641
  // another user's running claude subprocess (lr-eb1a).
609
- if (usersModule.isMultiUser() && (!ws._clayUser || ws._clayUser.role !== "admin")) {
642
+ if (!ws._clayUser || ws._clayUser.role !== "admin") {
610
643
  sendTo(ws, { type: "error", message: "Admin access required" });
611
644
  return true;
612
645
  }
@@ -1058,7 +1091,7 @@ function attachSessions(ctx) {
1058
1091
  }
1059
1092
 
1060
1093
  if (msg.type === "cursor_move" || msg.type === "cursor_leave" || msg.type === "text_select") {
1061
- if (!usersModule.isMultiUser() || !ws._clayUser) return true;
1094
+ if (!ws._clayUser) return true;
1062
1095
  var u = ws._clayUser;
1063
1096
  var p = u.profile || {};
1064
1097
  var cursorMsg = {
@@ -1555,14 +1588,13 @@ function attachSessions(ctx) {
1555
1588
  // --- Daemon config / server management (admin-only in multi-user mode) ---
1556
1589
  if (msg.type === "get_daemon_config" || msg.type === "set_pin" || msg.type === "set_keep_awake" ||
1557
1590
  msg.type === "set_auto_continue" || msg.type === "set_image_retention" || msg.type === "set_mem_available_threshold" ||
1591
+ msg.type === "set_tokens_per_mb_headroom" ||
1558
1592
  msg.type === "set_lite_auto_enroll" ||
1559
1593
  msg.type === "shutdown_server" || msg.type === "restart_server") {
1560
- if (usersModule.isMultiUser()) {
1561
- var _wsUser = ws._clayUser;
1562
- if (!_wsUser || _wsUser.role !== "admin") {
1563
- sendTo(ws, { type: "error", message: "Admin access required" });
1564
- return true;
1565
- }
1594
+ var _wsUser = ws._clayUser;
1595
+ if (!_wsUser || _wsUser.role !== "admin") {
1596
+ sendTo(ws, { type: "error", message: "Admin access required" });
1597
+ return true;
1566
1598
  }
1567
1599
  }
1568
1600
 
@@ -1629,6 +1661,15 @@ function attachSessions(ctx) {
1629
1661
  return true;
1630
1662
  }
1631
1663
 
1664
+ if (msg.type === "set_tokens_per_mb_headroom") {
1665
+ if (typeof opts.onSetTokensPerMbHeadroom === "function") {
1666
+ var tpmResult = opts.onSetTokensPerMbHeadroom(msg.value);
1667
+ sendTo(ws, { type: "set_tokens_per_mb_headroom_result", ok: tpmResult.ok, tokensPerMbHeadroom: tpmResult.tokensPerMbHeadroom });
1668
+ send({ type: "tokens_per_mb_headroom_changed", tokensPerMbHeadroom: tpmResult.tokensPerMbHeadroom });
1669
+ }
1670
+ return true;
1671
+ }
1672
+
1632
1673
  if (msg.type === "shutdown_server") {
1633
1674
  if (typeof opts.onShutdown === "function") {
1634
1675
  sendTo(ws, { type: "shutdown_server_result", ok: true });