@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.
- package/bin/cli.js +23 -1
- package/lib/agents.js +13 -3
- package/lib/build-sha.json +2 -2
- package/lib/cli/ipc-subcommands.js +84 -4
- package/lib/daemon.js +111 -7
- package/lib/effective-protocol.js +82 -0
- package/lib/project-connection.js +21 -8
- package/lib/project-filesystem.js +4 -4
- package/lib/project-http.js +4 -4
- package/lib/project-loop.js +49 -5
- package/lib/project-sessions.js +166 -68
- package/lib/project-user-mention.js +7 -7
- package/lib/project-user-message.js +81 -14
- package/lib/project.js +28 -22
- package/lib/public/app.js +18 -4
- package/lib/public/css/base.css +14 -0
- package/lib/public/css/filebrowser.css +6 -0
- package/lib/public/css/home-hub.css +28 -8
- package/lib/public/css/icon-strip.css +17 -0
- package/lib/public/css/messages.css +11 -0
- package/lib/public/css/mobile-nav.css +22 -0
- package/lib/public/css/server-settings.css +9 -0
- package/lib/public/css/sidebar.css +15 -0
- package/lib/public/css/title-bar.css +10 -1
- package/lib/public/index.html +9 -2
- package/lib/public/modules/activity-latch.js +45 -0
- package/lib/public/modules/activity-state.js +195 -0
- package/lib/public/modules/app-connection.js +31 -6
- package/lib/public/modules/app-favicon.js +75 -1
- package/lib/public/modules/app-home-hub.js +14 -11
- package/lib/public/modules/app-loop-ui.js +86 -2
- package/lib/public/modules/app-messages.js +178 -54
- package/lib/public/modules/app-panels.js +91 -32
- package/lib/public/modules/app-projects.js +46 -9
- package/lib/public/modules/app-rate-limit.js +13 -1
- package/lib/public/modules/server-settings.js +256 -21
- package/lib/public/modules/sidebar-mobile.js +32 -22
- package/lib/public/modules/sidebar-projects.js +42 -14
- package/lib/public/modules/sidebar-sessions.js +168 -48
- package/lib/public/modules/theme.js +2 -2
- package/lib/public/modules/tools.js +11 -39
- package/lib/sdk-bridge.js +375 -33
- package/lib/sdk-message-processor.js +98 -15
- package/lib/sdk-skill-discovery.js +46 -6
- package/lib/sdk-slash-enrichment.js +5 -2
- package/lib/server-dm.js +5 -5
- package/lib/server-hub-sessions.js +70 -0
- package/lib/server.js +78 -43
- package/lib/session-activity.js +9 -2
- package/lib/sessions.js +64 -18
- package/lib/smtp.js +10 -1
- package/lib/terminal-manager.js +6 -6
- package/lib/ws-schema.js +16 -0
- package/lib/yoke/adapters/claude.js +7 -1
- package/lib/yoke/adapters/codex.js +219 -31
- package/package.json +2 -2
- package/scripts/check-test-count.js +397 -0
- package/scripts/test-file-completion-reporter.js +43 -0
- package/scripts/verify-installed-build.js +242 -15
- package/lib/model-context-windows.js +0 -74
- package/lib/public/modules/model-context-windows.js +0 -71
package/lib/server.js
CHANGED
|
@@ -18,6 +18,8 @@ var { CONFIG_DIR } = require("./config");
|
|
|
18
18
|
var { provisionLinuxUser } = require("./os-users");
|
|
19
19
|
var { detectLite } = require("./lite-detect");
|
|
20
20
|
var { readCappedBody } = require("./utils");
|
|
21
|
+
var { computeAllProjectSessions } = require("./server-hub-sessions");
|
|
22
|
+
var { resolveEffectiveProtocol } = require("./effective-protocol");
|
|
21
23
|
|
|
22
24
|
var https = require("https");
|
|
23
25
|
var pkg = require("../package.json");
|
|
@@ -226,6 +228,9 @@ function createServer(opts) {
|
|
|
226
228
|
var dangerouslySkipPermissions = opts.dangerouslySkipPermissions || false;
|
|
227
229
|
var osUsers = opts.osUsers || false;
|
|
228
230
|
var lanHost = opts.lanHost || null;
|
|
231
|
+
// lr-20e71c: operator-declared trust boundary for reading X-Forwarded-Proto
|
|
232
|
+
// from a reverse proxy. See lib/effective-protocol.js.
|
|
233
|
+
var trustedProxy = !!opts.trustedProxy;
|
|
229
234
|
// lr-2ea2a7: daemon.json knob overriding the in-heap session-history tail cap.
|
|
230
235
|
var historyInMemMax = opts.historyInMemMax;
|
|
231
236
|
var onAddProject = opts.onAddProject || null;
|
|
@@ -441,7 +446,14 @@ function createServer(opts) {
|
|
|
441
446
|
if (fullUrl === "/setup" && req.method === "GET") {
|
|
442
447
|
var host = req.headers.host || "localhost";
|
|
443
448
|
var hostname = host.split(":")[0];
|
|
444
|
-
|
|
449
|
+
// lr-20e71c: tlsOptions alone is daemon-internal-TLS-only and reports a
|
|
450
|
+
// false http:// link behind a TLS-terminating reverse proxy — resolve
|
|
451
|
+
// the real external protocol for this request instead.
|
|
452
|
+
var protocol = resolveEffectiveProtocol({
|
|
453
|
+
tlsOptions: tlsOptions,
|
|
454
|
+
trustedProxy: trustedProxy,
|
|
455
|
+
forwardedProtoHeader: req.headers["x-forwarded-proto"],
|
|
456
|
+
}).protocol;
|
|
445
457
|
var setupUrl = protocol + "://" + hostname + ":" + portNum;
|
|
446
458
|
var lanMode = /[?&]mode=lan/.test(req.url);
|
|
447
459
|
res.writeHead(200, {
|
|
@@ -456,7 +468,12 @@ function createServer(opts) {
|
|
|
456
468
|
if (fullUrl === "/pwa" && req.method === "GET") {
|
|
457
469
|
var host = req.headers.host || "localhost";
|
|
458
470
|
var hostname = host.split(":")[0];
|
|
459
|
-
|
|
471
|
+
// lr-20e71c: same effective-protocol resolution as /setup above.
|
|
472
|
+
var protocol = resolveEffectiveProtocol({
|
|
473
|
+
tlsOptions: tlsOptions,
|
|
474
|
+
trustedProxy: trustedProxy,
|
|
475
|
+
forwardedProtoHeader: req.headers["x-forwarded-proto"],
|
|
476
|
+
}).protocol;
|
|
460
477
|
var pwaUrl = protocol + "://" + hostname + ":" + portNum;
|
|
461
478
|
res.writeHead(200, {
|
|
462
479
|
"Content-Type": "text/html; charset=utf-8",
|
|
@@ -770,7 +787,16 @@ function createServer(opts) {
|
|
|
770
787
|
}
|
|
771
788
|
|
|
772
789
|
// Set last-visited project cookie for root redirect
|
|
773
|
-
|
|
790
|
+
// lr-20e71c: tlsOptions alone under-reports HTTPS behind a trusted
|
|
791
|
+
// TLS-terminating proxy (Caddy) — resolve the effective protocol so the
|
|
792
|
+
// Secure attribute is set whenever the browser actually sees HTTPS, not
|
|
793
|
+
// only when the daemon itself terminates TLS.
|
|
794
|
+
var cookieEffectiveProtocol = resolveEffectiveProtocol({
|
|
795
|
+
tlsOptions: tlsOptions,
|
|
796
|
+
trustedProxy: trustedProxy,
|
|
797
|
+
forwardedProtoHeader: req.headers["x-forwarded-proto"],
|
|
798
|
+
}).protocol;
|
|
799
|
+
res.setHeader("Set-Cookie", "clagentic_last_project=" + slug + "; Path=/; SameSite=Strict; Max-Age=31536000" + (cookieEffectiveProtocol === "https" ? "; Secure" : ""));
|
|
774
800
|
|
|
775
801
|
// Check project access for HTTP requests
|
|
776
802
|
if (onGetProjectAccess) {
|
|
@@ -792,7 +818,7 @@ function createServer(opts) {
|
|
|
792
818
|
var projectUrlWithQS = qsIdx >= 0 ? projectUrl + req.url.substring(qsIdx) : projectUrl;
|
|
793
819
|
|
|
794
820
|
// Attach user info for project HTTP handler
|
|
795
|
-
req.
|
|
821
|
+
req._clagenticUser = getMultiUserFromReq(req);
|
|
796
822
|
|
|
797
823
|
// Try project HTTP handler first (APIs)
|
|
798
824
|
var origUrl = req.url;
|
|
@@ -880,14 +906,14 @@ function createServer(opts) {
|
|
|
880
906
|
// handleProtocols echoes back the offered subprotocol whenever the client
|
|
881
907
|
// offered one and the upgrade authenticated (via ticket OR cookie — see
|
|
882
908
|
// lr-4c58ae): the WS spec requires the 101 response to echo an accepted
|
|
883
|
-
// subprotocol when one was offered, on any auth path. req.
|
|
909
|
+
// subprotocol when one was offered, on any auth path. req._clagenticAcceptedProtocol
|
|
884
910
|
// is set by the upgrade handler below after auth resolves, BEFORE
|
|
885
911
|
// wss.handleUpgrade() is called, so it is available here.
|
|
886
912
|
var wss = new WebSocketServer({
|
|
887
913
|
noServer: true,
|
|
888
914
|
handleProtocols: function (protocols, req) {
|
|
889
|
-
if (req.
|
|
890
|
-
return req.
|
|
915
|
+
if (req._clagenticAcceptedProtocol && protocols.has(req._clagenticAcceptedProtocol)) {
|
|
916
|
+
return req._clagenticAcceptedProtocol;
|
|
891
917
|
}
|
|
892
918
|
return false;
|
|
893
919
|
},
|
|
@@ -975,7 +1001,7 @@ function createServer(opts) {
|
|
|
975
1001
|
// what authenticated this request, so echo it as-is without burning it).
|
|
976
1002
|
// See the WebSocketServer handleProtocols hook above.
|
|
977
1003
|
if (offeredTicket && (wsTicketUser || wsCookieUser)) {
|
|
978
|
-
req.
|
|
1004
|
+
req._clagenticAcceptedProtocol = "clagentic.auth." + offeredTicket;
|
|
979
1005
|
}
|
|
980
1006
|
|
|
981
1007
|
// Drain gate (lr-6b30): reject new sessions while draining so in-flight
|
|
@@ -1063,9 +1089,17 @@ function createServer(opts) {
|
|
|
1063
1089
|
}
|
|
1064
1090
|
return origEmit.apply(ws, arguments);
|
|
1065
1091
|
};
|
|
1066
|
-
ws.
|
|
1092
|
+
ws._clagenticUser = wsUser; // attach user context
|
|
1067
1093
|
var remoteAddr = req.socket.remoteAddress || "";
|
|
1068
|
-
ws.
|
|
1094
|
+
ws._clagenticLocal = (remoteAddr === "127.0.0.1" || remoteAddr === "::1" || remoteAddr === "::ffff:127.0.0.1");
|
|
1095
|
+
// lr-20e71c: resolve the real external protocol for THIS connection at
|
|
1096
|
+
// upgrade time, while req.headers is still in scope — project-sessions.js's
|
|
1097
|
+
// per-message dispatch only has ws/msg, not the original upgrade req.
|
|
1098
|
+
ws._clagenticEffectiveProtocol = resolveEffectiveProtocol({
|
|
1099
|
+
tlsOptions: tlsOptions,
|
|
1100
|
+
trustedProxy: trustedProxy,
|
|
1101
|
+
forwardedProtoHeader: req.headers["x-forwarded-proto"],
|
|
1102
|
+
});
|
|
1069
1103
|
// Clear cross-project unread for this project when client connects.
|
|
1070
1104
|
// lr-0aa7b6: map is keyed per-session ("slug::localId") now, so clear
|
|
1071
1105
|
// every entry whose slug prefix matches the project just connected to.
|
|
@@ -1121,12 +1155,12 @@ function createServer(opts) {
|
|
|
1121
1155
|
// (lib/project-loop.js hub_recent_sessions_list) to attribute the alert
|
|
1122
1156
|
// state to the individual notifying session rather than the whole project.
|
|
1123
1157
|
// ownSlug is the slug of the project ws is connected to: for that project,
|
|
1124
|
-
// unread is tracked per-session via ws.
|
|
1158
|
+
// unread is tracked per-session via ws._clagenticUnread[localId] (the existing
|
|
1125
1159
|
// same-project mechanism in lib/sessions.js doSendAndRecord); for every
|
|
1126
1160
|
// other project, unread is tracked via the composite crossProjectUnread map.
|
|
1127
1161
|
function getSessionUnread(ws, ownSlug, sessSlug, localId) {
|
|
1128
1162
|
if (sessSlug === ownSlug) {
|
|
1129
|
-
var ownMap = ws.
|
|
1163
|
+
var ownMap = ws._clagenticUnread || {};
|
|
1130
1164
|
return ownMap[localId] || 0;
|
|
1131
1165
|
}
|
|
1132
1166
|
var map = getCrossProjectUnread(ws);
|
|
@@ -1151,7 +1185,7 @@ function createServer(opts) {
|
|
|
1151
1185
|
// lr-13c047 (Badge A prune-on-delete): a deleted session's crossProjectUnread
|
|
1152
1186
|
// entry previously had no clear path at all — onSessionDone is increment-only
|
|
1153
1187
|
// and the only clears were on full project-switch reconnect (below) or the
|
|
1154
|
-
// same-project ws.
|
|
1188
|
+
// same-project ws._clagenticUnread zeroing in switchSession. If the session that
|
|
1155
1189
|
// accrued the unread count is deleted before any client ever reconnects to
|
|
1156
1190
|
// its project, that count is now permanently unreachable (its key can never
|
|
1157
1191
|
// be zeroed by the connect-time prefix clear, since the session no longer
|
|
@@ -1206,7 +1240,7 @@ function createServer(opts) {
|
|
|
1206
1240
|
ctx.forEachClient(function (ws) {
|
|
1207
1241
|
var filtered = allProjectsList;
|
|
1208
1242
|
if (onGetProjectAccess) {
|
|
1209
|
-
var wsUser = ws.
|
|
1243
|
+
var wsUser = ws._clagenticUser;
|
|
1210
1244
|
if (wsUser) {
|
|
1211
1245
|
filtered = allProjectsList.filter(function (p) {
|
|
1212
1246
|
var access = onGetProjectAccess(p.slug);
|
|
@@ -1237,7 +1271,7 @@ function createServer(opts) {
|
|
|
1237
1271
|
type: "projects_updated",
|
|
1238
1272
|
projects: projectsWithUnread,
|
|
1239
1273
|
projectCount: projectsWithUnread.length,
|
|
1240
|
-
removedProjects: getRemovedProjects(ws.
|
|
1274
|
+
removedProjects: getRemovedProjects(ws._clagenticUser ? ws._clagenticUser.id : null),
|
|
1241
1275
|
folderMeta: getFolderMeta(),
|
|
1242
1276
|
}));
|
|
1243
1277
|
}
|
|
@@ -1286,29 +1320,30 @@ function createServer(opts) {
|
|
|
1286
1320
|
// recent-sessions list uses this to gather every project identically —
|
|
1287
1321
|
// matching the palette's behavior — so the global recency sort is honest
|
|
1288
1322
|
// and the currently-connected project doesn't dominate the result.
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1323
|
+
//
|
|
1324
|
+
// userId: REQUIRED to filter results to what the viewing user may
|
|
1325
|
+
// actually see. Unlike getProjectList/broadcastProcessingChange (which
|
|
1326
|
+
// the identical onGetProjectAccess + users.canAccessProject gate above
|
|
1327
|
+
// already protects), this function previously took no userId at all
|
|
1328
|
+
// and filtered only on `!s.hidden` -- it structurally could not
|
|
1329
|
+
// enforce per-project access or private-session visibility, leaking
|
|
1330
|
+
// cross-project and private sessions into the Home Hub recent-sessions
|
|
1331
|
+
// list. Fails CLOSED: no userId (or no onGetProjectAccess wiring) means
|
|
1332
|
+
// no sessions are returned. There is no legitimate no-auth caller of
|
|
1333
|
+
// this function -- the WS upgrade handler above rejects any connection
|
|
1334
|
+
// without an authenticated user (wsAuthedUser) with 401 before
|
|
1335
|
+
// ws._clagenticUser can ever be set, including in single-user/PIN mode
|
|
1336
|
+
// (still a real authenticated user, just one account) -- so failing
|
|
1337
|
+
// closed here never breaks a real deployment mode.
|
|
1338
|
+
getAllProjectSessions: function (includeSelf, userId) {
|
|
1339
|
+
return computeAllProjectSessions({
|
|
1340
|
+
projects: projects,
|
|
1341
|
+
users: users,
|
|
1342
|
+
onGetProjectAccess: onGetProjectAccess,
|
|
1343
|
+
callerSlug: slug,
|
|
1344
|
+
includeSelf: includeSelf,
|
|
1345
|
+
userId: userId,
|
|
1310
1346
|
});
|
|
1311
|
-
return allSessions;
|
|
1312
1347
|
},
|
|
1313
1348
|
getHubSchedules: function () {
|
|
1314
1349
|
var allSchedules = [];
|
|
@@ -1386,7 +1421,7 @@ function createServer(opts) {
|
|
|
1386
1421
|
markCrossProjectRead: function (ws, projSlug) { markCrossProjectRead(ws, projSlug); },
|
|
1387
1422
|
// lr-0aa7b6: per-session unread lookup for the Home Hub Recent
|
|
1388
1423
|
// Sessions data path — see getSessionUnread's header above for why
|
|
1389
|
-
// this must distinguish "own project" (ws.
|
|
1424
|
+
// this must distinguish "own project" (ws._clagenticUnread) from
|
|
1390
1425
|
// "other project" (composite crossProjectUnread map).
|
|
1391
1426
|
getSessionUnread: function (ws, sessSlug, localId) { return getSessionUnread(ws, slug, sessSlug, localId); },
|
|
1392
1427
|
onAddProject: onAddProject,
|
|
@@ -1545,8 +1580,8 @@ function createServer(opts) {
|
|
|
1545
1580
|
var list = [];
|
|
1546
1581
|
projects.forEach(function (ctx) {
|
|
1547
1582
|
ctx.forEachClient(function (ws) {
|
|
1548
|
-
if (!ws.
|
|
1549
|
-
var u = ws.
|
|
1583
|
+
if (!ws._clagenticUser) return;
|
|
1584
|
+
var u = ws._clagenticUser;
|
|
1550
1585
|
if (seen[u.id]) return;
|
|
1551
1586
|
seen[u.id] = true;
|
|
1552
1587
|
var p = u.profile || {};
|
|
@@ -1588,7 +1623,7 @@ function createServer(opts) {
|
|
|
1588
1623
|
var sentUsers = {};
|
|
1589
1624
|
projects.forEach(function (ctx) {
|
|
1590
1625
|
ctx.forEachClient(function (ws) {
|
|
1591
|
-
var userId = ws.
|
|
1626
|
+
var userId = ws._clagenticUser ? ws._clagenticUser.id : null;
|
|
1592
1627
|
var key = userId || "__anon__";
|
|
1593
1628
|
if (sentUsers[key]) {
|
|
1594
1629
|
// Already computed for this user, just send the cached msg
|
|
@@ -1648,7 +1683,7 @@ function createServer(opts) {
|
|
|
1648
1683
|
projects.forEach(function (ctx) {
|
|
1649
1684
|
if (typeof ctx.forEachClient !== "function") return;
|
|
1650
1685
|
ctx.forEachClient(function (ws) {
|
|
1651
|
-
if (ws.
|
|
1686
|
+
if (ws._clagenticUser && ws._clagenticUser.id === userId && ws.readyState === 1) {
|
|
1652
1687
|
ws.send(data);
|
|
1653
1688
|
}
|
|
1654
1689
|
});
|
|
@@ -1664,7 +1699,7 @@ function createServer(opts) {
|
|
|
1664
1699
|
if (typeof ctx.forEachClient !== "function") return;
|
|
1665
1700
|
ctx.forEachClient(function (ws) {
|
|
1666
1701
|
if (found) return;
|
|
1667
|
-
if (ws.
|
|
1702
|
+
if (ws._clagenticUser && ws._clagenticUser.id === userId && ws.readyState === 1) {
|
|
1668
1703
|
found = true;
|
|
1669
1704
|
}
|
|
1670
1705
|
});
|
package/lib/session-activity.js
CHANGED
|
@@ -73,7 +73,14 @@
|
|
|
73
73
|
*/
|
|
74
74
|
function createRegistry() {
|
|
75
75
|
return {
|
|
76
|
-
|
|
76
|
+
// lr-66c118 (fold-in, flagged by BOBBIE on 2/4 and 3/4): tokens is
|
|
77
|
+
// written by bracket assignment (registry.tokens[token] = ...) keyed by
|
|
78
|
+
// SDK/Codex-supplied ids with no prototype guard. Object.create(null)
|
|
79
|
+
// removes the Object.prototype chain so a crafted token id (e.g.
|
|
80
|
+
// "__proto__" or "constructor") cannot collide with an inherited
|
|
81
|
+
// property/method. Session-scoped, no demonstrated exploit — cheap
|
|
82
|
+
// hardening, not a response to a live vulnerability.
|
|
83
|
+
tokens: Object.create(null), // token -> { source, label, startedAt, generation }
|
|
77
84
|
generation: 0,
|
|
78
85
|
};
|
|
79
86
|
}
|
|
@@ -251,7 +258,7 @@ function replaceRegistry(session, snapshot) {
|
|
|
251
258
|
|
|
252
259
|
/**
|
|
253
260
|
* Detailed per-source breakdown of currently-live tokens, for scoping to
|
|
254
|
-
* the viewing client only (ws.
|
|
261
|
+
* the viewing client only (ws._clagenticActiveSession-style filtering) rather
|
|
255
262
|
* than broadcasting to every connected client -- see lr-9bcd7b spec's
|
|
256
263
|
* chattiness mitigation #3.
|
|
257
264
|
* @param {object} session
|
package/lib/sessions.js
CHANGED
|
@@ -35,6 +35,26 @@ function effectiveSessionModel(session, sm) {
|
|
|
35
35
|
return (sm && sm.currentModel) || "";
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// Message types whose client-side handler writes the global client-local
|
|
39
|
+
// 'processing'/'sessionIsProcessing' edge latch (app-messages.js's status/
|
|
40
|
+
// done/auth_required handlers). Stamping localId at the shared send choke
|
|
41
|
+
// points (doSendToSession/doSendAndRecord below, and project.js's own
|
|
42
|
+
// sendToSession/sendToSessionOthers which reuse this same list) means every
|
|
43
|
+
// one of the ~15 status/done/auth_required send sites across sessions.js/
|
|
44
|
+
// project.js/project-loop.js/sdk-bridge.js gets session-scoping for free,
|
|
45
|
+
// mirroring the existing scheduled_message_queued/sent localId pattern
|
|
46
|
+
// (project.js), without widening this to every message type — most types
|
|
47
|
+
// are already inherently session-scoped by their own handler logic and
|
|
48
|
+
// don't need it.
|
|
49
|
+
var ACTIVITY_LATCH_TYPES = { status: true, done: true, auth_required: true };
|
|
50
|
+
|
|
51
|
+
function stampActivityLocalId(session, obj) {
|
|
52
|
+
if (ACTIVITY_LATCH_TYPES[obj.type] && obj.localId === undefined) {
|
|
53
|
+
obj.localId = (session && session.localId !== undefined) ? session.localId : session;
|
|
54
|
+
}
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
57
|
+
|
|
38
58
|
function createSessionManager(opts) {
|
|
39
59
|
var cwd = opts.cwd;
|
|
40
60
|
var send = opts.send; // function(obj) - broadcast to all clients
|
|
@@ -130,6 +150,22 @@ function createSessionManager(opts) {
|
|
|
130
150
|
metaObj.pendingAutoResume = true;
|
|
131
151
|
if (session.pendingAutoResumeReason) metaObj.pendingAutoResumeReason = session.pendingAutoResumeReason;
|
|
132
152
|
}
|
|
153
|
+
// lr-62157d: durable auto-title state. Without this, titleAutoGenerated
|
|
154
|
+
// and titleManuallySet lived in memory only — every daemon restart reset
|
|
155
|
+
// both to false, so the "already auto-titled" / "user renamed it" guards
|
|
156
|
+
// at sdk-message-processor.js and sdk-bridge.js were guarding against
|
|
157
|
+
// state that could never actually be true after a restart. turnCount is
|
|
158
|
+
// persisted alongside them because the turn-threshold gate (see the
|
|
159
|
+
// '>=' fix at sdk-message-processor.js) depends on it surviving too —
|
|
160
|
+
// a restarted session that lost its turn count would silently miss the
|
|
161
|
+
// auto-title window forever instead of catching up on a later turn.
|
|
162
|
+
// titleProvisional marks a title set from the raw first-message
|
|
163
|
+
// truncation (project-user-message.js) so autoGenerateTitle knows it is
|
|
164
|
+
// safe to overwrite even though the flags above look "not yet set".
|
|
165
|
+
if (session.titleAutoGenerated) metaObj.titleAutoGenerated = true;
|
|
166
|
+
if (session.titleManuallySet) metaObj.titleManuallySet = true;
|
|
167
|
+
if (session.titleProvisional) metaObj.titleProvisional = true;
|
|
168
|
+
if (typeof session.turnCount === "number" && session.turnCount > 0) metaObj.turnCount = session.turnCount;
|
|
133
169
|
return JSON.stringify(metaObj);
|
|
134
170
|
}
|
|
135
171
|
|
|
@@ -723,6 +759,14 @@ function createSessionManager(opts) {
|
|
|
723
759
|
session.pendingAutoResume = true;
|
|
724
760
|
session.pendingAutoResumeReason = m.pendingAutoResumeReason || null;
|
|
725
761
|
}
|
|
762
|
+
// lr-62157d: restore auto-title state across a daemon restart — see
|
|
763
|
+
// buildMetaLine's write side for why this must persist. Without this,
|
|
764
|
+
// the guards at sdk-message-processor.js/sdk-bridge.js always saw
|
|
765
|
+
// false/0 after a restart no matter what actually happened before it.
|
|
766
|
+
session.titleAutoGenerated = !!m.titleAutoGenerated;
|
|
767
|
+
session.titleManuallySet = !!m.titleManuallySet;
|
|
768
|
+
session.titleProvisional = !!m.titleProvisional;
|
|
769
|
+
session.turnCount = typeof m.turnCount === "number" ? m.turnCount : 0;
|
|
726
770
|
sessions.set(localId, session);
|
|
727
771
|
}
|
|
728
772
|
}
|
|
@@ -793,8 +837,8 @@ function createSessionManager(opts) {
|
|
|
793
837
|
// Per-client filtering (multi-user mode)
|
|
794
838
|
sendEach(function (ws, filterFn) {
|
|
795
839
|
var filtered = filterFn ? allVisible.filter(filterFn) : allVisible;
|
|
796
|
-
var clientActiveId = ws.
|
|
797
|
-
var wsUnread = ws.
|
|
840
|
+
var clientActiveId = ws._clagenticActiveSession;
|
|
841
|
+
var wsUnread = ws._clagenticUnread || {};
|
|
798
842
|
if (ws.readyState === 1) {
|
|
799
843
|
ws.send(JSON.stringify({
|
|
800
844
|
type: "session_list",
|
|
@@ -1030,15 +1074,15 @@ function createSessionManager(opts) {
|
|
|
1030
1074
|
// (targetWs=null) bypass this gate — they operate on already-validated session
|
|
1031
1075
|
// references.
|
|
1032
1076
|
//
|
|
1033
|
-
// No-auth / single-user connections have
|
|
1077
|
+
// No-auth / single-user connections have _clagenticUser === null (set by
|
|
1034
1078
|
// project-connection.js:92 as wsUser || null). In that deployment there is
|
|
1035
1079
|
// no user identity to check — the connection is the implicit owner. We skip
|
|
1036
|
-
// the gate entirely for null users so that
|
|
1080
|
+
// the gate entirely for null users so that _clagenticActiveSession is still
|
|
1037
1081
|
// bound below, keeping the live-broadcast filter (doSendAndRecord /
|
|
1038
1082
|
// doSendToSession) in sync. Authenticated users who lack access are still
|
|
1039
1083
|
// rejected by canAccessSession. (regression introduced by dca60a7, lr-690b)
|
|
1040
1084
|
if (targetWs) {
|
|
1041
|
-
var requestingUser = targetWs.
|
|
1085
|
+
var requestingUser = targetWs._clagenticUser || null;
|
|
1042
1086
|
if (requestingUser) {
|
|
1043
1087
|
// Use { visibility: "public" } so canAccessProject passes and the
|
|
1044
1088
|
// session-level ownership/visibility rules do the real work.
|
|
@@ -1047,18 +1091,18 @@ function createSessionManager(opts) {
|
|
|
1047
1091
|
return;
|
|
1048
1092
|
}
|
|
1049
1093
|
}
|
|
1050
|
-
// null requestingUser = no-auth deployment; fall through to bind
|
|
1094
|
+
// null requestingUser = no-auth deployment; fall through to bind _clagenticActiveSession.
|
|
1051
1095
|
}
|
|
1052
1096
|
|
|
1053
1097
|
activeSessionId = localId;
|
|
1054
1098
|
if (targetWs) {
|
|
1055
|
-
targetWs.
|
|
1099
|
+
targetWs._clagenticActiveSession = localId;
|
|
1056
1100
|
// Clear unread for this session (multi-user)
|
|
1057
|
-
if (targetWs.
|
|
1101
|
+
if (targetWs._clagenticUnread) targetWs._clagenticUnread[localId] = 0;
|
|
1058
1102
|
} else if (sendEach) {
|
|
1059
1103
|
// No specific target: update all connected clients (server-initiated switch)
|
|
1060
1104
|
sendEach(function (ws) {
|
|
1061
|
-
ws.
|
|
1105
|
+
ws._clagenticActiveSession = localId;
|
|
1062
1106
|
});
|
|
1063
1107
|
}
|
|
1064
1108
|
// Update LRU when a session is switched to (history will be loaded in replayHistory).
|
|
@@ -1240,11 +1284,12 @@ function createSessionManager(opts) {
|
|
|
1240
1284
|
}
|
|
1241
1285
|
|
|
1242
1286
|
function doSendToSession(session, obj) {
|
|
1287
|
+
stampActivityLocalId(session, obj);
|
|
1243
1288
|
// Send to active clients without recording to history/disk (ephemeral data)
|
|
1244
1289
|
if (sendEach) {
|
|
1245
1290
|
var data = JSON.stringify(obj);
|
|
1246
1291
|
sendEach(function (ws) {
|
|
1247
|
-
if (ws.
|
|
1292
|
+
if (ws._clagenticActiveSession === session.localId && ws.readyState === 1) {
|
|
1248
1293
|
ws.send(data);
|
|
1249
1294
|
}
|
|
1250
1295
|
});
|
|
@@ -1254,6 +1299,7 @@ function createSessionManager(opts) {
|
|
|
1254
1299
|
}
|
|
1255
1300
|
|
|
1256
1301
|
function doSendAndRecord(session, obj) {
|
|
1302
|
+
stampActivityLocalId(session, obj);
|
|
1257
1303
|
// Stamp every recorded message so history replay preserves original times
|
|
1258
1304
|
if (!obj._ts) obj._ts = Date.now();
|
|
1259
1305
|
// If history has not been loaded from disk yet, do not trigger a load just
|
|
@@ -1273,7 +1319,7 @@ function createSessionManager(opts) {
|
|
|
1273
1319
|
var data = JSON.stringify(obj);
|
|
1274
1320
|
var ioData = null;
|
|
1275
1321
|
sendEach(function (ws) {
|
|
1276
|
-
if (ws.
|
|
1322
|
+
if (ws._clagenticActiveSession === session.localId) {
|
|
1277
1323
|
if (ws.readyState === 1) ws.send(data);
|
|
1278
1324
|
} else if (session.isProcessing && !session._ioThrottle) {
|
|
1279
1325
|
if (!ioData) ioData = JSON.stringify({ type: "session_io", id: session.localId });
|
|
@@ -1281,13 +1327,13 @@ function createSessionManager(opts) {
|
|
|
1281
1327
|
}
|
|
1282
1328
|
// Track unread: increment on "done" for clients not viewing this session
|
|
1283
1329
|
// Only count if session has no owner (my session) or owner matches this client
|
|
1284
|
-
if (obj.type === "done" && ws.
|
|
1285
|
-
var _isMySession = !session.ownerId || (ws.
|
|
1330
|
+
if (obj.type === "done" && ws._clagenticActiveSession !== session.localId) {
|
|
1331
|
+
var _isMySession = !session.ownerId || (ws._clagenticUser && ws._clagenticUser.id === session.ownerId);
|
|
1286
1332
|
if (_isMySession) {
|
|
1287
|
-
if (!ws.
|
|
1288
|
-
ws.
|
|
1333
|
+
if (!ws._clagenticUnread) ws._clagenticUnread = {};
|
|
1334
|
+
ws._clagenticUnread[session.localId] = (ws._clagenticUnread[session.localId] || 0) + 1;
|
|
1289
1335
|
if (ws.readyState === 1) {
|
|
1290
|
-
ws.send(JSON.stringify({ type: "session_unread", id: session.localId, count: ws.
|
|
1336
|
+
ws.send(JSON.stringify({ type: "session_unread", id: session.localId, count: ws._clagenticUnread[session.localId] }));
|
|
1291
1337
|
}
|
|
1292
1338
|
}
|
|
1293
1339
|
}
|
|
@@ -1619,7 +1665,7 @@ function createSessionManager(opts) {
|
|
|
1619
1665
|
broadcastSessionList: broadcastSessionList,
|
|
1620
1666
|
broadcastSessionDeleted: broadcastSessionDeleted,
|
|
1621
1667
|
getTotalUnread: function (ws) {
|
|
1622
|
-
var unreadMap = (ws && ws.
|
|
1668
|
+
var unreadMap = (ws && ws._clagenticUnread) ? ws._clagenticUnread : {};
|
|
1623
1669
|
var total = 0;
|
|
1624
1670
|
var keys = Object.keys(unreadMap);
|
|
1625
1671
|
for (var i = 0; i < keys.length; i++) {
|
|
@@ -1770,4 +1816,4 @@ function createSessionManager(opts) {
|
|
|
1770
1816
|
return _instance;
|
|
1771
1817
|
}
|
|
1772
1818
|
|
|
1773
|
-
module.exports = { createSessionManager, effectiveSessionModel };
|
|
1819
|
+
module.exports = { createSessionManager, effectiveSessionModel, stampActivityLocalId };
|
package/lib/smtp.js
CHANGED
|
@@ -183,7 +183,15 @@ function sendInviteEmail(email, inviteUrl, inviterName) {
|
|
|
183
183
|
|
|
184
184
|
// --- Cleanup expired OTPs ---
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
// lr-795882: unref()'d — matches the equivalent ws-ticket sweep in
|
|
187
|
+
// server-auth.js (wsTicketSweepInterval). This is a housekeeping sweep, not
|
|
188
|
+
// something that should keep the process alive on its own; leaving it
|
|
189
|
+
// ref'd meant every test that required this module (or re-required it after
|
|
190
|
+
// busting require.cache, as test/ws-ticket-auth-lr-de5fcb.test.js's
|
|
191
|
+
// makeAuth() helper does once per test) left a real, permanently-running
|
|
192
|
+
// setInterval handle on the event loop, blocking `node --test` from ever
|
|
193
|
+
// reaching idle without --test-force-exit.
|
|
194
|
+
var _otpCleanupInterval = setInterval(function () {
|
|
187
195
|
var now = Date.now();
|
|
188
196
|
var keys = Object.keys(otpStore);
|
|
189
197
|
for (var i = 0; i < keys.length; i++) {
|
|
@@ -192,6 +200,7 @@ setInterval(function () {
|
|
|
192
200
|
}
|
|
193
201
|
}
|
|
194
202
|
}, 60000);
|
|
203
|
+
if (_otpCleanupInterval.unref) _otpCleanupInterval.unref();
|
|
195
204
|
|
|
196
205
|
module.exports = {
|
|
197
206
|
getSmtpConfig: getSmtpConfig,
|
package/lib/terminal-manager.js
CHANGED
|
@@ -9,9 +9,9 @@ var SCROLLBACK_MAX = 50 * 1024; // 50 KB per terminal
|
|
|
9
9
|
* opts: { cwd, send, sendTo, broadcastTermList }
|
|
10
10
|
*
|
|
11
11
|
* Ownership enforcement is always active. Each terminal records ownerUserId
|
|
12
|
-
* from ws.
|
|
12
|
+
* from ws._clagenticUser.id at creation time. Operations that mutate or read
|
|
13
13
|
* private output (attach, write, close, rename) are restricted to the owning
|
|
14
|
-
* user or admins (ws.
|
|
14
|
+
* user or admins (ws._clagenticUser.role === "admin"). term_list results are
|
|
15
15
|
* filtered to the requesting user's own terminals; admins see all with an
|
|
16
16
|
* ownerUserId field attached.
|
|
17
17
|
*/
|
|
@@ -41,11 +41,11 @@ function createTerminalManager(opts) {
|
|
|
41
41
|
|
|
42
42
|
// Returns true if callerWs is authorized for the given terminal session.
|
|
43
43
|
// Authorized if: no owner set, same user, or caller is admin.
|
|
44
|
-
// system context (callerWs === null): allowed. Unauthenticated ws (
|
|
44
|
+
// system context (callerWs === null): allowed. Unauthenticated ws (_clagenticUser null): denied.
|
|
45
45
|
function isAuthorized(session, callerWs) {
|
|
46
46
|
if (!callerWs) return true; // internal/system call — no WS context
|
|
47
47
|
if (!session.ownerUserId) return true; // unowned terminal — anyone may access
|
|
48
|
-
var caller = callerWs.
|
|
48
|
+
var caller = callerWs._clagenticUser;
|
|
49
49
|
if (!caller) return false; // unauthenticated ws — deny access to owned terminals
|
|
50
50
|
if (caller.role === "admin") return true;
|
|
51
51
|
return caller.id === session.ownerUserId;
|
|
@@ -71,7 +71,7 @@ function createTerminalManager(opts) {
|
|
|
71
71
|
exitCode: null,
|
|
72
72
|
subscribers: new Set(),
|
|
73
73
|
ownerWs: ownerWs || null,
|
|
74
|
-
ownerUserId: (ownerWs && ownerWs.
|
|
74
|
+
ownerUserId: (ownerWs && ownerWs._clagenticUser && ownerWs._clagenticUser.id) ? ownerWs._clagenticUser.id : null,
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
pty.onData(function (data) {
|
|
@@ -246,7 +246,7 @@ function createTerminalManager(opts) {
|
|
|
246
246
|
exited: session.exited,
|
|
247
247
|
};
|
|
248
248
|
// Admins see the owner label so they can distinguish whose terminal it is.
|
|
249
|
-
if (callerWs && callerWs.
|
|
249
|
+
if (callerWs && callerWs._clagenticUser && callerWs._clagenticUser.role === "admin" && session.ownerUserId) {
|
|
250
250
|
entry.ownerUserId = session.ownerUserId;
|
|
251
251
|
}
|
|
252
252
|
result.push(entry);
|
package/lib/ws-schema.js
CHANGED
|
@@ -33,6 +33,10 @@ var schema = {
|
|
|
33
33
|
"fork_session": { direction: "c2s", handler: "lib/project-sessions.js", description: "Fork a session from a given message UUID" },
|
|
34
34
|
"input_sync": { direction: "c2s", handler: "lib/project-sessions.js", description: "Sync the current input field text to other clients" },
|
|
35
35
|
|
|
36
|
+
// lr-66c118: session_list items carry isProcessing/unread/ownerId — the
|
|
37
|
+
// exact fields lib/public/modules/activity-state.js's sessionActivity()
|
|
38
|
+
// derives every render surface's dot from. No new wire message type was
|
|
39
|
+
// added for "activity"; it is data already on this existing message.
|
|
36
40
|
"session_list": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Full list of sessions for the sidebar" },
|
|
37
41
|
"session_switched": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Confirmation that active session changed" },
|
|
38
42
|
"session_id": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "CLI session ID assigned to the current session" },
|
|
@@ -68,6 +72,13 @@ var schema = {
|
|
|
68
72
|
"message_uuid": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "UUID assigned to a user or assistant message" },
|
|
69
73
|
"prompt_suggestion": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Suggested follow-up prompt from the assistant" },
|
|
70
74
|
"context_preview": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Preview of context sources included in a query" },
|
|
75
|
+
// lr-66c118 fold-in: found missing from this schema by the new CI
|
|
76
|
+
// absence-invariant (test/activity-state-lr-66c118.test.js) that scans
|
|
77
|
+
// every real sendAndRecord(session, { type: "..." }) call site — these 4
|
|
78
|
+
// were live, sent types with no documentation entry.
|
|
79
|
+
"plan_content": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Plan-mode content for the plan card" },
|
|
80
|
+
"sdk_notification": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Informational notification surfaced from the vendor SDK" },
|
|
81
|
+
"diagnostic": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Session-scoped diagnostic toast (settings preflight, memory shedding, adapter warnings)" },
|
|
71
82
|
|
|
72
83
|
// -----------------------------------------------------------------------
|
|
73
84
|
// Thinking
|
|
@@ -98,6 +109,8 @@ var schema = {
|
|
|
98
109
|
"team_request_state": { direction: "c2s", handler: "lib/project-team.js", description: "Client requests current team snapshot" },
|
|
99
110
|
"task_started": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Background task started" },
|
|
100
111
|
"task_progress": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Background task progress update" },
|
|
112
|
+
// lr-66c118 fold-in: see the plan_content/sdk_notification/diagnostic note above.
|
|
113
|
+
"task_updated": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Background task status/description patch" },
|
|
101
114
|
|
|
102
115
|
// -----------------------------------------------------------------------
|
|
103
116
|
// Permissions
|
|
@@ -450,6 +463,9 @@ var schema = {
|
|
|
450
463
|
"hub_schedules_list": { direction: "c2s", handler: "lib/project-loop.js", description: "Request the hub schedules list" },
|
|
451
464
|
"hub_schedules": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Hub schedules list" },
|
|
452
465
|
"hub_recent_sessions_list": { direction: "c2s", handler: "lib/project-loop.js", description: "Request cross-project recent sessions for hub" },
|
|
466
|
+
// lr-66c118: each session item now also carries ownerId (added alongside
|
|
467
|
+
// isProcessing/unread) so the Home Hub Recent Sessions dot can render the
|
|
468
|
+
// multi-user 'other' tone via activity-state.js, same as session_list.
|
|
453
469
|
"hub_recent_sessions": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Cross-project recent sessions list for hub" },
|
|
454
470
|
"schedule_run_started": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A scheduled run has started" },
|
|
455
471
|
"schedule_run_finished": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A scheduled run has finished" },
|
|
@@ -91,7 +91,13 @@ function flattenEvent(raw) {
|
|
|
91
91
|
base.yokeType = "turn_start";
|
|
92
92
|
if (evt.message && evt.message.usage) {
|
|
93
93
|
var u = evt.message.usage;
|
|
94
|
-
|
|
94
|
+
// lr-3af675: input_tokens, cache_read_input_tokens, and
|
|
95
|
+
// cache_creation_input_tokens are disjoint (Anthropic prompt-caching
|
|
96
|
+
// docs) and all three occupy the context window. The input_tokens +
|
|
97
|
+
// cache_read_input_tokens sum was correct as far as it went;
|
|
98
|
+
// cache_creation_input_tokens was simply omitted, under-reporting
|
|
99
|
+
// context fill on cache-write-heavy turns.
|
|
100
|
+
base.inputTokens = (u.input_tokens || 0) + (u.cache_read_input_tokens || 0) + (u.cache_creation_input_tokens || 0);
|
|
95
101
|
}
|
|
96
102
|
return base;
|
|
97
103
|
}
|