@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.
- package/README.md +90 -21
- package/bin/cli.js +170 -60
- package/deploy/clagentic-console.service +2 -0
- package/lib/agents-favorites.js +3 -1
- package/lib/agents.js +75 -5
- package/lib/audit.js +23 -2
- package/lib/browser-mcp-server.js +5 -5
- package/lib/clone-validate.js +44 -0
- package/lib/config.js +175 -2
- package/lib/daemon.js +115 -9
- package/lib/dm.js +12 -1
- package/lib/ipc.js +12 -0
- package/lib/lite-detect.js +92 -0
- package/lib/os-users.js +8 -8
- package/lib/project-connection.js +7 -1
- package/lib/project-external-trigger.js +65 -6
- package/lib/project-loop.js +44 -3
- package/lib/project-sessions.js +95 -37
- package/lib/project.js +6 -1
- package/lib/public/app.js +6 -3
- package/lib/public/css/at-agents.css +68 -0
- package/lib/public/index.html +60 -0
- package/lib/public/modules/app-messages.js +38 -4
- package/lib/public/modules/at-agents.js +248 -0
- package/lib/public/modules/escape-html.js +19 -0
- package/lib/public/modules/filebrowser.js +12 -9
- package/lib/public/modules/input.js +26 -4
- package/lib/public/modules/pending-navigate.js +28 -0
- package/lib/public/modules/playbook.js +1 -1
- package/lib/public/modules/project-settings.js +75 -0
- package/lib/public/modules/project-switcher.js +1 -1
- package/lib/public/modules/server-settings.js +33 -0
- package/lib/public/modules/sticky-notes-fmt.js +52 -0
- package/lib/public/modules/sticky-notes.js +23 -5
- package/lib/public/modules/theme.js +1 -1
- package/lib/public/modules/tool-palette.js +1 -1
- package/lib/public/modules/utils.js +1 -3
- package/lib/public/style.css +1 -0
- package/lib/push.js +13 -2
- package/lib/scheduler.js +26 -2
- package/lib/sdk-bridge.js +7 -4
- package/lib/server-admin.js +1 -1
- package/lib/server-dm.js +16 -0
- package/lib/server-settings.js +42 -0
- package/lib/server-skills.js +10 -7
- package/lib/server.js +14 -3
- package/lib/sessions.js +4 -0
- package/lib/ws-schema.js +11 -1
- package/lib/yoke/adapters/claude-worker.js +2 -2
- package/lib/yoke/adapters/claude.js +47 -10
- package/lib/yoke/adapters/codex.js +14 -3
- package/lib/yoke/mcp-bridge-server.js +7 -7
- package/package.json +3 -2
- package/lib/relay-agent-claims.js +0 -480
package/lib/audit.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// audit.js — Append-only audit log for privileged actions.
|
|
2
|
-
// Writes JSON lines to ~/.clagentic/audit.log (mode 0o600).
|
|
2
|
+
// Writes JSON lines to ~/.clagentic/console/audit.log (CONFIG_DIR/audit.log, mode 0o600).
|
|
3
3
|
// Never throws into callers: all errors are logged to stderr only.
|
|
4
4
|
|
|
5
5
|
var fs = require("fs");
|
|
@@ -7,6 +7,24 @@ var path = require("path");
|
|
|
7
7
|
var config = require("./config");
|
|
8
8
|
|
|
9
9
|
var AUDIT_LOG_PATH = path.join(config.CONFIG_DIR, "audit.log");
|
|
10
|
+
var OLD_AUDIT_LOG_PATH = path.join(config.CONFIG_DIR, "..", "audit.log");
|
|
11
|
+
|
|
12
|
+
// One-time migration: copy old audit.log to new location if new is absent.
|
|
13
|
+
// Copy-not-rename so rollback still finds the old file.
|
|
14
|
+
// Only runs if CLAGENTIC_HOME is not explicitly set (default layout).
|
|
15
|
+
// Note: this runs at module load time, potentially before ensureConfigDir() creates
|
|
16
|
+
// console/ — so we ensure the parent dir exists ourselves before copying.
|
|
17
|
+
if (!process.env.CLAGENTIC_HOME && !fs.existsSync(AUDIT_LOG_PATH) && fs.existsSync(OLD_AUDIT_LOG_PATH)) {
|
|
18
|
+
try {
|
|
19
|
+
fs.mkdirSync(path.dirname(AUDIT_LOG_PATH), { recursive: true });
|
|
20
|
+
fs.copyFileSync(OLD_AUDIT_LOG_PATH, AUDIT_LOG_PATH);
|
|
21
|
+
try { fs.chmodSync(AUDIT_LOG_PATH, 0o600); } catch (_) {}
|
|
22
|
+
console.warn("[audit] Migrated audit.log to ~/.clagentic/console/audit.log");
|
|
23
|
+
} catch (e) {
|
|
24
|
+
console.error("[audit] Migration of audit.log failed (non-fatal):", e.message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
10
28
|
var _logFd = null;
|
|
11
29
|
|
|
12
30
|
function _getLogFd() {
|
|
@@ -54,4 +72,7 @@ function log(action, ctx) {
|
|
|
54
72
|
});
|
|
55
73
|
}
|
|
56
74
|
|
|
57
|
-
module.exports = {
|
|
75
|
+
module.exports = {
|
|
76
|
+
log: log,
|
|
77
|
+
auditLogPath: function () { return AUDIT_LOG_PATH; },
|
|
78
|
+
};
|
|
@@ -320,10 +320,10 @@ function getToolDefs(sendCommand, getTabList, contextOps) {
|
|
|
320
320
|
function (args) {
|
|
321
321
|
var script = "(function() {" +
|
|
322
322
|
"var el = document.querySelector(" + JSON.stringify(args.selector) + ");" +
|
|
323
|
-
"if (!el) return 'Element not found: " + args.selector
|
|
323
|
+
"if (!el) return 'Element not found: ' + " + JSON.stringify(args.selector) + ";" +
|
|
324
324
|
"el.scrollIntoView({ block: 'center', behavior: 'instant' });" +
|
|
325
325
|
"el.click();" +
|
|
326
|
-
"return 'Clicked: " + args.selector
|
|
326
|
+
"return 'Clicked: ' + " + JSON.stringify(args.selector) + ";" +
|
|
327
327
|
"})()";
|
|
328
328
|
return sendCommand("tab_evaluate", { tabId: args.tabId, script: script }).then(function (result) {
|
|
329
329
|
return { content: [{ type: "text", text: result.value || "Click executed" }] };
|
|
@@ -343,14 +343,14 @@ function getToolDefs(sendCommand, getTabList, contextOps) {
|
|
|
343
343
|
function (args) {
|
|
344
344
|
var script = "(function() {" +
|
|
345
345
|
"var el = document.querySelector(" + JSON.stringify(args.selector) + ");" +
|
|
346
|
-
"if (!el) return 'Element not found: " + args.selector
|
|
346
|
+
"if (!el) return 'Element not found: ' + " + JSON.stringify(args.selector) + ";" +
|
|
347
347
|
"el.focus();" +
|
|
348
348
|
"var nativeSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value') || Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value');" +
|
|
349
349
|
"if (nativeSetter && nativeSetter.set) { nativeSetter.set.call(el, " + JSON.stringify(args.text) + "); }" +
|
|
350
350
|
"else { el.value = " + JSON.stringify(args.text) + "; }" +
|
|
351
351
|
"el.dispatchEvent(new Event('input', { bubbles: true }));" +
|
|
352
352
|
"el.dispatchEvent(new Event('change', { bubbles: true }));" +
|
|
353
|
-
"return 'Typed into: " + args.selector
|
|
353
|
+
"return 'Typed into: ' + " + JSON.stringify(args.selector) + ";" +
|
|
354
354
|
"})()";
|
|
355
355
|
return sendCommand("tab_evaluate", { tabId: args.tabId, script: script }).then(function (result) {
|
|
356
356
|
return { content: [{ type: "text", text: result.value || "Type executed" }] };
|
|
@@ -375,7 +375,7 @@ function getToolDefs(sendCommand, getTabList, contextOps) {
|
|
|
375
375
|
"var el = document.querySelector(" + JSON.stringify(args.selector) + ");" +
|
|
376
376
|
"if (!el) return 'Element not found';" +
|
|
377
377
|
"el.scrollIntoView({ block: 'center', behavior: 'smooth' });" +
|
|
378
|
-
"return 'Scrolled to: " + args.selector
|
|
378
|
+
"return 'Scrolled to: ' + " + JSON.stringify(args.selector) + ";" +
|
|
379
379
|
"})()";
|
|
380
380
|
} else {
|
|
381
381
|
var x = args.x || 0;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// clone-validate.js — URL validation and spawn-arg hardening for git clone (lr-28b5).
|
|
2
|
+
//
|
|
3
|
+
// Extracted from daemon.js onCloneProject so this logic is directly testable.
|
|
4
|
+
// Daemon.js calls validateCloneUrl() and buildCloneArgs() rather than inlining.
|
|
5
|
+
|
|
6
|
+
var CLONE_ALLOWED_SCHEMES = ["https://", "http://", "git://", "ssh://", "git@"];
|
|
7
|
+
|
|
8
|
+
// Validate a git clone URL.
|
|
9
|
+
// Returns null on success, or an error string describing the rejection.
|
|
10
|
+
function validateCloneUrl(cloneUrl) {
|
|
11
|
+
// Reject leading-dash values: option injection vector (e.g. --upload-pack=<cmd>).
|
|
12
|
+
if (cloneUrl.startsWith("-")) {
|
|
13
|
+
return "Invalid clone URL: URL must not start with '-'";
|
|
14
|
+
}
|
|
15
|
+
// Scheme allow-list: only permit safe transports.
|
|
16
|
+
for (var i = 0; i < CLONE_ALLOWED_SCHEMES.length; i++) {
|
|
17
|
+
if (cloneUrl.startsWith(CLONE_ALLOWED_SCHEMES[i])) {
|
|
18
|
+
return null; // allowed
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return "Invalid clone URL: unsupported scheme. Allowed: https, http, git, ssh, git@";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Build the argv and env overrides for the git clone subprocess.
|
|
25
|
+
//
|
|
26
|
+
// The "--" argv terminator (argv[1]) prevents cloneUrl from being parsed as a
|
|
27
|
+
// git option even if validation is somehow bypassed.
|
|
28
|
+
//
|
|
29
|
+
// GIT_ALLOW_PROTOCOL restricts git's transport layer to safe protocols,
|
|
30
|
+
// blocking ext:: and file:: transports at the git level as a second line of
|
|
31
|
+
// defence in case future validation regressions let through a bad URL.
|
|
32
|
+
//
|
|
33
|
+
// Returns { args: string[], envOverrides: Object } — callers merge envOverrides
|
|
34
|
+
// into the spawn env.
|
|
35
|
+
function buildCloneArgs(cloneUrl, targetDir) {
|
|
36
|
+
return {
|
|
37
|
+
args: ["clone", "--", cloneUrl, targetDir],
|
|
38
|
+
envOverrides: {
|
|
39
|
+
GIT_ALLOW_PROTOCOL: "https:http:git:ssh",
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = { validateCloneUrl: validateCloneUrl, buildCloneArgs: buildCloneArgs, CLONE_ALLOWED_SCHEMES: CLONE_ALLOWED_SCHEMES };
|
package/lib/config.js
CHANGED
|
@@ -44,15 +44,53 @@ var CLAGENTIC_HOME = process.env.CLAGENTIC_HOME
|
|
|
44
44
|
var OLD_CLAY_HOME = path.join(REAL_HOME, ".clay");
|
|
45
45
|
if (!fs.existsSync(CLAGENTIC_HOME) && fs.existsSync(OLD_CLAY_HOME)) {
|
|
46
46
|
try {
|
|
47
|
-
fs.cpSync(OLD_CLAY_HOME, CLAGENTIC_HOME, { recursive: true });
|
|
47
|
+
fs.cpSync(OLD_CLAY_HOME, CLAGENTIC_HOME, { recursive: true, preserveTimestamps: true });
|
|
48
48
|
console.log("[config] Migrated " + OLD_CLAY_HOME + " → " + CLAGENTIC_HOME + " — ~/.clay/ can be deleted when verified");
|
|
49
49
|
} catch (e) {
|
|
50
50
|
console.error("[config] Migration failed:", e.message);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
// One-time migration: copy all Console data from ~/.clagentic/ root into
|
|
55
|
+
// ~/.clagentic/console/ if not yet done.
|
|
56
|
+
//
|
|
57
|
+
// Sentinel: console/.migrated marker file. Using sessions/ directory existence
|
|
58
|
+
// as the sentinel is wrong — partial earlier migrations (lr-5dca, lr-eb5a)
|
|
59
|
+
// created console/sessions/ before this full sweep ran, causing the sentinel
|
|
60
|
+
// to fire too early and leaving any sessions written after that point orphaned.
|
|
61
|
+
// A marker file written only at sweep completion is the correct pattern
|
|
62
|
+
// (same as how ~/.clay/ → ~/.clagentic/ worked: gated on destination absence).
|
|
63
|
+
//
|
|
64
|
+
// Skip-if-dest-exists for each entry so files already in console/ from
|
|
65
|
+
// earlier partial migrations are preserved.
|
|
66
|
+
var _consoleMigrated = path.join(CLAGENTIC_HOME, "console", ".migrated");
|
|
67
|
+
if (!fs.existsSync(_consoleMigrated) && fs.existsSync(CLAGENTIC_HOME)) {
|
|
68
|
+
try {
|
|
69
|
+
fs.mkdirSync(path.join(CLAGENTIC_HOME, "console"), { recursive: true });
|
|
70
|
+
// cpSync cannot copy a dir into one of its own subdirs — iterate entries
|
|
71
|
+
// individually and skip the console/ subdir itself to avoid recursion.
|
|
72
|
+
var _rootEntries = fs.readdirSync(CLAGENTIC_HOME);
|
|
73
|
+
for (var _ri = 0; _ri < _rootEntries.length; _ri++) {
|
|
74
|
+
if (_rootEntries[_ri] === "console") continue;
|
|
75
|
+
var _src = path.join(CLAGENTIC_HOME, _rootEntries[_ri]);
|
|
76
|
+
var _dst = path.join(CLAGENTIC_HOME, "console", _rootEntries[_ri]);
|
|
77
|
+
if (!fs.existsSync(_dst)) {
|
|
78
|
+
try { fs.cpSync(_src, _dst, { recursive: true, preserveTimestamps: true }); } catch (_ce) {}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Write sentinel only after the sweep completes so a crash mid-sweep
|
|
82
|
+
// causes a retry on next start rather than silently leaving data behind.
|
|
83
|
+
fs.writeFileSync(_consoleMigrated, "");
|
|
84
|
+
console.log("[config] Migrated ~/.clagentic/ → ~/.clagentic/console/ — root files can be cleaned up when verified");
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error("[config] Migration to console/ subdir failed:", e.message);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
var CONSOLE_DIR = path.join(CLAGENTIC_HOME, "console");
|
|
91
|
+
var CONFIG_DIR = CONSOLE_DIR;
|
|
55
92
|
var EXTERNAL_TRIGGERS_DIR = path.join(CONFIG_DIR, "external-triggers");
|
|
93
|
+
var OLD_EXTERNAL_TRIGGERS_DIR = path.join(CLAGENTIC_HOME, "external-triggers");
|
|
56
94
|
var OLD_CLAYRC = path.join(REAL_HOME, ".clayrc");
|
|
57
95
|
var CLAGENTIC_RC_PATH = path.join(REAL_HOME, ".clagentic-rc");
|
|
58
96
|
// One-time migration: copy .clayrc → .clagentic-rc if new file absent
|
|
@@ -60,6 +98,7 @@ if (!fs.existsSync(CLAGENTIC_RC_PATH) && fs.existsSync(OLD_CLAYRC)) {
|
|
|
60
98
|
try { fs.copyFileSync(OLD_CLAYRC, CLAGENTIC_RC_PATH); } catch (e) {}
|
|
61
99
|
}
|
|
62
100
|
var CRASH_INFO_PATH = path.join(CONFIG_DIR, "crash.json");
|
|
101
|
+
var OLD_CRASH_INFO_PATH = path.join(CLAGENTIC_HOME, "crash.json");
|
|
63
102
|
|
|
64
103
|
// Dev mode uses separate daemon files so dev and prod can run simultaneously
|
|
65
104
|
var _devMode = !!(process.env.CLAGENTIC_DEV || process.env.CLAY_DEV);
|
|
@@ -68,6 +107,11 @@ function configPath() {
|
|
|
68
107
|
return path.join(CONFIG_DIR, _devMode ? "daemon-dev.json" : "daemon.json");
|
|
69
108
|
}
|
|
70
109
|
|
|
110
|
+
// Path used before lr-12d0 moved CONFIG_DIR to console/ (was CLAGENTIC_HOME root).
|
|
111
|
+
function oldConfigPath() {
|
|
112
|
+
return path.join(CLAGENTIC_HOME, _devMode ? "daemon-dev.json" : "daemon.json");
|
|
113
|
+
}
|
|
114
|
+
|
|
71
115
|
function socketPath() {
|
|
72
116
|
if (process.platform === "win32") {
|
|
73
117
|
var pipeName = _devMode ? "clagentic-daemon-dev" : "clagentic-daemon";
|
|
@@ -76,10 +120,22 @@ function socketPath() {
|
|
|
76
120
|
return path.join(CONFIG_DIR, _devMode ? "daemon-dev.sock" : "daemon.sock");
|
|
77
121
|
}
|
|
78
122
|
|
|
123
|
+
// Path used by pre-lr-12d0 daemons (before CONFIG_DIR moved to console/).
|
|
124
|
+
// Only meaningful on Unix — Windows named pipes were unchanged.
|
|
125
|
+
function oldSocketPath() {
|
|
126
|
+
if (process.platform === "win32") return null;
|
|
127
|
+
return path.join(CLAGENTIC_HOME, _devMode ? "daemon-dev.sock" : "daemon.sock");
|
|
128
|
+
}
|
|
129
|
+
|
|
79
130
|
function logPath() {
|
|
80
131
|
return path.join(CONFIG_DIR, _devMode ? "daemon-dev.log" : "daemon.log");
|
|
81
132
|
}
|
|
82
133
|
|
|
134
|
+
// Path used by pre-lr-12d0 daemons (before CONFIG_DIR moved to console/).
|
|
135
|
+
function oldLogPath() {
|
|
136
|
+
return path.join(CLAGENTIC_HOME, _devMode ? "daemon-dev.log" : "daemon.log");
|
|
137
|
+
}
|
|
138
|
+
|
|
83
139
|
function chmodSafe(filePath, mode) {
|
|
84
140
|
if (process.platform === "win32") return;
|
|
85
141
|
try { fs.chmodSync(filePath, mode); } catch (e) {}
|
|
@@ -88,6 +144,118 @@ function chmodSafe(filePath, mode) {
|
|
|
88
144
|
function ensureConfigDir() {
|
|
89
145
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
90
146
|
chmodSafe(CONFIG_DIR, 0o700);
|
|
147
|
+
// One-time migrations: copy Console-owned runtime files to console/ subdir.
|
|
148
|
+
// Rules: copy-not-rename (rollback safety), never overwrite newer dest,
|
|
149
|
+
// non-fatal on permission errors, skip when CLAGENTIC_HOME is custom.
|
|
150
|
+
if (!process.env.CLAGENTIC_HOME) {
|
|
151
|
+
// daemon.log / daemon-dev.log
|
|
152
|
+
var oldLog = oldLogPath();
|
|
153
|
+
var newLog = logPath();
|
|
154
|
+
if (fs.existsSync(oldLog) && !fs.existsSync(newLog)) {
|
|
155
|
+
try {
|
|
156
|
+
fs.copyFileSync(oldLog, newLog);
|
|
157
|
+
console.warn("[config] Migrated " + oldLog + " → " + newLog);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
console.error("[config] Migration of daemon log failed (non-fatal):", e.message);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// crash.json
|
|
163
|
+
if (fs.existsSync(OLD_CRASH_INFO_PATH) && !fs.existsSync(CRASH_INFO_PATH)) {
|
|
164
|
+
try {
|
|
165
|
+
fs.copyFileSync(OLD_CRASH_INFO_PATH, CRASH_INFO_PATH);
|
|
166
|
+
try { fs.chmodSync(CRASH_INFO_PATH, 0o600); } catch (_) {}
|
|
167
|
+
console.warn("[config] Migrated crash.json → " + CRASH_INFO_PATH);
|
|
168
|
+
} catch (e) {
|
|
169
|
+
console.error("[config] Migration of crash.json failed (non-fatal):", e.message);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// external-triggers/
|
|
173
|
+
if (fs.existsSync(OLD_EXTERNAL_TRIGGERS_DIR) && !fs.existsSync(EXTERNAL_TRIGGERS_DIR)) {
|
|
174
|
+
try {
|
|
175
|
+
fs.cpSync(OLD_EXTERNAL_TRIGGERS_DIR, EXTERNAL_TRIGGERS_DIR, { recursive: true });
|
|
176
|
+
console.warn("[config] Migrated external-triggers/ → " + EXTERNAL_TRIGGERS_DIR);
|
|
177
|
+
} catch (e) {
|
|
178
|
+
console.error("[config] Migration of external-triggers/ failed (non-fatal):", e.message);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// daemon.json / daemon-dev.json (lr-eb5a: moved into console/)
|
|
182
|
+
var oldCfg = oldConfigPath();
|
|
183
|
+
var newCfg = configPath();
|
|
184
|
+
if (fs.existsSync(oldCfg) && !fs.existsSync(newCfg)) {
|
|
185
|
+
try {
|
|
186
|
+
fs.copyFileSync(oldCfg, newCfg);
|
|
187
|
+
try { fs.chmodSync(newCfg, 0o600); } catch (_) {}
|
|
188
|
+
console.warn("[config] Migrated " + oldCfg + " → " + newCfg);
|
|
189
|
+
} catch (e) {
|
|
190
|
+
console.error("[config] Migration of daemon.json failed (non-fatal):", e.message);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Guard stale old socket cleanup: only unlink when the old-path daemon is
|
|
196
|
+
// dead. If a live pre-1.5 daemon is still on that path we must not yank its
|
|
197
|
+
// socket out from under it — warn instead so the operator can shut it down
|
|
198
|
+
// cleanly. (lr-6ed3)
|
|
199
|
+
//
|
|
200
|
+
// checkOldDaemon() is async; we use a fire-and-forget approach here because
|
|
201
|
+
// ensureConfigDir() is sync in several call sites. The probe resolves quickly
|
|
202
|
+
// (connect or 1 s timeout) and the unlink/warn runs as a microtask.
|
|
203
|
+
if (process.platform !== "win32") {
|
|
204
|
+
var oldSock = oldSocketPath();
|
|
205
|
+
if (oldSock && fs.existsSync(oldSock)) {
|
|
206
|
+
checkOldDaemon().then(function (result) {
|
|
207
|
+
if (!result) return; // Windows guard inside checkOldDaemon()
|
|
208
|
+
if (result.alive) {
|
|
209
|
+
// A live pre-1.5 daemon is still using this socket — leave it alone.
|
|
210
|
+
console.warn("[config] Pre-1.5 daemon is still running at " + oldSock + " — socket not removed. Run clagentic-console --shutdown to stop it.");
|
|
211
|
+
} else {
|
|
212
|
+
try {
|
|
213
|
+
fs.unlinkSync(oldSock);
|
|
214
|
+
console.warn("[config] Removed stale pre-1.5 socket at " + oldSock + " (moved to " + socketPath() + ")");
|
|
215
|
+
} catch (e) {
|
|
216
|
+
console.warn("[config] Could not remove stale socket at " + oldSock + ": " + e.message);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Check whether a pre-1.5 daemon is still live on the old socket path.
|
|
226
|
+
*
|
|
227
|
+
* Returns a Promise resolving to:
|
|
228
|
+
* { alive: true, sockPath: <oldSocketPath> } — live old daemon listening
|
|
229
|
+
* { alive: false, sockPath: <oldSocketPath> } — old socket file absent or dead
|
|
230
|
+
* null — Windows (old path unchanged, skip)
|
|
231
|
+
*
|
|
232
|
+
* Caller is responsible for acting on the result (shutdown + wait, or unlink).
|
|
233
|
+
*/
|
|
234
|
+
function checkOldDaemon() {
|
|
235
|
+
if (process.platform === "win32") return Promise.resolve(null);
|
|
236
|
+
var oldSock = oldSocketPath();
|
|
237
|
+
if (!oldSock) return Promise.resolve(null);
|
|
238
|
+
|
|
239
|
+
return new Promise(function (resolve) {
|
|
240
|
+
if (!fs.existsSync(oldSock)) return resolve({ alive: false, sockPath: oldSock });
|
|
241
|
+
|
|
242
|
+
var client = net.connect(oldSock);
|
|
243
|
+
var timer = setTimeout(function () {
|
|
244
|
+
client.destroy();
|
|
245
|
+
resolve({ alive: false, sockPath: oldSock });
|
|
246
|
+
}, 1000);
|
|
247
|
+
|
|
248
|
+
client.on("connect", function () {
|
|
249
|
+
clearTimeout(timer);
|
|
250
|
+
client.destroy();
|
|
251
|
+
resolve({ alive: true, sockPath: oldSock });
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
client.on("error", function () {
|
|
255
|
+
clearTimeout(timer);
|
|
256
|
+
resolve({ alive: false, sockPath: oldSock });
|
|
257
|
+
});
|
|
258
|
+
});
|
|
91
259
|
}
|
|
92
260
|
|
|
93
261
|
function loadConfig() {
|
|
@@ -304,16 +472,21 @@ function removeFromClayrc(projectPath) {
|
|
|
304
472
|
|
|
305
473
|
module.exports = {
|
|
306
474
|
CONFIG_DIR: CONFIG_DIR,
|
|
475
|
+
CLAGENTIC_HOME: CLAGENTIC_HOME,
|
|
307
476
|
EXTERNAL_TRIGGERS_DIR: EXTERNAL_TRIGGERS_DIR,
|
|
308
477
|
configPath: configPath,
|
|
478
|
+
oldConfigPath: oldConfigPath,
|
|
309
479
|
socketPath: socketPath,
|
|
480
|
+
oldSocketPath: oldSocketPath,
|
|
310
481
|
logPath: logPath,
|
|
482
|
+
oldLogPath: oldLogPath,
|
|
311
483
|
ensureConfigDir: ensureConfigDir,
|
|
312
484
|
loadConfig: loadConfig,
|
|
313
485
|
saveConfig: saveConfig,
|
|
314
486
|
isPidAlive: isPidAlive,
|
|
315
487
|
isDaemonAlive: isDaemonAlive,
|
|
316
488
|
isDaemonAliveAsync: isDaemonAliveAsync,
|
|
489
|
+
checkOldDaemon: checkOldDaemon,
|
|
317
490
|
generateSlug: generateSlug,
|
|
318
491
|
clearStaleConfig: clearStaleConfig,
|
|
319
492
|
crashInfoPath: crashInfoPath,
|
package/lib/daemon.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// --- Node version check ---
|
|
4
4
|
var nodeMajor = parseInt(process.versions.node.split(".")[0], 10);
|
|
5
5
|
if (nodeMajor < 20) {
|
|
6
|
-
console.error("\x1b[31m[
|
|
7
|
-
console.error("[
|
|
6
|
+
console.error("\x1b[31m[clagentic-console] Node.js 20+ is required (current: " + process.version + ")\x1b[0m");
|
|
7
|
+
console.error("[clagentic-console] The Claude Agent SDK 0.2.40+ requires Node 20 for Symbol.dispose support.");
|
|
8
8
|
console.error("");
|
|
9
9
|
console.error(" Upgrade Node: nvm install 22 && nvm use 22");
|
|
10
10
|
process.exit(78); // EX_CONFIG — fatal config error, don't auto-restart
|
|
@@ -23,24 +23,61 @@ delete process.env.CLAUDECODE;
|
|
|
23
23
|
|
|
24
24
|
var fs = require("fs");
|
|
25
25
|
var path = require("path");
|
|
26
|
-
var { loadConfig, saveConfig, socketPath, generateSlug, syncClayrc, removeFromClayrc, writeCrashInfo, readCrashInfo, clearCrashInfo, isPidAlive, clearStaleConfig, REAL_HOME } = require("./config");
|
|
26
|
+
var { loadConfig, saveConfig, socketPath, ensureConfigDir, generateSlug, syncClayrc, removeFromClayrc, writeCrashInfo, readCrashInfo, clearCrashInfo, isPidAlive, clearStaleConfig, REAL_HOME } = require("./config");
|
|
27
27
|
var { createIPCServer } = require("./ipc");
|
|
28
28
|
var { createServer, generateAuthToken } = require("./server");
|
|
29
29
|
var { checkAclSupport, grantProjectAccess, revokeProjectAccess, provisionAllUsers, provisionLinuxUser, grantAllUsersAccess, deactivateLinuxUser, ensureProjectsDir } = require("./os-users");
|
|
30
30
|
var usersModule = require("./users");
|
|
31
31
|
var { createWorktree, removeWorktree, isWorktree } = require("./worktree");
|
|
32
32
|
var { isWorktreeSlug, scanAndRegisterWorktrees, rescanWorktrees, cleanupWorktreesForParent, getFilteredRemovedProjects, registerWorktreeSlug, unregisterWorktreeSlug } = require("./daemon-projects");
|
|
33
|
+
var { validateCloneUrl, buildCloneArgs } = require("./clone-validate");
|
|
33
34
|
var { DEFAULT_MEM_AVAILABLE_MIN_MB } = require("./sdk-bridge");
|
|
35
|
+
var liteDetect = require("./lite-detect");
|
|
36
|
+
var { execFile: liteExecFile } = require("child_process");
|
|
34
37
|
|
|
35
38
|
var daemonVersion = require("../package.json").version;
|
|
36
39
|
var configFile = process.env.CLAGENTIC_CONFIG || process.env.CLAY_CONFIG || require("./config").configPath();
|
|
37
40
|
var config;
|
|
38
41
|
|
|
42
|
+
// Ensure dirs exist before any file access — daemon must be self-sufficient when
|
|
43
|
+
// launched directly by systemd/supervisor with no prior CLI run.
|
|
44
|
+
ensureConfigDir();
|
|
45
|
+
|
|
39
46
|
try {
|
|
40
47
|
config = JSON.parse(fs.readFileSync(configFile, "utf8"));
|
|
41
48
|
} catch (e) {
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
if (e.code === "ENOENT") {
|
|
50
|
+
// Guard: if CLAGENTIC_HOME was erroneously set to the socket subdirectory
|
|
51
|
+
// (e.g. ~/.clagentic/console instead of ~/.clagentic), a real daemon.json
|
|
52
|
+
// will exist one level above CLAGENTIC_HOME. Detect this and refuse to
|
|
53
|
+
// bootstrap an empty config — that would silently discard all projects.
|
|
54
|
+
var { CLAGENTIC_HOME: _cgHome } = require("./config");
|
|
55
|
+
var _siblingConfig = path.join(path.dirname(_cgHome), "daemon.json");
|
|
56
|
+
try {
|
|
57
|
+
var _sibling = JSON.parse(fs.readFileSync(_siblingConfig, "utf8"));
|
|
58
|
+
if (_sibling && Array.isArray(_sibling.projects) && _sibling.projects.length > 0) {
|
|
59
|
+
console.error("[daemon] ERROR: CLAGENTIC_HOME appears to point at the console/ socket subdirectory (" + _cgHome + ").");
|
|
60
|
+
console.error("[daemon] A populated daemon.json with " + _sibling.projects.length + " project(s) exists at " + _siblingConfig + ".");
|
|
61
|
+
console.error("[daemon] Set CLAGENTIC_HOME to the parent directory (" + path.dirname(_cgHome) + ") to use the correct config.");
|
|
62
|
+
process.exit(78); // EX_CONFIG — do not auto-restart
|
|
63
|
+
}
|
|
64
|
+
} catch (_e) { /* sibling check is best-effort; fall through to normal bootstrap */ }
|
|
65
|
+
|
|
66
|
+
// No config file yet (fresh install, systemd-only start). Bootstrap minimal defaults.
|
|
67
|
+
console.warn("[daemon] No config file found at " + configFile + " — bootstrapping defaults. Run clagentic-console to configure projects.");
|
|
68
|
+
var _isDev = !!(process.env.CLAGENTIC_DEV || process.env.CLAY_DEV);
|
|
69
|
+
config = { port: _isDev ? 2635 : 2633, projects: [], mode: "single", setupCompleted: false };
|
|
70
|
+
// Persist so subsequent reads succeed.
|
|
71
|
+
try {
|
|
72
|
+
fs.writeFileSync(configFile, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
73
|
+
} catch (writeErr) {
|
|
74
|
+
console.error("[daemon] Failed to persist bootstrap config:", writeErr.message);
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
console.error("[daemon] Failed to read config:", e.message);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
44
81
|
}
|
|
45
82
|
console.log("[daemon] v" + daemonVersion + " PID " + process.pid + " config " + configFile);
|
|
46
83
|
|
|
@@ -175,6 +212,19 @@ var relay = createServer({
|
|
|
175
212
|
}
|
|
176
213
|
// Discover and register worktrees for the new project
|
|
177
214
|
scanAndRegisterWorktrees(relay, absPath, slug, null, wsUser && wsUser.id && wsUser.role !== "admin" ? wsUser.id : null);
|
|
215
|
+
// Auto-enroll in Clagentic: Lite if enabled and Lite is installed
|
|
216
|
+
if (config.liteAutoEnroll) {
|
|
217
|
+
var liteStatus = liteDetect.detectLite();
|
|
218
|
+
if (liteStatus.installed && !liteDetect.isProjectEnrolled(absPath)) {
|
|
219
|
+
liteExecFile("clagentic-lite", ["enroll", absPath], { timeout: 30000 }, function (err) {
|
|
220
|
+
if (err) {
|
|
221
|
+
console.warn("[daemon] Lite auto-enroll failed for " + absPath + ":", err.message);
|
|
222
|
+
} else {
|
|
223
|
+
console.log("[daemon] Lite auto-enrolled project:", absPath);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
178
228
|
// Broadcast updated project list to all clients
|
|
179
229
|
relay.broadcastAll({
|
|
180
230
|
type: "projects_updated",
|
|
@@ -260,6 +310,19 @@ var relay = createServer({
|
|
|
260
310
|
} else if (config.osUsers) {
|
|
261
311
|
console.log("[daemon] Skipping ACL grant: osUsers=true but linuxUser=", wsUser && wsUser.linuxUser);
|
|
262
312
|
}
|
|
313
|
+
// Auto-enroll in Clagentic: Lite if enabled and Lite is installed
|
|
314
|
+
if (config.liteAutoEnroll) {
|
|
315
|
+
var liteStatus = liteDetect.detectLite();
|
|
316
|
+
if (liteStatus.installed && !liteDetect.isProjectEnrolled(targetDir)) {
|
|
317
|
+
liteExecFile("clagentic-lite", ["enroll", targetDir], { timeout: 30000 }, function (err) {
|
|
318
|
+
if (err) {
|
|
319
|
+
console.warn("[daemon] Lite auto-enroll failed for " + targetDir + ":", err.message);
|
|
320
|
+
} else {
|
|
321
|
+
console.log("[daemon] Lite auto-enrolled project:", targetDir);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}
|
|
263
326
|
relay.broadcastAll({
|
|
264
327
|
type: "projects_updated",
|
|
265
328
|
projects: relay.getProjects(),
|
|
@@ -324,7 +387,18 @@ var relay = createServer({
|
|
|
324
387
|
return;
|
|
325
388
|
}
|
|
326
389
|
}
|
|
327
|
-
|
|
390
|
+
// Security: validate cloneUrl before passing to git spawn (lr-28b5).
|
|
391
|
+
// validateCloneUrl rejects leading-dash (option injection) and non-allow-listed schemes.
|
|
392
|
+
// buildCloneArgs adds the "--" argv terminator and GIT_ALLOW_PROTOCOL env restriction
|
|
393
|
+
// as defence-in-depth even if future validation regressions let a bad URL through.
|
|
394
|
+
var urlErr = validateCloneUrl(cloneUrl);
|
|
395
|
+
if (urlErr) {
|
|
396
|
+
callback({ ok: false, error: urlErr });
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
var cloneArgSpec = buildCloneArgs(cloneUrl, targetDir);
|
|
400
|
+
spawnOpts.env = Object.assign({}, spawnOpts.env || process.env, cloneArgSpec.envOverrides);
|
|
401
|
+
var proc = spawn("git", cloneArgSpec.args, spawnOpts);
|
|
328
402
|
var stderrBuf = "";
|
|
329
403
|
proc.stderr.on("data", function (chunk) { stderrBuf += chunk.toString(); });
|
|
330
404
|
// 5 minute timeout
|
|
@@ -847,8 +921,16 @@ var relay = createServer({
|
|
|
847
921
|
updateChannel: config.updateChannel || "stable",
|
|
848
922
|
imageRetentionDays: config.imageRetentionDays !== undefined ? config.imageRetentionDays : 7,
|
|
849
923
|
memAvailableMinMB: config.memAvailableMinMB !== undefined ? config.memAvailableMinMB : DEFAULT_MEM_AVAILABLE_MIN_MB,
|
|
924
|
+
liteAutoEnroll: !!config.liteAutoEnroll,
|
|
850
925
|
};
|
|
851
926
|
},
|
|
927
|
+
onSetLiteAutoEnroll: function (value) {
|
|
928
|
+
var want = !!value;
|
|
929
|
+
config.liteAutoEnroll = want;
|
|
930
|
+
saveConfig(config);
|
|
931
|
+
console.log("[daemon] Lite auto-enroll:", want, "(web)");
|
|
932
|
+
return { ok: true, liteAutoEnroll: want };
|
|
933
|
+
},
|
|
852
934
|
onSetImageRetention: function (days) {
|
|
853
935
|
var d = parseInt(days, 10);
|
|
854
936
|
if (isNaN(d) || d < 0) d = 7;
|
|
@@ -969,7 +1051,7 @@ var relay = createServer({
|
|
|
969
1051
|
if (config.osUsers) {
|
|
970
1052
|
var projectPath = config.projects[i].path;
|
|
971
1053
|
var ownerId = config.projects[i].ownerId || null;
|
|
972
|
-
// When switching to public: grant ACL to ALL
|
|
1054
|
+
// When switching to public: grant ACL to ALL users
|
|
973
1055
|
if (visibility === "public" && prevVisibility !== "public") {
|
|
974
1056
|
grantAllUsersAccess(projectPath, usersModule);
|
|
975
1057
|
}
|
|
@@ -1051,7 +1133,7 @@ var relay = createServer({
|
|
|
1051
1133
|
}
|
|
1052
1134
|
},
|
|
1053
1135
|
onUserDeleted: function (userId, linuxUser) {
|
|
1054
|
-
// Deactivate the Linux account when a
|
|
1136
|
+
// Deactivate the Linux account when a user is deleted
|
|
1055
1137
|
if (!config.osUsers || !linuxUser) return;
|
|
1056
1138
|
deactivateLinuxUser(linuxUser);
|
|
1057
1139
|
},
|
|
@@ -1141,6 +1223,29 @@ for (var i = 0; i < projects.length; i++) {
|
|
|
1141
1223
|
// Sync ~/.clayrc on startup
|
|
1142
1224
|
try { syncClayrc(config.projects); } catch (e) {}
|
|
1143
1225
|
|
|
1226
|
+
// Auto-enroll in Clagentic: Lite at startup if liteAutoEnroll is enabled
|
|
1227
|
+
if (config.liteAutoEnroll) {
|
|
1228
|
+
(function () {
|
|
1229
|
+
var liteStatus = liteDetect.detectLite();
|
|
1230
|
+
if (!liteStatus.installed) return;
|
|
1231
|
+
var registeredProjects = config.projects || [];
|
|
1232
|
+
for (var li = 0; li < registeredProjects.length; li++) {
|
|
1233
|
+
var lp = registeredProjects[li];
|
|
1234
|
+
if (lp.path && !liteDetect.isProjectEnrolled(lp.path)) {
|
|
1235
|
+
(function (projectPath) {
|
|
1236
|
+
liteExecFile("clagentic-lite", ["enroll", projectPath], { timeout: 30000 }, function (err) {
|
|
1237
|
+
if (err) {
|
|
1238
|
+
console.warn("[daemon] Lite startup auto-enroll failed for " + projectPath + ":", err.message);
|
|
1239
|
+
} else {
|
|
1240
|
+
console.log("[daemon] Lite startup auto-enrolled:", projectPath);
|
|
1241
|
+
}
|
|
1242
|
+
});
|
|
1243
|
+
})(lp.path);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
})();
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1144
1249
|
// --- IPC server ---
|
|
1145
1250
|
// Clean up stale socket/config left by a previously killed daemon
|
|
1146
1251
|
var existingConfig = loadConfig();
|
|
@@ -1522,7 +1627,7 @@ function spawnAndRestart() {
|
|
|
1522
1627
|
relay.server.close(function () {
|
|
1523
1628
|
try {
|
|
1524
1629
|
var { spawn: spawnRestart } = require("child_process");
|
|
1525
|
-
var { logPath: restartLogPath, configPath: restartConfigPath } = require("./config");
|
|
1630
|
+
var { logPath: restartLogPath, configPath: restartConfigPath, CLAGENTIC_HOME: restartClagenticHome } = require("./config");
|
|
1526
1631
|
var daemonScript = path.join(__dirname, "daemon.js");
|
|
1527
1632
|
var logFd = fs.openSync(restartLogPath(), "a");
|
|
1528
1633
|
var child = spawnRestart(process.execPath, [daemonScript], {
|
|
@@ -1531,6 +1636,7 @@ function spawnAndRestart() {
|
|
|
1531
1636
|
stdio: ["ignore", logFd, logFd],
|
|
1532
1637
|
env: Object.assign({}, process.env, {
|
|
1533
1638
|
CLAGENTIC_CONFIG: restartConfigPath(),
|
|
1639
|
+
CLAGENTIC_HOME: restartClagenticHome,
|
|
1534
1640
|
}),
|
|
1535
1641
|
});
|
|
1536
1642
|
child.unref();
|
package/lib/dm.js
CHANGED
|
@@ -18,7 +18,17 @@ function dmKey(userId1, userId2) {
|
|
|
18
18
|
// File path for a DM conversation
|
|
19
19
|
function dmFilePath(key) {
|
|
20
20
|
// Replace : with _ for safe filename
|
|
21
|
-
|
|
21
|
+
var resolved = path.join(DM_DIR, key.replace(/:/g, "_") + ".jsonl");
|
|
22
|
+
// Defense-in-depth: assert the resolved path stays within DM_DIR.
|
|
23
|
+
// path.resolve is used to canonicalize both sides before comparison so that
|
|
24
|
+
// any surviving .. segments (e.g. from a malformed key that slipped through
|
|
25
|
+
// caller-side validation) cannot escape the directory.
|
|
26
|
+
var dmDirResolved = path.resolve(DM_DIR);
|
|
27
|
+
if (!path.resolve(resolved).startsWith(dmDirResolved + path.sep) &&
|
|
28
|
+
path.resolve(resolved) !== dmDirResolved) {
|
|
29
|
+
throw new Error("dm: path traversal detected for key: " + key);
|
|
30
|
+
}
|
|
31
|
+
return resolved;
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
// Load DM history from JSONL file
|
|
@@ -120,6 +130,7 @@ function getDmList(userId) {
|
|
|
120
130
|
|
|
121
131
|
module.exports = {
|
|
122
132
|
dmKey: dmKey,
|
|
133
|
+
dmFilePath: dmFilePath,
|
|
123
134
|
openDm: openDm,
|
|
124
135
|
sendMessage: sendMessage,
|
|
125
136
|
getDmList: getDmList,
|
package/lib/ipc.js
CHANGED
|
@@ -6,6 +6,12 @@ var fs = require("fs");
|
|
|
6
6
|
* handler(msg) should return a response object (or a Promise of one).
|
|
7
7
|
*/
|
|
8
8
|
function createIPCServer(sockPath, handler) {
|
|
9
|
+
// Ensure the socket's parent directory exists (e.g. ~/.clagentic/console/).
|
|
10
|
+
// The daemon may start without a prior CLI invocation, so it must be self-sufficient.
|
|
11
|
+
if (process.platform !== "win32") {
|
|
12
|
+
try { fs.mkdirSync(require("path").dirname(sockPath), { recursive: true }); } catch (e) {}
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
// Remove stale socket file (not needed for Windows named pipes)
|
|
10
16
|
if (process.platform !== "win32") {
|
|
11
17
|
try { fs.unlinkSync(sockPath); } catch (e) {}
|
|
@@ -53,6 +59,12 @@ function createIPCServer(sockPath, handler) {
|
|
|
53
59
|
console.log("[ipc] Socket in use, removing stale socket and retrying...");
|
|
54
60
|
try { fs.unlinkSync(sockPath); } catch (e) {}
|
|
55
61
|
server.listen(sockPath);
|
|
62
|
+
} else if (err.code === "ENOENT" && !retried) {
|
|
63
|
+
// Parent directory missing — create it and retry once.
|
|
64
|
+
retried = true;
|
|
65
|
+
console.log("[ipc] Socket directory missing, creating and retrying...");
|
|
66
|
+
try { fs.mkdirSync(require("path").dirname(sockPath), { recursive: true }); } catch (e) {}
|
|
67
|
+
server.listen(sockPath);
|
|
56
68
|
} else {
|
|
57
69
|
console.error("[ipc] Failed to bind socket:", err.message);
|
|
58
70
|
process.exit(1);
|