@clagentic/console 1.11.0 → 1.12.0-beta.2

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 (99) hide show
  1. package/README.md +1 -0
  2. package/bin/cli.js +14 -2
  3. package/lib/build-changes.js +8 -2
  4. package/lib/build-sha.json +2 -2
  5. package/lib/build-update-offer.js +31 -7
  6. package/lib/claude-settings-env.js +142 -0
  7. package/lib/cli/arg-validation.js +1 -1
  8. package/lib/cli/duration.js +27 -0
  9. package/lib/cli/ipc-subcommands.js +26 -0
  10. package/lib/cli/schedule-input-subcommands.js +1 -22
  11. package/lib/cli/session-subcommands.js +38 -7
  12. package/lib/daemon.js +26 -0
  13. package/lib/notification-prefs.js +257 -0
  14. package/lib/notify/core.js +175 -0
  15. package/lib/notify/index.js +31 -0
  16. package/lib/notify/live-prompts.js +36 -0
  17. package/lib/notify/payload.js +63 -0
  18. package/lib/notify/target.js +5 -0
  19. package/lib/notify/type-registry.js +64 -0
  20. package/lib/notify/types.js +20 -0
  21. package/lib/open-sockets.js +27 -0
  22. package/lib/outbound-access.js +74 -0
  23. package/lib/outbound-entry.js +109 -0
  24. package/lib/outbound-ledger.js +306 -0
  25. package/lib/outbound-query.js +153 -0
  26. package/lib/pending-prompts.js +31 -16
  27. package/lib/project-connection.js +40 -1
  28. package/lib/project-filesystem.js +20 -5
  29. package/lib/project-http.js +9 -1
  30. package/lib/project-loop.js +25 -13
  31. package/lib/project-notifications.js +206 -42
  32. package/lib/project-prompt-responses.js +1 -1
  33. package/lib/project-sessions.js +30 -1
  34. package/lib/project.js +15 -1
  35. package/lib/prompt-registry.js +92 -24
  36. package/lib/prompt-reminders.js +282 -0
  37. package/lib/prompt-source.js +43 -8
  38. package/lib/public/app.js +1 -0
  39. package/lib/public/css/diagnostics.css +28 -0
  40. package/lib/public/css/home-hub.css +12 -0
  41. package/lib/public/css/icon-strip.css +9 -0
  42. package/lib/public/css/input.css +93 -0
  43. package/lib/public/css/menus.css +22 -0
  44. package/lib/public/css/mobile-nav.css +11 -0
  45. package/lib/public/css/server-settings.css +24 -0
  46. package/lib/public/css/sidebar.css +24 -0
  47. package/lib/public/index.html +6 -0
  48. package/lib/public/modules/activity-state.js +20 -4
  49. package/lib/public/modules/app-connection.js +22 -5
  50. package/lib/public/modules/app-header.js +2 -0
  51. package/lib/public/modules/app-messages.js +6 -2
  52. package/lib/public/modules/app-notifications.js +65 -40
  53. package/lib/public/modules/app-projects.js +3 -1
  54. package/lib/public/modules/app-rate-limit.js +12 -6
  55. package/lib/public/modules/app-rendering.js +26 -3
  56. package/lib/public/modules/build-update-sessions.js +81 -0
  57. package/lib/public/modules/collapsible-text.js +77 -0
  58. package/lib/public/modules/diagnostics.js +9 -2
  59. package/lib/public/modules/env-shadow-notice.js +34 -0
  60. package/lib/public/modules/keep-alive.js +66 -0
  61. package/lib/public/modules/notification-prefs.js +151 -0
  62. package/lib/public/modules/notify-client.js +153 -0
  63. package/lib/public/modules/project-settings.js +5 -0
  64. package/lib/public/modules/prompt-reminders-setting.js +13 -0
  65. package/lib/public/modules/prompt-state.js +3 -3
  66. package/lib/public/modules/prompts.js +1 -1
  67. package/lib/public/modules/server-settings.js +3 -0
  68. package/lib/public/modules/sidebar-mobile.js +8 -0
  69. package/lib/public/modules/sidebar-sessions.js +27 -0
  70. package/lib/public/modules/terminal-links.js +175 -0
  71. package/lib/public/modules/terminal.js +19 -103
  72. package/lib/public/notify-sw-logic.js +300 -0
  73. package/lib/public/notify-target.js +97 -0
  74. package/lib/public/sw.js +15 -62
  75. package/lib/push-audience.js +84 -0
  76. package/lib/push.js +87 -20
  77. package/lib/runtime-env.js +1 -0
  78. package/lib/sdk-bridge.js +83 -36
  79. package/lib/sdk-message-processor.js +148 -49
  80. package/lib/sender-ref.js +3 -0
  81. package/lib/server.js +80 -4
  82. package/lib/session-directory.js +6 -4
  83. package/lib/session-input-ipc.js +11 -1
  84. package/lib/session-input.js +95 -14
  85. package/lib/session-liveness.js +53 -0
  86. package/lib/session-reclaim.js +37 -2
  87. package/lib/sessions.js +58 -4
  88. package/lib/usage-store.js +403 -0
  89. package/lib/vendor-auth.js +33 -2
  90. package/lib/ws-schema.js +13 -2
  91. package/lib/yoke/adapters/claude-vendor.js +11 -1
  92. package/lib/yoke/adapters/claude.js +17 -0
  93. package/lib/yoke/adapters/codex.js +5 -1
  94. package/lib/yoke/auth-checks.js +17 -2
  95. package/lib/yoke/index.js +21 -3
  96. package/lib/yoke/provider-credentials.js +24 -0
  97. package/lib/yoke/registry.js +8 -1
  98. package/package.json +2 -2
  99. package/scripts/check-test-count.js +14 -0
@@ -6,9 +6,10 @@ var fs = require("fs");
6
6
  var path = require("path");
7
7
  var config = require("./config");
8
8
  var yokeRegistry = require("./yoke").registry;
9
+ var notificationPrefs = require("./notification-prefs");
10
+ var audienceFor = require("./push-audience").audienceFor;
9
11
 
10
12
  var NOTIF_FILE = path.join(config.CONFIG_DIR, "notifications.json");
11
- var REMINDER_INTERVAL = 60 * 60 * 1000; // 1 hour
12
13
 
13
14
  function generateId() {
14
15
  var rand = Math.random().toString(36).substring(2, 8);
@@ -33,6 +34,8 @@ var formatters = {
33
34
  loginCommand: data.loginCommand || "",
34
35
  linuxUser: data.linuxUser || null,
35
36
  canAutoLogin: !!data.canAutoLogin,
37
+ // Stays until acted on; the banner reads this flag, not a type list.
38
+ persistent: true,
36
39
  },
37
40
  };
38
41
  },
@@ -82,6 +85,24 @@ var formatters = {
82
85
  };
83
86
  },
84
87
 
88
+ // The one live reminder of a session's unanswered prompts (see
89
+ // lib/prompt-reminders.js). Not actionable: it names what waits, and a click
90
+ // goes to the session, where the prompt card answers.
91
+ permission_reminder: function (data) {
92
+ return {
93
+ type: "permission_reminder",
94
+ title: data.title || "Prompts waiting",
95
+ body: data.body || "",
96
+ meta: {
97
+ requestIds: data.requestIds || [],
98
+ count: data.count || 0,
99
+ ageMs: data.ageMs || 0,
100
+ agents: data.agents || [],
101
+ tools: data.tools || [],
102
+ },
103
+ };
104
+ },
105
+
85
106
  mate_dm: function (data) {
86
107
  return {
87
108
  type: "mate_dm",
@@ -124,19 +145,27 @@ var formatters = {
124
145
  function attachNotifications(ctx) {
125
146
  var broadcastAll = ctx.broadcastAll;
126
147
  var sendToUser = ctx.sendToUser || null; // (userId, msg) -> void; iterates all project clients
148
+ // (buildMsg(viewerId) -> msg) -> void; one message per live connection, so a
149
+ // count can differ by viewer. Absent: the global count goes to everyone.
150
+ var broadcastPerViewer = ctx.broadcastPerViewer || null;
127
151
  var pushModule = ctx.pushModule;
128
152
  var notifications = loadNotifications();
129
- var reminderTimer = null;
130
-
131
- // A prompt notification is actionable only while its prompt's resolver
132
- // lives in this process; none survives a restart, so a persisted one would
133
- // offer buttons for a prompt nothing can answer.
153
+ var prefsStore = ctx.prefsStore || null;
154
+ var reconcileReminders = null;
155
+ var isMultiUser = ctx.isMultiUser || null;
156
+ var listAdmins = ctx.listAdmins || null;
157
+
158
+ // A prompt notification (and the reminder about it) is actionable only while
159
+ // its prompt's resolver lives in this process; none survives a restart, so a
160
+ // persisted one would offer buttons for a prompt nothing can answer.
134
161
  function loadNotifications() {
135
162
  try {
136
163
  var raw = fs.readFileSync(NOTIF_FILE, "utf8");
137
164
  var parsed = JSON.parse(raw);
138
165
  if (Array.isArray(parsed)) {
139
- return parsed.filter(function (n) { return !(n && n.type === "permission_request"); });
166
+ return parsed.filter(function (n) {
167
+ return !(n && (n.type === "permission_request" || n.type === "permission_reminder"));
168
+ });
140
169
  }
141
170
  } catch (e) {}
142
171
  return [];
@@ -156,9 +185,34 @@ function attachNotifications(ctx) {
156
185
  return notifications.length;
157
186
  }
158
187
 
188
+ // The badge counts what this viewer is shown, never a banner withheld from
189
+ // them (a larger count would reveal that it exists).
190
+ function unreadCountFor(viewer) {
191
+ return notifications.filter(function (n) { return visibleTo(n, viewer); }).length;
192
+ }
193
+
194
+ // Sends buildMsg(viewer) to the given user ids, or to every connection.
195
+ function deliver(userIds, buildMsg) {
196
+ if (userIds && typeof sendToUser === "function") {
197
+ userIds.forEach(function (id) { sendToUser(id, buildMsg(id)); });
198
+ } else if (broadcastPerViewer) {
199
+ broadcastPerViewer(buildMsg);
200
+ } else {
201
+ broadcastAll(buildMsg(null));
202
+ }
203
+ }
204
+
159
205
  // --- Core API ---
160
206
 
161
- function notify(event, data) {
207
+ // meta, set by the notification core when it delivers a banner (lib/notify/):
208
+ // key the collapse identity; a banner under the same key replaces
209
+ // the earlier one, and a resolve closes the banners under it.
210
+ // collapse "request" | "session", the key's rule.
211
+ // persistent the registry says the banner is not auto-dismissed.
212
+ // liveInState the page may check the banner against the live prompts.
213
+ // They travel on the notification (key, collapse, persistent, liveInState).
214
+ function notify(event, data, meta) {
215
+ meta = meta || {};
162
216
  data = data || {};
163
217
  var formatter = formatters[event];
164
218
  if (!formatter) {
@@ -168,9 +222,21 @@ function attachNotifications(ctx) {
168
222
  var formatted = formatter(data || {});
169
223
  if (!formatted) return null;
170
224
 
225
+ // A prompt banner carries tool input, so it follows the push audience
226
+ // (lib/push-audience.js): the owner, or the admins for an ownerless session
227
+ // in multi-user mode, never every client.
228
+ if (event === "permission_request" && !data.targetUserId && !Array.isArray(data.targetUserIds)) {
229
+ var audience = audienceFor(data.ownerId, isMultiUser, listAdmins);
230
+ data = Object.assign({}, data, {
231
+ targetUserId: audience.kind === "owner" ? audience.userIds[0] : null,
232
+ targetUserIds: audience.kind === "admins" ? audience.userIds : null,
233
+ });
234
+ }
235
+
171
236
  var notif = {
172
237
  id: generateId(),
173
238
  type: formatted.type || event,
239
+ category: notificationPrefs.categoryOfNotification(formatted.type || event),
174
240
  title: formatted.title || "",
175
241
  body: formatted.body || "",
176
242
  slug: data.slug || "",
@@ -178,23 +244,28 @@ function attachNotifications(ctx) {
178
244
  mateId: data.mateId || null,
179
245
  ownerId: data.ownerId || null,
180
246
  targetUserId: data.targetUserId || null,
247
+ targetUserIds: Array.isArray(data.targetUserIds) ? data.targetUserIds : null,
181
248
  createdAt: Date.now(),
249
+ key: meta.key || null,
250
+ collapse: meta.collapse || null,
251
+ persistent: meta.persistent === true,
252
+ liveInState: meta.liveInState === true,
182
253
  meta: formatted.meta || {},
183
254
  };
184
255
  notifications.unshift(notif);
185
256
  saveNotifications();
186
- var payload = {
187
- type: "notification_created",
188
- notification: notif,
189
- unreadCount: getUnreadCount(),
190
- };
191
- // If targeted at a specific user, deliver only to that user's connections.
192
- // Otherwise broadcast to everyone (existing behavior).
193
- if (notif.targetUserId && typeof sendToUser === "function") {
194
- sendToUser(notif.targetUserId, payload);
195
- } else {
196
- broadcastAll(payload);
197
- }
257
+ // Targeted at specific users: only their connections hear it. Otherwise
258
+ // every connection does.
259
+ var recipients = null;
260
+ if (notif.targetUserIds && typeof sendToUser === "function") recipients = notif.targetUserIds;
261
+ else if (notif.targetUserId && typeof sendToUser === "function") recipients = [notif.targetUserId];
262
+ deliver(recipients, function (viewer) {
263
+ return {
264
+ type: "notification_created",
265
+ notification: notif,
266
+ unreadCount: recipients || broadcastPerViewer ? unreadCountFor(viewer) : getUnreadCount(),
267
+ };
268
+ });
198
269
  return notif;
199
270
  }
200
271
 
@@ -203,21 +274,49 @@ function attachNotifications(ctx) {
203
274
  notifications = notifications.filter(function(n) { return ids.indexOf(n.id) === -1; });
204
275
  if (notifications.length !== before) {
205
276
  saveNotifications();
206
- broadcastAll({
207
- type: "notification_dismissed",
208
- ids: ids,
209
- unreadCount: getUnreadCount(),
277
+ deliver(null, function (viewer) {
278
+ return {
279
+ type: "notification_dismissed",
280
+ ids: ids,
281
+ unreadCount: broadcastPerViewer ? unreadCountFor(viewer) : getUnreadCount(),
282
+ };
210
283
  });
211
284
  }
212
285
  }
213
286
 
287
+ // The core's banner surface (lib/notify/): a banner under a key the
288
+ // notification just collapsed to replaces the earlier one on every client,
289
+ // the dismissal and the new banner travelling together.
290
+ function show(event, data, meta) {
291
+ var key = meta && meta.key;
292
+ if (key) {
293
+ var old = idsByKey([key]);
294
+ if (old.length) dismiss(old);
295
+ }
296
+ return notify(event, data, meta);
297
+ }
298
+
299
+ function idsByKey(keys) {
300
+ return notifications.filter(function (n) {
301
+ return n.key && keys.indexOf(n.key) !== -1;
302
+ }).map(function (n) { return n.id; });
303
+ }
304
+
214
305
  // A prompt notification is only actionable while its prompt is pending; the
215
- // prompt registry calls this on every transition that ends one, so the
216
- // banner buttons never outlive it.
217
- function dismissByRequestId(requestId) {
218
- if (!requestId) return;
306
+ // core calls this when a target resolves, so the banner buttons never
307
+ // outlive the prompt.
308
+ function dismissKeys(keys) {
309
+ var ids = idsByKey(keys || []);
310
+ if (ids.length) dismiss(ids);
311
+ }
312
+
313
+ // The banners of one prompt, when only its request id is known (a stale
314
+ // answer no session claims). The slug scopes it to the prompt's project and
315
+ // is required: a request id alone names nothing, so no slug dismisses nothing.
316
+ function dismissRequest(slug, requestId) {
317
+ if (!slug || !requestId) return;
219
318
  var ids = notifications.filter(function (n) {
220
- return n.type === "permission_request" && n.meta && n.meta.requestId === requestId;
319
+ return n.collapse === "request" && n.meta && n.meta.requestId === requestId && n.slug === slug;
221
320
  }).map(function (n) { return n.id; });
222
321
  if (ids.length) dismiss(ids);
223
322
  }
@@ -230,29 +329,78 @@ function attachNotifications(ctx) {
230
329
  }
231
330
  }
232
331
 
233
- // --- Periodic reminder ---
332
+ // --- Prompt reminders (scheduling lives in lib/prompt-reminders.js) ---
234
333
 
235
- function startReminder() {
236
- // Reminder push is suppressed in multi-user mode: the unread count is
237
- // per-project state that would leak to all push subscribers regardless of
238
- // which user owns the notifications.
334
+ function setReminderReconciler(fn) {
335
+ reconcileReminders = typeof fn === "function" ? fn : null;
239
336
  }
240
337
 
241
- function stopReminder() {
242
- if (reminderTimer) { clearInterval(reminderTimer); reminderTimer = null; }
338
+ // Recounts or clears live reminders after a prompt settled or a session's
339
+ // reminders were switched. A fault here must not undo the settle that
340
+ // called it.
341
+ function reconcileRemindersNow() {
342
+ if (!reconcileReminders) return;
343
+ try {
344
+ reconcileReminders();
345
+ } catch (e) {
346
+ console.error("[notifications] reminder reconcile failed:", e && e.message ? e.message : e);
347
+ }
243
348
  }
244
349
 
245
- startReminder();
350
+ var PROMPT_TYPES = { permission_request: true, permission_reminder: true };
351
+
352
+ function visibleTo(n, viewer) {
353
+ if (Array.isArray(n.targetUserIds)) return n.targetUserIds.indexOf(viewer) !== -1;
354
+ if (PROMPT_TYPES[n.type] && n.targetUserId) return n.targetUserId === viewer;
355
+ return true;
356
+ }
246
357
 
247
358
  // --- Connection state (called per-client with sendTo) ---
248
359
 
249
- function sendConnectionState(ws, sendTo) {
360
+ // livePrompts: the prompts awaiting the operator in this project when the
361
+ // client connected (lib/notify/live-prompts.js); the page checks the
362
+ // notifications on the device against it.
363
+ function sendConnectionState(ws, sendTo, livePrompts) {
250
364
  if (!sendTo) return;
365
+ // A notification aimed at admins only, or a prompt banner aimed at its
366
+ // owner, is not handed to anyone else on connect, as it is not live.
367
+ var viewer = userIdOf(ws);
251
368
  sendTo(ws, {
252
369
  type: "notifications_state",
253
- notifications: notifications,
254
- unreadCount: getUnreadCount(),
370
+ notifications: notifications.filter(function (n) { return visibleTo(n, viewer); }),
371
+ unreadCount: unreadCountFor(viewer),
372
+ livePrompts: livePrompts || null,
255
373
  });
374
+ if (prefsStore) sendTo(ws, prefsMessage(userIdOf(ws)));
375
+ }
376
+
377
+ // --- Per-user preferences (lib/notification-prefs.js) ---
378
+
379
+ function userIdOf(ws) {
380
+ return ws && ws._clagenticUser ? ws._clagenticUser.id : null;
381
+ }
382
+
383
+ function prefsMessage(userId) {
384
+ var v = prefsStore.view(userId);
385
+ return {
386
+ type: "notification_prefs",
387
+ prefs: v.prefs,
388
+ preset: v.preset,
389
+ known: v.known,
390
+ categories: notificationPrefs.CATEGORIES.map(function (id) {
391
+ return { id: id, label: notificationPrefs.CATEGORY_LABELS[id] };
392
+ }),
393
+ presets: Object.keys(notificationPrefs.PRESETS).map(function (id) {
394
+ return { id: id, label: notificationPrefs.PRESETS[id].label };
395
+ }),
396
+ };
397
+ }
398
+
399
+ // Every connection of the user (the phone and the desktop) hears the change.
400
+ function sendPrefsToUser(userId) {
401
+ var msg = prefsMessage(userId);
402
+ if (userId && typeof sendToUser === "function") sendToUser(userId, msg);
403
+ else broadcastAll(msg);
256
404
  }
257
405
 
258
406
  // --- Message handler ---
@@ -266,16 +414,32 @@ function attachNotifications(ctx) {
266
414
  dismissAll();
267
415
  return true;
268
416
  }
417
+ if (prefsStore && msg.type === "notification_prefs_set") {
418
+ prefsStore.set(userIdOf(ws), { preset: msg.preset, surfaces: msg.surfaces });
419
+ sendPrefsToUser(userIdOf(ws));
420
+ return true;
421
+ }
422
+ if (prefsStore && msg.type === "notification_prefs_migrate") {
423
+ // First load after the preferences moved to the server: carry what this
424
+ // browser held, once.
425
+ var legacy = msg.legacy && typeof msg.legacy === "object" ? { sound: msg.legacy.sound !== false } : null;
426
+ prefsStore.migrateLegacy(userIdOf(ws), legacy);
427
+ sendPrefsToUser(userIdOf(ws));
428
+ return true;
429
+ }
269
430
  return false;
270
431
  }
271
432
 
272
433
  return {
273
434
  notify: notify,
274
- dismissByRequestId: dismissByRequestId,
435
+ show: show,
436
+ dismissKeys: dismissKeys,
437
+ dismissRequest: dismissRequest,
438
+ setReminderReconciler: setReminderReconciler,
439
+ reconcileReminders: reconcileRemindersNow,
275
440
  getUnreadCount: getUnreadCount,
276
441
  sendConnectionState: sendConnectionState,
277
442
  handleNotificationMessage: handleNotificationMessage,
278
- stopReminder: stopReminder,
279
443
  };
280
444
  }
281
445
 
@@ -104,7 +104,7 @@ function attachPromptResponses(ctx) {
104
104
  // synchronously kills the subprocess mid-write ("Operation aborted").
105
105
  session.isProcessing = false;
106
106
  onProcessingChanged();
107
- promptsFor(sm).cancelSession(session, "cleared");
107
+ promptsFor(sm).cancelSession(session, "cleared", { source: promptSource.CANCEL.USER });
108
108
  sm.broadcastSessionList();
109
109
  setImmediate(function () {
110
110
  if (session.abortController) session.abortController.abort();
@@ -10,6 +10,7 @@ var agentsModule = require("./agents");
10
10
  var agentsFavorites = require("./agents-favorites");
11
11
  var sessionActivity = require("./session-activity");
12
12
  var { promptsFor } = require("./prompt-registry");
13
+ var promptSource = require("./prompt-source");
13
14
  var { attachPromptResponses } = require("./project-prompt-responses");
14
15
  var { attachSessionGrants } = require("./project-session-grants");
15
16
  var { ownValue } = require("./prompt-kinds/codecs");
@@ -102,6 +103,7 @@ function attachSessions(ctx) {
102
103
  var projectAccess = ctx.projectAccess;
103
104
  var userPresence = ctx.userPresence;
104
105
  var pushModule = ctx.pushModule;
106
+ var getNotificationsModule = ctx.getNotificationsModule || function () { return null; };
105
107
  var getSessionForWs = ctx.getSessionForWs;
106
108
  var getLinuxUserForSession = ctx.getLinuxUserForSession;
107
109
  var ensureProjectAccessForSession = ctx.ensureProjectAccessForSession;
@@ -509,6 +511,33 @@ function attachSessions(ctx) {
509
511
  return true;
510
512
  }
511
513
 
514
+ if (msg.type === "set_session_keep_alive") {
515
+ if (typeof msg.sessionId === "number") {
516
+ var keepAliveTarget = sm.sessions.get(msg.sessionId);
517
+ if (!keepAliveTarget) return true;
518
+ if (ws._clagenticUser) {
519
+ if (!usersModule.canAccessSession(ws._clagenticUser.id, keepAliveTarget, { visibility: "public" })) return true;
520
+ }
521
+ sm.setSessionKeepAlive(msg.sessionId, msg.keepAlive === true);
522
+ }
523
+ return true;
524
+ }
525
+
526
+ if (msg.type === "set_session_prompt_reminders") {
527
+ if (typeof msg.sessionId === "number") {
528
+ var reminderTarget = sm.sessions.get(msg.sessionId);
529
+ if (!reminderTarget) return true;
530
+ if (ws._clagenticUser) {
531
+ if (!usersModule.canAccessSession(ws._clagenticUser.id, reminderTarget, { visibility: "public" })) return true;
532
+ }
533
+ sm.setSessionPromptReminders(msg.sessionId, msg.enabled !== false);
534
+ // A live reminder of a session just switched off goes now, not at the next tick.
535
+ var reminderNm = getNotificationsModule();
536
+ if (reminderNm && typeof reminderNm.reconcileReminders === "function") reminderNm.reconcileReminders();
537
+ }
538
+ return true;
539
+ }
540
+
512
541
  if (msg.type === "reorder_session_bookmarks") {
513
542
  if (typeof msg.sourceId === "number" && typeof msg.targetId === "number" && msg.sourceId !== msg.targetId) {
514
543
  var source = sm.sessions.get(msg.sourceId);
@@ -1293,7 +1322,7 @@ function attachSessions(ctx) {
1293
1322
  session.abortController = null;
1294
1323
  session.blocks = {};
1295
1324
  session.sentToolResults = {};
1296
- promptsFor(sm).cancelSession(session, "rewind");
1325
+ promptsFor(sm).cancelSession(session, "rewind", { source: promptSource.CANCEL.USER });
1297
1326
  // lr-9bcd7b: a rewind destroys the in-flight query outright (the
1298
1327
  // queryInstance null-out above), so nothing can genuinely still be
1299
1328
  // running for this session afterward. Unlike the reconciliation
package/lib/project.js CHANGED
@@ -3,6 +3,7 @@ var path = require("path");
3
3
  var os = require("os");
4
4
  var crypto = require("crypto");
5
5
  var { createSessionManager, stampActivityLocalId } = require("./sessions");
6
+ var sessionLiveness = require("./session-liveness");
6
7
  var { promptsFor } = require("./prompt-registry");
7
8
  var { createSDKBridge, createMessageQueue } = require("./sdk-bridge");
8
9
  var { createTerminalManager } = require("./terminal-manager");
@@ -449,6 +450,7 @@ function createProjectContext(opts) {
449
450
  onProcessingChanged: onProcessingChanged,
450
451
  getProjectName: function () { return title || project; },
451
452
  getProjectSlug: function () { return slug; },
453
+ getPushModule: function () { return pushModule; },
452
454
  });
453
455
  sm.availableVendors = Object.keys(adapters);
454
456
  sm.defaultVendor = defaultVendor;
@@ -1187,7 +1189,6 @@ function createProjectContext(opts) {
1187
1189
  // adapters for this project (see project-connection handleConnection).
1188
1190
  warmup: function () {
1189
1191
  sdk.warmup();
1190
- sdk.startIdleReaper();
1191
1192
  if (!osUsers && !sessionTitleMigrationScheduled) {
1192
1193
  sessionTitleMigrationScheduled = true;
1193
1194
  setTimeout(function () {
@@ -1201,6 +1202,12 @@ function createProjectContext(opts) {
1201
1202
  },
1202
1203
  });
1203
1204
 
1205
+ // The idle reaper runs from attach, not from the first WebSocket: a project
1206
+ // reached only over IPC (open-session, send-input, scheduled input, external
1207
+ // trigger, loop) would otherwise never reap its idle sessions. A repeated
1208
+ // start is a no-op in the bridge, and destroy() stops the timer.
1209
+ sdk.startIdleReaper();
1210
+
1204
1211
  // --- Destroy ---
1205
1212
  // opts.reason says why the project is going away. Only a daemon shutdown
1206
1213
  // (sessionReclaim.RESTART_REASON) records its live background agents as
@@ -1210,6 +1217,9 @@ function createProjectContext(opts) {
1210
1217
  function destroy(opts) {
1211
1218
  var daemonShutdown = !!opts && opts.reason === sessionReclaim.RESTART_REASON;
1212
1219
  var tally = opts && opts.tally;
1220
+ // Ended before the aborts below, which would otherwise record the
1221
+ // daemon going away as each session's own abort.
1222
+ if (daemonShutdown) promptsFor(sm).shutdown();
1213
1223
  _loop.stopTimer();
1214
1224
  stopAllWatches();
1215
1225
  // Abort all active sessions and clean up mention sessions
@@ -1251,6 +1261,7 @@ function createProjectContext(opts) {
1251
1261
  try { _localMcp.shutdown(); } catch (e) {}
1252
1262
  }
1253
1263
  for (var ws of clients) {
1264
+ _connection.recordDisconnect(ws);
1254
1265
  try { ws.close(); } catch (e) {}
1255
1266
  }
1256
1267
  clients.clear();
@@ -1282,11 +1293,13 @@ function createProjectContext(opts) {
1282
1293
  function getStatus() {
1283
1294
  var sessionCount = sm.sessions.size;
1284
1295
  var hasProcessing = false;
1296
+ var hasWaiting = false;
1285
1297
  // Every prompt awaiting the operator, of any kind, flags the project.
1286
1298
  var pendingPermCount = 0;
1287
1299
  var prompts = promptsFor(sm);
1288
1300
  sm.sessions.forEach(function (s) {
1289
1301
  if (s.isProcessing) hasProcessing = true;
1302
+ if (sessionLiveness.activityOf(s) === sessionLiveness.ACTIVITY.WAITING) hasWaiting = true;
1290
1303
  pendingPermCount += prompts.pendingCount(s);
1291
1304
  });
1292
1305
  var status = {
@@ -1300,6 +1313,7 @@ function createProjectContext(opts) {
1300
1313
  clients: clients.size,
1301
1314
  sessions: sessionCount,
1302
1315
  isProcessing: hasProcessing,
1316
+ waiting: hasWaiting,
1303
1317
  pendingPermissions: pendingPermCount,
1304
1318
  projectOwnerId: projectOwnerId,
1305
1319
  };