@clagentic/console 1.6.0 → 1.7.0-beta.1

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 (85) hide show
  1. package/bin/cli.js +20 -102
  2. package/deploy/clagentic-console.service +10 -1
  3. package/lib/agents-favorites.js +0 -1
  4. package/lib/agents.js +0 -10
  5. package/lib/cli-sessions.js +0 -12
  6. package/lib/codex-defaults.js +4 -1
  7. package/lib/config.js +0 -8
  8. package/lib/daemon.js +88 -9
  9. package/lib/dm.js +0 -1
  10. package/lib/ipc.js +129 -59
  11. package/lib/loop-handoff.js +5 -1
  12. package/lib/memory-limits.js +214 -36
  13. package/lib/memory-shed.js +207 -0
  14. package/lib/notes.js +0 -20
  15. package/lib/os-users.js +0 -3
  16. package/lib/project-connection.js +31 -5
  17. package/lib/project-external-trigger.js +2 -1
  18. package/lib/project-filesystem.js +18 -11
  19. package/lib/project-knowledge.js +0 -8
  20. package/lib/project-loop.js +162 -9
  21. package/lib/project-sessions.js +87 -21
  22. package/lib/project-user-mention.js +2 -1
  23. package/lib/project-user-message.js +16 -5
  24. package/lib/project.js +14 -25
  25. package/lib/public/app.js +1 -2
  26. package/lib/public/css/channel-layout.css +25 -158
  27. package/lib/public/css/diagnostics.css +17 -1
  28. package/lib/public/css/icon-strip.css +1 -32
  29. package/lib/public/css/input.css +0 -56
  30. package/lib/public/css/loop.css +94 -0
  31. package/lib/public/css/messages.css +23 -4
  32. package/lib/public/css/mobile-nav.css +0 -124
  33. package/lib/public/index.html +11 -11
  34. package/lib/public/modules/app-connection.js +2 -1
  35. package/lib/public/modules/app-favicon.js +1 -1
  36. package/lib/public/modules/app-loop-ui.js +140 -4
  37. package/lib/public/modules/app-messages.js +17 -11
  38. package/lib/public/modules/app-projects.js +1 -1
  39. package/lib/public/modules/custom-icons.js +15 -1
  40. package/lib/public/modules/dom-refs.js +1 -2
  41. package/lib/public/modules/emoji-picker.js +6 -1
  42. package/lib/public/modules/filebrowser.js +33 -9
  43. package/lib/public/modules/input.js +39 -0
  44. package/lib/public/modules/scheduler.js +20 -6
  45. package/lib/public/modules/sidebar-mobile.js +0 -64
  46. package/lib/public/modules/sidebar-projects.js +90 -25
  47. package/lib/public/modules/sidebar-sessions.js +80 -13
  48. package/lib/public/modules/stt.js +2 -6
  49. package/lib/public/modules/tool-palette.js +0 -1
  50. package/lib/public/modules/tools.js +2 -6
  51. package/lib/public/style.css +0 -1
  52. package/lib/scheduler.js +0 -1
  53. package/lib/sdk-bridge.js +126 -194
  54. package/lib/sdk-message-processor.js +24 -9
  55. package/lib/sdk-permission-ownership.js +51 -0
  56. package/lib/server-auth.js +25 -18
  57. package/lib/server-dm.js +1 -1
  58. package/lib/server-skills.js +9 -1
  59. package/lib/server.js +18 -3
  60. package/lib/session-search.js +4 -299
  61. package/lib/sessions.js +467 -82
  62. package/lib/smtp.js +0 -15
  63. package/lib/user-presence.js +0 -12
  64. package/lib/users-preferences.js +2 -2
  65. package/lib/users.js +0 -5
  66. package/lib/utils.js +56 -0
  67. package/lib/ws-schema.js +3 -14
  68. package/lib/yoke/adapters/codex.js +96 -10
  69. package/lib/yoke/codex-local-image.js +79 -0
  70. package/package.json +1 -1
  71. package/scripts/postinstall.js +16 -11
  72. package/lib/ask-user-mcp-server.js +0 -121
  73. package/lib/project-memory.js +0 -39
  74. package/lib/public/console-icon.png +0 -0
  75. package/lib/public/css/debate.css +0 -1610
  76. package/lib/public/favicon-banded-32.png +0 -0
  77. package/lib/public/favicon-dark.svg +0 -32
  78. package/lib/public/favicon.svg +0 -32
  79. package/lib/public/icon-banded-96.png +0 -0
  80. package/lib/public/icons/email/gmail.svg +0 -7
  81. package/lib/public/icons/email/outlook.svg +0 -35
  82. package/lib/public/icons/email/yahoo.svg +0 -1
  83. package/lib/public/modules/events.js +0 -21
  84. package/lib/public/modules/state.js +0 -3
  85. package/lib/sdk-worker.js +0 -730
package/bin/cli.js CHANGED
@@ -33,8 +33,7 @@ if (_isDev || process.argv.includes("--debug")) {
33
33
  var crypto = require("crypto");
34
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
- var { generateAuthToken } = require("../lib/server");
37
- var { enableMultiUser, disableMultiUser, hasAdmin, isMultiUser, getSetupCode } = require("../lib/users");
36
+ var { hasAdmin, getSetupCode, hashPin } = require("../lib/users");
38
37
 
39
38
  function openUrl(url) {
40
39
  try {
@@ -1576,7 +1575,7 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers) {
1576
1575
  pid: null,
1577
1576
  port: port,
1578
1577
  host: host,
1579
- pinHash: mode === "multi" && cliPin ? generateAuthToken(cliPin) : (prevConfig && prevConfig.pinHash) || null,
1578
+ pinHash: mode === "multi" && cliPin ? hashPin(cliPin) : (prevConfig && prevConfig.pinHash) || null,
1580
1579
  tls: hasTls,
1581
1580
  mkcertDetected: mkcertDetected,
1582
1581
  debug: debugMode,
@@ -1639,16 +1638,9 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers) {
1639
1638
  return;
1640
1639
  }
1641
1640
 
1642
- // Enable/disable multi-user mode based on startup config
1643
- var _pendingSetupCode = null;
1644
- if (config.mode === "multi") {
1645
- var muResult = enableMultiUser();
1646
- if (muResult.setupCode) {
1647
- _pendingSetupCode = muResult.setupCode;
1648
- }
1649
- } else if (isMultiUser()) {
1650
- disableMultiUser();
1651
- }
1641
+ // Multi-user mode is always on (single-user mode was removed, lr-ec2d).
1642
+ // getSetupCode() auto-generates a code when there's no admin yet.
1643
+ var _pendingSetupCode = hasAdmin() ? null : getSetupCode();
1652
1644
 
1653
1645
  // Headless mode — print status and exit immediately
1654
1646
  if (headlessMode) {
@@ -1776,14 +1768,13 @@ async function devMode(mode, keepAwake, existingPinHash, wantOsUsers) {
1776
1768
  ensureConfigDir();
1777
1769
  saveConfig(config);
1778
1770
 
1779
- // Enable/disable multi-user mode based on startup config
1780
- if (config.mode === "multi") {
1781
- var muResult = enableMultiUser();
1782
- if (muResult.setupCode) {
1783
- console.log("\x1b[38;2;0;183;133m[dev]\x1b[0m Multi-user mode enabled. Setup code: " + muResult.setupCode);
1771
+ // Multi-user mode is always on (single-user mode was removed, lr-ec2d).
1772
+ // getSetupCode() auto-generates a code when there's no admin yet.
1773
+ if (!hasAdmin()) {
1774
+ var devSetupCode = getSetupCode();
1775
+ if (devSetupCode) {
1776
+ console.log("\x1b[38;2;0;183;133m[dev]\x1b[0m Multi-user mode enabled. Setup code: " + devSetupCode);
1784
1777
  }
1785
- } else if (isMultiUser()) {
1786
- disableMultiUser();
1787
1778
  }
1788
1779
 
1789
1780
  var daemonScript = path.join(__dirname, "..", "lib", "daemon.js");
@@ -2153,24 +2144,14 @@ function showSettingsMenu(config, ip) {
2153
2144
  : a.dim + "Off" + a.reset;
2154
2145
 
2155
2146
  log(sym.bar + " HTTPS " + tlsStatus);
2156
- var muEnabled = isMultiUser();
2157
- var muStatus = muEnabled
2158
- ? a.green + "Enabled" + a.reset
2159
- : a.dim + "Off" + a.reset;
2160
2147
 
2161
- var modeLabel = config.mode === "multi" ? "Multi-user" : "Single user";
2162
- var modeStatus = config.mode === "multi"
2163
- ? a.indigo + modeLabel + a.reset
2164
- : a.dim + modeLabel + a.reset;
2165
- log(sym.bar + " Mode " + modeStatus);
2148
+ // Multi-user mode is always on (single-user mode was removed, lr-ec2d).
2149
+ log(sym.bar + " Mode " + a.indigo + "Multi-user" + a.reset);
2166
2150
  log(sym.bar + " PIN " + pinStatus);
2167
- log(sym.bar + " Multi-user " + muStatus);
2168
2151
  var osUsersStatus = isOsUsers
2169
2152
  ? a.green + "Enabled" + a.reset
2170
2153
  : a.dim + "Off" + a.reset;
2171
- if (muEnabled) {
2172
- log(sym.bar + " OS users " + osUsersStatus);
2173
- }
2154
+ log(sym.bar + " OS users " + osUsersStatus);
2174
2155
  if (process.platform === "darwin") {
2175
2156
  log(sym.bar + " Keep awake " + awakeStatus);
2176
2157
  }
@@ -2179,28 +2160,13 @@ function showSettingsMenu(config, ip) {
2179
2160
  // Build items
2180
2161
  var items = [];
2181
2162
 
2182
- if (!muEnabled) {
2183
- if (config.pinHash) {
2184
- items.push({ label: "Change PIN", value: "pin" });
2185
- items.push({ label: "Remove PIN", value: "remove_pin" });
2186
- } else {
2187
- items.push({ label: "Set PIN", value: "pin" });
2188
- }
2189
- }
2190
- if (muEnabled) {
2191
- items.push({ label: "Disable multi-user mode", value: "disable_multi_user" });
2192
- if (isOsUsers) {
2193
- items.push({ label: "Disable OS-level user isolation", value: "disable_os_users" });
2194
- } else {
2195
- items.push({ label: "Enable OS-level user isolation", value: "os_users" });
2196
- }
2163
+ if (isOsUsers) {
2164
+ items.push({ label: "Disable OS-level user isolation", value: "disable_os_users" });
2197
2165
  } else {
2198
- items.push({ label: "Enable multi-user mode", value: "multi_user" });
2166
+ items.push({ label: "Enable OS-level user isolation", value: "os_users" });
2199
2167
  }
2200
- if (muEnabled) {
2201
- items.push({ label: "Show setup code", value: "show_setup_code" });
2202
- }
2203
- if (muEnabled && hasAdmin()) {
2168
+ items.push({ label: "Show setup code", value: "show_setup_code" });
2169
+ if (hasAdmin()) {
2204
2170
  items.push({ label: "Recover admin password", value: "recover_admin" });
2205
2171
  }
2206
2172
  if (process.platform === "darwin") {
@@ -2216,7 +2182,7 @@ function showSettingsMenu(config, ip) {
2216
2182
  log(sym.bar);
2217
2183
  promptPin(function (pin) {
2218
2184
  if (pin) {
2219
- var hash = generateAuthToken(pin);
2185
+ var hash = hashPin(pin);
2220
2186
  sendIPCCommand(socketPath(), { cmd: "set_pin", pinHash: hash }).then(function () {
2221
2187
  config.pinHash = hash;
2222
2188
  log(sym.done + " " + a.green + "PIN updated" + a.reset);
@@ -2238,54 +2204,6 @@ function showSettingsMenu(config, ip) {
2238
2204
  });
2239
2205
  break;
2240
2206
 
2241
- case "multi_user":
2242
- var muResult = enableMultiUser();
2243
- log(sym.bar);
2244
- log(sym.bar + " " + a.yellow + sym.warn + " Experimental Feature" + a.reset);
2245
- log(sym.bar);
2246
- log(sym.bar + " " + a.dim + "Multi-user mode is experimental and may change in future releases." + a.reset);
2247
- log(sym.bar + " " + a.dim + "Sharing access to AI-powered tools may be subject to your provider's" + a.reset);
2248
- log(sym.bar + " " + a.dim + "terms of service. Please review the applicable usage policies before" + a.reset);
2249
- log(sym.bar + " " + a.dim + "granting access to other users." + a.reset);
2250
- log(sym.bar);
2251
- if (muResult.setupCode) {
2252
- log(sym.bar + " " + a.green + "Multi-user mode enabled." + a.reset);
2253
- log(sym.bar);
2254
- log(sym.bar + " Setup code: " + a.bold + muResult.setupCode + a.reset);
2255
- log(sym.bar);
2256
- log(sym.bar + " " + a.dim + "Open Clagentic: Console in your browser and enter this code to create the admin account." + a.reset);
2257
- log(sym.bar + " " + a.dim + "The code is single-use and will be cleared once the admin is set up." + a.reset);
2258
- } else {
2259
- log(sym.bar + " " + a.dim + "Multi-user mode is already enabled." + a.reset);
2260
- }
2261
- log(sym.bar);
2262
- promptSelect("Back?", [{ label: "Back", value: "back" }], function () {
2263
- showSettingsMenu(config, ip);
2264
- });
2265
- break;
2266
-
2267
- case "disable_multi_user":
2268
- log(sym.bar);
2269
- log(sym.bar + " " + a.yellow + sym.warn + " Disable multi-user mode?" + a.reset);
2270
- log(sym.bar);
2271
- log(sym.bar + " " + a.dim + "Sessions created by other users will no longer be visible." + a.reset);
2272
- log(sym.bar + " " + a.dim + "User accounts will be preserved and restored if re-enabled." + a.reset);
2273
- log(sym.bar);
2274
- promptSelect("Confirm", [
2275
- { label: "Disable multi-user mode", value: "confirm" },
2276
- { label: "Cancel", value: "cancel" },
2277
- ], function (confirmChoice) {
2278
- if (confirmChoice === "confirm") {
2279
- disableMultiUser();
2280
- log(sym.bar);
2281
- log(sym.done + " " + a.green + "Multi-user mode disabled." + a.reset);
2282
- log(sym.bar + " " + a.dim + "Restart the daemon for changes to take full effect." + a.reset);
2283
- log(sym.bar);
2284
- }
2285
- showSettingsMenu(config, ip);
2286
- });
2287
- break;
2288
-
2289
2207
  case "os_users":
2290
2208
  if (process.platform === "win32") {
2291
2209
  log(sym.bar);
@@ -12,7 +12,16 @@ RestartPreventExitStatus=78
12
12
  KillMode=mixed
13
13
  TimeoutStopSec=20
14
14
  SendSIGKILL=yes
15
- # Soft ceiling — kernel begins reclaiming memory early (requires systemd 240+; host runs systemd 255)
15
+ # Soft/hard ceilings below are DOCUMENTATION-ONLY FALLBACKS (requires systemd 240+; host runs
16
+ # systemd 255). Do not trust a `%` memory directive inside a container: systemd resolves it
17
+ # against the cgroup-visible MemTotal at the HOST layer, not the container's true RAM — only
18
+ # userspace (via lxcfs) sees the container-true /proc/meminfo value. Inside an LXC container
19
+ # these percentages are silently miscalibrated (lr-c10f6d). The postinstall step
20
+ # (scripts/postinstall.js + lib/memory-limits.js) always overwrites these with a systemd
21
+ # drop-in computed as ABSOLUTE bytes from /proc/meminfo MemTotal (floor(60%)/floor(75%), or an
22
+ # explicit operator daemon.json override) — that drop-in, not the lines below, is what actually
23
+ # applies on any host running the real installer.
24
+ # Soft ceiling — kernel begins reclaiming memory early
16
25
  MemoryHigh=70%
17
26
  # Hard ceiling — triggers per-service OOM so OOMPolicy fires instead of host-level OOM killer
18
27
  MemoryMax=85%
@@ -205,7 +205,6 @@ function touchRecent(agent) {
205
205
 
206
206
  module.exports = {
207
207
  FAVORITES_PATH: FAVORITES_PATH,
208
- RECENTS_LIMIT: RECENTS_LIMIT,
209
208
  listFavorites: listFavorites,
210
209
  isFavorite: isFavorite,
211
210
  addFavorite: addFavorite,
package/lib/agents.js CHANGED
@@ -33,7 +33,6 @@ var { REAL_HOME } = require("./config");
33
33
 
34
34
  // Still exported for callers that referenced them (backwards compat).
35
35
  var AGENTS_SOURCE_DIR = path.join(REAL_HOME, ".claude", "agents");
36
- var PLUGINS_CACHE_DIR = path.join(REAL_HOME, ".claude", "plugins", "cache");
37
36
 
38
37
  // Minimal frontmatter parser — kept for any callers that still use it.
39
38
  function parseFrontmatter(raw) {
@@ -214,12 +213,6 @@ function getAll() {
214
213
  return _cache.slice();
215
214
  }
216
215
 
217
- // Legacy alias. Returns the same as getAll() — kept so callers that used
218
- // discoverAllAgents() still work without changes.
219
- function discoverAllAgents() {
220
- return getAll();
221
- }
222
-
223
216
  // Read all named-agent definitions from a project-local .claude/agents/ directory,
224
217
  // merged with the global ~/.claude/agents/ directory.
225
218
  //
@@ -294,7 +287,6 @@ function readProjectAgents(projectDir, _globalAgentsDir) {
294
287
 
295
288
  module.exports = {
296
289
  AGENTS_SOURCE_DIR: AGENTS_SOURCE_DIR,
297
- PLUGINS_CACHE_DIR: PLUGINS_CACHE_DIR,
298
290
  parseFrontmatter: parseFrontmatter,
299
291
  slugifyAgentName: slugifyAgentName,
300
292
  readAgentToolsFromFile: readAgentToolsFromFile,
@@ -302,6 +294,4 @@ module.exports = {
302
294
  // New SDK-backed surface:
303
295
  refresh: refresh,
304
296
  getAll: getAll,
305
- // Legacy compat alias (no longer shells out to claude CLI):
306
- discoverAllAgents: discoverAllAgents,
307
297
  };
@@ -197,16 +197,6 @@ function listCliSessions(cwd) {
197
197
  });
198
198
  }
199
199
 
200
- /**
201
- * Get the most recent CLI session for a given project directory.
202
- * Returns the session object or null if none found.
203
- */
204
- function getMostRecentCliSession(cwd) {
205
- return listCliSessions(cwd).then(function (sessions) {
206
- return sessions.length > 0 ? sessions[0] : null;
207
- });
208
- }
209
-
210
200
  /**
211
201
  * Extract user message text from a CLI JSONL content field.
212
202
  * Content can be a string or an array of content blocks.
@@ -310,9 +300,7 @@ function readCliSessionHistory(cwd, sessionId) {
310
300
 
311
301
  module.exports = {
312
302
  listCliSessions: listCliSessions,
313
- getMostRecentCliSession: getMostRecentCliSession,
314
303
  readCliSessionHistory: readCliSessionHistory,
315
304
  parseSessionFile: parseSessionFile,
316
305
  encodeCwd: encodeCwd,
317
- extractText: extractText,
318
306
  };
@@ -1,6 +1,9 @@
1
+ // lr-f7a4 — sandbox defaults to "workspace-write" (matches the Codex CLI's own
2
+ // safe default). "danger-full-access" removes all filesystem guardrails and
3
+ // must be an explicit opt-in via the UI/session setting, never the default.
1
4
  var CODEX_DEFAULTS = {
2
5
  approval: "on-failure",
3
- sandbox: "danger-full-access",
6
+ sandbox: "workspace-write",
4
7
  webSearch: "live",
5
8
  };
6
9
 
package/lib/config.js CHANGED
@@ -457,10 +457,6 @@ function clearCrashInfo() {
457
457
 
458
458
  // --- ~/.clagentic-rc (recent projects persistence) ---
459
459
 
460
- function clagentic_rcPath() {
461
- return CLAGENTIC_RC_PATH;
462
- }
463
-
464
460
  function loadClayrc() {
465
461
  try {
466
462
  var data = fs.readFileSync(CLAGENTIC_RC_PATH, "utf8");
@@ -549,11 +545,9 @@ module.exports = {
549
545
  CLAGENTIC_HOME: CLAGENTIC_HOME,
550
546
  EXTERNAL_TRIGGERS_DIR: EXTERNAL_TRIGGERS_DIR,
551
547
  configPath: configPath,
552
- oldConfigPath: oldConfigPath,
553
548
  socketPath: socketPath,
554
549
  oldSocketPath: oldSocketPath,
555
550
  logPath: logPath,
556
- oldLogPath: oldLogPath,
557
551
  ensureConfigDir: ensureConfigDir,
558
552
  loadConfig: loadConfig,
559
553
  saveConfig: saveConfig,
@@ -567,7 +561,6 @@ module.exports = {
567
561
  writeCrashInfo: writeCrashInfo,
568
562
  readCrashInfo: readCrashInfo,
569
563
  clearCrashInfo: clearCrashInfo,
570
- clayrcPath: clagentic_rcPath,
571
564
  loadClayrc: loadClayrc,
572
565
  saveClayrc: saveClayrc,
573
566
  syncClayrc: syncClayrc,
@@ -575,6 +568,5 @@ module.exports = {
575
568
  chmodSafe: chmodSafe,
576
569
  isDevMode: _devMode,
577
570
  REAL_HOME: REAL_HOME,
578
- OLD_CLAY_HOME: OLD_CLAY_HOME,
579
571
  };
580
572
 
package/lib/daemon.js CHANGED
@@ -32,8 +32,10 @@ var { createWorktree, removeWorktree, isWorktree } = require("./worktree");
32
32
  var { isWorktreeSlug, scanAndRegisterWorktrees, rescanWorktrees, cleanupWorktreesForParent, getFilteredRemovedProjects, registerWorktreeSlug, unregisterWorktreeSlug } = require("./daemon-projects");
33
33
  var { validateCloneUrl, buildCloneArgs } = require("./clone-validate");
34
34
  var { DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiveCount } = require("./sdk-bridge");
35
- var { startMemoryHighWatcher } = require("./memory-limits");
35
+ var { startMemoryHighWatcher, checkAppliedMemoryCeiling } = require("./memory-limits");
36
36
  var { createDrain } = require("./drain");
37
+ var { shedMemory } = require("./memory-shed");
38
+ var { dropSkillsCache } = require("./server-skills");
37
39
  var liteDetect = require("./lite-detect");
38
40
  var { execFile: liteExecFile } = require("child_process");
39
41
  var { SLUG_RE: CUSTOM_ICON_SLUG_RE, CUSTOM_EMOJI_CT } = require("./server-settings");
@@ -263,6 +265,9 @@ var relay = createServer({
263
265
  dangerouslySkipPermissions: config.dangerouslySkipPermissions || false,
264
266
  osUsers: config.osUsers || false,
265
267
  lanHost: lanIp ? lanIp + ":" + config.port : null,
268
+ // lr-2ea2a7: optional daemon.json override for the in-heap session-history
269
+ // tail cap (default 1000 entries, see lib/sessions.js HISTORY_INMEM_MAX_DEFAULT).
270
+ historyInMemMax: typeof config.historyInMemMax === "number" ? config.historyInMemMax : undefined,
266
271
  getRemovedProjects: function (userId) { return getFilteredRemovedProjects(config, userId); },
267
272
  getFolderMeta: function () { return config.folderMeta || {}; },
268
273
  onAddProject: function (absPath, wsUser) {
@@ -461,16 +466,30 @@ var relay = createServer({
461
466
  });
462
467
  } catch (e) {}
463
468
  }
464
- // Pre-create target directory as root and chown to user
465
- if (fs.existsSync(targetDir)) {
466
- callback({ ok: false, error: "Target directory already exists: " + targetDir });
469
+ // Reserve targetDir atomically. mkdirSync (non-recursive) throws EEXIST
470
+ // if the directory is already there, which also covers the case where
471
+ // another concurrent clone_project of the same repo URL got there first
472
+ // (the previous fs.existsSync + later mkdirSync had a TOCTOU gap that let
473
+ // two callers both believe they owned targetDir — lr-1bdb item C). Only
474
+ // the invocation whose mkdirSync actually created the directory is
475
+ // allowed to rmSync it later on failure.
476
+ var _createdTargetDir = false;
477
+ try {
478
+ fs.mkdirSync(targetDir, config.osUsers && wsUser && wsUser.linuxUser && spawnOpts.uid != null ? { mode: 0o700 } : undefined);
479
+ _createdTargetDir = true;
480
+ } catch (e) {
481
+ if (e.code === "EEXIST") {
482
+ callback({ ok: false, error: "Target directory already in use: " + targetDir });
483
+ } else {
484
+ callback({ ok: false, error: "Failed to prepare project directory: " + e.message });
485
+ }
467
486
  return;
468
487
  }
469
488
  if (config.osUsers && wsUser && wsUser.linuxUser && spawnOpts.uid != null) {
470
489
  try {
471
- fs.mkdirSync(targetDir, { mode: 0o700 });
472
490
  fs.chownSync(targetDir, spawnOpts.uid, spawnOpts.gid);
473
491
  } catch (e) {
492
+ if (_createdTargetDir) { try { fs.rmSync(targetDir, { recursive: true, force: true }); } catch (ce) {} }
474
493
  callback({ ok: false, error: "Failed to prepare project directory: " + e.message });
475
494
  return;
476
495
  }
@@ -1179,7 +1198,7 @@ var relay = createServer({
1179
1198
  return config.toolPalettes || {};
1180
1199
  },
1181
1200
  onSetToolPalette: function (paletteName, order, hidden) {
1182
- if (paletteName !== "session" && paletteName !== "mate") {
1201
+ if (paletteName !== "session") {
1183
1202
  return { error: "Unknown palette" };
1184
1203
  }
1185
1204
  var safeOrder = Array.isArray(order)
@@ -1446,7 +1465,11 @@ if (config.liteAutoEnroll) {
1446
1465
  }
1447
1466
 
1448
1467
  // --- IPC server ---
1449
- // Clean up stale socket/config left by a previously killed daemon
1468
+ // Clean up stale socket/config left by a previously killed daemon. Only
1469
+ // clears config for a PID that is actually dead -- it must never assume a
1470
+ // PID mismatch alone means staleness. createIPCServer's own connect-probe
1471
+ // (below) is what actually refuses startup if a live daemon still answers
1472
+ // on the socket (lr-1bdb item A).
1450
1473
  var existingConfig = loadConfig();
1451
1474
  if (existingConfig && existingConfig.pid && existingConfig.pid !== process.pid) {
1452
1475
  if (!isPidAlive(existingConfig.pid)) {
@@ -1716,6 +1739,13 @@ var ipc = createIPCServer(socketPath(), function (msg) {
1716
1739
  default:
1717
1740
  return { ok: false, error: "unknown command: " + msg.cmd };
1718
1741
  }
1742
+ }, function onLiveDaemon() {
1743
+ // A live daemon already answers on this socket -- refuse to start rather
1744
+ // than stealing/orphaning its socket (lr-1bdb item A). Exit without
1745
+ // touching config so the running daemon is unaffected; --shutdown/
1746
+ // --restart/--add against it keep working.
1747
+ console.error("[daemon] Another clagentic-console daemon is already running. Exiting without starting a second instance.");
1748
+ process.exit(1);
1719
1749
  });
1720
1750
 
1721
1751
  // --- Start listening (with retry for port-in-use during update handoff) ---
@@ -1750,11 +1780,60 @@ function startListening() {
1750
1780
 
1751
1781
  // Start MemoryHigh watermark watcher (lr-de07).
1752
1782
  // Detects soft memory ceiling crossings and emits structured log events;
1753
- // onCrossing notifies the drain controller (lr-6b30) to enter drain state.
1783
+ // onCrossing runs an in-process shedding pass (lr-5e70) FIRST — an
1784
+ // immediate attempt to reduce RSS via retrim/evict/cache-drop — then
1785
+ // notifies the drain controller (lr-6b30), which independently decides
1786
+ // whether to refuse new connections and eventually exit. Shedding and
1787
+ // drain are deliberately independent responses to the same signal: a
1788
+ // shedding pass that fails or is rate-limited must never block drain
1789
+ // from entering, and drain entering must never skip a shedding attempt.
1754
1790
  if (process.platform === "linux") {
1755
1791
  _memoryWatcher = startMemoryHighWatcher(config, {
1756
- onCrossing: function (detail) { _drain.onMemoryHighCrossing(detail); },
1792
+ onCrossing: function (detail) {
1793
+ try {
1794
+ var shedProjects = [];
1795
+ if (relay && typeof relay.forEachProject === "function") {
1796
+ relay.forEachProject(function (ctx) {
1797
+ if (ctx && ctx.sm) shedProjects.push({ slug: ctx.slug, sm: ctx.sm, send: ctx.send });
1798
+ });
1799
+ }
1800
+ shedMemory({
1801
+ projects: shedProjects,
1802
+ caches: { skills: { drop: dropSkillsCache } },
1803
+ });
1804
+ } catch (e) {
1805
+ console.error("[daemon] Memory shedding pass failed:", e && e.message ? e.message : e);
1806
+ }
1807
+ _drain.onMemoryHighCrossing(detail);
1808
+ },
1757
1809
  });
1810
+
1811
+ // Startup sanity check (lr-c10f6d): verify the applied cgroup memory.max
1812
+ // ceiling is actually below the container's true RAM. A `%` unit-file
1813
+ // directive is resolved by systemd against the wrong MemTotal inside an
1814
+ // LXC container (only lxcfs-backed /proc/meminfo sees the true value),
1815
+ // so a stale drop-in or an un-applied postinstall can leave the ceiling
1816
+ // silently inoperative — this turns that into a visible fault.
1817
+ var ceilingCheck = checkAppliedMemoryCeiling();
1818
+ if (ceilingCheck.ok && ceilingCheck.inoperative) {
1819
+ var ceilingEvent = {
1820
+ event: "memory_ceiling_inoperative",
1821
+ timestamp: new Date().toISOString(),
1822
+ appliedMaxRaw: ceilingCheck.appliedMaxRaw,
1823
+ appliedMaxBytes: ceilingCheck.appliedMaxBytes,
1824
+ memTotalBytes: ceilingCheck.memTotalBytes,
1825
+ reason: ceilingCheck.reason,
1826
+ };
1827
+ process.stderr.write("[daemon] WARN memory_ceiling_inoperative " + JSON.stringify(ceilingEvent) + "\n");
1828
+ setTimeout(function () {
1829
+ relay.broadcastAll({
1830
+ type: "toast",
1831
+ level: "warn",
1832
+ message: "Memory ceiling exceeds container RAM — OOM protection inoperative.",
1833
+ detail: ceilingCheck.reason,
1834
+ });
1835
+ }, 3000);
1836
+ }
1758
1837
  }
1759
1838
 
1760
1839
  // Auto-provision Linux accounts on startup if OS users mode is enabled.
package/lib/dm.js CHANGED
@@ -134,7 +134,6 @@ module.exports = {
134
134
  openDm: openDm,
135
135
  sendMessage: sendMessage,
136
136
  getDmList: getDmList,
137
- loadHistory: loadHistory,
138
137
  DM_DIR: DM_DIR,
139
138
  };
140
139