@clagentic/console 1.9.0-beta.1 → 1.9.0-beta.3
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/bin/cli.js +23 -1
- package/lib/agents.js +13 -3
- package/lib/build-sha.json +2 -2
- package/lib/cli/ipc-subcommands.js +84 -4
- package/lib/daemon.js +111 -7
- package/lib/effective-protocol.js +82 -0
- package/lib/project-connection.js +21 -8
- package/lib/project-filesystem.js +4 -4
- package/lib/project-http.js +4 -4
- package/lib/project-loop.js +49 -5
- package/lib/project-sessions.js +166 -68
- package/lib/project-user-mention.js +7 -7
- package/lib/project-user-message.js +81 -14
- package/lib/project.js +28 -22
- package/lib/public/app.js +18 -4
- package/lib/public/css/base.css +14 -0
- package/lib/public/css/filebrowser.css +6 -0
- package/lib/public/css/home-hub.css +28 -8
- package/lib/public/css/icon-strip.css +17 -0
- package/lib/public/css/messages.css +11 -0
- package/lib/public/css/mobile-nav.css +22 -0
- package/lib/public/css/server-settings.css +9 -0
- package/lib/public/css/sidebar.css +15 -0
- package/lib/public/css/title-bar.css +10 -1
- package/lib/public/index.html +9 -2
- package/lib/public/modules/activity-latch.js +45 -0
- package/lib/public/modules/activity-state.js +195 -0
- package/lib/public/modules/app-connection.js +31 -6
- package/lib/public/modules/app-favicon.js +75 -1
- package/lib/public/modules/app-home-hub.js +14 -11
- package/lib/public/modules/app-loop-ui.js +86 -2
- package/lib/public/modules/app-messages.js +178 -54
- package/lib/public/modules/app-panels.js +91 -32
- package/lib/public/modules/app-projects.js +46 -9
- package/lib/public/modules/app-rate-limit.js +13 -1
- package/lib/public/modules/server-settings.js +256 -21
- package/lib/public/modules/sidebar-mobile.js +32 -22
- package/lib/public/modules/sidebar-projects.js +42 -14
- package/lib/public/modules/sidebar-sessions.js +168 -48
- package/lib/public/modules/theme.js +2 -2
- package/lib/public/modules/tools.js +11 -39
- package/lib/sdk-bridge.js +375 -33
- package/lib/sdk-message-processor.js +98 -15
- package/lib/sdk-skill-discovery.js +46 -6
- package/lib/sdk-slash-enrichment.js +5 -2
- package/lib/server-dm.js +5 -5
- package/lib/server-hub-sessions.js +70 -0
- package/lib/server.js +78 -43
- package/lib/session-activity.js +9 -2
- package/lib/sessions.js +64 -18
- package/lib/smtp.js +10 -1
- package/lib/terminal-manager.js +6 -6
- package/lib/ws-schema.js +16 -0
- package/lib/yoke/adapters/claude.js +7 -1
- package/lib/yoke/adapters/codex.js +219 -31
- package/package.json +2 -2
- package/scripts/check-test-count.js +397 -0
- package/scripts/test-file-completion-reporter.js +43 -0
- package/scripts/verify-installed-build.js +242 -15
- package/lib/model-context-windows.js +0 -74
- package/lib/public/modules/model-context-windows.js +0 -71
package/bin/cli.js
CHANGED
|
@@ -33,7 +33,7 @@ var { forkDaemon, devMode, setDaemonWatcherOpts } = require("../lib/cli/daemon-l
|
|
|
33
33
|
var { setup, promptRestoreProjects, showMainMenu } = require("../lib/cli/menus");
|
|
34
34
|
var { getLocalIP } = require("../lib/cli/net-detect");
|
|
35
35
|
var { log, a, sym } = require("../lib/cli/tui");
|
|
36
|
-
var { handleShutdown, handleRestart, handleAdd, handleRemove, handleList } = require("../lib/cli/ipc-subcommands");
|
|
36
|
+
var { handleShutdown, handleRestart, handleAdd, handleRemove, handleList, handleActivityDiagnostics, handleProcessBuildStatus } = require("../lib/cli/ipc-subcommands");
|
|
37
37
|
|
|
38
38
|
var args = process.argv.slice(2);
|
|
39
39
|
|
|
@@ -69,6 +69,8 @@ var noRestart = false;
|
|
|
69
69
|
var addPath = null;
|
|
70
70
|
var removePath = null;
|
|
71
71
|
var listMode = false;
|
|
72
|
+
var activityDiagnosticsMode = false;
|
|
73
|
+
var processBuildStatusMode = false;
|
|
72
74
|
var dangerouslySkipPermissions = false;
|
|
73
75
|
var headlessMode = false;
|
|
74
76
|
var watchMode = false;
|
|
@@ -118,6 +120,10 @@ for (var i = 0; i < args.length; i++) {
|
|
|
118
120
|
i++;
|
|
119
121
|
} else if (args[i] === "--list") {
|
|
120
122
|
listMode = true;
|
|
123
|
+
} else if (args[i] === "--activity-diagnostics") {
|
|
124
|
+
activityDiagnosticsMode = true;
|
|
125
|
+
} else if (args[i] === "--process-build-status") {
|
|
126
|
+
processBuildStatusMode = true;
|
|
121
127
|
} else if (args[i] === "--headless") {
|
|
122
128
|
headlessMode = true;
|
|
123
129
|
autoYes = true;
|
|
@@ -132,6 +138,8 @@ for (var i = 0; i < args.length; i++) {
|
|
|
132
138
|
console.log(" clagentic-console --add <path> Add a project to the running daemon");
|
|
133
139
|
console.log(" clagentic-console --remove <path> Remove a project from the running daemon");
|
|
134
140
|
console.log(" clagentic-console --list List registered projects");
|
|
141
|
+
console.log(" clagentic-console --activity-diagnostics Print activity-divergence probe totals as JSON (agent-readable)");
|
|
142
|
+
console.log(" clagentic-console --process-build-status Print the running process's loaded build SHA as JSON (agent-readable)");
|
|
135
143
|
console.log(" clagentic-console release list-betas List promotable beta versions (maintainer/release-engineering)");
|
|
136
144
|
console.log("");
|
|
137
145
|
console.log("Options:");
|
|
@@ -149,6 +157,8 @@ for (var i = 0; i < args.length; i++) {
|
|
|
149
157
|
console.log(" --add <path> Add a project directory (use '.' for current)");
|
|
150
158
|
console.log(" --remove <path> Remove a project directory");
|
|
151
159
|
console.log(" --list List all registered projects");
|
|
160
|
+
console.log(" --activity-diagnostics Print activity-divergence probe totals as JSON");
|
|
161
|
+
console.log(" --process-build-status Print the running process's loaded build SHA as JSON");
|
|
152
162
|
console.log(" --headless Start daemon and exit immediately (implies --yes)");
|
|
153
163
|
console.log(" --multi-user Start in multi-user mode (use with --yes for headless)");
|
|
154
164
|
console.log(" --os-users Enable OS-level user isolation (Linux, requires root + --multi-user)");
|
|
@@ -194,6 +204,18 @@ if (listMode) {
|
|
|
194
204
|
return;
|
|
195
205
|
}
|
|
196
206
|
|
|
207
|
+
// --- Handle --activity-diagnostics before anything else ---
|
|
208
|
+
if (activityDiagnosticsMode) {
|
|
209
|
+
handleActivityDiagnostics();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// --- Handle --process-build-status before anything else ---
|
|
214
|
+
if (processBuildStatusMode) {
|
|
215
|
+
handleProcessBuildStatus();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
197
219
|
// --multi-user / --os-users are now handled in the main entry flow (setup wizard or repeat run)
|
|
198
220
|
// Flags are parsed above and applied during forkDaemon()
|
|
199
221
|
|
package/lib/agents.js
CHANGED
|
@@ -83,6 +83,12 @@ function slugifyAgentName(name) {
|
|
|
83
83
|
// enforcement in the query setup path.
|
|
84
84
|
//
|
|
85
85
|
// agentName: the agent identity string (e.g. "agentic-director").
|
|
86
|
+
// globalAgentsDir: optional override of AGENTS_SOURCE_DIR. On a shared
|
|
87
|
+
// multi-user daemon, callers resolve the SESSION OWNER's home
|
|
88
|
+
// (os-users.getLinuxUserHome(linuxUser)) and pass
|
|
89
|
+
// path.join(thatHome, ".claude", "agents") here so the on-disk agent
|
|
90
|
+
// definition is read from the invoking user's own home, not the daemon
|
|
91
|
+
// process's REAL_HOME (lr-3ccc78 twin of the skill-discovery fix).
|
|
86
92
|
// Returns: string[] of tool names if the tools field is a valid JSON array,
|
|
87
93
|
// null if the file is absent, the frontmatter is missing, or the
|
|
88
94
|
// tools field cannot be parsed.
|
|
@@ -90,11 +96,12 @@ function slugifyAgentName(name) {
|
|
|
90
96
|
// Failures are silent (logged at debug level) — callers treat null as "no
|
|
91
97
|
// restriction from this source" and fall through to whatever the SDK applies
|
|
92
98
|
// via claudeOpts.agent.
|
|
93
|
-
function readAgentToolsFromFile(agentName) {
|
|
99
|
+
function readAgentToolsFromFile(agentName, globalAgentsDir) {
|
|
94
100
|
if (!agentName || typeof agentName !== "string") return null;
|
|
95
101
|
var slug = slugifyAgentName(agentName);
|
|
96
102
|
if (!slug) return null;
|
|
97
|
-
var
|
|
103
|
+
var baseDir = (typeof globalAgentsDir === "string" && globalAgentsDir) ? globalAgentsDir : AGENTS_SOURCE_DIR;
|
|
104
|
+
var filePath = path.join(baseDir, slug + ".md");
|
|
98
105
|
var raw;
|
|
99
106
|
try {
|
|
100
107
|
raw = fs.readFileSync(filePath, "utf8");
|
|
@@ -256,7 +263,10 @@ function _readAgentsFromDir(agentsDir) {
|
|
|
256
263
|
return results;
|
|
257
264
|
}
|
|
258
265
|
|
|
259
|
-
// _globalAgentsDir is an optional override
|
|
266
|
+
// _globalAgentsDir is an optional override of the global agents directory.
|
|
267
|
+
// Tests use it to point at a fixture dir; production callers on a shared
|
|
268
|
+
// multi-user daemon pass the session owner's own ~/.claude/agents (see
|
|
269
|
+
// readAgentToolsFromFile above, lr-3ccc78).
|
|
260
270
|
function readProjectAgents(projectDir, _globalAgentsDir) {
|
|
261
271
|
if (!projectDir || typeof projectDir !== "string") return [];
|
|
262
272
|
|
package/lib/build-sha.json
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
// lib/cli/ipc-subcommands.js
|
|
2
2
|
//
|
|
3
3
|
// One-shot IPC subcommand handlers for bin/cli.js: --shutdown, --restart,
|
|
4
|
-
// --add <path>, --remove <path>, --list. Each of
|
|
5
|
-
// daemon over the Unix socket and exits the
|
|
6
|
-
// return control to the caller) —
|
|
7
|
-
//
|
|
4
|
+
// --add <path>, --remove <path>, --list, --activity-diagnostics. Each of
|
|
5
|
+
// these talks to the running daemon over the Unix socket and exits the
|
|
6
|
+
// process directly (they never return control to the caller) —
|
|
7
|
+
// --shutdown/--restart/--add/--remove/--list extracted verbatim from
|
|
8
|
+
// bin/cli.js (lr-4e49 Part 1), no behavior change.
|
|
9
|
+
// --activity-diagnostics added by lr-8b476f: the only agent-readable
|
|
10
|
+
// (Bash+Read, no browser/WS/devtools) retrieval path for the lr-58c813
|
|
11
|
+
// server-side activity-divergence probe. Prints raw JSON to stdout so a
|
|
12
|
+
// read-only crew agent can run this directly.
|
|
13
|
+
// --process-build-status added by lr-dc9a3b: reports the build SHA the
|
|
14
|
+
// RUNNING daemon actually loaded at startup (distinct from the on-disk
|
|
15
|
+
// artifact's build-sha.json), so scripts/verify-installed-build.js can gate
|
|
16
|
+
// on process build identity, not just artifact build identity.
|
|
8
17
|
|
|
9
18
|
var fs = require("fs");
|
|
10
19
|
var path = require("path");
|
|
@@ -177,10 +186,81 @@ function handleList() {
|
|
|
177
186
|
});
|
|
178
187
|
}
|
|
179
188
|
|
|
189
|
+
// lr-dc9a3b: prints the running process's build-identity status (same data
|
|
190
|
+
// lib/daemon.js's "get_build_status" IPC case returns) as raw JSON to
|
|
191
|
+
// stdout. This is the retrieval path scripts/verify-installed-build.js uses
|
|
192
|
+
// to check what the RUNNING daemon loaded, distinct from what the ON-DISK
|
|
193
|
+
// artifact contains (see that script's own header comment for the
|
|
194
|
+
// artifact-vs-process distinction this exists to close):
|
|
195
|
+
// `clagentic-console --process-build-status`.
|
|
196
|
+
function handleProcessBuildStatus() {
|
|
197
|
+
var statusConfig = loadConfig();
|
|
198
|
+
isDaemonAliveAsync(statusConfig).then(function (alive) {
|
|
199
|
+
if (!alive) {
|
|
200
|
+
// No running daemon is not itself an error here -- a caller comparing
|
|
201
|
+
// artifact vs. process needs to be able to tell "nothing to compare
|
|
202
|
+
// against" apart from "compared and it mismatched". Distinguish via
|
|
203
|
+
// ok:false + a stable error string rather than a bare non-zero exit
|
|
204
|
+
// with no machine-readable reason.
|
|
205
|
+
console.log(JSON.stringify({ ok: false, error: "no running daemon" }, null, 2));
|
|
206
|
+
process.exit(1);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
sendIPCCommand(socketPath(), { cmd: "get_build_status" }).then(function (res) {
|
|
210
|
+
if (!res.ok) {
|
|
211
|
+
console.error("Failed: " + (res.error || "unknown error"));
|
|
212
|
+
process.exit(1);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
// Raw JSON to stdout -- the point is machine readability for a gate
|
|
216
|
+
// script, not a human-formatted summary (contrast handleList's
|
|
217
|
+
// formatted output).
|
|
218
|
+
console.log(JSON.stringify({
|
|
219
|
+
loadedBuildSha: res.loadedBuildSha,
|
|
220
|
+
staleInodes: res.staleInodes,
|
|
221
|
+
pid: res.pid,
|
|
222
|
+
}, null, 2));
|
|
223
|
+
process.exit(0);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// lr-8b476f: prints the activity-divergence probe totals (same data
|
|
229
|
+
// process_stats's WS response folds in, see lib/daemon.js's
|
|
230
|
+
// "get_activity_diagnostics" IPC case) as raw JSON to stdout. This is the
|
|
231
|
+
// retrieval path for a read-only crew agent (Bash+Read only, no browser,
|
|
232
|
+
// no WS client, no devtools): `clagentic-console --activity-diagnostics`.
|
|
233
|
+
function handleActivityDiagnostics() {
|
|
234
|
+
var diagConfig = loadConfig();
|
|
235
|
+
isDaemonAliveAsync(diagConfig).then(function (alive) {
|
|
236
|
+
if (!alive) {
|
|
237
|
+
console.error("No running daemon. Start with: npx @clagentic/console");
|
|
238
|
+
process.exit(1);
|
|
239
|
+
}
|
|
240
|
+
sendIPCCommand(socketPath(), { cmd: "get_activity_diagnostics" }).then(function (res) {
|
|
241
|
+
if (!res.ok) {
|
|
242
|
+
console.error("Failed: " + (res.error || "unknown error"));
|
|
243
|
+
process.exit(1);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
// Raw JSON to stdout — the point is machine readability, not a
|
|
247
|
+
// human-formatted summary (contrast handleList's formatted output).
|
|
248
|
+
console.log(JSON.stringify({
|
|
249
|
+
activeLiveCount: res.activeLiveCount,
|
|
250
|
+
activityDivergenceCount: res.activityDivergenceCount,
|
|
251
|
+
activityDivergenceRecentSamples: res.activityDivergenceRecentSamples,
|
|
252
|
+
}, null, 2));
|
|
253
|
+
process.exit(0);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
180
258
|
module.exports = {
|
|
181
259
|
handleShutdown: handleShutdown,
|
|
182
260
|
handleRestart: handleRestart,
|
|
183
261
|
handleAdd: handleAdd,
|
|
184
262
|
handleRemove: handleRemove,
|
|
185
263
|
handleList: handleList,
|
|
264
|
+
handleActivityDiagnostics: handleActivityDiagnostics,
|
|
265
|
+
handleProcessBuildStatus: handleProcessBuildStatus,
|
|
186
266
|
};
|
package/lib/daemon.js
CHANGED
|
@@ -31,7 +31,7 @@ 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
33
|
var { validateCloneUrl, buildCloneArgs } = require("./clone-validate");
|
|
34
|
-
var { DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiveCount } = require("./sdk-bridge");
|
|
34
|
+
var { DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiveCount, buildActivityDiagnosticsResponse } = require("./sdk-bridge");
|
|
35
35
|
var { startMemoryHighWatcher, checkAppliedMemoryCeiling } = require("./memory-limits");
|
|
36
36
|
var { createDrain } = require("./drain");
|
|
37
37
|
var { shedMemory } = require("./memory-shed");
|
|
@@ -106,6 +106,25 @@ function checkStaleInodes() {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
// lr-dc9a3b: the SHA this process actually loaded lib/build-sha.json with at
|
|
110
|
+
// startup, captured once here so a later re-read of the on-disk file (after
|
|
111
|
+
// an install replaces it) can never be confused with what THIS process is
|
|
112
|
+
// running. Read defensively — a dev checkout that has never run `npm pack`
|
|
113
|
+
// (prepack writes this file, and it is gitignored) will not have it, and
|
|
114
|
+
// that is a legitimate "no build-identity signal available" state, not an
|
|
115
|
+
// error.
|
|
116
|
+
var loadedBuildSha = null;
|
|
117
|
+
try {
|
|
118
|
+
var _buildShaContents = fs.readFileSync(path.join(__dirname, 'build-sha.json'), 'utf8');
|
|
119
|
+
var _buildShaParsed = JSON.parse(_buildShaContents);
|
|
120
|
+
if (_buildShaParsed && typeof _buildShaParsed.sha === 'string') {
|
|
121
|
+
loadedBuildSha = _buildShaParsed.sha;
|
|
122
|
+
}
|
|
123
|
+
} catch (_) {
|
|
124
|
+
// lib/build-sha.json missing/unreadable/malformed — loadedBuildSha stays
|
|
125
|
+
// null, which get_build_status reports honestly rather than guessing.
|
|
126
|
+
}
|
|
127
|
+
|
|
109
128
|
if (checkStaleInodes()) {
|
|
110
129
|
console.warn('[daemon] WARNING: this process is serving STALE code — on-disk JS has been replaced');
|
|
111
130
|
console.warn('[daemon] WARNING: restart the daemon to load the new build:');
|
|
@@ -260,6 +279,10 @@ var relay = createServer({
|
|
|
260
279
|
tlsOptions: tlsOptions,
|
|
261
280
|
caPath: caRoot,
|
|
262
281
|
builtinCert: config.builtinCert || false,
|
|
282
|
+
// lr-20e71c: operator-declared trust boundary for reading X-Forwarded-Proto
|
|
283
|
+
// from a reverse proxy (e.g. Caddy). Never read the header unconditionally —
|
|
284
|
+
// see lib/effective-protocol.js.
|
|
285
|
+
trustedProxy: !!config.trustedProxy,
|
|
263
286
|
port: config.port,
|
|
264
287
|
debug: config.debug || false,
|
|
265
288
|
dangerouslySkipPermissions: config.dangerouslySkipPermissions || false,
|
|
@@ -1112,10 +1135,19 @@ var relay = createServer({
|
|
|
1112
1135
|
}
|
|
1113
1136
|
return { ok: false, error: "Project not found" };
|
|
1114
1137
|
},
|
|
1115
|
-
|
|
1138
|
+
// lr-20e71c: `tls` stays the accurate name for daemon-internal TLS
|
|
1139
|
+
// termination (tlsOptions !== null) — it must NOT be repurposed to mean
|
|
1140
|
+
// "reachable over HTTPS". effectiveProtocol is the separate, request-scoped
|
|
1141
|
+
// source of truth for that: server.js resolves it per-WS-connection via
|
|
1142
|
+
// lib/effective-protocol.js (trustedProxy-gated X-Forwarded-Proto) and
|
|
1143
|
+
// passes it in here so the settings badge and any other consumer render
|
|
1144
|
+
// the real external protocol, not the internal-termination flag.
|
|
1145
|
+
onGetDaemonConfig: function (effectiveProtocol) {
|
|
1116
1146
|
return {
|
|
1117
1147
|
port: config.port,
|
|
1118
1148
|
tls: !!tlsOptions,
|
|
1149
|
+
tlsEffective: effectiveProtocol ? effectiveProtocol.protocol === "https" : !!tlsOptions,
|
|
1150
|
+
tlsState: effectiveProtocol ? effectiveProtocol.state : (tlsOptions ? "direct" : "disabled"),
|
|
1119
1151
|
debug: !!config.debug,
|
|
1120
1152
|
headless: !!config.headless,
|
|
1121
1153
|
keepAwake: !!config.keepAwake,
|
|
@@ -1130,7 +1162,13 @@ var relay = createServer({
|
|
|
1130
1162
|
updateChannel: config.updateChannel || "stable",
|
|
1131
1163
|
imageRetentionDays: config.imageRetentionDays !== undefined ? config.imageRetentionDays : 7,
|
|
1132
1164
|
memAvailableMinMB: config.memAvailableMinMB !== undefined ? config.memAvailableMinMB : DEFAULT_MEM_AVAILABLE_MIN_MB,
|
|
1165
|
+
// lr-9e6569: config.memAvailableMinMB absent means the value below is a
|
|
1166
|
+
// fallback default, not something the operator ever saved -- renders
|
|
1167
|
+
// identically to a persisted value equal to the default without this
|
|
1168
|
+
// flag, which is part of why a silently-discarded edit went unnoticed.
|
|
1169
|
+
memAvailableMinMBIsDefault: config.memAvailableMinMB === undefined,
|
|
1133
1170
|
tokensPerMbHeadroom: config.tokensPerMbHeadroom !== undefined ? config.tokensPerMbHeadroom : DEFAULT_TOKENS_PER_MB_HEADROOM,
|
|
1171
|
+
tokensPerMbHeadroomIsDefault: config.tokensPerMbHeadroom === undefined,
|
|
1134
1172
|
liteAutoEnroll: !!config.liteAutoEnroll,
|
|
1135
1173
|
};
|
|
1136
1174
|
},
|
|
@@ -1188,7 +1226,15 @@ var relay = createServer({
|
|
|
1188
1226
|
},
|
|
1189
1227
|
onSetMemAvailableThreshold: function (mb) {
|
|
1190
1228
|
var val = parseInt(mb, 10);
|
|
1191
|
-
|
|
1229
|
+
// lr-93e3c8 (item 6): out-of-range used to silently reset to the
|
|
1230
|
+
// default and still report ok:true -- a UX trap on the exact knob an
|
|
1231
|
+
// operator reaches for while already blocked by this same guard.
|
|
1232
|
+
// Reject and report instead of silently substituting a value the
|
|
1233
|
+
// caller didn't ask for.
|
|
1234
|
+
if (isNaN(val) || val < 0) {
|
|
1235
|
+
console.warn("[daemon] MemAvailable threshold rejected: " + mb + " (must be a number >= 0)");
|
|
1236
|
+
return { ok: false, error: "Value must be a number >= 0", memAvailableMinMB: config.memAvailableMinMB !== undefined ? config.memAvailableMinMB : DEFAULT_MEM_AVAILABLE_MIN_MB };
|
|
1237
|
+
}
|
|
1192
1238
|
config.memAvailableMinMB = val;
|
|
1193
1239
|
saveConfig(config);
|
|
1194
1240
|
console.log("[daemon] MemAvailable threshold:", val, "MB (web)");
|
|
@@ -1196,8 +1242,13 @@ var relay = createServer({
|
|
|
1196
1242
|
},
|
|
1197
1243
|
onSetTokensPerMbHeadroom: function (tpm) {
|
|
1198
1244
|
var val = parseInt(tpm, 10);
|
|
1199
|
-
//
|
|
1200
|
-
|
|
1245
|
+
// lr-93e3c8 (item 6): valid range 10-500 tokens/MB. Out-of-range used to
|
|
1246
|
+
// silently clamp to the default and still report ok:true -- see comment
|
|
1247
|
+
// on onSetMemAvailableThreshold above; same trap, same fix.
|
|
1248
|
+
if (isNaN(val) || val < 10 || val > 500) {
|
|
1249
|
+
console.warn("[daemon] Tokens per MB headroom rejected: " + tpm + " (must be 10-500)");
|
|
1250
|
+
return { ok: false, error: "Value must be 10-500", tokensPerMbHeadroom: config.tokensPerMbHeadroom !== undefined ? config.tokensPerMbHeadroom : DEFAULT_TOKENS_PER_MB_HEADROOM };
|
|
1251
|
+
}
|
|
1201
1252
|
config.tokensPerMbHeadroom = val;
|
|
1202
1253
|
saveConfig(config);
|
|
1203
1254
|
console.log("[daemon] Tokens per MB headroom:", val, "(web)");
|
|
@@ -1553,6 +1604,53 @@ var ipc = createIPCServer(socketPath(), function (msg) {
|
|
|
1553
1604
|
uptime: process.uptime(),
|
|
1554
1605
|
};
|
|
1555
1606
|
|
|
1607
|
+
// lr-8b476f: agent-readable counterpart to the WS-only process_stats
|
|
1608
|
+
// handler (lib/project-sessions.js:668-709). Reads the same shared
|
|
1609
|
+
// module-level counter (lib/sdk-bridge.js) that process_stats already
|
|
1610
|
+
// folds into its response via getMemoryStats() — buildActivityDiagnosticsResponse
|
|
1611
|
+
// is unit-tested directly (test/activity-diagnostics-retrieval-lr-8b476f.test.js),
|
|
1612
|
+
// since daemon.js has no module.exports and cannot be required
|
|
1613
|
+
// in-process without binding real sockets/HTTP servers.
|
|
1614
|
+
//
|
|
1615
|
+
// Read-only, mutates nothing. Gated the same way every other IPC
|
|
1616
|
+
// command on this socket is gated: CONFIG_DIR (containing daemon.sock)
|
|
1617
|
+
// is chmod 0700 (ensureConfigDir, lib/config.js), so only the daemon's
|
|
1618
|
+
// own OS user can connect at all — no new auth surface is introduced,
|
|
1619
|
+
// and none is copied from process_stats's WS gap (lr-2016fe) either,
|
|
1620
|
+
// since this is a different transport with its own (stricter, OS-level)
|
|
1621
|
+
// gate rather than an unaudited role check.
|
|
1622
|
+
//
|
|
1623
|
+
// Samples carry no session-identifying field, matching process_stats's
|
|
1624
|
+
// BOBBIE-remediated shape exactly (lib/sdk-bridge.js
|
|
1625
|
+
// _recordActivityDivergenceIfAny) — this command reads the SAME
|
|
1626
|
+
// samples, so nothing new is exposed by adding this second retrieval
|
|
1627
|
+
// path.
|
|
1628
|
+
case "get_activity_diagnostics":
|
|
1629
|
+
return buildActivityDiagnosticsResponse();
|
|
1630
|
+
|
|
1631
|
+
// lr-dc9a3b: makes the running-vs-installed mismatch a first-class,
|
|
1632
|
+
// queryable signal instead of a journalctl-only warning nothing
|
|
1633
|
+
// consumes. verify-installed-build.js (the post-merge gate) already
|
|
1634
|
+
// compares the ON-DISK build-sha.json against merged HEAD -- that
|
|
1635
|
+
// proves the ARTIFACT is right, not that the RUNNING PROCESS loaded
|
|
1636
|
+
// it. This reports the SHA this process actually loaded at startup
|
|
1637
|
+
// (loadedBuildSha, captured once above -- never re-read, so an install
|
|
1638
|
+
// replacing the file on disk after startup cannot change what this
|
|
1639
|
+
// reports) plus the existing checkStaleInodes() detector's live
|
|
1640
|
+
// result, so a caller can tell "process never picked up the new
|
|
1641
|
+
// build" apart from "process picked it up but its deleted-inode
|
|
1642
|
+
// handles say the file has since moved again".
|
|
1643
|
+
//
|
|
1644
|
+
// Read-only, mutates nothing, same OS-level socket gate as every other
|
|
1645
|
+
// command on this connection (CONFIG_DIR is chmod 0700).
|
|
1646
|
+
case "get_build_status":
|
|
1647
|
+
return {
|
|
1648
|
+
ok: true,
|
|
1649
|
+
loadedBuildSha: loadedBuildSha,
|
|
1650
|
+
staleInodes: checkStaleInodes(),
|
|
1651
|
+
pid: process.pid,
|
|
1652
|
+
};
|
|
1653
|
+
|
|
1556
1654
|
case "set_pin": {
|
|
1557
1655
|
config.pinHash = msg.pinHash || null;
|
|
1558
1656
|
relay.setAuthToken(config.pinHash);
|
|
@@ -1763,8 +1861,14 @@ var MAX_LISTEN_RETRIES = 15;
|
|
|
1763
1861
|
|
|
1764
1862
|
function startListening() {
|
|
1765
1863
|
relay.server.listen(config.port, listenHost, function () {
|
|
1766
|
-
|
|
1767
|
-
|
|
1864
|
+
// Startup has no live request, so there is no X-Forwarded-Proto to read —
|
|
1865
|
+
// resolveEffectiveProtocol's "proxy" state requires one. Reflect the
|
|
1866
|
+
// operator's trustedProxy declaration directly instead of silently
|
|
1867
|
+
// printing http:// for a deployment they've told us sits behind a
|
|
1868
|
+
// TLS-terminating proxy (lr-20e71c).
|
|
1869
|
+
var protocol = tlsOptions ? "https" : (config.trustedProxy ? "https" : "http");
|
|
1870
|
+
var protocolNote = (!tlsOptions && config.trustedProxy) ? " (proxy-terminated)" : "";
|
|
1871
|
+
console.log("[daemon] Listening on " + protocol + "://" + listenHost + ":" + config.port + protocolNote);
|
|
1768
1872
|
console.log("[daemon] PID:", process.pid);
|
|
1769
1873
|
console.log("[daemon] Projects:", config.projects.length);
|
|
1770
1874
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// effective-protocol.js — single source of truth for the EXTERNAL protocol a
|
|
2
|
+
// client actually reached this daemon over, as distinct from tlsOptions
|
|
3
|
+
// (daemon-internal TLS termination only, see lib/daemon.js).
|
|
4
|
+
//
|
|
5
|
+
// Root cause (lr-20e71c): tlsOptions is non-null only when the daemon itself
|
|
6
|
+
// terminates TLS from CONFIG_DIR/certs. A deployment fronted by a reverse
|
|
7
|
+
// proxy (e.g. Caddy) that terminates TLS and forwards plain HTTP to the
|
|
8
|
+
// daemon is genuinely served over HTTPS, but tlsOptions is correctly null —
|
|
9
|
+
// so any code that read tlsOptions as a stand-in for "is this HTTPS" (the
|
|
10
|
+
// System Settings badge, the share-URL protocol) reported a false negative.
|
|
11
|
+
//
|
|
12
|
+
// X-Forwarded-Proto is NOT trusted unconditionally — an untrusted client
|
|
13
|
+
// could set it to spoof an "Enabled" readout over what is really plain HTTP.
|
|
14
|
+
// It is only consulted when the operator has explicitly declared this
|
|
15
|
+
// deployment sits behind a trusted proxy (config.trustedProxy). Caddy sets
|
|
16
|
+
// the header automatically; the operator's config declaration is the trust
|
|
17
|
+
// boundary, not the header's mere presence.
|
|
18
|
+
//
|
|
19
|
+
// Multi-hop chains (comma-separated header value): per RFC 7239 / the de
|
|
20
|
+
// facto X-Forwarded-* convention, each proxy in a chain APPENDS its own
|
|
21
|
+
// value to the right, so the LEFTMOST entry is the value the ORIGINAL
|
|
22
|
+
// client supplied (attacker-controlled) and the RIGHTMOST is the value the
|
|
23
|
+
// hop closest to this daemon set. "Rightmost is authoritative" is only true
|
|
24
|
+
// when every hop between the client and this daemon is itself trusted not
|
|
25
|
+
// to pass an untouched client-supplied value through — and config.trustedProxy
|
|
26
|
+
// is a single boolean with no hop-count, so it cannot express "trust exactly
|
|
27
|
+
// the last N hops" or "trust hop closest to us but not earlier ones". A
|
|
28
|
+
// misconfigured or attacker-reachable intermediate hop could still leave an
|
|
29
|
+
// attacker-controlled value in the rightmost position under some proxy
|
|
30
|
+
// topologies. Given that ambiguity, a multi-valued header is treated as
|
|
31
|
+
// untrustworthy under this trust model and ignored entirely (falls through
|
|
32
|
+
// to "disabled") rather than guessing which position is safe. Operators
|
|
33
|
+
// running a single, directly-adjacent trusted proxy (the Caddy deployment
|
|
34
|
+
// this repo ships) always see a single-valued header and are unaffected;
|
|
35
|
+
// only a chain deeper than one hop is refused.
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the three possible states a deployment's external protocol can be in.
|
|
39
|
+
*
|
|
40
|
+
* @param {Object} params
|
|
41
|
+
* @param {Object|null} params.tlsOptions - daemon-internal TLS cert material
|
|
42
|
+
* (non-null only when Node itself is terminating TLS). Name stays
|
|
43
|
+
* unchanged — it is NOT the effective-protocol source of truth.
|
|
44
|
+
* @param {boolean} params.trustedProxy - operator-declared trust boundary
|
|
45
|
+
* for reading X-Forwarded-Proto from this request.
|
|
46
|
+
* @param {string|null|undefined} params.forwardedProtoHeader - the raw
|
|
47
|
+
* X-Forwarded-Proto header value. A single value is trusted when
|
|
48
|
+
* trustedProxy is set; a comma-separated (multi-hop) value is rejected
|
|
49
|
+
* outright, since a single trustedProxy boolean cannot express which hop
|
|
50
|
+
* in the chain is the trustworthy one (see module comment above).
|
|
51
|
+
* @returns {{protocol: "http"|"https", state: "direct"|"proxy"|"disabled"}}
|
|
52
|
+
* state drives the three badge renders: "direct" = daemon terminates TLS
|
|
53
|
+
* itself; "proxy" = a trusted proxy terminates TLS in front of the daemon;
|
|
54
|
+
* "disabled" = genuinely unencrypted, must stay visibly distinct from the
|
|
55
|
+
* other two.
|
|
56
|
+
*/
|
|
57
|
+
function resolveEffectiveProtocol(params) {
|
|
58
|
+
var tlsOptions = params && params.tlsOptions;
|
|
59
|
+
var trustedProxy = !!(params && params.trustedProxy);
|
|
60
|
+
var forwardedProtoHeader = params && params.forwardedProtoHeader;
|
|
61
|
+
|
|
62
|
+
if (tlsOptions) {
|
|
63
|
+
return { protocol: "https", state: "direct" };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (trustedProxy && forwardedProtoHeader) {
|
|
67
|
+
var rawHeader = String(forwardedProtoHeader);
|
|
68
|
+
// A multi-hop (comma-separated) value is refused rather than guessed at
|
|
69
|
+
// — see module comment above for why neither "leftmost" nor "rightmost"
|
|
70
|
+
// is safe to assume under a single-boolean trust model.
|
|
71
|
+
if (rawHeader.indexOf(",") === -1) {
|
|
72
|
+
var singleProto = rawHeader.trim().toLowerCase();
|
|
73
|
+
if (singleProto === "https") {
|
|
74
|
+
return { protocol: "https", state: "proxy" };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return { protocol: "http", state: "disabled" };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = { resolveEffectiveProtocol: resolveEffectiveProtocol };
|
|
@@ -89,7 +89,7 @@ function attachConnection(ctx) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
function handleConnection(ws, wsUser, handleMessage, handleDisconnection) {
|
|
92
|
-
ws.
|
|
92
|
+
ws._clagenticUser = wsUser || null;
|
|
93
93
|
clients.add(ws);
|
|
94
94
|
broadcastClientCount();
|
|
95
95
|
|
|
@@ -113,7 +113,7 @@ function attachConnection(ctx) {
|
|
|
113
113
|
var projectOwnerId = getProjectOwnerId();
|
|
114
114
|
|
|
115
115
|
// Send cached state
|
|
116
|
-
var _userId = ws.
|
|
116
|
+
var _userId = ws._clagenticUser ? ws._clagenticUser.id : null;
|
|
117
117
|
var _filteredProjects = getProjectList(_userId);
|
|
118
118
|
var title = getTitle();
|
|
119
119
|
var project = getProject();
|
|
@@ -189,7 +189,7 @@ function attachConnection(ctx) {
|
|
|
189
189
|
autoCreated = true;
|
|
190
190
|
}
|
|
191
191
|
if (active && !autoCreated) {
|
|
192
|
-
ws.
|
|
192
|
+
ws._clagenticActiveSession = active.localId;
|
|
193
193
|
var _vendorCaps = (sm.capabilitiesByVendor && sm.capabilitiesByVendor[active.vendor || sm.defaultVendor || "claude"]) || {};
|
|
194
194
|
// Load history from disk before checking hasHistory — the session may have
|
|
195
195
|
// been evicted from the LRU cache (lr-f311 lazy load), in which case
|
|
@@ -229,7 +229,17 @@ function attachConnection(ctx) {
|
|
|
229
229
|
// lr-041af8: carry the restored session's own effective model — see
|
|
230
230
|
// effectiveSessionModel() in sessions.js and the model_info/config_state
|
|
231
231
|
// fix above in this same connect handler.
|
|
232
|
-
|
|
232
|
+
// This hydration send previously omitted isProcessing — sessions.js's
|
|
233
|
+
// switchSession() send DOES carry it, but a client that hydrates via
|
|
234
|
+
// THIS path (fresh connect / reconnect) never got the authoritative
|
|
235
|
+
// reconciled value here, only via the separate status:"processing"
|
|
236
|
+
// send below (guarded by active.isProcessing) — and that separate
|
|
237
|
+
// message carried no session-scoping (see localId note below), so a
|
|
238
|
+
// client's derived 'sessionIsProcessing' could lag or desync from
|
|
239
|
+
// server truth across a reconnect. Carrying it directly on
|
|
240
|
+
// session_switched matches switchSession() and gives the client a
|
|
241
|
+
// single authoritative snapshot value to reconcile the footer against.
|
|
242
|
+
sendTo(ws, { type: "session_switched", id: active.localId, cliSessionId: active.cliSessionId || null, loop: active.loop || null, vendor: active.vendor || null, model: sm.effectiveSessionModel(active), hasHistory: _hasHistory, capabilities: _vendorCaps, isProcessing: !!active.isProcessing, agentName: active.agentName || null });
|
|
233
243
|
// Send per-session context sources
|
|
234
244
|
var sessionSources = loadContextSources(slug, active.localId);
|
|
235
245
|
sendTo(ws, { type: "context_sources_state", active: sessionSources });
|
|
@@ -239,7 +249,10 @@ function attachConnection(ctx) {
|
|
|
239
249
|
sm.replayHistory(active, undefined, ws, hydrateImageRefs);
|
|
240
250
|
|
|
241
251
|
if (active.isProcessing) {
|
|
242
|
-
|
|
252
|
+
// Carry localId so the client can session-scope this edge (matching
|
|
253
|
+
// the scheduled_message_* pattern) instead of writing the global
|
|
254
|
+
// 'processing' latch blind to which session it belongs to.
|
|
255
|
+
sendTo(ws, { type: "status", status: "processing", localId: active.localId });
|
|
243
256
|
}
|
|
244
257
|
var pendingIds = Object.keys(active.pendingPermissions);
|
|
245
258
|
for (var pi = 0; pi < pendingIds.length; pi++) {
|
|
@@ -302,10 +315,10 @@ function attachConnection(ctx) {
|
|
|
302
315
|
}
|
|
303
316
|
|
|
304
317
|
function handleDisconnection(ws) {
|
|
305
|
-
if (ws.
|
|
306
|
-
var dcPresKey = ws.
|
|
318
|
+
if (ws._clagenticActiveSession) {
|
|
319
|
+
var dcPresKey = ws._clagenticUser ? ws._clagenticUser.id : "_default";
|
|
307
320
|
var dcExisting = userPresence.getPresence(slug, dcPresKey);
|
|
308
|
-
userPresence.setPresence(slug, dcPresKey, ws.
|
|
321
|
+
userPresence.setPresence(slug, dcPresKey, ws._clagenticActiveSession, dcExisting ? dcExisting.mateDm : null);
|
|
309
322
|
}
|
|
310
323
|
tm.detachAll(ws);
|
|
311
324
|
clients.delete(ws);
|
|
@@ -43,8 +43,8 @@ function attachFilesystem(ctx) {
|
|
|
43
43
|
function handleFilesystemMessage(ws, msg) {
|
|
44
44
|
// --- File browser permission gate ---
|
|
45
45
|
if (msg.type === "fs_list" || msg.type === "fs_read" || msg.type === "fs_write" || msg.type === "fs_delete" || msg.type === "fs_rename" || msg.type === "fs_mkdir" || msg.type === "fs_upload" || msg.type === "fs_search") {
|
|
46
|
-
if (ws.
|
|
47
|
-
var fbPerms = usersModule.getEffectivePermissions(ws.
|
|
46
|
+
if (ws._clagenticUser) {
|
|
47
|
+
var fbPerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
|
|
48
48
|
if (!fbPerms.fileBrowser) {
|
|
49
49
|
sendTo(ws, { type: msg.type + "_result", error: "File browser access is not permitted" });
|
|
50
50
|
return true;
|
|
@@ -231,8 +231,8 @@ function attachFilesystem(ctx) {
|
|
|
231
231
|
msg.type === "read_global_claude_md" || msg.type === "write_global_claude_md" ||
|
|
232
232
|
msg.type === "get_shared_env" || msg.type === "set_shared_env" ||
|
|
233
233
|
msg.type === "transfer_project_owner") {
|
|
234
|
-
if (ws.
|
|
235
|
-
var psPerms = usersModule.getEffectivePermissions(ws.
|
|
234
|
+
if (ws._clagenticUser) {
|
|
235
|
+
var psPerms = usersModule.getEffectivePermissions(ws._clagenticUser, osUsers);
|
|
236
236
|
if (!psPerms.projectSettings) {
|
|
237
237
|
sendTo(ws, { type: "error", text: "Project settings access is not permitted" });
|
|
238
238
|
return true;
|
package/lib/project-http.js
CHANGED
|
@@ -174,10 +174,10 @@ function attachHTTP(ctx) {
|
|
|
174
174
|
// Make readable by all local users and chown to session owner
|
|
175
175
|
try { fs.chmodSync(destPath, 0o644); } catch (e2) {}
|
|
176
176
|
try { fs.chmodSync(tmpDir, 0o755); } catch (e2) {}
|
|
177
|
-
if (req.
|
|
177
|
+
if (req._clagenticUser && req._clagenticUser.linuxUser) {
|
|
178
178
|
try {
|
|
179
179
|
var _osUM = require("./os-users");
|
|
180
|
-
var _uid = _osUM.getLinuxUserUid(req.
|
|
180
|
+
var _uid = _osUM.getLinuxUserUid(req._clagenticUser.linuxUser);
|
|
181
181
|
if (_uid != null) {
|
|
182
182
|
execFileSync("chown", [String(_uid), destPath]);
|
|
183
183
|
execFileSync("chown", [String(_uid), tmpDir]);
|
|
@@ -297,8 +297,8 @@ function attachHTTP(ctx) {
|
|
|
297
297
|
|
|
298
298
|
// Skills permission gate
|
|
299
299
|
if (urlPath === "/api/install-skill" || urlPath === "/api/uninstall-skill" || urlPath === "/api/installed-skills") {
|
|
300
|
-
if (req.
|
|
301
|
-
var skPerms = usersModule.getEffectivePermissions(req.
|
|
300
|
+
if (req._clagenticUser) {
|
|
301
|
+
var skPerms = usersModule.getEffectivePermissions(req._clagenticUser, osUsers);
|
|
302
302
|
if (!skPerms.skills) {
|
|
303
303
|
res.writeHead(403, { "Content-Type": "application/json" });
|
|
304
304
|
res.end('{"error":"Skills access is not permitted"}');
|