@clagentic/console 1.9.0-beta.1 → 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.
Files changed (61) hide show
  1. package/bin/cli.js +23 -1
  2. package/lib/agents.js +13 -3
  3. package/lib/build-sha.json +2 -2
  4. package/lib/cli/ipc-subcommands.js +84 -4
  5. package/lib/daemon.js +111 -7
  6. package/lib/effective-protocol.js +82 -0
  7. package/lib/project-connection.js +21 -8
  8. package/lib/project-filesystem.js +4 -4
  9. package/lib/project-http.js +4 -4
  10. package/lib/project-loop.js +49 -5
  11. package/lib/project-sessions.js +166 -68
  12. package/lib/project-user-mention.js +7 -7
  13. package/lib/project-user-message.js +81 -14
  14. package/lib/project.js +28 -22
  15. package/lib/public/app.js +18 -4
  16. package/lib/public/css/base.css +14 -0
  17. package/lib/public/css/filebrowser.css +6 -0
  18. package/lib/public/css/home-hub.css +28 -8
  19. package/lib/public/css/icon-strip.css +17 -0
  20. package/lib/public/css/messages.css +11 -0
  21. package/lib/public/css/mobile-nav.css +22 -0
  22. package/lib/public/css/server-settings.css +9 -0
  23. package/lib/public/css/sidebar.css +15 -0
  24. package/lib/public/css/title-bar.css +10 -1
  25. package/lib/public/index.html +9 -2
  26. package/lib/public/modules/activity-latch.js +45 -0
  27. package/lib/public/modules/activity-state.js +195 -0
  28. package/lib/public/modules/app-connection.js +31 -6
  29. package/lib/public/modules/app-favicon.js +75 -1
  30. package/lib/public/modules/app-home-hub.js +14 -11
  31. package/lib/public/modules/app-loop-ui.js +86 -2
  32. package/lib/public/modules/app-messages.js +178 -54
  33. package/lib/public/modules/app-panels.js +91 -32
  34. package/lib/public/modules/app-projects.js +46 -9
  35. package/lib/public/modules/app-rate-limit.js +13 -1
  36. package/lib/public/modules/server-settings.js +256 -21
  37. package/lib/public/modules/sidebar-mobile.js +32 -22
  38. package/lib/public/modules/sidebar-projects.js +42 -14
  39. package/lib/public/modules/sidebar-sessions.js +168 -48
  40. package/lib/public/modules/theme.js +2 -2
  41. package/lib/public/modules/tools.js +11 -39
  42. package/lib/sdk-bridge.js +375 -33
  43. package/lib/sdk-message-processor.js +98 -15
  44. package/lib/sdk-skill-discovery.js +46 -6
  45. package/lib/sdk-slash-enrichment.js +5 -2
  46. package/lib/server-dm.js +5 -5
  47. package/lib/server-hub-sessions.js +70 -0
  48. package/lib/server.js +78 -43
  49. package/lib/session-activity.js +9 -2
  50. package/lib/sessions.js +64 -18
  51. package/lib/smtp.js +10 -1
  52. package/lib/terminal-manager.js +6 -6
  53. package/lib/ws-schema.js +16 -0
  54. package/lib/yoke/adapters/claude.js +7 -1
  55. package/lib/yoke/adapters/codex.js +219 -31
  56. package/package.json +2 -2
  57. package/scripts/check-test-count.js +397 -0
  58. package/scripts/test-file-completion-reporter.js +43 -0
  59. package/scripts/verify-installed-build.js +242 -15
  60. package/lib/model-context-windows.js +0 -74
  61. package/lib/public/modules/model-context-windows.js +0 -71
@@ -769,11 +769,31 @@ function attachLoop(ctx) {
769
769
  var lastCoderSession = sm.sessions.get(loopState.currentSessionId);
770
770
  if (lastCoderSession) {
771
771
  lastCoderSession.singleTurn = false;
772
- lastCoderSession.loop.active = false;
773
772
  _loopOwnerUserId = lastCoderSession.ownerId || null;
774
773
  }
775
774
  }
776
775
 
776
+ // lr-fd38ac: clear the stale-resumability marker on EVERY session that
777
+ // belongs to this loop run, not just the last coder session. Four
778
+ // writers set `session.loop.active = true` (coder at runNextIteration(),
779
+ // judge at runJudge(), crafting at the two wizard-crafting sites) — every
780
+ // judge session and every prior iteration's coder session was left
781
+ // permanently orphaned at active:true, and the one session this used to
782
+ // fix reverted across a daemon restart because the clear was never
783
+ // persisted (sessions.js:109 writes session.loop into the on-disk meta
784
+ // line; sessions.js:711 rehydrates it — an in-memory-only clear never
785
+ // reaches either). Persist the clear on each session so it survives a
786
+ // restart and so switching into ANY finished loop session (coder, judge,
787
+ // any iteration) is resumable, not just the last one.
788
+ if (loopState.loopId) {
789
+ sm.sessions.forEach(function (s) {
790
+ if (s && s.loop && s.loop.loopId === loopState.loopId && s.loop.active) {
791
+ s.loop.active = false;
792
+ sm.saveSessionFile(s);
793
+ }
794
+ });
795
+ }
796
+
777
797
  loopState.active = false;
778
798
  loopState.phase = "done";
779
799
  loopState.stopping = false;
@@ -956,6 +976,23 @@ function attachLoop(ctx) {
956
976
  // lr-e31b: Queue a human message for delivery at the next iteration
957
977
  // boundary. See the comment in runNextIteration() for why this is
958
978
  // boundary-delivered rather than injected into the live iteration.
979
+ //
980
+ // lr-6fe5fc: this gate and the client's queue-mode UI gate
981
+ // (isLoopQueueSession() in app-loop-ui.js) are intentionally NOT the
982
+ // same predicate. This one answers "does the project have a running
983
+ // loop that will accept a queued message at all" — loopState.active
984
+ // alone, since pendingUserMessages is a single project-wide queue
985
+ // delivered at the next iteration boundary regardless of which session
986
+ // sent the WS message (loop_message carries no sessionId — see
987
+ // input.js). The client's gate additionally requires the loop's
988
+ // current session to be the one actually being viewed, which is a UX
989
+ // constraint (don't claim "queued for the next iteration" on a session
990
+ // that has nothing to do with that queue) this server-side accept
991
+ // check has no need to enforce, since it is already correctly scoped
992
+ // to the one loop this project can run at a time. Collapsing these
993
+ // into one shared function would misrepresent one of the two questions
994
+ // as the other; each stays the single authority for what it actually
995
+ // answers.
959
996
  if (msg.type === "loop_message") {
960
997
  if (!loopState.active) {
961
998
  sendTo(ws, { type: "loop_message_error", text: "No loop is currently running." });
@@ -981,9 +1018,9 @@ function attachLoop(ctx) {
981
1018
  // for removal (loop_message_remove below) independent of its array
982
1019
  // position, which shifts as other messages are queued/delivered.
983
1020
  var _lmEntry = { id: crypto.randomBytes(8).toString("hex"), text: _lmText, ts: Date.now() };
984
- if (ws && ws._clayUser) {
985
- _lmEntry.from = ws._clayUser.id;
986
- _lmEntry.fromName = ws._clayUser.displayName || ws._clayUser.username || "";
1021
+ if (ws && ws._clagenticUser) {
1022
+ _lmEntry.from = ws._clagenticUser.id;
1023
+ _lmEntry.fromName = ws._clagenticUser.displayName || ws._clagenticUser.username || "";
987
1024
  }
988
1025
  loopState.pendingUserMessages.push(_lmEntry);
989
1026
  saveLoopState();
@@ -1365,7 +1402,8 @@ function attachLoop(ctx) {
1365
1402
  // connected (most-recently-active) project crowded out the genuinely most
1366
1403
  // recent sessions overall. getAllProjectSessions returns annotated shallow
1367
1404
  // copies carrying _projectSlug/_projectTitle/_projectIcon for every project.
1368
- var allSessions = getAllProjectSessions ? getAllProjectSessions(true) : [];
1405
+ var hubUserId = ws._clagenticUser ? ws._clagenticUser.id : null;
1406
+ var allSessions = getAllProjectSessions ? getAllProjectSessions(true, hubUserId) : [];
1369
1407
  // Sort newest-first by lastActivity
1370
1408
  allSessions.sort(function (a, b) {
1371
1409
  return (b.lastActivity || b.createdAt || 0) - (a.lastActivity || a.createdAt || 0);
@@ -1393,6 +1431,12 @@ function attachLoop(ctx) {
1393
1431
  // state on this field so only the actually-notifying session's
1394
1432
  // row lights up, not every sibling row in the same project.
1395
1433
  unread: getSessionUnread(ws, sessProjectSlug, s.localId),
1434
+ // lr-66c118: multi-user activity tone. ownerId was already on the
1435
+ // session object (createSession) but never projected onto this
1436
+ // wire shape — the frontend derivation module (activity-state.js)
1437
+ // needs it to distinguish "my activity" from "another user's
1438
+ // activity" the same way session_list already does.
1439
+ ownerId: s.ownerId || null,
1396
1440
  };
1397
1441
  });
1398
1442
  sendTo(ws, { type: "hub_recent_sessions", sessions: mapped });
@@ -11,9 +11,25 @@ var sessionActivity = require("./session-activity");
11
11
  // Kick off SDK agent discovery in the background at module load.
12
12
  // Errors are swallowed inside refresh(); the cache starts empty and fills
13
13
  // when the SDK subprocess completes initialization (~9s on this box).
14
- agentsModule.refresh().catch(function (e) {
15
- console.error("[project-sessions] initial agent refresh failed:", e && e.message ? e.message : e);
16
- });
14
+ //
15
+ // lr-795882: skipped under `node --test` (NODE_TEST_CONTEXT is set natively
16
+ // by the test runner itself — not a project-invented flag). This module is
17
+ // required, directly or transitively via lib/project.js, by ~18 test files;
18
+ // none of them exercise agent discovery, so this was spawning a real
19
+ // @anthropic-ai/claude-agent-sdk subprocess purely as an unrequested
20
+ // module-load side effect on every full suite run. refresh()'s SDK session
21
+ // is aborted in a finally block (lib/agents.js) but the underlying process
22
+ // exit is deferred by the SDK's own internal debounce, so the spawned
23
+ // subprocess could still be alive — holding the event loop open — well
24
+ // after the module that triggered it finished loading. This was the root
25
+ // cause package.json's --test-force-exit was added to paper over (see
26
+ // 5c17b6d) and was never actually fixed, only masked. Tests that need real
27
+ // agent discovery call agentsModule.refresh() themselves explicitly.
28
+ if (!process.env.NODE_TEST_CONTEXT) {
29
+ agentsModule.refresh().catch(function (e) {
30
+ console.error("[project-sessions] initial agent refresh failed:", e && e.message ? e.message : e);
31
+ });
32
+ }
17
33
 
18
34
  // Format a user's answer to an ask_user_questions card as a plain user
19
35
  // message so the MCP path can feed it back to the agent on the next turn.
@@ -61,6 +77,28 @@ function formatAskUserAnswerAsMessage(input, answers) {
61
77
  * getUpdateChannel, setUpdateChannel,
62
78
  * getLatestVersion, setLatestVersion
63
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
+
64
102
  function attachSessions(ctx) {
65
103
  var cwd = ctx.cwd;
66
104
  var slug = ctx.slug;
@@ -111,7 +149,7 @@ function attachSessions(ctx) {
111
149
  function handleSessionsMessage(ws, msg) {
112
150
 
113
151
  if (msg.type === "push_subscribe") {
114
- var _pushUserId = ws._clayUser ? ws._clayUser.id : null;
152
+ var _pushUserId = ws._clagenticUser ? ws._clagenticUser.id : null;
115
153
  if (pushModule && msg.subscription) pushModule.addSubscription(msg.subscription, msg.replaceEndpoint, _pushUserId);
116
154
  return true;
117
155
  }
@@ -166,7 +204,7 @@ function attachSessions(ctx) {
166
204
 
167
205
  if (msg.type === "new_session") {
168
206
  var sessionOpts = {};
169
- if (ws._clayUser) sessionOpts.ownerId = ws._clayUser.id;
207
+ if (ws._clagenticUser) sessionOpts.ownerId = ws._clagenticUser.id;
170
208
  if (msg.sessionVisibility) sessionOpts.sessionVisibility = msg.sessionVisibility;
171
209
  if (msg.vendor) sessionOpts.vendor = msg.vendor;
172
210
  if (msg.agentName && typeof msg.agentName === "string") {
@@ -186,7 +224,7 @@ function attachSessions(ctx) {
186
224
  // session's in-progress choice instead of the actual saved default.
187
225
  newSess.model = sm._savedDefaultModel || null;
188
226
  newSess.permissionMode = sm._savedDefaultMode || null;
189
- ws._clayActiveSession = newSess.localId;
227
+ ws._clagenticActiveSession = newSess.localId;
190
228
  // Apply project-level email defaults to new session
191
229
  if (typeof ctx._email === "object" && ctx._email.getEmailDefaults) {
192
230
  var emailDefaults = ctx._email.getEmailDefaults();
@@ -196,7 +234,7 @@ function attachSessions(ctx) {
196
234
  sendTo(ws, { type: "context_sources_state", active: defaultSources });
197
235
  }
198
236
  }
199
- var nsPresKey = ws._clayUser ? ws._clayUser.id : "_default";
237
+ var nsPresKey = ws._clagenticUser ? ws._clagenticUser.id : "_default";
200
238
  userPresence.setPresence(slug, nsPresKey, newSess.localId, null);
201
239
  broadcastPresence();
202
240
  return true;
@@ -303,8 +341,8 @@ function attachSessions(ctx) {
303
341
  if (typeof msg.sessionId !== "number") return true;
304
342
  var agentTarget = sm.sessions.get(msg.sessionId);
305
343
  if (!agentTarget) return true;
306
- if (ws._clayUser) {
307
- 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;
308
346
  }
309
347
  var nextAgent = (msg.agentName && typeof msg.agentName === "string") ? msg.agentName : null;
310
348
  var prevAgent = agentTarget.agentName || null;
@@ -322,8 +360,8 @@ function attachSessions(ctx) {
322
360
  if (typeof msg.sessionId === "number" && (msg.visibility === "shared" || msg.visibility === "private")) {
323
361
  var visTarget = sm.sessions.get(msg.sessionId);
324
362
  if (!visTarget) return true;
325
- if (ws._clayUser) {
326
- 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;
327
365
  }
328
366
  sm.setSessionVisibility(msg.sessionId, msg.visibility);
329
367
  }
@@ -334,8 +372,8 @@ function attachSessions(ctx) {
334
372
  if (typeof msg.sessionId === "number") {
335
373
  var bookmarkTarget = sm.sessions.get(msg.sessionId);
336
374
  if (!bookmarkTarget) return true;
337
- if (ws._clayUser) {
338
- 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;
339
377
  }
340
378
  sm.setSessionBookmarked(msg.sessionId, !!msg.bookmarked);
341
379
  }
@@ -347,9 +385,9 @@ function attachSessions(ctx) {
347
385
  var source = sm.sessions.get(msg.sourceId);
348
386
  var target = sm.sessions.get(msg.targetId);
349
387
  if (!source || !target) return true;
350
- if (ws._clayUser) {
351
- if (!usersModule.canAccessSession(ws._clayUser.id, source, { visibility: "public" })) return true;
352
- 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;
353
391
  }
354
392
  sm.reorderBookmarkedSessions(msg.sourceId, msg.targetId, msg.insertBefore !== false);
355
393
  }
@@ -379,8 +417,8 @@ function attachSessions(ctx) {
379
417
  if (typeof bulkId !== "number") continue;
380
418
  var bulkTarget = sm.sessions.get(bulkId);
381
419
  if (!bulkTarget) continue;
382
- if (ws._clayUser) {
383
- 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;
384
422
  }
385
423
  deletableIds.push(bulkId);
386
424
  }
@@ -397,9 +435,9 @@ function attachSessions(ctx) {
397
435
  return true;
398
436
  }
399
437
  var projectOwnerId = getProjectOwnerId();
400
- var isAdmin = ws._clayUser && ws._clayUser.role === "admin";
401
- var isProjectOwner = ws._clayUser && projectOwnerId && ws._clayUser.id === projectOwnerId;
402
- 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)) {
403
441
  sendTo(ws, { type: "error", text: "Only project owners or admins can transfer ownership." });
404
442
  return true;
405
443
  }
@@ -469,10 +507,10 @@ function attachSessions(ctx) {
469
507
  }
470
508
  }
471
509
  var resumed = sm.resumeSession(msg.cliSessionId, { history: history, title: title, vendor: persistedVendor || undefined, allowedTools: persistedAllowedTools || undefined }, ws);
472
- if (resumed) ws._clayActiveSession = resumed.localId;
510
+ if (resumed) ws._clagenticActiveSession = resumed.localId;
473
511
  }).catch(function() {
474
512
  var resumed = sm.resumeSession(msg.cliSessionId, (persistedVendor || persistedAllowedTools) ? { vendor: persistedVendor, allowedTools: persistedAllowedTools } : undefined, ws);
475
- if (resumed) ws._clayActiveSession = resumed.localId;
513
+ if (resumed) ws._clagenticActiveSession = resumed.localId;
476
514
  });
477
515
  return true;
478
516
  }
@@ -544,11 +582,11 @@ function attachSessions(ctx) {
544
582
  }
545
583
  }
546
584
  // Check session access
547
- if (ws._clayUser) {
585
+ if (ws._clagenticUser) {
548
586
  var switchTarget = sm.sessions.get(msg.id);
549
- if (!usersModule.canAccessSession(ws._clayUser.id, switchTarget, { visibility: "public" })) return true;
587
+ if (!usersModule.canAccessSession(ws._clagenticUser.id, switchTarget, { visibility: "public" })) return true;
550
588
  }
551
- ws._clayActiveSession = msg.id;
589
+ ws._clagenticActiveSession = msg.id;
552
590
  sm.switchSession(msg.id, ws, hydrateImageRefs);
553
591
  broadcastPresence();
554
592
  // Send per-session context sources
@@ -568,15 +606,15 @@ function attachSessions(ctx) {
568
606
  var _swModel = sm.effectiveSessionModel(_swSess);
569
607
  var _swMode = (_swSess && _swSess.permissionMode) || sm.currentPermissionMode || "default";
570
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 });
571
- var swPresKey = ws._clayUser ? ws._clayUser.id : "_default";
609
+ var swPresKey = ws._clagenticUser ? ws._clagenticUser.id : "_default";
572
610
  userPresence.setPresence(slug, swPresKey, msg.id, null);
573
611
  }
574
612
  return true;
575
613
  }
576
614
 
577
615
  if (msg.type === "delete_session") {
578
- if (ws._clayUser) {
579
- var sdPerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
616
+ if (ws._clagenticUser) {
617
+ var sdPerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
580
618
  if (!sdPerms.sessionDelete) {
581
619
  sendTo(ws, { type: "error", text: "You do not have permission to delete sessions" });
582
620
  return true;
@@ -641,7 +679,7 @@ function attachSessions(ctx) {
641
679
  }
642
680
 
643
681
  if (msg.type === "update_now") {
644
- if (!ws._clayUser || ws._clayUser.role !== "admin") return true;
682
+ if (!ws._clagenticUser || ws._clagenticUser.role !== "admin") return true;
645
683
  send({ type: "update_started", version: getLatestVersion() || "" });
646
684
  var _ipc = require("./ipc");
647
685
  var _config = require("./config");
@@ -656,12 +694,27 @@ function attachSessions(ctx) {
656
694
  if (s.isProcessing) processingCount++;
657
695
  });
658
696
  var mem = process.memoryUsage();
659
- // lr-2d91: Include memory pressure fields so the admin panel can show
660
- // pressure building before the MemAvailable gate fires.
661
- var memStats = (sdk && typeof sdk.getMemoryStats === "function") ? sdk.getMemoryStats() : {};
662
697
  var memAvailMB = readMemAvailableMB();
663
- sendTo(ws, {
664
- 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 = {
665
718
  pid: process.pid,
666
719
  uptime: process.uptime(),
667
720
  memory: {
@@ -675,9 +728,29 @@ function attachSessions(ctx) {
675
728
  clients: clients.size,
676
729
  terminals: tm.list().length,
677
730
  memAvailableMB: memAvailMB,
678
- activeLiveCount: memStats.activeLiveCount !== undefined ? memStats.activeLiveCount : null,
679
- maxConcurrentSessions: memStats.maxConcurrentSessions !== undefined ? memStats.maxConcurrentSessions : null,
680
- });
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);
681
754
  return true;
682
755
  }
683
756
 
@@ -705,8 +778,13 @@ function attachSessions(ctx) {
705
778
  if (msg.type === "kill_process") {
706
779
  // Restrict to admins in multi-user mode — any user could otherwise SIGTERM
707
780
  // another user's running claude subprocess (lr-eb1a).
708
- if (!ws._clayUser || ws._clayUser.role !== "admin") {
709
- 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" });
710
788
  return true;
711
789
  }
712
790
  var pid = msg.pid;
@@ -1169,7 +1247,7 @@ function attachSessions(ctx) {
1169
1247
  return cliSess.readCliSessionHistory(cwd, result.sessionId).then(function(history) {
1170
1248
  var forked = sm.resumeSession(result.sessionId, { history: history, title: forkTitle }, ws);
1171
1249
  if (forked) {
1172
- ws._clayActiveSession = forked.localId;
1250
+ ws._clagenticActiveSession = forked.localId;
1173
1251
  sendTo(ws, { type: "fork_complete", sessionId: forked.localId });
1174
1252
  }
1175
1253
  });
@@ -1249,13 +1327,13 @@ function attachSessions(ctx) {
1249
1327
  }
1250
1328
 
1251
1329
  if (msg.type === "input_sync") {
1252
- sendToSessionOthers(ws, ws._clayActiveSession, msg);
1330
+ sendToSessionOthers(ws, ws._clagenticActiveSession, msg);
1253
1331
  return true;
1254
1332
  }
1255
1333
 
1256
1334
  if (msg.type === "cursor_move" || msg.type === "cursor_leave" || msg.type === "text_select") {
1257
- if (!ws._clayUser) return true;
1258
- var u = ws._clayUser;
1335
+ if (!ws._clagenticUser) return true;
1336
+ var u = ws._clagenticUser;
1259
1337
  var p = u.profile || {};
1260
1338
  var cursorMsg = {
1261
1339
  type: msg.type,
@@ -1273,7 +1351,7 @@ function attachSessions(ctx) {
1273
1351
  if (msg.type === "text_select") {
1274
1352
  cursorMsg.ranges = msg.ranges || [];
1275
1353
  }
1276
- sendToSessionOthers(ws, ws._clayActiveSession, cursorMsg);
1354
+ sendToSessionOthers(ws, ws._clagenticActiveSession, cursorMsg);
1277
1355
  return true;
1278
1356
  }
1279
1357
 
@@ -1453,8 +1531,8 @@ function attachSessions(ctx) {
1453
1531
  var rawPath = (msg.path || "").replace(/^~/, require("./config").REAL_HOME);
1454
1532
  var absTarget = path.resolve(rawPath);
1455
1533
  // Multi-user mode: non-admins can only browse their home directory
1456
- if (osUsers && osUsers.length > 0 && ws._clayUser && ws._clayUser.role !== "admin") {
1457
- 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;
1458
1536
  if (!browseHome || (absTarget !== browseHome && (absTarget + "/").indexOf(browseHome + "/") !== 0)) {
1459
1537
  sendTo(ws, { type: "browse_dir_result", path: msg.path, entries: [], error: "Access restricted to your home directory" });
1460
1538
  return true;
@@ -1500,12 +1578,12 @@ function attachSessions(ctx) {
1500
1578
  var addPath = (msg.path || "").replace(/^~/, require("./config").REAL_HOME);
1501
1579
  var addAbs = path.resolve(addPath);
1502
1580
  // Multi-user mode: normal users restricted to their home directory
1503
- if (osUsers && osUsers.length > 0 && ws._clayUser && ws._clayUser.role !== "admin") {
1504
- if (!ws._clayUser.linuxUser) {
1581
+ if (osUsers && osUsers.length > 0 && ws._clagenticUser && ws._clagenticUser.role !== "admin") {
1582
+ if (!ws._clagenticUser.linuxUser) {
1505
1583
  sendTo(ws, { type: "add_project_result", ok: false, error: "No Linux user assigned" });
1506
1584
  return true;
1507
1585
  }
1508
- var userHome = "/home/" + ws._clayUser.linuxUser;
1586
+ var userHome = "/home/" + ws._clagenticUser.linuxUser;
1509
1587
  if (addAbs !== userHome && (addAbs + "/").indexOf(userHome + "/") !== 0) {
1510
1588
  sendTo(ws, { type: "add_project_result", ok: false, error: "Path not allowed. You can only add directories under " + userHome });
1511
1589
  return true;
@@ -1522,7 +1600,7 @@ function attachSessions(ctx) {
1522
1600
  return true;
1523
1601
  }
1524
1602
  if (typeof opts.onAddProject === "function") {
1525
- var result = opts.onAddProject(addAbs, ws._clayUser);
1603
+ var result = opts.onAddProject(addAbs, ws._clagenticUser);
1526
1604
  sendTo(ws, { type: "add_project_result", ok: result.ok, slug: result.slug, error: result.error, existing: result.existing });
1527
1605
  } else {
1528
1606
  sendTo(ws, { type: "add_project_result", ok: false, error: "Not supported" });
@@ -1532,8 +1610,8 @@ function attachSessions(ctx) {
1532
1610
 
1533
1611
  // --- Create new empty project ---
1534
1612
  if (msg.type === "create_project" || msg.type === "clone_project") {
1535
- if (ws._clayUser) {
1536
- var cpPerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
1613
+ if (ws._clagenticUser) {
1614
+ var cpPerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
1537
1615
  if (!cpPerms.createProject) {
1538
1616
  sendTo(ws, { type: "add_project_result", ok: false, error: "You do not have permission to create projects" });
1539
1617
  return true;
@@ -1547,7 +1625,7 @@ function attachSessions(ctx) {
1547
1625
  return true;
1548
1626
  }
1549
1627
  if (typeof opts.onCreateProject === "function") {
1550
- var createResult = opts.onCreateProject(createName, ws._clayUser);
1628
+ var createResult = opts.onCreateProject(createName, ws._clagenticUser);
1551
1629
  sendTo(ws, { type: "add_project_result", ok: createResult.ok, slug: createResult.slug, error: createResult.error });
1552
1630
  } else {
1553
1631
  sendTo(ws, { type: "add_project_result", ok: false, error: "Not supported" });
@@ -1564,7 +1642,7 @@ function attachSessions(ctx) {
1564
1642
  }
1565
1643
  sendTo(ws, { type: "clone_project_progress", status: "cloning" });
1566
1644
  if (typeof opts.onCloneProject === "function") {
1567
- opts.onCloneProject(cloneUrl, ws._clayUser, function (cloneResult) {
1645
+ opts.onCloneProject(cloneUrl, ws._clagenticUser, function (cloneResult) {
1568
1646
  sendTo(ws, { type: "add_project_result", ok: cloneResult.ok, slug: cloneResult.slug, error: cloneResult.error });
1569
1647
  });
1570
1648
  } else {
@@ -1605,8 +1683,8 @@ function attachSessions(ctx) {
1605
1683
 
1606
1684
  // --- Remove project from web UI ---
1607
1685
  if (msg.type === "remove_project") {
1608
- if (ws._clayUser) {
1609
- var dpPerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
1686
+ if (ws._clagenticUser) {
1687
+ var dpPerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
1610
1688
  if (!dpPerms.deleteProject) {
1611
1689
  sendTo(ws, { type: "remove_project_result", ok: false, error: "You do not have permission to delete projects" });
1612
1690
  return true;
@@ -1629,7 +1707,7 @@ function attachSessions(ctx) {
1629
1707
  // returned by removeWorktree) was silently discarded: the client
1630
1708
  // was told removal succeeded while the worktree stayed on disk
1631
1709
  // (lr-fc2818).
1632
- var removeUserId = ws._clayUser ? ws._clayUser.id : null;
1710
+ var removeUserId = ws._clagenticUser ? ws._clagenticUser.id : null;
1633
1711
  var removeResult = opts.onRemoveProject(removeSlug, removeUserId) || {};
1634
1712
  sendTo(ws, { type: "remove_project_result", ok: removeResult.ok !== false, slug: removeSlug, error: removeResult.error });
1635
1713
  } else {
@@ -1640,8 +1718,8 @@ function attachSessions(ctx) {
1640
1718
 
1641
1719
  // --- Move a single schedule to another project ---
1642
1720
  if (msg.type === "schedule_move") {
1643
- if (ws._clayUser) {
1644
- var schMovePerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
1721
+ if (ws._clagenticUser) {
1722
+ var schMovePerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
1645
1723
  if (!schMovePerms.scheduledTasks) {
1646
1724
  sendTo(ws, { type: "error", text: "Scheduled tasks access is not permitted" });
1647
1725
  return true;
@@ -1796,16 +1874,24 @@ function attachSessions(ctx) {
1796
1874
  msg.type === "set_tokens_per_mb_headroom" ||
1797
1875
  msg.type === "set_lite_auto_enroll" ||
1798
1876
  msg.type === "shutdown_server" || msg.type === "restart_server") {
1799
- var _wsUser = ws._clayUser;
1877
+ var _wsUser = ws._clagenticUser;
1800
1878
  if (!_wsUser || _wsUser.role !== "admin") {
1801
- 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" });
1802
1885
  return true;
1803
1886
  }
1804
1887
  }
1805
1888
 
1806
1889
  if (msg.type === "get_daemon_config") {
1807
1890
  if (typeof opts.onGetDaemonConfig === "function") {
1808
- 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);
1809
1895
  sendTo(ws, { type: "daemon_config", config: daemonConfig });
1810
1896
  }
1811
1897
  return true;
@@ -1860,8 +1946,14 @@ function attachSessions(ctx) {
1860
1946
  if (msg.type === "set_mem_available_threshold") {
1861
1947
  if (typeof opts.onSetMemAvailableThreshold === "function") {
1862
1948
  var matResult = opts.onSetMemAvailableThreshold(msg.value);
1863
- sendTo(ws, { type: "set_mem_available_threshold_result", ok: matResult.ok, memAvailableMinMB: matResult.memAvailableMinMB });
1864
- 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
+ }
1865
1957
  }
1866
1958
  return true;
1867
1959
  }
@@ -1869,8 +1961,11 @@ function attachSessions(ctx) {
1869
1961
  if (msg.type === "set_tokens_per_mb_headroom") {
1870
1962
  if (typeof opts.onSetTokensPerMbHeadroom === "function") {
1871
1963
  var tpmResult = opts.onSetTokensPerMbHeadroom(msg.value);
1872
- sendTo(ws, { type: "set_tokens_per_mb_headroom_result", ok: tpmResult.ok, tokensPerMbHeadroom: tpmResult.tokensPerMbHeadroom });
1873
- 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
+ }
1874
1969
  }
1875
1970
  return true;
1876
1971
  }
@@ -1956,5 +2051,8 @@ function attachSessions(ctx) {
1956
2051
  };
1957
2052
  }
1958
2053
 
1959
- module.exports = { attachSessions: attachSessions };
2054
+ module.exports = {
2055
+ attachSessions: attachSessions,
2056
+ PROCESS_STATS_BASE_FIELD_KEYS: PROCESS_STATS_BASE_FIELD_KEYS,
2057
+ };
1960
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