@clagentic/console 1.10.0-beta.1 → 1.10.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 (94) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +10 -0
  3. package/lib/activity-clock.js +23 -0
  4. package/lib/agent-dispatch-tool.js +20 -0
  5. package/lib/build-changes.js +79 -0
  6. package/lib/build-identity.js +192 -0
  7. package/lib/build-monitor.js +125 -0
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-offer.js +141 -0
  10. package/lib/build-update-restart.js +142 -0
  11. package/lib/build-update-standing.js +184 -0
  12. package/lib/cli/daemon-launch.js +8 -5
  13. package/lib/cli/ipc-subcommands.js +6 -0
  14. package/lib/cli/session-subcommands.js +122 -0
  15. package/lib/cli-sessions.js +8 -1
  16. package/lib/cli-transcript-title.js +131 -0
  17. package/lib/codex-defaults.js +8 -2
  18. package/lib/daemon-projects.js +19 -0
  19. package/lib/daemon.js +166 -127
  20. package/lib/debug-log.js +17 -0
  21. package/lib/exit-flush.js +44 -0
  22. package/lib/grant-keys.js +179 -0
  23. package/lib/log-field.js +34 -0
  24. package/lib/memory-shed.js +13 -32
  25. package/lib/project-connection.js +14 -0
  26. package/lib/project-external-trigger.js +91 -123
  27. package/lib/project-http.js +2 -0
  28. package/lib/project-loop.js +5 -4
  29. package/lib/project-notifications.js +4 -0
  30. package/lib/project-prompt-responses.js +7 -5
  31. package/lib/project-session-grants.js +73 -0
  32. package/lib/project-sessions.js +55 -68
  33. package/lib/project-user-message.js +13 -25
  34. package/lib/project.js +25 -5
  35. package/lib/prompt-kinds/permission.js +18 -0
  36. package/lib/prompt-label.js +60 -0
  37. package/lib/prompt-registry.js +123 -13
  38. package/lib/prompt-source.js +65 -0
  39. package/lib/public/css/diagnostics.css +30 -0
  40. package/lib/public/css/notifications-center.css +15 -0
  41. package/lib/public/css/overlays.css +18 -0
  42. package/lib/public/css/rewind.css +8 -0
  43. package/lib/public/modules/agent-dispatch-tool.js +9 -0
  44. package/lib/public/modules/app-messages.js +10 -2
  45. package/lib/public/modules/app-notifications.js +9 -1
  46. package/lib/public/modules/app-panels.js +0 -1
  47. package/lib/public/modules/build-update-detail.js +54 -0
  48. package/lib/public/modules/diagnostics.js +126 -20
  49. package/lib/public/modules/prompt-banner.js +12 -0
  50. package/lib/public/modules/prompt-kinds/permission-choices.js +6 -1
  51. package/lib/public/modules/prompt-kinds/permission.js +15 -0
  52. package/lib/public/modules/prompt-label.js +44 -0
  53. package/lib/public/modules/prompts.js +9 -0
  54. package/lib/public/modules/session-grants.js +131 -0
  55. package/lib/public/modules/sidebar-sessions.js +11 -0
  56. package/lib/public/modules/tools.js +14 -2
  57. package/lib/public/modules/vendor-picker.js +2 -2
  58. package/lib/public/modules/vendor-registry.js +11 -2
  59. package/lib/runtime-env.js +1 -1
  60. package/lib/sdk-bridge.js +114 -115
  61. package/lib/sdk-message-processor.js +25 -87
  62. package/lib/sdk-skill-discovery.js +65 -60
  63. package/lib/server.js +15 -2
  64. package/lib/session-ai-title.js +80 -0
  65. package/lib/session-id.js +33 -0
  66. package/lib/session-input-ipc.js +32 -0
  67. package/lib/session-input.js +409 -0
  68. package/lib/session-reclaim.js +284 -0
  69. package/lib/session-resume.js +172 -0
  70. package/lib/sessions.js +31 -21
  71. package/lib/supervisor.js +39 -0
  72. package/lib/turn-initiator.js +108 -0
  73. package/lib/utils.js +9 -47
  74. package/lib/vendor-registry-message.js +1 -0
  75. package/lib/ws-schema.js +9 -4
  76. package/lib/yoke/adapters/claude-vendor.js +0 -1
  77. package/lib/yoke/adapters/claude-worker.js +6 -4
  78. package/lib/yoke/adapters/claude.js +29 -86
  79. package/lib/yoke/adapters/codex-capabilities.js +9 -6
  80. package/lib/yoke/adapters/codex-vendor.js +15 -15
  81. package/lib/yoke/adapters/codex.js +125 -136
  82. package/lib/yoke/auth-checks.js +8 -21
  83. package/lib/yoke/codex-app-server.js +27 -71
  84. package/lib/yoke/codex-binary.js +254 -0
  85. package/lib/yoke/codex-command.js +122 -0
  86. package/lib/yoke/codex-protocol.js +96 -0
  87. package/lib/yoke/codex-version.js +135 -0
  88. package/lib/yoke/index.js +20 -4
  89. package/lib/yoke/install-probe.js +21 -6
  90. package/lib/yoke/interface.js +14 -12
  91. package/lib/yoke/registry.js +41 -4
  92. package/package.json +1 -2
  93. package/scripts/verify-installed-build.js +59 -17
  94. package/lib/lore-attestation.js +0 -73
@@ -26,17 +26,28 @@
26
26
  import { iconHtml, refreshIcons } from './icons.js';
27
27
  import { formatDiagnosticSource as _formatSource } from './diagnostic-format.js';
28
28
  import { sendWs } from './ws-ref.js';
29
+ import { buildUpdateDetailEl } from './build-update-detail.js';
29
30
 
30
- // lr-e85fec: allowlist of actionable.action values this client will act on.
31
+ // Allowlist of actionable.action values this client will act on.
31
32
  // A diagnostic's `actionable.action` string is never sent to the server
32
33
  // verbatim as a WS message type — only a value in this map is ever wired to
33
34
  // a click, so the backend cannot steer the client into sending an arbitrary
34
35
  // WS command by way of a diagnostic message.
36
+ //
37
+ // Applying an installed build takes two clicks. The first asks the daemon for
38
+ // the offer (what a restart would end); nothing restarts. The offer arrives as
39
+ // another diagnostic carrying a one-use token, and only its "Restart now"
40
+ // sends that token back.
41
+ var CONFIRM_BUILD_UPDATE = 'confirm_build_update_restart';
35
42
  var ACTIONABLE_HANDLERS = {
36
43
  restart_for_build_update: function () { sendWs({ type: 'restart_for_build_update' }); },
44
+ confirm_build_update_restart: function (entry) {
45
+ var token = entry.buildUpdate && entry.buildUpdate.token;
46
+ if (typeof token === 'string' && token) sendWs({ type: 'restart_for_build_update', confirmToken: token });
47
+ },
37
48
  };
38
49
 
39
- // lr-e85fec: shared by both render sites below (panel entry + toast). Returns
50
+ // Shared by both render sites below (panel entry + toast). Returns
40
51
  // a clickable button when entry.actionable.action is a known action, or null
41
52
  // when there is no label or no known handler — callers render their own
42
53
  // existing icon+text hint in the null case, so this only owns the "known
@@ -50,11 +61,22 @@ function _buildActionableEl(entry, btnClass) {
50
61
  btn.textContent = entry.actionable.label;
51
62
  btn.addEventListener("click", function () {
52
63
  btn.disabled = true;
53
- handler();
64
+ handler(entry);
54
65
  });
55
66
  return btn;
56
67
  }
57
68
 
69
+ // The operator declines a restart offer by closing it; "Not now" says so
70
+ // beside the confirm button. Only an offer has one.
71
+ function _buildDeclineEl(entry, btnClass, onDecline) {
72
+ if (!entry.actionable || entry.actionable.action !== CONFIRM_BUILD_UPDATE) return null;
73
+ var btn = document.createElement("button");
74
+ btn.className = btnClass + " build-update-decline";
75
+ btn.textContent = "Not now";
76
+ btn.addEventListener("click", onDecline);
77
+ return btn;
78
+ }
79
+
58
80
  // --- Module state ---
59
81
  var diagnostics = []; // [{id, severity, source, message, actionable, ts}]
60
82
  var panelEl = null;
@@ -164,7 +186,7 @@ export function initDiagnostics() {
164
186
  // Public: add a diagnostic
165
187
  // ============================================================
166
188
 
167
- export function addDiagnostic(msg) {
189
+ export function addDiagnostic(msg, opts) {
168
190
  var now = Date.now();
169
191
 
170
192
  // lr-e901: same condition can arrive via two independent emitters (CLI-stderr
@@ -177,6 +199,7 @@ export function addDiagnostic(msg) {
177
199
  scope: msg.scope || "",
178
200
  message: msg.message || "",
179
201
  actionable: msg.actionable || null,
202
+ buildUpdate: msg.buildUpdate || null,
180
203
  ts: now,
181
204
  id: _nextDiagnosticId++,
182
205
  };
@@ -189,11 +212,73 @@ export function addDiagnostic(msg) {
189
212
  _updateBadge();
190
213
 
191
214
  // Toast for warning and error severity only.
192
- if (entry.severity === "warning" || entry.severity === "error") {
215
+ var toastAllowed = !(opts && opts.toast === false);
216
+ if (toastAllowed && (entry.severity === "warning" || entry.severity === "error")) {
193
217
  _showDiagnosticToast(entry);
194
218
  }
195
219
  }
196
220
 
221
+ /**
222
+ * Updates the entry a source already holds with a newer message (the update
223
+ * offer, once its change list is read). It replaces in place: no second entry,
224
+ * no new toast unless one was on screen, and nothing at all when the operator
225
+ * already dismissed the entry, so a refresh never resurrects a declined offer.
226
+ */
227
+ export function refreshDiagnostic(msg) {
228
+ var source = msg.source || "";
229
+ var action = _actionOf(msg);
230
+ // Only the entry carrying the same action is replaced: the restart
231
+ // confirmation shares the source and must survive a refresh of the offer.
232
+ var held = diagnostics.some(function (entry) { return entry.source === source && _actionOf(entry) === action; });
233
+ if (!held) return;
234
+ var toastOnScreen = _toastsFor(source, action).length > 0;
235
+ retractDiagnostics(source, action);
236
+ addDiagnostic(msg, { toast: toastOnScreen });
237
+ }
238
+
239
+ function _actionOf(entry) {
240
+ return entry && entry.actionable && entry.actionable.action ? entry.actionable.action : "";
241
+ }
242
+
243
+ function _toastsFor(source, action) {
244
+ return Array.prototype.filter.call(
245
+ _getToastContainer().querySelectorAll('[data-diag-source="' + source + '"]'),
246
+ function (el) { return action === undefined || el.getAttribute("data-diag-action") === action; }
247
+ );
248
+ }
249
+
250
+ /**
251
+ * Withdraws every diagnostic from one source: the condition it reported no
252
+ * longer holds, so its action must not stay clickable. Used when the daemon
253
+ * adopts the installed build while an update offer is on screen. With `action`
254
+ * only the entries carrying that action are withdrawn.
255
+ */
256
+ export function retractDiagnostics(source, action) {
257
+ if (!source) return;
258
+ var keep = [];
259
+ var removed = [];
260
+ diagnostics.forEach(function (entry) {
261
+ if (entry.source !== source || (action !== undefined && _actionOf(entry) !== action)) { keep.push(entry); return; }
262
+ removed.push(entry);
263
+ if (panelListEl) {
264
+ var itemEl = panelListEl.querySelector('[data-diag-id="' + entry.id + '"]');
265
+ if (itemEl && itemEl.parentNode) itemEl.parentNode.removeChild(itemEl);
266
+ }
267
+ });
268
+ diagnostics = keep;
269
+ // A repeat of the same condition must show again, not be taken for a duplicate.
270
+ if (action === undefined) {
271
+ Object.keys(_recentDiagnosticKeys).forEach(function (key) {
272
+ if (key.indexOf(source + "|") === 0) delete _recentDiagnosticKeys[key];
273
+ });
274
+ } else {
275
+ removed.forEach(function (entry) { delete _recentDiagnosticKeys[_diagnosticKey(entry)]; });
276
+ }
277
+ _toastsFor(source, action).forEach(_removeDiagnosticToast);
278
+ if (diagnostics.length === 0) _restoreEmptyPlaceholder();
279
+ _updateBadge();
280
+ }
281
+
197
282
  // Re-export the pure formatter so callers that import from this module
198
283
  // can reach it without a second import. Tests should import from
199
284
  // diagnostic-format.js directly (no DOM deps there).
@@ -220,12 +305,34 @@ function _getToastContainer() {
220
305
  return toastContainerEl;
221
306
  }
222
307
 
308
+ // The toast's lower part: the offer detail when the diagnostic carries one,
309
+ // then a known actionable.action as a real button (with "Not now" for an
310
+ // offer), else the plain hint. Returns whether an action button was added.
311
+ function _appendToastActions(el, entry, onDecline) {
312
+ var detailEl = buildUpdateDetailEl(entry.buildUpdate);
313
+ if (detailEl) el.appendChild(detailEl);
314
+ var actionBtn = _buildActionableEl(entry, "toast-diagnostic-action-btn");
315
+ if (actionBtn) {
316
+ el.appendChild(actionBtn);
317
+ var declineBtn = _buildDeclineEl(entry, "toast-diagnostic-action-btn", onDecline);
318
+ if (declineBtn) el.appendChild(declineBtn);
319
+ return true;
320
+ }
321
+ var hintEl = document.createElement("div");
322
+ hintEl.className = "toast-diagnostic-hint";
323
+ hintEl.textContent = "See Diagnostics panel for details";
324
+ el.appendChild(hintEl);
325
+ return false;
326
+ }
327
+
223
328
  function _showDiagnosticToast(entry) {
224
329
  var el = document.createElement("div");
225
330
  // Use a dedicated class so diagnostics are visually distinct from error messages.
226
331
  el.className = "toast toast-diagnostic toast-diagnostic-" + entry.severity;
227
332
  el.setAttribute("role", "alert");
228
333
  el.setAttribute("aria-live", "assertive");
334
+ el.setAttribute("data-diag-source", entry.source);
335
+ el.setAttribute("data-diag-action", _actionOf(entry));
229
336
 
230
337
  var headerEl = document.createElement("div");
231
338
  headerEl.className = "toast-diagnostic-header";
@@ -248,22 +355,15 @@ function _showDiagnosticToast(entry) {
248
355
  headerEl.appendChild(dismissBtn);
249
356
 
250
357
  var msgEl = document.createElement("div");
251
- msgEl.className = "toast-diagnostic-msg";
358
+ msgEl.className = "toast-diagnostic-msg diagnostic-multiline";
252
359
  msgEl.textContent = entry.message;
253
360
 
254
361
  el.appendChild(headerEl);
255
362
  el.appendChild(msgEl);
256
-
257
- // lr-e85fec: known actionable.action -> real button; else the plain hint.
258
- var actionBtn = _buildActionableEl(entry, "toast-diagnostic-action-btn");
259
- if (actionBtn) {
260
- el.appendChild(actionBtn);
261
- } else {
262
- var hintEl = document.createElement("div");
263
- hintEl.className = "toast-diagnostic-hint";
264
- hintEl.textContent = "See Diagnostics panel for details";
265
- el.appendChild(hintEl);
266
- }
363
+ var hasAction = _appendToastActions(el, entry, function () {
364
+ clearTimeout(timer);
365
+ _removeDiagnosticToast(el);
366
+ });
267
367
 
268
368
  _getToastContainer().appendChild(el);
269
369
  refreshIcons();
@@ -273,8 +373,8 @@ function _showDiagnosticToast(entry) {
273
373
 
274
374
  // Auto-dismiss after 6s — EXCEPT when an action button is present: an
275
375
  // operator deciding whether to restart must not have the offer vanish out
276
- // from under them before they've read it (lr-e85fec).
277
- var timer = actionBtn ? null : setTimeout(function () { _removeDiagnosticToast(el); }, 6000);
376
+ // from under them before they've read it.
377
+ var timer = hasAction ? null : setTimeout(function () { _removeDiagnosticToast(el); }, 6000);
278
378
 
279
379
  // Manual dismiss.
280
380
  dismissBtn.addEventListener("click", function () {
@@ -360,11 +460,13 @@ function _appendEntry(entry) {
360
460
  meta.appendChild(dismissBtn);
361
461
 
362
462
  var msgEl = document.createElement("div");
363
- msgEl.className = "diagnostics-message";
463
+ msgEl.className = "diagnostics-message diagnostic-multiline";
364
464
  msgEl.textContent = entry.message;
365
465
 
366
466
  item.appendChild(meta);
367
467
  item.appendChild(msgEl);
468
+ var panelDetail = buildUpdateDetailEl(entry.buildUpdate);
469
+ if (panelDetail) item.appendChild(panelDetail);
368
470
 
369
471
  // Actionable hint: surface label when present. lr-e85fec: a known action
370
472
  // renders as a real button (_buildActionableEl), not just a hint icon — a
@@ -376,6 +478,10 @@ function _appendEntry(entry) {
376
478
  var panelBtn = _buildActionableEl(entry, "diagnostics-actionable-btn");
377
479
  if (panelBtn) {
378
480
  actionEl.appendChild(panelBtn);
481
+ var panelDecline = _buildDeclineEl(entry, "diagnostics-actionable-btn", function () {
482
+ dismissDiagnostic(entry.id);
483
+ });
484
+ if (panelDecline) actionEl.appendChild(panelDecline);
379
485
  } else {
380
486
  var fixIcon = document.createElement("span");
381
487
  fixIcon.className = "diagnostics-actionable-icon";
@@ -45,6 +45,18 @@ export function bannerActions(kind, meta) {
45
45
  return [];
46
46
  }
47
47
 
48
+ /**
49
+ * The sentence a permission banner shows above its buttons saying what Allow
50
+ * for session would grant, or "" when the ask offers no such button.
51
+ * @param {string} kind
52
+ * @param {object} [meta] - the notification's meta.
53
+ */
54
+ export function bannerScope(kind, meta) {
55
+ if (kind !== "permission" || !meta || typeof meta.grantScope !== "string") return "";
56
+ var offered = bannerActions(kind, meta).some(function (a) { return a.decision === "allow_always"; });
57
+ return offered ? meta.grantScope : "";
58
+ }
59
+
48
60
  /**
49
61
  * Wire a banner's decision buttons to answer its prompt.
50
62
  * @param {Element} banner
@@ -7,6 +7,10 @@
7
7
  // suppressAlwaysAllowRule no persistent "allow for session" choice;
8
8
  // defaultToNo the ask opens on its decline choice, so a stray
9
9
  // keystroke or tap cannot approve it.
10
+ // A call that cannot be granted narrowly (grantScope null: a file tool, which
11
+ // never produces a session grant, or a command too long to keep) offers no
12
+ // Allow for session either; the server does not store one (a file tool's answer
13
+ // is allowed once, any other is refused).
10
14
  // The server refuses an Allow-for-session answer to a suppressed ask whatever
11
15
  // a client sends (lib/prompt-kinds/permission.js); omitting the choice here is
12
16
  // the presentation of that rule, not its enforcement.
@@ -21,7 +25,8 @@
21
25
  */
22
26
  export function permissionChoices(hints) {
23
27
  var h = hints || {};
24
- var approve = h.suppressAlwaysAllowRule === true ? ["allow"] : ["allow", "allow_always"];
28
+ var noSession = h.suppressAlwaysAllowRule === true || h.grantScope === null;
29
+ var approve = noSession ? ["allow"] : ["allow", "allow_always"];
25
30
  return h.defaultToNo === true ? ["deny"].concat(approve) : approve.concat(["deny"]);
26
31
  }
27
32
 
@@ -46,6 +46,17 @@ function ruleNote(fields) {
46
46
  return note;
47
47
  }
48
48
 
49
+ // What the Allow for session button would grant, stated before the click. Not
50
+ // drawn when the ask offers no such button.
51
+ function scopeNote(fields) {
52
+ if (permissionChoices(fields).indexOf("allow_always") === -1) return null;
53
+ if (typeof fields.grantScope !== "string" || !fields.grantScope) return null;
54
+ var note = document.createElement("div");
55
+ note.className = "permission-scope";
56
+ note.textContent = fields.grantScope;
57
+ return note;
58
+ }
59
+
49
60
  function shortPath(p) {
50
61
  if (!p) return "";
51
62
  var parts = p.split("/");
@@ -139,6 +150,8 @@ function drawFormal(fields, requestId, host) {
139
150
  var rule = ruleNote(fields);
140
151
  if (rule) body.appendChild(rule);
141
152
  body.appendChild(detailsElement("permission-details", fields.toolInput));
153
+ var scope = scopeNote(fields);
154
+ if (scope) body.appendChild(scope);
142
155
 
143
156
  var actions = document.createElement("div");
144
157
  actions.className = "permission-actions";
@@ -182,6 +195,8 @@ function drawConversational(fields, requestId, host) {
182
195
  var rule = ruleNote(fields);
183
196
  if (rule) content.appendChild(rule);
184
197
  content.appendChild(detailsElement("perm-details", fields.toolInput));
198
+ var scope = scopeNote(fields);
199
+ if (scope) content.appendChild(scope);
185
200
 
186
201
  var actions = document.createElement("div");
187
202
  actions.className = "permission-actions";
@@ -0,0 +1,44 @@
1
+ // prompt-label.js - how a prompt says whose it is: its project, its session
2
+ // and, when a background agent raised it, that agent. The server builds the
3
+ // label (lib/prompt-label.js) and sends it on every prompt and its
4
+ // notification; the card and the banner both draw it from here so the two
5
+ // cannot disagree.
6
+ //
7
+ // Deliberately free of DOM globals and of imports beyond escape-html, so the
8
+ // banner and tests can load it without the rest of the frontend module graph.
9
+
10
+ import { escapeHtml } from './escape-html.js';
11
+
12
+ /**
13
+ * @param {?{project?: string, session?: string, agent?: string}} label
14
+ * @returns {{name: string, value: string}[]} the parts that are present, in order.
15
+ */
16
+ export function promptLabelParts(label) {
17
+ if (!label || typeof label !== "object") return [];
18
+ var parts = [];
19
+ if (typeof label.project === "string" && label.project) parts.push({ name: "Project", value: label.project });
20
+ if (typeof label.session === "string" && label.session) parts.push({ name: "Session", value: label.session });
21
+ if (typeof label.agent === "string" && label.agent) parts.push({ name: "Agent", value: label.agent });
22
+ return parts;
23
+ }
24
+
25
+ /** The label as one line of plain text; "" when there is none. */
26
+ export function promptLabelText(label) {
27
+ return promptLabelParts(label).map(function (p) { return p.name + ": " + p.value; }).join(" | ");
28
+ }
29
+
30
+ /** The label as an element for a card, or null when there is none. */
31
+ export function promptLabelElement(label) {
32
+ var text = promptLabelText(label);
33
+ if (!text) return null;
34
+ var el = document.createElement("div");
35
+ el.className = "prompt-label";
36
+ el.textContent = text;
37
+ return el;
38
+ }
39
+
40
+ /** The label as escaped HTML for a banner, or "" when there is none. */
41
+ export function promptLabelHtml(label) {
42
+ var text = promptLabelText(label);
43
+ return text ? '<div class="notif-banner-label">' + escapeHtml(text) + '</div>' : "";
44
+ }
@@ -16,6 +16,7 @@ import {
16
16
  } from './prompt-card.js';
17
17
  import { PROMPT_KINDS } from './prompt-kinds/index.js';
18
18
  import { ownValue } from './prompt-kinds/own-key.js';
19
+ import { promptLabelElement } from './prompt-label.js';
19
20
 
20
21
  /**
21
22
  * @param {object} host
@@ -63,6 +64,14 @@ export function createPromptController(host) {
63
64
  });
64
65
  var container = renderer.draw(n.fields, n.requestId, rendererHost);
65
66
  container.dataset.promptKind = n.kind;
67
+ // Whose prompt this is, above everything else on the card. The kinds lay
68
+ // themselves out differently (a body block, a flex row with an avatar), so
69
+ // it goes in the first block that holds the card's text.
70
+ var label = promptLabelElement(n.fields && n.fields.label);
71
+ if (label) {
72
+ var holder = container.querySelector(".permission-body, .dm-bubble-content") || container;
73
+ holder.insertBefore(label, holder.firstChild);
74
+ }
66
75
  cards[n.requestId] = { container: container, kind: n.kind, fields: n.fields, host: rendererHost };
67
76
  host.place(container, renderer.focusSelector || null);
68
77
  return cards[n.requestId];
@@ -0,0 +1,131 @@
1
+ // session-grants.js - the operator's list of what a session may do without
2
+ // asking (its Allow for session grants), with a Revoke for each. The server
3
+ // owns the grants (lib/prompt-registry.js); this only asks for the list,
4
+ // draws what it is told and sends a revoke. A revoke takes effect on the
5
+ // session's next tool call, and the server answers with the list as it now is.
6
+ //
7
+ // Free of the rest of the frontend module graph apart from the connection, so
8
+ // a test can drive it with a hand-built DOM.
9
+
10
+ import { getWs } from './ws-ref.js';
11
+
12
+ var MODAL_ID = "session-grants-modal";
13
+
14
+ function send(msg) {
15
+ var ws = getWs();
16
+ if (!ws || ws.readyState !== 1) return false;
17
+ ws.send(JSON.stringify(msg));
18
+ return true;
19
+ }
20
+
21
+ function modal() {
22
+ return document.getElementById(MODAL_ID);
23
+ }
24
+
25
+ function close() {
26
+ var m = modal();
27
+ if (m && m.parentNode) m.parentNode.removeChild(m);
28
+ }
29
+
30
+ /**
31
+ * Draw a grant list into list; exported for tests.
32
+ * @param {Element} list
33
+ * @param {{key: string, text: string, wholeTool: boolean}[]} grants
34
+ * @param {number} sessionId
35
+ * @param {function(object): boolean} sendMsg
36
+ */
37
+ export function renderGrantList(list, grants, sessionId, sendMsg) {
38
+ list.textContent = "";
39
+ var error = document.createElement("div");
40
+ error.className = "session-grants-error";
41
+ list.appendChild(error);
42
+ if (!grants.length) {
43
+ var empty = document.createElement("div");
44
+ empty.className = "session-grants-empty";
45
+ empty.textContent = "This session has no Allow for session grants. Every tool call that needs approval asks.";
46
+ list.appendChild(empty);
47
+ return;
48
+ }
49
+ grants.forEach(function (g) {
50
+ var row = document.createElement("div");
51
+ row.className = "session-grants-row" + (g.wholeTool ? " session-grants-whole" : "");
52
+ row.dataset.grantKey = g.key;
53
+ var text = document.createElement("span");
54
+ text.className = "session-grants-text";
55
+ text.textContent = g.text;
56
+ var revoke = document.createElement("button");
57
+ revoke.className = "session-grants-revoke";
58
+ revoke.textContent = "Revoke";
59
+ // Disabled only while the request is in flight. The row goes when the
60
+ // server's list arrives without the grant; a failed send or a server
61
+ // refusal re-enables the button so the revoke can be retried.
62
+ revoke.addEventListener("click", function () {
63
+ revoke.disabled = true;
64
+ error.textContent = "";
65
+ var sent = sendMsg({ type: "revoke_session_grant", sessionId: sessionId, key: g.key });
66
+ if (sent === false) {
67
+ revoke.disabled = false;
68
+ error.textContent = "Could not revoke: not connected. Try again.";
69
+ }
70
+ });
71
+ row.appendChild(text);
72
+ row.appendChild(revoke);
73
+ list.appendChild(row);
74
+ });
75
+ }
76
+
77
+ /** Open the grants list for a session. */
78
+ export function openSessionGrants(sessionId) {
79
+ close();
80
+ var m = document.createElement("div");
81
+ m.id = MODAL_ID;
82
+ m.dataset.sessionId = String(sessionId);
83
+ var backdrop = document.createElement("div");
84
+ backdrop.className = "confirm-backdrop";
85
+ backdrop.addEventListener("click", close);
86
+ var dialog = document.createElement("div");
87
+ dialog.className = "confirm-dialog session-grants-dialog";
88
+ var title = document.createElement("div");
89
+ title.className = "session-grants-title";
90
+ title.textContent = "Allow for session grants";
91
+ var list = document.createElement("div");
92
+ list.className = "session-grants-list";
93
+ list.textContent = "Loading...";
94
+ var done = document.createElement("button");
95
+ done.className = "confirm-btn confirm-cancel";
96
+ done.textContent = "Close";
97
+ done.addEventListener("click", close);
98
+ dialog.appendChild(title);
99
+ dialog.appendChild(list);
100
+ dialog.appendChild(done);
101
+ m.appendChild(backdrop);
102
+ m.appendChild(dialog);
103
+ document.body.appendChild(m);
104
+ send({ type: "list_session_grants", sessionId: sessionId });
105
+ }
106
+
107
+ /**
108
+ * A server refusal: keep the rows, show why, and let each Revoke be tried
109
+ * again. Exported for tests.
110
+ * @param {Element} list
111
+ * @param {string} message
112
+ */
113
+ export function showGrantError(list, message) {
114
+ var buttons = list.querySelectorAll(".session-grants-revoke");
115
+ for (var i = 0; i < buttons.length; i++) buttons[i].disabled = false;
116
+ var error = list.querySelector(".session-grants-error");
117
+ if (error) error.textContent = message;
118
+ }
119
+
120
+ /** The server's session_grants message: redraw the list if it is the one open. */
121
+ export function handleSessionGrants(msg) {
122
+ var m = modal();
123
+ if (!m || m.dataset.sessionId !== String(msg.sessionId)) return;
124
+ var list = m.querySelector(".session-grants-list");
125
+ if (!list) return;
126
+ if (typeof msg.error === "string" && msg.error) {
127
+ showGrantError(list, "Could not revoke: " + msg.error);
128
+ return;
129
+ }
130
+ renderGrantList(list, Array.isArray(msg.grants) ? msg.grants : [], msg.sessionId, send);
131
+ }
@@ -8,6 +8,7 @@ import { openSearch as openSessionSearch } from './session-search.js';
8
8
  import { store } from './store.js';
9
9
  import { capabilityGate } from './vendor-registry.js';
10
10
  import { getWs } from './ws-ref.js';
11
+ import { openSessionGrants } from './session-grants.js';
11
12
  import { getSessionListEl } from './dom-refs.js';
12
13
  import { dismissOverlayPanels, closeSidebar, updatePageTitle, spawnDustParticles } from './sidebar.js';
13
14
  import { showConfirm } from './app-misc.js';
@@ -677,6 +678,16 @@ function showSessionCtxMenu(anchorBtn, sessionId, title, cliSid, sessionData) {
677
678
  });
678
679
  menu.appendChild(renameItem);
679
680
 
681
+ var grantsItem = document.createElement("button");
682
+ grantsItem.className = "session-ctx-item";
683
+ grantsItem.innerHTML = iconHtml("shield") + " <span>Permission grants</span>";
684
+ grantsItem.addEventListener("click", function (e) {
685
+ e.stopPropagation();
686
+ closeSessionCtxMenu();
687
+ openSessionGrants(sessionId);
688
+ });
689
+ menu.appendChild(grantsItem);
690
+
680
691
  // Session visibility toggle (only the session owner can change)
681
692
  if (sessionData && sessionData.ownerId && sessionData.ownerId === store.get('myUserId')) {
682
693
  var currentVis = (sessionData && sessionData.sessionVisibility) || "shared";
@@ -7,6 +7,7 @@ import { getChatLayout } from './theme.js';
7
7
  import { store } from './store.js';
8
8
  import { VENDOR_NAMES } from './app-rendering.js';
9
9
  import { createPromptController } from './prompts.js';
10
+ import { isAgentDispatchTool } from './agent-dispatch-tool.js';
10
11
 
11
12
  var ctx;
12
13
 
@@ -92,10 +93,21 @@ function toolGroupSummary(group) {
92
93
  counts[names[i]] = (counts[names[i]] || 0) + 1;
93
94
  }
94
95
  var uniqueNames = Object.keys(counts);
96
+ // A group mixing "Task" and "Agent" dispatches is still one kind of tool.
97
+ var dispatchKinds = uniqueNames.filter(isAgentDispatchTool);
98
+ if (dispatchKinds.length > 1 && dispatchKinds.length === uniqueNames.length) {
99
+ var dispatchTotal = 0;
100
+ dispatchKinds.forEach(function (k) { dispatchTotal += counts[k]; });
101
+ uniqueNames = ["Task"];
102
+ counts = { Task: dispatchTotal };
103
+ }
95
104
 
96
105
  if (uniqueNames.length === 1) {
97
106
  var name = uniqueNames[0];
107
+ // Read the count under the name it was tallied with, then pick the label
108
+ // family: an Agent-only group has no "Task" entry in counts.
98
109
  var n = counts[name];
110
+ if (isAgentDispatchTool(name)) name = "Task";
99
111
  if (allDone) {
100
112
  switch (name) {
101
113
  case "Read": return "Read " + n + " file" + (n > 1 ? "s" : "");
@@ -169,6 +181,7 @@ function isPlanFile(filePath) {
169
181
 
170
182
  export function toolSummary(name, input) {
171
183
  if (!input || typeof input !== "object") return "";
184
+ if (isAgentDispatchTool(name)) return input.description || "";
172
185
  switch (name) {
173
186
  case "Read": return shortPath(input.file_path);
174
187
  case "Edit": return shortPath(input.file_path);
@@ -178,7 +191,6 @@ export function toolSummary(name, input) {
178
191
  case "Grep": return (input.pattern || "") + (input.path ? " in " + shortPath(input.path) : "");
179
192
  case "WebFetch": return input.url || "";
180
193
  case "WebSearch": return input.query || "";
181
- case "Task": return input.description || "";
182
194
  case "EnterPlanMode": return "";
183
195
  case "ExitPlanMode": return "";
184
196
  default: return JSON.stringify(input).substring(0, 60);
@@ -194,7 +206,7 @@ export function toolActivityText(name, input) {
194
206
  if (name === "Glob" && input && input.pattern) return "Finding " + input.pattern;
195
207
  if (name === "WebSearch" && input && input.query) return "Searching: " + input.query;
196
208
  if (name === "WebFetch") return "Fetching URL...";
197
- if (name === "Task" && input && input.description) return input.description;
209
+ if (isAgentDispatchTool(name) && input && input.description) return input.description;
198
210
  if (name === "EnterPlanMode") return "Entering plan mode...";
199
211
  if (name === "ExitPlanMode") return "Finalizing the plan...";
200
212
  return "Running " + name + "...";
@@ -32,10 +32,10 @@ export function renderVendorPicker(container, rows, actions) {
32
32
  label.className = "vendor-toggle-label";
33
33
  label.textContent = row.displayName;
34
34
  btn.appendChild(label);
35
- if (row.checkFailed) {
35
+ if (row.checkFailed || row.version) {
36
36
  var note = document.createElement("span");
37
37
  note.className = "vendor-toggle-note";
38
- note.textContent = "Could not check";
38
+ note.textContent = row.checkFailed ? "Could not check" : row.version;
39
39
  btn.appendChild(note);
40
40
  }
41
41
  btn.addEventListener("click", function () { actions.onSelect(row.id); });
@@ -83,7 +83,9 @@ export function capabilityGate(key) {
83
83
  var value = caps[key];
84
84
  var enabled = Array.isArray(value) ? value.length > 0 : value === true;
85
85
  var reasons = store.get('capabilityReasons') || {};
86
- return { enabled: enabled, reason: enabled ? "" : (reasons[key] || "This agent does not support this.") };
86
+ var entry = vendorEntry(store.get('currentVendor') || defaultVendorId());
87
+ var own = entry && entry.capabilityReasons ? entry.capabilityReasons[key] : "";
88
+ return { enabled: enabled, reason: enabled ? "" : (own || reasons[key] || "This agent does not support this.") };
87
89
  }
88
90
 
89
91
  function escapeAttr(text) {
@@ -112,14 +114,20 @@ export function loginCommandFor(vendorId) {
112
114
  * The picker's rows, one per registered agent.
113
115
  * An agent whose install lookup failed is not reported as missing: its row says
114
116
  * the check could not be made, with the failure class.
115
- * @returns {Array<{id: string, displayName: string, icon: string, installed: boolean, checkFailed: boolean, active: boolean, title: string}>}
117
+ * An agent that is not usable says why when its probe knows (not installed, too
118
+ * old, an override that points nowhere); one that is usable says which binary
119
+ * and version will run.
120
+ * @returns {Array<{id: string, displayName: string, icon: string, installed: boolean, checkFailed: boolean, active: boolean, version: string, title: string}>}
116
121
  */
117
122
  export function pickerRows(vendors, current) {
118
123
  return (vendors || []).map(function (v) {
119
124
  var checkFailed = !v.installed && !!v.probeFailure;
125
+ var detail = v.installDetail || {};
120
126
  var title = v.displayName;
121
127
  if (checkFailed) title = v.displayName + ". Could not check: " + v.probeFailure + ". Use Re-check to try again.";
128
+ else if (!v.installed && detail.reason) title = v.displayName + ". " + detail.reason;
122
129
  else if (!v.installed) title = v.displayName + " is not installed. " + v.installHint;
130
+ else if (detail.version) title = v.displayName + " " + detail.version + (detail.path ? " (" + detail.path + ")" : "");
123
131
  return {
124
132
  id: v.id,
125
133
  displayName: v.displayName,
@@ -127,6 +135,7 @@ export function pickerRows(vendors, current) {
127
135
  installed: !!v.installed,
128
136
  checkFailed: checkFailed,
129
137
  active: v.id === current,
138
+ version: v.installed && detail.version ? detail.version : "",
130
139
  title: title,
131
140
  };
132
141
  });
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // Settings hold two environment texts: shared (every project, administrators
4
4
  // only) and per project. Every agent-runtime start (a Claude query in process
5
- // or in a worker, a Codex app-server, title generation, a model-list warmup)
5
+ // or in a worker, a Codex app-server, a model-list warmup)
6
6
  // takes its environment from here: the runtime's own environment first, then
7
7
  // the shared text, then the project text.
8
8
  //