@clagentic/console 1.5.0-beta.2 → 1.5.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +18 -14
  2. package/bin/cli.js +1 -0
  3. package/lib/cli-sessions.js +71 -18
  4. package/lib/config.js +80 -6
  5. package/lib/daemon-projects.js +1 -1
  6. package/lib/daemon.js +142 -26
  7. package/lib/pages.js +1 -42
  8. package/lib/project-connection.js +4 -8
  9. package/lib/project-external-trigger.js +62 -7
  10. package/lib/project-http.js +17 -1
  11. package/lib/project-loop.js +3 -2
  12. package/lib/project-notifications.js +3 -18
  13. package/lib/project-sessions.js +68 -27
  14. package/lib/project-team.js +417 -0
  15. package/lib/project-user-message.js +5 -10
  16. package/lib/project.js +53 -53
  17. package/lib/public/app.js +7 -15
  18. package/lib/public/css/home-hub.css +36 -0
  19. package/lib/public/css/icon-strip.css +28 -126
  20. package/lib/public/css/menus.css +2 -2
  21. package/lib/public/css/team-panel.css +149 -0
  22. package/lib/public/index.html +72 -15
  23. package/lib/public/modules/admin.js +1 -52
  24. package/lib/public/modules/agent-picker.js +11 -3
  25. package/lib/public/modules/app-cursors.js +43 -47
  26. package/lib/public/modules/app-home-hub.js +12 -0
  27. package/lib/public/modules/app-messages.js +18 -12
  28. package/lib/public/modules/app-rendering.js +1 -2
  29. package/lib/public/modules/server-settings.js +74 -5
  30. package/lib/public/modules/sidebar-mobile.js +9 -88
  31. package/lib/public/modules/sidebar-projects.js +1 -1
  32. package/lib/public/modules/sidebar-sessions.js +6 -2
  33. package/lib/public/modules/sidebar-users.js +37 -307
  34. package/lib/public/modules/team-panel.js +331 -0
  35. package/lib/public/modules/tools.js +3 -0
  36. package/lib/public/modules/user-settings.js +0 -3
  37. package/lib/public/style.css +1 -0
  38. package/lib/sdk-bridge.js +121 -8
  39. package/lib/sdk-message-processor.js +39 -4
  40. package/lib/sdk-worker.js +2 -2
  41. package/lib/server-admin.js +1 -86
  42. package/lib/server-auth.js +13 -124
  43. package/lib/server-dm.js +2 -7
  44. package/lib/server-palette.js +9 -20
  45. package/lib/server-settings.js +41 -243
  46. package/lib/server-skills.js +11 -13
  47. package/lib/server.js +37 -60
  48. package/lib/sessions.js +16 -50
  49. package/lib/terminal-manager.js +13 -15
  50. package/lib/users-auth.js +0 -38
  51. package/lib/users.js +14 -11
  52. package/lib/ws-schema.js +12 -0
  53. package/lib/yoke/adapters/claude.js +5 -0
  54. package/package.json +1 -1
@@ -15,55 +15,21 @@ function attachSettings(ctx) {
15
15
  function handleRequest(req, res, fullUrl) {
16
16
  // GET /api/profile
17
17
  if (req.method === "GET" && fullUrl === "/api/profile") {
18
- if (users.isMultiUser()) {
19
- var mu = getMultiUserFromReq(req);
20
- if (!mu) {
21
- res.writeHead(401, { "Content-Type": "application/json" });
22
- res.end('{"error":"unauthorized"}');
23
- return true;
24
- }
25
- var profile = mu.profile || { name: "", lang: "en-US", avatarColor: "#7c3aed", avatarStyle: "thumbs", avatarSeed: "", avatarCustom: "" };
26
- profile.username = mu.username;
27
- profile.userId = mu.id;
28
- profile.role = mu.role;
29
- profile.pinEnabled = !!mu.pinHash;
30
- profile.autoContinueOnRateLimit = !!mu.autoContinueOnRateLimit;
31
- profile.chatLayout = mu.chatLayout || "channel";
32
- profile.themeMode = mu.themeMode || null;
33
- profile.themeBrand = mu.themeBrand || null;
34
- res.writeHead(200, { "Content-Type": "application/json" });
35
- res.end(JSON.stringify(profile));
18
+ var mu = getMultiUserFromReq(req);
19
+ if (!mu) {
20
+ res.writeHead(401, { "Content-Type": "application/json" });
21
+ res.end('{"error":"unauthorized"}');
36
22
  return true;
37
23
  }
38
- var profile = { name: "", lang: "en-US", avatarColor: "#7c3aed", avatarStyle: "thumbs", avatarSeed: "", avatarCustom: "" };
39
- try {
40
- var raw = fs.readFileSync(profilePath, "utf8");
41
- var saved = JSON.parse(raw);
42
- if (saved.name !== undefined) profile.name = saved.name;
43
- if (saved.lang) profile.lang = saved.lang;
44
- if (saved.avatarColor) profile.avatarColor = saved.avatarColor;
45
- if (saved.avatarStyle) profile.avatarStyle = saved.avatarStyle;
46
- if (saved.avatarSeed) profile.avatarSeed = saved.avatarSeed;
47
- if (saved.avatarCustom) profile.avatarCustom = saved.avatarCustom;
48
- } catch (e) { /* file doesn't exist yet */ }
49
- // Single-user settings from daemon config
50
- if (typeof opts.onGetDaemonConfig === "function") {
51
- var dc = opts.onGetDaemonConfig();
52
- profile.autoContinueOnRateLimit = !!dc.autoContinueOnRateLimit;
53
- profile.chatLayout = dc.chatLayout || "channel";
54
- profile.themeMode = dc.themeMode || null;
55
- profile.themeBrand = dc.themeBrand || null;
56
- }
57
- // Check if custom avatar file exists
58
- try {
59
- var avatarFiles = fs.readdirSync(path.join(CONFIG_DIR, "avatars"));
60
- for (var afi = 0; afi < avatarFiles.length; afi++) {
61
- if (avatarFiles[afi].startsWith("default.")) {
62
- profile.avatarCustom = "/api/avatar/default?v=" + fs.statSync(path.join(CONFIG_DIR, "avatars", avatarFiles[afi])).mtimeMs;
63
- break;
64
- }
65
- }
66
- } catch (e) {}
24
+ var profile = mu.profile || { name: "", lang: "en-US", avatarColor: "#7c3aed", avatarStyle: "thumbs", avatarSeed: "", avatarCustom: "" };
25
+ profile.username = mu.username;
26
+ profile.userId = mu.id;
27
+ profile.role = mu.role;
28
+ profile.pinEnabled = !!mu.pinHash;
29
+ profile.autoContinueOnRateLimit = !!mu.autoContinueOnRateLimit;
30
+ profile.chatLayout = mu.chatLayout || "channel";
31
+ profile.themeMode = mu.themeMode || null;
32
+ profile.themeBrand = mu.themeBrand || null;
67
33
  res.writeHead(200, { "Content-Type": "application/json" });
68
34
  res.end(JSON.stringify(profile));
69
35
  return true;
@@ -86,29 +52,17 @@ function attachSettings(ctx) {
86
52
  if (typeof data.avatarSeed === "string") profile.avatarSeed = data.avatarSeed.substring(0, 30);
87
53
  if (typeof data.avatarCustom === "string") profile.avatarCustom = data.avatarCustom;
88
54
  if (data.avatarCustom === null || data.avatarCustom === "") profile.avatarCustom = undefined;
89
- if (users.isMultiUser()) {
90
- var mu = getMultiUserFromReq(req);
91
- if (!mu) {
92
- res.writeHead(401, { "Content-Type": "application/json" });
93
- res.end('{"error":"unauthorized"}');
94
- return;
95
- }
96
- users.updateUserProfile(mu.id, profile);
97
- // Broadcast updated avatar/presence to all projects
98
- projects.forEach(function (pCtx) {
99
- pCtx.refreshUserProfile(mu.id);
100
- });
101
- } else {
102
- if (!isRequestAuthed(req)) {
103
- res.writeHead(401, { "Content-Type": "application/json" });
104
- res.end('{"error":"unauthorized"}');
105
- return;
106
- }
107
- fs.writeFileSync(profilePath, JSON.stringify(profile, null, 2), "utf8");
108
- if (process.platform !== "win32") {
109
- try { fs.chmodSync(profilePath, 0o600); } catch (chmodErr) {}
110
- }
55
+ var mu = getMultiUserFromReq(req);
56
+ if (!mu) {
57
+ res.writeHead(401, { "Content-Type": "application/json" });
58
+ res.end('{"error":"unauthorized"}');
59
+ return;
111
60
  }
61
+ users.updateUserProfile(mu.id, profile);
62
+ // Broadcast updated avatar/presence to all projects
63
+ projects.forEach(function (pCtx) {
64
+ pCtx.refreshUserProfile(mu.id);
65
+ });
112
66
  res.writeHead(200, { "Content-Type": "application/json" });
113
67
  res.end(JSON.stringify(profile));
114
68
  } catch (e) {
@@ -150,22 +104,13 @@ function attachSettings(ctx) {
150
104
  var avatarDir = path.join(CONFIG_DIR, "avatars");
151
105
  fs.mkdirSync(avatarDir, { recursive: true });
152
106
 
153
- var userId = "default";
154
- if (users.isMultiUser()) {
155
- var mu = getMultiUserFromReq(req);
156
- if (!mu) {
157
- res.writeHead(401, { "Content-Type": "application/json" });
158
- res.end('{"error":"unauthorized"}');
159
- return;
160
- }
161
- userId = mu.id;
162
- } else {
163
- if (!isRequestAuthed(req)) {
164
- res.writeHead(401, { "Content-Type": "application/json" });
165
- res.end('{"error":"unauthorized"}');
166
- return;
167
- }
107
+ var mu = getMultiUserFromReq(req);
108
+ if (!mu) {
109
+ res.writeHead(401, { "Content-Type": "application/json" });
110
+ res.end('{"error":"unauthorized"}');
111
+ return;
168
112
  }
113
+ var userId = mu.id;
169
114
  var filename = userId + "." + ext;
170
115
  // Remove old avatar files for this user
171
116
  try {
@@ -215,13 +160,8 @@ function attachSettings(ctx) {
215
160
  return true;
216
161
  }
217
162
 
218
- // Change own PIN (multi-user mode)
163
+ // Change own PIN
219
164
  if (req.method === "PUT" && fullUrl === "/api/user/pin") {
220
- if (!users.isMultiUser()) {
221
- res.writeHead(404, { "Content-Type": "application/json" });
222
- res.end('{"error":"Not found"}');
223
- return true;
224
- }
225
165
  var mu = getMultiUserFromReq(req);
226
166
  if (!mu) {
227
167
  res.writeHead(401, { "Content-Type": "application/json" });
@@ -273,32 +213,7 @@ function attachSettings(ctx) {
273
213
 
274
214
  // PUT /api/user/auto-continue
275
215
  if (req.method === "PUT" && fullUrl === "/api/user/auto-continue") {
276
- var isMultiUser = users.isMultiUser();
277
216
  var mu = getMultiUserFromReq(req);
278
- if (!isMultiUser) {
279
- // Single-user: use daemon config fallback
280
- if (!isRequestAuthed(req)) {
281
- res.writeHead(401, { "Content-Type": "application/json" });
282
- res.end('{"error":"unauthorized"}');
283
- return true;
284
- }
285
- var body = "";
286
- req.on("data", function (chunk) { body += chunk; });
287
- req.on("end", function () {
288
- try {
289
- var data = JSON.parse(body);
290
- if (typeof opts.onSetAutoContinue === "function") {
291
- opts.onSetAutoContinue(!!data.enabled);
292
- }
293
- res.writeHead(200, { "Content-Type": "application/json" });
294
- res.end(JSON.stringify({ ok: true, autoContinueOnRateLimit: !!data.enabled }));
295
- } catch (e) {
296
- res.writeHead(400, { "Content-Type": "application/json" });
297
- res.end('{"error":"Invalid request"}');
298
- }
299
- });
300
- return true;
301
- }
302
217
  if (!mu) {
303
218
  res.writeHead(401, { "Content-Type": "application/json" });
304
219
  res.end('{"error":"unauthorized"}');
@@ -327,33 +242,7 @@ function attachSettings(ctx) {
327
242
 
328
243
  // PUT /api/user/chat-layout
329
244
  if (req.method === "PUT" && fullUrl === "/api/user/chat-layout") {
330
- var isMultiUser = users.isMultiUser();
331
245
  var mu = getMultiUserFromReq(req);
332
- if (!isMultiUser) {
333
- // Single-user: save to daemon config
334
- if (!isRequestAuthed(req)) {
335
- res.writeHead(401, { "Content-Type": "application/json" });
336
- res.end('{"error":"unauthorized"}');
337
- return true;
338
- }
339
- var body = "";
340
- req.on("data", function (chunk) { body += chunk; });
341
- req.on("end", function () {
342
- try {
343
- var data = JSON.parse(body);
344
- var val = (data.layout === "bubble") ? "bubble" : "channel";
345
- if (typeof opts.onSetChatLayout === "function") {
346
- opts.onSetChatLayout(val);
347
- }
348
- res.writeHead(200, { "Content-Type": "application/json" });
349
- res.end(JSON.stringify({ ok: true, chatLayout: val }));
350
- } catch (e) {
351
- res.writeHead(400, { "Content-Type": "application/json" });
352
- res.end('{"error":"Invalid request"}');
353
- }
354
- });
355
- return true;
356
- }
357
246
  if (!mu) {
358
247
  res.writeHead(401, { "Content-Type": "application/json" });
359
248
  res.end('{"error":"unauthorized"}');
@@ -382,9 +271,8 @@ function attachSettings(ctx) {
382
271
 
383
272
  // PUT /api/user/theme-mode
384
273
  if (req.method === "PUT" && fullUrl === "/api/user/theme-mode") {
385
- var isMultiUser = users.isMultiUser();
386
274
  var mu = getMultiUserFromReq(req);
387
- if (!isMultiUser && !isRequestAuthed(req)) {
275
+ if (!mu) {
388
276
  res.writeHead(401, { "Content-Type": "application/json" });
389
277
  res.end('{"error":"unauthorized"}');
390
278
  return true;
@@ -395,19 +283,6 @@ function attachSettings(ctx) {
395
283
  try {
396
284
  var data = JSON.parse(body);
397
285
  var mode = (data.themeMode === "light" || data.themeMode === "dark") ? data.themeMode : null;
398
- if (!isMultiUser) {
399
- if (typeof opts.onSetThemeMode === "function") {
400
- opts.onSetThemeMode(mode);
401
- }
402
- res.writeHead(200, { "Content-Type": "application/json" });
403
- res.end(JSON.stringify({ ok: true, themeMode: mode }));
404
- return;
405
- }
406
- if (!mu) {
407
- res.writeHead(401, { "Content-Type": "application/json" });
408
- res.end('{"error":"unauthorized"}');
409
- return;
410
- }
411
286
  var result = users.setThemeMode(mu.id, mode);
412
287
  if (result.error) {
413
288
  res.writeHead(400, { "Content-Type": "application/json" });
@@ -426,9 +301,8 @@ function attachSettings(ctx) {
426
301
 
427
302
  // PUT /api/user/theme-brand
428
303
  if (req.method === "PUT" && fullUrl === "/api/user/theme-brand") {
429
- var isMultiUser = users.isMultiUser();
430
304
  var mu = getMultiUserFromReq(req);
431
- if (!isMultiUser && !isRequestAuthed(req)) {
305
+ if (!mu) {
432
306
  res.writeHead(401, { "Content-Type": "application/json" });
433
307
  res.end('{"error":"unauthorized"}');
434
308
  return true;
@@ -439,19 +313,6 @@ function attachSettings(ctx) {
439
313
  try {
440
314
  var data = JSON.parse(body);
441
315
  var brand = (data.themeBrand === "classic" || data.themeBrand === "clagentic") ? data.themeBrand : null;
442
- if (!isMultiUser) {
443
- if (typeof opts.onSetThemeBrand === "function") {
444
- opts.onSetThemeBrand(brand);
445
- }
446
- res.writeHead(200, { "Content-Type": "application/json" });
447
- res.end(JSON.stringify({ ok: true, themeBrand: brand }));
448
- return;
449
- }
450
- if (!mu) {
451
- res.writeHead(401, { "Content-Type": "application/json" });
452
- res.end('{"error":"unauthorized"}');
453
- return;
454
- }
455
316
  var result = users.setThemeBrand(mu.id, brand);
456
317
  if (result.error) {
457
318
  res.writeHead(400, { "Content-Type": "application/json" });
@@ -470,21 +331,13 @@ function attachSettings(ctx) {
470
331
 
471
332
  // GET /api/user/tool-palettes
472
333
  if (req.method === "GET" && fullUrl === "/api/user/tool-palettes") {
473
- var isMultiUser = users.isMultiUser();
474
334
  var muGet = getMultiUserFromReq(req);
475
- var palettes = {};
476
- if (!isMultiUser) {
477
- if (typeof opts.onGetToolPalettes === "function") {
478
- palettes = opts.onGetToolPalettes() || {};
479
- }
480
- } else {
481
- if (!muGet) {
482
- res.writeHead(401, { "Content-Type": "application/json" });
483
- res.end('{"error":"unauthorized"}');
484
- return true;
485
- }
486
- palettes = users.getToolPalettes(muGet.id) || {};
335
+ if (!muGet) {
336
+ res.writeHead(401, { "Content-Type": "application/json" });
337
+ res.end('{"error":"unauthorized"}');
338
+ return true;
487
339
  }
340
+ var palettes = users.getToolPalettes(muGet.id) || {};
488
341
  res.writeHead(200, { "Content-Type": "application/json" });
489
342
  res.end(JSON.stringify(palettes));
490
343
  return true;
@@ -492,9 +345,8 @@ function attachSettings(ctx) {
492
345
 
493
346
  // PUT /api/user/tool-palettes
494
347
  if (req.method === "PUT" && fullUrl === "/api/user/tool-palettes") {
495
- var isMultiUser = users.isMultiUser();
496
348
  var muPut = getMultiUserFromReq(req);
497
- if (!isMultiUser && !isRequestAuthed(req)) {
349
+ if (!muPut) {
498
350
  res.writeHead(401, { "Content-Type": "application/json" });
499
351
  res.end('{"error":"unauthorized"}');
500
352
  return true;
@@ -507,22 +359,7 @@ function attachSettings(ctx) {
507
359
  var paletteName = dataTp.palette;
508
360
  var order = dataTp.order;
509
361
  var hidden = dataTp.hidden;
510
- var result;
511
- if (!isMultiUser) {
512
- if (typeof opts.onSetToolPalette !== "function") {
513
- res.writeHead(500, { "Content-Type": "application/json" });
514
- res.end('{"error":"Not supported"}');
515
- return;
516
- }
517
- result = opts.onSetToolPalette(paletteName, order, hidden);
518
- } else {
519
- if (!muPut) {
520
- res.writeHead(401, { "Content-Type": "application/json" });
521
- res.end('{"error":"unauthorized"}');
522
- return;
523
- }
524
- result = users.setToolPalette(muPut.id, paletteName, order, hidden);
525
- }
362
+ var result = users.setToolPalette(muPut.id, paletteName, order, hidden);
526
363
  if (result && result.error) {
527
364
  res.writeHead(400, { "Content-Type": "application/json" });
528
365
  res.end(JSON.stringify({ error: result.error }));
@@ -542,14 +379,8 @@ function attachSettings(ctx) {
542
379
  if (req.method === "GET" && fullUrl === "/api/user/auto-continue") {
543
380
  var mu = getMultiUserFromReq(req);
544
381
  if (!mu) {
545
- // Single-user: read from daemon config
546
- var enabled = false;
547
- if (typeof opts.onGetDaemonConfig === "function") {
548
- var dc = opts.onGetDaemonConfig();
549
- enabled = !!dc.autoContinueOnRateLimit;
550
- }
551
- res.writeHead(200, { "Content-Type": "application/json" });
552
- res.end(JSON.stringify({ autoContinueOnRateLimit: enabled }));
382
+ res.writeHead(401, { "Content-Type": "application/json" });
383
+ res.end('{"error":"unauthorized"}');
553
384
  return true;
554
385
  }
555
386
  var val = users.getAutoContinue(mu.id);
@@ -558,39 +389,6 @@ function attachSettings(ctx) {
558
389
  return true;
559
390
  }
560
391
 
561
-
562
- // POST /api/settings/enable-multiuser — Enable multi-user mode (single-user only)
563
- if (req.method === "POST" && fullUrl === "/api/settings/enable-multiuser") {
564
- if (users.isMultiUser()) {
565
- res.writeHead(400, { "Content-Type": "application/json" });
566
- res.end('{"error":"Already in multi-user mode"}');
567
- return true;
568
- }
569
- if (!isRequestAuthed(req)) {
570
- res.writeHead(401, { "Content-Type": "application/json" });
571
- res.end('{"error":"unauthorized"}');
572
- return true;
573
- }
574
- // Only allow in single-user mode with PIN
575
- if (!opts.pinHash) {
576
- res.writeHead(400, { "Content-Type": "application/json" });
577
- res.end('{"error":"PIN mode not enabled"}');
578
- return true;
579
- }
580
- var result = users.enableMultiUser();
581
- if (result.error) {
582
- res.writeHead(400, { "Content-Type": "application/json" });
583
- res.end(JSON.stringify({ error: result.error }));
584
- return true;
585
- }
586
- audit.log("settings.multiuser.enable", {
587
- actorId: "system",
588
- metadata: null,
589
- });
590
- res.writeHead(200, { "Content-Type": "application/json" });
591
- res.end(JSON.stringify({ ok: true, setupCode: result.setupCode }));
592
- return true;
593
- }
594
392
  return false;
595
393
  }
596
394
 
@@ -162,19 +162,17 @@ function attachSkills(ctx) {
162
162
  }
163
163
 
164
164
  // Permission gate
165
- if (users.isMultiUser()) {
166
- var skMu = getMultiUserFromReq(req);
167
- if (!skMu) {
168
- res.writeHead(401, { "Content-Type": "application/json" });
169
- res.end('{"error":"unauthorized"}');
170
- return true;
171
- }
172
- var skPerms = users.getEffectivePermissions(skMu, osUsers);
173
- if (!skPerms.skills) {
174
- res.writeHead(403, { "Content-Type": "application/json" });
175
- res.end('{"error":"Skills access is not permitted"}');
176
- return true;
177
- }
165
+ var skMu = getMultiUserFromReq(req);
166
+ if (!skMu) {
167
+ res.writeHead(401, { "Content-Type": "application/json" });
168
+ res.end('{"error":"unauthorized"}');
169
+ return true;
170
+ }
171
+ var skPerms = users.getEffectivePermissions(skMu, osUsers);
172
+ if (!skPerms.skills) {
173
+ res.writeHead(403, { "Content-Type": "application/json" });
174
+ res.end('{"error":"Skills access is not permitted"}');
175
+ return true;
178
176
  }
179
177
 
180
178
  // Skills proxy: leaderboard list
package/lib/server.js CHANGED
@@ -61,9 +61,6 @@ var MIME_TYPES = {
61
61
  ".ico": "image/x-icon",
62
62
  };
63
63
 
64
- var generateAuthToken = serverAuth.generateAuthToken;
65
- var verifyPin = serverAuth.verifyPin;
66
-
67
64
  function serveStatic(urlPath, res) {
68
65
  if (urlPath === "/") urlPath = "/index.html";
69
66
 
@@ -140,7 +137,6 @@ function stripPrefix(urlPath, slug) {
140
137
  function createServer(opts) {
141
138
  var tlsOptions = opts.tlsOptions || null;
142
139
  var caPath = opts.caPath || null;
143
- var pinHash = opts.pinHash || null;
144
140
  var portNum = opts.port || 2633;
145
141
  var debug = opts.debug || false;
146
142
  var dangerouslySkipPermissions = opts.dangerouslySkipPermissions || false;
@@ -186,7 +182,6 @@ function createServer(opts) {
186
182
  var onShutdown = opts.onShutdown || null;
187
183
  var onRestart = opts.onRestart || null;
188
184
  var onSetUpdateChannel = opts.onSetUpdateChannel || null;
189
- var onUpgradePin = opts.onUpgradePin || null;
190
185
  var onSetProjectVisibility = opts.onSetProjectVisibility || null;
191
186
  var onSetProjectAllowedUsers = opts.onSetProjectAllowedUsers || null;
192
187
  var onGetProjectAccess = opts.onGetProjectAccess || null;
@@ -202,9 +197,7 @@ function createServer(opts) {
202
197
  pages: pages,
203
198
  tlsOptions: tlsOptions,
204
199
  osUsers: osUsers,
205
- pinHash: pinHash,
206
200
  provisionLinuxUser: provisionLinuxUser,
207
- onUpgradePin: onUpgradePin,
208
201
  onUserProvisioned: onUserProvisioned,
209
202
  });
210
203
  var getMultiUserFromReq = auth.getMultiUserFromReq;
@@ -273,7 +266,7 @@ function createServer(opts) {
273
266
  broadcastAll: function (msg) { broadcastAll(msg); },
274
267
  sendToUser: function (userId, msg) { sendToUser(userId, msg); },
275
268
  pushModule: pushModule,
276
- isMultiUser: function () { return users.isMultiUser(); },
269
+ isMultiUser: function () { return true; },
277
270
  });
278
271
 
279
272
  // --- External trigger watcher (global singleton) ---
@@ -438,6 +431,18 @@ function createServer(opts) {
438
431
  heapTotal: mem.heapTotal,
439
432
  };
440
433
  health.pid = process.pid;
434
+ // Cheap probe: if the process holds deleted inodes, its on-disk code was replaced
435
+ // by a newer npm install while this daemon was still running.
436
+ var staleInodes = false;
437
+ if (process.platform === 'linux') {
438
+ try {
439
+ var mapsContent = fs.readFileSync('/proc/self/maps', 'utf8');
440
+ staleInodes = mapsContent.split('\n').some(function(line) {
441
+ return line.includes(' (deleted)');
442
+ });
443
+ } catch (_) {}
444
+ }
445
+ health.stale = staleInodes;
441
446
  }
442
447
  res.writeHead(200, { "Content-Type": "application/json" });
443
448
  res.end(JSON.stringify(health));
@@ -487,12 +492,6 @@ function createServer(opts) {
487
492
 
488
493
  // Multi-user info endpoint (who am I?)
489
494
  if (req.method === "GET" && fullUrl === "/api/me") {
490
- if (!users.isMultiUser()) {
491
- res.writeHead(200, { "Content-Type": "application/json" });
492
- var singleUserData = { multiUser: false, singleUserMigrationAvailable: !!pinHash };
493
- res.end(JSON.stringify(singleUserData));
494
- return;
495
- }
496
495
  var mu = getMultiUserFromReq(req);
497
496
  if (!mu) {
498
497
  res.writeHead(401, { "Content-Type": "application/json" });
@@ -519,7 +518,7 @@ function createServer(opts) {
519
518
  }
520
519
  if (projects.size > 0) {
521
520
  var targetSlug = null;
522
- var reqUser = users.isMultiUser() ? getMultiUserFromReq(req) : null;
521
+ var reqUser = getMultiUserFromReq(req);
523
522
  // Check for last-visited project cookie
524
523
  var lastProject = parseCookies(req)["clagentic_last_project"] || parseCookies(req)["clay_last_project"];
525
524
  if (lastProject && projects.has(lastProject)) {
@@ -553,13 +552,8 @@ function createServer(opts) {
553
552
  }
554
553
  }
555
554
  // No accessible projects — show info page
556
- if (users.isMultiUser()) {
557
- res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
558
- res.end(pages.noProjectsPageHtml());
559
- return;
560
- }
561
- res.writeHead(200, { "Content-Type": "text/plain" });
562
- res.end("No projects registered.");
555
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
556
+ res.end(pages.noProjectsPageHtml());
563
557
  return;
564
558
  }
565
559
 
@@ -642,8 +636,8 @@ function createServer(opts) {
642
636
  // Set last-visited project cookie for root redirect
643
637
  res.setHeader("Set-Cookie", "clagentic_last_project=" + slug + "; Path=/; SameSite=Strict; Max-Age=31536000" + (tlsOptions ? "; Secure" : ""));
644
638
 
645
- // Multi-user: check project access for HTTP requests
646
- if (users.isMultiUser() && onGetProjectAccess) {
639
+ // Check project access for HTTP requests
640
+ if (onGetProjectAccess) {
647
641
  var httpUser = getMultiUserFromReq(req);
648
642
  if (httpUser) {
649
643
  var httpAccess = onGetProjectAccess(slug);
@@ -661,10 +655,8 @@ function createServer(opts) {
661
655
  var qsIdx = req.url.indexOf("?");
662
656
  var projectUrlWithQS = qsIdx >= 0 ? projectUrl + req.url.substring(qsIdx) : projectUrl;
663
657
 
664
- // Attach user info for project HTTP handler (OS-level isolation)
665
- if (users.isMultiUser()) {
666
- req._clayUser = getMultiUserFromReq(req);
667
- }
658
+ // Attach user info for project HTTP handler
659
+ req._clayUser = getMultiUserFromReq(req);
668
660
 
669
661
  // Try project HTTP handler first (APIs)
670
662
  var origUrl = req.url;
@@ -793,23 +785,20 @@ function createServer(opts) {
793
785
  return;
794
786
  }
795
787
 
796
- // Attach user info to the WS connection for multi-user filtering
797
- var wsUser = null;
798
- if (users.isMultiUser()) {
799
- wsUser = getMultiUserFromReq(req);
800
- // Check project access for multi-user mode
801
- if (wsUser && onGetProjectAccess) {
802
- // For worktree projects, inherit access from parent
803
- var accessSlug = (wsSlug.indexOf("--") !== -1) ? wsSlug.split("--")[0] : wsSlug;
804
- var projectAccess = onGetProjectAccess(accessSlug);
805
- if (debug) console.log("[server] WS access check:", wsSlug, "user:", wsUser.id, "role:", wsUser.role, "visibility:", projectAccess && projectAccess.visibility, "ownerId:", projectAccess && projectAccess.ownerId, "allowed:", projectAccess && projectAccess.allowedUsers);
806
- if (projectAccess && !projectAccess.error) {
807
- if (!users.canAccessProject(wsUser.id, projectAccess)) {
808
- if (debug) console.log("[server] WS rejected: access denied for", wsUser.id, "on", wsSlug);
809
- socket.write("HTTP/1.1 403 Forbidden\r\n\r\n");
810
- socket.destroy();
811
- return;
812
- }
788
+ // Attach user info to the WS connection
789
+ var wsUser = getMultiUserFromReq(req);
790
+ // Check project access
791
+ if (wsUser && onGetProjectAccess) {
792
+ // For worktree projects, inherit access from parent
793
+ var accessSlug = (wsSlug.indexOf("--") !== -1) ? wsSlug.split("--")[0] : wsSlug;
794
+ var projectAccess = onGetProjectAccess(accessSlug);
795
+ if (debug) console.log("[server] WS access check:", wsSlug, "user:", wsUser.id, "role:", wsUser.role, "visibility:", projectAccess && projectAccess.visibility, "ownerId:", projectAccess && projectAccess.ownerId, "allowed:", projectAccess && projectAccess.allowedUsers);
796
+ if (projectAccess && !projectAccess.error) {
797
+ if (!users.canAccessProject(wsUser.id, projectAccess)) {
798
+ if (debug) console.log("[server] WS rejected: access denied for", wsUser.id, "on", wsSlug);
799
+ socket.write("HTTP/1.1 403 Forbidden\r\n\r\n");
800
+ socket.destroy();
801
+ return;
813
802
  }
814
803
  }
815
804
  }
@@ -884,7 +873,7 @@ function createServer(opts) {
884
873
  projects.forEach(function (ctx, projSlug) {
885
874
  ctx.forEachClient(function (ws) {
886
875
  var filtered = allProjectsList;
887
- if (users.isMultiUser() && onGetProjectAccess) {
876
+ if (onGetProjectAccess) {
888
877
  var wsUser = ws._clayUser;
889
878
  if (wsUser) {
890
879
  filtered = allProjectsList.filter(function (p) {
@@ -943,13 +932,12 @@ function createServer(opts) {
943
932
  lanHost: lanHost,
944
933
  port: portNum,
945
934
  tls: !!tlsOptions,
946
- authToken: pinHash || null,
947
935
  getProjectCount: function () { return projects.size; },
948
936
  getProjectList: function (userId) {
949
937
  var list = [];
950
938
  projects.forEach(function (ctx, s) {
951
939
  var status = ctx.getStatus();
952
- if (userId && users.isMultiUser() && onGetProjectAccess) {
940
+ if (userId && onGetProjectAccess) {
953
941
  var access = onGetProjectAccess(s);
954
942
  if (access && !access.error && !users.canAccessProject(userId, access)) return;
955
943
  }
@@ -1231,16 +1219,6 @@ function createServer(opts) {
1231
1219
  if (presenceTimer) clearTimeout(presenceTimer);
1232
1220
  presenceTimer = setTimeout(function () {
1233
1221
  presenceTimer = null;
1234
- if (!users.isMultiUser()) {
1235
- broadcastAll({
1236
- type: "projects_updated",
1237
- projects: getProjects(),
1238
- projectCount: projects.size,
1239
- removedProjects: getRemovedProjects(),
1240
- folderMeta: getFolderMeta(),
1241
- });
1242
- return;
1243
- }
1244
1222
  var serverUsers = getServerUsers();
1245
1223
  var allUsers = users.getAllUsers().map(function (u) {
1246
1224
  var p = u.profile || {};
@@ -1426,7 +1404,6 @@ function createServer(opts) {
1426
1404
  setProjectFolder: setProjectFolder,
1427
1405
  setProjectFolderName: setProjectFolderName,
1428
1406
  setProjectPreferredAgent: setProjectPreferredAgent,
1429
- setAuthToken: auth.setAuthToken,
1430
1407
  setRecovery: auth.setRecovery,
1431
1408
  clearRecovery: auth.clearRecovery,
1432
1409
  broadcastAll: broadcastAll,
@@ -1436,4 +1413,4 @@ function createServer(opts) {
1436
1413
  };
1437
1414
  }
1438
1415
 
1439
- module.exports = { createServer: createServer, generateAuthToken: generateAuthToken, verifyPin: verifyPin };
1416
+ module.exports = { createServer: createServer };