@clagentic/console 1.12.0-beta.2 → 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.
Files changed (127) hide show
  1. package/LICENSES/README.md +5 -0
  2. package/bin/cli.js +4 -2
  3. package/lib/agent-roster-ws.js +84 -0
  4. package/lib/agent-roster.js +312 -0
  5. package/lib/auth-required-notify.js +42 -0
  6. package/lib/build-sha.json +2 -2
  7. package/lib/build-update-notify.js +45 -0
  8. package/lib/build-update-offer.js +3 -4
  9. package/lib/build-update-standing.js +34 -14
  10. package/lib/cli/session-subcommands.js +26 -8
  11. package/lib/client-address.js +44 -0
  12. package/lib/daemon.js +25 -10
  13. package/lib/idle-compaction-setting.js +203 -0
  14. package/lib/mcp-bridge-credential.js +41 -0
  15. package/lib/notification-prefs.js +16 -22
  16. package/lib/notify/core.js +53 -18
  17. package/lib/notify/payload.js +2 -3
  18. package/lib/notify/type-registry.js +17 -0
  19. package/lib/notify/types.js +38 -1
  20. package/lib/outbound-access.js +12 -1
  21. package/lib/outbound-entry.js +8 -1
  22. package/lib/project-connection.js +9 -8
  23. package/lib/project-filesystem.js +23 -0
  24. package/lib/project-loop.js +16 -19
  25. package/lib/project-notifications.js +68 -7
  26. package/lib/project-sessions.js +9 -0
  27. package/lib/project-user-mention.js +22 -34
  28. package/lib/project-user-message.js +208 -4
  29. package/lib/project-user-shell.js +298 -0
  30. package/lib/project.js +26 -4
  31. package/lib/prompt-answer.js +145 -0
  32. package/lib/prompt-expiry.js +50 -0
  33. package/lib/prompt-registry.js +24 -1
  34. package/lib/prompt-source.js +16 -0
  35. package/lib/public/app.js +31 -2
  36. package/lib/public/css/agent-messages.css +96 -0
  37. package/lib/public/css/agent-roster.css +93 -0
  38. package/lib/public/css/diagnostics.css +1 -1
  39. package/lib/public/css/input.css +20 -141
  40. package/lib/public/css/login-panel.css +73 -0
  41. package/lib/public/css/menus.css +2 -2
  42. package/lib/public/css/sidebar.css +11 -0
  43. package/lib/public/css/team-panel.css +1 -6
  44. package/lib/public/css/team-view.css +101 -0
  45. package/lib/public/css/title-bar.css +10 -0
  46. package/lib/public/css/user-shell.css +144 -0
  47. package/lib/public/index.html +41 -7
  48. package/lib/public/modules/agent-avatar-picker.js +162 -0
  49. package/lib/public/modules/agent-avatar.js +153 -0
  50. package/lib/public/modules/agent-messages.js +285 -0
  51. package/lib/public/modules/agent-roster.js +157 -0
  52. package/lib/public/modules/app-connection.js +12 -0
  53. package/lib/public/modules/app-messages.js +55 -16
  54. package/lib/public/modules/app-notifications.js +59 -29
  55. package/lib/public/modules/app-panels.js +26 -3
  56. package/lib/public/modules/app-rate-limit.js +8 -165
  57. package/lib/public/modules/app-rendering.js +22 -7
  58. package/lib/public/modules/collapsible-text.js +33 -18
  59. package/lib/public/modules/compaction-state.js +34 -0
  60. package/lib/public/modules/custom-icons.js +23 -5
  61. package/lib/public/modules/diagnostics.js +52 -55
  62. package/lib/public/modules/injected-identity.js +24 -21
  63. package/lib/public/modules/input.js +176 -15
  64. package/lib/public/modules/login-panel.js +136 -0
  65. package/lib/public/modules/login-parser.js +73 -0
  66. package/lib/public/modules/login-tab.js +66 -0
  67. package/lib/public/modules/notifications.js +9 -1
  68. package/lib/public/modules/notify-client.js +114 -21
  69. package/lib/public/modules/pending-term-request.js +30 -0
  70. package/lib/public/modules/project-icon.js +22 -2
  71. package/lib/public/modules/queued-button.js +11 -0
  72. package/lib/public/modules/scheduled-input-actions.js +12 -4
  73. package/lib/public/modules/scheduled-outbox.js +230 -0
  74. package/lib/public/modules/send-now.js +200 -0
  75. package/lib/public/modules/server-settings.js +47 -1
  76. package/lib/public/modules/shell-card.js +76 -0
  77. package/lib/public/modules/shell-line.js +49 -0
  78. package/lib/public/modules/shell-queue.js +253 -0
  79. package/lib/public/modules/shell-settings-controls.js +76 -0
  80. package/lib/public/modules/sidebar-mobile.js +3 -3
  81. package/lib/public/modules/sidebar-sessions.js +8 -0
  82. package/lib/public/modules/sidebar-users.js +5 -7
  83. package/lib/public/modules/team-panel.js +30 -88
  84. package/lib/public/modules/team-view.js +211 -0
  85. package/lib/public/modules/terminal-links.js +18 -0
  86. package/lib/public/modules/terminal.js +65 -4
  87. package/lib/public/modules/tools.js +19 -0
  88. package/lib/public/modules/user-shell.js +824 -0
  89. package/lib/public/notify-sw-logic.js +35 -83
  90. package/lib/public/notify-target.js +70 -10
  91. package/lib/public/style.css +5 -0
  92. package/lib/public/sw.js +7 -3
  93. package/lib/queued-chat.js +392 -0
  94. package/lib/scheduled-input/ws.js +67 -9
  95. package/lib/sdk-bridge.js +122 -43
  96. package/lib/sdk-message-processor.js +46 -39
  97. package/lib/server-auth.js +6 -4
  98. package/lib/server-dm.js +11 -20
  99. package/lib/server-settings.js +39 -1
  100. package/lib/server.js +83 -19
  101. package/lib/session-directory.js +33 -8
  102. package/lib/session-end.js +97 -0
  103. package/lib/session-input-ipc.js +26 -0
  104. package/lib/session-input.js +176 -9
  105. package/lib/session-resume.js +1 -0
  106. package/lib/session-settings-file.js +53 -0
  107. package/lib/sessions.js +49 -5
  108. package/lib/team-traffic-ws.js +68 -0
  109. package/lib/team-traffic.js +318 -0
  110. package/lib/usage-store.js +7 -0
  111. package/lib/user-shell-settings.js +105 -0
  112. package/lib/ws-schema.js +27 -4
  113. package/lib/yoke/adapters/claude-capabilities.js +2 -0
  114. package/lib/yoke/adapters/claude-vendor.js +6 -0
  115. package/lib/yoke/adapters/claude-worker.js +39 -11
  116. package/lib/yoke/adapters/claude.js +218 -6
  117. package/lib/yoke/adapters/codex-capabilities.js +6 -1
  118. package/lib/yoke/adapters/codex-user-shell.js +265 -0
  119. package/lib/yoke/adapters/codex-vendor.js +7 -0
  120. package/lib/yoke/adapters/codex.js +186 -52
  121. package/lib/yoke/codex-app-server.js +8 -2
  122. package/lib/yoke/interface.js +54 -1
  123. package/lib/yoke/mcp-bridge-server.js +12 -8
  124. package/lib/yoke/registry.js +32 -0
  125. package/lib/yoke/user-shell.js +224 -0
  126. package/package.json +1 -1
  127. package/lib/public/modules/build-notice-gate.js +0 -73
@@ -1,18 +1,20 @@
1
1
  // lib/cli/session-subcommands.js
2
2
  //
3
- // `clagentic-console open-session`, `send-input`, `list-sessions` and
4
- // `list-outbound`: open a session in a project, send input to one, list the
5
- // sessions, or list what one session sent out, through the running daemon's IPC
3
+ // `clagentic-console open-session`, `send-input`, `end-session`, `answer-prompt`,
4
+ // `list-sessions` and `list-outbound`: open a session in a project, send input
5
+ // to one, stand one down, answer one of its pending prompts, list the sessions, or list what one session sent out, through the running daemon's IPC
6
6
  // socket. Each prints the daemon's result as JSON on stdout.
7
7
  //
8
8
  // Exit codes (documented in docs/guides/AGENT-GUIDE.md):
9
- // 0 the request was acted on (opened, delivered, resumed-and-delivered, listed)
9
+ // 0 the request was acted on (opened, delivered, resumed-and-delivered, listed,
10
+ // ended, already-ended)
10
11
  // 1 refused, error, or not-found for a request that named a session id
11
12
  // 3 ambiguous: an address named several sessions (or, for list-outbound, a
12
13
  // session id several projects hold); the candidates are in the JSON
13
14
  // 4 not-found for a request that gave an address (--to) or --reply
14
15
 
15
16
  var fs = require("fs");
17
+ var path = require("path");
16
18
 
17
19
  var { loadConfig, socketPath, isDaemonAliveAsync } = require("../config");
18
20
  var { sendIPCCommand } = require("../ipc");
@@ -36,12 +38,16 @@ var FLAGS = {
36
38
  "--state": "state",
37
39
  "--visibility": "sessionVisibility",
38
40
  "--permission-mode": "permissionMode",
41
+ "--settings": "settingsFile",
39
42
  "--initiator": "initiator",
40
43
  "--context-note": "contextNote",
41
44
  "--from": "from",
42
45
  "--from-session": "fromSession",
46
+ "--reason": "reason",
43
47
  "--since": "since",
44
48
  "--kind": "kind",
49
+ "--request": "requestId",
50
+ "--decision": "decision",
45
51
  };
46
52
 
47
53
  // Kept apart from FLAGS because the parser reads a value after every FLAGS
@@ -51,15 +57,19 @@ var SWITCHES = {
51
57
  };
52
58
 
53
59
  var USAGE = {
54
- "open-session": "Usage: clagentic-console open-session (--project <slug> | --to <address>) --prompt <text|-> [--vendor <id>] [--agent <name>] [--name <session-name>] [--visibility shared|private] [--permission-mode <mode>] [--initiator <kind>] [--context-note <text>] [--from <name>] [--from-session <id>]",
60
+ "open-session": "Usage: clagentic-console open-session (--project <slug> | --to <address>) --prompt <text|-> [--vendor <id>] [--agent <name>] [--name <session-name>] [--visibility shared|private] [--permission-mode <mode>] [--settings <path>] [--initiator <kind>] [--context-note <text>] [--from <name>] [--from-session <id>]",
55
61
  "send-input": "Usage: clagentic-console send-input (--project <slug> --session <id> | --to <address> | --reply) --prompt <text|-> [--initiator <kind>] [--context-note <text>] [--from <name>] [--from-session <id>]",
62
+ "end-session": "Usage: clagentic-console end-session (--project <slug> --session <id> | --to <address>) [--from <name>] [--from-session <id>] [--reason <text>]",
63
+ "answer-prompt": "Usage: clagentic-console answer-prompt (--project <slug> --session <id> | --to <address>) --request <id> --decision <allow|deny|allow_always|text> [--from <name>] [--from-session <id>]",
56
64
  "list-sessions": "Usage: clagentic-console list-sessions [--project <slug>] [--agent <name>] [--vendor <id>] [--state live|idle|reaped|any]",
57
65
  "list-outbound": "Usage: clagentic-console list-outbound --session <vendor-session-id> [--project <slug>] [--since <dur>] [--kind sent|opens]",
58
66
  };
59
67
 
60
68
  var ALLOWED = {
61
- "open-session": ["projectSlug", "to", "prompt", "vendor", "agentName", "sessionName", "sessionVisibility", "permissionMode", "initiator", "contextNote", "from", "fromSession"],
69
+ "open-session": ["projectSlug", "to", "prompt", "vendor", "agentName", "sessionName", "sessionVisibility", "permissionMode", "settingsFile", "initiator", "contextNote", "from", "fromSession"],
62
70
  "send-input": ["projectSlug", "sessionId", "to", "reply", "prompt", "initiator", "contextNote", "from", "fromSession"],
71
+ "end-session": ["projectSlug", "sessionId", "to", "reason", "from", "fromSession"],
72
+ "answer-prompt": ["projectSlug", "sessionId", "to", "requestId", "decision", "from", "fromSession"],
63
73
  "list-sessions": ["projectSlug", "agentName", "vendor", "state"],
64
74
  "list-outbound": ["sessionId", "projectSlug", "since", "kind"],
65
75
  };
@@ -67,6 +77,8 @@ var ALLOWED = {
67
77
  var REQUIRED = {
68
78
  "open-session": ["prompt"],
69
79
  "send-input": ["prompt"],
80
+ "end-session": [],
81
+ "answer-prompt": ["requestId", "decision"],
70
82
  "list-sessions": [],
71
83
  "list-outbound": ["sessionId"],
72
84
  };
@@ -74,11 +86,15 @@ var REQUIRED = {
74
86
  var TARGET_HINT = {
75
87
  "open-session": "--project, or --to",
76
88
  "send-input": "--session (with --project), or --to, or --reply",
89
+ "end-session": "--session (with --project), or --to",
90
+ "answer-prompt": "--session (with --project), or --to",
77
91
  };
78
92
 
79
93
  var IPC_COMMAND = {
80
94
  "open-session": "open_session",
81
95
  "send-input": "send_session_input",
96
+ "end-session": "end_session",
97
+ "answer-prompt": "answer_prompt",
82
98
  "list-sessions": "list_sessions",
83
99
  "list-outbound": "list_outbound",
84
100
  };
@@ -105,7 +121,7 @@ function checkTarget(verb, request) {
105
121
  if (given("reply")) return given("projectSlug") || given("sessionId") ? conflict : null;
106
122
  if (!given("projectSlug") && !given("sessionId")) return "Missing the target: " + TARGET_HINT[verb];
107
123
  if (!given("projectSlug")) return "Missing required option --project";
108
- if (verb === "send-input" && !given("sessionId")) return "Missing required option --session";
124
+ if ((verb === "send-input" || verb === "end-session" || verb === "answer-prompt") && !given("sessionId")) return "Missing required option --session";
109
125
  return null;
110
126
  }
111
127
 
@@ -141,6 +157,8 @@ function parseSessionArgs(verb, args, now) {
141
157
  if (!key || allowed.indexOf(key) === -1) return { error: "Unknown option for " + verb + ": " + args[i] };
142
158
  if (i + 1 >= args.length) return { error: "Missing value for " + args[i] };
143
159
  request[key] = args[++i];
160
+ // The daemon runs elsewhere: a relative path means nothing to it.
161
+ if (key === "settingsFile" && request[key]) request[key] = path.resolve(request[key]);
144
162
  }
145
163
  var required = REQUIRED[verb];
146
164
  for (var r = 0; r < required.length; r++) {
@@ -203,7 +221,7 @@ function runSessionVerb(verb, args) {
203
221
  request.prompt = fs.readFileSync(0, "utf8").replace(/\n$/, "");
204
222
  }
205
223
  request.cmd = IPC_COMMAND[verb];
206
- if (verb === "open-session" || verb === "send-input") withSenderRef(request, process.env);
224
+ if (verb === "open-session" || verb === "send-input" || verb === "end-session" || verb === "answer-prompt") withSenderRef(request, process.env);
207
225
 
208
226
  requestDaemon(request).then(function (res) {
209
227
  console.log(JSON.stringify(res, null, 2));
@@ -0,0 +1,44 @@
1
+ // client-address.js — one answer to "who is this client, and is it local?".
2
+ //
3
+ // The TCP peer is the client only when nothing sits in front of the daemon.
4
+ // Behind a same-host reverse proxy every client is the loopback peer, which
5
+ // collapses rate-limit buckets and audit records into one and makes proxied
6
+ // sockets look local.
7
+ //
8
+ // Address: with trustedProxy declared, X-Forwarded-For is used only when it is
9
+ // a single valid IP literal. A multi-valued chain, an invalid value or an
10
+ // absent header falls back to the peer; no hop is ever picked, for the same
11
+ // reason as lib/effective-protocol.js (trustedProxy is one boolean and cannot
12
+ // say which hop to trust). Without trustedProxy the header is ignored.
13
+ //
14
+ // Locality: a loopback peer with no forwarding header at all, whatever
15
+ // trustedProxy says, since a forwarding header means someone else is the client.
16
+
17
+ var net = require("net");
18
+
19
+ var LOOPBACK = ["127.0.0.1", "::1", "::ffff:127.0.0.1"];
20
+ var FORWARDING_HEADERS = ["x-forwarded-for", "forwarded", "x-real-ip"];
21
+
22
+ /**
23
+ * @param {Object} req - http.IncomingMessage (or an object with headers/socket)
24
+ * @param {boolean} trustedProxy - operator-declared proxy trust boundary
25
+ * @returns {{address: string, local: boolean}}
26
+ */
27
+ function resolveClientAddress(req, trustedProxy) {
28
+ var headers = (req && req.headers) || {};
29
+ var peer = (req && req.socket && req.socket.remoteAddress) || "";
30
+ var address = peer;
31
+
32
+ if (trustedProxy) {
33
+ var xff = headers["x-forwarded-for"];
34
+ if (typeof xff === "string" && xff.indexOf(",") === -1) {
35
+ var candidate = xff.trim();
36
+ if (net.isIP(candidate)) address = candidate;
37
+ }
38
+ }
39
+
40
+ var forwarded = FORWARDING_HEADERS.some(function (h) { return headers[h] !== undefined; });
41
+ return { address: address, local: LOOPBACK.indexOf(peer) !== -1 && !forwarded };
42
+ }
43
+
44
+ module.exports = { resolveClientAddress: resolveClientAddress };
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
- // The standing offer state for a client that connects: the held offer, or an
1280
- // explicit "no offer" so a client that missed a retraction drops a dead action.
1281
- onGetBuildUpdateDiagnostic: function () {
1282
- return buildStandingOffer.forNewClient();
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 closed build-update notice stays quiet in a client before the same
1420
- // notice may show again; the client applies it (lib/public/modules/build-notice-gate.js).
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
- broadcast: function (message) { relay.broadcastAll(message); },
1432
- compose: function (a, changes) {
1433
- return composeNotice(a, changes, BUILD_NOTICE_COOLDOWN_MS);
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,6 +1724,8 @@ 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
 
@@ -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
- // Notification type (project-notifications.js) -> category.
40
- var NOTIFICATION_CATEGORY = {
41
- response_done: "turn_done",
42
- permission_request: "approval",
43
- permission_reminder: "approval_reminder",
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
- // Push payload type -> category. A type absent here (the silent "test"
53
- // validation push) is never filtered.
54
- var PUSH_CATEGORY = {
55
- permission_request: "approval",
56
- elicitation: "approval",
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,15 +115,18 @@ function normalize(raw) {
124
115
  }
125
116
 
126
117
  function categoryOfNotification(type) {
127
- return Object.prototype.hasOwnProperty.call(NOTIFICATION_CATEGORY, type) ? NOTIFICATION_CATEGORY[type] : null;
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
- if (payload.type === "done") return payload.tag === "ralph-loop-done" ? "loop" : "turn_done";
133
127
  // A close push follows the preference of the notification it closes.
134
128
  if (payload.type === "notify_close") return categoryOfPush({ type: payload.closes });
135
- return Object.prototype.hasOwnProperty.call(PUSH_CATEGORY, payload.type) ? PUSH_CATEGORY[payload.type] : null;
129
+ return registeredCategory(payload.type);
136
130
  }
137
131
 
138
132
  function userKey(userId) {