@clagentic/console 1.4.0-beta.1 → 1.4.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/lib/daemon.js CHANGED
@@ -1325,28 +1325,57 @@ var ipc = createIPCServer(socketPath(), function (msg) {
1325
1325
  // This is the only reliable path — npx installs to a cache location that the
1326
1326
  // restart wrapper does not consult, so npx-spawned daemons get replaced by the
1327
1327
  // old global version on the next supervised restart.
1328
- var { execFileSync: execFileUpd } = require("child_process");
1329
- var updTag = config.updateChannel === "beta" ? "beta" : "latest";
1330
- var updOk = false;
1331
- try {
1332
- console.log("[daemon] Installing @clagentic/console@" + updTag + " globally...");
1333
- execFileUpd("npm", ["install", "-g", "@clagentic/console@" + updTag], {
1334
- stdio: ["ignore", "pipe", "pipe"],
1335
- timeout: 120000,
1336
- encoding: "utf8",
1337
- });
1338
- console.log("[daemon] Global install complete. Shutting down for supervised restart.");
1339
- updOk = true;
1340
- } catch (updErr) {
1341
- console.log("[daemon] Global install failed:", updErr.message);
1342
- relay.broadcastAll({ type: "update_failed", error: updErr.message });
1343
- return { ok: false, error: updErr.message };
1344
- }
1345
- if (updOk) {
1346
- updateHandoff = true;
1347
- setTimeout(function () { gracefulShutdown(); }, 100);
1348
- }
1349
- return { ok: true };
1328
+ // Resolve + install asynchronously. ipc.js awaits a returned Promise, so
1329
+ // returning an async IIFE here is safe without changing the outer handler.
1330
+ return (async function () {
1331
+ var { execFileSync: execFileUpd } = require("child_process");
1332
+ var updater = require("./updater");
1333
+
1334
+ // Resolve the target version the same way the startup updater does, then
1335
+ // install that EXACT version — never a bare dist-tag. Installing @latest/
1336
+ // @beta is unsafe: the tag can point at an older version than what is
1337
+ // running (e.g. a beta machine whose @latest resolves to an older stable),
1338
+ // which silently downgrades the daemon. We mirror checkAndUpdate: on the
1339
+ // beta channel (or a pre-release current version) consider both beta and
1340
+ // latest and take the newest; on stable consider latest only. Then guard
1341
+ // with isNewer so a downgrade is impossible.
1342
+ var isBetaCh = config.updateChannel === "beta" || (daemonVersion && daemonVersion.includes("-"));
1343
+ var updTags = isBetaCh ? ["beta", "latest"] : ["latest"];
1344
+ var updTarget = null;
1345
+ for (var _ut = 0; _ut < updTags.length; _ut++) {
1346
+ var _cand = await updater.fetchVersion(updTags[_ut] === "beta" ? "beta" : "stable");
1347
+ if (_cand && (!updTarget || updater.isNewer(_cand, updTarget))) {
1348
+ updTarget = _cand;
1349
+ }
1350
+ }
1351
+
1352
+ if (!updTarget || !updater.isNewer(updTarget, daemonVersion)) {
1353
+ console.log("[daemon] No newer version available (current " + daemonVersion + ", best candidate " + (updTarget || "none") + "). Skipping update.");
1354
+ relay.broadcastAll({ type: "update_failed", error: "Already on the latest available version (" + daemonVersion + ")" });
1355
+ return { ok: false, error: "Already up to date (" + daemonVersion + ")" };
1356
+ }
1357
+
1358
+ var updOk = false;
1359
+ try {
1360
+ console.log("[daemon] Installing @clagentic/console@" + updTarget + " globally (current " + daemonVersion + ")...");
1361
+ execFileUpd("npm", ["install", "-g", "@clagentic/console@" + updTarget], {
1362
+ stdio: ["ignore", "pipe", "pipe"],
1363
+ timeout: 120000,
1364
+ encoding: "utf8",
1365
+ });
1366
+ console.log("[daemon] Global install complete. Shutting down for supervised restart.");
1367
+ updOk = true;
1368
+ } catch (updErr) {
1369
+ console.log("[daemon] Global install failed:", updErr.message);
1370
+ relay.broadcastAll({ type: "update_failed", error: updErr.message });
1371
+ return { ok: false, error: updErr.message };
1372
+ }
1373
+ if (updOk) {
1374
+ updateHandoff = true;
1375
+ setTimeout(function () { gracefulShutdown(); }, 100);
1376
+ }
1377
+ return { ok: true };
1378
+ })();
1350
1379
  }
1351
1380
 
1352
1381
  default:
@@ -1144,37 +1144,31 @@ function attachLoop(ctx) {
1144
1144
 
1145
1145
  // --- Hub: cross-project recent sessions ---
1146
1146
  if (msg.type === "hub_recent_sessions_list") {
1147
- // Other-project sessions (already have _projectTitle set by getAllProjectSessions)
1148
- // getAllProjectSessions returns annotated shallow copies (not live objects).
1149
- // Each copy carries _projectTitle, _projectSlug, _projectIcon from server.js.
1150
- // We then append the current project's own sessions below with self metadata.
1151
- var otherSessions = getAllProjectSessions ? getAllProjectSessions() : [];
1152
- var selfStatus = getStatus ? getStatus() : {};
1153
- var selfSlug = selfStatus.slug || slug;
1154
- var selfTitle = selfStatus.title || selfStatus.project || selfSlug;
1155
- var selfIcon = selfStatus.icon || null;
1156
- var allSessions = otherSessions.slice();
1157
- sm.sessions.forEach(function (s) {
1158
- if (!s.hidden) {
1159
- allSessions.push(Object.assign({}, s, {
1160
- _projectSlug: selfSlug,
1161
- _projectTitle: selfTitle,
1162
- _projectIcon: selfIcon,
1163
- }));
1164
- }
1165
- });
1147
+ // Gather EVERY project uniformly (includeSelf=true) so the global recency
1148
+ // sort is honest. Previously self was special-cased: other projects came
1149
+ // through getAllProjectSessions() and self's sessions were appended
1150
+ // separately. Combined with a too-small top-10 slice, the currently
1151
+ // connected (most-recently-active) project crowded out the genuinely most
1152
+ // recent sessions overall. getAllProjectSessions returns annotated shallow
1153
+ // copies carrying _projectSlug/_projectTitle/_projectIcon for every project.
1154
+ var allSessions = getAllProjectSessions ? getAllProjectSessions(true) : [];
1166
1155
  // Sort newest-first by lastActivity
1167
1156
  allSessions.sort(function (a, b) {
1168
1157
  return (b.lastActivity || b.createdAt || 0) - (a.lastActivity || a.createdAt || 0);
1169
1158
  });
1170
- var top10 = allSessions.slice(0, 10);
1171
- var mapped = top10.map(function (s) {
1159
+ // The global sort above is the actual fix: every project is gathered
1160
+ // uniformly, so the top-N is the genuinely most-recent overall rather
1161
+ // than whatever the connected project happened to touch. The Hub card
1162
+ // shows 10; selection is now honest, so 10 is a display cap, not a
1163
+ // project-biased pool.
1164
+ var top = allSessions.slice(0, 10);
1165
+ var mapped = top.map(function (s) {
1172
1166
  return {
1173
1167
  id: s.localId,
1174
1168
  title: s.title || "New Session",
1175
1169
  lastActivity: s.lastActivity || s.createdAt || 0,
1176
- projectSlug: s._projectSlug || selfSlug,
1177
- projectTitle: s._projectTitle || selfTitle,
1170
+ projectSlug: s._projectSlug || slug,
1171
+ projectTitle: s._projectTitle || slug,
1178
1172
  projectIcon: s._projectIcon || null,
1179
1173
  vendor: s.vendor || null,
1180
1174
  agentName: s.agentName || null,
package/lib/server.js CHANGED
@@ -946,10 +946,15 @@ function createServer(opts) {
946
946
  });
947
947
  return list;
948
948
  },
949
- getAllProjectSessions: function () {
949
+ // includeSelf: when true, the calling project's own sessions are included
950
+ // in the uniform pass (so callers need not special-case self). The Hub
951
+ // recent-sessions list uses this to gather every project identically —
952
+ // matching the palette's behavior — so the global recency sort is honest
953
+ // and the currently-connected project doesn't dominate the result.
954
+ getAllProjectSessions: function (includeSelf) {
950
955
  var allSessions = [];
951
956
  projects.forEach(function (pCtx, pSlug) {
952
- if (pSlug === slug) return; // skip self
957
+ if (!includeSelf && pSlug === slug) return; // skip self unless asked
953
958
  var status = pCtx.getStatus();
954
959
  if (status.isWorktree) return;
955
960
  var pSm = pCtx.getSessionManager();
package/lib/updater.js CHANGED
@@ -81,10 +81,15 @@ function isNewer(latest, current) {
81
81
  return false;
82
82
  }
83
83
 
84
- function performUpdate(channel) {
85
- var tag = channel === "beta" ? "beta" : "latest";
84
+ // Install an EXACT version, never a dist-tag. Installing a tag (@latest/@beta)
85
+ // is unsafe: the tag can resolve to a different — even older — version than the
86
+ // one isNewer() approved, which is how a beta machine got silently downgraded to
87
+ // whatever @latest happened to point at. Pinning the resolved version makes a
88
+ // downgrade structurally impossible.
89
+ function performUpdate(version) {
90
+ if (!version) return false;
86
91
  try {
87
- execFileSync("npm", ["install", "-g", "@clagentic/console@" + tag], { stdio: "pipe" });
92
+ execFileSync("npm", ["install", "-g", "@clagentic/console@" + version], { stdio: "pipe" });
88
93
  return true;
89
94
  } catch (e) {
90
95
  return false;
@@ -116,13 +121,17 @@ async function checkAndUpdate(currentVersion, skipUpdate, channel) {
116
121
  }
117
122
  }
118
123
 
124
+ // Guard: only ever install something strictly newer than what is running.
125
+ // isNewer treats a same-base stable as newer than a pre-release, so this also
126
+ // never trades a beta down to an equal-or-older stable.
119
127
  if (!latest || !isNewer(latest, currentVersion)) return false;
120
128
 
121
- var tag = (isBeta && latest.includes("-")) ? "beta" : "latest";
122
129
  log(sym.pointer + " " + a.bold + "Update available" + a.reset + " " + a.dim + currentVersion + " -> " + latest + a.reset);
123
130
  log(sym.bar + " Installing...");
124
131
 
125
- if (performUpdate(tag === "beta" ? "beta" : "stable")) {
132
+ // Install the exact resolved version, not a dist-tag — the announced version
133
+ // and the installed version are then guaranteed identical.
134
+ if (performUpdate(latest)) {
126
135
  log(sym.done + " Updated to " + a.green + latest + a.reset);
127
136
  log("");
128
137
  reExec();
@@ -130,7 +139,7 @@ async function checkAndUpdate(currentVersion, skipUpdate, channel) {
130
139
  }
131
140
 
132
141
  log(sym.warn + " " + a.yellow + "Update failed" + a.reset + a.dim + " (permission denied?)" + a.reset);
133
- log(sym.bar + " " + a.dim + "Run manually: npm install -g @clagentic/console@" + tag + a.reset);
142
+ log(sym.bar + " " + a.dim + "Run manually: npm install -g @clagentic/console@" + latest + a.reset);
134
143
  log("");
135
144
  return false;
136
145
  }
package/package.json CHANGED
@@ -3,14 +3,14 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.4.0-beta.1",
6
+ "version": "1.4.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"
10
10
  },
11
11
  "scripts": {
12
12
  "dev": "node bin/cli.js --dev",
13
- "test": "node --test test/*.test.js",
13
+ "test": "node --test --test-force-exit test/*.test.js",
14
14
  "semantic-release": "semantic-release"
15
15
  },
16
16
  "files": [