@clagentic/console 1.10.0-beta.2 → 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 (42) hide show
  1. package/lib/activity-clock.js +23 -0
  2. package/lib/build-sha.json +2 -2
  3. package/lib/cli-transcript-title.js +131 -0
  4. package/lib/debug-log.js +17 -0
  5. package/lib/exit-flush.js +44 -0
  6. package/lib/grant-keys.js +179 -0
  7. package/lib/log-field.js +34 -0
  8. package/lib/project-http.js +2 -0
  9. package/lib/project-notifications.js +4 -0
  10. package/lib/project-prompt-responses.js +2 -1
  11. package/lib/project-session-grants.js +73 -0
  12. package/lib/project-sessions.js +12 -0
  13. package/lib/project-user-message.js +6 -5
  14. package/lib/project.js +2 -0
  15. package/lib/prompt-kinds/permission.js +18 -0
  16. package/lib/prompt-label.js +60 -0
  17. package/lib/prompt-registry.js +116 -13
  18. package/lib/prompt-source.js +65 -0
  19. package/lib/public/css/notifications-center.css +15 -0
  20. package/lib/public/css/overlays.css +18 -0
  21. package/lib/public/css/rewind.css +8 -0
  22. package/lib/public/modules/app-messages.js +3 -0
  23. package/lib/public/modules/app-notifications.js +9 -1
  24. package/lib/public/modules/prompt-banner.js +12 -0
  25. package/lib/public/modules/prompt-kinds/permission-choices.js +6 -1
  26. package/lib/public/modules/prompt-kinds/permission.js +15 -0
  27. package/lib/public/modules/prompt-label.js +44 -0
  28. package/lib/public/modules/prompts.js +9 -0
  29. package/lib/public/modules/session-grants.js +131 -0
  30. package/lib/public/modules/sidebar-sessions.js +11 -0
  31. package/lib/runtime-env.js +1 -1
  32. package/lib/sdk-bridge.js +53 -101
  33. package/lib/sdk-message-processor.js +14 -67
  34. package/lib/session-ai-title.js +80 -0
  35. package/lib/session-input.js +32 -2
  36. package/lib/sessions.js +14 -18
  37. package/lib/utils.js +9 -47
  38. package/lib/ws-schema.js +6 -3
  39. package/lib/yoke/adapters/claude.js +0 -57
  40. package/lib/yoke/adapters/codex.js +4 -75
  41. package/lib/yoke/interface.js +3 -7
  42. package/package.json +1 -1
@@ -15,6 +15,7 @@
15
15
  // An ask without hints (Codex approvals, older CLIs) is unchanged.
16
16
 
17
17
  var toolCall = require("./tool-call");
18
+ var grantKeys = require("../grant-keys");
18
19
  var { hasOwnKey } = require("./codecs");
19
20
 
20
21
  var DECISIONS = { allow: true, allow_always: true, deny: true };
@@ -54,12 +55,17 @@ module.exports = {
54
55
  store: "pendingPermissions",
55
56
  journal: true,
56
57
 
58
+ // grantScope is what Allow for Session would grant for this very call, as a
59
+ // sentence, or null when the call cannot be granted for the session. It is
60
+ // computed once, here, so the card, the banner and the check that settles
61
+ // the answer all read the same scope.
57
62
  fields: function (req) {
58
63
  return Object.assign({
59
64
  toolName: req.toolName,
60
65
  toolInput: req.toolInput,
61
66
  decisionReason: req.decisionReason || "",
62
67
  vendor: req.vendor,
68
+ grantScope: grantKeys.grantScopeText(req.toolName, req.toolInput),
63
69
  }, hintsOf(req));
64
70
  },
65
71
 
@@ -69,6 +75,7 @@ module.exports = {
69
75
  toolInput: record.toolInput,
70
76
  decisionReason: record.decisionReason || "",
71
77
  vendor: record.vendor,
78
+ grantScope: record.grantScope === undefined ? null : record.grantScope,
72
79
  }, hintsOf(record));
73
80
  },
74
81
 
@@ -78,6 +85,7 @@ module.exports = {
78
85
  return {
79
86
  suppressAlwaysAllowRule: hints.suppressAlwaysAllowRule,
80
87
  defaultToNo: hints.defaultToNo,
88
+ grantScope: record.grantScope === undefined ? null : record.grantScope,
81
89
  };
82
90
  },
83
91
 
@@ -91,6 +99,16 @@ module.exports = {
91
99
  if (decision === "allow_always" && record && record.suppressAlwaysAllowRule === true) {
92
100
  return { invalid: "always_allow_not_offered" };
93
101
  }
102
+ // A file tool never produces a session grant. An old client may still send
103
+ // Allow for Session for one: it is answered as this call only, nothing is
104
+ // stored.
105
+ if (decision === "allow_always" && record && grantKeys.isFileTool(record.toolName)) {
106
+ return { decision: "allow" };
107
+ }
108
+ // A call with nothing narrow enough to grant is never granted wider.
109
+ if (decision === "allow_always" && record && record.grantScope === null) {
110
+ return { invalid: "grant_scope_unavailable" };
111
+ }
94
112
  return { decision: decision };
95
113
  },
96
114
 
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ // Who a prompt is from: the project, the session and, when a background agent
4
+ // raised it, that agent. Every surface that shows a prompt (card, banner, push
5
+ // notification) shows these, because a banner reaches every connected client
6
+ // whatever project it is viewing, and a tool request alone does not say whose
7
+ // it is.
8
+
9
+ var FIELD_MAX = 80;
10
+ var UNTITLED = "(untitled session)";
11
+
12
+ // Titles and agent descriptions are authored outside the console (a session
13
+ // title is typed or model-generated, a Task description comes from the model),
14
+ // so each is reduced to one bounded line.
15
+ function oneLine(raw) {
16
+ if (typeof raw !== "string") return "";
17
+ var one = raw.replace(/\s+/g, " ").trim();
18
+ return one.length > FIELD_MAX ? one.slice(0, FIELD_MAX - 3) + "..." : one;
19
+ }
20
+
21
+ /**
22
+ * @param {{project: ?string, sessionTitle: ?string, agent: ?string}} parts
23
+ * @returns {{project: string, session: string, agent: string}} agent is ""
24
+ * when the prompt belongs to the session itself.
25
+ */
26
+ function promptLabel(parts) {
27
+ var p = parts || {};
28
+ return {
29
+ project: oneLine(p.project),
30
+ session: oneLine(p.sessionTitle) || UNTITLED,
31
+ agent: oneLine(p.agent),
32
+ };
33
+ }
34
+
35
+ /**
36
+ * The label as one line for a push notification.
37
+ * @param {?{project: string, session: string, agent: string}} label
38
+ * @returns {string} "" for no label.
39
+ */
40
+ function formatPromptLabel(label) {
41
+ if (!label) return "";
42
+ var out = [];
43
+ if (label.project) out.push("Project: " + label.project);
44
+ if (label.session) out.push("Session: " + label.session);
45
+ if (label.agent) out.push("Agent: " + label.agent);
46
+ return out.join(" | ");
47
+ }
48
+
49
+ /**
50
+ * A push body that says whose prompt it is on its first line.
51
+ * @param {?object} label
52
+ * @param {string} body
53
+ */
54
+ function withPromptLabel(label, body) {
55
+ var line = formatPromptLabel(label);
56
+ if (!line) return body || "";
57
+ return body ? line + "\n" + body : line;
58
+ }
59
+
60
+ module.exports = { promptLabel: promptLabel, formatPromptLabel: formatPromptLabel, withPromptLabel: withPromptLabel };
@@ -45,6 +45,11 @@ var crypto = require("crypto");
45
45
  var utils = require("./utils");
46
46
  var promptKinds = require("./prompt-kinds");
47
47
  var codecs = require("./prompt-kinds/codecs");
48
+ var grantKeys = require("./grant-keys");
49
+ var sessionReclaim = require("./session-reclaim");
50
+ var { promptLabel } = require("./prompt-label");
51
+ var promptSource = require("./prompt-source");
52
+ var { logField } = require("./log-field");
48
53
  var { ownValue, putOwn, hasOwnKey } = codecs;
49
54
 
50
55
  var KINDS = promptKinds.KINDS;
@@ -117,6 +122,11 @@ function openedBy(item) {
117
122
  * @param {function(object)} deps.saveSessionFile - durable session meta write.
118
123
  * @param {function(): ?object} [deps.getNotificationsModule]
119
124
  * @param {function()} [deps.onProcessingChanged] - cross-project badge refresh.
125
+ * @param {function(): string} [deps.getProjectName] - the project's display
126
+ * name, read at each prompt so a rename shows on the next one.
127
+ * @param {function(): string} [deps.getProjectSlug] - the project's slug, which
128
+ * the lifecycle log lines carry because console session ids repeat across
129
+ * projects.
120
130
  */
121
131
  function createPromptRegistry(deps) {
122
132
  var index = deps.index;
@@ -125,6 +135,8 @@ function createPromptRegistry(deps) {
125
135
  var saveSessionFile = deps.saveSessionFile;
126
136
  var getNotificationsModule = deps.getNotificationsModule || function () { return null; };
127
137
  var onProcessingChanged = deps.onProcessingChanged || function () {};
138
+ var getProjectName = deps.getProjectName || function () { return ""; };
139
+ var getProjectSlug = deps.getProjectSlug || function () { return ""; };
128
140
 
129
141
  // Project-scope prompts (no session): requestId -> record.
130
142
  var projectPrompts = Object.create(null);
@@ -222,7 +234,36 @@ function createPromptRegistry(deps) {
222
234
  pruneToolOwners(session);
223
235
  }
224
236
 
225
- function settle(session, requestId, entry, value, event) {
237
+ // One line each when an operator prompt opens and when it settles, so the
238
+ // journal shows that a prompt was pending, for whom, and how it ended. Only
239
+ // identifiers and the outcome: never the tool input, the question, the
240
+ // answer or any prompt text.
241
+ function lifecycleFields(session, requestId, record, kind) {
242
+ var taskId = session ? ownerTaskOf(session, record) : null;
243
+ return "project=" + logField(getProjectSlug())
244
+ + " session=" + logField(session && session.localId)
245
+ + " request=" + logField(requestId, 80)
246
+ + " kind=" + logField(kind.name)
247
+ + " tool=" + logField(record.toolName)
248
+ + " agent=" + (taskId ? "task:" + logField(taskId, 80) : "none");
249
+ }
250
+
251
+ function logOpened(session, requestId, record, kind) {
252
+ if (!kind.journal) return;
253
+ console.log("[prompt-registry] prompt opened: " + lifecycleFields(session, requestId, record, kind));
254
+ }
255
+
256
+ // info: { status: "resolved"|"cancelled", source, reason?, decision?, granted? }
257
+ function logSettled(session, requestId, entry, info) {
258
+ if (!entry.kind.journal) return;
259
+ var line = "[prompt-registry] prompt " + info.status + ": " + lifecycleFields(session, requestId, entry.record, entry.kind);
260
+ if (info.decision) line += " decision=" + logField(info.decision);
261
+ if (info.status === "resolved") line += " grant=" + (info.granted ? "stored" : "none");
262
+ if (info.reason) line += " reason=" + logField(info.reason);
263
+ console.log(line + " " + promptSource.describe(info.source));
264
+ }
265
+
266
+ function settle(session, requestId, entry, value, event, info) {
226
267
  var map = session ? session[entry.store] : projectPrompts;
227
268
  if (!map || ownValue(map, requestId) !== entry.record) return false;
228
269
  delete map[requestId];
@@ -233,6 +274,7 @@ function createPromptRegistry(deps) {
233
274
  dismissNotification(requestId);
234
275
  if (event) sendAndRecord(session, event);
235
276
  onProcessingChanged();
277
+ if (info) logSettled(session, requestId, entry, info);
236
278
  }
237
279
  entry.record.resolve(value);
238
280
  if (session) {
@@ -248,7 +290,11 @@ function createPromptRegistry(deps) {
248
290
  var event = (entry.kind.journal && !(opts && opts.record === false))
249
291
  ? { type: "prompt_cancel", requestId: requestId, kind: entry.kind.name, reason: reason }
250
292
  : null;
251
- return settle(session, requestId, entry, entry.kind.cancelled(reason), event);
293
+ return settle(session, requestId, entry, entry.kind.cancelled(reason), event, {
294
+ status: "cancelled",
295
+ reason: reason,
296
+ source: (opts && opts.source) || promptSource.fromCancel(reason),
297
+ });
252
298
  }
253
299
 
254
300
  function cancelWhere(session, reason, predicate, opts) {
@@ -311,6 +357,7 @@ function createPromptRegistry(deps) {
311
357
  var owner = scoped ? session : null;
312
358
 
313
359
  if (scoped) {
360
+ record.label = labelFor(session, record.toolUseId);
314
361
  record.query = session.queryInstance || null;
315
362
  putOwn(sessionMap(session, kind.store), requestId, record);
316
363
  putOwn(index, requestId, session.localId);
@@ -323,8 +370,9 @@ function createPromptRegistry(deps) {
323
370
  requestId: requestId,
324
371
  kind: kind.name,
325
372
  toolUseId: record.toolUseId,
326
- }, kind.requestFields(record)));
373
+ }, labelFields(record), kind.requestFields(record)));
327
374
  onProcessingChanged();
375
+ logOpened(owner, requestId, record, kind);
328
376
  }
329
377
 
330
378
  var cleanups = [];
@@ -337,7 +385,9 @@ function createPromptRegistry(deps) {
337
385
  }
338
386
  var timeoutMs = opts.timeoutMs != null ? opts.timeoutMs : kind.defaultTimeoutMs;
339
387
  if (timeoutMs) {
340
- var timer = setTimeout(function () { cancelEntry(owner, requestId, entry, "expired"); }, timeoutMs);
388
+ var timer = setTimeout(function () {
389
+ cancelEntry(owner, requestId, entry, "expired", { source: promptSource.fromTimeout() });
390
+ }, timeoutMs);
341
391
  cleanups.push(function () { clearTimeout(timer); });
342
392
  }
343
393
  if (cleanups.length) {
@@ -348,10 +398,10 @@ function createPromptRegistry(deps) {
348
398
  var nm = getNotificationsModule();
349
399
  if (nm && typeof nm.notify === "function") {
350
400
  var kindFields = typeof kind.notificationFields === "function" ? kind.notificationFields(record) : {};
351
- nm.notify("permission_request", Object.assign({}, opts.notification, kindFields, { requestId: requestId, kind: kind.name }));
401
+ nm.notify("permission_request", Object.assign({}, opts.notification, kindFields, labelFields(record), { requestId: requestId, kind: kind.name }));
352
402
  }
353
403
  }
354
- return { requestId: requestId, answer: answer, pending: true };
404
+ return { requestId: requestId, answer: answer, pending: true, label: record.label || null };
355
405
  }
356
406
 
357
407
  // The pending entry for requestId (its live record and kind adapter), or
@@ -413,6 +463,9 @@ function createPromptRegistry(deps) {
413
463
  * @param {string} [opts.denyMessage] - override for a plain deny.
414
464
  * @param {?object} [opts.responder] - the connection that answered, if
415
465
  * any; handed to the resolution effects.
466
+ * @param {?object} [opts.source] - who answered (lib/prompt-source.js); it is
467
+ * logged and recorded on the prompt_resolved event. A caller that names none
468
+ * is logged as unspecified and its event carries no source.
416
469
  */
417
470
  function respond(requestId, msg, opts) {
418
471
  opts = opts || {};
@@ -427,12 +480,20 @@ function createPromptRegistry(deps) {
427
480
  if (response.invalid) {
428
481
  return { status: "invalid", reason: response.invalid, pending: kind.journal ? pendingMessage(requestId, found) : null };
429
482
  }
430
- if (kind.grantsSession(response)) grant(found.session, found.record.toolName, found.record.toolInput);
483
+ var granted = kind.grantsSession(response) ? grant(found.session, found.record.toolName, found.record.toolInput) : false;
431
484
  var event = kind.journal
432
485
  ? Object.assign({ type: "prompt_resolved", requestId: requestId, kind: kind.name }, kind.resolvedFields(response, found.record))
433
486
  : null;
487
+ if (event && opts.source) event.source = opts.source;
434
488
  var prompt = publicView(requestId, found);
435
- settle(found.session, requestId, found, kind.outcome(found.record, response, opts), event);
489
+ // The decision word or action only; an answer's content stays out of the log.
490
+ var decision = event && (typeof event.decision === "string" ? event.decision : (typeof event.action === "string" ? event.action : null));
491
+ settle(found.session, requestId, found, kind.outcome(found.record, response, opts), event, {
492
+ status: "resolved",
493
+ decision: decision,
494
+ granted: granted,
495
+ source: opts.source || null,
496
+ });
436
497
  var outcome = { status: "resolved", session: found.session, prompt: prompt, kind: kind.name, response: response };
437
498
  if (resolutionEffects) resolutionEffects(outcome, opts.responder || null);
438
499
  return outcome;
@@ -544,16 +605,55 @@ function createPromptRegistry(deps) {
544
605
  return out;
545
606
  }
546
607
 
608
+ // Who the prompt is from; null for a prompt with no session.
609
+ function labelFor(session, toolUseId) {
610
+ if (!session) return null;
611
+ var agent = sessionReclaim.ownerLabelOfTool(session, { ownerTaskOfTool: ownerTaskOfTool }, toolUseId);
612
+ return promptLabel({ project: getProjectName(), sessionTitle: session.title, agent: agent });
613
+ }
614
+
615
+ function labelFields(record) {
616
+ return record && record.label ? { label: record.label } : {};
617
+ }
618
+
547
619
  function isGranted(session, toolName, input) {
548
- return ownValue(session.allowedTools, utils.permissionGrantKey(toolName, input)) === true;
620
+ return grantKeys.isGranted(session.allowedTools, toolName, input);
549
621
  }
550
622
 
551
- // Flushed immediately so the grant survives a daemon restart or a resume
552
- // that rebuilds the session from disk.
623
+ // Grants only what the call asked for (lib/grant-keys.js). Flushed
624
+ // immediately so the grant survives a daemon restart or a resume that
625
+ // rebuilds the session from disk. Returns whether a grant was stored: a call
626
+ // with no narrow key, or a grant map with no room left in the persisted
627
+ // record, is allowed this once and nothing wider.
553
628
  function grant(session, toolName, input) {
629
+ var key = utils.permissionGrantKey(toolName, input);
630
+ if (key === null) return false;
554
631
  if (!session.allowedTools) session.allowedTools = Object.create(null);
555
- putOwn(session.allowedTools, utils.permissionGrantKey(toolName, input), true);
632
+ if (!grantKeys.fitsBudget(session.allowedTools, key)) {
633
+ console.warn("[prompt-registry] session grant not stored, the record has no room: " + key.slice(0, 40));
634
+ return false;
635
+ }
636
+ putOwn(session.allowedTools, key, true);
556
637
  saveSessionFile(session);
638
+ return true;
639
+ }
640
+
641
+ /** The session's grants, each described for the operator. */
642
+ function listGrants(session) {
643
+ var map = session && session.allowedTools;
644
+ if (!map) return [];
645
+ return Object.keys(map).filter(function (k) { return grantKeys.isGrantValue(k, map[k]); }).sort().map(grantKeys.describeGrantKey);
646
+ }
647
+
648
+ /**
649
+ * Take one grant away; the next call it covered prompts. Persisted at once.
650
+ * @returns {boolean} whether the session held it.
651
+ */
652
+ function revokeGrant(session, key) {
653
+ if (!session || typeof key !== "string" || !grantKeys.isGrantValue(key, ownValue(session.allowedTools, key))) return false;
654
+ delete session.allowedTools[key];
655
+ saveSessionFile(session);
656
+ return true;
557
657
  }
558
658
 
559
659
  // The wire message re-presenting one pending prompt.
@@ -563,7 +663,7 @@ function createPromptRegistry(deps) {
563
663
  requestId: requestId,
564
664
  kind: entry.kind.name,
565
665
  toolUseId: entry.record.toolUseId,
566
- }, entry.kind.requestFields(entry.record));
666
+ }, labelFields(entry.record), entry.kind.requestFields(entry.record));
567
667
  }
568
668
 
569
669
  /** Wire messages re-presenting every pending prompt of a session. */
@@ -637,8 +737,11 @@ function createPromptRegistry(deps) {
637
737
  isTaskTracked: isTaskTracked,
638
738
  taskOwnsPending: taskOwnsPending,
639
739
  trackedTaskIds: trackedTaskIds,
740
+ labelFor: labelFor,
640
741
  isGranted: isGranted,
641
742
  grant: grant,
743
+ listGrants: listGrants,
744
+ revokeGrant: revokeGrant,
642
745
  pendingMessages: pendingMessages,
643
746
  pendingCount: pendingCount,
644
747
  replayAnnotator: replayAnnotator,
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ // Who or what settled a prompt. The prompt registry (lib/prompt-registry.js)
4
+ // logs a source for every prompt it settles and records the one for an answer
5
+ // in the session history (the prompt_resolved event), so "who allowed this"
6
+ // can be answered after the fact.
7
+ //
8
+ // { kind: "ws", clientId, user } an answer from a browser connection
9
+ // { kind: "push", action, user } an answer from a push notification
10
+ // { kind: "timeout" } the prompt's own timer ran out
11
+ // { kind: "cancel", reason } the scope that owned the prompt ended
12
+ //
13
+ // clientId is a per-connection label made here, not a credential; user is the
14
+ // authenticated user's id, or null in single-user mode. Prompt content never
15
+ // appears in a source.
16
+
17
+ var crypto = require("crypto");
18
+ var { logField } = require("./log-field");
19
+
20
+ function clientIdOf(ws) {
21
+ if (!ws) return null;
22
+ if (!ws._clagenticClientId) ws._clagenticClientId = "c-" + crypto.randomBytes(4).toString("hex");
23
+ return ws._clagenticClientId;
24
+ }
25
+
26
+ function userIdOf(user) {
27
+ return user && user.id !== undefined && user.id !== null ? String(user.id) : null;
28
+ }
29
+
30
+ function fromWs(ws) {
31
+ return { kind: "ws", clientId: clientIdOf(ws), user: userIdOf(ws && ws._clagenticUser) };
32
+ }
33
+
34
+ // req is the HTTP request the answer arrived on.
35
+ function fromPush(req, action) {
36
+ return { kind: "push", action: action, user: userIdOf(req && req._clagenticUser) };
37
+ }
38
+
39
+ function fromTimeout() {
40
+ return { kind: "timeout" };
41
+ }
42
+
43
+ function fromCancel(reason) {
44
+ return { kind: "cancel", reason: reason };
45
+ }
46
+
47
+ // The source as log fields, "source=ws client=c-1a2b user=u1". A cancel's
48
+ // reason is its own field on the settle line, not repeated here.
49
+ function describe(source) {
50
+ if (!source) return "source=unspecified";
51
+ var out = "source=" + logField(source.kind);
52
+ if (source.clientId) out += " client=" + logField(source.clientId);
53
+ if (source.action) out += " action=" + logField(source.action);
54
+ if (source.kind === "ws" || source.kind === "push") out += " user=" + logField(source.user);
55
+ return out;
56
+ }
57
+
58
+ module.exports = {
59
+ fromWs: fromWs,
60
+ fromPush: fromPush,
61
+ fromTimeout: fromTimeout,
62
+ fromCancel: fromCancel,
63
+ describe: describe,
64
+ clientIdOf: clientIdOf,
65
+ };
@@ -136,6 +136,21 @@
136
136
  letter-spacing: 0.12em;
137
137
  margin-bottom: 3px;
138
138
  }
139
+ /* Whose prompt this is and what Allow for session grants: wrapped, never
140
+ cut off, because a clipped label is the failure these lines exist to fix. */
141
+ .notif-banner-label {
142
+ font-family: var(--font-mono, monospace);
143
+ font-size: 10.5px;
144
+ color: var(--accent);
145
+ margin-bottom: 3px;
146
+ overflow-wrap: anywhere;
147
+ }
148
+ .notif-banner-scope {
149
+ font-size: 12px;
150
+ color: var(--text-secondary);
151
+ margin-top: 3px;
152
+ overflow-wrap: anywhere;
153
+ }
139
154
  .notif-banner-title {
140
155
  font-weight: 500;
141
156
  font-size: 13px;
@@ -544,6 +544,24 @@ button.top-bar-pill.pill-accent:hover { background: color-mix(in srgb, var(--acc
544
544
 
545
545
  #skill-install-modal.hidden { display: none; }
546
546
 
547
+ #session-grants-modal {
548
+ position: fixed;
549
+ inset: 0;
550
+ z-index: 300;
551
+ display: flex;
552
+ align-items: center;
553
+ justify-content: center;
554
+ }
555
+ .session-grants-dialog { max-width: 520px; }
556
+ .session-grants-title { font-weight: 600; font-size: 16px; margin-bottom: 12px; color: var(--text); }
557
+ .session-grants-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; max-height: 50vh; overflow-y: auto; }
558
+ .session-grants-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; background: rgba(var(--overlay-rgb), 0.05); border: 1px solid var(--border); }
559
+ .session-grants-whole { border-color: var(--warning, #f39c12); }
560
+ .session-grants-text { flex: 1; min-width: 0; font-size: 13px; color: var(--text); overflow-wrap: anywhere; }
561
+ .session-grants-revoke { flex-shrink: 0; background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text); cursor: pointer; padding: 4px 10px; font-size: 12px; }
562
+ .session-grants-revoke:disabled { opacity: 0.5; cursor: default; }
563
+ .session-grants-empty { font-size: 13px; color: var(--text-muted); }
564
+
547
565
  .skill-install-dialog { max-width: 460px; padding: 28px 32px; }
548
566
  .skill-install-title { font-weight: 600; font-size: 17px; margin-bottom: 8px; color: var(--text); }
549
567
  .skill-install-reason { color: var(--text-secondary); font-size: 14px; line-height: 1.5; margin-bottom: 18px; }
@@ -618,6 +618,14 @@
618
618
 
619
619
  /* The user's own ask rule that forced the prompt. */
620
620
  .permission-rule { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
621
+ .permission-scope { font-size: 12px; color: var(--text-secondary); margin-top: 6px; overflow-wrap: anywhere; }
622
+ .prompt-label {
623
+ font-family: var(--font-mono, monospace);
624
+ font-size: 11px;
625
+ color: var(--accent);
626
+ margin-bottom: 4px;
627
+ overflow-wrap: anywhere;
628
+ }
621
629
 
622
630
  /* An ask that must open on No: the approve choices lose their primary
623
631
  styling and the decline choice leads. */
@@ -65,6 +65,7 @@ import { handleRateLimitEvent, updateRateLimitUsage, addScheduledMessageBubble,
65
65
  import { handleRemoteCursorMove, handleRemoteCursorLeave, handleRemoteSelection, clearRemoteCursors } from './app-cursors.js';
66
66
  import { showLoopBanner, updateLoopBanner, updateLoopInputVisibility, updateLoopPendingBanner, showRalphApprovalBar, updateRalphApprovalStatus, openRalphPreviewModal, showExecModal, updateExecModalStatus } from './app-loop-ui.js';
67
67
  import { handleSkillInstallWs } from './app-skills-install.js';
68
+ import { handleSessionGrants } from './session-grants.js';
68
69
  import { handleNotificationsState, handleNotificationCreated, handleNotificationDismissed, handleNotificationDismissedAll, showUpdateBanner } from './app-notifications.js';
69
70
  import { handleMentionStart, handleMentionActivity, handleMentionStream, handleMentionDone, handleMentionError, renderMentionUser, renderMentionResponse, renderUserMention } from './mention.js';
70
71
  import { handleTeamState, handleTeamMemberUpdate, handleTeamTaskUpdate, handleTeamMessage as handleTeamMsg, handleTeamGone } from './team-panel.js';
@@ -1477,6 +1478,8 @@ registerHandlers({
1477
1478
  addSystemMessage("Error: " + msg.text, true);
1478
1479
  },
1479
1480
 
1481
+ session_grants: handleSessionGrants,
1482
+
1480
1483
  // --- Notifications ---
1481
1484
  notifications_state: handleNotificationsState,
1482
1485
  notification_created: handleNotificationCreated,
@@ -13,7 +13,8 @@ import { switchProject } from './app-projects.js';
13
13
  import { userAvatarUrl } from './avatar.js';
14
14
  import { openTerminal } from './terminal.js';
15
15
  import { askWording } from './prompt-kinds/index.js';
16
- import { wirePromptBanner, restoreUnconfirmedBanners, bannerActions } from './prompt-banner.js';
16
+ import { wirePromptBanner, restoreUnconfirmedBanners, bannerActions, bannerScope } from './prompt-banner.js';
17
+ import { promptLabelHtml } from './prompt-label.js';
17
18
 
18
19
  // The server dismisses a prompt's banner once the prompt settles, however it
19
20
  // was answered.
@@ -139,12 +140,19 @@ function showBanner(notif, autoDismissMs) {
139
140
  '</div>';
140
141
  }
141
142
 
143
+ // The server says whose prompt this is (project, session, agent) and what
144
+ // Allow for session would grant: a banner reaches every client whatever
145
+ // project it is viewing, and the tool request alone does not say.
146
+ var scopeText = isPermission ? bannerScope(promptKind, notif.meta) : "";
147
+
142
148
  banner.innerHTML =
143
149
  '<div class="notif-banner-icon">' + iconHtmlStr + '</div>' +
144
150
  '<div class="notif-banner-body">' +
145
151
  (projectName ? '<div class="notif-banner-project">' + escapeHtml(projectName) + '</div>' : '') +
152
+ (isPermission ? promptLabelHtml(notif.meta.label) : '') +
146
153
  '<div class="notif-banner-title">' + escapeHtml(notif.title) + '</div>' +
147
154
  (notif.body ? '<div class="notif-banner-text">' + escapeHtml(notif.body) + '</div>' : '') +
155
+ (scopeText ? '<div class="notif-banner-scope">' + escapeHtml(scopeText) + '</div>' : '') +
148
156
  actionsHtml +
149
157
  '</div>' +
150
158
  (!isEmpty ? '<button class="notif-banner-close">' + iconHtml("x") + '</button>' : '');
@@ -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
+ }