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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/LICENSES/README.md +5 -0
  2. package/README.md +1 -0
  3. package/bin/cli.js +5 -2
  4. package/lib/agent-roster-ws.js +84 -0
  5. package/lib/agent-roster.js +312 -0
  6. package/lib/auth-required-notify.js +42 -0
  7. package/lib/build-changes.js +8 -2
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-notify.js +45 -0
  10. package/lib/build-update-offer.js +34 -11
  11. package/lib/build-update-standing.js +34 -14
  12. package/lib/claude-settings-env.js +142 -0
  13. package/lib/cli/duration.js +27 -0
  14. package/lib/cli/schedule-input-subcommands.js +1 -22
  15. package/lib/cli/session-subcommands.js +60 -11
  16. package/lib/client-address.js +44 -0
  17. package/lib/daemon.js +31 -10
  18. package/lib/idle-compaction-setting.js +203 -0
  19. package/lib/mcp-bridge-credential.js +41 -0
  20. package/lib/notification-prefs.js +18 -22
  21. package/lib/notify/core.js +210 -0
  22. package/lib/notify/index.js +31 -0
  23. package/lib/notify/live-prompts.js +36 -0
  24. package/lib/notify/payload.js +62 -0
  25. package/lib/notify/target.js +5 -0
  26. package/lib/notify/type-registry.js +81 -0
  27. package/lib/notify/types.js +57 -0
  28. package/lib/open-sockets.js +27 -0
  29. package/lib/outbound-access.js +85 -0
  30. package/lib/outbound-entry.js +116 -0
  31. package/lib/outbound-ledger.js +306 -0
  32. package/lib/outbound-query.js +153 -0
  33. package/lib/pending-prompts.js +31 -16
  34. package/lib/project-connection.js +48 -8
  35. package/lib/project-filesystem.js +43 -5
  36. package/lib/project-http.js +9 -1
  37. package/lib/project-loop.js +38 -26
  38. package/lib/project-notifications.js +122 -39
  39. package/lib/project-prompt-responses.js +1 -1
  40. package/lib/project-sessions.js +11 -1
  41. package/lib/project-user-mention.js +22 -34
  42. package/lib/project-user-message.js +208 -4
  43. package/lib/project-user-shell.js +298 -0
  44. package/lib/project.js +41 -5
  45. package/lib/prompt-answer.js +145 -0
  46. package/lib/prompt-expiry.js +50 -0
  47. package/lib/prompt-registry.js +98 -25
  48. package/lib/prompt-reminders.js +38 -33
  49. package/lib/prompt-source.js +59 -8
  50. package/lib/public/app.js +32 -2
  51. package/lib/public/css/agent-messages.css +96 -0
  52. package/lib/public/css/agent-roster.css +93 -0
  53. package/lib/public/css/diagnostics.css +29 -1
  54. package/lib/public/css/home-hub.css +12 -0
  55. package/lib/public/css/icon-strip.css +9 -0
  56. package/lib/public/css/input.css +20 -141
  57. package/lib/public/css/login-panel.css +73 -0
  58. package/lib/public/css/menus.css +2 -2
  59. package/lib/public/css/mobile-nav.css +11 -0
  60. package/lib/public/css/sidebar.css +18 -0
  61. package/lib/public/css/team-panel.css +1 -6
  62. package/lib/public/css/team-view.css +101 -0
  63. package/lib/public/css/title-bar.css +10 -0
  64. package/lib/public/css/user-shell.css +144 -0
  65. package/lib/public/index.html +44 -7
  66. package/lib/public/modules/activity-state.js +20 -4
  67. package/lib/public/modules/agent-avatar-picker.js +162 -0
  68. package/lib/public/modules/agent-avatar.js +153 -0
  69. package/lib/public/modules/agent-messages.js +285 -0
  70. package/lib/public/modules/agent-roster.js +157 -0
  71. package/lib/public/modules/app-connection.js +34 -5
  72. package/lib/public/modules/app-messages.js +55 -16
  73. package/lib/public/modules/app-notifications.js +104 -75
  74. package/lib/public/modules/app-panels.js +26 -3
  75. package/lib/public/modules/app-projects.js +3 -1
  76. package/lib/public/modules/app-rate-limit.js +8 -165
  77. package/lib/public/modules/app-rendering.js +32 -7
  78. package/lib/public/modules/build-update-sessions.js +81 -0
  79. package/lib/public/modules/collapsible-text.js +33 -18
  80. package/lib/public/modules/compaction-state.js +34 -0
  81. package/lib/public/modules/custom-icons.js +23 -5
  82. package/lib/public/modules/diagnostics.js +61 -57
  83. package/lib/public/modules/env-shadow-notice.js +34 -0
  84. package/lib/public/modules/injected-identity.js +24 -21
  85. package/lib/public/modules/input.js +176 -15
  86. package/lib/public/modules/login-panel.js +136 -0
  87. package/lib/public/modules/login-parser.js +73 -0
  88. package/lib/public/modules/login-tab.js +66 -0
  89. package/lib/public/modules/notifications.js +9 -1
  90. package/lib/public/modules/notify-client.js +246 -0
  91. package/lib/public/modules/pending-term-request.js +30 -0
  92. package/lib/public/modules/project-icon.js +22 -2
  93. package/lib/public/modules/project-settings.js +5 -0
  94. package/lib/public/modules/prompt-state.js +3 -3
  95. package/lib/public/modules/prompts.js +1 -1
  96. package/lib/public/modules/queued-button.js +11 -0
  97. package/lib/public/modules/scheduled-input-actions.js +12 -4
  98. package/lib/public/modules/scheduled-outbox.js +230 -0
  99. package/lib/public/modules/send-now.js +200 -0
  100. package/lib/public/modules/server-settings.js +50 -1
  101. package/lib/public/modules/shell-card.js +76 -0
  102. package/lib/public/modules/shell-line.js +49 -0
  103. package/lib/public/modules/shell-queue.js +253 -0
  104. package/lib/public/modules/shell-settings-controls.js +76 -0
  105. package/lib/public/modules/sidebar-mobile.js +3 -3
  106. package/lib/public/modules/sidebar-sessions.js +8 -0
  107. package/lib/public/modules/sidebar-users.js +5 -7
  108. package/lib/public/modules/team-panel.js +30 -88
  109. package/lib/public/modules/team-view.js +211 -0
  110. package/lib/public/modules/terminal-links.js +193 -0
  111. package/lib/public/modules/terminal.js +84 -107
  112. package/lib/public/modules/tools.js +19 -0
  113. package/lib/public/modules/user-shell.js +824 -0
  114. package/lib/public/notify-sw-logic.js +252 -0
  115. package/lib/public/notify-target.js +157 -0
  116. package/lib/public/style.css +5 -0
  117. package/lib/public/sw.js +20 -69
  118. package/lib/push.js +63 -19
  119. package/lib/queued-chat.js +392 -0
  120. package/lib/runtime-env.js +1 -0
  121. package/lib/scheduled-input/ws.js +67 -9
  122. package/lib/sdk-bridge.js +184 -73
  123. package/lib/sdk-message-processor.js +124 -76
  124. package/lib/server-auth.js +6 -4
  125. package/lib/server-dm.js +11 -20
  126. package/lib/server-settings.js +39 -1
  127. package/lib/server.js +112 -16
  128. package/lib/session-directory.js +39 -12
  129. package/lib/session-end.js +97 -0
  130. package/lib/session-input-ipc.js +37 -1
  131. package/lib/session-input.js +263 -21
  132. package/lib/session-liveness.js +53 -0
  133. package/lib/session-reclaim.js +37 -2
  134. package/lib/session-resume.js +1 -0
  135. package/lib/session-settings-file.js +53 -0
  136. package/lib/sessions.js +80 -9
  137. package/lib/team-traffic-ws.js +68 -0
  138. package/lib/team-traffic.js +318 -0
  139. package/lib/usage-store.js +36 -7
  140. package/lib/user-shell-settings.js +105 -0
  141. package/lib/vendor-auth.js +33 -2
  142. package/lib/ws-schema.js +33 -5
  143. package/lib/yoke/adapters/claude-capabilities.js +2 -0
  144. package/lib/yoke/adapters/claude-vendor.js +17 -1
  145. package/lib/yoke/adapters/claude-worker.js +39 -11
  146. package/lib/yoke/adapters/claude.js +225 -6
  147. package/lib/yoke/adapters/codex-capabilities.js +6 -1
  148. package/lib/yoke/adapters/codex-user-shell.js +265 -0
  149. package/lib/yoke/adapters/codex-vendor.js +7 -0
  150. package/lib/yoke/adapters/codex.js +186 -52
  151. package/lib/yoke/auth-checks.js +17 -2
  152. package/lib/yoke/codex-app-server.js +8 -2
  153. package/lib/yoke/index.js +21 -3
  154. package/lib/yoke/interface.js +54 -1
  155. package/lib/yoke/mcp-bridge-server.js +12 -8
  156. package/lib/yoke/provider-credentials.js +24 -0
  157. package/lib/yoke/registry.js +40 -1
  158. package/lib/yoke/user-shell.js +224 -0
  159. package/package.json +2 -2
  160. package/scripts/check-test-count.js +14 -0
  161. package/lib/public/modules/build-notice-gate.js +0 -73
@@ -2,6 +2,10 @@ var fs = require("fs");
2
2
  var path = require("path");
3
3
  var fileScope = require("./project-file-scope");
4
4
  var projectGit = require("./project-git");
5
+ var claudeSettingsEnv = require("./claude-settings-env");
6
+ var idleCompaction = require("./idle-compaction-setting");
7
+ var runtimeEnv = require("./runtime-env");
8
+ var { REAL_HOME } = require("./config");
5
9
 
6
10
  // Settings that act on the whole machine (not on this project), so the
7
11
  // per-user projectSettings permission is not enough: administrators only.
@@ -56,6 +60,18 @@ function attachFilesystem(ctx) {
56
60
  var IMAGE_EXTS = ctx.IMAGE_EXTS;
57
61
  var fileAccess = ctx.fileAccess;
58
62
 
63
+ // Names a Settings text sets that the daemon user's Claude settings file
64
+ // sets too; the file wins at the runtime, so the editor says so. The one file
65
+ // is located from the daemon's own environment (claude-settings-env.js), never
66
+ // from the text, and os-users mode reads none. configDirNote tells the editor
67
+ // to say the check covers that file only when the text sets CLAUDE_CONFIG_DIR.
68
+ function shadowInfoFor(text) {
69
+ return {
70
+ shadowedKeys: claudeSettingsEnv.shadowedKeys(text, { homeDir: REAL_HOME, osUsers: !!osUsers }),
71
+ shadowConfigDirNote: claudeSettingsEnv.setsConfigDir(text),
72
+ };
73
+ }
74
+
59
75
  // In multi-user mode the project's environment text applies to the project
60
76
  // owner's sessions (lib/runtime-env.js projectEnvApplies), so only the owner
61
77
  // or an administrator may read or change it: anyone else would be writing
@@ -242,10 +258,10 @@ function attachFilesystem(ctx) {
242
258
  } catch (e) {}
243
259
  // appliesTo tells the Settings page whom the text reaches; canEdit that
244
260
  // this user may see and change it. No value goes to a user who may not.
245
- sendTo(ws, {
261
+ sendTo(ws, Object.assign({
246
262
  type: "project_env_result", slug: slug, envrc: envrc, hasEnvrc: hasEnvrc,
247
263
  appliesTo: envMultiUser ? "owner" : "everyone", canEdit: canManageEnv,
248
- });
264
+ }, canManageEnv ? shadowInfoFor(envrc) : { shadowedKeys: [] }));
249
265
  return true;
250
266
  }
251
267
 
@@ -266,13 +282,35 @@ function attachFilesystem(ctx) {
266
282
  return true;
267
283
  }
268
284
  var setResult = opts.onSetProjectEnv(envSlug, envText);
269
- sendTo(ws, { type: "set_project_env_result", ok: setResult.ok, slug: slug, error: setResult.error });
285
+ sendTo(ws, Object.assign({ type: "set_project_env_result", ok: setResult.ok, slug: slug, error: setResult.error }, setResult.ok ? shadowInfoFor(envText) : { shadowedKeys: [] }));
270
286
  } else {
271
287
  sendTo(ws, { type: "set_project_env_result", ok: false, error: "Not supported" });
272
288
  }
273
289
  return true;
274
290
  }
275
291
 
292
+ // --- Claude idleCompaction user setting ---
293
+ // Acts on the requesting account's own settings file. Without OS-level
294
+ // isolation every user shares the daemon account's one file, so changing it
295
+ // is an administrator action there; reading is open.
296
+ if (msg.type === "get_idle_compaction" || msg.type === "set_idle_compaction") {
297
+ var isSet = msg.type === "set_idle_compaction";
298
+ var resultType = isSet ? "set_idle_compaction_result" : "idle_compaction_result";
299
+ var icMultiUser = typeof projectAccess.isMultiUser === "function" ? projectAccess.isMultiUser() : true;
300
+ if (isSet && icMultiUser && !osUsers && !projectAccess.isAdmin(ws._clagenticUser, projectAccess.authOf(ws))) {
301
+ sendTo(ws, { type: resultType, ok: false, error: "Only an administrator can change the shared Claude settings file" });
302
+ return true;
303
+ }
304
+ var icOpts = { osUsers: !!osUsers, osUserInfo: getOsUserInfoForWs(ws), homeDir: REAL_HOME };
305
+ var icPending = isSet
306
+ ? idleCompaction.applyForOwner("write", msg.value, icOpts)
307
+ : idleCompaction.applyForOwner("read", null, icOpts);
308
+ icPending.then(function (icResult) {
309
+ sendTo(ws, { type: resultType, ok: icResult.ok, value: icResult.value, error: icResult.error });
310
+ });
311
+ return true;
312
+ }
313
+
276
314
  // --- Global CLAUDE.md ---
277
315
  if (msg.type === "read_global_claude_md") {
278
316
  var globalMdPath = path.join(require("./config").REAL_HOME, ".claude", "CLAUDE.md");
@@ -307,7 +345,7 @@ function attachFilesystem(ctx) {
307
345
  var sharedResult = opts.onGetSharedEnv();
308
346
  sharedEnvrc = sharedResult.envrc || "";
309
347
  }
310
- sendTo(ws, { type: "shared_env_result", envrc: sharedEnvrc });
348
+ sendTo(ws, Object.assign({ type: "shared_env_result", envrc: sharedEnvrc }, shadowInfoFor(sharedEnvrc)));
311
349
  return true;
312
350
  }
313
351
 
@@ -323,7 +361,7 @@ function attachFilesystem(ctx) {
323
361
  return true;
324
362
  }
325
363
  var sharedSetResult = opts.onSetSharedEnv(msg.envrc || "");
326
- sendTo(ws, { type: "set_shared_env_result", ok: sharedSetResult.ok, error: sharedSetResult.error });
364
+ sendTo(ws, Object.assign({ type: "set_shared_env_result", ok: sharedSetResult.ok, error: sharedSetResult.error }, sharedSetResult.ok ? shadowInfoFor(msg.envrc || "") : { shadowedKeys: [] }));
327
365
  } else {
328
366
  sendTo(ws, { type: "set_shared_env_result", ok: false, error: "Not supported" });
329
367
  }
@@ -205,7 +205,15 @@ function attachHTTP(ctx) {
205
205
  if (req.method === "POST" && urlPath === "/api/push-subscribe") {
206
206
  parseJsonBody(req).then(function (body) {
207
207
  var sub = body.subscription || body;
208
- if (pushModule) pushModule.addSubscription(sub, body.replaceEndpoint);
208
+ // The user is resolved as the top-level route resolves it (the login
209
+ // cookie, set on req by lib/server.js); a subscription stored without
210
+ // one reaches no user-targeted push.
211
+ var pushUser = req._clagenticUser || null;
212
+ if (pushModule && pushModule.addSubscription(sub, body.replaceEndpoint, pushUser ? pushUser.id : null) === false && sub && sub.endpoint) {
213
+ res.writeHead(401, { "Content-Type": "application/json" });
214
+ res.end('{"error":"sign in to enable push notifications"}');
215
+ return;
216
+ }
209
217
  res.writeHead(200, { "Content-Type": "application/json" });
210
218
  res.end('{"ok":true}');
211
219
  }).catch(function () {
@@ -3,9 +3,10 @@ var path = require("path");
3
3
  var crypto = require("crypto");
4
4
  var { execFileSync } = require("child_process");
5
5
  var { createLoopRegistry } = require("./scheduler");
6
+ var sessionLiveness = require("./session-liveness");
6
7
  var store = require("./store");
7
8
  var usersModule = require("./users");
8
- var { pushForSession } = require("./push-audience");
9
+ var { notifyFor } = require("./notify");
9
10
  var { writeHandoff, buildHandoffPreamble } = require("./loop-handoff");
10
11
  var { authOf } = require("./project-access");
11
12
  var { INITIATORS } = require("./turn-initiator");
@@ -102,8 +103,21 @@ function attachLoop(ctx) {
102
103
  // runNextIteration(), and on stop/finish so nothing leaks into a
103
104
  // future run.
104
105
  pendingUserMessages: [],
106
+ // The browser tab that sent loop_start. In memory only, never persisted:
107
+ // a cron, schedule, rerun or resume has no starter. Runner sessions switch
108
+ // only this tab, and only while it is still connected.
109
+ starterWs: null,
105
110
  };
106
111
 
112
+ // createSession arguments for a session the runner creates (iteration or
113
+ // judge). A connected starter tab is the one tab that follows the loop;
114
+ // with no starter, or one that has gone, nothing switches.
115
+ function runnerSessionArgs() {
116
+ var starter = loopState.starterWs;
117
+ if (starter && starter.readyState === 1) return [undefined, starter];
118
+ return [{ activate: false }];
119
+ }
120
+
107
121
  function loopDir() {
108
122
  var id = loopState.loopFilesId || loopState.loopId;
109
123
  if (!id) return null;
@@ -460,6 +474,7 @@ function attachLoop(ctx) {
460
474
  loopState.settings = loopConfig.settings || null;
461
475
  loopState.startedAt = Date.now();
462
476
  loopState.pendingUserMessages = [];
477
+ loopState.starterWs = loopOpts.starterWs || null;
463
478
  saveLoopState();
464
479
 
465
480
  stopClaudeDirWatch();
@@ -490,7 +505,7 @@ function attachLoop(ctx) {
490
505
  return;
491
506
  }
492
507
 
493
- var session = sm.createSession();
508
+ var session = sm.createSession.apply(sm, runnerSessionArgs());
494
509
  var loopSource = loopRegistry.getById(loopState.loopId);
495
510
  var loopName = (loopState.wizardData && loopState.wizardData.name) || (loopSource && loopSource.name) || "";
496
511
  var loopSourceTag = (loopSource && loopSource.source) || null;
@@ -671,7 +686,7 @@ function attachLoop(ctx) {
671
686
  "- PASS: [brief explanation]\n" +
672
687
  "- FAIL: [brief explanation of what is still missing]";
673
688
 
674
- var judgeSession = sm.createSession();
689
+ var judgeSession = sm.createSession.apply(sm, runnerSessionArgs());
675
690
  var judgeSource = loopRegistry.getById(loopState.loopId);
676
691
  var judgeName = (loopState.wizardData && loopState.wizardData.name) || (judgeSource && judgeSource.name) || "";
677
692
  var judgeSourceTag = (judgeSource && judgeSource.source) || null;
@@ -823,6 +838,7 @@ function attachLoop(ctx) {
823
838
  loopState.stopping = false;
824
839
  loopState.currentSessionId = null;
825
840
  loopState.judgeSessionId = null;
841
+ loopState.starterWs = null;
826
842
  // Drop any messages queued but never delivered to an iteration — the loop
827
843
  // is done, so there is no future boundary to deliver them at (lr-e31b).
828
844
  var _hadUndelivered = loopState.pendingUserMessages && loopState.pendingUserMessages.length > 0;
@@ -852,28 +868,25 @@ function attachLoop(ctx) {
852
868
  activeRegistryId = null;
853
869
  }
854
870
 
855
- if (pushModule) {
856
- var _finishBody = reason === "pass" || reason === "complete"
857
- ? "Completed after " + loopState.iteration + " iteration(s)"
858
- : reason === "max_iterations"
859
- ? "Reached max iterations (" + loopState.maxIterations + ")"
860
- : reason === "stopped" ? "Stopped by user" : "Ended due to error";
861
- var _loopDonePayload = {
862
- type: "done", slug: slug, title: "Loop Complete", body: _finishBody, tag: "ralph-loop-done",
863
- };
864
- // Body carries iteration status: loop owner only, never a blind broadcast.
865
- pushForSession(pushModule, _loopOwnerUserId, _loopDonePayload);
866
- }
867
-
868
- if (notificationsModule) {
869
- notificationsModule.notify("loop_complete", {
871
+ var _finishBody = reason === "pass" || reason === "complete"
872
+ ? "Completed after " + loopState.iteration + " iteration(s)"
873
+ : reason === "max_iterations"
874
+ ? "Reached max iterations (" + loopState.maxIterations + ")"
875
+ : reason === "stopped" ? "Stopped by user" : "Ended due to error";
876
+ // One notify() per loop end, to the loop's owner alone (the push body
877
+ // carries iteration status), landing on the loop's last session.
878
+ notifyFor(pushModule, notificationsModule).notify(reason === "error" ? "loop_error" : "loop_complete", {
879
+ slug: slug,
880
+ sessionId: _lastSessionId,
881
+ }, {
882
+ push: { title: "Loop Complete", body: _finishBody },
883
+ banner: {
870
884
  reason: reason,
871
885
  name: loopState.name,
872
886
  iterations: loopState.iteration,
873
887
  maxIterations: loopState.maxIterations,
874
- sessionId: _lastSessionId,
875
- });
876
- }
888
+ },
889
+ }, { ownerId: _loopOwnerUserId });
877
890
 
878
891
  // Process next queued trigger if any
879
892
  if (pendingTriggers.length > 0) {
@@ -989,7 +1002,7 @@ function attachLoop(ctx) {
989
1002
  fs.writeFileSync(ljPath, JSON.stringify(lj, null, 2), "utf8");
990
1003
  }
991
1004
  }
992
- startLoop({ maxIterations: msg.maxIterations });
1005
+ startLoop({ maxIterations: msg.maxIterations, starterWs: ws });
993
1006
  return true;
994
1007
  }
995
1008
 
@@ -1155,12 +1168,11 @@ function attachLoop(ctx) {
1155
1168
  "## Task\n" + (wData.task || "") +
1156
1169
  "\n\n## Loop Directory\n" + lDir;
1157
1170
 
1158
- var judgeCraftSession = sm.createSession();
1171
+ var judgeCraftSession = sm.createSession(undefined, ws);
1159
1172
  judgeCraftSession.title = (isRalphCraft ? "Ralph" : "Task") + (craftName ? " " + craftName : "") + " Crafting";
1160
1173
  judgeCraftSession.ralphCraftingMode = true;
1161
1174
  judgeCraftSession.loop = { active: true, iteration: 0, role: "crafting", loopId: newLoopId, name: craftName, source: recordSource, startedAt: loopState.startedAt };
1162
1175
  sm.saveSessionFile(judgeCraftSession);
1163
- sm.switchSession(judgeCraftSession.localId, null, hydrateImageRefs);
1164
1176
  loopState.craftingSessionId = judgeCraftSession.localId;
1165
1177
 
1166
1178
  loopRegistry.updateRecord(newLoopId, { craftingSessionId: judgeCraftSession.localId });
@@ -1231,12 +1243,11 @@ function attachLoop(ctx) {
1231
1243
  }
1232
1244
 
1233
1245
  // Create a new session for crafting
1234
- var craftingSession = sm.createSession();
1246
+ var craftingSession = sm.createSession(undefined, ws);
1235
1247
  craftingSession.title = (isRalphCraft ? "Ralph" : "Task") + (craftName ? " " + craftName : "") + " Crafting";
1236
1248
  craftingSession.ralphCraftingMode = true;
1237
1249
  craftingSession.loop = { active: true, iteration: 0, role: "crafting", loopId: newLoopId, name: craftName, source: recordSource, startedAt: loopState.startedAt };
1238
1250
  sm.saveSessionFile(craftingSession);
1239
- sm.switchSession(craftingSession.localId, null, hydrateImageRefs);
1240
1251
  loopState.craftingSessionId = craftingSession.localId;
1241
1252
 
1242
1253
  // Store crafting session ID in the registry record
@@ -1463,6 +1474,7 @@ function attachLoop(ctx) {
1463
1474
  // needs it to distinguish "my activity" from "another user's
1464
1475
  // activity" the same way session_list already does.
1465
1476
  ownerId: s.ownerId || null,
1477
+ waiting: sessionLiveness.activityOf(s) === sessionLiveness.ACTIVITY.WAITING,
1466
1478
  };
1467
1479
  });
1468
1480
  sendTo(ws, { type: "hub_recent_sessions", sessions: mapped });
@@ -8,6 +8,7 @@ var config = require("./config");
8
8
  var yokeRegistry = require("./yoke").registry;
9
9
  var notificationPrefs = require("./notification-prefs");
10
10
  var audienceFor = require("./push-audience").audienceFor;
11
+ var notifyCore = require("./notify");
11
12
 
12
13
  var NOTIF_FILE = path.join(config.CONFIG_DIR, "notifications.json");
13
14
 
@@ -34,10 +35,37 @@ var formatters = {
34
35
  loginCommand: data.loginCommand || "",
35
36
  linuxUser: data.linuxUser || null,
36
37
  canAutoLogin: !!data.canAutoLogin,
38
+ // Stays until acted on; the banner reads this flag, not a type list.
39
+ persistent: true,
40
+ },
41
+ };
42
+ },
43
+
44
+ // The installed build is newer than the running one. The page builds the
45
+ // diagnostics entry (the place its restart action lives) from the offer in
46
+ // meta; the offer carries no restart token, which is issued per requester.
47
+ build_update_offer: function (data) {
48
+ return {
49
+ type: "build_update_offer",
50
+ title: data.title || "A newer build is installed",
51
+ body: data.body || "",
52
+ meta: {
53
+ message: data.message || "",
54
+ buildUpdate: data.buildUpdate || null,
55
+ actionable: data.actionable || null,
37
56
  },
38
57
  };
39
58
  },
40
59
 
60
+ update_available: function (data) {
61
+ return {
62
+ type: "update_available",
63
+ title: data.title || "Update available",
64
+ body: data.body || "",
65
+ meta: { version: data.version || "", current: data.current || "" },
66
+ };
67
+ },
68
+
41
69
  loop_complete: function (data) {
42
70
  var reason = data.reason || "complete";
43
71
  var body = (reason === "pass" || reason === "complete")
@@ -92,7 +120,6 @@ var formatters = {
92
120
  title: data.title || "Prompts waiting",
93
121
  body: data.body || "",
94
122
  meta: {
95
- reminderKey: data.reminderKey || null,
96
123
  requestIds: data.requestIds || [],
97
124
  count: data.count || 0,
98
125
  ageMs: data.ageMs || 0,
@@ -137,6 +164,10 @@ var formatters = {
137
164
  },
138
165
  };
139
166
 
167
+ // A loop that ended in error is its own type, so it is registered and filtered
168
+ // as one; the formatter reads the reason either way.
169
+ formatters.loop_error = formatters.loop_complete;
170
+
140
171
  // ========================================================
141
172
  // Module (global singleton)
142
173
  // ========================================================
@@ -154,16 +185,21 @@ function attachNotifications(ctx) {
154
185
  var isMultiUser = ctx.isMultiUser || null;
155
186
  var listAdmins = ctx.listAdmins || null;
156
187
 
188
+ var onResolvedByOperator = typeof ctx.onResolvedByOperator === "function" ? ctx.onResolvedByOperator : null;
189
+
157
190
  // A prompt notification (and the reminder about it) is actionable only while
158
191
  // its prompt's resolver lives in this process; none survives a restart, so a
159
- // persisted one would offer buttons for a prompt nothing can answer.
192
+ // persisted one would offer buttons for a prompt nothing can answer. A type
193
+ // registered ephemeral (the build-update offer) is rebuilt from live state.
160
194
  function loadNotifications() {
161
195
  try {
162
196
  var raw = fs.readFileSync(NOTIF_FILE, "utf8");
163
197
  var parsed = JSON.parse(raw);
164
198
  if (Array.isArray(parsed)) {
165
199
  return parsed.filter(function (n) {
166
- return !(n && (n.type === "permission_request" || n.type === "permission_reminder"));
200
+ if (!n) return false;
201
+ var registered = notifyCore.getType(n.type);
202
+ return !(n.type === "permission_request" || n.type === "permission_reminder" || (registered && registered.ephemeral));
167
203
  });
168
204
  }
169
205
  } catch (e) {}
@@ -203,7 +239,15 @@ function attachNotifications(ctx) {
203
239
 
204
240
  // --- Core API ---
205
241
 
206
- function notify(event, data) {
242
+ // meta, set by the notification core when it delivers a banner (lib/notify/):
243
+ // key the collapse identity; a banner under the same key replaces
244
+ // the earlier one, and a resolve closes the banners under it.
245
+ // collapse "request" | "session", the key's rule.
246
+ // persistent the registry says the banner is not auto-dismissed.
247
+ // liveInState the page may check the banner against the live prompts.
248
+ // They travel on the notification (key, collapse, persistent, liveInState).
249
+ function notify(event, data, meta) {
250
+ meta = meta || {};
207
251
  data = data || {};
208
252
  var formatter = formatters[event];
209
253
  if (!formatter) {
@@ -233,10 +277,15 @@ function attachNotifications(ctx) {
233
277
  slug: data.slug || "",
234
278
  sessionId: data.sessionId || null,
235
279
  mateId: data.mateId || null,
280
+ peerId: data.peerId || null,
236
281
  ownerId: data.ownerId || null,
237
282
  targetUserId: data.targetUserId || null,
238
283
  targetUserIds: Array.isArray(data.targetUserIds) ? data.targetUserIds : null,
239
284
  createdAt: Date.now(),
285
+ key: meta.key || null,
286
+ collapse: meta.collapse || null,
287
+ persistent: meta.persistent === true,
288
+ liveInState: meta.liveInState === true,
240
289
  meta: formatted.meta || {},
241
290
  };
242
291
  notifications.unshift(notif);
@@ -271,48 +320,74 @@ function attachNotifications(ctx) {
271
320
  }
272
321
  }
273
322
 
323
+ // The core's banner surface (lib/notify/): a banner under a key the
324
+ // notification just collapsed to replaces the earlier one on every client,
325
+ // the dismissal and the new banner travelling together.
326
+ function show(event, data, meta) {
327
+ var key = meta && meta.key;
328
+ if (key) {
329
+ var old = idsByKey([key]);
330
+ if (old.length) dismiss(old);
331
+ }
332
+ return notify(event, data, meta);
333
+ }
334
+
335
+ function idsByKey(keys) {
336
+ return notifications.filter(function (n) {
337
+ return n.key && keys.indexOf(n.key) !== -1;
338
+ }).map(function (n) { return n.id; });
339
+ }
340
+
274
341
  // A prompt notification is only actionable while its prompt is pending; the
275
- // prompt registry calls this on every transition that ends one, so the
276
- // banner buttons never outlive it.
277
- function dismissByRequestId(requestId) {
278
- if (!requestId) return;
342
+ // core calls this when a target resolves, so the banner buttons never
343
+ // outlive the prompt.
344
+ function dismissKeys(keys) {
345
+ var ids = idsByKey(keys || []);
346
+ if (ids.length) dismiss(ids);
347
+ }
348
+
349
+ // The banners of one prompt, when only its request id is known (a stale
350
+ // answer no session claims). The slug scopes it to the prompt's project and
351
+ // is required: a request id alone names nothing, so no slug dismisses nothing.
352
+ function dismissRequest(slug, requestId) {
353
+ if (!slug || !requestId) return;
279
354
  var ids = notifications.filter(function (n) {
280
- return n.type === "permission_request" && n.meta && n.meta.requestId === requestId;
355
+ return n.collapse === "request" && n.meta && n.meta.requestId === requestId && n.slug === slug;
281
356
  }).map(function (n) { return n.id; });
282
357
  if (ids.length) dismiss(ids);
283
- // A reminder that names this prompt is now wrong, or gone.
284
- reconcileRemindersNow();
358
+ }
359
+
360
+ // The operator closed these banners. A notification of a type that is also
361
+ // shown on the phone (push) is closed there too, and the type's owner is told
362
+ // it was declined, so a close in one window is a close on every device.
363
+ function resolveDismissed(list) {
364
+ if (!pushModule && !onResolvedByOperator) return;
365
+ var core = notifyCore.notifyFor(pushModule, api);
366
+ var seen = Object.create(null);
367
+ list.forEach(function (n) {
368
+ var type = notifyCore.getType(n.type);
369
+ if (!type || type.category !== "system" || type.closeOnResolve || seen[n.type]) return;
370
+ // Only a system type about the console itself (no project, no session)
371
+ // is closed this way; a sign-in notice belongs to its session.
372
+ if (n.sessionId || n.slug) return;
373
+ seen[n.type] = true;
374
+ core.resolve({ slug: null, sessionId: null }, { ownerId: null, isMultiUser: isMultiUser, listAdmins: listAdmins }, { type: n.type });
375
+ if (onResolvedByOperator) onResolvedByOperator(n.type);
376
+ });
285
377
  }
286
378
 
287
379
  function dismissAll() {
288
380
  if (notifications.length > 0) {
381
+ var closing = notifications;
289
382
  notifications = [];
290
383
  saveNotifications();
291
384
  broadcastAll({ type: "notification_dismissed_all", unreadCount: 0 });
385
+ resolveDismissed(closing);
292
386
  }
293
387
  }
294
388
 
295
389
  // --- Prompt reminders (scheduling lives in lib/prompt-reminders.js) ---
296
390
 
297
- function reminderIds(key) {
298
- return notifications.filter(function (n) {
299
- return n.type === "permission_reminder" && n.meta && n.meta.reminderKey === key;
300
- }).map(function (n) { return n.id; });
301
- }
302
-
303
- // A session has at most one live reminder: the new one replaces the old on
304
- // every surface (the dismissal and the new notification travel together).
305
- function replaceReminder(key, data) {
306
- var old = reminderIds(key);
307
- if (old.length) dismiss(old);
308
- return notify("permission_reminder", Object.assign({}, data, { reminderKey: key }));
309
- }
310
-
311
- function dismissReminder(key) {
312
- var ids = reminderIds(key);
313
- if (ids.length) dismiss(ids);
314
- }
315
-
316
391
  function setReminderReconciler(fn) {
317
392
  reconcileReminders = typeof fn === "function" ? fn : null;
318
393
  }
@@ -329,17 +404,20 @@ function attachNotifications(ctx) {
329
404
  }
330
405
  }
331
406
 
332
- var PROMPT_TYPES = { permission_request: true, permission_reminder: true };
333
-
407
+ // A notification aimed at users is shown to them alone, whatever its type:
408
+ // the live delivery and the list a connecting client is handed agree.
334
409
  function visibleTo(n, viewer) {
335
410
  if (Array.isArray(n.targetUserIds)) return n.targetUserIds.indexOf(viewer) !== -1;
336
- if (PROMPT_TYPES[n.type] && n.targetUserId) return n.targetUserId === viewer;
411
+ if (n.targetUserId) return n.targetUserId === viewer;
337
412
  return true;
338
413
  }
339
414
 
340
415
  // --- Connection state (called per-client with sendTo) ---
341
416
 
342
- function sendConnectionState(ws, sendTo) {
417
+ // livePrompts: the prompts awaiting the operator in this project when the
418
+ // client connected (lib/notify/live-prompts.js); the page checks the
419
+ // notifications on the device against it.
420
+ function sendConnectionState(ws, sendTo, livePrompts) {
343
421
  if (!sendTo) return;
344
422
  // A notification aimed at admins only, or a prompt banner aimed at its
345
423
  // owner, is not handed to anyone else on connect, as it is not live.
@@ -348,6 +426,7 @@ function attachNotifications(ctx) {
348
426
  type: "notifications_state",
349
427
  notifications: notifications.filter(function (n) { return visibleTo(n, viewer); }),
350
428
  unreadCount: unreadCountFor(viewer),
429
+ livePrompts: livePrompts || null,
351
430
  });
352
431
  if (prefsStore) sendTo(ws, prefsMessage(userIdOf(ws)));
353
432
  }
@@ -385,7 +464,10 @@ function attachNotifications(ctx) {
385
464
 
386
465
  function handleNotificationMessage(ws, msg) {
387
466
  if (msg.type === "notification_dismiss") {
388
- dismiss(msg.ids || []);
467
+ var ids = Array.isArray(msg.ids) ? msg.ids : [];
468
+ var closing = notifications.filter(function (n) { return ids.indexOf(n.id) !== -1; });
469
+ dismiss(ids);
470
+ resolveDismissed(closing);
389
471
  return true;
390
472
  }
391
473
  if (msg.type === "notification_dismiss_all") {
@@ -408,17 +490,18 @@ function attachNotifications(ctx) {
408
490
  return false;
409
491
  }
410
492
 
411
- return {
493
+ var api = {
412
494
  notify: notify,
413
- dismissByRequestId: dismissByRequestId,
414
- replaceReminder: replaceReminder,
415
- dismissReminder: dismissReminder,
495
+ show: show,
496
+ dismissKeys: dismissKeys,
497
+ dismissRequest: dismissRequest,
416
498
  setReminderReconciler: setReminderReconciler,
417
499
  reconcileReminders: reconcileRemindersNow,
418
500
  getUnreadCount: getUnreadCount,
419
501
  sendConnectionState: sendConnectionState,
420
502
  handleNotificationMessage: handleNotificationMessage,
421
503
  };
504
+ return api;
422
505
  }
423
506
 
424
507
  module.exports = { attachNotifications: attachNotifications };
@@ -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");
@@ -20,6 +21,7 @@ var { checkPermissionMode } = require("./permission-mode-policy");
20
21
  var { attachPermissionSettings, isServerAdmin } = require("./project-permission-settings");
21
22
  var { effectiveSessionMode } = require("./sessions");
22
23
  var { composeRestartingNotice } = require("./build-update-offer");
24
+ var { notifyFor } = require("./notify");
23
25
  // Kick off SDK agent discovery in the background at module load.
24
26
  // Errors are swallowed inside refresh(); the cache starts empty and fills
25
27
  // when the SDK subprocess completes initialization (~9s on this box).
@@ -800,7 +802,15 @@ function attachSessions(ctx) {
800
802
  fetchVersion(updateChannel).then(function (latest) {
801
803
  if (latest && isNewer(latest, currentVersion)) {
802
804
  setLatestVersion(latest);
805
+ // The asking client's settings button reads the reply; the banner and
806
+ // the push for every admin come from the core, which collapses the
807
+ // repeat from each client's hourly check into one.
803
808
  sendTo(ws, { type: "update_available", version: latest, current: currentVersion });
809
+ var updateText = { title: "Update available", body: "Clagentic: Console v" + latest + " is available" };
810
+ notifyFor(pushModule, getNotificationsModule()).notify("update_available", { slug: null, sessionId: null }, {
811
+ push: updateText,
812
+ banner: Object.assign({ version: latest, current: currentVersion }, updateText),
813
+ }, {});
804
814
  } else {
805
815
  sendTo(ws, { type: "up_to_date", version: currentVersion });
806
816
  }
@@ -1321,7 +1331,7 @@ function attachSessions(ctx) {
1321
1331
  session.abortController = null;
1322
1332
  session.blocks = {};
1323
1333
  session.sentToolResults = {};
1324
- promptsFor(sm).cancelSession(session, "rewind");
1334
+ promptsFor(sm).cancelSession(session, "rewind", { source: promptSource.CANCEL.USER });
1325
1335
  // lr-9bcd7b: a rewind destroys the in-flight query outright (the
1326
1336
  // queryInstance null-out above), so nothing can genuinely still be
1327
1337
  // running for this session afterward. Unlike the reconciliation