@clagentic/console 1.6.0-beta.1 → 1.6.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +18 -0
  2. package/lib/daemon.js +94 -0
  3. package/lib/project-sessions.js +26 -0
  4. package/lib/public/css/base.css +18 -0
  5. package/lib/public/css/diagnostics.css +8 -0
  6. package/lib/public/css/icon-strip.css +201 -0
  7. package/lib/public/css/menus.css +2 -2
  8. package/lib/public/css/mobile-nav.css +24 -0
  9. package/lib/public/css/server-settings.css +100 -0
  10. package/lib/public/index.html +13 -0
  11. package/lib/public/modules/app-header.js +4 -7
  12. package/lib/public/modules/app-home-hub.js +31 -7
  13. package/lib/public/modules/app-messages.js +5 -0
  14. package/lib/public/modules/app-notifications.js +5 -1
  15. package/lib/public/modules/app-projects.js +10 -5
  16. package/lib/public/modules/command-palette.js +16 -5
  17. package/lib/public/modules/custom-icons-settings.js +399 -0
  18. package/lib/public/modules/custom-icons.js +114 -0
  19. package/lib/public/modules/diagnostics.js +10 -0
  20. package/lib/public/modules/emoji-picker.js +253 -6
  21. package/lib/public/modules/popover-position.js +192 -0
  22. package/lib/public/modules/project-icon.js +113 -0
  23. package/lib/public/modules/project-settings.js +2 -2
  24. package/lib/public/modules/project-switcher.js +2 -1
  25. package/lib/public/modules/scheduler-config.js +5 -8
  26. package/lib/public/modules/scheduler.js +5 -6
  27. package/lib/public/modules/server-settings.js +6 -0
  28. package/lib/public/modules/sidebar-mobile.js +4 -6
  29. package/lib/public/modules/sidebar-projects.js +35 -90
  30. package/lib/public/modules/sidebar-sessions.js +6 -20
  31. package/lib/public/modules/sticky-notes.js +4 -4
  32. package/lib/public/modules/terminal.js +5 -12
  33. package/lib/server-settings.js +221 -1
  34. package/lib/server.js +2 -0
  35. package/lib/sessions.js +16 -9
  36. package/lib/ws-schema.js +2 -0
  37. package/package.json +2 -1
@@ -1,6 +1,27 @@
1
1
  var fs = require("fs");
2
2
  var path = require("path");
3
3
  var audit = require("./audit");
4
+ var projectModule = require("./project");
5
+
6
+ // Validate a custom-emoji slug: lowercase alphanumeric, hyphen, underscore, 1-64 chars.
7
+ // Must pass BEFORE any filesystem operation (structurally excludes . and /).
8
+ var SLUG_RE = /^[a-z0-9_-]{1,64}$/;
9
+
10
+ // Content-type → file extension map for custom emoji uploads.
11
+ var CUSTOM_EMOJI_EXT = {
12
+ "image/jpeg": "jpg",
13
+ "image/png": "png",
14
+ "image/gif": "gif",
15
+ "image/webp": "webp",
16
+ };
17
+
18
+ // Extension → Content-Type for serving.
19
+ var CUSTOM_EMOJI_CT = {
20
+ jpg: "image/jpeg",
21
+ png: "image/png",
22
+ gif: "image/gif",
23
+ webp: "image/webp",
24
+ };
4
25
 
5
26
  function attachSettings(ctx) {
6
27
  var users = ctx.users;
@@ -150,6 +171,7 @@ function attachSettings(ctx) {
150
171
  res.writeHead(200, {
151
172
  "Content-Type": ctMap[ext] || "application/octet-stream",
152
173
  "Cache-Control": "public, max-age=31536000, immutable",
174
+ "X-Content-Type-Options": "nosniff",
153
175
  });
154
176
  res.end(fs.readFileSync(path.join(avatarDir, match)));
155
177
  return true;
@@ -389,11 +411,209 @@ function attachSettings(ctx) {
389
411
  return true;
390
412
  }
391
413
 
414
+ // -----------------------------------------------------------------------
415
+ // Custom emoji routes — /api/custom-emoji[/:slug]
416
+ // Storage: CONFIG_DIR/custom-emoji/{slug}.{ext}
417
+ // Global shared namespace (not per-user).
418
+ // -----------------------------------------------------------------------
419
+
420
+ var customEmojiDir = path.join(CONFIG_DIR, "custom-emoji");
421
+
422
+ // GET /api/custom-emoji — list all uploads [{slug, url, size, ext, contentType}]
423
+ // size/ext/contentType are additive (lr-d1d9) — existing consumers that only
424
+ // read {slug, url} are unaffected.
425
+ if (req.method === "GET" && fullUrl === "/api/custom-emoji") {
426
+ var list = [];
427
+ try {
428
+ var emojiFiles = fs.readdirSync(customEmojiDir);
429
+ for (var lfi = 0; lfi < emojiFiles.length; lfi++) {
430
+ var lf = emojiFiles[lfi];
431
+ var lfExt = path.extname(lf).slice(1);
432
+ if (!CUSTOM_EMOJI_CT[lfExt]) continue;
433
+ var lfSlug = path.basename(lf, "." + lfExt);
434
+ if (!SLUG_RE.test(lfSlug)) continue;
435
+ var lfEntry = { slug: lfSlug, url: "/api/custom-emoji/" + lfSlug, ext: lfExt, contentType: CUSTOM_EMOJI_CT[lfExt] };
436
+ try { lfEntry.size = fs.statSync(path.join(customEmojiDir, lf)).size; } catch (e) { /* stat failed — omit size */ }
437
+ list.push(lfEntry);
438
+ }
439
+ } catch (e) { /* dir absent → empty list */ }
440
+ res.writeHead(200, { "Content-Type": "application/json" });
441
+ res.end(JSON.stringify(list));
442
+ return true;
443
+ }
444
+
445
+ // POST /api/custom-emoji/:slug — upload a new custom emoji image
446
+ if (req.method === "POST" && fullUrl.startsWith("/api/custom-emoji/")) {
447
+ var postSlug = fullUrl.slice("/api/custom-emoji/".length).split("?")[0];
448
+
449
+ // Auth gate
450
+ var muPost = getMultiUserFromReq(req);
451
+ if (!muPost) {
452
+ res.writeHead(401, { "Content-Type": "application/json" });
453
+ res.end('{"error":"unauthorized"}');
454
+ return true;
455
+ }
456
+
457
+ // Validate slug before any filesystem use
458
+ if (!SLUG_RE.test(postSlug)) {
459
+ res.writeHead(400, { "Content-Type": "application/json" });
460
+ res.end('{"error":"Invalid slug"}');
461
+ return true;
462
+ }
463
+
464
+ var postChunks = [];
465
+ var postSize = 0;
466
+ var postMaxSize = 512 * 1024; // 512 KB
467
+ req.on("data", function (chunk) {
468
+ postSize += chunk.length;
469
+ if (postSize <= postMaxSize) postChunks.push(chunk);
470
+ });
471
+ req.on("end", function () {
472
+ if (postSize > postMaxSize) {
473
+ res.writeHead(413, { "Content-Type": "application/json" });
474
+ res.end('{"error":"File too large (max 512 KB)"}');
475
+ return;
476
+ }
477
+ var raw = Buffer.concat(postChunks);
478
+
479
+ // Magic-byte type detection — reuse same pattern as avatar handler
480
+ var ct = null;
481
+ if (raw[0] === 0xFF && raw[1] === 0xD8) ct = "image/jpeg";
482
+ else if (raw[0] === 0x89 && raw[1] === 0x50) ct = "image/png";
483
+ else if (raw[0] === 0x47 && raw[1] === 0x49) ct = "image/gif";
484
+ else if (raw[0] === 0x52 && raw[1] === 0x49) ct = "image/webp";
485
+
486
+ if (!ct) {
487
+ res.writeHead(400, { "Content-Type": "application/json" });
488
+ res.end('{"error":"Unsupported image format"}');
489
+ return;
490
+ }
491
+
492
+ var ext = CUSTOM_EMOJI_EXT[ct];
493
+ try { fs.mkdirSync(customEmojiDir, { recursive: true }); } catch (e) {}
494
+
495
+ // Build + validate the target path (defense-in-depth — slug already
496
+ // validated by SLUG_RE but guard against path.resolve surprises).
497
+ // safePath requires the file to exist, so we use a pre-write resolve check.
498
+ var candidatePath = path.join(customEmojiDir, postSlug + "." + ext);
499
+ var resolvedCandidate = path.resolve(customEmojiDir, postSlug + "." + ext);
500
+ if (!resolvedCandidate.startsWith(customEmojiDir + path.sep)) {
501
+ res.writeHead(400, { "Content-Type": "application/json" });
502
+ res.end('{"error":"Invalid path"}');
503
+ return;
504
+ }
505
+
506
+ // Remove any existing file for this slug (different ext)
507
+ try {
508
+ var existingAll = fs.readdirSync(customEmojiDir);
509
+ for (var ri = 0; ri < existingAll.length; ri++) {
510
+ var rf = existingAll[ri];
511
+ var rfExt = path.extname(rf).slice(1);
512
+ if (!CUSTOM_EMOJI_CT[rfExt]) continue;
513
+ if (path.basename(rf, "." + rfExt) === postSlug) {
514
+ fs.unlinkSync(path.join(customEmojiDir, rf));
515
+ }
516
+ }
517
+ } catch (e) {}
518
+
519
+ fs.writeFileSync(candidatePath, raw);
520
+ try { fs.chmodSync(candidatePath, 0o644); } catch (e) {}
521
+
522
+ res.writeHead(200, { "Content-Type": "application/json" });
523
+ res.end(JSON.stringify({ ok: true, slug: postSlug, url: "/api/custom-emoji/" + postSlug }));
524
+ });
525
+ return true;
526
+ }
527
+
528
+ // GET /api/custom-emoji/:slug — serve the image for a slug
529
+ if (req.method === "GET" && fullUrl.startsWith("/api/custom-emoji/")) {
530
+ var getSlug = fullUrl.slice("/api/custom-emoji/".length).split("?")[0];
531
+
532
+ if (!SLUG_RE.test(getSlug)) {
533
+ res.writeHead(404, { "Content-Type": "application/json" });
534
+ res.end('{"error":"not found"}');
535
+ return true;
536
+ }
537
+
538
+ try {
539
+ var getFiles = fs.readdirSync(customEmojiDir);
540
+ var getMatch = null;
541
+ for (var gfi = 0; gfi < getFiles.length; gfi++) {
542
+ var gf = getFiles[gfi];
543
+ var gfExt = path.extname(gf).slice(1);
544
+ if (!CUSTOM_EMOJI_CT[gfExt]) continue;
545
+ // Exact-basename match (NOT startsWith — prevents prefix collisions)
546
+ if (path.basename(gf, "." + gfExt) === getSlug) {
547
+ getMatch = gf;
548
+ break;
549
+ }
550
+ }
551
+ if (getMatch) {
552
+ var matchExt = path.extname(getMatch).slice(1);
553
+ var matchPath = path.join(customEmojiDir, getMatch);
554
+ // Defense-in-depth: verify resolved path stays within customEmojiDir
555
+ var safeMatchPath = projectModule.safePath(customEmojiDir, getMatch);
556
+ if (!safeMatchPath) {
557
+ res.writeHead(404, { "Content-Type": "application/json" });
558
+ res.end('{"error":"not found"}');
559
+ return true;
560
+ }
561
+ res.writeHead(200, {
562
+ "Content-Type": CUSTOM_EMOJI_CT[matchExt] || "application/octet-stream",
563
+ "Cache-Control": "public, max-age=31536000, immutable",
564
+ "X-Content-Type-Options": "nosniff",
565
+ });
566
+ res.end(fs.readFileSync(matchPath));
567
+ return true;
568
+ }
569
+ } catch (e) {}
570
+
571
+ res.writeHead(404, { "Content-Type": "application/json" });
572
+ res.end('{"error":"not found"}');
573
+ return true;
574
+ }
575
+
576
+ // DELETE /api/custom-emoji/:slug — remove an uploaded emoji
577
+ if (req.method === "DELETE" && fullUrl.startsWith("/api/custom-emoji/")) {
578
+ var delSlug = fullUrl.slice("/api/custom-emoji/".length).split("?")[0];
579
+
580
+ // Auth gate
581
+ var muDel = getMultiUserFromReq(req);
582
+ if (!muDel) {
583
+ res.writeHead(401, { "Content-Type": "application/json" });
584
+ res.end('{"error":"unauthorized"}');
585
+ return true;
586
+ }
587
+
588
+ if (!SLUG_RE.test(delSlug)) {
589
+ res.writeHead(400, { "Content-Type": "application/json" });
590
+ res.end('{"error":"Invalid slug"}');
591
+ return true;
592
+ }
593
+
594
+ try {
595
+ var delFiles = fs.readdirSync(customEmojiDir);
596
+ for (var dfi = 0; dfi < delFiles.length; dfi++) {
597
+ var df = delFiles[dfi];
598
+ var dfExt = path.extname(df).slice(1);
599
+ if (!CUSTOM_EMOJI_CT[dfExt]) continue;
600
+ if (path.basename(df, "." + dfExt) === delSlug) {
601
+ var safeDelPath = projectModule.safePath(customEmojiDir, df);
602
+ if (safeDelPath) fs.unlinkSync(safeDelPath);
603
+ }
604
+ }
605
+ } catch (e) {}
606
+
607
+ res.writeHead(200, { "Content-Type": "application/json" });
608
+ res.end('{"ok":true}');
609
+ return true;
610
+ }
611
+
392
612
  return false;
393
613
  }
394
614
 
395
615
  return { handleRequest: handleRequest };
396
616
  }
397
617
 
398
- module.exports = { attachSettings: attachSettings };
618
+ module.exports = { attachSettings: attachSettings, SLUG_RE: SLUG_RE, CUSTOM_EMOJI_CT: CUSTOM_EMOJI_CT };
399
619
 
package/lib/server.js CHANGED
@@ -153,6 +153,7 @@ function createServer(opts) {
153
153
  var onSetProjectFolder = opts.onSetProjectFolder || null;
154
154
  var onRenameProjectFolder = opts.onRenameProjectFolder || null;
155
155
  var onSetFolderIcon = opts.onSetFolderIcon || null;
156
+ var onRenameCustomIcon = opts.onRenameCustomIcon || null;
156
157
  var getFolderMeta = opts.getFolderMeta || function () { return {}; };
157
158
  var onProjectOwnerChanged = opts.onProjectOwnerChanged || null;
158
159
  var onGetServerDefaultEffort = opts.onGetServerDefaultEffort || null;
@@ -1076,6 +1077,7 @@ function createServer(opts) {
1076
1077
  onSetProjectFolder: onSetProjectFolder,
1077
1078
  onRenameProjectFolder: onRenameProjectFolder,
1078
1079
  onSetFolderIcon: onSetFolderIcon,
1080
+ onRenameCustomIcon: onRenameCustomIcon,
1079
1081
  onProjectOwnerChanged: onProjectOwnerChanged,
1080
1082
  onGetServerDefaultEffort: onGetServerDefaultEffort,
1081
1083
  onSetServerDefaultEffort: onSetServerDefaultEffort,
package/lib/sessions.js CHANGED
@@ -553,18 +553,25 @@ function createSessionManager(opts) {
553
553
  // (same rules as getVisibleSessions / server-palette). Internal callers
554
554
  // (targetWs=null) bypass this gate — they operate on already-validated session
555
555
  // references.
556
+ //
557
+ // No-auth / single-user connections have _clayUser === null (set by
558
+ // project-connection.js:92 as wsUser || null). In that deployment there is
559
+ // no user identity to check — the connection is the implicit owner. We skip
560
+ // the gate entirely for null users so that _clayActiveSession is still
561
+ // bound below, keeping the live-broadcast filter (doSendAndRecord /
562
+ // doSendToSession) in sync. Authenticated users who lack access are still
563
+ // rejected by canAccessSession. (regression introduced by dca60a7, lr-690b)
556
564
  if (targetWs) {
557
565
  var requestingUser = targetWs._clayUser || null;
558
- if (!requestingUser) {
559
- if (sendTo) sendTo(targetWs, { type: "error", error: "Access denied" });
560
- return;
561
- }
562
- // Use { visibility: "public" } so canAccessProject passes and the
563
- // session-level ownership/visibility rules do the real work.
564
- if (!users.canAccessSession(requestingUser.id, session, { visibility: "public" })) {
565
- if (sendTo) sendTo(targetWs, { type: "error", error: "Access denied" });
566
- return;
566
+ if (requestingUser) {
567
+ // Use { visibility: "public" } so canAccessProject passes and the
568
+ // session-level ownership/visibility rules do the real work.
569
+ if (!users.canAccessSession(requestingUser.id, session, { visibility: "public" })) {
570
+ if (sendTo) sendTo(targetWs, { type: "error", error: "Access denied" });
571
+ return;
572
+ }
567
573
  }
574
+ // null requestingUser = no-auth deployment; fall through to bind _clayActiveSession.
568
575
  }
569
576
 
570
577
  activeSessionId = localId;
package/lib/ws-schema.js CHANGED
@@ -270,6 +270,8 @@ var schema = {
270
270
  "rename_project_folder_result": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Rename folder result" },
271
271
  "set_folder_icon": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set or clear the emoji icon for a named folder" },
272
272
  "set_folder_icon_result": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Set folder icon result" },
273
+ "rename_custom_icon": { direction: "c2s", handler: "lib/project-sessions.js", description: "Rename a custom-icon upload (oldSlug -> newSlug), rewriting all project/folder references atomically" },
274
+ "rename_custom_icon_result": { direction: "s2c", handler: "lib/public/modules/custom-icons-settings.js", description: "Custom icon rename result" },
273
275
  "transfer_project_owner": { direction: "c2s", handler: "lib/project-sessions.js", description: "Transfer project ownership to another user" },
274
276
  "project_owner_changed": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Project ownership was transferred" },
275
277
  "projects_updated": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Broadcast: project list changed" },
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.6.0-beta.1",
6
+ "version": "1.6.0-beta.2",
7
7
  "description": "Self-hosted console for Claude Code and Codex. Multi-user, browser-based, persistent AI sessions.",
8
8
  "bin": {
9
9
  "clagentic-console": "./bin/cli.js"
@@ -12,6 +12,7 @@
12
12
  "dev": "node bin/cli.js --dev",
13
13
  "postinstall": "node scripts/postinstall.js",
14
14
  "test": "node --test --test-force-exit test/*.test.js",
15
+ "install:local-test": "sh -c 'f=$(npm pack) && npm install -g \"$f\" && rm -f \"$f\"'",
15
16
  "semantic-release": "semantic-release"
16
17
  },
17
18
  "files": [