@clagentic/console 1.12.0-beta.3 → 1.13.0-beta.1

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 (243) hide show
  1. package/README.md +7 -1
  2. package/bin/cli.js +18 -15
  3. package/lib/agent-roster-ws.js +38 -13
  4. package/lib/agent-roster.js +111 -12
  5. package/lib/agents.js +68 -33
  6. package/lib/atomic-install.js +334 -0
  7. package/lib/build-changes.js +33 -4
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-offer.js +12 -0
  10. package/lib/chat-width.js +31 -0
  11. package/lib/cli/agent-usage.js +126 -0
  12. package/lib/cli/arg-validation.js +1 -1
  13. package/lib/cli/compact-output.js +69 -0
  14. package/lib/cli/ipc-subcommands.js +92 -67
  15. package/lib/cli/output.js +28 -0
  16. package/lib/cli/restart-verb.js +132 -0
  17. package/lib/cli/schedule-input-subcommands.js +45 -8
  18. package/lib/cli/session-subcommands.js +37 -11
  19. package/lib/cli/settings-subcommands.js +74 -0
  20. package/lib/cli-transcript-title.js +56 -3
  21. package/lib/client-files.js +79 -0
  22. package/lib/daemon.js +100 -28
  23. package/lib/default-avatar-color.js +4 -0
  24. package/lib/drain.js +58 -10
  25. package/lib/mcp-tool-input.js +2 -2
  26. package/lib/model-families.js +49 -1
  27. package/lib/notify/type-registry.js +4 -0
  28. package/lib/notify/types.js +7 -4
  29. package/lib/pages.js +13 -63
  30. package/lib/permission-summary.js +12 -16
  31. package/lib/plan-usage-reader.js +70 -0
  32. package/lib/project-connection.js +4 -2
  33. package/lib/project-filesystem.js +6 -7
  34. package/lib/project-notifications.js +55 -8
  35. package/lib/project-prompt-expiry-settings.js +42 -0
  36. package/lib/project-sessions.js +52 -0
  37. package/lib/project-settings-gate.js +98 -0
  38. package/lib/project-user-mention.js +3 -2
  39. package/lib/project.js +1 -1
  40. package/lib/prompt-expiry-settings.js +49 -0
  41. package/lib/prompt-expiry.js +24 -3
  42. package/lib/prompt-kinds/codecs.js +6 -2
  43. package/lib/public/app.js +36 -36
  44. package/lib/public/css/admin.css +156 -170
  45. package/lib/public/css/agent-messages.css +24 -24
  46. package/lib/public/css/agent-picker.css +90 -38
  47. package/lib/public/css/agent-roster.css +61 -27
  48. package/lib/public/css/at-agents.css +10 -10
  49. package/lib/public/css/base.css +207 -184
  50. package/lib/public/css/chat-layout.css +228 -0
  51. package/lib/public/css/command-palette.css +86 -88
  52. package/lib/public/css/diagnostics.css +78 -204
  53. package/lib/public/css/diff.css +10 -10
  54. package/lib/public/css/filebrowser.css +32 -60
  55. package/lib/public/css/home-hub.css +100 -100
  56. package/lib/public/css/icon-strip.css +195 -238
  57. package/lib/public/css/input.css +191 -212
  58. package/lib/public/css/login-panel.css +16 -16
  59. package/lib/public/css/loop.css +96 -187
  60. package/lib/public/css/mention.css +49 -110
  61. package/lib/public/css/menus.css +162 -169
  62. package/lib/public/css/messages.css +49 -123
  63. package/lib/public/css/mobile-nav.css +207 -264
  64. package/lib/public/css/notifications-center.css +45 -124
  65. package/lib/public/css/overlay.css +269 -0
  66. package/lib/public/css/overlays.css +134 -156
  67. package/lib/public/css/playbook.css +41 -41
  68. package/lib/public/css/profile.css +43 -112
  69. package/lib/public/css/rewind.css +112 -112
  70. package/lib/public/css/scheduler-modal.css +27 -135
  71. package/lib/public/css/scheduler.css +204 -210
  72. package/lib/public/css/server-settings.css +173 -239
  73. package/lib/public/css/session-search.css +20 -20
  74. package/lib/public/css/settings-nav.css +197 -0
  75. package/lib/public/css/sidebar.css +213 -304
  76. package/lib/public/css/skills.css +121 -135
  77. package/lib/public/css/sticky-notes.css +114 -200
  78. package/lib/public/css/stt.css +17 -26
  79. package/lib/public/css/team-panel.css +36 -36
  80. package/lib/public/css/team-view.css +9 -9
  81. package/lib/public/css/title-bar.css +83 -100
  82. package/lib/public/css/tooltip.css +10 -10
  83. package/lib/public/css/user-settings.css +78 -131
  84. package/lib/public/css/user-shell.css +125 -29
  85. package/lib/public/index.html +178 -177
  86. package/lib/public/manifest.json +0 -2
  87. package/lib/public/modules/admin.js +54 -92
  88. package/lib/public/modules/agent-avatar.js +134 -3
  89. package/lib/public/modules/agent-messages.js +2 -1
  90. package/lib/public/modules/agent-picker.js +23 -21
  91. package/lib/public/modules/agent-roster-groups.js +128 -0
  92. package/lib/public/modules/agent-roster.js +40 -11
  93. package/lib/public/modules/app-connection.js +13 -1
  94. package/lib/public/modules/app-cursors.js +9 -9
  95. package/lib/public/modules/app-favicon.js +8 -16
  96. package/lib/public/modules/app-header.js +28 -19
  97. package/lib/public/modules/app-history-replay.js +67 -4
  98. package/lib/public/modules/app-home-hub.js +15 -0
  99. package/lib/public/modules/app-loop-ui.js +41 -47
  100. package/lib/public/modules/app-loop-wizard.js +9 -10
  101. package/lib/public/modules/app-messages.js +32 -36
  102. package/lib/public/modules/app-misc.js +22 -92
  103. package/lib/public/modules/app-modals.js +98 -0
  104. package/lib/public/modules/app-notifications.js +124 -135
  105. package/lib/public/modules/app-panels.js +28 -32
  106. package/lib/public/modules/app-projects.js +30 -40
  107. package/lib/public/modules/app-rate-limit.js +26 -9
  108. package/lib/public/modules/app-rendering.js +128 -110
  109. package/lib/public/modules/app-skills-install.js +6 -4
  110. package/lib/public/modules/assistant-identity.js +55 -0
  111. package/lib/public/modules/at-agents.js +3 -0
  112. package/lib/public/modules/build-guard.js +25 -11
  113. package/lib/public/modules/chat-width-choice.js +75 -0
  114. package/lib/public/modules/chat-width-prefs.js +52 -0
  115. package/lib/public/modules/chat-width.js +102 -0
  116. package/lib/public/modules/collapsible-text.js +36 -4
  117. package/lib/public/modules/command-palette.js +28 -34
  118. package/lib/public/modules/context-sources.js +3 -5
  119. package/lib/public/modules/diagnostics.js +130 -129
  120. package/lib/public/modules/info-panel.js +31 -0
  121. package/lib/public/modules/injected-identity.js +8 -8
  122. package/lib/public/modules/input-list-menu.js +39 -0
  123. package/lib/public/modules/input.js +22 -21
  124. package/lib/public/modules/markdown.js +10 -11
  125. package/lib/public/modules/mcp-ui.js +4 -14
  126. package/lib/public/modules/mention.js +100 -229
  127. package/lib/public/modules/message-header.js +80 -0
  128. package/lib/public/modules/message-participants.js +39 -0
  129. package/lib/public/modules/mobile-action-sheet.js +46 -0
  130. package/lib/public/modules/mobile-nav-sheet.js +104 -0
  131. package/lib/public/modules/model-families.js +41 -4
  132. package/lib/public/modules/note-order.js +39 -0
  133. package/lib/public/modules/notifications.js +35 -52
  134. package/lib/public/modules/overlay-history.js +73 -19
  135. package/lib/public/modules/overlay-menu.js +123 -0
  136. package/lib/public/modules/overlay-modal.js +186 -0
  137. package/lib/public/modules/overlay-registry.js +392 -0
  138. package/lib/public/modules/overlay-stack.js +110 -0
  139. package/lib/public/modules/overlay.js +117 -0
  140. package/lib/public/modules/popover-position.js +18 -2
  141. package/lib/public/modules/preference-sync.js +28 -0
  142. package/lib/public/modules/profile.js +24 -49
  143. package/lib/public/modules/project-settings.js +27 -172
  144. package/lib/public/modules/prompt-expiry-controls.js +46 -0
  145. package/lib/public/modules/prompt-kinds/command-summary.js +149 -0
  146. package/lib/public/modules/prompt-kinds/permission.js +70 -92
  147. package/lib/public/modules/prompts.js +1 -2
  148. package/lib/public/modules/qrcode.js +6 -21
  149. package/lib/public/modules/queued-button.js +15 -2
  150. package/lib/public/modules/rewind.js +9 -3
  151. package/lib/public/modules/schedule-time.js +32 -7
  152. package/lib/public/modules/scheduled-outbox.js +51 -18
  153. package/lib/public/modules/scheduler-config.js +87 -127
  154. package/lib/public/modules/scheduler.js +29 -26
  155. package/lib/public/modules/serialized-save.js +79 -0
  156. package/lib/public/modules/server-settings.js +75 -65
  157. package/lib/public/modules/session-grants.js +16 -19
  158. package/lib/public/modules/session-list-avatars.js +98 -0
  159. package/lib/public/modules/session-vendor-state.js +86 -0
  160. package/lib/public/modules/settings-access.js +35 -0
  161. package/lib/public/modules/settings-hub.js +125 -0
  162. package/lib/public/modules/settings-nav.js +182 -0
  163. package/lib/public/modules/shell-line.js +24 -0
  164. package/lib/public/modules/sidebar-mobile.js +151 -195
  165. package/lib/public/modules/sidebar-projects.js +88 -129
  166. package/lib/public/modules/sidebar-sessions.js +66 -34
  167. package/lib/public/modules/sidebar.js +2 -2
  168. package/lib/public/modules/skills.js +11 -26
  169. package/lib/public/modules/sticky-notes.js +19 -16
  170. package/lib/public/modules/stt.js +9 -23
  171. package/lib/public/modules/terminal.js +86 -90
  172. package/lib/public/modules/theme-choice.js +126 -0
  173. package/lib/public/modules/theme-colors.js +19 -0
  174. package/lib/public/modules/theme-prefs.js +121 -0
  175. package/lib/public/modules/theme.js +227 -605
  176. package/lib/public/modules/tool-palette.js +7 -17
  177. package/lib/public/modules/tools.js +8 -10
  178. package/lib/public/modules/user-settings.js +59 -115
  179. package/lib/public/modules/user-shell.js +9 -2
  180. package/lib/public/modules/utils.js +10 -12
  181. package/lib/public/modules/vendor-picker.js +4 -2
  182. package/lib/public/modules/vendor-registry.js +1 -2
  183. package/lib/public/style.css +3 -1
  184. package/lib/public/sw.js +9 -2
  185. package/lib/public/theme-core.js +411 -0
  186. package/lib/request-body.js +70 -0
  187. package/lib/sdk-bridge.js +227 -88
  188. package/lib/sdk-message-processor.js +44 -16
  189. package/lib/server-admin.js +198 -200
  190. package/lib/server-auth.js +16 -13
  191. package/lib/server-dm.js +4 -3
  192. package/lib/server-settings.js +177 -130
  193. package/lib/server.js +87 -36
  194. package/lib/session-background-tasks.js +79 -0
  195. package/lib/session-directory.js +138 -13
  196. package/lib/session-input-ipc.js +2 -0
  197. package/lib/session-input.js +39 -5
  198. package/lib/session-list-avatars.js +16 -0
  199. package/lib/session-reclaim.js +37 -25
  200. package/lib/session-vendor.js +37 -0
  201. package/lib/sessions.js +99 -34
  202. package/lib/settings-ipc.js +60 -0
  203. package/lib/settings-registry.js +86 -0
  204. package/lib/terminal-manager.js +17 -5
  205. package/lib/theme-files.js +132 -0
  206. package/lib/theme-seed.js +136 -0
  207. package/lib/themes/clagentic-dark.json +13 -6
  208. package/lib/themes/clagentic-light.json +12 -5
  209. package/lib/updater.js +6 -4
  210. package/lib/usage-store.js +97 -10
  211. package/lib/users-preferences.js +118 -19
  212. package/lib/users.js +19 -10
  213. package/lib/vendor-catalog.js +130 -0
  214. package/lib/ws-schema.js +4 -2
  215. package/lib/yoke/adapters/claude.js +81 -1
  216. package/lib/yoke/adapters/codex-user-shell.js +87 -23
  217. package/lib/yoke/adapters/codex.js +89 -5
  218. package/lib/yoke/codex-binary.js +59 -0
  219. package/package.json +1 -1
  220. package/scripts/check-test-count.js +5 -0
  221. package/scripts/install-local-test.js +50 -9
  222. package/scripts/write-build-sha.js +18 -2
  223. package/lib/public/css/channel-layout.css +0 -329
  224. package/lib/themes/ayu-light.json +0 -9
  225. package/lib/themes/catppuccin-latte.json +0 -9
  226. package/lib/themes/catppuccin-mocha.json +0 -9
  227. package/lib/themes/dracula.json +0 -9
  228. package/lib/themes/everforest-light.json +0 -9
  229. package/lib/themes/everforest.json +0 -9
  230. package/lib/themes/github-light.json +0 -9
  231. package/lib/themes/gruvbox-dark.json +0 -9
  232. package/lib/themes/gruvbox-light.json +0 -9
  233. package/lib/themes/monokai.json +0 -9
  234. package/lib/themes/nord-light.json +0 -9
  235. package/lib/themes/nord.json +0 -9
  236. package/lib/themes/one-dark.json +0 -9
  237. package/lib/themes/one-light.json +0 -9
  238. package/lib/themes/rose-pine-dawn.json +0 -9
  239. package/lib/themes/rose-pine.json +0 -9
  240. package/lib/themes/solarized-dark.json +0 -9
  241. package/lib/themes/solarized-light.json +0 -9
  242. package/lib/themes/tokyo-night-light.json +0 -9
  243. package/lib/themes/tokyo-night.json +0 -9
@@ -20,6 +20,8 @@ var { loadConfig, socketPath, isDaemonAliveAsync } = require("../config");
20
20
  var { sendIPCCommand } = require("../ipc");
21
21
  var senderRef = require("../sender-ref");
22
22
  var { parseDuration } = require("./duration");
23
+ var agentUsage = require("./agent-usage");
24
+ var compact = require("./compact-output");
23
25
 
24
26
  // A resumed session starts a runtime before the call answers: longer than the
25
27
  // IPC default.
@@ -48,30 +50,28 @@ var FLAGS = {
48
50
  "--kind": "kind",
49
51
  "--request": "requestId",
50
52
  "--decision": "decision",
53
+ "--limit": "limit",
51
54
  };
52
55
 
53
56
  // Kept apart from FLAGS because the parser reads a value after every FLAGS
54
57
  // entry; a flag listed there would swallow the next argument.
55
58
  var SWITCHES = {
56
59
  "--reply": "reply",
60
+ "--verbose": "verbose",
57
61
  };
58
62
 
59
- var USAGE = {
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>]",
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>]",
64
- "list-sessions": "Usage: clagentic-console list-sessions [--project <slug>] [--agent <name>] [--vendor <id>] [--state live|idle|reaped|any]",
65
- "list-outbound": "Usage: clagentic-console list-outbound --session <vendor-session-id> [--project <slug>] [--since <dur>] [--kind sent|opens]",
66
- };
63
+ var USAGE = {};
64
+ agentUsage.VERB_ORDER.forEach(function (key) {
65
+ if (key.indexOf(" ") === -1) USAGE[key] = agentUsage.usageLine(key);
66
+ });
67
67
 
68
68
  var ALLOWED = {
69
69
  "open-session": ["projectSlug", "to", "prompt", "vendor", "agentName", "sessionName", "sessionVisibility", "permissionMode", "settingsFile", "initiator", "contextNote", "from", "fromSession"],
70
70
  "send-input": ["projectSlug", "sessionId", "to", "reply", "prompt", "initiator", "contextNote", "from", "fromSession"],
71
71
  "end-session": ["projectSlug", "sessionId", "to", "reason", "from", "fromSession"],
72
72
  "answer-prompt": ["projectSlug", "sessionId", "to", "requestId", "decision", "from", "fromSession"],
73
- "list-sessions": ["projectSlug", "agentName", "vendor", "state"],
74
- "list-outbound": ["sessionId", "projectSlug", "since", "kind"],
73
+ "list-sessions": ["projectSlug", "agentName", "vendor", "state", "limit", "verbose"],
74
+ "list-outbound": ["sessionId", "projectSlug", "since", "kind", "verbose"],
75
75
  };
76
76
 
77
77
  var REQUIRED = {
@@ -156,6 +156,7 @@ function parseSessionArgs(verb, args, now) {
156
156
  var key = has(FLAGS, args[i]) ? FLAGS[args[i]] : null;
157
157
  if (!key || allowed.indexOf(key) === -1) return { error: "Unknown option for " + verb + ": " + args[i] };
158
158
  if (i + 1 >= args.length) return { error: "Missing value for " + args[i] };
159
+ if (has(request, key)) return { error: "Option given twice: " + args[i] };
159
160
  request[key] = args[++i];
160
161
  // The daemon runs elsewhere: a relative path means nothing to it.
161
162
  if (key === "settingsFile" && request[key]) request[key] = path.resolve(request[key]);
@@ -166,6 +167,10 @@ function parseSessionArgs(verb, args, now) {
166
167
  }
167
168
  var targetError = checkTarget(verb, request);
168
169
  if (targetError) return { error: targetError };
170
+ if (request.limit !== undefined) {
171
+ if (!/^[1-9][0-9]{0,8}$/.test(request.limit)) return { error: "--limit must be a whole number of 1 or more" };
172
+ request.limit = Number(request.limit);
173
+ }
169
174
  if (verb === "list-outbound") {
170
175
  var outboundError = resolveOutboundOptions(request, now === undefined ? Date.now() : now);
171
176
  if (outboundError) return { error: outboundError };
@@ -209,7 +214,23 @@ function fail(message) {
209
214
  process.exit(1);
210
215
  }
211
216
 
217
+ // What a listing verb prints: the compact rows, or the daemon's whole answer
218
+ // with --verbose.
219
+ function presentResult(verb, res, verbose) {
220
+ if (verbose) return res;
221
+ if (verb === "list-sessions") return compact.compactSessions(res);
222
+ if (verb === "list-outbound") return compact.compactOutbound(res);
223
+ return res;
224
+ }
225
+
212
226
  function runSessionVerb(verb, args) {
227
+ // Before parsing, so help works whatever else is missing or wrong. It is
228
+ // printed and the process ends on its own: nothing else is open.
229
+ if (agentUsage.wantsHelp(args, Object.keys(FLAGS))) {
230
+ console.log(agentUsage.helpText(verb));
231
+ process.exitCode = EXIT.OK;
232
+ return;
233
+ }
213
234
  var parsed = parseSessionArgs(verb, args);
214
235
  if (parsed.error) {
215
236
  console.error(parsed.error);
@@ -222,9 +243,13 @@ function runSessionVerb(verb, args) {
222
243
  }
223
244
  request.cmd = IPC_COMMAND[verb];
224
245
  if (verb === "open-session" || verb === "send-input" || verb === "end-session" || verb === "answer-prompt") withSenderRef(request, process.env);
246
+ var verbose = !!request.verbose;
247
+ // list-outbound has one record shape; the compact form is cut here, so the
248
+ // daemon is not told.
249
+ if (verb === "list-outbound") delete request.verbose;
225
250
 
226
251
  requestDaemon(request).then(function (res) {
227
- console.log(JSON.stringify(res, null, 2));
252
+ console.log(JSON.stringify(presentResult(verb, res, verbose), null, 2));
228
253
  // Not process.exit: on a pipe it can cut the JSON off before stdout drains.
229
254
  process.exitCode = exitCodeFor(res, request);
230
255
  });
@@ -247,6 +272,7 @@ function requestDaemon(request, deps) {
247
272
  module.exports = {
248
273
  requestDaemon: requestDaemon,
249
274
  parseSessionArgs: parseSessionArgs,
275
+ presentResult: presentResult,
250
276
  withSenderRef: withSenderRef,
251
277
  exitCodeFor: exitCodeFor,
252
278
  runSessionVerb: runSessionVerb,
@@ -0,0 +1,74 @@
1
+ // lib/cli/settings-subcommands.js
2
+ //
3
+ // `clagentic-console settings get <key>`, `settings set <key> <value>` and
4
+ // `settings list`: read and change server-wide settings through the running
5
+ // daemon's IPC socket. Each prints the daemon's result as JSON on stdout.
6
+ //
7
+ // <value> is parsed as JSON when it parses (10 is a number, true a boolean),
8
+ // otherwise it is taken as a string; the daemon validates it.
9
+ //
10
+ // Exit codes (documented in docs/guides/AGENT-GUIDE.md):
11
+ // 0 read, saved or listed
12
+ // 1 refused, unknown key, error, or a usage error (no daemon contact)
13
+
14
+ var { requestDaemon } = require("./session-subcommands");
15
+
16
+ var USAGE = [
17
+ "Usage: clagentic-console settings get <key>",
18
+ " clagentic-console settings set <key> <value>",
19
+ " clagentic-console settings list",
20
+ ].join("\n");
21
+
22
+ var IPC_COMMAND = { get: "settings_get", set: "settings_set", list: "settings_list" };
23
+
24
+ // The value is JSON when it parses, else the raw string.
25
+ function parseValue(text) {
26
+ try {
27
+ return JSON.parse(text);
28
+ } catch (e) {
29
+ return text;
30
+ }
31
+ }
32
+
33
+ // Returns { help: true }, { request } or { error }. Pure: no IPC.
34
+ function parseSettingsArgs(args) {
35
+ var sub = args[0];
36
+ if (sub === undefined) return { error: "Missing settings subcommand" };
37
+ if (sub === "-h" || sub === "--help") return { help: true };
38
+ if (!Object.prototype.hasOwnProperty.call(IPC_COMMAND, sub)) return { error: "Unknown settings subcommand: " + sub };
39
+ var rest = args.slice(1);
40
+ if (rest.indexOf("-h") !== -1 || rest.indexOf("--help") !== -1) return { help: true };
41
+ var arity = { get: 1, set: 2, list: 0 }[sub];
42
+ if (rest.length < arity) return { error: "Missing argument for settings " + sub };
43
+ if (rest.length > arity) return { error: "Unexpected argument for settings " + sub + ": " + rest[arity] };
44
+ var request = { cmd: IPC_COMMAND[sub] };
45
+ if (sub !== "list") request.key = rest[0];
46
+ if (sub === "set") request.value = parseValue(rest[1]);
47
+ return { request: request };
48
+ }
49
+
50
+ function runSettingsVerb(args) {
51
+ var parsed = parseSettingsArgs(args);
52
+ if (parsed.help) {
53
+ console.log(USAGE);
54
+ return;
55
+ }
56
+ if (parsed.error) {
57
+ console.error(parsed.error);
58
+ console.error(USAGE);
59
+ process.exitCode = 1;
60
+ return;
61
+ }
62
+ requestDaemon(parsed.request).then(function (res) {
63
+ console.log(JSON.stringify(res, null, 2));
64
+ // Not process.exit: on a pipe it can cut the JSON off before stdout drains.
65
+ process.exitCode = res && res.ok ? 0 : 1;
66
+ });
67
+ }
68
+
69
+ module.exports = {
70
+ parseSettingsArgs: parseSettingsArgs,
71
+ parseValue: parseValue,
72
+ runSettingsVerb: runSettingsVerb,
73
+ USAGE: USAGE,
74
+ };
@@ -84,6 +84,26 @@ function readLatestAiTitle(filePath, sessionId) {
84
84
  }).catch(function () { return null; });
85
85
  }
86
86
 
87
+ // The fallback sweep reads the projects directory and stats one path per
88
+ // project, and findTranscript runs on every turn result. Two bounded memos keep
89
+ // that to one sweep per (claudeDir, sessionId): the path a sweep resolved
90
+ // (re-verified with one stat on reuse), and the time of a sweep that found
91
+ // nothing (no new sweep until retryMs has passed, so a transcript written later
92
+ // is still found). Insertion order makes the oldest entry the first key.
93
+ var limits = {
94
+ maxEntries: 512,
95
+ retryMs: 60 * 1000,
96
+ now: function () { return Date.now(); },
97
+ };
98
+ var hits = new Map();
99
+ var misses = new Map();
100
+
101
+ function remember(memo, key, value) {
102
+ memo.delete(key);
103
+ memo.set(key, value);
104
+ while (memo.size > limits.maxEntries) memo.delete(memo.keys().next().value);
105
+ }
106
+
87
107
  // Finds <claudeDir>/projects/*/<sessionId>.jsonl. The directory named for a
88
108
  // cwd in cwds is tried first; any other project directory is searched after,
89
109
  // because the CLI names the directory for the cwd the query ran in.
@@ -110,8 +130,12 @@ function findTranscript(claudeDir, cwds, sessionId) {
110
130
  return exists(p).then(function (ok) { return ok ? p : tryDirs(i + 1); });
111
131
  }
112
132
 
113
- return tryDirs(0).then(function (hit) {
114
- if (hit) return hit;
133
+ var key = claudeDir + "\0" + sessionId;
134
+
135
+ // The sweep over every project directory. The result, hit or miss, is
136
+ // memoized so a session whose transcript is outside its cwd's directory does
137
+ // not pay for the sweep on every turn.
138
+ function fullScan() {
115
139
  return fs.promises.readdir(projectsDir).then(function (names) {
116
140
  function next(i) {
117
141
  if (i >= names.length) return Promise.resolve(null);
@@ -121,11 +145,40 @@ function findTranscript(claudeDir, cwds, sessionId) {
121
145
  return exists(p).then(function (ok) { return ok ? p : next(i + 1); });
122
146
  }
123
147
  return next(0);
124
- }, function () { return null; });
148
+ }, function () { return null; }).then(function (found) {
149
+ if (found) {
150
+ remember(hits, key, found);
151
+ misses.delete(key);
152
+ } else {
153
+ remember(misses, key, limits.now());
154
+ }
155
+ return found;
156
+ });
157
+ }
158
+
159
+ // The cwd directories are always tried first, so a transcript that appears in
160
+ // the cwd's own directory still wins over a memoized fallback path.
161
+ return tryDirs(0).then(function (hit) {
162
+ if (hit) return hit;
163
+ var memo = hits.get(key);
164
+ if (memo) {
165
+ return exists(memo).then(function (ok) {
166
+ if (ok) return memo;
167
+ hits.delete(key);
168
+ return fullScan();
169
+ });
170
+ }
171
+ var missedAt = misses.get(key);
172
+ if (missedAt !== undefined && limits.now() - missedAt < limits.retryMs) return null;
173
+ return fullScan();
125
174
  });
126
175
  }
127
176
 
128
177
  module.exports = {
129
178
  readLatestAiTitle: readLatestAiTitle,
130
179
  findTranscript: findTranscript,
180
+ // Test seams: the bounds and clock are module values, not settings.
181
+ limits: limits,
182
+ resetMemo: function () { hits.clear(); misses.clear(); },
183
+ memoSizes: function () { return { hits: hits.size, misses: misses.size }; },
131
184
  };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ // client-files.js — the browser client file set this process loaded at startup.
4
+ //
5
+ // The server used to read lib/public from the install directory on every
6
+ // request. After an npm install without a restart, the running (old) server then
7
+ // handed out the NEW client, which can need a server route the old build lacks
8
+ // and fails at boot. The set is therefore read once, when this module is first
9
+ // required (daemon startup, before any later install), and served from memory
10
+ // from then on, so a process only ever serves the client of the build it runs.
11
+ //
12
+ // The restart-to-update path is unaffected: it is an in-band offer the loaded
13
+ // client already holds, and a restart loads the new set.
14
+
15
+ var fs = require("fs");
16
+ var path = require("path");
17
+
18
+ var PUBLIC_DIR = path.join(__dirname, "public");
19
+
20
+ /** Key for a file below `root`: posix separators, no leading slash. */
21
+ function keyFor(root, filePath) {
22
+ return path.relative(root, filePath).split(path.sep).join("/");
23
+ }
24
+
25
+ /** Runs one filesystem step; a failure names the path and the cause. */
26
+ function step(what, target, fn) {
27
+ try {
28
+ return fn();
29
+ } catch (e) {
30
+ throw new Error("Clagentic: Console cannot start: " + what + " " + target + " failed: " +
31
+ (e && e.code ? e.code + " " : "") + (e && e.message ? e.message : String(e)));
32
+ }
33
+ }
34
+
35
+ // A skipped file would publish a partial client, a browser that boots against
36
+ // a half-served set. Every failure aborts the capture instead.
37
+ function walk(root, dir, into) {
38
+ var names = step("reading directory", dir, function () { return fs.readdirSync(dir); });
39
+ for (var i = 0; i < names.length; i++) {
40
+ var full = path.join(dir, names[i]);
41
+ var stat = step("inspecting", full, function () { return fs.statSync(full); });
42
+ if (stat.isDirectory()) {
43
+ walk(root, full, into);
44
+ } else if (stat.isFile()) {
45
+ into.set(keyFor(root, full), step("reading", full, function () { return fs.readFileSync(full); }));
46
+ }
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Reads every file below `root` into memory, or throws naming the path and
52
+ * cause of the first failure; it never returns a partial set. The returned set
53
+ * is immutable in use: `read` hands back the captured bytes whatever the disk
54
+ * holds later.
55
+ */
56
+ function capture(root) {
57
+ var files = new Map();
58
+ walk(root, root, files);
59
+ var bytes = 0;
60
+ files.forEach(function (buf) { bytes += buf.length; });
61
+ return {
62
+ root: root,
63
+ count: files.size,
64
+ bytes: bytes,
65
+ /** The captured bytes for a path relative to the root, or null. */
66
+ read: function (relPath) {
67
+ var buf = files.get(relPath);
68
+ return buf === undefined ? null : buf;
69
+ },
70
+ keys: function () { return Array.from(files.keys()); },
71
+ };
72
+ }
73
+
74
+ var publicFiles = capture(PUBLIC_DIR);
75
+
76
+ module.exports = {
77
+ capture: capture,
78
+ publicFiles: publicFiles,
79
+ };
package/lib/daemon.js CHANGED
@@ -42,13 +42,16 @@ var { validateMemAvailableThresholdMB, validateTokensPerMbHeadroom } = require("
42
42
  var { startMemoryHighWatcher, checkAppliedMemoryCeiling } = require("./memory-limits");
43
43
  var { readPermissionSettings, DEFAULT_OPENED_SESSION_MODE } = require("./permission-settings");
44
44
  var userShellSettings = require("./user-shell-settings");
45
+ var promptExpirySettings = require("./prompt-expiry-settings");
46
+ var chatWidthSetting = require("./settings-registry").findSetting("chatWidth");
47
+ var sessionListAvatarsSetting = require("./settings-registry").findSetting("sessionListAvatars");
45
48
  var { createDrain } = require("./drain");
46
49
  var { setNewWorkGate } = require("./new-work-gate");
47
50
  var { shedMemory } = require("./memory-shed");
48
51
  var { dropSkillsCache } = require("./server-skills");
49
52
  var { createBuildMonitor } = require("./build-monitor");
50
53
  var { createBuildUpdateRestart } = require("./build-update-restart");
51
- var { composeNotice, noticeCooldownFrom, composeRestartingNotice } = require("./build-update-offer");
54
+ var { composeNotice, noticeCooldownFrom, composeRestartingNotice, inFlightSessions } = require("./build-update-offer");
52
55
  var { createStandingOffer } = require("./build-update-standing");
53
56
  var buildUpdateNotify = require("./build-update-notify");
54
57
  var { listBuildChanges, resolveHistoryRepo } = require("./build-changes");
@@ -177,7 +180,7 @@ function migrateSingleUserToMultiUser(cfg, data) {
177
180
  profile: {
178
181
  name: "Admin",
179
182
  lang: "en-US",
180
- avatarColor: "#7c3aed",
183
+ avatarColor: require("./default-avatar-color").DEFAULT_AVATAR_COLOR,
181
184
  avatarStyle: "thumbs",
182
185
  avatarSeed: cryptoMig.randomBytes(4).toString("hex"),
183
186
  },
@@ -293,7 +296,7 @@ var envSettings = createEnvSettings({
293
296
  // --- Create multi-project server ---
294
297
  var listenHost = config.host || "0.0.0.0";
295
298
 
296
- var relay = createServer({
299
+ var serverHooks = {
297
300
  tlsOptions: tlsOptions,
298
301
  caPath: caRoot,
299
302
  builtinCert: config.builtinCert || false,
@@ -1057,6 +1060,14 @@ var relay = createServer({
1057
1060
  saveConfig(config);
1058
1061
  return { ok: true, settings: userShellSettings.readUserShellSettings(config) };
1059
1062
  },
1063
+ onGetPromptExpirySettings: function () {
1064
+ return promptExpirySettings.settingsMessage(config);
1065
+ },
1066
+ onSetPromptExpirySettings: function (minutes) {
1067
+ promptExpirySettings.applySettingChange(config, minutes);
1068
+ saveConfig(config);
1069
+ return { ok: true };
1070
+ },
1060
1071
  onGetProjectDefaultMode: function (slug) {
1061
1072
  for (var i = 0; i < config.projects.length; i++) {
1062
1073
  if (config.projects[i].slug === slug) {
@@ -1130,9 +1141,9 @@ var relay = createServer({
1130
1141
  headless: !!config.headless,
1131
1142
  keepAwake: !!config.keepAwake,
1132
1143
  autoContinueOnRateLimit: !!config.autoContinueOnRateLimit,
1133
- chatLayout: config.chatLayout || "channel",
1144
+ chatWidth: chatWidthSetting.read(config),
1145
+ sessionListAvatars: sessionListAvatarsSetting.read(config),
1134
1146
  themeMode: config.themeMode || null,
1135
- themeBrand: config.themeBrand || null,
1136
1147
  pinEnabled: !!config.pinHash,
1137
1148
  platform: process.platform,
1138
1149
  hostname: os2.hostname(),
@@ -1174,12 +1185,26 @@ var relay = createServer({
1174
1185
  // onSetPin intentionally removed — single-user PIN mode no longer exists (lr-ec2d).
1175
1186
  // Individual user PINs are managed via users.js / server-admin.js.
1176
1187
  onSetPin: null,
1177
- onSetChatLayout: function (layout) {
1178
- var val = (layout === "bubble") ? "bubble" : "channel";
1179
- config.chatLayout = val;
1188
+ // The width a user with no saved choice gets (`settings set chatWidth`).
1189
+ onSetChatWidthDefault: function (width) {
1190
+ chatWidthSetting.apply(config, width);
1180
1191
  saveConfig(config);
1181
- console.log("[daemon] Chat layout:", val, "(web)");
1182
- return { ok: true, chatLayout: val };
1192
+ console.log("[daemon] Default chat width:", chatWidthSetting.read(config));
1193
+ return { ok: true };
1194
+ },
1195
+ onGetChatWidthDefault: function () {
1196
+ return { type: "daemon_config_changed", chatWidth: chatWidthSetting.read(config) };
1197
+ },
1198
+ // Whether a person with no saved choice sees agent avatars in the session lists
1199
+ // (`settings set sessionListAvatars`).
1200
+ onSetSessionListAvatarsDefault: function (value) {
1201
+ sessionListAvatarsSetting.apply(config, value);
1202
+ saveConfig(config);
1203
+ console.log("[daemon] Default avatars in session list:", sessionListAvatarsSetting.read(config));
1204
+ return { ok: true };
1205
+ },
1206
+ onGetSessionListAvatarsDefault: function () {
1207
+ return { type: "daemon_config_changed", sessionListAvatars: sessionListAvatarsSetting.read(config) };
1183
1208
  },
1184
1209
  onSetThemeMode: function (mode) {
1185
1210
  var val = (mode === "light" || mode === "dark") ? mode : null;
@@ -1188,13 +1213,6 @@ var relay = createServer({
1188
1213
  console.log("[daemon] Theme mode:", val, "(web)");
1189
1214
  return { ok: true, themeMode: val };
1190
1215
  },
1191
- onSetThemeBrand: function (brand) {
1192
- var val = (brand === "classic" || brand === "clagentic") ? brand : null;
1193
- config.themeBrand = val;
1194
- saveConfig(config);
1195
- console.log("[daemon] Theme brand:", val, "(web)");
1196
- return { ok: true, themeBrand: val };
1197
- },
1198
1216
  onSetAutoContinue: function (value) {
1199
1217
  var want = !!value;
1200
1218
  config.autoContinueOnRateLimit = want;
@@ -1401,7 +1419,24 @@ var relay = createServer({
1401
1419
  });
1402
1420
  return { ok: true, slug: wtSlug, path: result.path };
1403
1421
  },
1404
- });
1422
+ };
1423
+ var relay = createServer(serverHooks);
1424
+
1425
+ // Setters and page announcements for the keys of lib/settings-registry.js.
1426
+ var settingsHooks = {
1427
+ promptExpiryMinutes: {
1428
+ set: serverHooks.onSetPromptExpirySettings,
1429
+ announce: serverHooks.onGetPromptExpirySettings,
1430
+ },
1431
+ chatWidth: {
1432
+ set: serverHooks.onSetChatWidthDefault,
1433
+ announce: serverHooks.onGetChatWidthDefault,
1434
+ },
1435
+ sessionListAvatars: {
1436
+ set: serverHooks.onSetSessionListAvatarsDefault,
1437
+ announce: serverHooks.onGetSessionListAvatarsDefault,
1438
+ },
1439
+ };
1405
1440
 
1406
1441
  // --- Build adoption: is the installed build the one this process loaded? ---
1407
1442
  // The verdict is buildIdentity.assess() (sha plus content hash), not the
@@ -1409,10 +1444,11 @@ var relay = createServer({
1409
1444
  // checks is announced: in the journal, and as an offer in the UI. Announcing
1410
1445
  // restarts nothing; the one path to a restart is the operator's confirmed
1411
1446
  // click handled by buildUpdateRestart (lib/build-update-restart.js).
1412
- var buildHistoryRepo = resolveHistoryRepo(config.buildSourceRepo, path.join(__dirname, ".."));
1413
-
1447
+ // Resolved per call: the source recorded by install:local-test sits in the
1448
+ // installed build, which is the one that changes under a running daemon.
1414
1449
  function listChangesBetweenBuilds(range) {
1415
- return listBuildChanges({ repo: buildHistoryRepo, fromSha: range.fromSha, toSha: range.toSha });
1450
+ var repo = resolveHistoryRepo(config.buildSourceRepo, path.join(__dirname, ".."));
1451
+ return listBuildChanges({ repo: repo, fromSha: range.fromSha, toSha: range.toSha });
1416
1452
  }
1417
1453
 
1418
1454
  function liveProjectsForOffer() {
@@ -1747,6 +1783,25 @@ var ipc = createIPCServer(socketPath(), function (msg) {
1747
1783
  getProject: relay.getProject,
1748
1784
  }, msg);
1749
1785
 
1786
+ // Server-wide settings by key (`clagentic-console settings`). A set goes
1787
+ // through the same hooks the Settings page uses and is announced to open
1788
+ // pages. Same OS-level socket gate as every command here (CONFIG_DIR is
1789
+ // chmod 0700): any process running as the daemon's OS user may set them.
1790
+ case "settings_get":
1791
+ case "settings_set":
1792
+ case "settings_list":
1793
+ return require("./settings-ipc").handleSettingsCommand({
1794
+ registry: require("./settings-registry"),
1795
+ getConfig: function () { return config; },
1796
+ set: function (key, value) {
1797
+ var hooks = settingsHooks[key];
1798
+ if (!hooks) return false;
1799
+ hooks.set(value);
1800
+ return true;
1801
+ },
1802
+ announce: function (key) { relay.broadcastAll(settingsHooks[key].announce()); },
1803
+ }, msg);
1804
+
1750
1805
  case "set_pin": {
1751
1806
  config.pinHash = msg.pinHash || null;
1752
1807
  relay.setAuthToken(config.pinHash);
@@ -1873,6 +1928,11 @@ var ipc = createIPCServer(socketPath(), function (msg) {
1873
1928
  gracefulShutdown();
1874
1929
  return { ok: true };
1875
1930
 
1931
+ // Read-only: the sessions a restart now would end, for the restart verb to
1932
+ // report before it asks for one. It informs; nothing is refused on it.
1933
+ case "get_interruptions":
1934
+ return { ok: true, sessions: inFlightSessions(liveProjectsForOffer()) };
1935
+
1876
1936
  case "restart":
1877
1937
  console.log("[daemon] Restart requested via IPC");
1878
1938
  spawnAndRestart();
@@ -1901,7 +1961,7 @@ var ipc = createIPCServer(socketPath(), function (msg) {
1901
1961
  // Resolve + install asynchronously. ipc.js awaits a returned Promise, so
1902
1962
  // returning an async IIFE here is safe without changing the outer handler.
1903
1963
  return (async function () {
1904
- var { execFileSync: execFileUpd } = require("child_process");
1964
+ var { installGlobalAtomically } = require("./atomic-install");
1905
1965
  var updater = require("./updater");
1906
1966
 
1907
1967
  // Resolve the target version the same way the startup updater does, then
@@ -1931,10 +1991,11 @@ var ipc = createIPCServer(socketPath(), function (msg) {
1931
1991
  var updOk = false;
1932
1992
  try {
1933
1993
  console.log("[daemon] Installing @clagentic/console@" + updTarget + " globally (current " + daemonVersion + ")...");
1934
- execFileUpd("npm", ["install", "-g", "@clagentic/console@" + updTarget], {
1935
- stdio: ["ignore", "pipe", "pipe"],
1936
- timeout: 120000,
1937
- encoding: "utf8",
1994
+ // Staged install plus atomic swap: the clagentic-console command stays
1995
+ // on PATH for CLI callers while the new build is installed.
1996
+ await installGlobalAtomically({
1997
+ spec: "@clagentic/console@" + updTarget,
1998
+ timeoutMs: 120000,
1938
1999
  // CLAGENTIC_CONSOLE_SELF_UPDATE=1 tells postinstall.js not to restart the
1939
2000
  // service — gracefulShutdown() below hands off to systemd Restart=always.
1940
2001
  env: Object.assign({}, process.env, { CLAGENTIC_CONSOLE_SELF_UPDATE: "1" }),
@@ -1997,6 +2058,7 @@ function startListening() {
1997
2058
  gracefulShutdown: gracefulShutdown,
1998
2059
  getActiveCount: getActiveLiveCount,
1999
2060
  drainTimeoutMs: drainTimeoutMs,
2061
+ sigtermDrainTimeoutMs: config.sigtermDrainTimeoutMs,
2000
2062
  onPressureChange: function (underPressure, detail) {
2001
2063
  relay.broadcastAll({
2002
2064
  type: "diagnostic",
@@ -2314,8 +2376,18 @@ function gracefulShutdown() {
2314
2376
  }, 10000);
2315
2377
  }
2316
2378
 
2317
- process.on("SIGTERM", gracefulShutdown);
2318
- process.on("SIGINT", gracefulShutdown);
2379
+ // SIGTERM (systemctl stop/restart) and SIGINT wait a short, bounded time for
2380
+ // running queries through the drain before shutting down, so a raw service stop
2381
+ // does not cut agent work off at once. Before the drain controller exists there
2382
+ // is nothing to wait for, so the signal shuts down directly.
2383
+ function terminationSignalHandler(reason) {
2384
+ return function () {
2385
+ if (_drain) _drain.enterTermDrain(reason);
2386
+ else gracefulShutdown();
2387
+ };
2388
+ }
2389
+ process.on("SIGTERM", terminationSignalHandler("signal_term"));
2390
+ process.on("SIGINT", terminationSignalHandler("signal_int"));
2319
2391
 
2320
2392
  // Last-resort cleanup: kill caffeinate if process exits without graceful shutdown
2321
2393
  process.on("exit", function () {
@@ -0,0 +1,4 @@
1
+ // The avatar colour a user gets before they pick one. It is stored data (a
2
+ // user's own choice, kept in their profile), not a theme colour, so it does not
3
+ // follow the active theme.
4
+ module.exports = { DEFAULT_AVATAR_COLOR: "#7c3aed" };