@clagentic/console 1.11.0 → 1.12.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 (41) hide show
  1. package/bin/cli.js +12 -1
  2. package/lib/build-sha.json +2 -2
  3. package/lib/cli/arg-validation.js +1 -1
  4. package/lib/cli/ipc-subcommands.js +26 -0
  5. package/lib/daemon.js +20 -0
  6. package/lib/notification-prefs.js +255 -0
  7. package/lib/project-loop.js +3 -6
  8. package/lib/project-notifications.js +176 -34
  9. package/lib/project-sessions.js +28 -0
  10. package/lib/prompt-registry.js +18 -0
  11. package/lib/prompt-reminders.js +277 -0
  12. package/lib/public/css/input.css +93 -0
  13. package/lib/public/css/menus.css +22 -0
  14. package/lib/public/css/server-settings.css +24 -0
  15. package/lib/public/css/sidebar.css +17 -0
  16. package/lib/public/index.html +3 -0
  17. package/lib/public/modules/app-header.js +2 -0
  18. package/lib/public/modules/app-messages.js +6 -2
  19. package/lib/public/modules/app-notifications.js +29 -3
  20. package/lib/public/modules/app-rate-limit.js +12 -6
  21. package/lib/public/modules/app-rendering.js +16 -3
  22. package/lib/public/modules/collapsible-text.js +77 -0
  23. package/lib/public/modules/keep-alive.js +66 -0
  24. package/lib/public/modules/notification-prefs.js +151 -0
  25. package/lib/public/modules/prompt-reminders-setting.js +13 -0
  26. package/lib/public/modules/sidebar-mobile.js +8 -0
  27. package/lib/public/modules/sidebar-sessions.js +27 -0
  28. package/lib/public/sw.js +7 -1
  29. package/lib/push-audience.js +84 -0
  30. package/lib/push.js +24 -1
  31. package/lib/sdk-bridge.js +27 -12
  32. package/lib/sdk-message-processor.js +72 -14
  33. package/lib/sender-ref.js +3 -0
  34. package/lib/server.js +46 -2
  35. package/lib/session-input.js +7 -1
  36. package/lib/sessions.js +27 -0
  37. package/lib/usage-store.js +381 -0
  38. package/lib/ws-schema.js +6 -0
  39. package/lib/yoke/adapters/claude.js +10 -0
  40. package/lib/yoke/adapters/codex.js +5 -1
  41. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -33,7 +33,7 @@ var { forkDaemon, devMode, setDaemonWatcherOpts } = require("../lib/cli/daemon-l
33
33
  var { setup, promptRestoreProjects, showMainMenu } = require("../lib/cli/menus");
34
34
  var { getLocalIP } = require("../lib/cli/net-detect");
35
35
  var { log, a, sym } = require("../lib/cli/tui");
36
- var { handleShutdown, handleRestart, handleAdd, handleRemove, handleList, handleActivityDiagnostics, handleProcessBuildStatus } = require("../lib/cli/ipc-subcommands");
36
+ var { handleShutdown, handleRestart, handleAdd, handleRemove, handleList, handleActivityDiagnostics, handleUsage, handleProcessBuildStatus } = require("../lib/cli/ipc-subcommands");
37
37
 
38
38
  var args = process.argv.slice(2);
39
39
 
@@ -116,6 +116,7 @@ var addPath = null;
116
116
  var removePath = null;
117
117
  var listMode = false;
118
118
  var activityDiagnosticsMode = false;
119
+ var usageMode = false;
119
120
  var processBuildStatusMode = false;
120
121
  var headlessMode = false;
121
122
  var watchMode = false;
@@ -175,6 +176,8 @@ for (var i = 0; i < args.length; i++) {
175
176
  listMode = true;
176
177
  } else if (args[i] === "--activity-diagnostics") {
177
178
  activityDiagnosticsMode = true;
179
+ } else if (args[i] === "--usage") {
180
+ usageMode = true;
178
181
  } else if (args[i] === "--process-build-status") {
179
182
  processBuildStatusMode = true;
180
183
  } else if (args[i] === "--headless") {
@@ -193,6 +196,7 @@ for (var i = 0; i < args.length; i++) {
193
196
  console.log(" clagentic-console --remove <path> Remove a project from the running daemon");
194
197
  console.log(" clagentic-console --list List registered projects");
195
198
  console.log(" clagentic-console --activity-diagnostics Print activity-divergence probe totals as JSON (agent-readable)");
199
+ console.log(" clagentic-console --usage Print account usage per vendor and rate-limit bucket as JSON, with how fresh each reading is and why (agent-readable)");
196
200
  console.log(" clagentic-console --process-build-status Print the running process's loaded build SHA as JSON (agent-readable)");
197
201
  console.log(" 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>] Open a session and run a first prompt (prints JSON)");
198
202
  console.log(" clagentic-console send-input (--project <slug> --session <id> | --to <address> | --reply) --prompt <text|-> [--initiator <kind>] [--context-note <text>] [--from <name>] [--from-session <id>] Send input to a session, resuming it if needed (prints JSON; exit 3 ambiguous, 4 not found by address)");
@@ -222,6 +226,7 @@ for (var i = 0; i < args.length; i++) {
222
226
  console.log(" --remove <path> Remove a project directory");
223
227
  console.log(" --list List all registered projects");
224
228
  console.log(" --activity-diagnostics Print activity-divergence probe totals as JSON");
229
+ console.log(" --usage Print account usage per vendor and rate-limit bucket as JSON, with freshness and why a reading is old");
225
230
  console.log(" --process-build-status Print the running process's loaded build SHA as JSON");
226
231
  console.log(" --headless Start daemon and exit immediately (implies --yes)");
227
232
  console.log(" --multi-user Start in multi-user mode (use with --yes for headless)");
@@ -272,6 +277,12 @@ if (activityDiagnosticsMode) {
272
277
  return;
273
278
  }
274
279
 
280
+ // --- Handle --usage before anything else ---
281
+ if (usageMode) {
282
+ handleUsage();
283
+ return;
284
+ }
285
+
275
286
  // --- Handle --process-build-status before anything else ---
276
287
  if (processBuildStatusMode) {
277
288
  handleProcessBuildStatus();
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "64781e933f0b75244454f5effdb42544cae89712",
3
- "writtenAt": "2026-10-23T20:59:57.884Z"
2
+ "sha": "5f4c7d6096bab03fe3f9cedac6ea45d9f59c872e",
3
+ "writtenAt": "2026-11-04T21:44:36.944Z"
4
4
  }
@@ -9,7 +9,7 @@
9
9
  var BOOLEAN_FLAGS = [
10
10
  "--no-https", "--local-cert", "--no-update", "--skip-update", "--dev",
11
11
  "--watch", "-w", "--debug", "-y", "--yes", "--shutdown", "--restart",
12
- "--no-restart", "--list", "--activity-diagnostics", "--process-build-status",
12
+ "--no-restart", "--list", "--activity-diagnostics", "--usage", "--process-build-status",
13
13
  "--headless", "--multi-user", "--os-users",
14
14
  // Removed flag: the flag loop prints its own dedicated message and exits 1.
15
15
  "--dangerously-skip-permissions",
@@ -261,7 +261,33 @@ function handleActivityDiagnostics() {
261
261
  });
262
262
  }
263
263
 
264
+ // Prints per-vendor, per-bucket account usage (see lib/usage-store.js) as raw
265
+ // JSON, the same agent-readable shape as --activity-diagnostics.
266
+ function handleUsage() {
267
+ var usageConfig = loadConfig();
268
+ isDaemonAliveAsync(usageConfig).then(function (alive) {
269
+ if (!alive) {
270
+ console.error("No running daemon. Start with: npx @clagentic/console");
271
+ process.exit(1);
272
+ }
273
+ sendIPCCommand(socketPath(), { cmd: "get_usage" }).then(function (res) {
274
+ if (!res.ok) {
275
+ console.error("Failed: " + (res.error || "unknown error"));
276
+ process.exit(1);
277
+ return;
278
+ }
279
+ console.log(JSON.stringify({
280
+ generatedAt: res.generatedAt,
281
+ staleAfterSeconds: res.staleAfterSeconds,
282
+ vendors: res.vendors,
283
+ }, null, 2));
284
+ process.exit(0);
285
+ });
286
+ });
287
+ }
288
+
264
289
  module.exports = {
290
+ handleUsage: handleUsage,
265
291
  handleShutdown: handleShutdown,
266
292
  handleRestart: handleRestart,
267
293
  handleAdd: handleAdd,
package/lib/daemon.js CHANGED
@@ -1564,6 +1564,15 @@ if (existingConfig && existingConfig.pid && existingConfig.pid !== process.pid)
1564
1564
  clearStaleConfig();
1565
1565
  }
1566
1566
  }
1567
+ // Load persisted account usage before IPC can serve get_usage. A bad file
1568
+ // starts empty (see lib/usage-store.js) and must never block daemon start.
1569
+ try {
1570
+ var _usageStoreMod = require("./usage-store");
1571
+ _usageStoreMod.enablePersistence(path.join(CONFIG_DIR, _usageStoreMod.STORE_FILE_NAME));
1572
+ } catch (e) {
1573
+ console.error("[daemon] Clagentic: Console usage persistence disabled:", e && e.message ? e.message : e);
1574
+ }
1575
+
1567
1576
  var ipc = createIPCServer(socketPath(), function (msg) {
1568
1577
  console.log("[daemon] IPC:", msg.cmd);
1569
1578
  switch (msg.cmd) {
@@ -1655,6 +1664,11 @@ var ipc = createIPCServer(socketPath(), function (msg) {
1655
1664
  case "get_activity_diagnostics":
1656
1665
  return buildActivityDiagnosticsResponse();
1657
1666
 
1667
+ case "get_usage":
1668
+ return Object.assign({ ok: true }, require("./usage-store").snapshot({
1669
+ vendorIds: require("./yoke").registry.ids(),
1670
+ }));
1671
+
1658
1672
  // lr-dc9a3b: makes the running-vs-installed mismatch a first-class,
1659
1673
  // queryable signal instead of a journalctl-only warning nothing
1660
1674
  // consumes. verify-installed-build.js (the post-merge gate) already
@@ -2236,6 +2250,12 @@ function gracefulShutdown() {
2236
2250
 
2237
2251
  ipc.close();
2238
2252
 
2253
+ try {
2254
+ require("./usage-store").flush();
2255
+ } catch (e) {
2256
+ console.error("[daemon] Clagentic: Console usage flush at shutdown failed:", e && e.message ? e.message : e);
2257
+ }
2258
+
2239
2259
  // Remove PID from config (skip when a self-spawned replacement's PID is already saved)
2240
2260
  if (!successorSpawned) {
2241
2261
  try {
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+
3
+ // Per-user notification preferences, kept on the server so the phone and the
4
+ // desktop of one user agree and so push can be filtered where it is sent.
5
+ //
6
+ // A preference is a boolean for each (surface, category): the surfaces are the
7
+ // in-app banner, the sound and push; the categories group the notification
8
+ // types that exist. Muting a category never hides the item: the notifications
9
+ // panel and the session's prompt card still show it. Only the alert, the sound
10
+ // and the push are suppressed (the client reads this for the first two, the
11
+ // push module for the third).
12
+ //
13
+ // Store: <CONFIG_DIR>/notification-prefs.json, i.e. ~/.clagentic/console/
14
+ // notification-prefs.json, written atomically with mode 0600:
15
+ // { "version": 1, "users": { "<userId or _default>": { "banner": {...}, "sound": {...}, "push": {...} } } }
16
+ // The key "_default" is the one user of a daemon that has no accounts.
17
+
18
+ var fs = require("fs");
19
+ var path = require("path");
20
+ var config = require("./config");
21
+ var store = require("./store");
22
+
23
+ var FILE_NAME = "notification-prefs.json";
24
+ var DEFAULT_USER = "_default";
25
+
26
+ var SURFACES = ["banner", "sound", "push"];
27
+ var CATEGORIES = ["turn_done", "approval", "approval_reminder", "loop", "messages", "system"];
28
+
29
+ // Display names for the settings panel; the client renders these.
30
+ var CATEGORY_LABELS = {
31
+ turn_done: "Turn finished",
32
+ approval: "Approval prompts and questions",
33
+ approval_reminder: "Approval reminders",
34
+ loop: "Loop and schedule results",
35
+ messages: "Messages and mentions",
36
+ system: "Account and system notices",
37
+ };
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",
46
+ mate_dm: "messages",
47
+ mention_response: "messages",
48
+ user_mention: "messages",
49
+ auth_required: "system",
50
+ };
51
+
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
+ };
62
+
63
+ // Today's behaviour: every banner and push is on; the sound plays for a
64
+ // finished turn only.
65
+ function defaultPrefs() {
66
+ var out = {};
67
+ SURFACES.forEach(function (surface) {
68
+ out[surface] = {};
69
+ CATEGORIES.forEach(function (category) {
70
+ out[surface][category] = surface === "sound" ? category === "turn_done" : true;
71
+ });
72
+ });
73
+ return out;
74
+ }
75
+
76
+ // The categories each preset switches on, on every surface. "system" is left
77
+ // as the user has it: an expired login or a failed update needs the operator
78
+ // whatever else is muted.
79
+ var PRESETS = {
80
+ all: { label: "Everything (default)", enabled: null },
81
+ approval_prompts: { label: "Approval prompts only", enabled: ["approval", "approval_reminder"] },
82
+ approval_reminders: { label: "Approval reminders only", enabled: ["approval_reminder"] },
83
+ };
84
+
85
+ function applyPreset(prefs, presetName) {
86
+ // presetName comes from a client: only a preset this module defines counts.
87
+ if (!Object.prototype.hasOwnProperty.call(PRESETS, presetName)) return null;
88
+ var preset = PRESETS[presetName];
89
+ var base = defaultPrefs();
90
+ var next = {};
91
+ SURFACES.forEach(function (surface) {
92
+ next[surface] = {};
93
+ CATEGORIES.forEach(function (category) {
94
+ if (category === "system") next[surface][category] = prefs[surface][category];
95
+ else if (preset.enabled === null) next[surface][category] = base[surface][category];
96
+ else next[surface][category] = preset.enabled.indexOf(category) !== -1;
97
+ });
98
+ });
99
+ return next;
100
+ }
101
+
102
+ // Which preset the preferences equal, or null for a custom mix.
103
+ function presetOf(prefs) {
104
+ var names = Object.keys(PRESETS);
105
+ for (var i = 0; i < names.length; i++) {
106
+ var applied = applyPreset(prefs, names[i]);
107
+ if (JSON.stringify(applied) === JSON.stringify(prefs)) return names[i];
108
+ }
109
+ return null;
110
+ }
111
+
112
+ // Stored data is whatever a file or a client held; only known booleans count.
113
+ function normalize(raw) {
114
+ var out = defaultPrefs();
115
+ if (!raw || typeof raw !== "object") return out;
116
+ SURFACES.forEach(function (surface) {
117
+ var row = raw[surface];
118
+ if (!row || typeof row !== "object") return;
119
+ CATEGORIES.forEach(function (category) {
120
+ if (typeof row[category] === "boolean") out[surface][category] = row[category];
121
+ });
122
+ });
123
+ return out;
124
+ }
125
+
126
+ function categoryOfNotification(type) {
127
+ return Object.prototype.hasOwnProperty.call(NOTIFICATION_CATEGORY, type) ? NOTIFICATION_CATEGORY[type] : null;
128
+ }
129
+
130
+ function categoryOfPush(payload) {
131
+ if (!payload || typeof payload.type !== "string") return null;
132
+ if (payload.type === "done") return payload.tag === "ralph-loop-done" ? "loop" : "turn_done";
133
+ return Object.prototype.hasOwnProperty.call(PUSH_CATEGORY, payload.type) ? PUSH_CATEGORY[payload.type] : null;
134
+ }
135
+
136
+ function userKey(userId) {
137
+ return typeof userId === "string" && userId ? userId : DEFAULT_USER;
138
+ }
139
+
140
+ /**
141
+ * @param {object} [o]
142
+ * @param {string} [o.file] absolute path of the store file (tests); default is
143
+ * the console config directory's notification-prefs.json.
144
+ * @param {function(object)} [o.persist] writes the whole document; default is
145
+ * store.js, which queues and writes atomically.
146
+ */
147
+ function createPrefsStore(o) {
148
+ o = o || {};
149
+ var file = o.file || path.join(config.CONFIG_DIR, FILE_NAME);
150
+ var persist = o.persist || function (doc) {
151
+ return store.writeJsonAt(file, doc).catch(function (err) {
152
+ process.stderr.write("[notification-prefs] save failed: " + (err && err.message ? err.message : err) + "\n");
153
+ });
154
+ };
155
+ var users = Object.create(null);
156
+
157
+ try {
158
+ var saved = JSON.parse(fs.readFileSync(file, "utf8"));
159
+ if (saved && saved.users && typeof saved.users === "object") {
160
+ Object.keys(saved.users).forEach(function (id) { users[id] = normalize(saved.users[id]); });
161
+ }
162
+ } catch (e) {
163
+ if (e.code !== "ENOENT") process.stderr.write("[notification-prefs] ignoring unreadable " + file + ": " + e.message + "\n");
164
+ }
165
+
166
+ function save() {
167
+ return persist({ version: 1, users: users });
168
+ }
169
+
170
+ function get(userId) {
171
+ var key = userKey(userId);
172
+ return users[key] ? normalize(users[key]) : defaultPrefs();
173
+ }
174
+
175
+ function view(userId) {
176
+ var prefs = get(userId);
177
+ return {
178
+ prefs: prefs,
179
+ preset: presetOf(prefs),
180
+ known: Object.prototype.hasOwnProperty.call(users, userKey(userId)),
181
+ };
182
+ }
183
+
184
+ /**
185
+ * Change a user's preferences by preset name or by per-cell patch
186
+ * ({surface: {category: boolean}}). Unknown names and non-booleans are
187
+ * ignored. Returns the user's resulting view.
188
+ */
189
+ function set(userId, change) {
190
+ var key = userKey(userId);
191
+ var prefs = get(userId);
192
+ if (change && typeof change.preset === "string") {
193
+ var applied = applyPreset(prefs, change.preset);
194
+ if (applied) prefs = applied;
195
+ }
196
+ if (change && change.surfaces && typeof change.surfaces === "object") {
197
+ prefs = normalize(Object.assign({}, prefs, mergeSurfaces(prefs, change.surfaces)));
198
+ }
199
+ users[key] = prefs;
200
+ save();
201
+ return view(userId);
202
+ }
203
+
204
+ function mergeSurfaces(prefs, patch) {
205
+ var out = {};
206
+ SURFACES.forEach(function (surface) {
207
+ out[surface] = Object.assign({}, prefs[surface], patch[surface] && typeof patch[surface] === "object" ? patch[surface] : {});
208
+ });
209
+ return out;
210
+ }
211
+
212
+ /**
213
+ * Seed a user's preferences from what the browser held before they lived on
214
+ * the server, once: only when the user has none stored. Today's globals map
215
+ * as far as they mean anything per user: the sound switch is the turn-done
216
+ * sound. The browser-alert and push switches describe this browser's
217
+ * permission and subscription, not a choice about types, and stay with it.
218
+ */
219
+ function migrateLegacy(userId, legacy) {
220
+ if (Object.prototype.hasOwnProperty.call(users, userKey(userId))) return view(userId);
221
+ var prefs = defaultPrefs();
222
+ if (legacy && legacy.sound === false) prefs.sound.turn_done = false;
223
+ users[userKey(userId)] = prefs;
224
+ save();
225
+ return view(userId);
226
+ }
227
+
228
+ function allows(userId, surface, category) {
229
+ if (!category) return true;
230
+ var row = get(userId)[surface];
231
+ return !row || row[category] !== false;
232
+ }
233
+
234
+ return {
235
+ get: get,
236
+ view: view,
237
+ set: set,
238
+ migrateLegacy: migrateLegacy,
239
+ allows: allows,
240
+ };
241
+ }
242
+
243
+ module.exports = {
244
+ createPrefsStore: createPrefsStore,
245
+ categoryOfNotification: categoryOfNotification,
246
+ categoryOfPush: categoryOfPush,
247
+ defaultPrefs: defaultPrefs,
248
+ userKey: userKey,
249
+ SURFACES: SURFACES,
250
+ CATEGORIES: CATEGORIES,
251
+ CATEGORY_LABELS: CATEGORY_LABELS,
252
+ PRESETS: PRESETS,
253
+ DEFAULT_USER: DEFAULT_USER,
254
+ FILE_NAME: FILE_NAME,
255
+ };
@@ -5,6 +5,7 @@ var { execFileSync } = require("child_process");
5
5
  var { createLoopRegistry } = require("./scheduler");
6
6
  var store = require("./store");
7
7
  var usersModule = require("./users");
8
+ var { pushForSession } = require("./push-audience");
8
9
  var { writeHandoff, buildHandoffPreamble } = require("./loop-handoff");
9
10
  var { authOf } = require("./project-access");
10
11
  var { INITIATORS } = require("./turn-initiator");
@@ -860,12 +861,8 @@ function attachLoop(ctx) {
860
861
  var _loopDonePayload = {
861
862
  type: "done", slug: slug, title: "Loop Complete", body: _finishBody, tag: "ralph-loop-done",
862
863
  };
863
- // Route to loop session owner only — body carries iteration status.
864
- if (_loopOwnerUserId && pushModule.sendPushToUser) {
865
- pushModule.sendPushToUser(_loopOwnerUserId, _loopDonePayload);
866
- } else {
867
- pushModule.sendPush(_loopDonePayload);
868
- }
864
+ // Body carries iteration status: loop owner only, never a blind broadcast.
865
+ pushForSession(pushModule, _loopOwnerUserId, _loopDonePayload);
869
866
  }
870
867
 
871
868
  if (notificationsModule) {