@clagentic/console 1.10.0-beta.1 → 1.10.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/README.md +1 -1
- package/bin/cli.js +10 -0
- package/lib/activity-clock.js +23 -0
- package/lib/agent-dispatch-tool.js +20 -0
- package/lib/build-changes.js +79 -0
- package/lib/build-identity.js +192 -0
- package/lib/build-monitor.js +125 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +141 -0
- package/lib/build-update-restart.js +142 -0
- package/lib/build-update-standing.js +184 -0
- package/lib/cli/daemon-launch.js +8 -5
- package/lib/cli/ipc-subcommands.js +6 -0
- package/lib/cli/session-subcommands.js +122 -0
- package/lib/cli-sessions.js +8 -1
- package/lib/cli-transcript-title.js +131 -0
- package/lib/codex-defaults.js +8 -2
- package/lib/daemon-projects.js +19 -0
- package/lib/daemon.js +166 -127
- package/lib/debug-log.js +17 -0
- package/lib/exit-flush.js +44 -0
- package/lib/grant-keys.js +179 -0
- package/lib/log-field.js +34 -0
- package/lib/memory-shed.js +13 -32
- package/lib/project-connection.js +14 -0
- package/lib/project-external-trigger.js +91 -123
- package/lib/project-http.js +2 -0
- package/lib/project-loop.js +5 -4
- package/lib/project-notifications.js +4 -0
- package/lib/project-prompt-responses.js +7 -5
- package/lib/project-session-grants.js +73 -0
- package/lib/project-sessions.js +55 -68
- package/lib/project-user-message.js +13 -25
- package/lib/project.js +25 -5
- package/lib/prompt-kinds/permission.js +18 -0
- package/lib/prompt-label.js +60 -0
- package/lib/prompt-registry.js +123 -13
- package/lib/prompt-source.js +65 -0
- package/lib/public/css/diagnostics.css +30 -0
- package/lib/public/css/notifications-center.css +15 -0
- package/lib/public/css/overlays.css +18 -0
- package/lib/public/css/rewind.css +8 -0
- package/lib/public/modules/agent-dispatch-tool.js +9 -0
- package/lib/public/modules/app-messages.js +10 -2
- package/lib/public/modules/app-notifications.js +9 -1
- package/lib/public/modules/app-panels.js +0 -1
- package/lib/public/modules/build-update-detail.js +54 -0
- package/lib/public/modules/diagnostics.js +126 -20
- package/lib/public/modules/prompt-banner.js +12 -0
- package/lib/public/modules/prompt-kinds/permission-choices.js +6 -1
- package/lib/public/modules/prompt-kinds/permission.js +15 -0
- package/lib/public/modules/prompt-label.js +44 -0
- package/lib/public/modules/prompts.js +9 -0
- package/lib/public/modules/session-grants.js +131 -0
- package/lib/public/modules/sidebar-sessions.js +11 -0
- package/lib/public/modules/tools.js +14 -2
- package/lib/public/modules/vendor-picker.js +2 -2
- package/lib/public/modules/vendor-registry.js +11 -2
- package/lib/runtime-env.js +1 -1
- package/lib/sdk-bridge.js +114 -115
- package/lib/sdk-message-processor.js +25 -87
- package/lib/sdk-skill-discovery.js +65 -60
- package/lib/server.js +15 -2
- package/lib/session-ai-title.js +80 -0
- package/lib/session-id.js +33 -0
- package/lib/session-input-ipc.js +32 -0
- package/lib/session-input.js +409 -0
- package/lib/session-reclaim.js +284 -0
- package/lib/session-resume.js +172 -0
- package/lib/sessions.js +31 -21
- package/lib/supervisor.js +39 -0
- package/lib/turn-initiator.js +108 -0
- package/lib/utils.js +9 -47
- package/lib/vendor-registry-message.js +1 -0
- package/lib/ws-schema.js +9 -4
- package/lib/yoke/adapters/claude-vendor.js +0 -1
- package/lib/yoke/adapters/claude-worker.js +6 -4
- package/lib/yoke/adapters/claude.js +29 -86
- package/lib/yoke/adapters/codex-capabilities.js +9 -6
- package/lib/yoke/adapters/codex-vendor.js +15 -15
- package/lib/yoke/adapters/codex.js +125 -136
- package/lib/yoke/auth-checks.js +8 -21
- package/lib/yoke/codex-app-server.js +27 -71
- package/lib/yoke/codex-binary.js +254 -0
- package/lib/yoke/codex-command.js +122 -0
- package/lib/yoke/codex-protocol.js +96 -0
- package/lib/yoke/codex-version.js +135 -0
- package/lib/yoke/index.js +20 -4
- package/lib/yoke/install-probe.js +21 -6
- package/lib/yoke/interface.js +14 -12
- package/lib/yoke/registry.js +41 -4
- package/package.json +1 -2
- package/scripts/verify-installed-build.js +59 -17
- package/lib/lore-attestation.js +0 -73
package/lib/codex-defaults.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
var normalizeApprovalPolicy = require("./yoke/codex-protocol").normalizeApprovalPolicy;
|
|
2
|
+
|
|
1
3
|
// lr-f7a4 — sandbox defaults to "workspace-write" (matches the Codex CLI's own
|
|
2
4
|
// safe default). "danger-full-access" removes all filesystem guardrails and
|
|
3
5
|
// must be an explicit opt-in via the UI/session setting, never the default.
|
|
6
|
+
//
|
|
7
|
+
// The approval default is "on-request". "on-failure" is not a policy of its
|
|
8
|
+
// own in current Codex releases (it is an alias of "on-request"), so a saved
|
|
9
|
+
// "on-failure" is read as the value it means.
|
|
4
10
|
var CODEX_DEFAULTS = {
|
|
5
|
-
approval: "on-
|
|
11
|
+
approval: "on-request",
|
|
6
12
|
sandbox: "workspace-write",
|
|
7
13
|
webSearch: "live",
|
|
8
14
|
};
|
|
9
15
|
|
|
10
16
|
function getCodexConfig(sm) {
|
|
11
17
|
return {
|
|
12
|
-
approval:
|
|
18
|
+
approval: sm && sm.codexApproval ? normalizeApprovalPolicy(sm.codexApproval) : CODEX_DEFAULTS.approval,
|
|
13
19
|
sandbox: (sm && sm.codexSandbox) || CODEX_DEFAULTS.sandbox,
|
|
14
20
|
webSearch: (sm && sm.codexWebSearch) || CODEX_DEFAULTS.webSearch,
|
|
15
21
|
};
|
package/lib/daemon-projects.js
CHANGED
|
@@ -11,6 +11,22 @@ var { scanWorktrees, isWorktree } = require("./worktree");
|
|
|
11
11
|
var worktreeRegistry = {}; // parentSlug -> [wtSlug, ...]
|
|
12
12
|
var worktreeTimers = {}; // parentSlug -> intervalId
|
|
13
13
|
var worktreeScanning = {}; // parentSlug -> boolean (mutex)
|
|
14
|
+
// Set when shutdown begins and never cleared: a rescan that fires from then on
|
|
15
|
+
// would re-add worktrees (and create adapters for them) to projects that were
|
|
16
|
+
// just destroyed, inside the shutdown's force-exit window.
|
|
17
|
+
var rescansStopped = false;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Stop every worktree rescan timer and make any rescan or registration that
|
|
21
|
+
* still arrives a no-op. Shutdown calls this before it destroys the projects.
|
|
22
|
+
*/
|
|
23
|
+
function stopWorktreeRescans() {
|
|
24
|
+
rescansStopped = true;
|
|
25
|
+
Object.keys(worktreeTimers).forEach(function (parentSlug) {
|
|
26
|
+
clearInterval(worktreeTimers[parentSlug]);
|
|
27
|
+
delete worktreeTimers[parentSlug];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
14
30
|
|
|
15
31
|
function isWorktreeSlug(slug) {
|
|
16
32
|
return slug.indexOf("--") !== -1;
|
|
@@ -25,6 +41,7 @@ function isWorktreeSlug(slug) {
|
|
|
25
41
|
* @param {string} parentOwnerId - owner user ID
|
|
26
42
|
*/
|
|
27
43
|
function scanAndRegisterWorktrees(relay, parentPath, parentSlug, parentIcon, parentOwnerId) {
|
|
44
|
+
if (rescansStopped) return;
|
|
28
45
|
if (isWorktree(parentPath)) return;
|
|
29
46
|
var worktrees = scanWorktrees(parentPath);
|
|
30
47
|
if (worktrees.length === 0) return;
|
|
@@ -59,6 +76,7 @@ function scanAndRegisterWorktrees(relay, parentPath, parentSlug, parentIcon, par
|
|
|
59
76
|
* @param {object} [config] - daemon config (optional, for broadcasting project count)
|
|
60
77
|
*/
|
|
61
78
|
function rescanWorktrees(relay, parentPath, parentSlug, parentIcon, parentOwnerId, config) {
|
|
79
|
+
if (rescansStopped) return;
|
|
62
80
|
if (worktreeScanning[parentSlug]) return;
|
|
63
81
|
worktreeScanning[parentSlug] = true;
|
|
64
82
|
try {
|
|
@@ -193,6 +211,7 @@ module.exports = {
|
|
|
193
211
|
isWorktreeSlug: isWorktreeSlug,
|
|
194
212
|
scanAndRegisterWorktrees: scanAndRegisterWorktrees,
|
|
195
213
|
rescanWorktrees: rescanWorktrees,
|
|
214
|
+
stopWorktreeRescans: stopWorktreeRescans,
|
|
196
215
|
cleanupWorktreesForParent: cleanupWorktreesForParent,
|
|
197
216
|
getFilteredRemovedProjects: getFilteredRemovedProjects,
|
|
198
217
|
registerWorktreeSlug: registerWorktreeSlug,
|
package/lib/daemon.js
CHANGED
|
@@ -23,6 +23,9 @@ delete process.env.CLAUDECODE;
|
|
|
23
23
|
|
|
24
24
|
var fs = require("fs");
|
|
25
25
|
var path = require("path");
|
|
26
|
+
// What this process loaded is recorded before anything else is required from
|
|
27
|
+
// lib/, so an install landing during startup is seen as a change afterwards.
|
|
28
|
+
var buildIdentity = require("./build-identity").createBuildIdentity(__dirname);
|
|
26
29
|
var { loadConfig, saveConfig, socketPath, ensureConfigDir, generateSlug, syncClayrc, removeFromClayrc, writeCrashInfo, readCrashInfo, clearCrashInfo, isPidAlive, clearStaleConfig, REAL_HOME, CONFIG_DIR, CLAGENTIC_HOME } = require("./config");
|
|
27
30
|
var { createIPCServer } = require("./ipc");
|
|
28
31
|
var { createEnvSettings, removeEnvrcOnOwnerChange } = require("./daemon-env-settings");
|
|
@@ -32,7 +35,7 @@ var promptRegistry = require("./prompt-registry");
|
|
|
32
35
|
var { checkAclSupport, grantProjectAccess, revokeProjectAccess, provisionAllUsers, provisionLinuxUser, grantAllUsersAccess, deactivateLinuxUser, ensureProjectsDir } = require("./os-users");
|
|
33
36
|
var usersModule = require("./users");
|
|
34
37
|
var { createWorktree, removeWorktree, isWorktree } = require("./worktree");
|
|
35
|
-
var { isWorktreeSlug, scanAndRegisterWorktrees, rescanWorktrees, cleanupWorktreesForParent, getFilteredRemovedProjects, registerWorktreeSlug, unregisterWorktreeSlug, getProjectAccessRecord } = require("./daemon-projects");
|
|
38
|
+
var { isWorktreeSlug, scanAndRegisterWorktrees, rescanWorktrees, stopWorktreeRescans, cleanupWorktreesForParent, getFilteredRemovedProjects, registerWorktreeSlug, unregisterWorktreeSlug, getProjectAccessRecord } = require("./daemon-projects");
|
|
36
39
|
var { validateCloneUrl, buildCloneArgs } = require("./clone-validate");
|
|
37
40
|
var { DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiveCount, buildActivityDiagnosticsResponse } = require("./sdk-bridge");
|
|
38
41
|
var { validateMemAvailableThresholdMB, validateTokensPerMbHeadroom } = require("./memory-setting-validate");
|
|
@@ -41,7 +44,13 @@ var { createDrain } = require("./drain");
|
|
|
41
44
|
var { setNewWorkGate } = require("./new-work-gate");
|
|
42
45
|
var { shedMemory } = require("./memory-shed");
|
|
43
46
|
var { dropSkillsCache } = require("./server-skills");
|
|
44
|
-
var {
|
|
47
|
+
var { waitForIdleThenAct } = require("./build-update-check");
|
|
48
|
+
var { createBuildMonitor } = require("./build-monitor");
|
|
49
|
+
var { createBuildUpdateRestart } = require("./build-update-restart");
|
|
50
|
+
var { buildOffer, summarizeOffer } = require("./build-update-offer");
|
|
51
|
+
var { createStandingOffer } = require("./build-update-standing");
|
|
52
|
+
var { listBuildChanges, resolveHistoryRepo } = require("./build-changes");
|
|
53
|
+
var { RESTART_EXIT_CODE, isSupervised, unsupervisedEnv } = require("./supervisor");
|
|
45
54
|
var liteDetect = require("./lite-detect");
|
|
46
55
|
var { execFile: liteExecFile } = require("child_process");
|
|
47
56
|
var { SLUG_RE: CUSTOM_ICON_SLUG_RE, CUSTOM_EMOJI_CT } = require("./server-settings");
|
|
@@ -101,9 +110,11 @@ if (_projectsDirNotice) console.log(_projectsDirNotice);
|
|
|
101
110
|
if (process.env.SUDO_USER) console.log("[daemon] SUDO_USER: " + process.env.SUDO_USER);
|
|
102
111
|
console.log("[daemon] UID: " + (typeof process.getuid === "function" ? process.getuid() : "N/A"));
|
|
103
112
|
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
//
|
|
113
|
+
// Whether this process maps a file an install has since unlinked. Reported by
|
|
114
|
+
// get_build_status for diagnosis only: an identical reinstall also unlinks the
|
|
115
|
+
// native module this process keeps mapped, and the marker never clears, so it
|
|
116
|
+
// cannot say whether the installed build differs from the loaded one. That
|
|
117
|
+
// verdict comes from buildIdentity (sha plus content hash).
|
|
107
118
|
function checkStaleInodes() {
|
|
108
119
|
if (process.platform !== 'linux') return false;
|
|
109
120
|
try {
|
|
@@ -116,31 +127,15 @@ function checkStaleInodes() {
|
|
|
116
127
|
}
|
|
117
128
|
}
|
|
118
129
|
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
// running.
|
|
123
|
-
//
|
|
124
|
-
// that is a legitimate "no build-identity signal available" state, not an
|
|
125
|
-
// error.
|
|
130
|
+
// The SHA this process loaded lib/build-sha.json with at startup (captured by
|
|
131
|
+
// buildIdentity at the top of this file), never re-read, so a later install
|
|
132
|
+
// replacing the file on disk can never be confused with what THIS process is
|
|
133
|
+
// running. null for a checkout that has never run `npm pack` (prepack writes
|
|
134
|
+
// the file and it is gitignored): "no build-identity signal", not an error.
|
|
126
135
|
var loadedBuildSha = null;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (_buildShaParsed && typeof _buildShaParsed.sha === 'string') {
|
|
131
|
-
loadedBuildSha = _buildShaParsed.sha;
|
|
132
|
-
}
|
|
133
|
-
} catch (_) {
|
|
134
|
-
// lib/build-sha.json missing/unreadable/malformed — loadedBuildSha stays
|
|
135
|
-
// null, which get_build_status reports honestly rather than guessing.
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (checkStaleInodes()) {
|
|
139
|
-
console.warn('[daemon] WARNING: this process is serving STALE code — on-disk JS has been replaced');
|
|
140
|
-
console.warn('[daemon] WARNING: restart the daemon to load the new build:');
|
|
141
|
-
console.warn('[daemon] WARNING: systemctl restart clagentic-console');
|
|
142
|
-
console.warn('[daemon] WARNING: — or — clagentic-console --restart');
|
|
143
|
-
}
|
|
136
|
+
loadedBuildSha = buildIdentity.loaded.sha;
|
|
137
|
+
console.log("[daemon] Build: sha=" + (loadedBuildSha || "(none)") +
|
|
138
|
+
" files=" + (buildIdentity.loaded.contentHash ? buildIdentity.loaded.contentHash.slice(0, 12) : "(unreadable)"));
|
|
144
139
|
|
|
145
140
|
|
|
146
141
|
// --- Single-user to multi-user migration (lr-ec2d) ---
|
|
@@ -1253,25 +1248,19 @@ var relay = createServer({
|
|
|
1253
1248
|
console.log("[daemon] Restart requested via web UI");
|
|
1254
1249
|
spawnAndRestart();
|
|
1255
1250
|
},
|
|
1256
|
-
//
|
|
1257
|
-
//
|
|
1258
|
-
//
|
|
1259
|
-
//
|
|
1260
|
-
//
|
|
1261
|
-
//
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
//
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
getActiveCount: getActiveLiveCount,
|
|
1270
|
-
onIdle: function () {
|
|
1271
|
-
console.log("[daemon] Restarting to adopt new build (activeCount=" + getActiveLiveCount() + ")");
|
|
1272
|
-
spawnAndRestart();
|
|
1273
|
-
},
|
|
1274
|
-
});
|
|
1251
|
+
// The operator's click on "Restart to apply update". Without a token it
|
|
1252
|
+
// answers with the offer (both builds, the commits between them, what a
|
|
1253
|
+
// restart would end) and restarts nothing; with the token of an offer the
|
|
1254
|
+
// operator was shown it schedules the restart, which waits a bounded time
|
|
1255
|
+
// for running turns and re-checks that nothing unseen is live. See
|
|
1256
|
+
// lib/build-update-restart.js. Resolves { status, offer?, note? }.
|
|
1257
|
+
onRestartForBuildUpdate: function (token) {
|
|
1258
|
+
return buildUpdateRestart.request(token);
|
|
1259
|
+
},
|
|
1260
|
+
// The standing offer state for a client that connects: the held offer, or an
|
|
1261
|
+
// explicit "no offer" so a client that missed a retraction drops a dead action.
|
|
1262
|
+
onGetBuildUpdateDiagnostic: function () {
|
|
1263
|
+
return buildStandingOffer.forNewClient();
|
|
1275
1264
|
},
|
|
1276
1265
|
onSetProjectVisibility: function (slug, visibility) {
|
|
1277
1266
|
for (var i = 0; i < config.projects.length; i++) {
|
|
@@ -1385,19 +1374,89 @@ var relay = createServer({
|
|
|
1385
1374
|
},
|
|
1386
1375
|
});
|
|
1387
1376
|
|
|
1388
|
-
//
|
|
1389
|
-
//
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1377
|
+
// --- Build adoption: is the installed build the one this process loaded? ---
|
|
1378
|
+
// The verdict is buildIdentity.assess() (sha plus content hash), not the
|
|
1379
|
+
// kernel's deleted-mapping marker. Only a stale verdict seen on consecutive
|
|
1380
|
+
// checks is announced: in the journal, and as an offer in the UI. Announcing
|
|
1381
|
+
// restarts nothing; the one path to a restart is the operator's confirmed
|
|
1382
|
+
// click handled by buildUpdateRestart (lib/build-update-restart.js).
|
|
1383
|
+
var buildHistoryRepo = resolveHistoryRepo(config.buildSourceRepo, path.join(__dirname, ".."));
|
|
1384
|
+
|
|
1385
|
+
function listChangesBetweenBuilds(range) {
|
|
1386
|
+
return listBuildChanges({ repo: buildHistoryRepo, fromSha: range.fromSha, toSha: range.toSha });
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
function liveProjectsForOffer() {
|
|
1390
|
+
var out = [];
|
|
1391
|
+
relay.forEachProject(function (ctx, slug) {
|
|
1392
|
+
if (ctx && ctx.sm) out.push({ slug: slug, sm: ctx.sm });
|
|
1393
|
+
});
|
|
1394
|
+
return out;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
var BUILD_CHECK_MS = Number(readConsoleEnv("CLAGENTIC_CONSOLE_BUILD_CHECK_MS")) || 60 * 1000;
|
|
1398
|
+
// A failed change-list read is retried no more often than the journal reminder.
|
|
1399
|
+
var BUILD_REMINDER_EVERY = 30;
|
|
1400
|
+
|
|
1401
|
+
// The offer clients hold is reconciled against the monitor's confirmed stale
|
|
1402
|
+
// assessment after every poll (lib/build-update-standing.js): it is shown,
|
|
1403
|
+
// refreshed or retracted to match, and only when that differs from what was
|
|
1404
|
+
// last shown.
|
|
1405
|
+
var buildStandingOffer = createStandingOffer({
|
|
1406
|
+
listChanges: listChangesBetweenBuilds,
|
|
1407
|
+
desired: function () { return buildMonitor.confirmedStale(); },
|
|
1408
|
+
retryAfterMs: BUILD_CHECK_MS * BUILD_REMINDER_EVERY,
|
|
1409
|
+
broadcast: function (message) { relay.broadcastAll(message); },
|
|
1410
|
+
compose: function (a, changes) {
|
|
1411
|
+
return {
|
|
1412
|
+
type: "diagnostic",
|
|
1413
|
+
severity: "warning",
|
|
1414
|
+
source: "build-update",
|
|
1415
|
+
message: summarizeOffer(a) + " Restart to apply it when it suits you; nothing restarts on its own.",
|
|
1416
|
+
buildUpdate: buildOffer({ assessment: a, changes: changes }),
|
|
1417
|
+
actionable: { label: "Restart to apply update", action: "restart_for_build_update" },
|
|
1418
|
+
};
|
|
1419
|
+
},
|
|
1420
|
+
log: function (line) { console.log("[daemon] " + line); },
|
|
1421
|
+
});
|
|
1422
|
+
|
|
1423
|
+
var buildUpdateRestart = createBuildUpdateRestart({
|
|
1424
|
+
assess: function () { return buildIdentity.assess(); },
|
|
1425
|
+
getProjects: liveProjectsForOffer,
|
|
1426
|
+
listChanges: listChangesBetweenBuilds,
|
|
1427
|
+
restart: function () {
|
|
1428
|
+
console.log("[daemon] Restarting to adopt the installed build, as the operator confirmed");
|
|
1429
|
+
spawnAndRestart();
|
|
1430
|
+
},
|
|
1431
|
+
waitForIdleThenAct: waitForIdleThenAct,
|
|
1432
|
+
announce: function (message) {
|
|
1433
|
+
relay.broadcastAll({ type: "diagnostic", severity: "warning", source: "build-update", message: message });
|
|
1434
|
+
},
|
|
1435
|
+
log: function (line) { console.log("[daemon] " + line); },
|
|
1436
|
+
});
|
|
1437
|
+
|
|
1438
|
+
var buildMonitor = createBuildMonitor({
|
|
1439
|
+
assess: function () { return buildIdentity.assess(); },
|
|
1440
|
+
log: function (line) { console.log("[daemon] " + line); },
|
|
1441
|
+
reminderEvery: BUILD_REMINDER_EVERY,
|
|
1442
|
+
});
|
|
1443
|
+
|
|
1444
|
+
function runBuildCheck() {
|
|
1445
|
+
try {
|
|
1446
|
+
buildMonitor.check();
|
|
1447
|
+
} catch (e) {
|
|
1448
|
+
// A failed check is only a missed nudge; it must never take the daemon down.
|
|
1449
|
+
console.error("[daemon] Build check failed (non-fatal):", e && e.message ? e.message : e);
|
|
1396
1450
|
}
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1451
|
+
// Reconciled after every poll, including one whose check failed: the desired
|
|
1452
|
+
// state is whatever the monitor last confirmed. It does not throw.
|
|
1453
|
+
buildStandingOffer.reconcile(buildMonitor.confirmedStale());
|
|
1400
1454
|
}
|
|
1455
|
+
var buildCheckHandle = setInterval(runBuildCheck, BUILD_CHECK_MS);
|
|
1456
|
+
var buildFirstCheckHandle = setTimeout(runBuildCheck, Math.min(10000, BUILD_CHECK_MS));
|
|
1457
|
+
[buildCheckHandle, buildFirstCheckHandle].forEach(function (h) {
|
|
1458
|
+
if (h && typeof h.unref === "function") h.unref();
|
|
1459
|
+
});
|
|
1401
1460
|
|
|
1402
1461
|
var IDLE_MS = Number(readConsoleEnv("CLAGENTIC_CONSOLE_IDLE_RUNTIME_MS")) || 5 * 60 * 1000;
|
|
1403
1462
|
var REAP_MS = Number(readConsoleEnv("CLAGENTIC_CONSOLE_IDLE_REAPER_MS")) || 60 * 1000;
|
|
@@ -1408,9 +1467,10 @@ function stopCodexReaper() {
|
|
|
1408
1467
|
stopIdleReaper();
|
|
1409
1468
|
stopIdleReaper = null;
|
|
1410
1469
|
}
|
|
1411
|
-
if (
|
|
1412
|
-
clearInterval(
|
|
1413
|
-
|
|
1470
|
+
if (buildCheckHandle) {
|
|
1471
|
+
clearInterval(buildCheckHandle);
|
|
1472
|
+
clearTimeout(buildFirstCheckHandle);
|
|
1473
|
+
buildCheckHandle = null;
|
|
1414
1474
|
}
|
|
1415
1475
|
if (_memoryWatcher) {
|
|
1416
1476
|
_memoryWatcher.stop();
|
|
@@ -1419,6 +1479,9 @@ function stopCodexReaper() {
|
|
|
1419
1479
|
}
|
|
1420
1480
|
|
|
1421
1481
|
function shutdownProjects() {
|
|
1482
|
+
// First, before any project is destroyed: a rescan firing mid-shutdown would
|
|
1483
|
+
// re-add worktrees to projects that are being torn down.
|
|
1484
|
+
stopWorktreeRescans();
|
|
1422
1485
|
stopCodexReaper();
|
|
1423
1486
|
try {
|
|
1424
1487
|
var result = relay.destroyAll();
|
|
@@ -1592,13 +1655,34 @@ var ipc = createIPCServer(socketPath(), function (msg) {
|
|
|
1592
1655
|
//
|
|
1593
1656
|
// Read-only, mutates nothing, same OS-level socket gate as every other
|
|
1594
1657
|
// command on this connection (CONFIG_DIR is chmod 0700).
|
|
1595
|
-
case "get_build_status":
|
|
1658
|
+
case "get_build_status": {
|
|
1659
|
+
// state is exactly one of adopted / stale / inconclusive (with the
|
|
1660
|
+
// reason), from the sha and a content hash of the installed files. An
|
|
1661
|
+
// identical reinstall over this process is adopted; staleInodes is
|
|
1662
|
+
// reported for diagnosis and is not what decides it.
|
|
1663
|
+
var buildAssessment = buildIdentity.assess();
|
|
1596
1664
|
return {
|
|
1597
1665
|
ok: true,
|
|
1598
1666
|
loadedBuildSha: loadedBuildSha,
|
|
1667
|
+
installedBuildSha: buildAssessment.installedBuildSha,
|
|
1668
|
+
state: buildAssessment.state,
|
|
1669
|
+
reason: buildAssessment.reason,
|
|
1670
|
+
detail: buildAssessment.detail,
|
|
1671
|
+
loadedContentHash: buildAssessment.loadedContentHash,
|
|
1672
|
+
installedContentHash: buildAssessment.installedContentHash,
|
|
1599
1673
|
staleInodes: checkStaleInodes(),
|
|
1600
1674
|
pid: process.pid,
|
|
1601
1675
|
};
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
// Open a session, or send input to one, from a caller that is not the
|
|
1679
|
+
// browser. The same lib/session-input.js code the external-trigger file
|
|
1680
|
+
// drop runs, so a request gets the same result either way. Same OS-level
|
|
1681
|
+
// socket gate as every command here (CONFIG_DIR is chmod 0700); input never
|
|
1682
|
+
// counts as a human turn (session-input.js refuses that initiator).
|
|
1683
|
+
case "open_session":
|
|
1684
|
+
case "send_session_input":
|
|
1685
|
+
return require("./session-input-ipc").handleSessionCommand(relay.sessionInput, msg);
|
|
1602
1686
|
|
|
1603
1687
|
case "set_pin": {
|
|
1604
1688
|
config.pinHash = msg.pinHash || null;
|
|
@@ -1930,64 +2014,6 @@ function startListening() {
|
|
|
1930
2014
|
}
|
|
1931
2015
|
}
|
|
1932
2016
|
|
|
1933
|
-
// --- lr-e85fec: build-adoption diagnostic ---
|
|
1934
|
-
// Polls whether the on-disk build (lib/build-sha.json, rewritten by every
|
|
1935
|
-
// `npm install -g`) has moved past what THIS process loaded at startup
|
|
1936
|
-
// (loadedBuildSha, captured once above and never re-read). lr-22e8's
|
|
1937
|
-
// stale-inode/journald warning already surfaces this on the log, but
|
|
1938
|
-
// nothing acted on it (see lr-e85fec's task description — the same
|
|
1939
|
-
// warning fired 403 times before anyone noticed). This turns the
|
|
1940
|
-
// detector into an OFFERED, operator-initiated affordance instead of a
|
|
1941
|
-
// passive log line: a diagnostic with an actionable "restart to apply"
|
|
1942
|
-
// button the operator can act on when THEY choose, never an automatic
|
|
1943
|
-
// restart (see onRestartForBuildUpdate below — restart only ever fires
|
|
1944
|
-
// in direct response to that click).
|
|
1945
|
-
//
|
|
1946
|
-
// Only fires once per detected staleness (edge-triggered on
|
|
1947
|
-
// _buildUpdateAnnounced), not on every poll — a 5-minute interval would
|
|
1948
|
-
// otherwise re-toast the same condition indefinitely until the operator
|
|
1949
|
-
// actually restarts.
|
|
1950
|
-
var _buildUpdateAnnounced = false;
|
|
1951
|
-
var BUILD_UPDATE_POLL_MS = 5 * 60 * 1000;
|
|
1952
|
-
var _buildShaPath = path.join(__dirname, "build-sha.json");
|
|
1953
|
-
function _pollBuildUpdate() {
|
|
1954
|
-
try {
|
|
1955
|
-
var installedSha = readInstalledBuildSha(_buildShaPath);
|
|
1956
|
-
var result = checkForNewerInstalledBuild({
|
|
1957
|
-
loadedBuildSha: loadedBuildSha,
|
|
1958
|
-
installedBuildSha: installedSha,
|
|
1959
|
-
});
|
|
1960
|
-
if (result.stale && !_buildUpdateAnnounced) {
|
|
1961
|
-
_buildUpdateAnnounced = true;
|
|
1962
|
-
console.log("[daemon] Newer build installed on disk (" + result.installedBuildSha +
|
|
1963
|
-
") than this process loaded (" + result.loadedBuildSha + ") — offering restart in UI.");
|
|
1964
|
-
relay.broadcastAll({
|
|
1965
|
-
type: "diagnostic",
|
|
1966
|
-
severity: "warning",
|
|
1967
|
-
source: "build-update",
|
|
1968
|
-
message: "A newer build has been installed but is not yet running. Restart to apply it.",
|
|
1969
|
-
actionable: { label: "Restart to apply update", action: "restart_for_build_update" },
|
|
1970
|
-
});
|
|
1971
|
-
} else if (!result.stale) {
|
|
1972
|
-
// Covers the (rare) case of a manual downgrade/rollback reinstalling
|
|
1973
|
-
// the same SHA this process already has — re-arm so a subsequent
|
|
1974
|
-
// genuine update is announced again rather than staying suppressed
|
|
1975
|
-
// forever from one earlier announcement.
|
|
1976
|
-
_buildUpdateAnnounced = false;
|
|
1977
|
-
}
|
|
1978
|
-
} catch (e) {
|
|
1979
|
-
// A detection failure must never crash the daemon — this is a
|
|
1980
|
-
// best-effort UI nudge, not a load-bearing control path.
|
|
1981
|
-
console.error("[daemon] Build-update check failed (non-fatal):", e && e.message ? e.message : e);
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
1984
|
-
var _buildUpdateTimer = setInterval(_pollBuildUpdate, BUILD_UPDATE_POLL_MS);
|
|
1985
|
-
if (_buildUpdateTimer && typeof _buildUpdateTimer.unref === "function") _buildUpdateTimer.unref();
|
|
1986
|
-
// Run once shortly after startup too — otherwise an install that lands
|
|
1987
|
-
// moments after this process started would sit undetected for a full
|
|
1988
|
-
// poll interval before the operator sees anything.
|
|
1989
|
-
setTimeout(_pollBuildUpdate, 10000);
|
|
1990
|
-
|
|
1991
2017
|
// Auto-provision Linux accounts on startup if OS users mode is enabled.
|
|
1992
2018
|
// ACLs are NOT re-applied on every startup (too slow with recursive setfacl).
|
|
1993
2019
|
// ACLs are set when: projects are added, users are added, or visibility changes.
|
|
@@ -2091,6 +2117,17 @@ if (config.keepAwake && process.platform === "darwin") {
|
|
|
2091
2117
|
|
|
2092
2118
|
// --- Spawn new daemon and graceful restart ---
|
|
2093
2119
|
function spawnAndRestart() {
|
|
2120
|
+
// Under a supervisor the restart is an exit and nothing more. A replacement
|
|
2121
|
+
// spawned here is not the unit's main process, so the unit kills it with the
|
|
2122
|
+
// rest of its cgroup and then starts its own: one extra process killed, the
|
|
2123
|
+
// restart working only by accident. Self-respawn is for unsupervised starts.
|
|
2124
|
+
if (isSupervised()) {
|
|
2125
|
+
console.log("[daemon] Running under a supervisor: exiting with code " + RESTART_EXIT_CODE +
|
|
2126
|
+
" for it to start the replacement; not spawning one");
|
|
2127
|
+
updateHandoff = true;
|
|
2128
|
+
gracefulShutdown();
|
|
2129
|
+
return;
|
|
2130
|
+
}
|
|
2094
2131
|
try {
|
|
2095
2132
|
updateHandoff = true;
|
|
2096
2133
|
ipc.close();
|
|
@@ -2108,13 +2145,14 @@ function spawnAndRestart() {
|
|
|
2108
2145
|
detached: true,
|
|
2109
2146
|
windowsHide: true,
|
|
2110
2147
|
stdio: ["ignore", logFd, logFd],
|
|
2111
|
-
env: Object.assign(
|
|
2148
|
+
env: Object.assign(unsupervisedEnv(), {
|
|
2112
2149
|
CLAGENTIC_CONSOLE_CONFIG: restartConfigPath(),
|
|
2113
2150
|
CLAGENTIC_CONSOLE_HOME: restartClagenticHome,
|
|
2114
2151
|
}),
|
|
2115
2152
|
});
|
|
2116
2153
|
child.unref();
|
|
2117
2154
|
fs.closeSync(logFd);
|
|
2155
|
+
successorSpawned = true;
|
|
2118
2156
|
config.pid = child.pid;
|
|
2119
2157
|
// Write PID synchronously before exit so the config file is not
|
|
2120
2158
|
// left with a stale PID during the restart window. saveConfig() is
|
|
@@ -2127,7 +2165,7 @@ function spawnAndRestart() {
|
|
|
2127
2165
|
saveConfig(config);
|
|
2128
2166
|
}
|
|
2129
2167
|
console.log("[daemon] Spawned new daemon (PID " + child.pid + "), exiting.");
|
|
2130
|
-
process.exit(
|
|
2168
|
+
process.exit(RESTART_EXIT_CODE);
|
|
2131
2169
|
} catch (e) {
|
|
2132
2170
|
console.error("[daemon] Restart failed:", e.message);
|
|
2133
2171
|
process.exit(1);
|
|
@@ -2154,14 +2192,15 @@ function spawnAndRestart() {
|
|
|
2154
2192
|
}
|
|
2155
2193
|
|
|
2156
2194
|
// --- Graceful shutdown ---
|
|
2157
|
-
var updateHandoff = false; // true when shutting down
|
|
2195
|
+
var updateHandoff = false; // true when shutting down to be replaced (exit code RESTART_EXIT_CODE)
|
|
2196
|
+
var successorSpawned = false; // true once a self-spawned replacement has its pid saved in the config
|
|
2158
2197
|
var shutdownStarted = false;
|
|
2159
2198
|
|
|
2160
2199
|
function gracefulShutdown() {
|
|
2161
2200
|
try { console.log("[daemon] Shutting down..."); } catch (e) {}
|
|
2162
2201
|
if (shutdownStarted) return;
|
|
2163
2202
|
shutdownStarted = true;
|
|
2164
|
-
var exitCode = updateHandoff ?
|
|
2203
|
+
var exitCode = updateHandoff ? RESTART_EXIT_CODE : 0;
|
|
2165
2204
|
|
|
2166
2205
|
if (caffeinateProc) {
|
|
2167
2206
|
try { caffeinateProc.kill(); } catch (e) {}
|
|
@@ -2169,8 +2208,8 @@ function gracefulShutdown() {
|
|
|
2169
2208
|
|
|
2170
2209
|
ipc.close();
|
|
2171
2210
|
|
|
2172
|
-
// Remove PID from config (skip
|
|
2173
|
-
if (!
|
|
2211
|
+
// Remove PID from config (skip when a self-spawned replacement's PID is already saved)
|
|
2212
|
+
if (!successorSpawned) {
|
|
2174
2213
|
try {
|
|
2175
2214
|
var c = loadConfig();
|
|
2176
2215
|
if (c && c.pid === process.pid) {
|
package/lib/debug-log.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Lines worth keeping off the journal by default: they fire per stream event.
|
|
4
|
+
// Set CLAGENTIC_CONSOLE_DEBUG to see them. The variable is read at each call so
|
|
5
|
+
// an operator can start the daemon with it and a test can set it for one case.
|
|
6
|
+
|
|
7
|
+
var { readConsoleEnv } = require("./env-compat");
|
|
8
|
+
|
|
9
|
+
function debugEnabled() {
|
|
10
|
+
return !!readConsoleEnv("CLAGENTIC_CONSOLE_DEBUG");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function debugLog(line) {
|
|
14
|
+
if (debugEnabled()) console.log(line);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { debugLog: debugLog, debugEnabled: debugEnabled };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Everything that must be written before the process ends, behind ONE
|
|
4
|
+
// process "exit" listener however many callers register.
|
|
5
|
+
//
|
|
6
|
+
// Each project's session manager used to add its own listener, so a daemon with
|
|
7
|
+
// fifty projects added fifty to `process` at startup and tripped Node's
|
|
8
|
+
// MaxListenersExceededWarning (the default cap is 10; the daemon raises it, and
|
|
9
|
+
// raising it again would only move the line). The listener is installed when
|
|
10
|
+
// the first flusher registers and removed when the last one unregisters, so a
|
|
11
|
+
// daemon that opens and closes projects does not accumulate any.
|
|
12
|
+
|
|
13
|
+
var flushers = new Set();
|
|
14
|
+
var installed = false;
|
|
15
|
+
|
|
16
|
+
function flushAll() {
|
|
17
|
+
flushers.forEach(function (flush) {
|
|
18
|
+
// One flusher failing must not stop the others: this is the last chance
|
|
19
|
+
// any of them gets to write.
|
|
20
|
+
try { flush(); }
|
|
21
|
+
catch (e) { console.error("[exit-flush] flush failed:", e && e.message ? e.message : e); }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {function(): void} flush - runs synchronously when the process exits.
|
|
27
|
+
* @returns {function(): void} unregister; safe to call more than once.
|
|
28
|
+
*/
|
|
29
|
+
function registerExitFlush(flush) {
|
|
30
|
+
flushers.add(flush);
|
|
31
|
+
if (!installed) {
|
|
32
|
+
process.on("exit", flushAll);
|
|
33
|
+
installed = true;
|
|
34
|
+
}
|
|
35
|
+
return function unregister() {
|
|
36
|
+
flushers.delete(flush);
|
|
37
|
+
if (installed && flushers.size === 0) {
|
|
38
|
+
process.removeListener("exit", flushAll);
|
|
39
|
+
installed = false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = { registerExitFlush: registerExitFlush };
|