@clagentic/console 1.12.0-beta.1 → 1.12.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/LICENSES/README.md +5 -0
- package/README.md +1 -0
- package/bin/cli.js +5 -2
- package/lib/agent-roster-ws.js +84 -0
- package/lib/agent-roster.js +312 -0
- package/lib/auth-required-notify.js +42 -0
- package/lib/build-changes.js +8 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-notify.js +45 -0
- package/lib/build-update-offer.js +34 -11
- package/lib/build-update-standing.js +34 -14
- package/lib/claude-settings-env.js +142 -0
- package/lib/cli/duration.js +27 -0
- package/lib/cli/schedule-input-subcommands.js +1 -22
- package/lib/cli/session-subcommands.js +60 -11
- package/lib/client-address.js +44 -0
- package/lib/daemon.js +31 -10
- package/lib/idle-compaction-setting.js +203 -0
- package/lib/mcp-bridge-credential.js +41 -0
- package/lib/notification-prefs.js +18 -22
- package/lib/notify/core.js +210 -0
- package/lib/notify/index.js +31 -0
- package/lib/notify/live-prompts.js +36 -0
- package/lib/notify/payload.js +62 -0
- package/lib/notify/target.js +5 -0
- package/lib/notify/type-registry.js +81 -0
- package/lib/notify/types.js +57 -0
- package/lib/open-sockets.js +27 -0
- package/lib/outbound-access.js +85 -0
- package/lib/outbound-entry.js +116 -0
- package/lib/outbound-ledger.js +306 -0
- package/lib/outbound-query.js +153 -0
- package/lib/pending-prompts.js +31 -16
- package/lib/project-connection.js +48 -8
- package/lib/project-filesystem.js +43 -5
- package/lib/project-http.js +9 -1
- package/lib/project-loop.js +38 -26
- package/lib/project-notifications.js +122 -39
- package/lib/project-prompt-responses.js +1 -1
- package/lib/project-sessions.js +11 -1
- package/lib/project-user-mention.js +22 -34
- package/lib/project-user-message.js +208 -4
- package/lib/project-user-shell.js +298 -0
- package/lib/project.js +41 -5
- package/lib/prompt-answer.js +145 -0
- package/lib/prompt-expiry.js +50 -0
- package/lib/prompt-registry.js +98 -25
- package/lib/prompt-reminders.js +38 -33
- package/lib/prompt-source.js +59 -8
- package/lib/public/app.js +32 -2
- package/lib/public/css/agent-messages.css +96 -0
- package/lib/public/css/agent-roster.css +93 -0
- package/lib/public/css/diagnostics.css +29 -1
- package/lib/public/css/home-hub.css +12 -0
- package/lib/public/css/icon-strip.css +9 -0
- package/lib/public/css/input.css +20 -141
- package/lib/public/css/login-panel.css +73 -0
- package/lib/public/css/menus.css +2 -2
- package/lib/public/css/mobile-nav.css +11 -0
- package/lib/public/css/sidebar.css +18 -0
- package/lib/public/css/team-panel.css +1 -6
- package/lib/public/css/team-view.css +101 -0
- package/lib/public/css/title-bar.css +10 -0
- package/lib/public/css/user-shell.css +144 -0
- package/lib/public/index.html +44 -7
- package/lib/public/modules/activity-state.js +20 -4
- package/lib/public/modules/agent-avatar-picker.js +162 -0
- package/lib/public/modules/agent-avatar.js +153 -0
- package/lib/public/modules/agent-messages.js +285 -0
- package/lib/public/modules/agent-roster.js +157 -0
- package/lib/public/modules/app-connection.js +34 -5
- package/lib/public/modules/app-messages.js +55 -16
- package/lib/public/modules/app-notifications.js +104 -75
- package/lib/public/modules/app-panels.js +26 -3
- package/lib/public/modules/app-projects.js +3 -1
- package/lib/public/modules/app-rate-limit.js +8 -165
- package/lib/public/modules/app-rendering.js +32 -7
- package/lib/public/modules/build-update-sessions.js +81 -0
- package/lib/public/modules/collapsible-text.js +33 -18
- package/lib/public/modules/compaction-state.js +34 -0
- package/lib/public/modules/custom-icons.js +23 -5
- package/lib/public/modules/diagnostics.js +61 -57
- package/lib/public/modules/env-shadow-notice.js +34 -0
- package/lib/public/modules/injected-identity.js +24 -21
- package/lib/public/modules/input.js +176 -15
- package/lib/public/modules/login-panel.js +136 -0
- package/lib/public/modules/login-parser.js +73 -0
- package/lib/public/modules/login-tab.js +66 -0
- package/lib/public/modules/notifications.js +9 -1
- package/lib/public/modules/notify-client.js +246 -0
- package/lib/public/modules/pending-term-request.js +30 -0
- package/lib/public/modules/project-icon.js +22 -2
- package/lib/public/modules/project-settings.js +5 -0
- package/lib/public/modules/prompt-state.js +3 -3
- package/lib/public/modules/prompts.js +1 -1
- package/lib/public/modules/queued-button.js +11 -0
- package/lib/public/modules/scheduled-input-actions.js +12 -4
- package/lib/public/modules/scheduled-outbox.js +230 -0
- package/lib/public/modules/send-now.js +200 -0
- package/lib/public/modules/server-settings.js +50 -1
- package/lib/public/modules/shell-card.js +76 -0
- package/lib/public/modules/shell-line.js +49 -0
- package/lib/public/modules/shell-queue.js +253 -0
- package/lib/public/modules/shell-settings-controls.js +76 -0
- package/lib/public/modules/sidebar-mobile.js +3 -3
- package/lib/public/modules/sidebar-sessions.js +8 -0
- package/lib/public/modules/sidebar-users.js +5 -7
- package/lib/public/modules/team-panel.js +30 -88
- package/lib/public/modules/team-view.js +211 -0
- package/lib/public/modules/terminal-links.js +193 -0
- package/lib/public/modules/terminal.js +84 -107
- package/lib/public/modules/tools.js +19 -0
- package/lib/public/modules/user-shell.js +824 -0
- package/lib/public/notify-sw-logic.js +252 -0
- package/lib/public/notify-target.js +157 -0
- package/lib/public/style.css +5 -0
- package/lib/public/sw.js +20 -69
- package/lib/push.js +63 -19
- package/lib/queued-chat.js +392 -0
- package/lib/runtime-env.js +1 -0
- package/lib/scheduled-input/ws.js +67 -9
- package/lib/sdk-bridge.js +184 -73
- package/lib/sdk-message-processor.js +124 -76
- package/lib/server-auth.js +6 -4
- package/lib/server-dm.js +11 -20
- package/lib/server-settings.js +39 -1
- package/lib/server.js +112 -16
- package/lib/session-directory.js +39 -12
- package/lib/session-end.js +97 -0
- package/lib/session-input-ipc.js +37 -1
- package/lib/session-input.js +263 -21
- package/lib/session-liveness.js +53 -0
- package/lib/session-reclaim.js +37 -2
- package/lib/session-resume.js +1 -0
- package/lib/session-settings-file.js +53 -0
- package/lib/sessions.js +80 -9
- package/lib/team-traffic-ws.js +68 -0
- package/lib/team-traffic.js +318 -0
- package/lib/usage-store.js +36 -7
- package/lib/user-shell-settings.js +105 -0
- package/lib/vendor-auth.js +33 -2
- package/lib/ws-schema.js +33 -5
- package/lib/yoke/adapters/claude-capabilities.js +2 -0
- package/lib/yoke/adapters/claude-vendor.js +17 -1
- package/lib/yoke/adapters/claude-worker.js +39 -11
- package/lib/yoke/adapters/claude.js +225 -6
- package/lib/yoke/adapters/codex-capabilities.js +6 -1
- package/lib/yoke/adapters/codex-user-shell.js +265 -0
- package/lib/yoke/adapters/codex-vendor.js +7 -0
- package/lib/yoke/adapters/codex.js +186 -52
- package/lib/yoke/auth-checks.js +17 -2
- package/lib/yoke/codex-app-server.js +8 -2
- package/lib/yoke/index.js +21 -3
- package/lib/yoke/interface.js +54 -1
- package/lib/yoke/mcp-bridge-server.js +12 -8
- package/lib/yoke/provider-credentials.js +24 -0
- package/lib/yoke/registry.js +40 -1
- package/lib/yoke/user-shell.js +224 -0
- package/package.json +2 -2
- package/scripts/check-test-count.js +14 -0
- package/lib/public/modules/build-notice-gate.js +0 -73
package/lib/daemon.js
CHANGED
|
@@ -41,6 +41,7 @@ var { DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiv
|
|
|
41
41
|
var { validateMemAvailableThresholdMB, validateTokensPerMbHeadroom } = require("./memory-setting-validate");
|
|
42
42
|
var { startMemoryHighWatcher, checkAppliedMemoryCeiling } = require("./memory-limits");
|
|
43
43
|
var { readPermissionSettings, DEFAULT_OPENED_SESSION_MODE } = require("./permission-settings");
|
|
44
|
+
var userShellSettings = require("./user-shell-settings");
|
|
44
45
|
var { createDrain } = require("./drain");
|
|
45
46
|
var { setNewWorkGate } = require("./new-work-gate");
|
|
46
47
|
var { shedMemory } = require("./memory-shed");
|
|
@@ -49,6 +50,7 @@ var { createBuildMonitor } = require("./build-monitor");
|
|
|
49
50
|
var { createBuildUpdateRestart } = require("./build-update-restart");
|
|
50
51
|
var { composeNotice, noticeCooldownFrom, composeRestartingNotice } = require("./build-update-offer");
|
|
51
52
|
var { createStandingOffer } = require("./build-update-standing");
|
|
53
|
+
var buildUpdateNotify = require("./build-update-notify");
|
|
52
54
|
var { listBuildChanges, resolveHistoryRepo } = require("./build-changes");
|
|
53
55
|
var { RESTART_EXIT_CODE, isSupervised, unsupervisedEnv } = require("./supervisor");
|
|
54
56
|
var liteDetect = require("./lite-detect");
|
|
@@ -1047,6 +1049,14 @@ var relay = createServer({
|
|
|
1047
1049
|
saveConfig(config);
|
|
1048
1050
|
return { ok: true, settings: readPermissionSettings(config) };
|
|
1049
1051
|
},
|
|
1052
|
+
onGetUserShellSettings: function () {
|
|
1053
|
+
return userShellSettings.readUserShellSettings(config);
|
|
1054
|
+
},
|
|
1055
|
+
onSetUserShellSettings: function (values) {
|
|
1056
|
+
userShellSettings.applySettingChanges(config, values);
|
|
1057
|
+
saveConfig(config);
|
|
1058
|
+
return { ok: true, settings: userShellSettings.readUserShellSettings(config) };
|
|
1059
|
+
},
|
|
1050
1060
|
onGetProjectDefaultMode: function (slug) {
|
|
1051
1061
|
for (var i = 0; i < config.projects.length; i++) {
|
|
1052
1062
|
if (config.projects[i].slug === slug) {
|
|
@@ -1276,10 +1286,10 @@ var relay = createServer({
|
|
|
1276
1286
|
onRestartForBuildUpdate: function (token) {
|
|
1277
1287
|
return buildUpdateRestart.request(token);
|
|
1278
1288
|
},
|
|
1279
|
-
//
|
|
1280
|
-
//
|
|
1281
|
-
|
|
1282
|
-
|
|
1289
|
+
// A banner of a system notification was closed by the operator in some page:
|
|
1290
|
+
// the offer then stays quiet for the cooldown (lib/build-update-standing.js).
|
|
1291
|
+
onNotificationResolved: function (type) {
|
|
1292
|
+
if (type === buildUpdateNotify.TYPE) buildStandingOffer.declined();
|
|
1283
1293
|
},
|
|
1284
1294
|
onSetProjectVisibility: function (slug, visibility) {
|
|
1285
1295
|
for (var i = 0; i < config.projects.length; i++) {
|
|
@@ -1416,8 +1426,8 @@ function liveProjectsForOffer() {
|
|
|
1416
1426
|
var BUILD_CHECK_MS = Number(readConsoleEnv("CLAGENTIC_CONSOLE_BUILD_CHECK_MS")) || 60 * 1000;
|
|
1417
1427
|
// A failed change-list read is retried no more often than the journal reminder.
|
|
1418
1428
|
var BUILD_REMINDER_EVERY = 30;
|
|
1419
|
-
// How long a
|
|
1420
|
-
//
|
|
1429
|
+
// How long a declined build-update offer stays quiet before the same
|
|
1430
|
+
// offer may show again (lib/build-update-standing.js).
|
|
1421
1431
|
var BUILD_NOTICE_COOLDOWN_MS = noticeCooldownFrom(readConsoleEnv("CLAGENTIC_CONSOLE_BUILD_NOTICE_COOLDOWN_MS"));
|
|
1422
1432
|
|
|
1423
1433
|
// The offer clients hold is reconciled against the monitor's confirmed stale
|
|
@@ -1428,10 +1438,10 @@ var buildStandingOffer = createStandingOffer({
|
|
|
1428
1438
|
listChanges: listChangesBetweenBuilds,
|
|
1429
1439
|
desired: function () { return buildMonitor.confirmedStale(); },
|
|
1430
1440
|
retryAfterMs: BUILD_CHECK_MS * BUILD_REMINDER_EVERY,
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1441
|
+
quietMs: BUILD_NOTICE_COOLDOWN_MS,
|
|
1442
|
+
show: function (message) { buildUpdateNotify.showBuildOffer(relay.notifyEnv(), message); },
|
|
1443
|
+
retract: function () { buildUpdateNotify.resolveBuildOffer(relay.notifyEnv()); },
|
|
1444
|
+
compose: composeNotice,
|
|
1435
1445
|
log: function (line) { console.log("[daemon] " + line); },
|
|
1436
1446
|
});
|
|
1437
1447
|
|
|
@@ -1444,6 +1454,9 @@ var buildUpdateRestart = createBuildUpdateRestart({
|
|
|
1444
1454
|
spawnAndRestart();
|
|
1445
1455
|
},
|
|
1446
1456
|
onScheduled: function () {
|
|
1457
|
+
// The offer is closed on every surface; the confirmation card a page holds
|
|
1458
|
+
// is the answer to that operator's own click, so it is withdrawn directly.
|
|
1459
|
+
buildUpdateNotify.resolveBuildOffer(relay.notifyEnv());
|
|
1447
1460
|
relay.broadcastAll({ type: "diagnostic_retract", source: "build-update" });
|
|
1448
1461
|
relay.broadcastAll(composeRestartingNotice());
|
|
1449
1462
|
},
|
|
@@ -1711,9 +1724,17 @@ var ipc = createIPCServer(socketPath(), function (msg) {
|
|
|
1711
1724
|
// counts as a human turn (session-input.js refuses that initiator).
|
|
1712
1725
|
case "open_session":
|
|
1713
1726
|
case "send_session_input":
|
|
1727
|
+
case "end_session":
|
|
1728
|
+
case "answer_prompt":
|
|
1714
1729
|
case "list_sessions":
|
|
1715
1730
|
return require("./session-input-ipc").handleSessionCommand(relay.sessionInput, msg);
|
|
1716
1731
|
|
|
1732
|
+
// What one session sent out (the sender-side outbound ledger). Read-only;
|
|
1733
|
+
// the prompt text of an entry is shown only when the caller may read the
|
|
1734
|
+
// target session (lib/outbound-access.js). Same OS-level socket gate.
|
|
1735
|
+
case "list_outbound":
|
|
1736
|
+
return require("./session-input-ipc").handleOutboundCommand(relay.outboundQuery, msg);
|
|
1737
|
+
|
|
1717
1738
|
// Scheduled input: text sent into a session later, once or on a repeat with
|
|
1718
1739
|
// an end. The same service the clock button in the browser uses, so a record
|
|
1719
1740
|
// made here shows there and the reverse. Same OS-level socket gate as the
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// idle-compaction-setting.js - read and write the Claude user setting
|
|
2
|
+
// "idleCompaction" in the Claude user settings file, the same file the CLI
|
|
3
|
+
// reads. The console owns that one key only: every other key is preserved.
|
|
4
|
+
//
|
|
5
|
+
// The setting is off-or-default by design. In the Claude SDK types, false stops
|
|
6
|
+
// Claude Code from compacting an idle session and true does not turn it on, so
|
|
7
|
+
// this module only ever writes false, or removes the key to return to the CLI
|
|
8
|
+
// default. A missing file reads as the default. A file that exists but cannot
|
|
9
|
+
// be read or parsed is reported and never written over.
|
|
10
|
+
|
|
11
|
+
var fs = require("fs");
|
|
12
|
+
var os = require("os");
|
|
13
|
+
var path = require("path");
|
|
14
|
+
var childProcess = require("child_process");
|
|
15
|
+
var claudeSettingsEnv = require("./claude-settings-env");
|
|
16
|
+
|
|
17
|
+
var KEY = "idleCompaction";
|
|
18
|
+
|
|
19
|
+
// "default" = key absent (the CLI decides), "off" = false, "on" = true as
|
|
20
|
+
// written by someone else; the console never writes "on".
|
|
21
|
+
function valueName(parsed) {
|
|
22
|
+
if (parsed[KEY] === false) return "off";
|
|
23
|
+
if (parsed[KEY] === true) return "on";
|
|
24
|
+
return "default";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function readParsed(file) {
|
|
28
|
+
var text;
|
|
29
|
+
var fd = null;
|
|
30
|
+
try {
|
|
31
|
+
// O_NONBLOCK so opening a FIFO returns at once instead of waiting for a
|
|
32
|
+
// writer; the type check on the open descriptor closes the check/open race.
|
|
33
|
+
fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
|
|
34
|
+
if (!fs.fstatSync(fd).isFile()) {
|
|
35
|
+
return { ok: false, error: "Settings path is not a regular file; it was left unchanged" };
|
|
36
|
+
}
|
|
37
|
+
text = fs.readFileSync(fd, "utf8");
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if (e && e.code === "ENOENT") return { ok: true, parsed: {}, exists: false };
|
|
40
|
+
return { ok: false, error: "Settings file could not be read: " + (e.code || e.message) };
|
|
41
|
+
} finally {
|
|
42
|
+
if (fd !== null) fs.closeSync(fd);
|
|
43
|
+
}
|
|
44
|
+
var parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = JSON.parse(text);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
return { ok: false, error: "Settings file is not valid JSON; it was left unchanged" };
|
|
49
|
+
}
|
|
50
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
51
|
+
return { ok: false, error: "Settings file is not a JSON object; it was left unchanged" };
|
|
52
|
+
}
|
|
53
|
+
return { ok: true, parsed: parsed, exists: true };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The real file a settings path points at. A dangling link resolves to its
|
|
57
|
+
// link target so a first write creates the target rather than replacing the link.
|
|
58
|
+
function resolveTarget(file) {
|
|
59
|
+
try {
|
|
60
|
+
return fs.realpathSync(file);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
try {
|
|
63
|
+
if (fs.lstatSync(file).isSymbolicLink()) {
|
|
64
|
+
return resolveTarget(path.resolve(path.dirname(file), fs.readlinkSync(file)));
|
|
65
|
+
}
|
|
66
|
+
} catch (e2) { /* not a link: use the path as given */ }
|
|
67
|
+
return file;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {string} file absolute path of the user settings file
|
|
73
|
+
* @returns {{ok: boolean, value?: string, error?: string}}
|
|
74
|
+
*/
|
|
75
|
+
function readSetting(file) {
|
|
76
|
+
var r = readParsed(file);
|
|
77
|
+
if (!r.ok) return { ok: false, error: r.error };
|
|
78
|
+
return { ok: true, value: valueName(r.parsed) };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {string} file absolute path of the user settings file
|
|
83
|
+
* @param {"off"|"default"} mode off writes false; default removes the key
|
|
84
|
+
* @returns {{ok: boolean, value?: string, error?: string}}
|
|
85
|
+
*/
|
|
86
|
+
function writeSetting(file, mode) {
|
|
87
|
+
if (mode !== "off" && mode !== "default") {
|
|
88
|
+
return { ok: false, error: "Value must be off or default" };
|
|
89
|
+
}
|
|
90
|
+
// Write through a symlink to its target so the link survives the rename.
|
|
91
|
+
file = resolveTarget(file);
|
|
92
|
+
var r = readParsed(file);
|
|
93
|
+
if (!r.ok) return { ok: false, error: r.error };
|
|
94
|
+
var parsed = r.parsed;
|
|
95
|
+
if (mode === "default") {
|
|
96
|
+
if (!(KEY in parsed)) return { ok: true, value: "default" };
|
|
97
|
+
delete parsed[KEY];
|
|
98
|
+
} else {
|
|
99
|
+
parsed[KEY] = false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var dir = path.dirname(file);
|
|
103
|
+
var tmp = path.join(dir, "." + path.basename(file) + "." + process.pid + "." + Date.now() + ".tmp");
|
|
104
|
+
try {
|
|
105
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
106
|
+
var mode0 = r.exists ? fs.statSync(file).mode & 0o777 : 0o600;
|
|
107
|
+
var fd = fs.openSync(tmp, "wx", mode0);
|
|
108
|
+
try {
|
|
109
|
+
fs.writeFileSync(fd, JSON.stringify(parsed, null, 2) + "\n");
|
|
110
|
+
fs.fchmodSync(fd, mode0);
|
|
111
|
+
fs.fsyncSync(fd);
|
|
112
|
+
} finally {
|
|
113
|
+
fs.closeSync(fd);
|
|
114
|
+
}
|
|
115
|
+
fs.renameSync(tmp, file);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
try { fs.unlinkSync(tmp); } catch (e2) { /* tmp may not exist */ }
|
|
118
|
+
return { ok: false, error: "Settings file could not be written: " + (e.code || e.message) };
|
|
119
|
+
}
|
|
120
|
+
return { ok: true, value: valueName(parsed) };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The settings file of the account a request acts for, never anyone else's.
|
|
125
|
+
* Under os-users mode that is the user's own home; otherwise it is the file the
|
|
126
|
+
* daemon account's CLI reads (claude-settings-env.js).
|
|
127
|
+
*
|
|
128
|
+
* @param {{osUserInfo?: {home: string}|null, osUsers?: boolean, homeDir?: string}} opts
|
|
129
|
+
* @returns {?string} null when the owner's file cannot be named
|
|
130
|
+
*/
|
|
131
|
+
function settingsFileFor(opts) {
|
|
132
|
+
opts = opts || {};
|
|
133
|
+
if (opts.osUsers) {
|
|
134
|
+
if (!opts.osUserInfo || !opts.osUserInfo.home) return null;
|
|
135
|
+
return path.join(opts.osUserInfo.home, ".claude", "settings.json");
|
|
136
|
+
}
|
|
137
|
+
return claudeSettingsEnv.resolveSettingsFile({ homeDir: opts.homeDir || os.homedir() });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Run a read or write against the owner's file. Under os-users mode the work
|
|
142
|
+
* runs in a child process under the owner's uid and gid, the same way other
|
|
143
|
+
* per-user file access does, so the daemon never touches another account's
|
|
144
|
+
* file with its own privileges.
|
|
145
|
+
*
|
|
146
|
+
* @param {"read"|"write"} op
|
|
147
|
+
* @param {"off"|"default"|null} mode for write
|
|
148
|
+
* @param {{osUserInfo?: object|null, osUsers?: boolean, homeDir?: string}} opts
|
|
149
|
+
* @returns {Promise<{ok: boolean, value?: string, error?: string}>}
|
|
150
|
+
*/
|
|
151
|
+
function applyForOwner(op, mode, opts) {
|
|
152
|
+
var file = settingsFileFor(opts);
|
|
153
|
+
if (!file) return Promise.resolve({ ok: false, error: "The settings file for this account is not available" });
|
|
154
|
+
// One chain per settings file: read-modify-rename must not interleave, or the
|
|
155
|
+
// last rename silently drops an earlier request. A failed link does not break
|
|
156
|
+
// the chain because each link resolves to a result object, never rejects.
|
|
157
|
+
var prev = queues.get(file) || Promise.resolve();
|
|
158
|
+
var next = prev.then(function () { return runForOwner(op, mode, opts, file); });
|
|
159
|
+
var tail = next.then(function () {}, function () {});
|
|
160
|
+
queues.set(file, tail);
|
|
161
|
+
tail.then(function () { if (queues.get(file) === tail) queues.delete(file); });
|
|
162
|
+
return next;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
var queues = new Map();
|
|
166
|
+
|
|
167
|
+
function runForOwner(op, mode, opts, file) {
|
|
168
|
+
var run = op === "write" ? function () { return writeSetting(file, mode); } : function () { return readSetting(file); };
|
|
169
|
+
if (!(opts && opts.osUsers)) {
|
|
170
|
+
try {
|
|
171
|
+
return Promise.resolve(run());
|
|
172
|
+
} catch (e) {
|
|
173
|
+
return Promise.resolve({ ok: false, error: "The settings file could not be accessed: " + (e.code || e.message) });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
var script = "var m=require(" + JSON.stringify(__filename) + ");" +
|
|
177
|
+
"process.stdout.write(JSON.stringify(" +
|
|
178
|
+
(op === "write" ? "m.writeSetting(" + JSON.stringify(file) + "," + JSON.stringify(mode) + ")" : "m.readSetting(" + JSON.stringify(file) + ")") + "));";
|
|
179
|
+
// Async so a slow or stuck child never blocks the daemon event loop.
|
|
180
|
+
return new Promise(function (resolve) {
|
|
181
|
+
childProcess.execFile(process.execPath, ["-e", script], {
|
|
182
|
+
encoding: "utf8",
|
|
183
|
+
timeout: 10000,
|
|
184
|
+
uid: opts.osUserInfo.uid,
|
|
185
|
+
gid: opts.osUserInfo.gid,
|
|
186
|
+
}, function (err, out) {
|
|
187
|
+
if (err) return resolve({ ok: false, error: "The settings file for this account could not be reached" });
|
|
188
|
+
try {
|
|
189
|
+
resolve(JSON.parse(String(out).trim()));
|
|
190
|
+
} catch (e) {
|
|
191
|
+
resolve({ ok: false, error: "The settings file for this account could not be reached" });
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
module.exports = {
|
|
198
|
+
KEY: KEY,
|
|
199
|
+
readSetting: readSetting,
|
|
200
|
+
writeSetting: writeSetting,
|
|
201
|
+
settingsFileFor: settingsFileFor,
|
|
202
|
+
applyForOwner: applyForOwner,
|
|
203
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// mcp-bridge-credential.js - the per-project credential the local MCP bridge
|
|
4
|
+
// child presents to the daemon. The daemon holds one random secret in memory
|
|
5
|
+
// for its lifetime (never written anywhere); the credential for a project is
|
|
6
|
+
// HMAC-SHA256(secret, slug), so a credential for one project is refused on any
|
|
7
|
+
// other. The peer address of a request grants nothing: a reverse proxy on the
|
|
8
|
+
// same host makes every client look local.
|
|
9
|
+
|
|
10
|
+
var crypto = require("crypto");
|
|
11
|
+
|
|
12
|
+
var ENV_NAME = "CLAGENTIC_CONSOLE_MCP_BRIDGE_TOKEN";
|
|
13
|
+
var HEADER_NAME = "x-clagentic-console-mcp-bridge-token";
|
|
14
|
+
|
|
15
|
+
var _secret = null;
|
|
16
|
+
|
|
17
|
+
function secret() {
|
|
18
|
+
if (!_secret) _secret = crypto.randomBytes(32);
|
|
19
|
+
return _secret;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function credentialFor(slug) {
|
|
23
|
+
return crypto.createHmac("sha256", secret()).update(String(slug)).digest("hex");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Constant-time and total: a missing, non-string or wrong-length value is a
|
|
27
|
+
// plain false. Both sides are hashed first so timingSafeEqual always sees
|
|
28
|
+
// equal-length buffers whatever the caller sent.
|
|
29
|
+
function verifyCredential(slug, presented) {
|
|
30
|
+
if (typeof presented !== "string" || !presented) return false;
|
|
31
|
+
var a = crypto.createHash("sha256").update(presented).digest();
|
|
32
|
+
var b = crypto.createHash("sha256").update(credentialFor(slug)).digest();
|
|
33
|
+
return crypto.timingSafeEqual(a, b);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
ENV_NAME: ENV_NAME,
|
|
38
|
+
HEADER_NAME: HEADER_NAME,
|
|
39
|
+
credentialFor: credentialFor,
|
|
40
|
+
verifyCredential: verifyCredential,
|
|
41
|
+
};
|
|
@@ -36,29 +36,20 @@ var CATEGORY_LABELS = {
|
|
|
36
36
|
system: "Account and system notices",
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
loop_complete: "loop",
|
|
45
|
-
loop_error: "loop",
|
|
39
|
+
// The category of a notification type comes from the type's registration
|
|
40
|
+
// (lib/notify/types.js), for the banner and the push alike. Only a type no
|
|
41
|
+
// emitter registers is listed here: the type names rows saved by earlier
|
|
42
|
+
// versions carry.
|
|
43
|
+
var UNREGISTERED_CATEGORY = {
|
|
46
44
|
mate_dm: "messages",
|
|
47
45
|
mention_response: "messages",
|
|
48
|
-
user_mention: "messages",
|
|
49
|
-
auth_required: "system",
|
|
50
46
|
};
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
//
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
ask_user: "approval",
|
|
58
|
-
permission_reminder: "approval_reminder",
|
|
59
|
-
dm: "messages",
|
|
60
|
-
user_mention: "messages",
|
|
61
|
-
};
|
|
48
|
+
function registeredCategory(type) {
|
|
49
|
+
// Required here, not at load: the core loads the push modules that load this one.
|
|
50
|
+
var registered = require("./notify").getType(type);
|
|
51
|
+
return registered ? registered.category : null;
|
|
52
|
+
}
|
|
62
53
|
|
|
63
54
|
// Today's behaviour: every banner and push is on; the sound plays for a
|
|
64
55
|
// finished turn only.
|
|
@@ -124,13 +115,18 @@ function normalize(raw) {
|
|
|
124
115
|
}
|
|
125
116
|
|
|
126
117
|
function categoryOfNotification(type) {
|
|
127
|
-
|
|
118
|
+
var registered = registeredCategory(type);
|
|
119
|
+
if (registered) return registered;
|
|
120
|
+
return Object.prototype.hasOwnProperty.call(UNREGISTERED_CATEGORY, type) ? UNREGISTERED_CATEGORY[type] : null;
|
|
128
121
|
}
|
|
129
122
|
|
|
123
|
+
// A push payload's category is its type's. A type no one registers (the silent
|
|
124
|
+
// "test" validation push) is never filtered.
|
|
130
125
|
function categoryOfPush(payload) {
|
|
131
126
|
if (!payload || typeof payload.type !== "string") return null;
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
// A close push follows the preference of the notification it closes.
|
|
128
|
+
if (payload.type === "notify_close") return categoryOfPush({ type: payload.closes });
|
|
129
|
+
return registeredCategory(payload.type);
|
|
134
130
|
}
|
|
135
131
|
|
|
136
132
|
function userKey(userId) {
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The notification core: the one place that turns a target and a message into a
|
|
4
|
+
// push, collapses repeats, and closes a push when its prompt resolves.
|
|
5
|
+
// Emitters call notify() and resolve() and keep no tag, route or dedupe logic.
|
|
6
|
+
// A notification reaches the surfaces its type registers: push, and the in-app
|
|
7
|
+
// banner (lib/project-notifications.js is the banner store the core delivers
|
|
8
|
+
// to; it is not a second core).
|
|
9
|
+
//
|
|
10
|
+
// The core keeps no memory of what it showed. Every tag is derived from the
|
|
11
|
+
// type's collapse rule and the target alone (payload.tagFor), so resolve() can
|
|
12
|
+
// name the tags to close from the target it is given, in any process: a close
|
|
13
|
+
// still works after a daemon restart.
|
|
14
|
+
|
|
15
|
+
var target = require("./target");
|
|
16
|
+
var payloads = require("./payload");
|
|
17
|
+
var { pushForSession, audienceFor } = require("../push-audience");
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {object} deps
|
|
21
|
+
* @param {object} deps.registry a type registry (type-registry.js).
|
|
22
|
+
* @param {?object} deps.push the push module (sendPush, sendPushToUser).
|
|
23
|
+
* @param {?{show: function, dismissKeys: function}} [deps.inApp] the in-app
|
|
24
|
+
* banner store: show(event, data, meta) creates a banner, replacing the one
|
|
25
|
+
* under the same meta.key; dismissKeys(keys) removes the banners under them.
|
|
26
|
+
*/
|
|
27
|
+
function createNotifyCore(deps) {
|
|
28
|
+
var registry = deps.registry;
|
|
29
|
+
var push = deps.push || null;
|
|
30
|
+
var inApp = deps.inApp || null;
|
|
31
|
+
|
|
32
|
+
function audienceOf(audience) {
|
|
33
|
+
return {
|
|
34
|
+
ownerId: audience && audience.ownerId || null,
|
|
35
|
+
isMultiUser: audience && audience.isMultiUser,
|
|
36
|
+
listAdmins: audience && audience.listAdmins,
|
|
37
|
+
isOnline: audience && typeof audience.isOnline === "function" ? audience.isOnline : null,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isOnline(aud) {
|
|
42
|
+
if (!aud.isOnline || !aud.ownerId) return false;
|
|
43
|
+
try {
|
|
44
|
+
return aud.isOnline(aud.ownerId) === true;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
// A presence reader that fails counts as offline: a push too many beats
|
|
47
|
+
// a message nobody sees.
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// A type with a fixed audience ignores the owner the emitter names: the
|
|
53
|
+
// admins (or the one person of a single-user install) are the recipients.
|
|
54
|
+
function audienceForType(type, aud) {
|
|
55
|
+
if (type.audience !== "admins") return aud;
|
|
56
|
+
return Object.assign({}, aud, { ownerId: null });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function perSurface(content) {
|
|
60
|
+
var c = content || {};
|
|
61
|
+
if (c.push || c.banner) return { push: c.push || null, banner: c.banner || null };
|
|
62
|
+
return { push: c, banner: null };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function deliver(audience, payload) {
|
|
66
|
+
return pushForSession(push, audience.ownerId, payload, audience.isMultiUser, audience.listAdmins);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The banner follows the push audience: the owner, or the admins for an
|
|
70
|
+
// ownerless session in multi-user mode, so no one else reads its title.
|
|
71
|
+
function bannerData(type, norm, raw, audience, data) {
|
|
72
|
+
var aud = audienceFor(audience.ownerId, audience.isMultiUser, audience.listAdmins);
|
|
73
|
+
// The audience and the target are applied last: emitter content cannot
|
|
74
|
+
// widen or redirect who reads the banner, or where it points.
|
|
75
|
+
var fixed = {
|
|
76
|
+
ownerId: audience.ownerId,
|
|
77
|
+
targetUserId: aud.kind === "owner" ? aud.userIds[0] : null,
|
|
78
|
+
targetUserIds: aud.kind === "admins" ? aud.userIds : null,
|
|
79
|
+
slug: norm.slug,
|
|
80
|
+
sessionId: raw.sessionId,
|
|
81
|
+
requestId: norm.requestId,
|
|
82
|
+
};
|
|
83
|
+
// A direct message's target names the other person, not a project.
|
|
84
|
+
fixed.peerId = norm.peerId || null;
|
|
85
|
+
return Object.assign({}, data, fixed);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Shows (or replaces) the notification for a target, on every surface the
|
|
90
|
+
* type registers.
|
|
91
|
+
* @param {string} typeName a registered type.
|
|
92
|
+
* @param {{slug: ?string, sessionId: ?(number|string), requestId: ?string}} t
|
|
93
|
+
* @param {{push: ?object, banner: ?object}|object} content what each surface
|
|
94
|
+
* shows. push: the push text ({title, body}, or what the type's format
|
|
95
|
+
* reads); banner: the in-app store's own content (the target and audience
|
|
96
|
+
* fields are added here). A surface without content is not delivered to;
|
|
97
|
+
* the core picks the surfaces from the type's registration, never the
|
|
98
|
+
* emitter. A content naming neither key is the push content itself.
|
|
99
|
+
* @param {{ownerId: ?string, isMultiUser: ?function, listAdmins: ?function, isOnline: ?function}} [audience]
|
|
100
|
+
* who the notification belongs to (the session's owner; for a message, its
|
|
101
|
+
* recipient); the push audience rules (lib/push-audience.js) decide the
|
|
102
|
+
* recipients from it, for the push and the banner alike. The mode, admin
|
|
103
|
+
* and presence readers are optional; the presence reader (userId ->
|
|
104
|
+
* boolean) is used only by types that skip the push for an online person.
|
|
105
|
+
* @returns {?object} the payload built, or null when nothing was delivered.
|
|
106
|
+
*/
|
|
107
|
+
function notify(typeName, t, content, audience) {
|
|
108
|
+
var type = registry.get(typeName);
|
|
109
|
+
if (!type) throw new Error("unregistered notification type: " + typeName);
|
|
110
|
+
var norm = target.makeTarget(t);
|
|
111
|
+
if (!norm) throw new Error("invalid notification target for " + typeName);
|
|
112
|
+
if (type.collapse === "request" && !norm.requestId) {
|
|
113
|
+
throw new Error("notification type " + typeName + " needs a requestId");
|
|
114
|
+
}
|
|
115
|
+
var bySurface = perSurface(content);
|
|
116
|
+
var aud = audienceForType(type, audienceOf(audience));
|
|
117
|
+
var payload = payloads.buildPayload(type, norm, bySurface.push || bySurface.banner);
|
|
118
|
+
var delivered = false;
|
|
119
|
+
var skipPush = type.pushUnlessOnline && isOnline(aud);
|
|
120
|
+
if (push && bySurface.push && !skipPush) {
|
|
121
|
+
deliver(aud, payload);
|
|
122
|
+
delivered = true;
|
|
123
|
+
}
|
|
124
|
+
if (inApp && type.banner && bySurface.banner) {
|
|
125
|
+
inApp.show(typeName, bannerData(type, norm, t, aud, bySurface.banner), {
|
|
126
|
+
key: payload.tag,
|
|
127
|
+
collapse: type.collapse,
|
|
128
|
+
persistent: type.persistent,
|
|
129
|
+
liveInState: type.liveInState,
|
|
130
|
+
});
|
|
131
|
+
delivered = true;
|
|
132
|
+
}
|
|
133
|
+
return delivered ? payload : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// The close-on-resolve types the targets' resolve reaches, grouped by
|
|
137
|
+
// notification category: a close push follows the preference of the
|
|
138
|
+
// notification it closes, and types of one category share a preference, so
|
|
139
|
+
// one push per category carries all its tags.
|
|
140
|
+
function closeGroups(norms, onlyType) {
|
|
141
|
+
var groups = Object.create(null);
|
|
142
|
+
var order = [];
|
|
143
|
+
var bannerKeys = [];
|
|
144
|
+
norms.forEach(function (norm) {
|
|
145
|
+
registry.names().forEach(function (name) {
|
|
146
|
+
var type = registry.get(name);
|
|
147
|
+
if (onlyType) {
|
|
148
|
+
if (name !== onlyType) return;
|
|
149
|
+
} else {
|
|
150
|
+
if (!type.closeOnResolve) return;
|
|
151
|
+
// With a request named, that prompt's request-level notifications;
|
|
152
|
+
// without one, the session-level ones.
|
|
153
|
+
if ((type.collapse === "request") !== !!norm.requestId) return;
|
|
154
|
+
}
|
|
155
|
+
var key = type.category || name;
|
|
156
|
+
if (!groups[key]) {
|
|
157
|
+
groups[key] = { type: type, tags: [] };
|
|
158
|
+
order.push(key);
|
|
159
|
+
}
|
|
160
|
+
var tag = payloads.tagFor(type, norm);
|
|
161
|
+
if (groups[key].tags.indexOf(tag) === -1) groups[key].tags.push(tag);
|
|
162
|
+
if (type.banner && bannerKeys.indexOf(tag) === -1) bannerKeys.push(tag);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
return { groups: order.map(function (key) { return groups[key]; }), bannerKeys: bannerKeys };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Closes what is shown for a target, on every surface and every device in
|
|
170
|
+
* its audience: the push on each device, and the banner in every page.
|
|
171
|
+
* @param {object|object[]} what a target { slug, sessionId, requestId }, or a
|
|
172
|
+
* list of them (a prompt known by more than one id). With a requestId it
|
|
173
|
+
* closes that prompt's request-level notifications; without one (a session
|
|
174
|
+
* whose prompts all settled) it closes the session-level ones. A target
|
|
175
|
+
* without a session id closes no push (a request-only target retires the
|
|
176
|
+
* banners of that request).
|
|
177
|
+
* @param {{ownerId: ?string, isMultiUser: ?function, listAdmins: ?function}} [audience]
|
|
178
|
+
* the same audience the notification was sent to.
|
|
179
|
+
* @param {{type: ?string}} [opts] type: close only that registered type's
|
|
180
|
+
* notification at the target, whether or not the type closes with a
|
|
181
|
+
* prompt. This is how a system notification (no session, no prompt) is
|
|
182
|
+
* closed: its target is the console itself.
|
|
183
|
+
* @returns {number} how many close pushes were sent.
|
|
184
|
+
*/
|
|
185
|
+
function resolve(what, audience, opts) {
|
|
186
|
+
var onlyType = opts && opts.type ? opts.type : null;
|
|
187
|
+
if (onlyType && !registry.get(onlyType)) throw new Error("unregistered notification type: " + onlyType);
|
|
188
|
+
var all = [].concat(what).map(target.makeTarget).filter(Boolean);
|
|
189
|
+
var norms = onlyType ? all : all.filter(function (n) { return n.sessionId; });
|
|
190
|
+
var closing = closeGroups(norms, onlyType);
|
|
191
|
+
if (inApp && closing.bannerKeys.length) inApp.dismissKeys(closing.bannerKeys);
|
|
192
|
+
// An answer that arrives for a prompt no session claims (a stale one) names
|
|
193
|
+
// only its request: the banners of that request are retired, in its project.
|
|
194
|
+
if (inApp && !onlyType && typeof inApp.dismissRequest === "function") {
|
|
195
|
+
all.filter(function (n) { return !n.sessionId && n.requestId; }).forEach(function (n) {
|
|
196
|
+
inApp.dismissRequest(n.slug, n.requestId);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (!push) return 0;
|
|
200
|
+
var aud = audienceOf(audience);
|
|
201
|
+
closing.groups.forEach(function (g) {
|
|
202
|
+
deliver(audienceForType(g.type, aud), payloads.buildClose(g.type, g.tags));
|
|
203
|
+
});
|
|
204
|
+
return closing.groups.length;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return { notify: notify, resolve: resolve };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
module.exports = { createNotifyCore: createNotifyCore };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The notification core's public surface. notifyFor(push, inApp) returns the
|
|
4
|
+
// core bound to a push module and the in-app banner store.
|
|
5
|
+
|
|
6
|
+
var { createTypeRegistry } = require("./type-registry");
|
|
7
|
+
var { registerBuiltins } = require("./types");
|
|
8
|
+
var { createNotifyCore } = require("./core");
|
|
9
|
+
var target = require("./target");
|
|
10
|
+
|
|
11
|
+
var registry = registerBuiltins(createTypeRegistry());
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The core is stateless (every tag derives from the target), so a notification
|
|
15
|
+
* raised through one instance is closed through another.
|
|
16
|
+
* @param {?object} push the push module; null for no push.
|
|
17
|
+
* @param {?object} [inApp] the in-app banner store (lib/project-notifications.js).
|
|
18
|
+
*/
|
|
19
|
+
function notifyFor(push, inApp) {
|
|
20
|
+
return createNotifyCore({ registry: registry, push: push || null, inApp: inApp || null });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
notifyFor: notifyFor,
|
|
25
|
+
registerType: registry.register,
|
|
26
|
+
getType: registry.get,
|
|
27
|
+
targetKey: target.targetKey,
|
|
28
|
+
makeTarget: target.makeTarget,
|
|
29
|
+
createNotifyCore: createNotifyCore,
|
|
30
|
+
createTypeRegistry: createTypeRegistry,
|
|
31
|
+
};
|