@clagentic/console 1.4.1 → 1.5.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 (54) hide show
  1. package/README.md +90 -21
  2. package/bin/cli.js +170 -60
  3. package/deploy/clagentic-console.service +2 -0
  4. package/lib/agents-favorites.js +3 -1
  5. package/lib/agents.js +75 -5
  6. package/lib/audit.js +23 -2
  7. package/lib/browser-mcp-server.js +5 -5
  8. package/lib/clone-validate.js +44 -0
  9. package/lib/config.js +175 -2
  10. package/lib/daemon.js +115 -9
  11. package/lib/dm.js +12 -1
  12. package/lib/ipc.js +12 -0
  13. package/lib/lite-detect.js +92 -0
  14. package/lib/os-users.js +8 -8
  15. package/lib/project-connection.js +7 -1
  16. package/lib/project-external-trigger.js +65 -6
  17. package/lib/project-loop.js +44 -3
  18. package/lib/project-sessions.js +95 -37
  19. package/lib/project.js +6 -1
  20. package/lib/public/app.js +6 -3
  21. package/lib/public/css/at-agents.css +68 -0
  22. package/lib/public/index.html +60 -0
  23. package/lib/public/modules/app-messages.js +38 -4
  24. package/lib/public/modules/at-agents.js +248 -0
  25. package/lib/public/modules/escape-html.js +19 -0
  26. package/lib/public/modules/filebrowser.js +12 -9
  27. package/lib/public/modules/input.js +26 -4
  28. package/lib/public/modules/pending-navigate.js +28 -0
  29. package/lib/public/modules/playbook.js +1 -1
  30. package/lib/public/modules/project-settings.js +75 -0
  31. package/lib/public/modules/project-switcher.js +1 -1
  32. package/lib/public/modules/server-settings.js +33 -0
  33. package/lib/public/modules/sticky-notes-fmt.js +52 -0
  34. package/lib/public/modules/sticky-notes.js +23 -5
  35. package/lib/public/modules/theme.js +1 -1
  36. package/lib/public/modules/tool-palette.js +1 -1
  37. package/lib/public/modules/utils.js +1 -3
  38. package/lib/public/style.css +1 -0
  39. package/lib/push.js +13 -2
  40. package/lib/scheduler.js +26 -2
  41. package/lib/sdk-bridge.js +7 -4
  42. package/lib/server-admin.js +1 -1
  43. package/lib/server-dm.js +16 -0
  44. package/lib/server-settings.js +42 -0
  45. package/lib/server-skills.js +10 -7
  46. package/lib/server.js +14 -3
  47. package/lib/sessions.js +4 -0
  48. package/lib/ws-schema.js +11 -1
  49. package/lib/yoke/adapters/claude-worker.js +2 -2
  50. package/lib/yoke/adapters/claude.js +47 -10
  51. package/lib/yoke/adapters/codex.js +14 -3
  52. package/lib/yoke/mcp-bridge-server.js +7 -7
  53. package/package.json +3 -2
  54. package/lib/relay-agent-claims.js +0 -480
package/bin/cli.js CHANGED
@@ -4,8 +4,8 @@
4
4
  var _nodeMajor = parseInt(process.versions.node.split(".")[0], 10);
5
5
  if (_nodeMajor < 20) {
6
6
  console.error("");
7
- console.error("\x1b[31m[clay] Node.js 20+ is required (current: " + process.version + ")\x1b[0m");
8
- console.error("[clay] The Claude Agent SDK 0.2.40+ requires Node 20 for Symbol.dispose support.");
7
+ console.error("\x1b[31m[clagentic-console] Node.js 20+ is required (current: " + process.version + ")\x1b[0m");
8
+ console.error("[clagentic-console] The Claude Agent SDK 0.2.40+ requires Node 20 for Symbol.dispose support.");
9
9
  console.error("");
10
10
  console.error(" Upgrade Node: nvm install 22 && nvm use 22");
11
11
  console.error("");
@@ -20,7 +20,7 @@ var qrcode = require("qrcode-terminal");
20
20
  var net = require("net");
21
21
 
22
22
  // Detect dev mode — dev and prod use separate daemon files so they can run simultaneously
23
- var _isDev = (process.argv[1] && (path.basename(process.argv[1]) === "clay-dev" || path.basename(process.argv[1]) === "clagentic-dev")) || process.argv.includes("--dev");
23
+ var _isDev = (process.argv[1] && path.basename(process.argv[1]) === "clagentic-dev") || process.argv.includes("--dev");
24
24
  if (_isDev) {
25
25
  process.env.CLAGENTIC_DEV = "1";
26
26
  }
@@ -31,7 +31,7 @@ if (_isDev || process.argv.includes("--debug")) {
31
31
  }
32
32
 
33
33
  var crypto = require("crypto");
34
- var { loadConfig, saveConfig, configPath, socketPath, logPath, ensureConfigDir, isDaemonAlive, isDaemonAliveAsync, generateSlug, clearStaleConfig, loadClayrc, saveClayrc, readCrashInfo, REAL_HOME } = require("../lib/config");
34
+ var { loadConfig, saveConfig, configPath, socketPath, oldSocketPath, logPath, ensureConfigDir, isDaemonAlive, isDaemonAliveAsync, checkOldDaemon, generateSlug, clearStaleConfig, loadClayrc, saveClayrc, readCrashInfo, REAL_HOME, CONFIG_DIR, CLAGENTIC_HOME } = require("../lib/config");
35
35
  var { sendIPCCommand } = require("../lib/ipc");
36
36
  var { generateAuthToken } = require("../lib/server");
37
37
  var { enableMultiUser, disableMultiUser, hasAdmin, isMultiUser, getSetupCode } = require("../lib/users");
@@ -58,6 +58,7 @@ var autoYes = false;
58
58
  var cliPin = null;
59
59
  var shutdownMode = false;
60
60
  var restartMode = false;
61
+ var noRestart = false;
61
62
  var addPath = null;
62
63
  var removePath = null;
63
64
  var listMode = false;
@@ -102,6 +103,8 @@ for (var i = 0; i < args.length; i++) {
102
103
  shutdownMode = true;
103
104
  } else if (args[i] === "--restart") {
104
105
  restartMode = true;
106
+ } else if (args[i] === "--no-restart") {
107
+ noRestart = true;
105
108
  } else if (args[i] === "--add") {
106
109
  addPath = args[i + 1] || ".";
107
110
  i++;
@@ -120,10 +123,10 @@ for (var i = 0; i < args.length; i++) {
120
123
  } else if (args[i] === "--os-users") {
121
124
  osUsersMode = true;
122
125
  } else if (args[i] === "-h" || args[i] === "--help") {
123
- console.log("Usage: clagentic [-p|--port <port>] [--host <address>] [--no-https] [--no-update] [--debug] [-y|--yes] [--pin <pin>] [--shutdown] [--restart]");
124
- console.log(" clagentic --add <path> Add a project to the running daemon");
125
- console.log(" clagentic --remove <path> Remove a project from the running daemon");
126
- console.log(" clagentic --list List registered projects");
126
+ console.log("Usage: clagentic-console [-p|--port <port>] [--host <address>] [--no-https] [--no-update] [--debug] [-y|--yes] [--pin <pin>] [--shutdown] [--restart] [--no-restart]");
127
+ console.log(" clagentic-console --add <path> Add a project to the running daemon");
128
+ console.log(" clagentic-console --remove <path> Remove a project from the running daemon");
129
+ console.log(" clagentic-console --list List registered projects");
127
130
  console.log("");
128
131
  console.log("Options:");
129
132
  console.log(" -p, --port <port> Port to listen on (default: 2633)");
@@ -137,6 +140,7 @@ for (var i = 0; i < args.length; i++) {
137
140
  console.log(" --pin <pin> Set 6-digit PIN (use with --yes)");
138
141
  console.log(" --shutdown Shut down the running relay daemon");
139
142
  console.log(" --restart Restart the running relay daemon");
143
+ console.log(" --no-restart Do not auto-restart on crash (useful for debugging crash state)");
140
144
  console.log(" --add <path> Add a project directory (use '.' for current)");
141
145
  console.log(" --remove <path> Remove a project directory");
142
146
  console.log(" --list List all registered projects");
@@ -159,16 +163,39 @@ if (_isDev) {
159
163
  if (shutdownMode) {
160
164
  var shutdownConfig = loadConfig();
161
165
  isDaemonAliveAsync(shutdownConfig).then(function (alive) {
162
- if (!alive) {
163
- console.error("No running daemon found.");
164
- process.exit(1);
166
+ if (alive) {
167
+ return sendIPCCommand(socketPath(), { cmd: "shutdown" }).then(function (resp) {
168
+ if (resp && resp.ok) {
169
+ console.log("Server stopped.");
170
+ clearStaleConfig();
171
+ process.exit(0);
172
+ } else {
173
+ var pid = shutdownConfig && shutdownConfig.pid;
174
+ console.error("Shutdown failed: daemon did not acknowledge the command.");
175
+ if (pid) console.error(" Daemon PID: " + pid + " (try: kill " + pid + ")");
176
+ console.error(" Or: systemctl restart clagentic-console");
177
+ process.exit(1);
178
+ }
179
+ });
165
180
  }
166
- sendIPCCommand(socketPath(), { cmd: "shutdown" }).then(function () {
167
- console.log("Server stopped.");
168
- clearStaleConfig();
169
- process.exit(0);
170
- }).catch(function (err) {
171
- console.error("Shutdown failed:", err.message);
181
+ // New socket not alive — check whether a pre-1.5 daemon is on the old path
182
+ return checkOldDaemon().then(function (old) {
183
+ if (old && old.alive) {
184
+ console.log("[migration] Sending shutdown to pre-1.5 daemon at " + old.sockPath);
185
+ return sendIPCCommand(old.sockPath, { cmd: "shutdown" }).then(function (resp) {
186
+ if (resp && resp.ok) {
187
+ console.log("Server stopped.");
188
+ process.exit(0);
189
+ } else {
190
+ var oldPid = shutdownConfig && shutdownConfig.pid;
191
+ console.error("Shutdown of pre-1.5 daemon failed: no acknowledgement from " + old.sockPath);
192
+ if (oldPid) console.error(" Daemon PID: " + oldPid + " (try: kill " + oldPid + ")");
193
+ console.error(" Or: systemctl restart clagentic-console");
194
+ process.exit(1);
195
+ }
196
+ });
197
+ }
198
+ console.error("No running daemon found.");
172
199
  process.exit(1);
173
200
  });
174
201
  });
@@ -179,15 +206,41 @@ if (shutdownMode) {
179
206
  if (restartMode) {
180
207
  var restartConfig = loadConfig();
181
208
  isDaemonAliveAsync(restartConfig).then(function (alive) {
182
- if (!alive) {
183
- console.error("No running daemon found.");
184
- process.exit(1);
209
+ if (alive) {
210
+ return sendIPCCommand(socketPath(), { cmd: "restart" }).then(function (resp) {
211
+ if (resp && resp.ok) {
212
+ console.log("Server restarted.");
213
+ process.exit(0);
214
+ } else {
215
+ var pid = restartConfig && restartConfig.pid;
216
+ console.error("Restart failed: daemon did not acknowledge the command.");
217
+ if (pid) console.error(" Daemon PID: " + pid + " (try: kill " + pid + " && clagentic-console)");
218
+ console.error(" Or: systemctl restart clagentic-console");
219
+ process.exit(1);
220
+ }
221
+ });
185
222
  }
186
- sendIPCCommand(socketPath(), { cmd: "restart" }).then(function () {
187
- console.log("Server restarted.");
188
- process.exit(0);
189
- }).catch(function (err) {
190
- console.error("Restart failed:", err.message);
223
+ // New socket not alive — check whether a pre-1.5 daemon is on the old path
224
+ return checkOldDaemon().then(function (old) {
225
+ if (old && old.alive) {
226
+ // Pre-1.5 daemon does not understand {cmd:"restart"} for the CLI restart
227
+ // flow (it would restart on the old socket path). Shut it down instead so
228
+ // the caller can re-run without a port conflict.
229
+ console.log("[migration] Pre-1.5 daemon found at " + old.sockPath + " — shutting it down so a fresh start can proceed.");
230
+ return sendIPCCommand(old.sockPath, { cmd: "shutdown" }).then(function (resp) {
231
+ if (resp && resp.ok) {
232
+ console.log("Pre-1.5 daemon stopped. Run clagentic-console to start the updated daemon.");
233
+ process.exit(0);
234
+ } else {
235
+ var oldPid = restartConfig && restartConfig.pid;
236
+ console.error("Shutdown of pre-1.5 daemon failed: no acknowledgement from " + old.sockPath);
237
+ if (oldPid) console.error(" Daemon PID: " + oldPid + " (try: kill " + oldPid + ")");
238
+ console.error(" Or: systemctl restart clagentic-console");
239
+ process.exit(1);
240
+ }
241
+ });
242
+ }
243
+ console.error("No running daemon found.");
191
244
  process.exit(1);
192
245
  });
193
246
  });
@@ -292,7 +345,7 @@ var a = {
292
345
  reset: "\x1b[0m",
293
346
  bold: "\x1b[1m",
294
347
  dim: "\x1b[2m",
295
- clay: isBasicTerm ? "\x1b[34m" : "\x1b[38;2;88;87;252m", // #5857FC Indigo — active interaction
348
+ indigo: isBasicTerm ? "\x1b[34m" : "\x1b[38;2;88;87;252m", // #5857FC Indigo — active interaction
296
349
  green: "\x1b[32m",
297
350
  yellow: "\x1b[33m",
298
351
  red: "\x1b[31m",
@@ -302,7 +355,7 @@ function gradient(text) {
302
355
  if (isBasicTerm) {
303
356
  return a.yellow + text + a.reset;
304
357
  }
305
- // Terracotta (#FE7150) → Warm brown (#D09558) — Clay earthy warmth
358
+ // Terracotta (#FE7150) → Warm brown (#D09558) gradient
306
359
  var r0 = 254, g0 = 113, b0 = 80;
307
360
  var r1 = 208, g1 = 149, b1 = 88;
308
361
  var out = "";
@@ -318,7 +371,7 @@ function gradient(text) {
318
371
  }
319
372
 
320
373
  var sym = {
321
- pointer: a.clay + "◆" + a.reset,
374
+ pointer: a.indigo + "◆" + a.reset,
322
375
  done: a.green + "◇" + a.reset,
323
376
  bar: a.dim + "│" + a.reset,
324
377
  end: a.dim + "└" + a.reset,
@@ -389,6 +442,19 @@ function onDaemonDied() {
389
442
  return;
390
443
  }
391
444
 
445
+ // --no-restart: leave the daemon dead so the developer can inspect crash state
446
+ if (noRestart) {
447
+ log("");
448
+ log(sym.warn + " " + a.yellow + "Server crashed. --no-restart is set — not restarting." + a.reset);
449
+ if (crashInfo.reason) {
450
+ log(a.dim + " " + crashInfo.reason.split("\n")[0] + a.reset);
451
+ }
452
+ log(a.dim + " Check logs: " + a.reset + logPath());
453
+ log("");
454
+ process.exit(1);
455
+ return;
456
+ }
457
+
392
458
  // Reset backoff counter if enough time has passed since last restart burst
393
459
  var now = Date.now();
394
460
  if (_restartBackoffStart && now - _restartBackoffStart > 60000) {
@@ -457,6 +523,7 @@ async function restartDaemonFromConfig() {
457
523
  // Debug mode: run in foreground with logs to stdout
458
524
  if (debugMode) {
459
525
  process.env.CLAGENTIC_CONFIG = configPath();
526
+ process.env.CLAGENTIC_HOME = CLAGENTIC_HOME;
460
527
  newConfig.pid = process.pid;
461
528
  saveConfig(newConfig);
462
529
  require(daemonScript);
@@ -472,6 +539,7 @@ async function restartDaemonFromConfig() {
472
539
  stdio: ["ignore", logFd, logFd],
473
540
  env: Object.assign({}, process.env, {
474
541
  CLAGENTIC_CONFIG: configPath(),
542
+ CLAGENTIC_HOME: CLAGENTIC_HOME,
475
543
  }),
476
544
  });
477
545
  child.unref();
@@ -818,7 +886,7 @@ function promptPin(callback) {
818
886
  }
819
887
  } else if (/\d/.test(ch) && pin.length < 6) {
820
888
  pin += ch;
821
- process.stdout.write(a.clay + "●" + a.reset);
889
+ process.stdout.write(a.indigo + "●" + a.reset);
822
890
  }
823
891
  });
824
892
  }
@@ -1121,7 +1189,7 @@ function promptMultiSelect(title, items, callback) {
1121
1189
  function render() {
1122
1190
  var out = "";
1123
1191
  for (var i = 0; i < items.length; i++) {
1124
- var cursor = i === idx ? a.clay + ">" + a.reset : " ";
1192
+ var cursor = i === idx ? a.indigo + ">" + a.reset : " ";
1125
1193
  var check = selected[i]
1126
1194
  ? a.green + a.bold + "■" + a.reset
1127
1195
  : a.dim + "□" + a.reset;
@@ -1288,14 +1356,14 @@ function setup(callback) {
1288
1356
  console.clear();
1289
1357
  printLogo();
1290
1358
  log("");
1291
- log(sym.pointer + " " + a.bold + "Clay" + a.reset + a.dim + " · Unofficial, open-source project" + a.reset);
1359
+ log(sym.pointer + " " + a.bold + "Clagentic: Console" + a.reset + a.dim + " · Unofficial, open-source project" + a.reset);
1292
1360
  log(sym.bar);
1293
1361
  log(sym.bar + " " + a.yellow + sym.warn + " Disclaimer" + a.reset);
1294
1362
  log(sym.bar);
1295
1363
  log(sym.bar + " " + a.dim + "This is an independent project and is not affiliated with Anthropic." + a.reset);
1296
1364
  log(sym.bar + " " + a.dim + "Claude is a trademark of Anthropic." + a.reset);
1297
1365
  log(sym.bar);
1298
- log(sym.bar + " " + a.dim + "Clay is provided \"as is\" without warranty of any kind. Users are" + a.reset);
1366
+ log(sym.bar + " " + a.dim + "Clagentic: Console is provided \"as is\" without warranty of any kind. Users are" + a.reset);
1299
1367
  log(sym.bar + " " + a.dim + "responsible for complying with the terms of service of underlying AI" + a.reset);
1300
1368
  log(sym.bar + " " + a.dim + "providers (e.g., Anthropic, OpenAI) and all applicable terms of any" + a.reset);
1301
1369
  log(sym.bar + " " + a.dim + "third-party services." + a.reset);
@@ -1342,24 +1410,14 @@ function setup(callback) {
1342
1410
  }
1343
1411
  port = p;
1344
1412
  log(sym.bar);
1345
- askMode();
1413
+ // Single-user mode removed (lr-bd9f). All new installs are multi-user.
1414
+ // Existing single-user installs continue to work until the full removal
1415
+ // lands — see task lr-bd9f-redux.
1416
+ askOsUsers("multi");
1346
1417
  });
1347
1418
  });
1348
1419
  }
1349
1420
 
1350
- function askMode() {
1351
- promptSelect("How will you use Clay?", [
1352
- { label: "Just me (single user)", value: "single" },
1353
- { label: "Multiple users", value: "multi" },
1354
- ], function (mode) {
1355
- if (mode === "single") {
1356
- finishSetup(mode, false);
1357
- } else {
1358
- askOsUsers(mode);
1359
- }
1360
- });
1361
- }
1362
-
1363
1421
  function askOsUsers(mode) {
1364
1422
  // Only offer OS user isolation on Linux
1365
1423
  if (process.platform !== "linux") {
@@ -1378,7 +1436,7 @@ function setup(callback) {
1378
1436
  log(sym.bar);
1379
1437
  log(sym.bar + " " + a.yellow + sym.warn + " OS-Level User Isolation" + a.reset);
1380
1438
  log(sym.bar);
1381
- log(sym.bar + " " + a.dim + "This feature maps each Clay user to a Linux OS user account." + a.reset);
1439
+ log(sym.bar + " " + a.dim + "This feature maps each Clagentic: Console user to a Linux OS user account." + a.reset);
1382
1440
  log(sym.bar + " " + a.dim + "The daemon must run as root and will spawn processes (SDK workers," + a.reset);
1383
1441
  log(sym.bar + " " + a.dim + "terminals, file operations) as the mapped Linux user." + a.reset);
1384
1442
  log(sym.bar);
@@ -1387,7 +1445,7 @@ function setup(callback) {
1387
1445
  log(sym.bar + " " + a.dim + "- Terminals and file access follow Linux permissions" + a.reset);
1388
1446
  log(sym.bar + " " + a.dim + "- Linux user accounts are created automatically (clay-username)" + a.reset);
1389
1447
  log(sym.bar);
1390
- log(sym.bar + " " + a.dim + "Recommended: Run on a dedicated Clay server or cloud instance," + a.reset);
1448
+ log(sym.bar + " " + a.dim + "Recommended: Run on a dedicated Clagentic: Console server or cloud instance," + a.reset);
1391
1449
  log(sym.bar + " " + a.dim + "not on a personal computer or general-purpose server." + a.reset);
1392
1450
  log(sym.bar);
1393
1451
  promptSelect("Confirm", [
@@ -1458,11 +1516,34 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers) {
1458
1516
  }
1459
1517
  }
1460
1518
 
1519
+ // Migration shim: detect and shut down a pre-1.5 daemon holding the old socket
1520
+ // path. This prevents the port-in-use dead-end on upgrade. (lr-6ed3)
1521
+ if (process.platform !== "win32") {
1522
+ var oldCheck = await checkOldDaemon();
1523
+ if (oldCheck && oldCheck.alive) {
1524
+ log(sym.warn + " " + a.yellow + "Pre-1.5 daemon detected at " + oldCheck.sockPath + " — shutting it down..." + a.reset);
1525
+ await sendIPCCommand(oldCheck.sockPath, { cmd: "shutdown" });
1526
+ // Wait up to 5 s for the port to be released
1527
+ var migWaited = 0;
1528
+ while (migWaited < 5000) {
1529
+ await new Promise(function (resolve) { setTimeout(resolve, 300); });
1530
+ migWaited += 300;
1531
+ if (await isPortFree(port)) break;
1532
+ }
1533
+ log(sym.done + " " + a.green + "Pre-1.5 daemon stopped. Continuing startup..." + a.reset);
1534
+ } else if (oldCheck && !oldCheck.alive && fs.existsSync(oldCheck.sockPath)) {
1535
+ // Stale socket not yet cleaned up by ensureConfigDir (e.g. ensureConfigDir not
1536
+ // called yet on this path). Remove it now so nothing trips on it later.
1537
+ try { fs.unlinkSync(oldCheck.sockPath); } catch (e) {}
1538
+ }
1539
+ }
1540
+
1461
1541
  // Check port availability
1462
1542
  var portFree = await isPortFree(port);
1463
1543
  if (!portFree) {
1464
1544
  log(a.red + "Port " + port + " is already in use." + a.reset);
1465
- log(a.dim + "Is another Clay daemon running?" + a.reset);
1545
+ log(a.dim + "Another process is holding this port." + a.reset);
1546
+ log(a.dim + "If a pre-1.5 daemon is running, clagentic-console --shutdown will stop it." + a.reset);
1466
1547
  process.exit(1);
1467
1548
  return;
1468
1549
  }
@@ -1545,6 +1626,7 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers) {
1545
1626
  // Debug mode: run in foreground with logs to stdout
1546
1627
  if (debugMode) {
1547
1628
  process.env.CLAGENTIC_CONFIG = configPath();
1629
+ process.env.CLAGENTIC_HOME = CLAGENTIC_HOME;
1548
1630
  config.pid = process.pid;
1549
1631
  saveConfig(config);
1550
1632
  require(daemonScript);
@@ -1560,6 +1642,7 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers) {
1560
1642
  stdio: ["ignore", logFd, logFd],
1561
1643
  env: Object.assign({}, process.env, {
1562
1644
  CLAGENTIC_CONFIG: configPath(),
1645
+ CLAGENTIC_HOME: CLAGENTIC_HOME,
1563
1646
  }),
1564
1647
  });
1565
1648
  child.unref();
@@ -1603,12 +1686,12 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers) {
1603
1686
  : protocol + "://" + ip + ":" + config.port;
1604
1687
  console.log(" " + sym.done + " Daemon started (PID " + config.pid + ")");
1605
1688
  console.log(" " + sym.done + " " + url);
1606
- if (config.mkcertDetected) console.log(" " + sym.warn + " Clay now ships with a builtin HTTPS certificate. To use it, pass --builtin-cert or uninstall mkcert.");
1689
+ if (config.mkcertDetected) console.log(" " + sym.warn + " Clagentic: Console now ships with a builtin HTTPS certificate. To use it, pass --builtin-cert or uninstall mkcert.");
1607
1690
  if (_pendingSetupCode) {
1608
1691
  console.log("");
1609
1692
  console.log(" " + sym.done + " " + a.green + "Multi-user mode enabled." + a.reset);
1610
1693
  console.log(" " + sym.bar + " Setup code: " + a.bold + _pendingSetupCode + a.reset);
1611
- console.log(" " + sym.bar + " Open Clay in your browser and enter this code to create the admin account.");
1694
+ console.log(" " + sym.bar + " Open Clagentic: Console in your browser and enter this code to create the admin account.");
1612
1695
  }
1613
1696
  console.log(" " + sym.done + " Headless mode — exiting CLI");
1614
1697
  process.exit(0);
@@ -1637,6 +1720,25 @@ async function devMode(mode, keepAwake, existingPinHash, wantOsUsers) {
1637
1720
  }
1638
1721
  }
1639
1722
 
1723
+ // Migration shim: detect and shut down a pre-1.5 daemon on the old (dev) socket
1724
+ // path before checking port availability — mirrors what forkDaemon() does. (lr-6ed3)
1725
+ if (process.platform !== "win32") {
1726
+ var devOldCheck = await checkOldDaemon();
1727
+ if (devOldCheck && devOldCheck.alive) {
1728
+ log(sym.warn + " " + a.yellow + "Pre-1.5 daemon detected at " + devOldCheck.sockPath + " — shutting it down..." + a.reset);
1729
+ await sendIPCCommand(devOldCheck.sockPath, { cmd: "shutdown" });
1730
+ var devMigWaited = 0;
1731
+ while (devMigWaited < 5000) {
1732
+ await new Promise(function (resolve) { setTimeout(resolve, 300); });
1733
+ devMigWaited += 300;
1734
+ if (await isPortFree(port)) break;
1735
+ }
1736
+ log(sym.done + " " + a.green + "Pre-1.5 daemon stopped. Continuing startup..." + a.reset);
1737
+ } else if (devOldCheck && !devOldCheck.alive && fs.existsSync(devOldCheck.sockPath)) {
1738
+ try { fs.unlinkSync(devOldCheck.sockPath); } catch (e) {}
1739
+ }
1740
+ }
1741
+
1640
1742
  var portFree = await isPortFree(port);
1641
1743
  if (!portFree) {
1642
1744
  console.log("\x1b[31m[dev] Port " + port + " is already in use.\x1b[0m");
@@ -1729,6 +1831,7 @@ async function devMode(mode, keepAwake, existingPinHash, wantOsUsers) {
1729
1831
  stdio: ["ignore", "inherit", "inherit"],
1730
1832
  env: Object.assign({}, process.env, {
1731
1833
  CLAGENTIC_CONFIG: configPath(),
1834
+ CLAGENTIC_HOME: CLAGENTIC_HOME,
1732
1835
  }),
1733
1836
  });
1734
1837
 
@@ -1751,7 +1854,12 @@ async function devMode(mode, keepAwake, existingPinHash, wantOsUsers) {
1751
1854
  process.exit(78);
1752
1855
  return;
1753
1856
  }
1754
- // Unexpected exit — auto restart
1857
+ // Unexpected exit — auto restart (suppressed when --no-restart is set)
1858
+ if (noRestart) {
1859
+ console.log("\x1b[33m[dev] Daemon exited (code " + code + "). --no-restart is set — not restarting.\x1b[0m");
1860
+ process.exit(code || 1);
1861
+ return;
1862
+ }
1755
1863
  console.log("\x1b[33m[dev] Daemon exited (code " + code + "), restarting...\x1b[0m");
1756
1864
  setTimeout(spawnDaemon, 500);
1757
1865
  });
@@ -1885,6 +1993,7 @@ async function restartDaemonWithTLS(config, callback) {
1885
1993
  stdio: ["ignore", logFd, logFd],
1886
1994
  env: Object.assign({}, process.env, {
1887
1995
  CLAGENTIC_CONFIG: configPath(),
1996
+ CLAGENTIC_HOME: CLAGENTIC_HOME,
1888
1997
  }),
1889
1998
  });
1890
1999
  child.unref();
@@ -1911,6 +2020,7 @@ async function restartDaemonWithTLS(config, callback) {
1911
2020
  stdio: ["ignore", logFd2, logFd2],
1912
2021
  env: Object.assign({}, process.env, {
1913
2022
  CLAGENTIC_CONFIG: configPath(),
2023
+ CLAGENTIC_HOME: CLAGENTIC_HOME,
1914
2024
  }),
1915
2025
  });
1916
2026
  child2.unref();
@@ -1963,7 +2073,7 @@ function showMainMenu(config, ip, setupCode) {
1963
2073
 
1964
2074
  function afterQr() {
1965
2075
  // Status line
1966
- log(" " + a.dim + "clagentic" + a.reset + " " + a.dim + "v" + currentVersion + a.reset + a.dim + " — " + url + a.reset);
2076
+ log(" " + a.dim + "Clagentic: Console" + a.reset + " " + a.dim + "v" + currentVersion + a.reset + a.dim + " — " + url + a.reset);
1967
2077
  var parts = [];
1968
2078
  parts.push(a.bold + projs.length + a.reset + a.dim + (projs.length === 1 ? " project" : " projects"));
1969
2079
  parts.push(a.reset + a.bold + totalSessions + a.reset + a.dim + (totalSessions === 1 ? " session" : " sessions"));
@@ -1976,7 +2086,7 @@ function showMainMenu(config, ip, setupCode) {
1976
2086
  log("");
1977
2087
 
1978
2088
  if (config.mkcertDetected) {
1979
- log(" " + sym.warn + " " + a.yellow + "Clay now ships with a builtin HTTPS certificate." + a.reset);
2089
+ log(" " + sym.warn + " " + a.yellow + "Clagentic: Console now ships with a builtin HTTPS certificate." + a.reset);
1980
2090
  log(" " + a.dim + "No more CA setup on each device." + a.reset);
1981
2091
  log(" " + a.dim + "To use it, pass --builtin-cert or uninstall mkcert." + a.reset);
1982
2092
  log("");
@@ -2095,7 +2205,7 @@ function showSettingsMenu(config, ip) {
2095
2205
 
2096
2206
  var modeLabel = config.mode === "multi" ? "Multi-user" : "Single user";
2097
2207
  var modeStatus = config.mode === "multi"
2098
- ? a.clay + modeLabel + a.reset
2208
+ ? a.indigo + modeLabel + a.reset
2099
2209
  : a.dim + modeLabel + a.reset;
2100
2210
  log(sym.bar + " Mode " + modeStatus);
2101
2211
  log(sym.bar + " PIN " + pinStatus);
@@ -2188,7 +2298,7 @@ function showSettingsMenu(config, ip) {
2188
2298
  log(sym.bar);
2189
2299
  log(sym.bar + " Setup code: " + a.bold + muResult.setupCode + a.reset);
2190
2300
  log(sym.bar);
2191
- log(sym.bar + " " + a.dim + "Open Clay in your browser and enter this code to create the admin account." + a.reset);
2301
+ log(sym.bar + " " + a.dim + "Open Clagentic: Console in your browser and enter this code to create the admin account." + a.reset);
2192
2302
  log(sym.bar + " " + a.dim + "The code is single-use and will be cleared once the admin is set up." + a.reset);
2193
2303
  } else {
2194
2304
  log(sym.bar + " " + a.dim + "Multi-user mode is already enabled." + a.reset);
@@ -2246,7 +2356,7 @@ function showSettingsMenu(config, ip) {
2246
2356
  log(sym.bar);
2247
2357
  log(sym.bar + " " + a.red + sym.warn + " OS-level user isolation requires Linux." + a.reset);
2248
2358
  log(sym.bar + " " + a.dim + "This feature depends on setfacl, getent, and uid/gid process spawning." + a.reset);
2249
- log(sym.bar + " " + a.dim + "Use Docker or a Linux VM to run Clay with OS user isolation." + a.reset);
2359
+ log(sym.bar + " " + a.dim + "Use Docker or a Linux VM to run Clagentic: Console with OS user isolation." + a.reset);
2250
2360
  log(sym.bar);
2251
2361
  showSettingsMenu(config, ip);
2252
2362
  return;
@@ -2254,7 +2364,7 @@ function showSettingsMenu(config, ip) {
2254
2364
  log(sym.bar);
2255
2365
  log(sym.bar + " " + a.yellow + sym.warn + " OS-Level User Isolation" + a.reset);
2256
2366
  log(sym.bar);
2257
- log(sym.bar + " " + a.dim + "This feature maps each Clay user to a Linux OS user account." + a.reset);
2367
+ log(sym.bar + " " + a.dim + "This feature maps each Clagentic: Console user to a Linux OS user account." + a.reset);
2258
2368
  log(sym.bar + " " + a.dim + "The daemon must run as root and will spawn processes (SDK workers," + a.reset);
2259
2369
  log(sym.bar + " " + a.dim + "terminals, file operations) as the mapped Linux user." + a.reset);
2260
2370
  log(sym.bar);
@@ -2263,7 +2373,7 @@ function showSettingsMenu(config, ip) {
2263
2373
  log(sym.bar + " " + a.dim + "- Terminals and file access follow Linux permissions" + a.reset);
2264
2374
  log(sym.bar + " " + a.dim + "- Linux user accounts are created automatically (clay-username)" + a.reset);
2265
2375
  log(sym.bar);
2266
- log(sym.bar + " " + a.dim + "Recommended: Run on a dedicated Clay server or cloud instance," + a.reset);
2376
+ log(sym.bar + " " + a.dim + "Recommended: Run on a dedicated Clagentic: Console server or cloud instance," + a.reset);
2267
2377
  log(sym.bar + " " + a.dim + "not on a personal computer or general-purpose server." + a.reset);
2268
2378
  log(sym.bar);
2269
2379
  promptSelect("Select", [
@@ -2755,7 +2865,7 @@ var currentVersion = require("../package.json").version;
2755
2865
  console.error("");
2756
2866
  console.error("Install it: " + a.bold + aclCheck.installCmd + a.reset);
2757
2867
  console.error("");
2758
- console.error("Then restart Clay.");
2868
+ console.error("Then restart Clagentic: Console.");
2759
2869
  process.exit(1);
2760
2870
  return;
2761
2871
  }
@@ -7,6 +7,8 @@ Type=simple
7
7
  ExecStart=/usr/local/bin/clagentic-daemon.sh
8
8
  Restart=always
9
9
  RestartSec=5
10
+ # EX_CONFIG (78) is a fatal configuration error (mis-set CLAGENTIC_HOME, unsupported Node) — do not restart-loop
11
+ RestartPreventExitStatus=78
10
12
  KillMode=mixed
11
13
  TimeoutStopSec=20
12
14
  SendSIGKILL=yes
@@ -150,8 +150,10 @@ function addFavorite(agent) {
150
150
  }
151
151
 
152
152
  // Remove an agent from favorites. Returns true if removed, false if not present.
153
+ // Note: schema v2 entries have only {name, addedAt} — no kind field — so we
154
+ // guard on name only (matching addFavorite and sameAgent).
153
155
  function removeFavorite(agent) {
154
- if (!agent || !agent.name || !agent.kind) return false;
156
+ if (!agent || !agent.name) return false;
155
157
  var store = readStore();
156
158
  var before = store.favorites.length;
157
159
  store.favorites = store.favorites.filter(function (f) { return !sameAgent(f, agent); });
package/lib/agents.js CHANGED
@@ -28,11 +28,8 @@
28
28
 
29
29
  var fs = require("fs");
30
30
  var path = require("path");
31
- var os = require("os");
32
-
33
- var REAL_HOME = process.env.SUDO_USER
34
- ? path.join("/home", process.env.SUDO_USER)
35
- : os.homedir();
31
+ // Use config.js REAL_HOME — it handles sudo/getent/root-reject uniformly.
32
+ var { REAL_HOME } = require("./config");
36
33
 
37
34
  // Still exported for callers that referenced them (backwards compat).
38
35
  var AGENTS_SOURCE_DIR = path.join(REAL_HOME, ".claude", "agents");
@@ -223,12 +220,85 @@ function discoverAllAgents() {
223
220
  return getAll();
224
221
  }
225
222
 
223
+ // Read all named-agent definitions from a project-local .claude/agents/ directory,
224
+ // merged with the global ~/.claude/agents/ directory.
225
+ //
226
+ // Claude Code resolves agents from both locations. Project-local definitions
227
+ // take precedence: if the same slug appears in both directories, the
228
+ // project-local entry wins.
229
+ //
230
+ // projectDir: absolute path to the project root (cwd).
231
+ // Returns: array of { name, slug, description } objects, sorted by name.
232
+ // Returns [] if neither directory exists or is readable — callers treat
233
+ // an empty array as "no agents" and degrade gracefully.
234
+ //
235
+ // This reads the filesystem directly (no SDK subprocess) — it is synchronous
236
+ // and cheap. Each agents directory is small (typically 0–20 files).
237
+ function _readAgentsFromDir(agentsDir) {
238
+ var entries;
239
+ try {
240
+ entries = fs.readdirSync(agentsDir);
241
+ } catch (e) {
242
+ // Directory absent or unreadable — not an error.
243
+ return [];
244
+ }
245
+ var results = [];
246
+ for (var i = 0; i < entries.length; i++) {
247
+ var entry = entries[i];
248
+ if (!entry || !entry.endsWith(".md")) continue;
249
+ var slug = entry.slice(0, -3); // strip .md
250
+ if (!slug) continue;
251
+ var filePath = path.join(agentsDir, entry);
252
+ var raw;
253
+ try {
254
+ raw = fs.readFileSync(filePath, "utf8");
255
+ } catch (e) {
256
+ continue;
257
+ }
258
+ var parsed = parseFrontmatter(raw);
259
+ var name = (parsed && parsed.meta && parsed.meta.name) ? String(parsed.meta.name) : slug;
260
+ var description = (parsed && parsed.meta && parsed.meta.description) ? String(parsed.meta.description) : "";
261
+ results.push({ name: name, slug: slug, description: description });
262
+ }
263
+ return results;
264
+ }
265
+
266
+ // _globalAgentsDir is an optional override used in tests; callers must not pass it.
267
+ function readProjectAgents(projectDir, _globalAgentsDir) {
268
+ if (!projectDir || typeof projectDir !== "string") return [];
269
+
270
+ var localDir = path.join(projectDir, ".claude", "agents");
271
+ var globalDir = (typeof _globalAgentsDir === "string" && _globalAgentsDir)
272
+ ? _globalAgentsDir
273
+ : path.join(REAL_HOME, ".claude", "agents");
274
+
275
+ var localEntries = _readAgentsFromDir(localDir);
276
+ var globalEntries = _readAgentsFromDir(globalDir);
277
+
278
+ // Build a slug-keyed map from global entries, then overlay local entries.
279
+ // Local definitions win when the same slug appears in both directories.
280
+ var bySlug = Object.create(null);
281
+ for (var i = 0; i < globalEntries.length; i++) {
282
+ bySlug[globalEntries[i].slug] = globalEntries[i];
283
+ }
284
+ for (var j = 0; j < localEntries.length; j++) {
285
+ bySlug[localEntries[j].slug] = localEntries[j];
286
+ }
287
+
288
+ var results = Object.keys(bySlug).map(function (slug) { return bySlug[slug]; });
289
+ results.sort(function (a, b) {
290
+ return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
291
+ });
292
+ return results;
293
+ }
294
+
226
295
  module.exports = {
227
296
  AGENTS_SOURCE_DIR: AGENTS_SOURCE_DIR,
228
297
  PLUGINS_CACHE_DIR: PLUGINS_CACHE_DIR,
229
298
  parseFrontmatter: parseFrontmatter,
230
299
  slugifyAgentName: slugifyAgentName,
231
300
  readAgentToolsFromFile: readAgentToolsFromFile,
301
+ readProjectAgents: readProjectAgents,
232
302
  // New SDK-backed surface:
233
303
  refresh: refresh,
234
304
  getAll: getAll,