@clagentic/console 1.8.0-beta.1 → 1.8.0-beta.2

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.
package/bin/cli.js CHANGED
@@ -283,9 +283,7 @@ var currentVersion = require("../package.json").version;
283
283
  if (headlessMode) {
284
284
  var protocol = config.tls ? "https" : "http";
285
285
  var ip = getLocalIP();
286
- var url = config.builtinCert
287
- ? toClayStudioUrl(ip, config.port, protocol)
288
- : protocol + "://" + ip + ":" + config.port;
286
+ var url = protocol + "://" + ip + ":" + config.port;
289
287
  console.log(" " + sym.done + " Daemon already running (PID " + config.pid + ")");
290
288
  console.log(" " + sym.done + " " + url);
291
289
  process.exit(0);
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "4669ffc3ce29de647a1cd498f9d78e0283459150",
3
- "writtenAt": "2026-07-17T20:17:41.853Z"
2
+ "sha": "c232fa900285c7f17d99d9ee419d7f806ccdec45",
3
+ "writtenAt": "2026-07-23T12:52:31.642Z"
4
4
  }
package/lib/cli/menus.js CHANGED
@@ -798,9 +798,7 @@ function showSettingsMenu(config, ip) {
798
798
  return;
799
799
  }
800
800
  var protocol = config.tls ? "https" : "http";
801
- var recoveryUrl = config.builtinCert
802
- ? toClayStudioUrl(ip, config.port, protocol) + "/recover/" + recoveryUrlPath
803
- : protocol + "://" + ip + ":" + config.port + "/recover/" + recoveryUrlPath;
801
+ var recoveryUrl = protocol + "://" + ip + ":" + config.port + "/recover/" + recoveryUrlPath;
804
802
  log(sym.bar);
805
803
  log(sym.bar + " " + a.yellow + sym.warn + " Admin Password Recovery" + a.reset);
806
804
  log(sym.bar);
@@ -35,7 +35,7 @@ function validateLoopId(id) {
35
35
  *
36
36
  * ctx fields:
37
37
  * cwd, slug, sm, sdk, send, sendTo, sendToSession, pushModule,
38
- * getHubSchedules, getAllProjectSessions, getStatus,
38
+ * getHubSchedules, getAllProjectSessions, getSessionUnread, getStatus,
39
39
  * getLinuxUserForSession, onProcessingChanged,
40
40
  * hydrateImageRefs
41
41
  */
@@ -51,6 +51,8 @@ function attachLoop(ctx) {
51
51
  var notificationsModule = ctx.notificationsModule;
52
52
  var getHubSchedules = ctx.getHubSchedules;
53
53
  var getAllProjectSessions = ctx.getAllProjectSessions;
54
+ // lr-0aa7b6: per-session unread lookup — (ws, sessionProjectSlug, localId) => count.
55
+ var getSessionUnread = ctx.getSessionUnread || function () { return 0; };
54
56
  var getStatus = ctx.getStatus;
55
57
  var getLinuxUserForSession = ctx.getLinuxUserForSession;
56
58
  var onProcessingChanged = ctx.onProcessingChanged;
@@ -1375,16 +1377,22 @@ function attachLoop(ctx) {
1375
1377
  // project-biased pool.
1376
1378
  var top = allSessions.slice(0, 10);
1377
1379
  var mapped = top.map(function (s) {
1380
+ var sessProjectSlug = s._projectSlug || slug;
1378
1381
  return {
1379
1382
  id: s.localId,
1380
1383
  title: s.title || "New Session",
1381
1384
  lastActivity: s.lastActivity || s.createdAt || 0,
1382
- projectSlug: s._projectSlug || slug,
1385
+ projectSlug: sessProjectSlug,
1383
1386
  projectTitle: s._projectTitle || slug,
1384
1387
  projectIcon: s._projectIcon || null,
1385
1388
  vendor: s.vendor || null,
1386
1389
  agentName: s.agentName || null,
1387
1390
  isProcessing: !!s.isProcessing,
1391
+ // lr-0aa7b6: THIS session's own unread count, not the project
1392
+ // aggregate — the client keys the merged status dot's alert(red)
1393
+ // state on this field so only the actually-notifying session's
1394
+ // row lights up, not every sibling row in the same project.
1395
+ unread: getSessionUnread(ws, sessProjectSlug, s.localId),
1388
1396
  };
1389
1397
  });
1390
1398
  sendTo(ws, { type: "hub_recent_sessions", sessions: mapped });
package/lib/project.js CHANGED
@@ -165,6 +165,11 @@ function createProjectContext(opts) {
165
165
  var getProjectList = opts.getProjectList || function () { return []; };
166
166
  var getAllProjectSessions = opts.getAllProjectSessions || function () { return []; };
167
167
  var getHubSchedules = opts.getHubSchedules || function () { return []; };
168
+ // lr-0aa7b6: per-session unread lookup consumed by the Home Hub Recent
169
+ // Sessions data path (project-loop.js hub_recent_sessions_list) to
170
+ // attribute alert state to the individual notifying session rather than
171
+ // the whole project.
172
+ var getSessionUnread = opts.getSessionUnread || function () { return 0; };
168
173
  var moveScheduleToProject = opts.moveScheduleToProject || function () { return { ok: false, error: "Not supported" }; };
169
174
  var moveAllSchedulesToProject = opts.moveAllSchedulesToProject || function () { return { ok: false, error: "Not supported" }; };
170
175
  var getScheduleCount = opts.getScheduleCount || function () { return 0; };
@@ -621,6 +626,7 @@ function createProjectContext(opts) {
621
626
  notificationsModule: _notifications,
622
627
  getHubSchedules: getHubSchedules,
623
628
  getAllProjectSessions: getAllProjectSessions,
629
+ getSessionUnread: getSessionUnread,
624
630
  getStatus: getStatus,
625
631
  getLinuxUserForSession: getLinuxUserForSession,
626
632
  onProcessingChanged: onProcessingChanged,
@@ -227,11 +227,24 @@ html, body {
227
227
  opacity: 1;
228
228
  transform: translateX(-50%) translateY(0);
229
229
  }
230
+ /* lr-136f81: --warning-bg / --error-12 are translucent tokens designed for
231
+ inline diagnostic badges sitting inside an already-opaque panel
232
+ (diagnostics.css:310-312). A position:fixed overlay toast has live chat
233
+ content behind it, so a translucent background lets that content bleed
234
+ through and the toast reads as malformed. Layer the tint over the opaque
235
+ --bg-alt toast surface instead of using the translucent token directly —
236
+ --warning-bg itself stays untouched so the diagnostic-badge use case is
237
+ unaffected. */
230
238
  .toast.toast-warn {
231
- background: var(--warning-bg);
239
+ background: linear-gradient(var(--warning-bg), var(--warning-bg)), var(--bg-alt);
232
240
  border-color: var(--warning);
233
241
  color: var(--warning);
234
242
  }
243
+ .toast.toast-error {
244
+ background: linear-gradient(var(--error-12), var(--error-12)), var(--bg-alt);
245
+ border-color: var(--error);
246
+ color: var(--error);
247
+ }
235
248
 
236
249
  /* SW update banner — shown when a new service worker activates while the page is visible */
237
250
  .sw-update-banner {
@@ -491,28 +491,40 @@
491
491
  opacity: 1;
492
492
  box-shadow: 0 0 6px rgba(80, 250, 123, 0.4);
493
493
  }
494
+ /* Alert state — color precedence LOCKED (andy, lr-0aa7b6):
495
+ alert(red) > processing(green) > live(green) > idle(grey). This class is
496
+ applied instead of .processing when the row's session is notifying, so
497
+ red always wins visually even if the session is also active. Same red
498
+ used by .icon-strip-project-badge (unread badge). Formerly a SEPARATE
499
+ right-side dot (.hub-recent-alert-dot, removed) — now just another color
500
+ state of the single left dot. */
501
+ .hub-recent-dot.alert {
502
+ background: #e74c3c;
503
+ opacity: 1;
504
+ box-shadow: 0 0 6px rgba(231, 76, 60, 0.5);
505
+ }
494
506
  .hub-recent-project-icon {
495
507
  font-size: 14px;
496
508
  width: 20px;
497
509
  text-align: center;
498
510
  flex-shrink: 0;
499
511
  }
500
- /* Per-project alert indicator — same red used by .icon-strip-project-badge
501
- (unread badge). A count wouldn't fit this row, so a plain dot is enough
502
- to show WHERE the alert is coming from. */
503
- .hub-recent-alert-dot {
504
- width: 6px;
505
- height: 6px;
506
- border-radius: 50%;
507
- flex-shrink: 0;
508
- background: #e74c3c;
509
- }
510
- .hub-recent-project-icon--blank {
512
+ /* Fallback badge for projects with no emoji/custom icon set — same "two
513
+ letters from the project name" abbreviation sidebar-projects.js and
514
+ sidebar-mobile.js render via getProjectAbbrev() for the identical
515
+ null-icon case (lr-e5faff), sized to fit the Recent Sessions row. */
516
+ .hub-recent-project-icon--abbrev {
511
517
  width: 20px;
512
518
  height: 20px;
513
519
  border-radius: 4px;
514
520
  background: rgba(var(--overlay-rgb), 0.08);
515
- display: inline-block;
521
+ display: inline-flex;
522
+ align-items: center;
523
+ justify-content: center;
524
+ font-size: 9px;
525
+ font-weight: 700;
526
+ letter-spacing: -0.2px;
527
+ color: var(--text-secondary);
516
528
  vertical-align: middle;
517
529
  }
518
530
  .hub-recent-title {
@@ -565,11 +577,16 @@
565
577
  #home-hub {
566
578
  padding: 32px 16px calc(80px + var(--safe-bottom, 0px));
567
579
  }
568
- .hub-greeting h1 {
569
- font-size: 22px;
570
- }
580
+ /* Close button (top:16px, 40px circle, right:20px) occupies the top-right
581
+ corner of #home-hub's padding box. Push the inner content down so the
582
+ search bar — full-width at this breakpoint — clears the button instead
583
+ of running underneath it (lr-ea6c65). */
571
584
  .home-hub-inner {
572
585
  max-width: 100%;
586
+ margin-top: 44px;
587
+ }
588
+ .hub-greeting h1 {
589
+ font-size: 22px;
573
590
  }
574
591
  .hub-columns {
575
592
  grid-template-columns: 1fr;
@@ -232,6 +232,20 @@ function fetchWsTicket() {
232
232
  .catch(function () { return { ticket: null }; });
233
233
  }
234
234
 
235
+ // Milliseconds to wait before re-verifying a single ws-ticket 401 (lr-e5c1fe).
236
+ var UNAUTH_RETRY_BACKOFF_MS = 400;
237
+
238
+ // lr-e5c1fe: a tab woken from background (visibilitychange / OS resume) can
239
+ // fire its first post-wake fetch before the browser has reattached cookies
240
+ // to outgoing requests — server-auth.js's getMultiUserFromReq() is a pure,
241
+ // synchronous cookie-header lookup with no server-side race of its own, so a
242
+ // 401 on /api/ws-ticket while the session cookie IS still valid can only be
243
+ // a client-side cookie-attachment gap on that one fetch, not a real session
244
+ // expiry. Treating a SINGLE such 401 as terminal showed the full-screen
245
+ // "session expired" wall on a session that "Sign in again" (a bare connect()
246
+ // re-run) then proved was still good. Re-verify once, after a short backoff,
247
+ // before declaring the session gone — only two consecutive 401s (auth
248
+ // actually confirmed absent) route to handleUnauthenticated().
235
249
  export function connect() {
236
250
  var ws = getWs();
237
251
  if (ws) { ws.onclose = null; ws.onmessage = null; ws.onerror = null; ws.close(); }
@@ -239,11 +253,20 @@ export function connect() {
239
253
 
240
254
  fetchWsTicket().then(function (result) {
241
255
  if (result.unauthenticated) {
242
- // Ticket fetch itself came back 401: the session is gone (expired /
243
- // revoked), not just cookie-less-on-upgrade. Route to sign-in instead
244
- // of opening a socket that would only 401 on the upgrade too — ties
245
- // into the Surface-1 unauth-vs-unreachable split below.
246
- handleUnauthenticated();
256
+ setTimeout(function () {
257
+ fetchWsTicket().then(function (retryResult) {
258
+ if (retryResult.unauthenticated) {
259
+ // Two consecutive 401s: auth is confirmed gone, not a transient
260
+ // wake-from-background cookie-attachment gap. Route to sign-in
261
+ // instead of opening a socket that would only 401 on the
262
+ // upgrade too — ties into the Surface-1 unauth-vs-unreachable
263
+ // split below.
264
+ handleUnauthenticated();
265
+ return;
266
+ }
267
+ openSocket(retryResult.ticket);
268
+ });
269
+ }, UNAUTH_RETRY_BACKOFF_MS);
247
270
  return;
248
271
  }
249
272
  openSocket(result.ticket);
@@ -362,8 +385,22 @@ export function scheduleReconnect() {
362
385
  // Check auth in parallel: if the server returns 401 while we're trying
363
386
  // to connect, route to the explicit unauthenticated state (lr-de5fcb
364
387
  // Surface 1) instead of silently reloading into a fresh reconnect loop.
388
+ // lr-e5c1fe: a single 401 here can be the same transient wake-from-
389
+ // background cookie-attachment gap fetchWsTicket() guards against in
390
+ // connect() — re-verify once before treating it as terminal, so this
391
+ // preflight can't independently fire the sign-in wall on a still-valid
392
+ // session out from under connect()'s own retry.
365
393
  fetch("/info").then(function (res) {
366
- if (res.status === 401) { handleUnauthenticated(); return null; }
394
+ if (res.status === 401) {
395
+ return new Promise(function (resolve) {
396
+ setTimeout(function () {
397
+ fetch("/info").then(function (retryRes) {
398
+ if (retryRes.status === 401) { handleUnauthenticated(); resolve(null); return; }
399
+ resolve(retryRes.ok ? retryRes.json().catch(function () { return null; }) : null);
400
+ }).catch(function () { resolve(null); });
401
+ }, UNAUTH_RETRY_BACKOFF_MS);
402
+ });
403
+ }
367
404
  return res.ok ? res.json().catch(function () { return null; }) : null;
368
405
  }).then(function (info) {
369
406
  if (info) checkStaleVersion(info);
@@ -6,6 +6,7 @@ import { getWs } from './ws-ref.js';
6
6
  import { escapeHtml, relativeTime } from './utils.js';
7
7
  import { switchProject, getCachedProjects, renderProjectList } from './app-projects.js';
8
8
  import { renderProjectIcon, projectIconHtml } from './project-icon.js';
9
+ import { getProjectAbbrev } from './sidebar-projects.js';
9
10
  import { openSchedulerToTab } from './scheduler.js';
10
11
  // playbook imports removed (Quick Start section removed from hub)
11
12
  import { exitDmMode } from './app-dm.js';
@@ -237,6 +238,12 @@ function formatScheduleTime(ts) {
237
238
  // renderProjectList() / app-projects.js and rendered as
238
239
  // .icon-strip-project-badge.has-unread / .hub-project-sessions elsewhere).
239
240
  // No separate alert data path — this is a read of the existing cache.
241
+ //
242
+ // This remains the PROJECT-LEVEL aggregate, intentionally — it still backs
243
+ // the Projects-list badge. It is NOT used for the Recent Sessions per-row
244
+ // dot below; that now keys off each session's own sess.unread (lr-0aa7b6),
245
+ // carried end-to-end from lib/server.js's per-session crossProjectUnread
246
+ // restructure through lib/project-loop.js's hub_recent_sessions_list.
240
247
  function projectHasAlert(projectSlug) {
241
248
  if (!projectSlug) return false;
242
249
  var projects = getCachedProjects();
@@ -451,29 +458,39 @@ export function handleHubRecentSessions(msg) {
451
458
  sessions.forEach(function (sess) {
452
459
  var item = document.createElement("div");
453
460
  item.className = "hub-recent-item";
454
- // projectIconHtml() routes custom (:slug:) icons to a safe <img> tag and
455
- // emoji to escaped text, replacing the raw escapeHtml(sess.projectIcon)
456
- // which showed ':slug:' as literal text (lr-a6da).
461
+ // projectIconHtml() -> safe <img>/escaped text (lr-a6da). No icon ->
462
+ // getProjectAbbrev() fallback, matching sidebar-projects.js /
463
+ // sidebar-mobile.js, instead of a blank slot (lr-e5faff).
457
464
  var iconHtml = sess.projectIcon
458
465
  ? '<span class="hub-recent-project-icon">' + projectIconHtml(sess.projectIcon) + '</span>'
459
- : '<span class="hub-recent-project-icon hub-recent-project-icon--blank"></span>';
466
+ : '<span class="hub-recent-project-icon hub-recent-project-icon--abbrev">' +
467
+ escapeHtml(getProjectAbbrev(sess.projectTitle || sess.projectSlug)) + '</span>';
460
468
  var timeStr = relativeTime(sess.lastActivity);
461
469
  var agentBadge = sess.agentName
462
470
  ? '<span class="hub-recent-agent">' + escapeHtml(sess.agentName) + '</span>'
463
471
  : '';
464
- var dotClass = "hub-recent-dot" + (sess.isProcessing ? " processing" : "");
465
- // Alert indicator: reuse the same per-project unread count that drives
466
- // the Projects-list badge (icon-strip-project-badge / hub-project-*),
467
- // rather than a new data path. A count won't fit this row, so render a
468
- // plain dot when the row's project has 1+ unresolved (unread) items.
469
- var alertHtml = projectHasAlert(sess.projectSlug)
470
- ? '<span class="hub-recent-alert-dot" title="Unread activity"></span>'
471
- : '';
472
+ // Single left status dot — color precedence LOCKED (andy, lr-0aa7b6):
473
+ // alert(red) > processing(green, pulsing) > live(green) > idle(grey).
474
+ // Alert wins over an active/processing session so the notification is
475
+ // always visible. Previously alert rendered as a SEPARATE right-side dot
476
+ // (.hub-recent-alert-dot); that's removed — alert is now just another
477
+ // color state of the one left dot.
478
+ //
479
+ // Alert state is keyed on THIS session's own unread count (sess.unread,
480
+ // populated server-side per-session — see hub_recent_sessions_list in
481
+ // lib/project-loop.js) — NOT the whole-project alert helper above. That
482
+ // per-project helper would light every sibling row in a notifying
483
+ // project's session list even when only one of them is actually
484
+ // notifying — that was the bug lr-0aa7b6 required fixing, not just
485
+ // documenting.
486
+ var hasAlert = (sess.unread || 0) > 0;
487
+ var dotClass = "hub-recent-dot" +
488
+ (hasAlert ? " alert" : (sess.isProcessing ? " processing" : ""));
489
+ var dotTitle = hasAlert ? "Unread activity" : (sess.isProcessing ? "Active" : "Idle");
472
490
  item.innerHTML =
473
- '<span class="' + dotClass + '"></span>' +
491
+ '<span class="' + dotClass + '" title="' + dotTitle + '"></span>' +
474
492
  iconHtml +
475
493
  '<span class="hub-recent-title">' + escapeHtml(sess.title) + '</span>' +
476
- alertHtml +
477
494
  agentBadge +
478
495
  '<span class="hub-recent-time">' + timeStr + '</span>';
479
496
  item.addEventListener("click", function () {
@@ -11,7 +11,11 @@ export function showToast(message, level, detail) {
11
11
  }
12
12
  document.body.appendChild(el);
13
13
  requestAnimationFrame(function () { el.classList.add("visible"); });
14
- var duration = level === "warn" ? 5000 : 1500;
14
+ // "warn" and "error" toasts carry actionable failure text (e.g. the
15
+ // worktree-remove "not a valid working tree" error, lr-76fbc3) that a
16
+ // 1500ms toast dismisses before it can be read. Give both levels the same
17
+ // longer window; plain success/info toasts keep the short default.
18
+ var duration = (level === "warn" || level === "error") ? 5000 : 1500;
15
19
  setTimeout(function () {
16
20
  el.classList.remove("visible");
17
21
  setTimeout(function () { el.remove(); }, 300);
package/lib/server.js CHANGED
@@ -1066,32 +1066,82 @@ function createServer(opts) {
1066
1066
  ws._clayUser = wsUser; // attach user context
1067
1067
  var remoteAddr = req.socket.remoteAddress || "";
1068
1068
  ws._clayLocal = (remoteAddr === "127.0.0.1" || remoteAddr === "::1" || remoteAddr === "::ffff:127.0.0.1");
1069
- // Clear cross-project unread for this project when client connects
1069
+ // Clear cross-project unread for this project when client connects.
1070
+ // lr-0aa7b6: map is keyed per-session ("slug::localId") now, so clear
1071
+ // every entry whose slug prefix matches the project just connected to.
1070
1072
  var unreadMap = getCrossProjectUnread(ws);
1071
- if (unreadMap[wsSlug]) {
1072
- unreadMap[wsSlug] = 0;
1073
+ var unreadPrefix = wsSlug + "::";
1074
+ var unreadKeys = Object.keys(unreadMap);
1075
+ for (var ui = 0; ui < unreadKeys.length; ui++) {
1076
+ if (unreadKeys[ui].indexOf(unreadPrefix) === 0) unreadMap[unreadKeys[ui]] = 0;
1073
1077
  }
1074
1078
  ctx.handleConnection(ws, wsUser);
1075
1079
  });
1076
1080
  });
1077
1081
 
1078
1082
  // --- Cross-project unread tracking ---
1079
- // WeakMap<ws, { slug: count }> tracks how many done events happened in other projects
1083
+ // WeakMap<ws, { "slug::localId": count }> tracks how many done events
1084
+ // happened in other projects, keyed per SESSION rather than per project
1085
+ // (lr-0aa7b6). A slug-only key made every session in a notifying project
1086
+ // look equally "unread" — the Home Hub Recent Sessions row for a sibling,
1087
+ // non-notifying session in the same project would light up too. localId
1088
+ // alone is not sufficient either: each project's SessionManager keeps its
1089
+ // own nextLocalId counter (see lib/sessions.js), so localId 3 in project A
1090
+ // and localId 3 in project B are unrelated sessions that would collide if
1091
+ // used as a bare key — hence the composite "slug::localId" key below.
1080
1092
  var crossProjectUnread = new WeakMap();
1081
1093
 
1094
+ function crossUnreadKey(slug, localId) {
1095
+ return slug + "::" + localId;
1096
+ }
1097
+
1082
1098
  function getCrossProjectUnread(ws) {
1083
1099
  var map = crossProjectUnread.get(ws);
1084
1100
  if (!map) { map = {}; crossProjectUnread.set(ws, map); }
1085
1101
  return map;
1086
1102
  }
1087
1103
 
1088
- function onSessionDone(sourceSlug) {
1089
- // Increment unread for all clients NOT connected to sourceSlug
1104
+ // Sum of all per-session unread entries belonging to a given project slug,
1105
+ // for a given client. Preserves the pre-lr-0aa7b6 project-badge contract
1106
+ // (proj.unread on the Projects-list) now that the underlying map is keyed
1107
+ // per-session rather than per-project — the badge is a rollup over the
1108
+ // restructured map, not a separate counter.
1109
+ function getCrossProjectUnreadForSlug(ws, projSlug) {
1110
+ var map = getCrossProjectUnread(ws);
1111
+ var prefix = projSlug + "::";
1112
+ var total = 0;
1113
+ var keys = Object.keys(map);
1114
+ for (var i = 0; i < keys.length; i++) {
1115
+ if (keys[i].indexOf(prefix) === 0) total += map[keys[i]] || 0;
1116
+ }
1117
+ return total;
1118
+ }
1119
+
1120
+ // Per-session unread lookup used by the Home Hub Recent Sessions data path
1121
+ // (lib/project-loop.js hub_recent_sessions_list) to attribute the alert
1122
+ // state to the individual notifying session rather than the whole project.
1123
+ // ownSlug is the slug of the project ws is connected to: for that project,
1124
+ // unread is tracked per-session via ws._clayUnread[localId] (the existing
1125
+ // same-project mechanism in lib/sessions.js doSendAndRecord); for every
1126
+ // other project, unread is tracked via the composite crossProjectUnread map.
1127
+ function getSessionUnread(ws, ownSlug, sessSlug, localId) {
1128
+ if (sessSlug === ownSlug) {
1129
+ var ownMap = ws._clayUnread || {};
1130
+ return ownMap[localId] || 0;
1131
+ }
1132
+ var map = getCrossProjectUnread(ws);
1133
+ return map[crossUnreadKey(sessSlug, localId)] || 0;
1134
+ }
1135
+
1136
+ function onSessionDone(sourceSlug, sourceLocalId) {
1137
+ // Increment unread for all clients NOT connected to sourceSlug, keyed to
1138
+ // the specific session that finished (lr-0aa7b6).
1139
+ var key = crossUnreadKey(sourceSlug, sourceLocalId);
1090
1140
  projects.forEach(function (ctx, projSlug) {
1091
1141
  if (projSlug === sourceSlug) return;
1092
1142
  ctx.forEachClient(function (ws) {
1093
1143
  var map = getCrossProjectUnread(ws);
1094
- map[sourceSlug] = (map[sourceSlug] || 0) + 1;
1144
+ map[key] = (map[key] || 0) + 1;
1095
1145
  });
1096
1146
  });
1097
1147
  // Trigger a projects_updated broadcast so clients get updated unread counts
@@ -1119,8 +1169,11 @@ function createServer(opts) {
1119
1169
  });
1120
1170
  }
1121
1171
  }
1122
- // Attach per-project unread counts for this client
1123
- var unreadMap = getCrossProjectUnread(ws);
1172
+ // Attach per-project unread counts for this client. lr-0aa7b6:
1173
+ // crossProjectUnread is now keyed per-session ("slug::localId"),
1174
+ // not per-project — the Projects-list badge total is a rollup
1175
+ // (sum) over that client's per-session entries for the project,
1176
+ // preserving the pre-restructure proj.unread contract.
1124
1177
  var projectsWithUnread = filtered.map(function (p) {
1125
1178
  var copy = {};
1126
1179
  var keys = Object.keys(p);
@@ -1129,7 +1182,7 @@ function createServer(opts) {
1129
1182
  if (p.slug === projSlug) {
1130
1183
  copy.unread = ctx.sm.getTotalUnread(ws);
1131
1184
  } else {
1132
- copy.unread = unreadMap[p.slug] || 0;
1185
+ copy.unread = getCrossProjectUnreadForSlug(ws, p.slug);
1133
1186
  }
1134
1187
  return copy;
1135
1188
  });
@@ -1275,7 +1328,12 @@ function createServer(opts) {
1275
1328
  },
1276
1329
  onPresenceChange: broadcastPresenceChange,
1277
1330
  onProcessingChanged: broadcastProcessingChange,
1278
- onSessionDone: function () { onSessionDone(slug); },
1331
+ onSessionDone: function (localId) { onSessionDone(slug, localId); },
1332
+ // lr-0aa7b6: per-session unread lookup for the Home Hub Recent
1333
+ // Sessions data path — see getSessionUnread's header above for why
1334
+ // this must distinguish "own project" (ws._clayUnread) from
1335
+ // "other project" (composite crossProjectUnread map).
1336
+ getSessionUnread: function (ws, sessSlug, localId) { return getSessionUnread(ws, slug, sessSlug, localId); },
1279
1337
  onAddProject: onAddProject,
1280
1338
  onCreateProject: onCreateProject,
1281
1339
  onCloneProject: onCloneProject,
package/lib/sessions.js CHANGED
@@ -1259,8 +1259,15 @@ function createSessionManager(opts) {
1259
1259
  } else if (session.localId === activeSessionId) {
1260
1260
  send(obj);
1261
1261
  }
1262
- // Notify server for cross-project unread tracking
1263
- if (obj.type === "done") onSessionDone();
1262
+ // Notify server for cross-project unread tracking. Pass the session's
1263
+ // own localId (lr-0aa7b6) so cross-project unread can be attributed to
1264
+ // the SPECIFIC session that finished, not just "this project has an
1265
+ // unread somewhere" — localId alone is only unique within this
1266
+ // project's SessionManager (nextLocalId is a per-project counter), so
1267
+ // the receiving side must pair it with the source project's slug
1268
+ // (already known to the caller wired in server.js) to form a globally
1269
+ // unique key.
1270
+ if (obj.type === "done") onSessionDone(session.localId);
1264
1271
  }
1265
1272
 
1266
1273
  function resumeSession(cliSessionId, opts, targetWs) {
package/lib/users.js CHANGED
@@ -29,19 +29,28 @@ function loadUsers() {
29
29
  // store.js is async-first; we fall back to synchronous fs here because the
30
30
  // entire users.js call graph is synchronous and converting all ~79 call sites
31
31
  // is a follow-up task (TODO(lr-b372): convert users.js callers to async).
32
+ var raw;
32
33
  try {
33
- var raw = fs.readFileSync(USERS_FILE, "utf8");
34
- var data = JSON.parse(raw);
35
- // Ensure all required fields exist
36
- if (!data.users) data.users = [];
37
- if (!data.invites) data.invites = [];
38
- if (data.multiUser === undefined) data.multiUser = true;
39
- if (data.setupCode === undefined) data.setupCode = null;
40
- if (data.smtp === undefined) data.smtp = null;
41
- return data;
34
+ raw = fs.readFileSync(USERS_FILE, "utf8");
42
35
  } catch (e) {
43
- return defaultData();
36
+ // ENOENT is the only case that legitimately means "no users yet" --
37
+ // every other read failure (EACCES, transient I/O error under
38
+ // contention, etc.) must not silently masquerade as an empty user set.
39
+ if (e && e.code === "ENOENT") return defaultData();
40
+ throw e;
44
41
  }
42
+ // A parse failure on an existing file means the file is corrupt, not
43
+ // absent. Swallowing this here previously caused findUserById() to return
44
+ // null for every user (lr-ae85d5), surfacing downstream as a confusing
45
+ // "ownerId is null" failure instead of a loud, diagnosable error.
46
+ var data = JSON.parse(raw);
47
+ // Ensure all required fields exist
48
+ if (!data.users) data.users = [];
49
+ if (!data.invites) data.invites = [];
50
+ if (data.multiUser === undefined) data.multiUser = true;
51
+ if (data.setupCode === undefined) data.setupCode = null;
52
+ if (data.smtp === undefined) data.smtp = null;
53
+ return data;
45
54
  }
46
55
 
47
56
  function saveUsers(data) {
package/lib/worktree.js CHANGED
@@ -104,11 +104,83 @@ function createWorktree(projectPath, branchName, dirName, baseBranch) {
104
104
  }
105
105
  }
106
106
 
107
+ // Resolve the actual registered path for a worktree identified by dirName
108
+ // (the leaf directory name, i.e. path.basename of the worktree's git-registered
109
+ // path -- see scanWorktrees()'s wt.dirName). Blindly reconstructing
110
+ // path.join(parentPath, dirName) is only correct when the worktree lives
111
+ // directly inside parentPath; a worktree registered elsewhere (e.g. created
112
+ // via `git worktree add ../sibling -b x` outside the app, or nested under a
113
+ // subdirectory) has a basename that does not round-trip back to its real
114
+ // path, and git then rejects the reconstructed path as "not a valid working
115
+ // tree" (lr-76fbc3). Matching against `git worktree list --porcelain` finds
116
+ // the actual registered path regardless of where it lives on disk.
117
+ //
118
+ // Matching on basename alone is not safe: two DIFFERENT parents can each
119
+ // register a worktree with the same leaf dirName (e.g. ./feat and
120
+ // ../sibling/feat), and `git worktree list` for either parent's repo returns
121
+ // BOTH entries (worktrees are tracked per-repository, not per-caller-cwd).
122
+ // Picking the first basename match would silently remove whichever one
123
+ // happens to sort first -- a wrong-target deletion is worse than the
124
+ // original "not a valid working tree" failure it replaced. So we bind the
125
+ // match to the caller's actual parent identity: first look for an entry
126
+ // whose resolved path is registered directly under resolvedParent (the
127
+ // expected common case); only fall back to a basename-only match when that
128
+ // yields exactly one candidate anywhere. If more than one candidate remains
129
+ // after both passes, the match is genuinely ambiguous -- refuse to guess and
130
+ // return null so the caller surfaces {ok:false,error} instead of resolving
131
+ // to a possibly-wrong path (PR #365 review).
132
+ //
133
+ // Returns the resolved absolute path, or null if no worktree with that
134
+ // dirName can be unambiguously resolved under parentPath.
135
+ function resolveWorktreePath(resolvedParent, worktreeDirName) {
136
+ try {
137
+ var output = execFileSync("git", ["worktree", "list", "--porcelain"], {
138
+ cwd: resolvedParent,
139
+ encoding: "utf8",
140
+ timeout: 5000,
141
+ stdio: ["pipe", "pipe", "pipe"],
142
+ });
143
+ var all = parseWorktreeOutput(output);
144
+ var underParent = [];
145
+ var basenameMatches = [];
146
+ for (var i = 0; i < all.length; i++) {
147
+ var wt = all[i];
148
+ if (wt.bare) continue;
149
+ if (path.basename(wt.path) !== worktreeDirName) continue;
150
+ var resolvedWt = path.resolve(wt.path);
151
+ basenameMatches.push(resolvedWt);
152
+ if (resolvedWt === path.join(resolvedParent, worktreeDirName)) {
153
+ underParent.push(resolvedWt);
154
+ }
155
+ }
156
+ // Preferred: exactly one entry registered directly under this parent.
157
+ if (underParent.length === 1) return underParent[0];
158
+ if (underParent.length > 1) return null; // should be impossible; refuse to guess
159
+ // Fallback: no entry lives directly under the parent (e.g. the
160
+ // lr-76fbc3 "registered elsewhere on disk" case) -- only safe when the
161
+ // basename identifies a single worktree across the whole repo.
162
+ if (basenameMatches.length === 1) return basenameMatches[0];
163
+ return null; // zero or ambiguous multiple matches -- caller surfaces an error
164
+ } catch (e) {
165
+ // fall through to null -- caller falls back to the naive join
166
+ }
167
+ return null;
168
+ }
169
+
107
170
  // Remove a worktree
108
171
  // Returns { ok, error }
109
172
  function removeWorktree(projectPath, worktreeDirName) {
110
173
  var resolvedParent = path.resolve(projectPath);
111
- var wtPath = path.join(resolvedParent, worktreeDirName);
174
+ // Resolve against what git actually registered rather than assuming the
175
+ // worktree lives directly inside resolvedParent (lr-76fbc3), and bind that
176
+ // resolution to THIS parent so a same-basename worktree under a different
177
+ // parent is never matched (PR #365 review). Fall back to the naive join
178
+ // only if resolveWorktreePath found no unambiguous match -- that join is
179
+ // always scoped to resolvedParent, so it can only ever point at a path
180
+ // under the caller's own parent directory (never at another parent's
181
+ // worktree); if nothing is registered there git rejects it and the real
182
+ // error is surfaced to the caller below.
183
+ var wtPath = resolveWorktreePath(resolvedParent, worktreeDirName) || path.join(resolvedParent, worktreeDirName);
112
184
  // Try normal remove first
113
185
  try {
114
186
  execFileSync("git", ["worktree", "remove", wtPath], {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.0-beta.1",
6
+ "version": "1.8.0-beta.2",
7
7
  "description": "Self-hosted console for Claude Code and Codex. Multi-user, browser-based, persistent AI sessions.",
8
8
  "bin": {
9
9
  "clagentic-console": "./bin/cli.js"