@clagentic/console 1.12.0 → 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
@@ -2,8 +2,8 @@
2
2
  //
3
3
  // One-shot IPC subcommand handlers for bin/cli.js: --shutdown, --restart,
4
4
  // --add <path>, --remove <path>, --list, --activity-diagnostics. Each of
5
- // these talks to the running daemon over the Unix socket and exits the
6
- // process directly (they never return control to the caller) —
5
+ // these talks to the running daemon over the Unix socket and ends the
6
+ // process itself (they never return control to the caller) —
7
7
  // --shutdown/--restart/--add/--remove/--list extracted verbatim from
8
8
  // bin/cli.js (lr-4e49 Part 1), no behavior change.
9
9
  // --activity-diagnostics added by lr-8b476f: the only agent-readable
@@ -14,12 +14,28 @@
14
14
  // RUNNING daemon actually loaded at startup (distinct from the on-disk
15
15
  // artifact's build-sha.json), so scripts/verify-installed-build.js can gate
16
16
  // on process build identity, not just artifact build identity.
17
+ //
18
+ // Every exit goes through exitFlushed (lib/cli/output.js): on a pipe, a write
19
+ // followed at once by process.exit can lose output. A handler that calls it must
20
+ // return straight after, because the exit happens once the output is flushed, not
21
+ // at the call.
17
22
 
18
23
  var fs = require("fs");
19
24
  var path = require("path");
20
25
 
21
26
  var { loadConfig, socketPath, isDaemonAliveAsync, checkOldDaemon, clearStaleConfig } = require("../config");
22
27
  var { sendIPCCommand } = require("../ipc");
28
+ var { exitFlushed } = require("./output");
29
+ var { runRestart, humanLines } = require("./restart-verb");
30
+
31
+ // The daemon's answer as JSON, whole: a field the daemon adds later is printed
32
+ // without a change here. Only the ok envelope is left out, since the exit code
33
+ // already says it.
34
+ function printDaemonJson(res) {
35
+ var body = Object.assign({}, res);
36
+ delete body.ok;
37
+ console.log(JSON.stringify(body, null, 2));
38
+ }
23
39
 
24
40
  function handleShutdown() {
25
41
  var shutdownConfig = loadConfig();
@@ -29,13 +45,13 @@ function handleShutdown() {
29
45
  if (resp && resp.ok) {
30
46
  console.log("Server stopped.");
31
47
  clearStaleConfig();
32
- process.exit(0);
48
+ exitFlushed(0);
33
49
  } else {
34
50
  var pid = shutdownConfig && shutdownConfig.pid;
35
51
  console.error("Shutdown failed: daemon did not acknowledge the command.");
36
52
  if (pid) console.error(" Daemon PID: " + pid + " (try: kill " + pid + ")");
37
53
  console.error(" Or: systemctl restart clagentic-console");
38
- process.exit(1);
54
+ exitFlushed(1);
39
55
  }
40
56
  });
41
57
  }
@@ -46,37 +62,53 @@ function handleShutdown() {
46
62
  return sendIPCCommand(old.sockPath, { cmd: "shutdown" }).then(function (resp) {
47
63
  if (resp && resp.ok) {
48
64
  console.log("Server stopped.");
49
- process.exit(0);
65
+ exitFlushed(0);
50
66
  } else {
51
67
  var oldPid = shutdownConfig && shutdownConfig.pid;
52
68
  console.error("Shutdown of pre-1.5 daemon failed: no acknowledgement from " + old.sockPath);
53
69
  if (oldPid) console.error(" Daemon PID: " + oldPid + " (try: kill " + oldPid + ")");
54
70
  console.error(" Or: systemctl restart clagentic-console");
55
- process.exit(1);
71
+ exitFlushed(1);
56
72
  }
57
73
  });
58
74
  }
59
75
  console.error("No running daemon found.");
60
- process.exit(1);
76
+ exitFlushed(1);
61
77
  });
62
78
  });
63
79
  }
64
80
 
65
- function handleRestart() {
81
+ function sleepMs(ms) {
82
+ return new Promise(function (resolve) { setTimeout(resolve, ms); });
83
+ }
84
+
85
+ // Reports the sessions in flight, restarts through the daemon's own restart
86
+ // command, and waits for the new process before saying so. With asJson the one
87
+ // report is printed as JSON and the exit code says the outcome (see
88
+ // lib/cli/restart-verb.js EXIT); without it the same result is human text.
89
+ function handleRestart(asJson) {
66
90
  var restartConfig = loadConfig();
67
91
  isDaemonAliveAsync(restartConfig).then(function (alive) {
68
92
  if (alive) {
69
- return sendIPCCommand(socketPath(), { cmd: "restart" }).then(function (resp) {
70
- if (resp && resp.ok) {
71
- console.log("Server restarted.");
72
- process.exit(0);
93
+ var sock = socketPath();
94
+ return runRestart({
95
+ send: function (msg) { return sendIPCCommand(sock, msg); },
96
+ sleep: sleepMs,
97
+ now: Date.now,
98
+ configPid: restartConfig && restartConfig.pid,
99
+ }).then(function (result) {
100
+ if (asJson) {
101
+ console.log(JSON.stringify(result.report, null, 2));
73
102
  } else {
103
+ var log = result.code === 0 ? console.log : console.error;
104
+ humanLines(result).forEach(function (line) { log(line); });
74
105
  var pid = restartConfig && restartConfig.pid;
75
- console.error("Restart failed: daemon did not acknowledge the command.");
76
- if (pid) console.error(" Daemon PID: " + pid + " (try: kill " + pid + " && clagentic-console)");
77
- console.error(" Or: systemctl restart clagentic-console");
78
- process.exit(1);
106
+ if (result.report.outcome === "restart-not-acknowledged") {
107
+ if (pid) console.error(" Daemon PID: " + pid + " (try: kill " + pid + " && clagentic-console)");
108
+ console.error(" Or: systemctl restart clagentic-console");
109
+ }
79
110
  }
111
+ exitFlushed(result.code);
80
112
  });
81
113
  }
82
114
  // New socket not alive — check whether a pre-1.5 daemon is on the old path
@@ -89,39 +121,44 @@ function handleRestart() {
89
121
  return sendIPCCommand(old.sockPath, { cmd: "shutdown" }).then(function (resp) {
90
122
  if (resp && resp.ok) {
91
123
  console.log("Pre-1.5 daemon stopped. Run clagentic-console to start the updated daemon.");
92
- process.exit(0);
124
+ exitFlushed(0);
93
125
  } else {
94
126
  var oldPid = restartConfig && restartConfig.pid;
95
127
  console.error("Shutdown of pre-1.5 daemon failed: no acknowledgement from " + old.sockPath);
96
128
  if (oldPid) console.error(" Daemon PID: " + oldPid + " (try: kill " + oldPid + ")");
97
129
  console.error(" Or: systemctl restart clagentic-console");
98
- process.exit(1);
130
+ exitFlushed(1);
99
131
  }
100
132
  });
101
133
  }
102
- console.error("No running daemon found.");
103
- process.exit(1);
134
+ if (asJson) console.log(JSON.stringify({ outcome: "no-daemon" }, null, 2));
135
+ else console.error("No running daemon found.");
136
+ exitFlushed(1);
104
137
  });
105
138
  });
106
139
  }
107
140
 
108
141
  function handleAdd(addPath) {
109
142
  var absAdd = path.resolve(addPath);
143
+ var stat = null;
110
144
  try {
111
- var stat = fs.statSync(absAdd);
112
- if (!stat.isDirectory()) {
113
- console.error("Not a directory: " + absAdd);
114
- process.exit(1);
115
- }
145
+ stat = fs.statSync(absAdd);
116
146
  } catch (e) {
117
147
  console.error("Directory not found: " + absAdd);
118
- process.exit(1);
148
+ exitFlushed(1);
149
+ return;
150
+ }
151
+ if (!stat.isDirectory()) {
152
+ console.error("Not a directory: " + absAdd);
153
+ exitFlushed(1);
154
+ return;
119
155
  }
120
156
  var addConfig = loadConfig();
121
157
  isDaemonAliveAsync(addConfig).then(function (alive) {
122
158
  if (!alive) {
123
159
  console.error("No running daemon. Start with: npx @clagentic/console");
124
- process.exit(1);
160
+ exitFlushed(1);
161
+ return;
125
162
  }
126
163
  sendIPCCommand(socketPath(), { cmd: "add_project", path: absAdd }).then(function (res) {
127
164
  if (res.ok) {
@@ -130,10 +167,10 @@ function handleAdd(addPath) {
130
167
  } else {
131
168
  console.log("Added: " + res.slug + " → " + absAdd);
132
169
  }
133
- process.exit(0);
170
+ exitFlushed(0);
134
171
  } else {
135
172
  console.error("Failed: " + (res.error || "unknown error"));
136
- process.exit(1);
173
+ exitFlushed(1);
137
174
  }
138
175
  });
139
176
  });
@@ -145,15 +182,16 @@ function handleRemove(removePath) {
145
182
  isDaemonAliveAsync(removeConfig).then(function (alive) {
146
183
  if (!alive) {
147
184
  console.error("No running daemon. Start with: npx @clagentic/console");
148
- process.exit(1);
185
+ exitFlushed(1);
186
+ return;
149
187
  }
150
188
  sendIPCCommand(socketPath(), { cmd: "remove_project", path: absRemove }).then(function (res) {
151
189
  if (res.ok) {
152
190
  console.log("Removed: " + path.basename(absRemove));
153
- process.exit(0);
191
+ exitFlushed(0);
154
192
  } else {
155
193
  console.error("Failed: " + (res.error || "project not found"));
156
- process.exit(1);
194
+ exitFlushed(1);
157
195
  }
158
196
  });
159
197
  });
@@ -164,12 +202,13 @@ function handleList() {
164
202
  isDaemonAliveAsync(listConfig).then(function (alive) {
165
203
  if (!alive) {
166
204
  console.error("No running daemon. Start with: npx @clagentic/console");
167
- process.exit(1);
205
+ exitFlushed(1);
206
+ return;
168
207
  }
169
208
  sendIPCCommand(socketPath(), { cmd: "get_status" }).then(function (res) {
170
209
  if (!res.ok || !res.projects || res.projects.length === 0) {
171
210
  console.log("No projects registered.");
172
- process.exit(0);
211
+ exitFlushed(0);
173
212
  return;
174
213
  }
175
214
  console.log("Projects (" + res.projects.length + "):\n");
@@ -181,7 +220,7 @@ function handleList() {
181
220
  console.log(label);
182
221
  }
183
222
  console.log("");
184
- process.exit(0);
223
+ exitFlushed(0);
185
224
  });
186
225
  });
187
226
  }
@@ -203,30 +242,20 @@ function handleProcessBuildStatus() {
203
242
  // ok:false + a stable error string rather than a bare non-zero exit
204
243
  // with no machine-readable reason.
205
244
  console.log(JSON.stringify({ ok: false, error: "no running daemon" }, null, 2));
206
- process.exit(1);
245
+ exitFlushed(1);
207
246
  return;
208
247
  }
209
248
  sendIPCCommand(socketPath(), { cmd: "get_build_status" }).then(function (res) {
210
249
  if (!res.ok) {
211
250
  console.error("Failed: " + (res.error || "unknown error"));
212
- process.exit(1);
251
+ exitFlushed(1);
213
252
  return;
214
253
  }
215
254
  // Raw JSON to stdout -- the point is machine readability for a gate
216
255
  // script, not a human-formatted summary (contrast handleList's
217
256
  // formatted output).
218
- console.log(JSON.stringify({
219
- loadedBuildSha: res.loadedBuildSha,
220
- installedBuildSha: res.installedBuildSha,
221
- state: res.state,
222
- reason: res.reason,
223
- detail: res.detail,
224
- loadedContentHash: res.loadedContentHash,
225
- installedContentHash: res.installedContentHash,
226
- staleInodes: res.staleInodes,
227
- pid: res.pid,
228
- }, null, 2));
229
- process.exit(0);
257
+ printDaemonJson(res);
258
+ exitFlushed(0);
230
259
  });
231
260
  });
232
261
  }
@@ -241,22 +270,20 @@ function handleActivityDiagnostics() {
241
270
  isDaemonAliveAsync(diagConfig).then(function (alive) {
242
271
  if (!alive) {
243
272
  console.error("No running daemon. Start with: npx @clagentic/console");
244
- process.exit(1);
273
+ exitFlushed(1);
274
+ return;
245
275
  }
246
276
  sendIPCCommand(socketPath(), { cmd: "get_activity_diagnostics" }).then(function (res) {
247
277
  if (!res.ok) {
248
278
  console.error("Failed: " + (res.error || "unknown error"));
249
- process.exit(1);
279
+ exitFlushed(1);
250
280
  return;
251
281
  }
252
- // Raw JSON to stdout — the point is machine readability, not a
253
- // human-formatted summary (contrast handleList's formatted output).
254
- console.log(JSON.stringify({
255
- activeLiveCount: res.activeLiveCount,
256
- activityDivergenceCount: res.activityDivergenceCount,
257
- activityDivergenceRecentSamples: res.activityDivergenceRecentSamples,
258
- }, null, 2));
259
- process.exit(0);
282
+ // The whole response, so openSockets and any field added later reach the
283
+ // caller. Machine readability, not a human-formatted summary (contrast
284
+ // handleList's formatted output).
285
+ printDaemonJson(res);
286
+ exitFlushed(0);
260
287
  });
261
288
  });
262
289
  }
@@ -268,20 +295,17 @@ function handleUsage() {
268
295
  isDaemonAliveAsync(usageConfig).then(function (alive) {
269
296
  if (!alive) {
270
297
  console.error("No running daemon. Start with: npx @clagentic/console");
271
- process.exit(1);
298
+ exitFlushed(1);
299
+ return;
272
300
  }
273
301
  sendIPCCommand(socketPath(), { cmd: "get_usage" }).then(function (res) {
274
302
  if (!res.ok) {
275
303
  console.error("Failed: " + (res.error || "unknown error"));
276
- process.exit(1);
304
+ exitFlushed(1);
277
305
  return;
278
306
  }
279
- console.log(JSON.stringify({
280
- generatedAt: res.generatedAt,
281
- staleAfterSeconds: res.staleAfterSeconds,
282
- vendors: res.vendors,
283
- }, null, 2));
284
- process.exit(0);
307
+ printDaemonJson(res);
308
+ exitFlushed(0);
285
309
  });
286
310
  });
287
311
  }
@@ -295,4 +319,5 @@ module.exports = {
295
319
  handleList: handleList,
296
320
  handleActivityDiagnostics: handleActivityDiagnostics,
297
321
  handleProcessBuildStatus: handleProcessBuildStatus,
322
+ printDaemonJson: printDaemonJson,
298
323
  };
@@ -0,0 +1,28 @@
1
+ // lib/cli/output.js
2
+ //
3
+ // Ending a CLI subcommand without losing what it printed. On a pipe, stdout is
4
+ // asynchronous in Node: console.log followed at once by process.exit can cut the
5
+ // output off, and the larger the output, the likelier. exitFlushed waits for the
6
+ // writes already queued on stdout and stderr to reach the operating system, then
7
+ // exits.
8
+
9
+ // A zero-length write is queued behind every earlier write on the same stream,
10
+ // so its callback runs only after they have been flushed.
11
+ function drained(stream, then) {
12
+ stream.write("", then);
13
+ }
14
+
15
+ // io is for tests: { out, err, exit } in place of the process streams and exit.
16
+ function exitFlushed(code, io) {
17
+ io = io || {};
18
+ var out = io.out || process.stdout;
19
+ var err = io.err || process.stderr;
20
+ var exit = io.exit || process.exit;
21
+ drained(err, function () {
22
+ drained(out, function () {
23
+ exit(code);
24
+ });
25
+ });
26
+ }
27
+
28
+ module.exports = { exitFlushed: exitFlushed };
@@ -0,0 +1,132 @@
1
+ // lib/cli/restart-verb.js
2
+ //
3
+ // The `clagentic-console --restart` verb as one function over injected I/O, so
4
+ // the wait is testable without a daemon. It does not restart anything itself:
5
+ // the restart is the daemon's existing IPC "restart" command (supervisor-aware,
6
+ // see spawnAndRestart in lib/daemon.js). This module only reports the sessions
7
+ // in flight before it, waits for the NEW process after it, and reads that
8
+ // process's build status.
9
+ //
10
+ // It never refuses on in-flight sessions, and it has no notion of who is
11
+ // calling: the same verb runs the same way for every caller.
12
+
13
+ var EXIT = {
14
+ OK: 0,
15
+ // No daemon to restart, the restart was not acknowledged, or the old pid is unknown.
16
+ FAILED: 1,
17
+ // No new process answered within the timeout.
18
+ TIMEOUT: 2,
19
+ // A new process is up but it did not load the installed build.
20
+ BUILD_MISMATCH: 3,
21
+ };
22
+
23
+ var DEFAULT_TIMEOUT_MS = 60 * 1000;
24
+ var DEFAULT_POLL_MS = 500;
25
+
26
+ function buildMatches(status) {
27
+ return !!status.loadedBuildSha && status.loadedBuildSha === status.installedBuildSha;
28
+ }
29
+
30
+ // What the wait last saw, so a timeout says what was there instead of the new process.
31
+ function seenOf(res) {
32
+ if (res && res.ok) return { pid: res.pid || null, state: res.state || null, error: null };
33
+ return { pid: null, state: null, error: (res && res.error) || "no answer" };
34
+ }
35
+
36
+ /**
37
+ * @param {object} deps
38
+ * @param {function(object): Promise<object>} deps.send one IPC command to the daemon
39
+ * @param {function(number): Promise<void>} deps.sleep
40
+ * @param {function(): number} deps.now
41
+ * @param {number|null} [deps.configPid] pid recorded in the config, used when the daemon does not report one
42
+ * @param {object} [opts]
43
+ * @param {number} [opts.timeoutMs]
44
+ * @param {number} [opts.pollMs]
45
+ * @returns {Promise<{code: number, report: object}>}
46
+ */
47
+ async function runRestart(deps, opts) {
48
+ opts = opts || {};
49
+ var timeoutMs = opts.timeoutMs || DEFAULT_TIMEOUT_MS;
50
+ var pollMs = opts.pollMs || DEFAULT_POLL_MS;
51
+ var report = {
52
+ outcome: null,
53
+ oldPid: null,
54
+ sessions: null,
55
+ newPid: null,
56
+ loadedBuildSha: null,
57
+ installedBuildSha: null,
58
+ state: null,
59
+ lastSeen: null,
60
+ };
61
+
62
+ var before = await deps.send({ cmd: "get_build_status" });
63
+ report.oldPid = (before && before.ok && before.pid) || deps.configPid || null;
64
+ if (!report.oldPid) {
65
+ // Without the old pid the wait cannot tell the old process from the new one.
66
+ report.outcome = "old-pid-unknown";
67
+ return { code: EXIT.FAILED, report: report };
68
+ }
69
+
70
+ var flight = await deps.send({ cmd: "get_interruptions" });
71
+ report.sessions = flight && flight.ok && Array.isArray(flight.sessions) ? flight.sessions : null;
72
+
73
+ var ack = await deps.send({ cmd: "restart" });
74
+ if (!ack || !ack.ok) {
75
+ report.outcome = "restart-not-acknowledged";
76
+ report.lastSeen = seenOf(ack);
77
+ return { code: EXIT.FAILED, report: report };
78
+ }
79
+
80
+ var started = deps.now();
81
+ var res;
82
+ for (;;) {
83
+ res = await deps.send({ cmd: "get_build_status" });
84
+ report.lastSeen = seenOf(res);
85
+ // The old process can still answer between the acknowledgement and its exit;
86
+ // only a different pid is the new process.
87
+ if (res && res.ok && res.pid && res.pid !== report.oldPid) break;
88
+ if (deps.now() - started >= timeoutMs) {
89
+ report.outcome = "timeout";
90
+ return { code: EXIT.TIMEOUT, report: report };
91
+ }
92
+ await deps.sleep(pollMs);
93
+ }
94
+
95
+ report.newPid = res.pid;
96
+ report.loadedBuildSha = res.loadedBuildSha || null;
97
+ report.installedBuildSha = res.installedBuildSha || null;
98
+ report.state = res.state || null;
99
+ if (!buildMatches(res)) {
100
+ report.outcome = "build-mismatch";
101
+ return { code: EXIT.BUILD_MISMATCH, report: report };
102
+ }
103
+ report.outcome = "restarted";
104
+ return { code: EXIT.OK, report: report };
105
+ }
106
+
107
+ function humanLines(result) {
108
+ var r = result.report;
109
+ var lines = [];
110
+ var n = r.sessions ? r.sessions.length : 0;
111
+ if (r.outcome === "restarted") {
112
+ if (n) lines.push("Sessions in flight before the restart: " + n);
113
+ lines.push("Server restarted (pid " + r.oldPid + " -> " + r.newPid + ", build " + r.loadedBuildSha + ").");
114
+ } else if (r.outcome === "timeout") {
115
+ lines.push("Restart requested, but no new process answered in time. Last seen: " + JSON.stringify(r.lastSeen));
116
+ } else if (r.outcome === "build-mismatch") {
117
+ lines.push("Server restarted (pid " + r.oldPid + " -> " + r.newPid + ") but did not load the installed build: loaded "
118
+ + r.loadedBuildSha + ", installed " + r.installedBuildSha + ", state " + r.state + ".");
119
+ } else if (r.outcome === "old-pid-unknown") {
120
+ lines.push("Restart not attempted: the running daemon's pid is unknown, so the new process could not be told from the old one.");
121
+ } else {
122
+ lines.push("Restart failed: daemon did not acknowledge the command.");
123
+ }
124
+ return lines;
125
+ }
126
+
127
+ module.exports = {
128
+ runRestart: runRestart,
129
+ humanLines: humanLines,
130
+ EXIT: EXIT,
131
+ DEFAULT_TIMEOUT_MS: DEFAULT_TIMEOUT_MS,
132
+ };
@@ -29,6 +29,8 @@ var senderRef = require("../sender-ref");
29
29
  var { LIMITS, isCount } = require("../scheduled-input/records");
30
30
  var { requestDaemon, withSenderRef, EXIT } = require("./session-subcommands");
31
31
  var { parseDuration } = require("./duration");
32
+ var agentUsage = require("./agent-usage");
33
+ var compact = require("./compact-output");
32
34
 
33
35
  // --- The time inputs: a duration ("10m", "1h30m"), a local clock time ("20:01")
34
36
  // and a local date-time ("2026-03-01T20:01"). Pure: each takes the current time
@@ -113,17 +115,21 @@ var FLAGS = {
113
115
  "--state": "state",
114
116
  };
115
117
 
118
+ // Flags that take no value, kept apart from FLAGS as in session-subcommands.js.
119
+ var SWITCHES = {
120
+ "--verbose": "verbose",
121
+ };
122
+
116
123
  var ALLOWED = {
117
124
  create: ["sessionId", "projectSlug", "in", "at", "every", "until", "count", "prompt", "promptFile"],
118
- list: ["sessionId", "projectSlug", "state"],
125
+ list: ["sessionId", "projectSlug", "state", "verbose"],
119
126
  delete: ["id", "projectSlug"],
120
127
  };
121
128
 
122
- var USAGE = {
123
- create: "Usage: clagentic-console schedule-input create --session <id> [--project <slug>] (--in <dur> | --at <time> | --every <dur> (--until <time> | --count <n>)) (--prompt <text|-> | --prompt-file <path>)",
124
- list: "Usage: clagentic-console schedule-input list [--session <id>] [--project <slug>] [--state armed|done|ended|any]",
125
- delete: "Usage: clagentic-console schedule-input delete --id <id> [--project <slug>]",
126
- };
129
+ var USAGE = {};
130
+ SUBCOMMANDS.forEach(function (sub) {
131
+ USAGE[sub] = agentUsage.usageLine("schedule-input " + sub);
132
+ });
127
133
 
128
134
  var IPC_COMMAND = {
129
135
  create: "schedule_input_create",
@@ -197,6 +203,13 @@ function parseScheduleArgs(sub, args, now, env) {
197
203
  var allowed = ALLOWED[sub];
198
204
  var parsed = {};
199
205
  for (var i = 0; i < args.length; i++) {
206
+ if (has(SWITCHES, args[i])) {
207
+ var switchKey = SWITCHES[args[i]];
208
+ if (allowed.indexOf(switchKey) === -1) return { error: "Unknown option for schedule-input " + sub + ": " + args[i] };
209
+ if (given(parsed, switchKey)) return { error: "Option given twice: " + args[i] };
210
+ parsed[switchKey] = true;
211
+ continue;
212
+ }
200
213
  var key = has(FLAGS, args[i]) ? FLAGS[args[i]] : null;
201
214
  if (!key || allowed.indexOf(key) === -1) return { error: "Unknown option for schedule-input " + sub + ": " + args[i] };
202
215
  if (i + 1 >= args.length) return { error: "Missing value for " + args[i] };
@@ -216,7 +229,7 @@ function parseScheduleArgs(sub, args, now, env) {
216
229
  if (sub === "list") {
217
230
  if (given(parsed, "sessionId")) request.sessionId = parsed.sessionId;
218
231
  if (given(parsed, "state")) request.state = parsed.state;
219
- return { request: request };
232
+ return { request: request, verbose: !!parsed.verbose };
220
233
  }
221
234
 
222
235
  if (!given(parsed, "sessionId")) return { error: "Missing required option --session" };
@@ -267,7 +280,29 @@ function fail(message) {
267
280
  process.exit(1);
268
281
  }
269
282
 
283
+ // What `schedule-input list` prints: compact rows, or the whole answer with --verbose.
284
+ function presentResult(sub, res, verbose) {
285
+ return sub === "list" && !verbose ? compact.compactScheduled(res) : res;
286
+ }
287
+
288
+ // Help is answered before anything is parsed: `schedule-input --help` for the
289
+ // three call shapes, `schedule-input <sub> --help` for one. Returns the text, or
290
+ // null when help was not asked for.
291
+ function helpFor(args) {
292
+ if (args.length === 0) return null;
293
+ var sub = args[0];
294
+ if (sub === "-h" || sub === "--help") return agentUsage.scheduleHelpText();
295
+ if (SUBCOMMANDS.indexOf(sub) === -1) return null;
296
+ return agentUsage.wantsHelp(args.slice(1), Object.keys(FLAGS)) ? agentUsage.helpText("schedule-input " + sub) : null;
297
+ }
298
+
270
299
  function runScheduleInput(args) {
300
+ var help = helpFor(args);
301
+ if (help !== null) {
302
+ console.log(help);
303
+ process.exitCode = EXIT.OK;
304
+ return;
305
+ }
271
306
  var sub = args[0];
272
307
  if (SUBCOMMANDS.indexOf(sub) === -1) {
273
308
  console.error("Unknown schedule-input command: " + String(sub));
@@ -287,7 +322,7 @@ function runScheduleInput(args) {
287
322
  withSenderRef(request, process.env);
288
323
  }
289
324
  requestDaemon(request).then(function (res) {
290
- console.log(JSON.stringify(withResolved(res, parsed.resolved), null, 2));
325
+ console.log(JSON.stringify(presentResult(sub, withResolved(res, parsed.resolved), parsed.verbose), null, 2));
291
326
  // Not process.exit: on a pipe it can cut the JSON off before stdout drains.
292
327
  process.exitCode = exitCodeFor(res);
293
328
  });
@@ -302,5 +337,7 @@ module.exports = {
302
337
  withResolved: withResolved,
303
338
  exitCodeFor: exitCodeFor,
304
339
  runScheduleInput: runScheduleInput,
340
+ presentResult: presentResult,
341
+ helpFor: helpFor,
305
342
  USAGE: USAGE,
306
343
  };