@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
@@ -0,0 +1,92 @@
1
+ // lite-detect.js — Passive detection of Clagentic: Lite installation.
2
+ //
3
+ // All functions are synchronous and safe to call at any time.
4
+ // If Lite is not installed, every function returns a falsy / "not enrolled" result
5
+ // with no error thrown and no log output.
6
+
7
+ var fs = require("fs");
8
+ var path = require("path");
9
+ var { execFileSync } = require("child_process");
10
+ var { CONFIG_DIR, REAL_HOME } = require("./config");
11
+
12
+ // Lite home: <CONFIG_DIR>/lite/ — mirrors the path contract established in lr-dc6c.
13
+ // CONFIG_DIR is the canonical clagentic data directory (resolves CLAGENTIC_HOME,
14
+ // sudo users, and legacy ~/.clay/ migration the same way as every other daemon path).
15
+ function getLiteHome() {
16
+ return path.join(CONFIG_DIR, "lite");
17
+ }
18
+
19
+ // Return true when the Lite home directory exists.
20
+ function liteHomeDirExists() {
21
+ try {
22
+ return fs.existsSync(getLiteHome());
23
+ } catch (e) {
24
+ return false;
25
+ }
26
+ }
27
+
28
+ // Candidate paths for the clagentic-lite binary (checked in order).
29
+ // PATH resolution is attempted first via `which`, then common user-local paths.
30
+ var LITE_BINARY_NAME = "clagentic-lite";
31
+ var LITE_CANDIDATE_PATHS = [
32
+ path.join(REAL_HOME, ".local", "bin", LITE_BINARY_NAME),
33
+ path.join(REAL_HOME, "bin", LITE_BINARY_NAME),
34
+ ];
35
+
36
+ function binaryExists() {
37
+ // 1. Try PATH resolution
38
+ try {
39
+ execFileSync("which", [LITE_BINARY_NAME], { stdio: "ignore", timeout: 2000 });
40
+ return true;
41
+ } catch (e) { /* not on PATH */ }
42
+
43
+ // 2. Check common user-local locations
44
+ for (var i = 0; i < LITE_CANDIDATE_PATHS.length; i++) {
45
+ try {
46
+ if (fs.existsSync(LITE_CANDIDATE_PATHS[i])) return true;
47
+ } catch (e) { /* keep checking */ }
48
+ }
49
+ return false;
50
+ }
51
+
52
+ /**
53
+ * Detect whether Clagentic: Lite is installed.
54
+ *
55
+ * Returns:
56
+ * { installed: true, liteHome: "/home/user/.clagentic/lite" }
57
+ * { installed: false, liteHome: null }
58
+ *
59
+ * Detection is passive — no subprocess is spawned for the main check.
60
+ * `which` is used only as a PATH lookup fallback and its failure is silently swallowed.
61
+ */
62
+ function detectLite() {
63
+ var homeExists = liteHomeDirExists();
64
+ var binExists = binaryExists();
65
+ if (homeExists && binExists) {
66
+ return { installed: true, liteHome: getLiteHome() };
67
+ }
68
+ return { installed: false, liteHome: null };
69
+ }
70
+
71
+ /**
72
+ * Check per-project enrollment status.
73
+ *
74
+ * Returns true if <projectDir>/.clagentic/lite/audit.db exists.
75
+ */
76
+ function isProjectEnrolled(projectDir) {
77
+ if (!projectDir) return false;
78
+ try {
79
+ return fs.existsSync(path.join(projectDir, ".clagentic", "lite", "audit.db"));
80
+ } catch (e) {
81
+ return false;
82
+ }
83
+ }
84
+
85
+ module.exports = {
86
+ detectLite: detectLite,
87
+ isProjectEnrolled: isProjectEnrolled,
88
+ getLiteHome: getLiteHome,
89
+ // Exported for testing
90
+ liteHomeDirExists: liteHomeDirExists,
91
+ binaryExists: binaryExists,
92
+ };
package/lib/os-users.js CHANGED
@@ -268,7 +268,7 @@ function revokeProjectAccess(projectPath, linuxUser) {
268
268
  }
269
269
 
270
270
  /**
271
- * Sanitize a Clay username into a valid Linux username.
271
+ * Sanitize a Clagentic: Console username into a valid Linux username.
272
272
  * Prefixes with "clay-", lowercases, replaces invalid chars with hyphens.
273
273
  * Linux usernames: start with [a-z_], then [a-z0-9_-], max 32 chars.
274
274
  */
@@ -384,7 +384,7 @@ function installClaudeCli(linuxName) {
384
384
  }
385
385
 
386
386
  /**
387
- * Provision a Linux user account for a Clay user.
387
+ * Provision a Linux user account for a Clagentic: Console user.
388
388
  * Creates the account via useradd with a home directory.
389
389
  * Returns { ok: true, linuxUser: "clay-xxx" } or { error: "..." }.
390
390
  */
@@ -393,7 +393,7 @@ function provisionLinuxUser(clayUsername) {
393
393
 
394
394
  // Handle name collisions by appending a number
395
395
  if (linuxUserExists(linuxName)) {
396
- // Check if this is a clay-managed user (reuse it)
396
+ // Check if this is a managed Linux user (reuse it)
397
397
  // Otherwise find an available name
398
398
  console.log("[os-users] Linux user " + linuxName + " already exists, reusing.");
399
399
  return { ok: true, linuxUser: linuxName };
@@ -406,11 +406,11 @@ function provisionLinuxUser(clayUsername) {
406
406
  stdio: "pipe",
407
407
  });
408
408
  ensureLinger(linuxName);
409
- console.log("[os-users] Provisioned Linux user: " + linuxName + " (Clay user: " + clayUsername + ")");
409
+ console.log("[os-users] Provisioned Linux user: " + linuxName + " (username: " + clayUsername + ")");
410
410
  installClaudeCli(linuxName);
411
411
  audit.log("osuser.create", {
412
412
  actorId: "system",
413
- metadata: { clayUsername: clayUsername, linuxUser: linuxName },
413
+ metadata: { username: clayUsername, linuxUser: linuxName },
414
414
  });
415
415
  return { ok: true, linuxUser: linuxName };
416
416
  } catch (e) {
@@ -421,7 +421,7 @@ function provisionLinuxUser(clayUsername) {
421
421
  }
422
422
 
423
423
  /**
424
- * Provision Linux accounts for all Clay users that don't have one yet.
424
+ * Provision Linux accounts for all users that don't have one yet.
425
425
  * usersModule: the users.js module (getAllUsers, updateLinuxUser, etc.)
426
426
  * Returns { provisioned: [...], skipped: [...], errors: [...] }.
427
427
  */
@@ -451,7 +451,7 @@ function provisionAllUsers(usersModule) {
451
451
 
452
452
  var provision = provisionLinuxUser(user.username);
453
453
  if (provision.ok) {
454
- // Update the Clay user record with the Linux username
454
+ // Update the user record with the Linux username
455
455
  var data = usersModule.loadUsers();
456
456
  for (var j = 0; j < data.users.length; j++) {
457
457
  if (data.users[j].id === user.id) {
@@ -470,7 +470,7 @@ function provisionAllUsers(usersModule) {
470
470
  }
471
471
 
472
472
  /**
473
- * Grant ACL access on a project directory to ALL Clay users with linuxUser mappings.
473
+ * Grant ACL access on a project directory to ALL users with linuxUser mappings.
474
474
  * Used when a project becomes public.
475
475
  * usersModule: the users.js module (getAllUsers, etc.)
476
476
  */
@@ -3,6 +3,9 @@ var path = require("path");
3
3
  var usersModule = require("./users");
4
4
  var userPresence = require("./user-presence");
5
5
  var { getCodexConfig } = require("./codex-defaults");
6
+ // detectLite is cached per-project in project.js and passed via ctx.liteStatus.
7
+ // This import is retained only for backward compat if ctx.liteStatus is absent.
8
+ var { detectLite } = require("./lite-detect");
6
9
 
7
10
  /**
8
11
  * Attach connection/disconnection handlers to a project context.
@@ -129,7 +132,10 @@ function attachConnection(ctx) {
129
132
  var restoredActive = restoredState.active;
130
133
  var initialVendor = (restoredActive && restoredActive.vendor) || sm.defaultVendor || "claude";
131
134
  var initialModels = (sm.modelsByVendor && sm.modelsByVendor[initialVendor]) || sm.availableModels || [];
132
- var infoMsg = { type: "info", cwd: cwd, slug: slug, project: title || project, version: currentVersion, debug: !!debug, dangerouslySkipPermissions: dangerouslySkipPermissions, osUsers: osUsers, lanHost: lanHost, projectCount: _filteredProjects.length, projects: _filteredProjects, projectOwnerId: projectOwnerId, ownerLocked: ownerLocked };
135
+ // Use the liteStatus cached at project-context creation time (project.js) to
136
+ // avoid a synchronous execFileSync("which",...) on every WS connect.
137
+ var _liteStatus = ctx.liteStatus || detectLite();
138
+ var infoMsg = { type: "info", cwd: cwd, slug: slug, project: title || project, version: currentVersion, debug: !!debug, dangerouslySkipPermissions: dangerouslySkipPermissions, osUsers: osUsers, lanHost: lanHost, projectCount: _filteredProjects.length, projects: _filteredProjects, projectOwnerId: projectOwnerId, ownerLocked: ownerLocked, liteInstalled: _liteStatus.installed, liteHome: _liteStatus.liteHome };
133
139
  // When dangerouslySkipPermissions is set in config but suppressed because
134
140
  // multi-user mode is active, tell the client so it can surface a warning.
135
141
  if (dangerouslySkipPermissionsConfigured && !dangerouslySkipPermissions) {
@@ -9,11 +9,20 @@ var PROCESSED_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000; // 30 days
9
9
  *
10
10
  * Watches ~/.clagentic/external-triggers/ for JSON files dropped by external
11
11
  * processes (scripts, daemons, agents). When a valid trigger file appears,
12
- * opens a new session in the named project with initialPrompt as the first
13
- * user-turn. The file is moved to processed/ on success.
12
+ * either opens a new session (v1 / v2 without sessionId) or injects a message
13
+ * into an existing session (v2 with sessionId). The file is moved to
14
+ * processed/ on success.
14
15
  *
15
16
  * Schema v1 (all fields except * are required):
16
17
  * { version: 1, id, projectSlug, initialPrompt, contextNote*, cwd*, createdAt* }
18
+ * -> always spawns a new session (backward-compatible, v1 files remain valid)
19
+ *
20
+ * Schema v2 (all fields except * are required):
21
+ * { version: 2, id, projectSlug, initialPrompt, contextNote*, cwd*, createdAt*, sessionId* }
22
+ * -> if sessionId present: pushMessage to the named session (mid-session inject)
23
+ * -> if sessionId absent: spawnSession (same as v1)
24
+ * On push_message path, if sessionId is not found the trigger is NOT archived
25
+ * so daemon-down recovery can retry when the session reconnects.
17
26
  *
18
27
  * ctx fields:
19
28
  * triggersDir — absolute path to ~/.clagentic/external-triggers/
@@ -49,10 +58,14 @@ function attachExternalTrigger(ctx) {
49
58
 
50
59
  function validateTrigger(obj) {
51
60
  if (!obj || typeof obj !== "object") return "not an object";
52
- if (obj.version !== 1) return "unsupported version: " + obj.version;
61
+ if (obj.version !== 1 && obj.version !== 2) return "unsupported version: " + obj.version;
53
62
  if (!obj.id || typeof obj.id !== "string") return "missing id";
54
63
  if (!obj.projectSlug || typeof obj.projectSlug !== "string") return "missing projectSlug";
55
64
  if (!obj.initialPrompt || typeof obj.initialPrompt !== "string") return "missing initialPrompt";
65
+ // sessionId is optional; if present it must be a non-empty string
66
+ if (obj.sessionId !== undefined && (typeof obj.sessionId !== "string" || !obj.sessionId)) {
67
+ return "sessionId must be a non-empty string when present";
68
+ }
56
69
  return null; // valid
57
70
  }
58
71
 
@@ -99,6 +112,39 @@ function attachExternalTrigger(ctx) {
99
112
  return true;
100
113
  }
101
114
 
115
+ // --- Mid-session inject ---
116
+
117
+ function pushMessageToSession(project, trigger) {
118
+ var sm = project.sm;
119
+ var sdk = project.sdk;
120
+
121
+ if (!sm || !sdk) {
122
+ console.error("[external-trigger] Project context missing sm/sdk for push_message, slug:", trigger.projectSlug);
123
+ return "error";
124
+ }
125
+
126
+ var found = null;
127
+ sm.sessions.forEach(function (s) {
128
+ if (!found && s.cliSessionId === trigger.sessionId) {
129
+ found = s;
130
+ }
131
+ });
132
+
133
+ if (!found) {
134
+ console.warn("[external-trigger] push_message: session not found: " + trigger.sessionId + " (trigger " + trigger.id + " not archived — will retry)");
135
+ return "not_found";
136
+ }
137
+
138
+ try {
139
+ sdk.pushMessage(found, trigger.initialPrompt, null);
140
+ console.log("[external-trigger] push_message delivered to session " + trigger.sessionId + " (trigger " + trigger.id + ")");
141
+ return "ok";
142
+ } catch (e) {
143
+ console.error("[external-trigger] push_message failed for trigger " + trigger.id + ":", e.message || e);
144
+ return "error";
145
+ }
146
+ }
147
+
102
148
  // --- Archive ---
103
149
 
104
150
  function archiveTrigger(triggerPath, id) {
@@ -149,9 +195,22 @@ function attachExternalTrigger(ctx) {
149
195
  return;
150
196
  }
151
197
 
152
- var ok = spawnSession(project, obj);
153
- if (ok) {
154
- archiveTrigger(filePath, id);
198
+ if (obj.sessionId) {
199
+ // v2 mid-session inject path
200
+ var result = pushMessageToSession(project, obj);
201
+ if (result === "ok") {
202
+ archiveTrigger(filePath, id);
203
+ } else if (result === "not_found") {
204
+ // Do not archive — allow daemon-down / timing retry.
205
+ // Clear dispatched so the watcher can re-process if the file is still present.
206
+ delete dispatched[id];
207
+ }
208
+ // "error" case: leave dispatched[id] set to avoid a rapid retry loop.
209
+ } else {
210
+ var ok = spawnSession(project, obj);
211
+ if (ok) {
212
+ archiveTrigger(filePath, id);
213
+ }
155
214
  }
156
215
  }
157
216
 
@@ -6,6 +6,20 @@ var { createLoopRegistry } = require("./scheduler");
6
6
  var store = require("./store");
7
7
  var usersModule = require("./users");
8
8
 
9
+ var LOOP_ID_RE = /^loop_[A-Za-z0-9_-]+$/;
10
+
11
+ /**
12
+ * Validate a loop ID before using it as a path component.
13
+ *
14
+ * Returns true if the id passes the allowlist regex.
15
+ * Returns false for any value that could enable path traversal or injection.
16
+ * All handlers that build a loop directory path from a user-supplied value
17
+ * must route through this function before any path.join / path.resolve call.
18
+ */
19
+ function validateLoopId(id) {
20
+ return LOOP_ID_RE.test(id || "");
21
+ }
22
+
9
23
  /**
10
24
  * Attach loop engine to a project context.
11
25
  *
@@ -284,6 +298,13 @@ function attachLoop(ctx) {
284
298
  console.log("[loop-registry] Schedule triggered: " + record.name + " -> linked task " + loopFilesId);
285
299
  }
286
300
 
301
+ // Validate the loop ID before using it as a path component (path traversal guard).
302
+ // linkedTaskId flows from client-supplied sData.taskId via schedule_create.
303
+ if (!validateLoopId(loopFilesId)) {
304
+ console.error("[loop-registry] Invalid loop ID rejected: " + loopFilesId);
305
+ return;
306
+ }
307
+
287
308
  // Verify the loop directory and PROMPT.md exist
288
309
  var recDir = path.join(cwd, ".claude", "loops", loopFilesId);
289
310
  try {
@@ -1010,7 +1031,17 @@ function attachLoop(ctx) {
1010
1031
 
1011
1032
  if (msg.type === "loop_registry_files") {
1012
1033
  var recId = msg.id;
1013
- var lDir = path.join(cwd, ".claude", "loops", recId);
1034
+ // Validate ID before using it as a path component (path traversal guard).
1035
+ if (!validateLoopId(recId)) {
1036
+ send({ type: "loop_registry_error", text: "invalid_loop_id" });
1037
+ return true;
1038
+ }
1039
+ var loopBase = path.resolve(cwd, ".claude", "loops");
1040
+ var lDir = path.resolve(loopBase, recId);
1041
+ if (!lDir.startsWith(loopBase + path.sep)) {
1042
+ send({ type: "loop_registry_error", text: "invalid_loop_id" });
1043
+ return true;
1044
+ }
1014
1045
  var promptContent = "";
1015
1046
  var judgeContent = "";
1016
1047
  var loopSettings = null;
@@ -1032,7 +1063,17 @@ function attachLoop(ctx) {
1032
1063
 
1033
1064
  if (msg.type === "loop_registry_save_files") {
1034
1065
  var recId2 = msg.id;
1035
- var lDir2 = path.join(cwd, ".claude", "loops", recId2);
1066
+ // Validate ID before using it as a path component (path traversal guard).
1067
+ if (!validateLoopId(recId2)) {
1068
+ send({ type: "loop_registry_error", text: "invalid_loop_id" });
1069
+ return true;
1070
+ }
1071
+ var loopBase2 = path.resolve(cwd, ".claude", "loops");
1072
+ var lDir2 = path.resolve(loopBase2, recId2);
1073
+ if (!lDir2.startsWith(loopBase2 + path.sep)) {
1074
+ send({ type: "loop_registry_error", text: "invalid_loop_id" });
1075
+ return true;
1076
+ }
1036
1077
  try {
1037
1078
  fs.mkdirSync(lDir2, { recursive: true });
1038
1079
  if (msg.prompt !== undefined) {
@@ -1348,4 +1389,4 @@ function attachLoop(ctx) {
1348
1389
  };
1349
1390
  }
1350
1391
 
1351
- module.exports = { attachLoop: attachLoop };
1392
+ module.exports = { attachLoop: attachLoop, validateLoopId: validateLoopId };
@@ -1,12 +1,11 @@
1
1
  var fs = require("fs");
2
2
  var path = require("path");
3
- var { execFileSync } = require("child_process");
3
+ var { execFileSync, execFile } = require("child_process");
4
4
  var { CODEX_DEFAULTS, getCodexConfig } = require("./codex-defaults");
5
+ var liteDetect = require("./lite-detect");
5
6
  var { readMemAvailableMB } = require("./sdk-bridge");
6
7
  var agentsModule = require("./agents");
7
8
  var agentsFavorites = require("./agents-favorites");
8
- var relayClaims = require("./relay-agent-claims");
9
-
10
9
  // Kick off SDK agent discovery in the background at module load.
11
10
  // Errors are swallowed inside refresh(); the cache starts empty and fills
12
11
  // when the SDK subprocess completes initialization (~9s on this box).
@@ -161,15 +160,6 @@ function attachSessions(ctx) {
161
160
  if (usersModule.isMultiUser()) {
162
161
  broadcastPresence();
163
162
  }
164
- // Wire relay live-claim for named-agent sessions (lr-9cfc).
165
- // Fire-and-forget; degrades silently when relay is absent.
166
- if (newSess.agentName) {
167
- (function (sessLocalId, agentName) {
168
- relayClaims.attachAgentSession(newSess, agentName, function (obj) {
169
- sendToSession(sessLocalId, obj);
170
- });
171
- })(newSess.localId, newSess.agentName);
172
- }
173
163
  return true;
174
164
  }
175
165
 
@@ -194,6 +184,17 @@ function attachSessions(ctx) {
194
184
  return true;
195
185
  }
196
186
 
187
+ // lr-c1a2 — get_agents returns agents installed in the project's
188
+ // .claude/agents/ directory (not the SDK global catalog). Used by the
189
+ // @ mention dropdown in the session input to offer project-local agents.
190
+ if (msg.type === "get_agents") {
191
+ var projectAgents = [];
192
+ try { projectAgents = agentsModule.readProjectAgents(cwd); }
193
+ catch (e) { console.error("[project-sessions] get_agents failed:", e && e.message ? e.message : e); }
194
+ sendTo(ws, { type: "project_agents_list", agents: projectAgents });
195
+ return true;
196
+ }
197
+
197
198
  // toggle_agent_favorite flips an agent's membership in chattable.json.
198
199
  // Required field: name.
199
200
  if (msg.type === "toggle_agent_favorite") {
@@ -236,24 +237,17 @@ function attachSessions(ctx) {
236
237
  try { agentsFavorites.touchRecent({ name: nextAgent }); }
237
238
  catch (e) { /* best-effort */ }
238
239
  }
239
- // Relay live-claim lifecycle for agent changes (lr-9cfc).
240
- // Release old claims; attach for new agent if set.
241
- if (prevAgent) {
242
- relayClaims.detachAgentSession(agentTarget.localId);
243
- }
244
- if (nextAgent) {
245
- (function (sessLocalId, agentName) {
246
- relayClaims.attachAgentSession(agentTarget, agentName, function (obj) {
247
- sendToSession(sessLocalId, obj);
248
- });
249
- })(agentTarget.localId, nextAgent);
250
- }
251
240
  sm.broadcastSessionList();
252
241
  return true;
253
242
  }
254
243
 
255
244
  if (msg.type === "set_session_visibility") {
256
245
  if (typeof msg.sessionId === "number" && (msg.visibility === "shared" || msg.visibility === "private")) {
246
+ var visTarget = sm.sessions.get(msg.sessionId);
247
+ if (!visTarget) return true;
248
+ if (usersModule.isMultiUser() && ws._clayUser) {
249
+ if (!usersModule.canAccessSession(ws._clayUser.id, visTarget, { visibility: "public" })) return true;
250
+ }
257
251
  sm.setSessionVisibility(msg.sessionId, msg.visibility);
258
252
  }
259
253
  return true;
@@ -299,13 +293,6 @@ function attachSessions(ctx) {
299
293
  deletableIds.push(bulkId);
300
294
  }
301
295
  if (deletableIds.length > 0) {
302
- // Release relay claims for any agent sessions in the bulk-delete set (lr-9cfc).
303
- for (var ri = 0; ri < deletableIds.length; ri++) {
304
- var relayBulkSess = sm.sessions.get(deletableIds[ri]);
305
- if (relayBulkSess && relayBulkSess.agentName) {
306
- relayClaims.detachAgentSession(deletableIds[ri]);
307
- }
308
- }
309
296
  sm.deleteSessionsBulk(deletableIds, ws);
310
297
  }
311
298
  return true;
@@ -497,11 +484,6 @@ function attachSessions(ctx) {
497
484
  }
498
485
  }
499
486
  if (msg.id && sm.sessions.has(msg.id)) {
500
- // Release relay claims for agent sessions before deletion (lr-9cfc).
501
- var sdSess = sm.sessions.get(msg.id);
502
- if (sdSess && sdSess.agentName) {
503
- relayClaims.detachAgentSession(msg.id);
504
- }
505
487
  sm.deleteSession(msg.id, ws);
506
488
  }
507
489
  return true;
@@ -611,12 +593,23 @@ function attachSessions(ctx) {
611
593
 
612
594
  if (msg.type === "stop_task") {
613
595
  if (msg.taskId) {
614
- sdk.stopTask(msg.taskId);
596
+ // Pass the requester's session so stopTask aborts the correct session
597
+ // rather than the globally-active one (lr-e0de). Single-session installs
598
+ // are unaffected: getSessionForWs returns the same session as
599
+ // sm.getActiveSession() when only one session exists.
600
+ var stopSession = getSessionForWs(ws);
601
+ sdk.stopTask(msg.taskId, stopSession);
615
602
  }
616
603
  return true;
617
604
  }
618
605
 
619
606
  if (msg.type === "kill_process") {
607
+ // Restrict to admins in multi-user mode — any user could otherwise SIGTERM
608
+ // another user's running claude subprocess (lr-eb1a).
609
+ if (usersModule.isMultiUser() && (!ws._clayUser || ws._clayUser.role !== "admin")) {
610
+ sendTo(ws, { type: "error", message: "Admin access required" });
611
+ return true;
612
+ }
620
613
  var pid = msg.pid;
621
614
  if (!pid || typeof pid !== "number") return true;
622
615
  // Verify target is actually a claude process before killing
@@ -1435,6 +1428,13 @@ function attachSessions(ctx) {
1435
1428
 
1436
1429
  // --- Move a single schedule to another project ---
1437
1430
  if (msg.type === "schedule_move") {
1431
+ if (ws._clayUser) {
1432
+ var schMovePerms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
1433
+ if (!schMovePerms.scheduledTasks) {
1434
+ sendTo(ws, { type: "error", text: "Scheduled tasks access is not permitted" });
1435
+ return true;
1436
+ }
1437
+ }
1438
1438
  var moveResult = moveScheduleToProject(msg.recordId, msg.fromSlug, msg.toSlug);
1439
1439
  if (moveResult.ok) {
1440
1440
  // Re-broadcast updated records to this project's clients
@@ -1555,6 +1555,7 @@ function attachSessions(ctx) {
1555
1555
  // --- Daemon config / server management (admin-only in multi-user mode) ---
1556
1556
  if (msg.type === "get_daemon_config" || msg.type === "set_pin" || msg.type === "set_keep_awake" ||
1557
1557
  msg.type === "set_auto_continue" || msg.type === "set_image_retention" || msg.type === "set_mem_available_threshold" ||
1558
+ msg.type === "set_lite_auto_enroll" ||
1558
1559
  msg.type === "shutdown_server" || msg.type === "restart_server") {
1559
1560
  if (usersModule.isMultiUser()) {
1560
1561
  var _wsUser = ws._clayUser;
@@ -1607,6 +1608,18 @@ function attachSessions(ctx) {
1607
1608
  return true;
1608
1609
  }
1609
1610
 
1611
+ if (msg.type === "set_lite_auto_enroll") {
1612
+ if (typeof opts.onSetLiteAutoEnroll === "function") {
1613
+ var laeResult = opts.onSetLiteAutoEnroll(msg.value);
1614
+ // set_lite_auto_enroll_result is intentionally not consumed by the client:
1615
+ // the daemon_config_changed broadcast below carries the updated liteAutoEnroll
1616
+ // flag and is the authoritative sync path for all connected clients.
1617
+ sendTo(ws, { type: "set_lite_auto_enroll_result", ok: laeResult.ok, liteAutoEnroll: laeResult.liteAutoEnroll });
1618
+ send({ type: "daemon_config_changed", liteAutoEnroll: laeResult.liteAutoEnroll });
1619
+ }
1620
+ return true;
1621
+ }
1622
+
1610
1623
  if (msg.type === "set_mem_available_threshold") {
1611
1624
  if (typeof opts.onSetMemAvailableThreshold === "function") {
1612
1625
  var matResult = opts.onSetMemAvailableThreshold(msg.value);
@@ -1644,6 +1657,51 @@ function attachSessions(ctx) {
1644
1657
  return true;
1645
1658
  }
1646
1659
 
1660
+ // --- Clagentic: Lite integration WS messages ---
1661
+
1662
+ // get_lite_project_status — responds with lite_project_status { enrolled: bool }
1663
+ if (msg.type === "get_lite_project_status") {
1664
+ var liteEnrolled = liteDetect.isProjectEnrolled(cwd);
1665
+ sendTo(ws, { type: "lite_project_status", enrolled: liteEnrolled });
1666
+ return true;
1667
+ }
1668
+
1669
+ // lite_enroll_project — shells out to `clagentic-lite enroll <projectDir>`
1670
+ if (msg.type === "lite_enroll_project") {
1671
+ execFile("clagentic-lite", ["enroll", cwd], { timeout: 30000 }, function (err, stdout, stderr) {
1672
+ if (err) {
1673
+ sendTo(ws, {
1674
+ type: "lite_enroll_result",
1675
+ ok: false,
1676
+ error: (stderr && stderr.trim()) || (err.message || "enroll failed"),
1677
+ });
1678
+ } else {
1679
+ sendTo(ws, { type: "lite_enroll_result", ok: true });
1680
+ // Refresh enrollment status after successful enroll
1681
+ sendTo(ws, { type: "lite_project_status", enrolled: liteDetect.isProjectEnrolled(cwd) });
1682
+ }
1683
+ });
1684
+ return true;
1685
+ }
1686
+
1687
+ // lite_unenroll_project — shells out to `clagentic-lite unenroll <projectDir>`
1688
+ if (msg.type === "lite_unenroll_project") {
1689
+ execFile("clagentic-lite", ["unenroll", cwd], { timeout: 30000 }, function (err, stdout, stderr) {
1690
+ if (err) {
1691
+ sendTo(ws, {
1692
+ type: "lite_unenroll_result",
1693
+ ok: false,
1694
+ error: (stderr && stderr.trim()) || (err.message || "unenroll failed"),
1695
+ });
1696
+ } else {
1697
+ sendTo(ws, { type: "lite_unenroll_result", ok: true });
1698
+ // Refresh enrollment status after successful unenroll
1699
+ sendTo(ws, { type: "lite_project_status", enrolled: liteDetect.isProjectEnrolled(cwd) });
1700
+ }
1701
+ });
1702
+ return true;
1703
+ }
1704
+
1647
1705
  return false;
1648
1706
  }
1649
1707
 
package/lib/project.js CHANGED
@@ -24,6 +24,7 @@ var { attachFilesystem } = require("./project-filesystem");
24
24
  var { attachSessions } = require("./project-sessions");
25
25
  var { attachUserMessage } = require("./project-user-message");
26
26
  var { attachConnection } = require("./project-connection");
27
+ var { detectLite } = require("./lite-detect");
27
28
  var { attachMcp } = require("./project-mcp");
28
29
  var { createLocalMcp } = require("./mcp-local");
29
30
  // project-notifications is attached globally in server.js, passed via opts.notificationsModule
@@ -182,6 +183,9 @@ function createProjectContext(opts) {
182
183
  var latestVersion = null;
183
184
  var sessionTitleMigrationScheduled = false;
184
185
 
186
+ // --- Lite detection (cached once per project context, not per WS connect) ---
187
+ var _liteStatus = detectLite();
188
+
185
189
  // --- YOKE adapters (multi-vendor, lazy init) ---
186
190
  var _yokeState = yoke.createAdapters({ cwd: cwd, slug: slug });
187
191
  var adapters = _yokeState.adapters;
@@ -642,7 +646,7 @@ function createProjectContext(opts) {
642
646
  });
643
647
  var nm = createNotesManager({ cwd: cwd, send: send, sendTo: sendTo });
644
648
 
645
- // Update checks disabled — this is a fork, not a chadbyte/clay release track.
649
+ // Update checks disabled — this is a fork; updates are managed via clagentic-console releases.
646
650
  function runVersionCheck() { /* no-op */ }
647
651
  function scheduleNextHourlyBroadcast() { /* no-op */ }
648
652
 
@@ -1127,6 +1131,7 @@ function createProjectContext(opts) {
1127
1131
  var _connection = attachConnection({
1128
1132
  cwd: cwd,
1129
1133
  slug: slug,
1134
+ liteStatus: _liteStatus,
1130
1135
  osUsers: osUsers,
1131
1136
  debug: debug,
1132
1137
  dangerouslySkipPermissions: dangerouslySkipPermissions,
package/lib/public/app.js CHANGED
@@ -20,14 +20,15 @@ import { initRewind, setRewindMode, showRewindModal, clearPendingRewindUuid, add
20
20
  import { initNotifications, showDoneNotification, playDoneSound, isNotifAlertEnabled, isNotifSoundEnabled } from './modules/notifications.js';
21
21
  import { initInput, clearPendingImages, handleInputSync, autoResize, builtinCommands, sendMessage, hasSendableContent, setScheduleBtnDisabled, setScheduleDelayMs, clearScheduleDelay } from './modules/input.js';
22
22
  import { initQrCode, triggerShare } from './modules/qrcode.js';
23
- import { initFileBrowser, loadRootDirectory, refreshTree, handleFsList, handleFsRead, handleDirChanged, refreshIfOpen, handleFileChanged, handleFileHistory, handleGitDiff, handleFileAt, getPendingNavigate, closeFileViewer, resetFileBrowser } from './modules/filebrowser.js';
23
+ import { initFileBrowser, loadRootDirectory, refreshTree, handleFsList, handleFsRead, handleDirChanged, refreshIfOpen, handleFileChanged, handleFileHistory, handleGitDiff, handleFileAt, closeFileViewer, resetFileBrowser } from './modules/filebrowser.js';
24
+ import { getPendingNavigate } from './modules/pending-navigate.js';
24
25
  import { initTerminal, openTerminal, closeTerminal, resetTerminals, handleTermList, handleTermCreated, handleTermOutput, handleTermResized, handleTermExited, handleTermClosed, sendTerminalCommand } from './modules/terminal.js';
25
26
  import { initContextSources, updateTerminalList, updateBrowserTabList, handleContextSourcesState, getActiveSources, hasActiveSources } from './modules/context-sources.js';
26
27
  import { initStickyNotes, handleNotesList, handleNoteCreated, handleNoteUpdated, handleNoteDeleted, openArchive, closeArchive, isArchiveOpen, hideNotes, showNotes, isNotesVisible, createNote } from './modules/sticky-notes.js';
27
28
  import { initTheme, getThemeColor, getComputedVar, onThemeChange, getCurrentTheme, getChatLayout } from './modules/theme.js';
28
29
  import { initTools, resetToolState, saveToolState, restoreToolState, renderAskUserQuestion, markAskUserAnswered, renderPermissionRequest, markPermissionResolved, markPermissionCancelled, renderElicitationRequest, markElicitationResolved, renderPlanBanner, renderPlanCard, handleTodoWrite, handleTaskCreate, handleTaskUpdate, startThinking, appendThinking, stopThinking, resetThinkingGroup, createToolItem, updateToolExecuting, updateToolResult, markAllToolsDone, addTurnMeta, resetTurnMetaCost, enableMainInput, getTools, getPlanContent, setPlanContent, isPlanFilePath, getTodoTools, updateSubagentActivity, addSubagentToolEntry, markSubagentDone, updateSubagentProgress, initSubagentStop, closeToolGroup, removeToolFromGroup } from './modules/tools.js';
29
- import { initServerSettings, updateSettingsStats, updateSettingsModels, updateDaemonConfig, handleSetPinResult, handleKeepAwakeChanged, handleAutoContinueChanged, handleRestartResult, handleShutdownResult, handleSharedEnv, handleSharedEnvSaved, handleGlobalClaudeMdRead, handleGlobalClaudeMdWrite, isSettingsOpen, closeSettings } from './modules/server-settings.js';
30
- import { initProjectSettings, handleInstructionsRead, handleInstructionsWrite, handleProjectEnv, handleProjectEnvSaved, isProjectSettingsOpen, closeProjectSettings, handleProjectSharedEnv, handleProjectSharedEnvSaved, handleProjectOwnerChanged } from './modules/project-settings.js';
30
+ import { initServerSettings, updateSettingsStats, updateSettingsModels, updateDaemonConfig, handleSetPinResult, handleKeepAwakeChanged, handleAutoContinueChanged, handleRestartResult, handleShutdownResult, handleSharedEnv, handleSharedEnvSaved, handleGlobalClaudeMdRead, handleGlobalClaudeMdWrite, isSettingsOpen, closeSettings, updateSsLiteVisibility, initSsLiteToggle } from './modules/server-settings.js';
31
+ import { initProjectSettings, handleInstructionsRead, handleInstructionsWrite, handleProjectEnv, handleProjectEnvSaved, isProjectSettingsOpen, closeProjectSettings, handleProjectSharedEnv, handleProjectSharedEnvSaved, handleProjectOwnerChanged, updateLiteVisibility, initLiteButtons, handleLiteProjectStatus, handleLiteEnrollResult, handleLiteUnenrollResult } from './modules/project-settings.js';
31
32
  import { initSkills, handleSkillInstalled, handleSkillUninstalled } from './modules/skills.js';
32
33
  import { initMcp } from './modules/mcp-ui.js';
33
34
  import { initScheduler, resetScheduler, handleLoopRegistryUpdated, handleScheduleRunStarted, handleScheduleRunFinished, handleLoopScheduled, openSchedulerToTab, isSchedulerOpen, closeScheduler, enterCraftingMode, exitCraftingMode, handleLoopRegistryFiles, getUpcomingSchedules } from './modules/scheduler.js';
@@ -825,6 +826,7 @@ import { initMention, handleMentionStart, handleMentionStream, handleMentionDone
825
826
  setContextView: function (v) { _panSetContextView(v); },
826
827
  applyContextView: function (v) { _panApplyContextView(v); },
827
828
  });
829
+ initSsLiteToggle();
828
830
 
829
831
  // --- Project Settings ---
830
832
  initProjectSettings({
@@ -838,6 +840,7 @@ import { initMention, handleMentionStart, handleMentionStream, handleMentionDone
838
840
  get currentThinking() { return store.get('currentThinking'); },
839
841
  get currentThinkingBudget() { return store.get('currentThinkingBudget'); },
840
842
  });
843
+ initLiteButtons();
841
844
 
842
845
  // --- QR code ---
843
846
  initQrCode();