@clagentic/console 1.9.0-beta.2 → 1.9.0-beta.3

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.
@@ -77,6 +77,28 @@ function formatAskUserAnswerAsMessage(input, answers) {
77
77
  * getUpdateChannel, setUpdateChannel,
78
78
  * getLatestVersion, setLatestVersion
79
79
  */
80
+
81
+ // lr-2016fe: the process_stats WS response is split into a base tier (sent
82
+ // to any authenticated caller) and an admin-only diagnostic tier (see the
83
+ // process_stats handler below). This is the allowlist of base-tier field
84
+ // keys — the ONLY keys the base-tier projection may emit. It is the
85
+ // structural guard: a field added to the handler's raw base object without
86
+ // also being added here is silently dropped from every response rather than
87
+ // silently shipped to a non-admin. Exported for test/ws-process-stats-role-
88
+ // gate-lr-2016fe.test.js, which asserts the exact base-tier key set of a
89
+ // real (non-admin) response equals this list — so adding a key here is a
90
+ // deliberate, reviewed decision, not something that happens by accident.
91
+ var PROCESS_STATS_BASE_FIELD_KEYS = [
92
+ "pid",
93
+ "uptime",
94
+ "memory",
95
+ "sessions",
96
+ "processing",
97
+ "clients",
98
+ "terminals",
99
+ "memAvailableMB",
100
+ ];
101
+
80
102
  function attachSessions(ctx) {
81
103
  var cwd = ctx.cwd;
82
104
  var slug = ctx.slug;
@@ -127,7 +149,7 @@ function attachSessions(ctx) {
127
149
  function handleSessionsMessage(ws, msg) {
128
150
 
129
151
  if (msg.type === "push_subscribe") {
130
- var _pushUserId = ws._clayUser ? ws._clayUser.id : null;
152
+ var _pushUserId = ws._clagenticUser ? ws._clagenticUser.id : null;
131
153
  if (pushModule && msg.subscription) pushModule.addSubscription(msg.subscription, msg.replaceEndpoint, _pushUserId);
132
154
  return true;
133
155
  }
@@ -182,7 +204,7 @@ function attachSessions(ctx) {
182
204
 
183
205
  if (msg.type === "new_session") {
184
206
  var sessionOpts = {};
185
- if (ws._clayUser) sessionOpts.ownerId = ws._clayUser.id;
207
+ if (ws._clagenticUser) sessionOpts.ownerId = ws._clagenticUser.id;
186
208
  if (msg.sessionVisibility) sessionOpts.sessionVisibility = msg.sessionVisibility;
187
209
  if (msg.vendor) sessionOpts.vendor = msg.vendor;
188
210
  if (msg.agentName && typeof msg.agentName === "string") {
@@ -202,7 +224,7 @@ function attachSessions(ctx) {
202
224
  // session's in-progress choice instead of the actual saved default.
203
225
  newSess.model = sm._savedDefaultModel || null;
204
226
  newSess.permissionMode = sm._savedDefaultMode || null;
205
- ws._clayActiveSession = newSess.localId;
227
+ ws._clagenticActiveSession = newSess.localId;
206
228
  // Apply project-level email defaults to new session
207
229
  if (typeof ctx._email === "object" && ctx._email.getEmailDefaults) {
208
230
  var emailDefaults = ctx._email.getEmailDefaults();
@@ -212,7 +234,7 @@ function attachSessions(ctx) {
212
234
  sendTo(ws, { type: "context_sources_state", active: defaultSources });
213
235
  }
214
236
  }
215
- var nsPresKey = ws._clayUser ? ws._clayUser.id : "_default";
237
+ var nsPresKey = ws._clagenticUser ? ws._clagenticUser.id : "_default";
216
238
  userPresence.setPresence(slug, nsPresKey, newSess.localId, null);
217
239
  broadcastPresence();
218
240
  return true;
@@ -319,8 +341,8 @@ function attachSessions(ctx) {
319
341
  if (typeof msg.sessionId !== "number") return true;
320
342
  var agentTarget = sm.sessions.get(msg.sessionId);
321
343
  if (!agentTarget) return true;
322
- if (ws._clayUser) {
323
- if (!usersModule.canAccessSession(ws._clayUser.id, agentTarget, { visibility: "public" })) return true;
344
+ if (ws._clagenticUser) {
345
+ if (!usersModule.canAccessSession(ws._clagenticUser.id, agentTarget, { visibility: "public" })) return true;
324
346
  }
325
347
  var nextAgent = (msg.agentName && typeof msg.agentName === "string") ? msg.agentName : null;
326
348
  var prevAgent = agentTarget.agentName || null;
@@ -338,8 +360,8 @@ function attachSessions(ctx) {
338
360
  if (typeof msg.sessionId === "number" && (msg.visibility === "shared" || msg.visibility === "private")) {
339
361
  var visTarget = sm.sessions.get(msg.sessionId);
340
362
  if (!visTarget) return true;
341
- if (ws._clayUser) {
342
- if (!usersModule.canAccessSession(ws._clayUser.id, visTarget, { visibility: "public" })) return true;
363
+ if (ws._clagenticUser) {
364
+ if (!usersModule.canAccessSession(ws._clagenticUser.id, visTarget, { visibility: "public" })) return true;
343
365
  }
344
366
  sm.setSessionVisibility(msg.sessionId, msg.visibility);
345
367
  }
@@ -350,8 +372,8 @@ function attachSessions(ctx) {
350
372
  if (typeof msg.sessionId === "number") {
351
373
  var bookmarkTarget = sm.sessions.get(msg.sessionId);
352
374
  if (!bookmarkTarget) return true;
353
- if (ws._clayUser) {
354
- if (!usersModule.canAccessSession(ws._clayUser.id, bookmarkTarget, { visibility: "public" })) return true;
375
+ if (ws._clagenticUser) {
376
+ if (!usersModule.canAccessSession(ws._clagenticUser.id, bookmarkTarget, { visibility: "public" })) return true;
355
377
  }
356
378
  sm.setSessionBookmarked(msg.sessionId, !!msg.bookmarked);
357
379
  }
@@ -363,9 +385,9 @@ function attachSessions(ctx) {
363
385
  var source = sm.sessions.get(msg.sourceId);
364
386
  var target = sm.sessions.get(msg.targetId);
365
387
  if (!source || !target) return true;
366
- if (ws._clayUser) {
367
- if (!usersModule.canAccessSession(ws._clayUser.id, source, { visibility: "public" })) return true;
368
- if (!usersModule.canAccessSession(ws._clayUser.id, target, { visibility: "public" })) return true;
388
+ if (ws._clagenticUser) {
389
+ if (!usersModule.canAccessSession(ws._clagenticUser.id, source, { visibility: "public" })) return true;
390
+ if (!usersModule.canAccessSession(ws._clagenticUser.id, target, { visibility: "public" })) return true;
369
391
  }
370
392
  sm.reorderBookmarkedSessions(msg.sourceId, msg.targetId, msg.insertBefore !== false);
371
393
  }
@@ -395,8 +417,8 @@ function attachSessions(ctx) {
395
417
  if (typeof bulkId !== "number") continue;
396
418
  var bulkTarget = sm.sessions.get(bulkId);
397
419
  if (!bulkTarget) continue;
398
- if (ws._clayUser) {
399
- if (!usersModule.canAccessSession(ws._clayUser.id, bulkTarget, { visibility: "public" })) continue;
420
+ if (ws._clagenticUser) {
421
+ if (!usersModule.canAccessSession(ws._clagenticUser.id, bulkTarget, { visibility: "public" })) continue;
400
422
  }
401
423
  deletableIds.push(bulkId);
402
424
  }
@@ -413,9 +435,9 @@ function attachSessions(ctx) {
413
435
  return true;
414
436
  }
415
437
  var projectOwnerId = getProjectOwnerId();
416
- var isAdmin = ws._clayUser && ws._clayUser.role === "admin";
417
- var isProjectOwner = ws._clayUser && projectOwnerId && ws._clayUser.id === projectOwnerId;
418
- if (!ws._clayUser || (!isAdmin && !isProjectOwner)) {
438
+ var isAdmin = ws._clagenticUser && ws._clagenticUser.role === "admin";
439
+ var isProjectOwner = ws._clagenticUser && projectOwnerId && ws._clagenticUser.id === projectOwnerId;
440
+ if (!ws._clagenticUser || (!isAdmin && !isProjectOwner)) {
419
441
  sendTo(ws, { type: "error", text: "Only project owners or admins can transfer ownership." });
420
442
  return true;
421
443
  }
@@ -485,10 +507,10 @@ function attachSessions(ctx) {
485
507
  }
486
508
  }
487
509
  var resumed = sm.resumeSession(msg.cliSessionId, { history: history, title: title, vendor: persistedVendor || undefined, allowedTools: persistedAllowedTools || undefined }, ws);
488
- if (resumed) ws._clayActiveSession = resumed.localId;
510
+ if (resumed) ws._clagenticActiveSession = resumed.localId;
489
511
  }).catch(function() {
490
512
  var resumed = sm.resumeSession(msg.cliSessionId, (persistedVendor || persistedAllowedTools) ? { vendor: persistedVendor, allowedTools: persistedAllowedTools } : undefined, ws);
491
- if (resumed) ws._clayActiveSession = resumed.localId;
513
+ if (resumed) ws._clagenticActiveSession = resumed.localId;
492
514
  });
493
515
  return true;
494
516
  }
@@ -560,11 +582,11 @@ function attachSessions(ctx) {
560
582
  }
561
583
  }
562
584
  // Check session access
563
- if (ws._clayUser) {
585
+ if (ws._clagenticUser) {
564
586
  var switchTarget = sm.sessions.get(msg.id);
565
- if (!usersModule.canAccessSession(ws._clayUser.id, switchTarget, { visibility: "public" })) return true;
587
+ if (!usersModule.canAccessSession(ws._clagenticUser.id, switchTarget, { visibility: "public" })) return true;
566
588
  }
567
- ws._clayActiveSession = msg.id;
589
+ ws._clagenticActiveSession = msg.id;
568
590
  sm.switchSession(msg.id, ws, hydrateImageRefs);
569
591
  broadcastPresence();
570
592
  // Send per-session context sources
@@ -584,15 +606,15 @@ function attachSessions(ctx) {
584
606
  var _swModel = sm.effectiveSessionModel(_swSess);
585
607
  var _swMode = (_swSess && _swSess.permissionMode) || sm.currentPermissionMode || "default";
586
608
  sendTo(ws, { type: "config_state", model: _swModel, mode: _swMode, effort: sm.currentEffort || "medium", betas: sm.currentBetas || [], thinking: sm.currentThinking || "adaptive", thinkingBudget: sm.currentThinkingBudget || 10000 });
587
- var swPresKey = ws._clayUser ? ws._clayUser.id : "_default";
609
+ var swPresKey = ws._clagenticUser ? ws._clagenticUser.id : "_default";
588
610
  userPresence.setPresence(slug, swPresKey, msg.id, null);
589
611
  }
590
612
  return true;
591
613
  }
592
614
 
593
615
  if (msg.type === "delete_session") {
594
- if (ws._clayUser) {
595
- var sdPerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
616
+ if (ws._clagenticUser) {
617
+ var sdPerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
596
618
  if (!sdPerms.sessionDelete) {
597
619
  sendTo(ws, { type: "error", text: "You do not have permission to delete sessions" });
598
620
  return true;
@@ -657,7 +679,7 @@ function attachSessions(ctx) {
657
679
  }
658
680
 
659
681
  if (msg.type === "update_now") {
660
- if (!ws._clayUser || ws._clayUser.role !== "admin") return true;
682
+ if (!ws._clagenticUser || ws._clagenticUser.role !== "admin") return true;
661
683
  send({ type: "update_started", version: getLatestVersion() || "" });
662
684
  var _ipc = require("./ipc");
663
685
  var _config = require("./config");
@@ -672,12 +694,27 @@ function attachSessions(ctx) {
672
694
  if (s.isProcessing) processingCount++;
673
695
  });
674
696
  var mem = process.memoryUsage();
675
- // lr-2d91: Include memory pressure fields so the admin panel can show
676
- // pressure building before the MemAvailable gate fires.
677
- var memStats = (sdk && typeof sdk.getMemoryStats === "function") ? sdk.getMemoryStats() : {};
678
697
  var memAvailMB = readMemAvailableMB();
679
- sendTo(ws, {
680
- type: "process_stats",
698
+ // lr-2016fe: the base/admin split here is STRUCTURAL, not a
699
+ // developer-discipline convention, because that convention already
700
+ // failed twice (PR #403 briefly added a session-identifying field
701
+ // with no gate at all; this handler's first fix moved the gate down
702
+ // but still let a future field land in the wrong tier by hand-typing
703
+ // it onto statsResp). PROCESS_STATS_BASE_FIELD_KEYS is the allowlist
704
+ // of what any authenticated caller — admin or not — may receive. The
705
+ // projection loop below is the only place that may populate the
706
+ // response's base-tier keys: it reads only keys named in the
707
+ // allowlist off rawBase, so a field added to rawBase without also
708
+ // adding its key to PROCESS_STATS_BASE_FIELD_KEYS is silently
709
+ // dropped from every response rather than silently shipped
710
+ // (test/ws-process-stats-role-gate-lr-2016fe.test.js asserts the
711
+ // exact base-tier key set). The admin-only
712
+ // diagnostic fields (sourced from sdk.getMemoryStats(), which is
713
+ // daemon-wide — module-scope counters shared across every project's
714
+ // bridge instance, not scoped to this project) are built as a wholly
715
+ // separate named object and merged in only inside the admin branch,
716
+ // so the base object's own shape is never touched by admin-tier work.
717
+ var rawBase = {
681
718
  pid: process.pid,
682
719
  uptime: process.uptime(),
683
720
  memory: {
@@ -691,21 +728,29 @@ function attachSessions(ctx) {
691
728
  clients: clients.size,
692
729
  terminals: tm.list().length,
693
730
  memAvailableMB: memAvailMB,
694
- activeLiveCount: memStats.activeLiveCount !== undefined ? memStats.activeLiveCount : null,
695
- maxConcurrentSessions: memStats.maxConcurrentSessions !== undefined ? memStats.maxConcurrentSessions : null,
696
- // lr-58c813: baseline instrumentation for the lr-5edd64 redesign —
697
- // count of session.isProcessing !== sessionActivity.isSessionActive(session)
698
- // divergences observed since daemon start, plus a bounded ring
699
- // buffer of the most recent occurrences. Read-only counter; does not
700
- // reflect or affect what any renderer displays. Samples carry no
701
- // session identifier (BOBBIE finding): this handler has no
702
- // admin/role gate, unlike its update_now/kill_process siblings, so
703
- // any authenticated client on a shared project could otherwise read
704
- // another user's session id through it. Fixing that pre-existing
705
- // gate gap is out of scope for this instrumentation-only PR.
706
- activityDivergenceCount: memStats.activityDivergenceCount !== undefined ? memStats.activityDivergenceCount : null,
707
- activityDivergenceRecentSamples: memStats.activityDivergenceRecentSamples || [],
708
- });
731
+ };
732
+ var baseFields = {};
733
+ for (var pbi = 0; pbi < PROCESS_STATS_BASE_FIELD_KEYS.length; pbi++) {
734
+ var pbKey = PROCESS_STATS_BASE_FIELD_KEYS[pbi];
735
+ baseFields[pbKey] = rawBase[pbKey];
736
+ }
737
+ var statsResp = Object.assign({ type: "process_stats" }, baseFields);
738
+ // The fields below (activeLiveCount, maxConcurrentSessions,
739
+ // activityDivergenceCount, activityDivergenceRecentSamples) are the
740
+ // ones a future author is most likely to enrich with per-session
741
+ // identifying data (that already happened once — see above), so
742
+ // sdk.getMemoryStats() itself is only ever called for an admin.
743
+ if (ws._clagenticUser && ws._clagenticUser.role === "admin") {
744
+ var memStats = (sdk && typeof sdk.getMemoryStats === "function") ? sdk.getMemoryStats() : {};
745
+ var diagnosticFields = {
746
+ activeLiveCount: memStats.activeLiveCount !== undefined ? memStats.activeLiveCount : null,
747
+ maxConcurrentSessions: memStats.maxConcurrentSessions !== undefined ? memStats.maxConcurrentSessions : null,
748
+ activityDivergenceCount: memStats.activityDivergenceCount !== undefined ? memStats.activityDivergenceCount : null,
749
+ activityDivergenceRecentSamples: memStats.activityDivergenceRecentSamples || [],
750
+ };
751
+ Object.assign(statsResp, diagnosticFields);
752
+ }
753
+ sendTo(ws, statsResp);
709
754
  return true;
710
755
  }
711
756
 
@@ -733,8 +778,13 @@ function attachSessions(ctx) {
733
778
  if (msg.type === "kill_process") {
734
779
  // Restrict to admins in multi-user mode — any user could otherwise SIGTERM
735
780
  // another user's running claude subprocess (lr-eb1a).
736
- if (!ws._clayUser || ws._clayUser.role !== "admin") {
737
- sendTo(ws, { type: "error", message: "Admin access required" });
781
+ if (!ws._clagenticUser || ws._clagenticUser.role !== "admin") {
782
+ // lr-93e3c8 (fnd-66af4e, item 7): app-messages.js's client-side
783
+ // `error` handler reads msg.text (addSystemMessage(msg.text, true)),
784
+ // not msg.message -- both admin-gate rejections in this file used
785
+ // to send `message:`, so the frame arrived client-side but rendered
786
+ // as addSystemMessage(undefined, true), effectively swallowed.
787
+ sendTo(ws, { type: "error", text: "Admin access required" });
738
788
  return true;
739
789
  }
740
790
  var pid = msg.pid;
@@ -1197,7 +1247,7 @@ function attachSessions(ctx) {
1197
1247
  return cliSess.readCliSessionHistory(cwd, result.sessionId).then(function(history) {
1198
1248
  var forked = sm.resumeSession(result.sessionId, { history: history, title: forkTitle }, ws);
1199
1249
  if (forked) {
1200
- ws._clayActiveSession = forked.localId;
1250
+ ws._clagenticActiveSession = forked.localId;
1201
1251
  sendTo(ws, { type: "fork_complete", sessionId: forked.localId });
1202
1252
  }
1203
1253
  });
@@ -1277,13 +1327,13 @@ function attachSessions(ctx) {
1277
1327
  }
1278
1328
 
1279
1329
  if (msg.type === "input_sync") {
1280
- sendToSessionOthers(ws, ws._clayActiveSession, msg);
1330
+ sendToSessionOthers(ws, ws._clagenticActiveSession, msg);
1281
1331
  return true;
1282
1332
  }
1283
1333
 
1284
1334
  if (msg.type === "cursor_move" || msg.type === "cursor_leave" || msg.type === "text_select") {
1285
- if (!ws._clayUser) return true;
1286
- var u = ws._clayUser;
1335
+ if (!ws._clagenticUser) return true;
1336
+ var u = ws._clagenticUser;
1287
1337
  var p = u.profile || {};
1288
1338
  var cursorMsg = {
1289
1339
  type: msg.type,
@@ -1301,7 +1351,7 @@ function attachSessions(ctx) {
1301
1351
  if (msg.type === "text_select") {
1302
1352
  cursorMsg.ranges = msg.ranges || [];
1303
1353
  }
1304
- sendToSessionOthers(ws, ws._clayActiveSession, cursorMsg);
1354
+ sendToSessionOthers(ws, ws._clagenticActiveSession, cursorMsg);
1305
1355
  return true;
1306
1356
  }
1307
1357
 
@@ -1481,8 +1531,8 @@ function attachSessions(ctx) {
1481
1531
  var rawPath = (msg.path || "").replace(/^~/, require("./config").REAL_HOME);
1482
1532
  var absTarget = path.resolve(rawPath);
1483
1533
  // Multi-user mode: non-admins can only browse their home directory
1484
- if (osUsers && osUsers.length > 0 && ws._clayUser && ws._clayUser.role !== "admin") {
1485
- var browseHome = ws._clayUser.linuxUser ? "/home/" + ws._clayUser.linuxUser : null;
1534
+ if (osUsers && osUsers.length > 0 && ws._clagenticUser && ws._clagenticUser.role !== "admin") {
1535
+ var browseHome = ws._clagenticUser.linuxUser ? "/home/" + ws._clagenticUser.linuxUser : null;
1486
1536
  if (!browseHome || (absTarget !== browseHome && (absTarget + "/").indexOf(browseHome + "/") !== 0)) {
1487
1537
  sendTo(ws, { type: "browse_dir_result", path: msg.path, entries: [], error: "Access restricted to your home directory" });
1488
1538
  return true;
@@ -1528,12 +1578,12 @@ function attachSessions(ctx) {
1528
1578
  var addPath = (msg.path || "").replace(/^~/, require("./config").REAL_HOME);
1529
1579
  var addAbs = path.resolve(addPath);
1530
1580
  // Multi-user mode: normal users restricted to their home directory
1531
- if (osUsers && osUsers.length > 0 && ws._clayUser && ws._clayUser.role !== "admin") {
1532
- if (!ws._clayUser.linuxUser) {
1581
+ if (osUsers && osUsers.length > 0 && ws._clagenticUser && ws._clagenticUser.role !== "admin") {
1582
+ if (!ws._clagenticUser.linuxUser) {
1533
1583
  sendTo(ws, { type: "add_project_result", ok: false, error: "No Linux user assigned" });
1534
1584
  return true;
1535
1585
  }
1536
- var userHome = "/home/" + ws._clayUser.linuxUser;
1586
+ var userHome = "/home/" + ws._clagenticUser.linuxUser;
1537
1587
  if (addAbs !== userHome && (addAbs + "/").indexOf(userHome + "/") !== 0) {
1538
1588
  sendTo(ws, { type: "add_project_result", ok: false, error: "Path not allowed. You can only add directories under " + userHome });
1539
1589
  return true;
@@ -1550,7 +1600,7 @@ function attachSessions(ctx) {
1550
1600
  return true;
1551
1601
  }
1552
1602
  if (typeof opts.onAddProject === "function") {
1553
- var result = opts.onAddProject(addAbs, ws._clayUser);
1603
+ var result = opts.onAddProject(addAbs, ws._clagenticUser);
1554
1604
  sendTo(ws, { type: "add_project_result", ok: result.ok, slug: result.slug, error: result.error, existing: result.existing });
1555
1605
  } else {
1556
1606
  sendTo(ws, { type: "add_project_result", ok: false, error: "Not supported" });
@@ -1560,8 +1610,8 @@ function attachSessions(ctx) {
1560
1610
 
1561
1611
  // --- Create new empty project ---
1562
1612
  if (msg.type === "create_project" || msg.type === "clone_project") {
1563
- if (ws._clayUser) {
1564
- var cpPerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
1613
+ if (ws._clagenticUser) {
1614
+ var cpPerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
1565
1615
  if (!cpPerms.createProject) {
1566
1616
  sendTo(ws, { type: "add_project_result", ok: false, error: "You do not have permission to create projects" });
1567
1617
  return true;
@@ -1575,7 +1625,7 @@ function attachSessions(ctx) {
1575
1625
  return true;
1576
1626
  }
1577
1627
  if (typeof opts.onCreateProject === "function") {
1578
- var createResult = opts.onCreateProject(createName, ws._clayUser);
1628
+ var createResult = opts.onCreateProject(createName, ws._clagenticUser);
1579
1629
  sendTo(ws, { type: "add_project_result", ok: createResult.ok, slug: createResult.slug, error: createResult.error });
1580
1630
  } else {
1581
1631
  sendTo(ws, { type: "add_project_result", ok: false, error: "Not supported" });
@@ -1592,7 +1642,7 @@ function attachSessions(ctx) {
1592
1642
  }
1593
1643
  sendTo(ws, { type: "clone_project_progress", status: "cloning" });
1594
1644
  if (typeof opts.onCloneProject === "function") {
1595
- opts.onCloneProject(cloneUrl, ws._clayUser, function (cloneResult) {
1645
+ opts.onCloneProject(cloneUrl, ws._clagenticUser, function (cloneResult) {
1596
1646
  sendTo(ws, { type: "add_project_result", ok: cloneResult.ok, slug: cloneResult.slug, error: cloneResult.error });
1597
1647
  });
1598
1648
  } else {
@@ -1633,8 +1683,8 @@ function attachSessions(ctx) {
1633
1683
 
1634
1684
  // --- Remove project from web UI ---
1635
1685
  if (msg.type === "remove_project") {
1636
- if (ws._clayUser) {
1637
- var dpPerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
1686
+ if (ws._clagenticUser) {
1687
+ var dpPerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
1638
1688
  if (!dpPerms.deleteProject) {
1639
1689
  sendTo(ws, { type: "remove_project_result", ok: false, error: "You do not have permission to delete projects" });
1640
1690
  return true;
@@ -1657,7 +1707,7 @@ function attachSessions(ctx) {
1657
1707
  // returned by removeWorktree) was silently discarded: the client
1658
1708
  // was told removal succeeded while the worktree stayed on disk
1659
1709
  // (lr-fc2818).
1660
- var removeUserId = ws._clayUser ? ws._clayUser.id : null;
1710
+ var removeUserId = ws._clagenticUser ? ws._clagenticUser.id : null;
1661
1711
  var removeResult = opts.onRemoveProject(removeSlug, removeUserId) || {};
1662
1712
  sendTo(ws, { type: "remove_project_result", ok: removeResult.ok !== false, slug: removeSlug, error: removeResult.error });
1663
1713
  } else {
@@ -1668,8 +1718,8 @@ function attachSessions(ctx) {
1668
1718
 
1669
1719
  // --- Move a single schedule to another project ---
1670
1720
  if (msg.type === "schedule_move") {
1671
- if (ws._clayUser) {
1672
- var schMovePerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
1721
+ if (ws._clagenticUser) {
1722
+ var schMovePerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
1673
1723
  if (!schMovePerms.scheduledTasks) {
1674
1724
  sendTo(ws, { type: "error", text: "Scheduled tasks access is not permitted" });
1675
1725
  return true;
@@ -1824,16 +1874,24 @@ function attachSessions(ctx) {
1824
1874
  msg.type === "set_tokens_per_mb_headroom" ||
1825
1875
  msg.type === "set_lite_auto_enroll" ||
1826
1876
  msg.type === "shutdown_server" || msg.type === "restart_server") {
1827
- var _wsUser = ws._clayUser;
1877
+ var _wsUser = ws._clagenticUser;
1828
1878
  if (!_wsUser || _wsUser.role !== "admin") {
1829
- sendTo(ws, { type: "error", message: "Admin access required" });
1879
+ // lr-93e3c8 (fnd-66af4e, item 7): app-messages.js's client-side
1880
+ // `error` handler reads msg.text (addSystemMessage(msg.text, true)),
1881
+ // not msg.message -- both admin-gate rejections in this file used
1882
+ // to send `message:`, so the frame arrived client-side but rendered
1883
+ // as addSystemMessage(undefined, true), effectively swallowed.
1884
+ sendTo(ws, { type: "error", text: "Admin access required" });
1830
1885
  return true;
1831
1886
  }
1832
1887
  }
1833
1888
 
1834
1889
  if (msg.type === "get_daemon_config") {
1835
1890
  if (typeof opts.onGetDaemonConfig === "function") {
1836
- var daemonConfig = opts.onGetDaemonConfig();
1891
+ // lr-20e71c: ws._clagenticEffectiveProtocol was resolved once at WS-upgrade
1892
+ // time (server.js), where X-Forwarded-Proto is still in scope — this
1893
+ // per-message dispatch only has ws/msg, not the original req.
1894
+ var daemonConfig = opts.onGetDaemonConfig(ws._clagenticEffectiveProtocol);
1837
1895
  sendTo(ws, { type: "daemon_config", config: daemonConfig });
1838
1896
  }
1839
1897
  return true;
@@ -1888,8 +1946,14 @@ function attachSessions(ctx) {
1888
1946
  if (msg.type === "set_mem_available_threshold") {
1889
1947
  if (typeof opts.onSetMemAvailableThreshold === "function") {
1890
1948
  var matResult = opts.onSetMemAvailableThreshold(msg.value);
1891
- sendTo(ws, { type: "set_mem_available_threshold_result", ok: matResult.ok, memAvailableMinMB: matResult.memAvailableMinMB });
1892
- send({ type: "mem_available_threshold_changed", memAvailableMinMB: matResult.memAvailableMinMB });
1949
+ sendTo(ws, { type: "set_mem_available_threshold_result", ok: matResult.ok, memAvailableMinMB: matResult.memAvailableMinMB, error: matResult.error });
1950
+ // lr-93e3c8 (item 6): only broadcast "changed" on an actual change —
1951
+ // onSetMemAvailableThreshold now rejects (ok:false) instead of
1952
+ // silently substituting a value, so a rejected edit must not tell
1953
+ // every other connected client the value changed when it didn't.
1954
+ if (matResult.ok) {
1955
+ send({ type: "mem_available_threshold_changed", memAvailableMinMB: matResult.memAvailableMinMB });
1956
+ }
1893
1957
  }
1894
1958
  return true;
1895
1959
  }
@@ -1897,8 +1961,11 @@ function attachSessions(ctx) {
1897
1961
  if (msg.type === "set_tokens_per_mb_headroom") {
1898
1962
  if (typeof opts.onSetTokensPerMbHeadroom === "function") {
1899
1963
  var tpmResult = opts.onSetTokensPerMbHeadroom(msg.value);
1900
- sendTo(ws, { type: "set_tokens_per_mb_headroom_result", ok: tpmResult.ok, tokensPerMbHeadroom: tpmResult.tokensPerMbHeadroom });
1901
- send({ type: "tokens_per_mb_headroom_changed", tokensPerMbHeadroom: tpmResult.tokensPerMbHeadroom });
1964
+ sendTo(ws, { type: "set_tokens_per_mb_headroom_result", ok: tpmResult.ok, tokensPerMbHeadroom: tpmResult.tokensPerMbHeadroom, error: tpmResult.error });
1965
+ // See comment on set_mem_available_threshold above — same reasoning.
1966
+ if (tpmResult.ok) {
1967
+ send({ type: "tokens_per_mb_headroom_changed", tokensPerMbHeadroom: tpmResult.tokensPerMbHeadroom });
1968
+ }
1902
1969
  }
1903
1970
  return true;
1904
1971
  }
@@ -1984,5 +2051,8 @@ function attachSessions(ctx) {
1984
2051
  };
1985
2052
  }
1986
2053
 
1987
- module.exports = { attachSessions: attachSessions };
2054
+ module.exports = {
2055
+ attachSessions: attachSessions,
2056
+ PROCESS_STATS_BASE_FIELD_KEYS: PROCESS_STATS_BASE_FIELD_KEYS,
2057
+ };
1988
2058
 
@@ -36,15 +36,15 @@ function attachUserMention(ctx) {
36
36
  }
37
37
 
38
38
  function resolveSenderName(ws) {
39
- if (!ws._clayUser) return "Someone";
40
- var u = ws._clayUser;
39
+ if (!ws._clagenticUser) return "Someone";
40
+ var u = ws._clagenticUser;
41
41
  var p = u.profile || {};
42
42
  return p.name || u.displayName || u.username || "Someone";
43
43
  }
44
44
 
45
45
  function resolveSenderAvatar(ws) {
46
- if (!ws._clayUser) return null;
47
- var u = ws._clayUser;
46
+ if (!ws._clagenticUser) return null;
47
+ var u = ws._clagenticUser;
48
48
  var p = u.profile || {};
49
49
  return {
50
50
  style: p.avatarStyle || "thumbs",
@@ -80,11 +80,11 @@ function attachUserMention(ctx) {
80
80
  var session = getSessionForWs(ws);
81
81
  if (!session) return;
82
82
 
83
- if (!ws._clayUser) {
83
+ if (!ws._clagenticUser) {
84
84
  sendTo(ws, { type: "user_mention_error", error: "You must be signed in to mention another user." });
85
85
  return;
86
86
  }
87
- if (ws._clayUser.id === msg.targetUserId) {
87
+ if (ws._clagenticUser.id === msg.targetUserId) {
88
88
  sendTo(ws, { type: "user_mention_error", error: "You cannot mention yourself." });
89
89
  return;
90
90
  }
@@ -95,7 +95,7 @@ function attachUserMention(ctx) {
95
95
  return;
96
96
  }
97
97
 
98
- var fromId = ws._clayUser.id;
98
+ var fromId = ws._clagenticUser.id;
99
99
  var fromName = resolveSenderName(ws);
100
100
  var fromAvatar = resolveSenderAvatar(ws) || {};
101
101
 
@@ -184,8 +184,8 @@ function attachUserMessage(ctx) {
184
184
 
185
185
  // --- Web terminal ---
186
186
  if (msg.type === "term_create") {
187
- if (ws._clayUser) {
188
- var termPerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
187
+ if (ws._clagenticUser) {
188
+ var termPerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
189
189
  if (!termPerms.terminal) {
190
190
  sendTo(ws, { type: "term_error", error: "Terminal access is not permitted" });
191
191
  return true;
@@ -234,7 +234,7 @@ function attachUserMessage(ctx) {
234
234
  tm.close(msg.id, ws);
235
235
  broadcastTermList();
236
236
  // Remove closed terminal from context sources
237
- var _termSessionId = ws._clayActiveSession || null;
237
+ var _termSessionId = ws._clagenticActiveSession || null;
238
238
  var saved = loadContextSources(slug, _termSessionId);
239
239
  var termKey = "term:" + msg.id;
240
240
  var filtered = saved.filter(function(id) { return id !== termKey; });
@@ -265,7 +265,7 @@ function attachUserMessage(ctx) {
265
265
  var tid = parseInt(srcId.split(":")[1], 10);
266
266
  return tm.getScrollback(tid, ws) !== null;
267
267
  });
268
- var _saveSessionId = ws._clayActiveSession || null;
268
+ var _saveSessionId = ws._clagenticActiveSession || null;
269
269
  saveContextSources(slug, _saveSessionId, activeIds);
270
270
  return true;
271
271
  }
@@ -299,8 +299,8 @@ function attachUserMessage(ctx) {
299
299
  msg.type === "loop_registry_remove" || msg.type === "loop_registry_convert" ||
300
300
  msg.type === "loop_registry_toggle" || msg.type === "loop_registry_rerun" ||
301
301
  msg.type === "schedule_create" || msg.type === "schedule_move") {
302
- if (ws._clayUser) {
303
- var schPerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
302
+ if (ws._clagenticUser) {
303
+ var schPerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
304
304
  if (!schPerms.scheduledTasks) {
305
305
  sendTo(ws, { type: "error", text: "Scheduled tasks access is not permitted" });
306
306
  return true;
@@ -375,8 +375,8 @@ function attachUserMessage(ctx) {
375
375
  }
376
376
 
377
377
  // Backfill ownerId for legacy sessions restored without one (multi-user only)
378
- if (!session.ownerId && ws._clayUser) {
379
- session.ownerId = ws._clayUser.id;
378
+ if (!session.ownerId && ws._clagenticUser) {
379
+ session.ownerId = ws._clagenticUser.id;
380
380
  sm.saveSessionFile(session);
381
381
  }
382
382
 
@@ -384,9 +384,9 @@ function attachUserMessage(ctx) {
384
384
 
385
385
  var userMsg2 = { type: "user_message", text: msg.text || "" };
386
386
  // Attach sender info for multi-user attribution (backward-compatible: old clients ignore these)
387
- if (ws._clayUser) {
388
- userMsg2.from = ws._clayUser.id;
389
- userMsg2.fromName = ws._clayUser.displayName || ws._clayUser.username || "";
387
+ if (ws._clagenticUser) {
388
+ userMsg2.from = ws._clagenticUser.id;
389
+ userMsg2.fromName = ws._clagenticUser.displayName || ws._clagenticUser.username || "";
390
390
  }
391
391
  var savedImagePaths = [];
392
392
  if (msg.images && msg.images.length > 0) {