@clagentic/console 1.9.0-beta.2 → 1.9.0
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 +12 -1
- package/lib/build-sha.json +2 -2
- package/lib/cli/ipc-subcommands.js +44 -0
- package/lib/daemon.js +86 -6
- package/lib/effective-protocol.js +82 -0
- package/lib/project-connection.js +6 -6
- package/lib/project-filesystem.js +4 -4
- package/lib/project-http.js +4 -4
- package/lib/project-loop.js +4 -4
- package/lib/project-sessions.js +147 -77
- package/lib/project-user-mention.js +7 -7
- package/lib/project-user-message.js +11 -11
- package/lib/project.js +21 -21
- package/lib/public/app.js +10 -6
- package/lib/public/css/filebrowser.css +6 -0
- package/lib/public/css/server-settings.css +9 -0
- package/lib/public/index.html +8 -2
- package/lib/public/modules/activity-latch.js +25 -139
- package/lib/public/modules/activity-state.js +44 -6
- package/lib/public/modules/app-connection.js +24 -5
- package/lib/public/modules/app-favicon.js +52 -65
- package/lib/public/modules/app-messages.js +114 -54
- package/lib/public/modules/app-projects.js +24 -7
- package/lib/public/modules/server-settings.js +256 -21
- package/lib/public/modules/theme.js +2 -2
- package/lib/sdk-bridge.js +76 -13
- package/lib/server-dm.js +5 -5
- package/lib/server-hub-sessions.js +1 -1
- package/lib/server.js +55 -22
- package/lib/session-activity.js +1 -1
- package/lib/sessions.js +17 -17
- package/lib/terminal-manager.js +6 -6
- package/package.json +1 -1
- package/scripts/verify-installed-build.js +242 -15
package/lib/server.js
CHANGED
|
@@ -19,6 +19,7 @@ var { provisionLinuxUser } = require("./os-users");
|
|
|
19
19
|
var { detectLite } = require("./lite-detect");
|
|
20
20
|
var { readCappedBody } = require("./utils");
|
|
21
21
|
var { computeAllProjectSessions } = require("./server-hub-sessions");
|
|
22
|
+
var { resolveEffectiveProtocol } = require("./effective-protocol");
|
|
22
23
|
|
|
23
24
|
var https = require("https");
|
|
24
25
|
var pkg = require("../package.json");
|
|
@@ -227,6 +228,9 @@ function createServer(opts) {
|
|
|
227
228
|
var dangerouslySkipPermissions = opts.dangerouslySkipPermissions || false;
|
|
228
229
|
var osUsers = opts.osUsers || false;
|
|
229
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;
|
|
230
234
|
// lr-2ea2a7: daemon.json knob overriding the in-heap session-history tail cap.
|
|
231
235
|
var historyInMemMax = opts.historyInMemMax;
|
|
232
236
|
var onAddProject = opts.onAddProject || null;
|
|
@@ -442,7 +446,14 @@ function createServer(opts) {
|
|
|
442
446
|
if (fullUrl === "/setup" && req.method === "GET") {
|
|
443
447
|
var host = req.headers.host || "localhost";
|
|
444
448
|
var hostname = host.split(":")[0];
|
|
445
|
-
|
|
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;
|
|
446
457
|
var setupUrl = protocol + "://" + hostname + ":" + portNum;
|
|
447
458
|
var lanMode = /[?&]mode=lan/.test(req.url);
|
|
448
459
|
res.writeHead(200, {
|
|
@@ -457,7 +468,12 @@ function createServer(opts) {
|
|
|
457
468
|
if (fullUrl === "/pwa" && req.method === "GET") {
|
|
458
469
|
var host = req.headers.host || "localhost";
|
|
459
470
|
var hostname = host.split(":")[0];
|
|
460
|
-
|
|
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;
|
|
461
477
|
var pwaUrl = protocol + "://" + hostname + ":" + portNum;
|
|
462
478
|
res.writeHead(200, {
|
|
463
479
|
"Content-Type": "text/html; charset=utf-8",
|
|
@@ -771,7 +787,16 @@ function createServer(opts) {
|
|
|
771
787
|
}
|
|
772
788
|
|
|
773
789
|
// Set last-visited project cookie for root redirect
|
|
774
|
-
|
|
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" : ""));
|
|
775
800
|
|
|
776
801
|
// Check project access for HTTP requests
|
|
777
802
|
if (onGetProjectAccess) {
|
|
@@ -793,7 +818,7 @@ function createServer(opts) {
|
|
|
793
818
|
var projectUrlWithQS = qsIdx >= 0 ? projectUrl + req.url.substring(qsIdx) : projectUrl;
|
|
794
819
|
|
|
795
820
|
// Attach user info for project HTTP handler
|
|
796
|
-
req.
|
|
821
|
+
req._clagenticUser = getMultiUserFromReq(req);
|
|
797
822
|
|
|
798
823
|
// Try project HTTP handler first (APIs)
|
|
799
824
|
var origUrl = req.url;
|
|
@@ -881,14 +906,14 @@ function createServer(opts) {
|
|
|
881
906
|
// handleProtocols echoes back the offered subprotocol whenever the client
|
|
882
907
|
// offered one and the upgrade authenticated (via ticket OR cookie — see
|
|
883
908
|
// lr-4c58ae): the WS spec requires the 101 response to echo an accepted
|
|
884
|
-
// subprotocol when one was offered, on any auth path. req.
|
|
909
|
+
// subprotocol when one was offered, on any auth path. req._clagenticAcceptedProtocol
|
|
885
910
|
// is set by the upgrade handler below after auth resolves, BEFORE
|
|
886
911
|
// wss.handleUpgrade() is called, so it is available here.
|
|
887
912
|
var wss = new WebSocketServer({
|
|
888
913
|
noServer: true,
|
|
889
914
|
handleProtocols: function (protocols, req) {
|
|
890
|
-
if (req.
|
|
891
|
-
return req.
|
|
915
|
+
if (req._clagenticAcceptedProtocol && protocols.has(req._clagenticAcceptedProtocol)) {
|
|
916
|
+
return req._clagenticAcceptedProtocol;
|
|
892
917
|
}
|
|
893
918
|
return false;
|
|
894
919
|
},
|
|
@@ -976,7 +1001,7 @@ function createServer(opts) {
|
|
|
976
1001
|
// what authenticated this request, so echo it as-is without burning it).
|
|
977
1002
|
// See the WebSocketServer handleProtocols hook above.
|
|
978
1003
|
if (offeredTicket && (wsTicketUser || wsCookieUser)) {
|
|
979
|
-
req.
|
|
1004
|
+
req._clagenticAcceptedProtocol = "clagentic.auth." + offeredTicket;
|
|
980
1005
|
}
|
|
981
1006
|
|
|
982
1007
|
// Drain gate (lr-6b30): reject new sessions while draining so in-flight
|
|
@@ -1064,9 +1089,17 @@ function createServer(opts) {
|
|
|
1064
1089
|
}
|
|
1065
1090
|
return origEmit.apply(ws, arguments);
|
|
1066
1091
|
};
|
|
1067
|
-
ws.
|
|
1092
|
+
ws._clagenticUser = wsUser; // attach user context
|
|
1068
1093
|
var remoteAddr = req.socket.remoteAddress || "";
|
|
1069
|
-
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
|
+
});
|
|
1070
1103
|
// Clear cross-project unread for this project when client connects.
|
|
1071
1104
|
// lr-0aa7b6: map is keyed per-session ("slug::localId") now, so clear
|
|
1072
1105
|
// every entry whose slug prefix matches the project just connected to.
|
|
@@ -1122,12 +1155,12 @@ function createServer(opts) {
|
|
|
1122
1155
|
// (lib/project-loop.js hub_recent_sessions_list) to attribute the alert
|
|
1123
1156
|
// state to the individual notifying session rather than the whole project.
|
|
1124
1157
|
// ownSlug is the slug of the project ws is connected to: for that project,
|
|
1125
|
-
// unread is tracked per-session via ws.
|
|
1158
|
+
// unread is tracked per-session via ws._clagenticUnread[localId] (the existing
|
|
1126
1159
|
// same-project mechanism in lib/sessions.js doSendAndRecord); for every
|
|
1127
1160
|
// other project, unread is tracked via the composite crossProjectUnread map.
|
|
1128
1161
|
function getSessionUnread(ws, ownSlug, sessSlug, localId) {
|
|
1129
1162
|
if (sessSlug === ownSlug) {
|
|
1130
|
-
var ownMap = ws.
|
|
1163
|
+
var ownMap = ws._clagenticUnread || {};
|
|
1131
1164
|
return ownMap[localId] || 0;
|
|
1132
1165
|
}
|
|
1133
1166
|
var map = getCrossProjectUnread(ws);
|
|
@@ -1152,7 +1185,7 @@ function createServer(opts) {
|
|
|
1152
1185
|
// lr-13c047 (Badge A prune-on-delete): a deleted session's crossProjectUnread
|
|
1153
1186
|
// entry previously had no clear path at all — onSessionDone is increment-only
|
|
1154
1187
|
// and the only clears were on full project-switch reconnect (below) or the
|
|
1155
|
-
// same-project ws.
|
|
1188
|
+
// same-project ws._clagenticUnread zeroing in switchSession. If the session that
|
|
1156
1189
|
// accrued the unread count is deleted before any client ever reconnects to
|
|
1157
1190
|
// its project, that count is now permanently unreachable (its key can never
|
|
1158
1191
|
// be zeroed by the connect-time prefix clear, since the session no longer
|
|
@@ -1207,7 +1240,7 @@ function createServer(opts) {
|
|
|
1207
1240
|
ctx.forEachClient(function (ws) {
|
|
1208
1241
|
var filtered = allProjectsList;
|
|
1209
1242
|
if (onGetProjectAccess) {
|
|
1210
|
-
var wsUser = ws.
|
|
1243
|
+
var wsUser = ws._clagenticUser;
|
|
1211
1244
|
if (wsUser) {
|
|
1212
1245
|
filtered = allProjectsList.filter(function (p) {
|
|
1213
1246
|
var access = onGetProjectAccess(p.slug);
|
|
@@ -1238,7 +1271,7 @@ function createServer(opts) {
|
|
|
1238
1271
|
type: "projects_updated",
|
|
1239
1272
|
projects: projectsWithUnread,
|
|
1240
1273
|
projectCount: projectsWithUnread.length,
|
|
1241
|
-
removedProjects: getRemovedProjects(ws.
|
|
1274
|
+
removedProjects: getRemovedProjects(ws._clagenticUser ? ws._clagenticUser.id : null),
|
|
1242
1275
|
folderMeta: getFolderMeta(),
|
|
1243
1276
|
}));
|
|
1244
1277
|
}
|
|
@@ -1299,7 +1332,7 @@ function createServer(opts) {
|
|
|
1299
1332
|
// no sessions are returned. There is no legitimate no-auth caller of
|
|
1300
1333
|
// this function -- the WS upgrade handler above rejects any connection
|
|
1301
1334
|
// without an authenticated user (wsAuthedUser) with 401 before
|
|
1302
|
-
// ws.
|
|
1335
|
+
// ws._clagenticUser can ever be set, including in single-user/PIN mode
|
|
1303
1336
|
// (still a real authenticated user, just one account) -- so failing
|
|
1304
1337
|
// closed here never breaks a real deployment mode.
|
|
1305
1338
|
getAllProjectSessions: function (includeSelf, userId) {
|
|
@@ -1388,7 +1421,7 @@ function createServer(opts) {
|
|
|
1388
1421
|
markCrossProjectRead: function (ws, projSlug) { markCrossProjectRead(ws, projSlug); },
|
|
1389
1422
|
// lr-0aa7b6: per-session unread lookup for the Home Hub Recent
|
|
1390
1423
|
// Sessions data path — see getSessionUnread's header above for why
|
|
1391
|
-
// this must distinguish "own project" (ws.
|
|
1424
|
+
// this must distinguish "own project" (ws._clagenticUnread) from
|
|
1392
1425
|
// "other project" (composite crossProjectUnread map).
|
|
1393
1426
|
getSessionUnread: function (ws, sessSlug, localId) { return getSessionUnread(ws, slug, sessSlug, localId); },
|
|
1394
1427
|
onAddProject: onAddProject,
|
|
@@ -1547,8 +1580,8 @@ function createServer(opts) {
|
|
|
1547
1580
|
var list = [];
|
|
1548
1581
|
projects.forEach(function (ctx) {
|
|
1549
1582
|
ctx.forEachClient(function (ws) {
|
|
1550
|
-
if (!ws.
|
|
1551
|
-
var u = ws.
|
|
1583
|
+
if (!ws._clagenticUser) return;
|
|
1584
|
+
var u = ws._clagenticUser;
|
|
1552
1585
|
if (seen[u.id]) return;
|
|
1553
1586
|
seen[u.id] = true;
|
|
1554
1587
|
var p = u.profile || {};
|
|
@@ -1590,7 +1623,7 @@ function createServer(opts) {
|
|
|
1590
1623
|
var sentUsers = {};
|
|
1591
1624
|
projects.forEach(function (ctx) {
|
|
1592
1625
|
ctx.forEachClient(function (ws) {
|
|
1593
|
-
var userId = ws.
|
|
1626
|
+
var userId = ws._clagenticUser ? ws._clagenticUser.id : null;
|
|
1594
1627
|
var key = userId || "__anon__";
|
|
1595
1628
|
if (sentUsers[key]) {
|
|
1596
1629
|
// Already computed for this user, just send the cached msg
|
|
@@ -1650,7 +1683,7 @@ function createServer(opts) {
|
|
|
1650
1683
|
projects.forEach(function (ctx) {
|
|
1651
1684
|
if (typeof ctx.forEachClient !== "function") return;
|
|
1652
1685
|
ctx.forEachClient(function (ws) {
|
|
1653
|
-
if (ws.
|
|
1686
|
+
if (ws._clagenticUser && ws._clagenticUser.id === userId && ws.readyState === 1) {
|
|
1654
1687
|
ws.send(data);
|
|
1655
1688
|
}
|
|
1656
1689
|
});
|
|
@@ -1666,7 +1699,7 @@ function createServer(opts) {
|
|
|
1666
1699
|
if (typeof ctx.forEachClient !== "function") return;
|
|
1667
1700
|
ctx.forEachClient(function (ws) {
|
|
1668
1701
|
if (found) return;
|
|
1669
|
-
if (ws.
|
|
1702
|
+
if (ws._clagenticUser && ws._clagenticUser.id === userId && ws.readyState === 1) {
|
|
1670
1703
|
found = true;
|
|
1671
1704
|
}
|
|
1672
1705
|
});
|
package/lib/session-activity.js
CHANGED
|
@@ -258,7 +258,7 @@ function replaceRegistry(session, snapshot) {
|
|
|
258
258
|
|
|
259
259
|
/**
|
|
260
260
|
* Detailed per-source breakdown of currently-live tokens, for scoping to
|
|
261
|
-
* the viewing client only (ws.
|
|
261
|
+
* the viewing client only (ws._clagenticActiveSession-style filtering) rather
|
|
262
262
|
* than broadcasting to every connected client -- see lr-9bcd7b spec's
|
|
263
263
|
* chattiness mitigation #3.
|
|
264
264
|
* @param {object} session
|
package/lib/sessions.js
CHANGED
|
@@ -837,8 +837,8 @@ function createSessionManager(opts) {
|
|
|
837
837
|
// Per-client filtering (multi-user mode)
|
|
838
838
|
sendEach(function (ws, filterFn) {
|
|
839
839
|
var filtered = filterFn ? allVisible.filter(filterFn) : allVisible;
|
|
840
|
-
var clientActiveId = ws.
|
|
841
|
-
var wsUnread = ws.
|
|
840
|
+
var clientActiveId = ws._clagenticActiveSession;
|
|
841
|
+
var wsUnread = ws._clagenticUnread || {};
|
|
842
842
|
if (ws.readyState === 1) {
|
|
843
843
|
ws.send(JSON.stringify({
|
|
844
844
|
type: "session_list",
|
|
@@ -1074,15 +1074,15 @@ function createSessionManager(opts) {
|
|
|
1074
1074
|
// (targetWs=null) bypass this gate — they operate on already-validated session
|
|
1075
1075
|
// references.
|
|
1076
1076
|
//
|
|
1077
|
-
// No-auth / single-user connections have
|
|
1077
|
+
// No-auth / single-user connections have _clagenticUser === null (set by
|
|
1078
1078
|
// project-connection.js:92 as wsUser || null). In that deployment there is
|
|
1079
1079
|
// no user identity to check — the connection is the implicit owner. We skip
|
|
1080
|
-
// the gate entirely for null users so that
|
|
1080
|
+
// the gate entirely for null users so that _clagenticActiveSession is still
|
|
1081
1081
|
// bound below, keeping the live-broadcast filter (doSendAndRecord /
|
|
1082
1082
|
// doSendToSession) in sync. Authenticated users who lack access are still
|
|
1083
1083
|
// rejected by canAccessSession. (regression introduced by dca60a7, lr-690b)
|
|
1084
1084
|
if (targetWs) {
|
|
1085
|
-
var requestingUser = targetWs.
|
|
1085
|
+
var requestingUser = targetWs._clagenticUser || null;
|
|
1086
1086
|
if (requestingUser) {
|
|
1087
1087
|
// Use { visibility: "public" } so canAccessProject passes and the
|
|
1088
1088
|
// session-level ownership/visibility rules do the real work.
|
|
@@ -1091,18 +1091,18 @@ function createSessionManager(opts) {
|
|
|
1091
1091
|
return;
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
|
-
// null requestingUser = no-auth deployment; fall through to bind
|
|
1094
|
+
// null requestingUser = no-auth deployment; fall through to bind _clagenticActiveSession.
|
|
1095
1095
|
}
|
|
1096
1096
|
|
|
1097
1097
|
activeSessionId = localId;
|
|
1098
1098
|
if (targetWs) {
|
|
1099
|
-
targetWs.
|
|
1099
|
+
targetWs._clagenticActiveSession = localId;
|
|
1100
1100
|
// Clear unread for this session (multi-user)
|
|
1101
|
-
if (targetWs.
|
|
1101
|
+
if (targetWs._clagenticUnread) targetWs._clagenticUnread[localId] = 0;
|
|
1102
1102
|
} else if (sendEach) {
|
|
1103
1103
|
// No specific target: update all connected clients (server-initiated switch)
|
|
1104
1104
|
sendEach(function (ws) {
|
|
1105
|
-
ws.
|
|
1105
|
+
ws._clagenticActiveSession = localId;
|
|
1106
1106
|
});
|
|
1107
1107
|
}
|
|
1108
1108
|
// Update LRU when a session is switched to (history will be loaded in replayHistory).
|
|
@@ -1289,7 +1289,7 @@ function createSessionManager(opts) {
|
|
|
1289
1289
|
if (sendEach) {
|
|
1290
1290
|
var data = JSON.stringify(obj);
|
|
1291
1291
|
sendEach(function (ws) {
|
|
1292
|
-
if (ws.
|
|
1292
|
+
if (ws._clagenticActiveSession === session.localId && ws.readyState === 1) {
|
|
1293
1293
|
ws.send(data);
|
|
1294
1294
|
}
|
|
1295
1295
|
});
|
|
@@ -1319,7 +1319,7 @@ function createSessionManager(opts) {
|
|
|
1319
1319
|
var data = JSON.stringify(obj);
|
|
1320
1320
|
var ioData = null;
|
|
1321
1321
|
sendEach(function (ws) {
|
|
1322
|
-
if (ws.
|
|
1322
|
+
if (ws._clagenticActiveSession === session.localId) {
|
|
1323
1323
|
if (ws.readyState === 1) ws.send(data);
|
|
1324
1324
|
} else if (session.isProcessing && !session._ioThrottle) {
|
|
1325
1325
|
if (!ioData) ioData = JSON.stringify({ type: "session_io", id: session.localId });
|
|
@@ -1327,13 +1327,13 @@ function createSessionManager(opts) {
|
|
|
1327
1327
|
}
|
|
1328
1328
|
// Track unread: increment on "done" for clients not viewing this session
|
|
1329
1329
|
// Only count if session has no owner (my session) or owner matches this client
|
|
1330
|
-
if (obj.type === "done" && ws.
|
|
1331
|
-
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);
|
|
1332
1332
|
if (_isMySession) {
|
|
1333
|
-
if (!ws.
|
|
1334
|
-
ws.
|
|
1333
|
+
if (!ws._clagenticUnread) ws._clagenticUnread = {};
|
|
1334
|
+
ws._clagenticUnread[session.localId] = (ws._clagenticUnread[session.localId] || 0) + 1;
|
|
1335
1335
|
if (ws.readyState === 1) {
|
|
1336
|
-
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] }));
|
|
1337
1337
|
}
|
|
1338
1338
|
}
|
|
1339
1339
|
}
|
|
@@ -1665,7 +1665,7 @@ function createSessionManager(opts) {
|
|
|
1665
1665
|
broadcastSessionList: broadcastSessionList,
|
|
1666
1666
|
broadcastSessionDeleted: broadcastSessionDeleted,
|
|
1667
1667
|
getTotalUnread: function (ws) {
|
|
1668
|
-
var unreadMap = (ws && ws.
|
|
1668
|
+
var unreadMap = (ws && ws._clagenticUnread) ? ws._clagenticUnread : {};
|
|
1669
1669
|
var total = 0;
|
|
1670
1670
|
var keys = Object.keys(unreadMap);
|
|
1671
1671
|
for (var i = 0; i < keys.length; i++) {
|
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/package.json
CHANGED