@clagentic/console 1.5.0-beta.3 → 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.
- package/README.md +18 -14
- package/lib/cli-sessions.js +71 -18
- package/lib/daemon.js +72 -24
- package/lib/pages.js +1 -42
- package/lib/project-connection.js +4 -8
- package/lib/project-loop.js +1 -1
- package/lib/project-notifications.js +3 -18
- package/lib/project-sessions.js +19 -26
- package/lib/project-user-message.js +5 -10
- package/lib/project.js +39 -52
- package/lib/public/app.js +5 -15
- package/lib/public/modules/admin.js +1 -52
- package/lib/public/modules/agent-picker.js +11 -3
- package/lib/public/modules/app-cursors.js +43 -47
- package/lib/public/modules/app-messages.js +5 -12
- package/lib/public/modules/app-rendering.js +1 -2
- package/lib/public/modules/sidebar-projects.js +1 -1
- package/lib/public/modules/sidebar-sessions.js +2 -2
- package/lib/public/modules/sidebar-users.js +2 -12
- package/lib/public/modules/user-settings.js +0 -3
- package/lib/sdk-bridge.js +47 -7
- package/lib/sdk-message-processor.js +3 -4
- package/lib/server-admin.js +1 -86
- package/lib/server-auth.js +13 -124
- package/lib/server-dm.js +2 -7
- package/lib/server-palette.js +9 -20
- package/lib/server-settings.js +41 -243
- package/lib/server-skills.js +11 -13
- package/lib/server.js +25 -60
- package/lib/sessions.js +16 -50
- package/lib/terminal-manager.js +13 -15
- package/lib/users-auth.js +0 -38
- package/lib/users.js +14 -11
- package/lib/yoke/adapters/claude.js +5 -0
- package/package.json +1 -1
package/lib/server-settings.js
CHANGED
|
@@ -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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
|
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 (!
|
|
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 (!
|
|
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
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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 (!
|
|
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
|
-
|
|
546
|
-
|
|
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
|
|
package/lib/server-skills.js
CHANGED
|
@@ -162,19 +162,17 @@ function attachSkills(ctx) {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
// Permission gate
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
|
269
|
+
isMultiUser: function () { return true; },
|
|
277
270
|
});
|
|
278
271
|
|
|
279
272
|
// --- External trigger watcher (global singleton) ---
|
|
@@ -499,12 +492,6 @@ function createServer(opts) {
|
|
|
499
492
|
|
|
500
493
|
// Multi-user info endpoint (who am I?)
|
|
501
494
|
if (req.method === "GET" && fullUrl === "/api/me") {
|
|
502
|
-
if (!users.isMultiUser()) {
|
|
503
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
504
|
-
var singleUserData = { multiUser: false, singleUserMigrationAvailable: !!pinHash };
|
|
505
|
-
res.end(JSON.stringify(singleUserData));
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
495
|
var mu = getMultiUserFromReq(req);
|
|
509
496
|
if (!mu) {
|
|
510
497
|
res.writeHead(401, { "Content-Type": "application/json" });
|
|
@@ -531,7 +518,7 @@ function createServer(opts) {
|
|
|
531
518
|
}
|
|
532
519
|
if (projects.size > 0) {
|
|
533
520
|
var targetSlug = null;
|
|
534
|
-
var reqUser =
|
|
521
|
+
var reqUser = getMultiUserFromReq(req);
|
|
535
522
|
// Check for last-visited project cookie
|
|
536
523
|
var lastProject = parseCookies(req)["clagentic_last_project"] || parseCookies(req)["clay_last_project"];
|
|
537
524
|
if (lastProject && projects.has(lastProject)) {
|
|
@@ -565,13 +552,8 @@ function createServer(opts) {
|
|
|
565
552
|
}
|
|
566
553
|
}
|
|
567
554
|
// No accessible projects — show info page
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
res.end(pages.noProjectsPageHtml());
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
res.writeHead(200, { "Content-Type": "text/plain" });
|
|
574
|
-
res.end("No projects registered.");
|
|
555
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
556
|
+
res.end(pages.noProjectsPageHtml());
|
|
575
557
|
return;
|
|
576
558
|
}
|
|
577
559
|
|
|
@@ -654,8 +636,8 @@ function createServer(opts) {
|
|
|
654
636
|
// Set last-visited project cookie for root redirect
|
|
655
637
|
res.setHeader("Set-Cookie", "clagentic_last_project=" + slug + "; Path=/; SameSite=Strict; Max-Age=31536000" + (tlsOptions ? "; Secure" : ""));
|
|
656
638
|
|
|
657
|
-
//
|
|
658
|
-
if (
|
|
639
|
+
// Check project access for HTTP requests
|
|
640
|
+
if (onGetProjectAccess) {
|
|
659
641
|
var httpUser = getMultiUserFromReq(req);
|
|
660
642
|
if (httpUser) {
|
|
661
643
|
var httpAccess = onGetProjectAccess(slug);
|
|
@@ -673,10 +655,8 @@ function createServer(opts) {
|
|
|
673
655
|
var qsIdx = req.url.indexOf("?");
|
|
674
656
|
var projectUrlWithQS = qsIdx >= 0 ? projectUrl + req.url.substring(qsIdx) : projectUrl;
|
|
675
657
|
|
|
676
|
-
// Attach user info for project HTTP handler
|
|
677
|
-
|
|
678
|
-
req._clayUser = getMultiUserFromReq(req);
|
|
679
|
-
}
|
|
658
|
+
// Attach user info for project HTTP handler
|
|
659
|
+
req._clayUser = getMultiUserFromReq(req);
|
|
680
660
|
|
|
681
661
|
// Try project HTTP handler first (APIs)
|
|
682
662
|
var origUrl = req.url;
|
|
@@ -805,23 +785,20 @@ function createServer(opts) {
|
|
|
805
785
|
return;
|
|
806
786
|
}
|
|
807
787
|
|
|
808
|
-
// Attach user info to the WS connection
|
|
809
|
-
var wsUser =
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
//
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
if (
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
socket.destroy();
|
|
823
|
-
return;
|
|
824
|
-
}
|
|
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;
|
|
825
802
|
}
|
|
826
803
|
}
|
|
827
804
|
}
|
|
@@ -896,7 +873,7 @@ function createServer(opts) {
|
|
|
896
873
|
projects.forEach(function (ctx, projSlug) {
|
|
897
874
|
ctx.forEachClient(function (ws) {
|
|
898
875
|
var filtered = allProjectsList;
|
|
899
|
-
if (
|
|
876
|
+
if (onGetProjectAccess) {
|
|
900
877
|
var wsUser = ws._clayUser;
|
|
901
878
|
if (wsUser) {
|
|
902
879
|
filtered = allProjectsList.filter(function (p) {
|
|
@@ -955,13 +932,12 @@ function createServer(opts) {
|
|
|
955
932
|
lanHost: lanHost,
|
|
956
933
|
port: portNum,
|
|
957
934
|
tls: !!tlsOptions,
|
|
958
|
-
authToken: pinHash || null,
|
|
959
935
|
getProjectCount: function () { return projects.size; },
|
|
960
936
|
getProjectList: function (userId) {
|
|
961
937
|
var list = [];
|
|
962
938
|
projects.forEach(function (ctx, s) {
|
|
963
939
|
var status = ctx.getStatus();
|
|
964
|
-
if (userId &&
|
|
940
|
+
if (userId && onGetProjectAccess) {
|
|
965
941
|
var access = onGetProjectAccess(s);
|
|
966
942
|
if (access && !access.error && !users.canAccessProject(userId, access)) return;
|
|
967
943
|
}
|
|
@@ -1243,16 +1219,6 @@ function createServer(opts) {
|
|
|
1243
1219
|
if (presenceTimer) clearTimeout(presenceTimer);
|
|
1244
1220
|
presenceTimer = setTimeout(function () {
|
|
1245
1221
|
presenceTimer = null;
|
|
1246
|
-
if (!users.isMultiUser()) {
|
|
1247
|
-
broadcastAll({
|
|
1248
|
-
type: "projects_updated",
|
|
1249
|
-
projects: getProjects(),
|
|
1250
|
-
projectCount: projects.size,
|
|
1251
|
-
removedProjects: getRemovedProjects(),
|
|
1252
|
-
folderMeta: getFolderMeta(),
|
|
1253
|
-
});
|
|
1254
|
-
return;
|
|
1255
|
-
}
|
|
1256
1222
|
var serverUsers = getServerUsers();
|
|
1257
1223
|
var allUsers = users.getAllUsers().map(function (u) {
|
|
1258
1224
|
var p = u.profile || {};
|
|
@@ -1438,7 +1404,6 @@ function createServer(opts) {
|
|
|
1438
1404
|
setProjectFolder: setProjectFolder,
|
|
1439
1405
|
setProjectFolderName: setProjectFolderName,
|
|
1440
1406
|
setProjectPreferredAgent: setProjectPreferredAgent,
|
|
1441
|
-
setAuthToken: auth.setAuthToken,
|
|
1442
1407
|
setRecovery: auth.setRecovery,
|
|
1443
1408
|
clearRecovery: auth.clearRecovery,
|
|
1444
1409
|
broadcastAll: broadcastAll,
|
|
@@ -1448,4 +1413,4 @@ function createServer(opts) {
|
|
|
1448
1413
|
};
|
|
1449
1414
|
}
|
|
1450
1415
|
|
|
1451
|
-
module.exports = { createServer: createServer
|
|
1416
|
+
module.exports = { createServer: createServer };
|