@clagentic/console 1.10.0-beta.3 → 1.10.0-beta.4

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 (38) hide show
  1. package/lib/build-sha.json +2 -2
  2. package/lib/build-update-offer.js +29 -0
  3. package/lib/daemon.js +5 -9
  4. package/lib/grant-keys.js +24 -137
  5. package/lib/identity/config.js +118 -0
  6. package/lib/identity/contract.js +61 -0
  7. package/lib/identity/delivery.js +224 -0
  8. package/lib/identity/holder.js +87 -0
  9. package/lib/identity/index.js +229 -0
  10. package/lib/identity/jose.js +13 -0
  11. package/lib/identity/origin.js +28 -0
  12. package/lib/identity/owner.js +30 -0
  13. package/lib/identity/providers/gatekeeper.js +91 -0
  14. package/lib/identity/providers/jwks-self.js +85 -0
  15. package/lib/identity/providers/module.js +98 -0
  16. package/lib/identity/providers/signing-key.js +118 -0
  17. package/lib/identity/record.js +23 -0
  18. package/lib/identity/unavailable.js +29 -0
  19. package/lib/project-notifications.js +2 -3
  20. package/lib/prompt-kinds/permission.js +0 -18
  21. package/lib/prompt-registry.js +5 -13
  22. package/lib/public/css/notifications-center.css +2 -8
  23. package/lib/public/css/rewind.css +0 -1
  24. package/lib/public/modules/app-notifications.js +4 -7
  25. package/lib/public/modules/build-notice-gate.js +73 -0
  26. package/lib/public/modules/diagnostics.js +43 -1
  27. package/lib/public/modules/prompt-banner.js +0 -12
  28. package/lib/public/modules/prompt-kinds/permission-choices.js +1 -6
  29. package/lib/public/modules/prompt-kinds/permission.js +0 -15
  30. package/lib/sdk-bridge.js +82 -3
  31. package/lib/sessions.js +7 -0
  32. package/lib/turn-initiator.js +29 -14
  33. package/lib/utils.js +4 -7
  34. package/lib/ws-schema.js +3 -3
  35. package/lib/yoke/adapters/claude-worker.js +5 -5
  36. package/lib/yoke/adapters/claude.js +5 -5
  37. package/package.json +3 -1
  38. package/scripts/vendor-identity-vectors.js +52 -0
@@ -0,0 +1,73 @@
1
+ // build-notice-gate.js — decides what the diagnostics list does with the
2
+ // "newer build installed" notice, which the daemon replays to every client that
3
+ // connects (once per project connection) and refreshes while the build is stale.
4
+ //
5
+ // Pure state and rules, no DOM: lib/public/modules/diagnostics.js asks it what
6
+ // to do and does it. The rules:
7
+ // - one notice per running/installed build pair; an identical one never stacks;
8
+ // - a different pair replaces the held one, or retracts it when the incoming
9
+ // pair is itself quiet (nothing new is shown until the cooldown passes);
10
+ // - once the operator has closed the notice (the toast, or the panel entry),
11
+ // the same pair stays quiet until the cooldown has passed.
12
+
13
+ export var BUILD_NOTICE_SOURCE = 'build-update';
14
+ export var BUILD_NOTICE_ACTION = 'restart_for_build_update';
15
+ export var DEFAULT_COOLDOWN_MS = 60 * 60 * 1000;
16
+
17
+ /** The pair a standing notice is about, or null when `msg` is not that notice. */
18
+ export function noticeKeyOf(msg) {
19
+ if (!msg || msg.source !== BUILD_NOTICE_SOURCE) return null;
20
+ if (!msg.actionable || msg.actionable.action !== BUILD_NOTICE_ACTION) return null;
21
+ var b = msg.buildUpdate;
22
+ if (!b || !b.loadedBuildSha || !b.installedBuildSha) return null;
23
+ return b.loadedBuildSha + ':' + b.installedBuildSha;
24
+ }
25
+
26
+ /** The daemon-configured cooldown carried on the notice, else the default. */
27
+ export function cooldownOf(msg) {
28
+ var ms = msg && msg.noticeCooldownMs;
29
+ return typeof ms === 'number' && isFinite(ms) && ms >= 0 ? ms : DEFAULT_COOLDOWN_MS;
30
+ }
31
+
32
+ export function createNoticeGate() {
33
+ // key -> {at, entryGone}. entryGone: the operator removed the panel entry too,
34
+ // so the notice must not come back at all, not just without a toast.
35
+ var closed = Object.create(null);
36
+
37
+ return {
38
+ /**
39
+ * @param {object} s
40
+ * @param {string} s.key — noticeKeyOf(msg)
41
+ * @param {?string} s.heldKey — key of the notice already in the list, or null
42
+ * @param {boolean} s.toastOnScreen — a toast for the held notice is showing
43
+ * @param {number} s.now
44
+ * @param {number} s.cooldownMs
45
+ * @returns {{action: 'add'|'replace'|'retract'|'skip'|'retoast', toast: boolean}}
46
+ */
47
+ decide: function (s) {
48
+ var rec = closed[s.key];
49
+ var quiet = rec !== undefined && s.now - rec.at < s.cooldownMs;
50
+ if (rec !== undefined && !quiet) delete closed[s.key];
51
+
52
+ if (s.heldKey === s.key) {
53
+ // Identical notice: never a second entry. After the cooldown the toast
54
+ // may come back if the operator had closed it.
55
+ if (rec !== undefined && !quiet && !s.toastOnScreen) return { action: 'retoast', toast: true };
56
+ return { action: 'skip', toast: false };
57
+ }
58
+ // A quiet current pair shows nothing, so a different held pair is stale
59
+ // and must go too: one current notice, never an obsolete one left visible.
60
+ if (quiet && s.heldKey) return { action: 'retract', toast: false };
61
+ if (quiet && rec.entryGone) return { action: 'skip', toast: false };
62
+ return { action: s.heldKey ? 'replace' : 'add', toast: !quiet };
63
+ },
64
+ toastClosed: function (key, now) {
65
+ if (!key) return;
66
+ var rec = closed[key];
67
+ closed[key] = { at: now, entryGone: rec ? rec.entryGone : false };
68
+ },
69
+ entryDismissed: function (key, now) {
70
+ if (key) closed[key] = { at: now, entryGone: true };
71
+ },
72
+ };
73
+ }
@@ -27,6 +27,11 @@ 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
29
  import { buildUpdateDetailEl } from './build-update-detail.js';
30
+ import {
31
+ BUILD_NOTICE_SOURCE, BUILD_NOTICE_ACTION, noticeKeyOf, cooldownOf, createNoticeGate,
32
+ } from './build-notice-gate.js';
33
+
34
+ var _noticeGate = createNoticeGate();
30
35
 
31
36
  // Allowlist of actionable.action values this client will act on.
32
37
  // A diagnostic's `actionable.action` string is never sent to the server
@@ -203,6 +208,9 @@ export function addDiagnostic(msg, opts) {
203
208
  ts: now,
204
209
  id: _nextDiagnosticId++,
205
210
  };
211
+ var gate = _gateBuildNotice(msg, now);
212
+ if (gate.action === "skip") return;
213
+ entry.noticeKey = gate.key;
206
214
  diagnostics.push(entry);
207
215
 
208
216
  // Render the new entry in the panel list.
@@ -212,12 +220,39 @@ export function addDiagnostic(msg, opts) {
212
220
  _updateBadge();
213
221
 
214
222
  // Toast for warning and error severity only.
215
- var toastAllowed = !(opts && opts.toast === false);
223
+ var toastAllowed = !(opts && opts.toast === false) && gate.toast;
216
224
  if (toastAllowed && (entry.severity === "warning" || entry.severity === "error")) {
217
225
  _showDiagnosticToast(entry);
218
226
  }
219
227
  }
220
228
 
229
+ // The standing build-update notice is replayed to every connection and refreshed
230
+ // while the build is stale; build-notice-gate.js decides whether this arrival
231
+ // adds, replaces, re-toasts or is dropped. Anything else passes through.
232
+ function _gateBuildNotice(msg, now) {
233
+ var key = noticeKeyOf(msg);
234
+ if (!key) return { action: "add", toast: true, key: null };
235
+ var held = diagnostics.filter(function (e) {
236
+ return e.source === BUILD_NOTICE_SOURCE && _actionOf(e) === BUILD_NOTICE_ACTION;
237
+ })[0] || null;
238
+ var decision = _noticeGate.decide({
239
+ key: key,
240
+ heldKey: held ? held.noticeKey || null : null,
241
+ toastOnScreen: held ? _toastsFor(BUILD_NOTICE_SOURCE, BUILD_NOTICE_ACTION).length > 0 : false,
242
+ now: now,
243
+ cooldownMs: cooldownOf(msg),
244
+ });
245
+ if (decision.action === "replace" || decision.action === "retract") {
246
+ retractDiagnostics(BUILD_NOTICE_SOURCE, BUILD_NOTICE_ACTION);
247
+ }
248
+ if (decision.action === "retract") return { action: "skip", toast: false, key: key };
249
+ if (decision.action === "retoast") {
250
+ _showDiagnosticToast(held);
251
+ return { action: "skip", toast: false, key: key };
252
+ }
253
+ return { action: decision.action, toast: decision.toast, key: key };
254
+ }
255
+
221
256
  /**
222
257
  * Updates the entry a source already holds with a newer message (the update
223
258
  * offer, once its change list is read). It replaces in place: no second entry,
@@ -379,6 +414,7 @@ function _showDiagnosticToast(entry) {
379
414
  // Manual dismiss.
380
415
  dismissBtn.addEventListener("click", function () {
381
416
  clearTimeout(timer);
417
+ _noticeGate.toastClosed(entry.noticeKey, Date.now());
382
418
  _removeDiagnosticToast(el);
383
419
  });
384
420
 
@@ -386,6 +422,7 @@ function _showDiagnosticToast(entry) {
386
422
  el.addEventListener("keydown", function (e) {
387
423
  if (e.key === "Escape" || e.key === "Enter" || e.key === " ") {
388
424
  clearTimeout(timer);
425
+ _noticeGate.toastClosed(entry.noticeKey, Date.now());
389
426
  _removeDiagnosticToast(el);
390
427
  }
391
428
  });
@@ -537,6 +574,7 @@ function dismissDiagnostic(id) {
537
574
  if (diagnostics[i].id === id) { idx = i; break; }
538
575
  }
539
576
  if (idx === -1) return;
577
+ _noticeGate.entryDismissed(diagnostics[idx].noticeKey, Date.now());
540
578
  diagnostics.splice(idx, 1);
541
579
 
542
580
  if (panelListEl) {
@@ -555,6 +593,10 @@ function dismissDiagnostic(id) {
555
593
  * no server-side dismiss contract (see module header note).
556
594
  */
557
595
  function clearAllDiagnostics() {
596
+ var clearedAt = Date.now();
597
+ diagnostics.forEach(function (entry) { _noticeGate.entryDismissed(entry.noticeKey, clearedAt); });
598
+ // Toasts for the cleared entries go too, so clear-all leaves nothing on screen.
599
+ Array.prototype.slice.call(_getToastContainer().querySelectorAll("[data-diag-source]")).forEach(_removeDiagnosticToast);
558
600
  diagnostics = [];
559
601
  if (panelListEl) panelListEl.innerHTML = "";
560
602
  _restoreEmptyPlaceholder();
@@ -45,18 +45,6 @@ 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
-
60
48
  /**
61
49
  * Wire a banner's decision buttons to answer its prompt.
62
50
  * @param {Element} banner
@@ -7,10 +7,6 @@
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).
14
10
  // The server refuses an Allow-for-session answer to a suppressed ask whatever
15
11
  // a client sends (lib/prompt-kinds/permission.js); omitting the choice here is
16
12
  // the presentation of that rule, not its enforcement.
@@ -25,8 +21,7 @@
25
21
  */
26
22
  export function permissionChoices(hints) {
27
23
  var h = hints || {};
28
- var noSession = h.suppressAlwaysAllowRule === true || h.grantScope === null;
29
- var approve = noSession ? ["allow"] : ["allow", "allow_always"];
24
+ var approve = h.suppressAlwaysAllowRule === true ? ["allow"] : ["allow", "allow_always"];
30
25
  return h.defaultToNo === true ? ["deny"].concat(approve) : approve.concat(["deny"]);
31
26
  }
32
27
 
@@ -46,17 +46,6 @@ 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
-
60
49
  function shortPath(p) {
61
50
  if (!p) return "";
62
51
  var parts = p.split("/");
@@ -150,8 +139,6 @@ function drawFormal(fields, requestId, host) {
150
139
  var rule = ruleNote(fields);
151
140
  if (rule) body.appendChild(rule);
152
141
  body.appendChild(detailsElement("permission-details", fields.toolInput));
153
- var scope = scopeNote(fields);
154
- if (scope) body.appendChild(scope);
155
142
 
156
143
  var actions = document.createElement("div");
157
144
  actions.className = "permission-actions";
@@ -195,8 +182,6 @@ function drawConversational(fields, requestId, host) {
195
182
  var rule = ruleNote(fields);
196
183
  if (rule) content.appendChild(rule);
197
184
  content.appendChild(detailsElement("perm-details", fields.toolInput));
198
- var scope = scopeNote(fields);
199
- if (scope) content.appendChild(scope);
200
185
 
201
186
  var actions = document.createElement("div");
202
187
  actions.className = "permission-actions";
package/lib/sdk-bridge.js CHANGED
@@ -433,6 +433,64 @@ function createSDKBridge(opts) {
433
433
  return queryOptions;
434
434
  }
435
435
 
436
+ // --- Identity surface (lib/identity) ---
437
+ // Everything here is inert unless the daemon configuration has an `identity`
438
+ // block: no module is loaded, no provider is asked, no file is made, and the
439
+ // query options carry no identity member.
440
+ var _identity = null;
441
+ function identityConfig() {
442
+ var cfg = typeof opts.getConfig === "function" ? opts.getConfig() : null;
443
+ return cfg ? cfg.identity : undefined;
444
+ }
445
+ function getIdentity() {
446
+ if (!_identity) {
447
+ _identity = require("./identity").createIdentity({
448
+ getConfig: identityConfig,
449
+ configDir: require("./config").CONFIG_DIR,
450
+ });
451
+ }
452
+ return _identity;
453
+ }
454
+
455
+ // The identity lease of one agent process, or null when no provider is
456
+ // configured. `agent` is the persona agent the process runs as, if any.
457
+ async function beginIdentity(vendorId, agent, linuxUser, initiator) {
458
+ var identity = getIdentity();
459
+ if (!identity.isEnabled()) return null;
460
+ var owner = null;
461
+ if (linuxUser) {
462
+ var resolved = require("./identity/owner").resolveOwner(linuxUser, require("./os-users").resolveOsUserInfo, console.warn);
463
+ if (resolved.unresolved) {
464
+ return identity.declared(initiator, "owner_unresolved", "the session's OS user could not be looked up");
465
+ }
466
+ owner = resolved.owner;
467
+ }
468
+ return identity.begin({
469
+ definition: (agent && slugifyAgentName(agent)) || null,
470
+ initiator: initiator,
471
+ rt: vendorId === "claude" ? "claude-code" : vendorId,
472
+ owner: owner,
473
+ });
474
+ }
475
+
476
+ // Puts the lease's record on the session and tells the person once when the
477
+ // provider could not supply an identity (not on every start that fails alike).
478
+ function recordIdentity(session, lease) {
479
+ var previous = session.identity || null;
480
+ session.identity = lease.record;
481
+ var unchanged = !!previous && JSON.stringify(previous) === JSON.stringify(lease.record);
482
+ if (lease.notice && !(previous && previous.unavailable === lease.record.unavailable)) {
483
+ sendAndRecord(session, { type: "diagnostic", severity: "warning", source: "identity", message: lease.notice });
484
+ }
485
+ if (!unchanged) sm.saveSessionFile(session);
486
+ }
487
+
488
+ function clearIdentityRecord(session) {
489
+ if (!session.identity) return;
490
+ delete session.identity;
491
+ sm.saveSessionFile(session);
492
+ }
493
+
436
494
  // Tells each connected client the agent registry again, after something
437
495
  // changed what it holds (a vendor's live capabilities were recorded). Install
438
496
  // state is per OS identity, so the project supplies a sender that gives every
@@ -1220,6 +1278,8 @@ function createSDKBridge(opts) {
1220
1278
  // not resources from a newer query that may have been created after an abort.
1221
1279
  var myQueryInstance = session.queryInstance;
1222
1280
  var myAbortController = session.abortController;
1281
+ var myIdentityLease = session._identityLease || null;
1282
+ if (myIdentityLease) session._identityLease = null;
1223
1283
  console.log("[sdk-bridge] processQueryStream: starting for-await loop, vendor=" + (session.vendor || adapter.vendor));
1224
1284
  try {
1225
1285
  for await (var msg of myQueryInstance) {
@@ -1409,6 +1469,8 @@ function createSDKBridge(opts) {
1409
1469
  }
1410
1470
  session.messageQueue = null;
1411
1471
  if (session.abortController === myAbortController) session.abortController = null;
1472
+ // The query's process is ended above; its identity directory goes with it.
1473
+ if (myIdentityLease) myIdentityLease.release();
1412
1474
 
1413
1475
  // lr-29f9: Reap the worker process immediately on query completion.
1414
1476
  // The worker is kept alive between turns by _adapterWorkerState reuse, but
@@ -1606,8 +1668,8 @@ function createSDKBridge(opts) {
1606
1668
  }
1607
1669
 
1608
1670
  // `initiator` (turn-initiator.js INITIATORS) is who started this turn. It is
1609
- // per turn: it stamps the first message and decides the new process's
1610
- // environment, and says nothing about later turns of the session.
1671
+ // per turn: it stamps the first message and says nothing about later turns
1672
+ // of the session or about the process's environment.
1611
1673
  async function startQuery(session, text, images, linuxUser, initiator) {
1612
1674
  async function ensureVendorReady(vendor) {
1613
1675
  if (!vendor) return null;
@@ -2112,7 +2174,6 @@ function createSDKBridge(opts) {
2112
2174
  var mergedMcpServers = mergeMcpServers(getMcpServers(), getRemoteMcpServers) || undefined;
2113
2175
  var queryOpts = {
2114
2176
  cwd: cwd,
2115
- initiator: initiator,
2116
2177
  model: queryModel,
2117
2178
  effort: ls.effort || sm.currentEffort || undefined,
2118
2179
  toolServers: mergedMcpServers,
@@ -2158,12 +2219,28 @@ function createSDKBridge(opts) {
2158
2219
  // The variables Settings add to this runtime's environment, as of now.
2159
2220
  withRuntimeEnv(queryOpts, session);
2160
2221
 
2222
+ // The identity of this agent process, when a provider is configured. Its
2223
+ // directory is delivered in the process's environment and removed when the
2224
+ // query ends (processQueryStream) or fails to start (below).
2225
+ var identityLease = identityConfig() == null
2226
+ ? null
2227
+ : await beginIdentity(sessionAdapter.vendor, claudeOpts.agent, linuxUser, initiator);
2228
+ if (identityLease) {
2229
+ recordIdentity(session, identityLease);
2230
+ queryOpts.identity = { dir: identityLease.dir };
2231
+ } else {
2232
+ // No identity is issued for this start (none configured any more): a record
2233
+ // an earlier start left must not stay on the session as if this one had it.
2234
+ clearIdentityRecord(session);
2235
+ }
2236
+
2161
2237
  var handle;
2162
2238
  console.log("[sdk-bridge] calling adapter.createQuery... vendor=" + sessionAdapter.vendor);
2163
2239
  try {
2164
2240
  handle = await sessionAdapter.createQuery(queryOpts);
2165
2241
  console.log("[sdk-bridge] createQuery returned handle, vendor=" + sessionAdapter.vendor);
2166
2242
  } catch (e) {
2243
+ if (identityLease) identityLease.release();
2167
2244
  console.error("[sdk-bridge] Failed to create query for session " + session.localId + ":", e.message || e);
2168
2245
  console.error("[sdk-bridge] cliSessionId:", session.cliSessionId, "resume:", !!session.cliSessionId);
2169
2246
  console.error("[sdk-bridge] Stack:", e.stack || "(no stack)");
@@ -2199,6 +2276,7 @@ function createSDKBridge(opts) {
2199
2276
 
2200
2277
  // Store QueryHandle on session for iteration and control.
2201
2278
  session.queryInstance = handle;
2279
+ if (identityLease) session._identityLease = identityLease;
2202
2280
 
2203
2281
  // Push initial user message through the QueryHandle
2204
2282
  console.log("[sdk-bridge] pushing initial message via handle.pushMessage...");
@@ -2236,6 +2314,7 @@ function createSDKBridge(opts) {
2236
2314
  // Unexpected synchronous throw anywhere in the post-slot-claim body.
2237
2315
  // Release the slot and surface the error so the UI does not spin forever.
2238
2316
  releaseSlot();
2317
+ if (identityLease) identityLease.release();
2239
2318
  session.isProcessing = false;
2240
2319
  onProcessingChanged();
2241
2320
  session.queryInstance = null;
package/lib/sessions.js CHANGED
@@ -182,6 +182,9 @@ function createSessionManager(opts) {
182
182
  if (session.titleManuallySet) metaObj.titleManuallySet = true;
183
183
  if (session.titleProvisional) metaObj.titleProvisional = true;
184
184
  if (typeof session.turnCount === "number" && session.turnCount > 0) metaObj.turnCount = session.turnCount;
185
+ // Which identity provider vouched for the session and at what grade. Only
186
+ // present when a provider is configured: a plain session has no such field.
187
+ if (session.identity) metaObj.identity = session.identity;
185
188
  return JSON.stringify(metaObj);
186
189
  }
187
190
 
@@ -784,6 +787,10 @@ function createSessionManager(opts) {
784
787
  session.titleManuallySet = !!m.titleManuallySet;
785
788
  session.titleProvisional = !!m.titleProvisional;
786
789
  session.turnCount = typeof m.turnCount === "number" ? m.turnCount : 0;
790
+ if (m.identity) {
791
+ var identityRecord = require("./identity/record").sanitizeRecord(m.identity);
792
+ if (identityRecord) session.identity = identityRecord;
793
+ }
787
794
  sessions.set(localId, session);
788
795
  }
789
796
  }
@@ -14,6 +14,8 @@
14
14
 
15
15
  var pkg = require("../package.json");
16
16
  var runtimeEnv = require("./runtime-env");
17
+ // Required for its constant only: nothing of the identity surface runs from here.
18
+ var IDENTITY_DIR_ENV = require("./identity/contract").IDENTITY_DIR_ENV;
17
19
 
18
20
  var INITIATORS = Object.freeze({
19
21
  // Text a person typed into the console.
@@ -60,14 +62,6 @@ function isClientComposed(initiator) {
60
62
  return isInitiator(initiator) && initiator !== INITIATORS.HUMAN;
61
63
  }
62
64
 
63
- // The CLI keeps a host-declared origin only when it is human, or the
64
- // scheduled-trigger kind in a process started with this variable. Every
65
- // automated turn uses the latter, so a process whose first turn is anything but
66
- // a typed one gets it.
67
- function isScheduledInitiator(initiator) {
68
- return isClientComposed(initiator);
69
- }
70
-
71
65
  // Identifies this product to the Claude Agent SDK ("<app>/<version>").
72
66
  function clientAppId() {
73
67
  return "clagentic-console/" + pkg.version;
@@ -75,17 +69,38 @@ function clientAppId() {
75
69
 
76
70
  // The environment additions the console always makes for a Claude process.
77
71
  // Laid over the process's own environment by the caller, never in place of it.
78
- function claudeHostEnv(initiator) {
79
- var env = { CLAUDE_AGENT_SDK_CLIENT_APP: clientAppId() };
80
- if (isScheduledInitiator(initiator)) env.CLAUDE_CODE_HOST_SCHEDULED_RUN = "1";
81
- return env;
72
+ //
73
+ // CLAUDE_CODE_HOST_SCHEDULED_RUN is declared on every process, whatever turn
74
+ // starts it. The CLI keeps a host-declared scheduled-trigger origin only in a
75
+ // process started with it, and the environment cannot change once the process
76
+ // runs, while turns of any initiator reach a live process (a typed turn starts
77
+ // it, a trigger or scheduled turn is pushed in later; messages buffered between
78
+ // turns are replayed into whichever process starts next). A typed turn's human
79
+ // origin is kept regardless of the variable. The variable's only other effect
80
+ // in the CLI is to switch off an oversized-attachment diagnostic event.
81
+ function claudeHostEnv() {
82
+ return {
83
+ CLAUDE_AGENT_SDK_CLIENT_APP: clientAppId(),
84
+ CLAUDE_CODE_HOST_SCHEDULED_RUN: "1",
85
+ };
82
86
  }
83
87
 
84
88
  // The complete environment for a Claude process: the process's own, then the
85
89
  // Settings overlay, then the console's additions. The SDK replaces the CLI's
86
90
  // environment with options.env, so this is always the whole environment.
87
- function claudeProcessEnv(base, overlay, initiator) {
88
- return Object.assign(runtimeEnv.composeRuntimeEnv(base, overlay), claudeHostEnv(initiator));
91
+ //
92
+ // CLAGENTIC_IDENTITY_DIR is the console's alone to set: an inherited value (from
93
+ // the daemon's own environment or from Settings) would name a directory the
94
+ // console never issued for this process, and a consumer would trust it. It is
95
+ // removed always; `identity` ({ dir: <delivery directory> | null }, present only
96
+ // when an identity provider is configured) is the only way it comes back.
97
+ function claudeProcessEnv(base, overlay, identity) {
98
+ var env = Object.assign(runtimeEnv.composeRuntimeEnv(base, overlay), claudeHostEnv());
99
+ delete env[IDENTITY_DIR_ENV];
100
+ if (identity && typeof identity === "object" && typeof identity.dir === "string" && identity.dir) {
101
+ env[IDENTITY_DIR_ENV] = identity.dir;
102
+ }
103
+ return env;
89
104
  }
90
105
 
91
106
  // A streamed Claude user message for a turn, with its provenance stamped.
package/lib/utils.js CHANGED
@@ -67,21 +67,18 @@ function resolveEncodedFile(baseDir, cwd, ext) {
67
67
  * handleCanUseTool check (lib/sdk-bridge.js:691).
68
68
  *
69
69
  * Keeps only entries whose key is a string and whose value is strictly
70
- * boolean `true` and not scoped to a file (a persisted Write:<path> key is
71
- * dropped: file tools never hold a session grant); drops everything else. A non-object input (including
70
+ * boolean `true` (see grantKeys.isGrantValue for the one retired key shape
71
+ * that is also dropped); drops everything else. A non-object input (including
72
72
  * null/undefined/arrays) yields an empty map rather than throwing. The map
73
73
  * has no prototype: its keys are tool names, and a name like "constructor"
74
- * must not be found as an inherited entry. A key longer than a grant can be,
75
- * or beyond the number a session record has room for, is dropped: grants are
76
- * persisted in a bounded part of the meta record (lib/grant-keys.js).
74
+ * must not be found as an inherited entry.
77
75
  */
78
76
  function sanitizeAllowedTools(value) {
79
77
  var out = Object.create(null);
80
78
  if (!value || typeof value !== "object" || Array.isArray(value)) return out;
81
79
  for (var key in value) {
82
80
  if (!Object.prototype.hasOwnProperty.call(value, key)) continue;
83
- if (typeof key === "string" && key.length <= grantKeys.MAX_KEY_LENGTH && grantKeys.isGrantValue(key, value[key])
84
- && Object.keys(out).length < grantKeys.MAX_GRANTS) out[key] = value[key];
81
+ if (typeof key === "string" && grantKeys.isGrantValue(key, value[key])) out[key] = true;
85
82
  }
86
83
  return out;
87
84
  }
package/lib/ws-schema.js CHANGED
@@ -122,9 +122,9 @@ var schema = {
122
122
  // suppressAlwaysAllowRule, defaultToNo, matchedAskRule; ask_user: input; elicitation: serverName,
123
123
  // message, mode, url, elicitationId, requestedSchema).
124
124
  // -----------------------------------------------------------------------
125
- "prompt_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt awaits the operator: {requestId, kind, toolUseId, label: {project, session, agent}, ...kind fields} (label names whose prompt it is; agent is empty unless a background agent raised it; a permission prompt also carries grantScope, the sentence saying what Allow for Session would grant, or null when it cannot be granted). On history replay it carries promptState {state: pending|resolved|cancelled, decision|answers|skipped|action, reason}, the server's authoritative state for the prompt at replay time" },
125
+ "prompt_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt awaits the operator: {requestId, kind, toolUseId, label: {project, session, agent}, ...kind fields} (label names whose prompt it is; agent is empty unless a background agent raised it). On history replay it carries promptState {state: pending|resolved|cancelled, decision|answers|skipped|action, reason}, the server's authoritative state for the prompt at replay time" },
126
126
  "prompt_pending": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt still awaiting the operator, re-presented on connect and session switch; same fields as prompt_request" },
127
- "prompt_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "The operator's answer: {requestId, kind, ...} with decision (+ feedback, planContent) for permission/plan, answers or decision:\"skip\" for ask_user (answers keyed by question index; each a label or text, or for a multi-select question the list of chosen labels), action (+ content, held to the requested schema) for elicitation. The kind is required and must match the prompt's. Decision allow_always grants only what the prompt's grantScope says, and to a permission prompt that carries suppressAlwaysAllowRule, or whose grantScope is null (nothing narrow enough to grant), settles nothing: the prompt is sent again as prompt_pending. A prompt of the extension kind is never answered this way" },
127
+ "prompt_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "The operator's answer: {requestId, kind, ...} with decision (+ feedback, planContent) for permission/plan, answers or decision:\"skip\" for ask_user (answers keyed by question index; each a label or text, or for a multi-select question the list of chosen labels), action (+ content, held to the requested schema) for elicitation. The kind is required and must match the prompt's. Decision allow_always grants the whole tool (Skill: the one skill) for the rest of the session, and to a permission prompt that carries suppressAlwaysAllowRule settles nothing: the prompt is sent again as prompt_pending. A prompt of the extension kind is never answered this way" },
128
128
  "prompt_resolved": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt was answered: {requestId, kind, decision|answers|skipped|action, source?}; a permission prompt forced by a user ask rule also carries matchedAskRule. source says who answered, as {kind:\"ws\", clientId, user} for a browser connection (clientId is a per-connection label, user the user id or null) or {kind:\"push\", action, user} for a push notification answer; it is absent when the answering path named none. The same source is written to the journal line the settle logs. Prompt content is never part of a source" },
129
129
  "prompt_cancel": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt ended without an answer: {requestId, kind, reason}; reason is aborted, expired, turn_ended, query_ended, rewind, cleared or shutdown. Reason \"stale\" is sent only to a client whose prompt_response named a prompt the server no longer holds, and is not recorded in history" },
130
130
 
@@ -136,7 +136,7 @@ var schema = {
136
136
  // permission_response.
137
137
  "list_session_grants": { direction: "c2s", handler: "lib/project-session-grants.js", description: "Ask for a session's Allow for Session grants: {sessionId?} (the connection's own session when absent). Answered with session_grants to the asker; refused silently for a session the user may not see" },
138
138
  "revoke_session_grant": { direction: "c2s", handler: "lib/project-session-grants.js", description: "Revoke one Allow for Session grant: {sessionId?, key}. Persisted at once and in force on the session's next tool call; every client viewing the session gets the resulting session_grants. Authorized by mayAnswerPrompt (lib/prompt-access.js), the rule that lets a user answer the session's prompts. For a session that rule refuses, the asker alone gets session_grants with an error string and no grants" },
139
- "session_grants": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A session's grants as {sessionId, grants: [{key, tool, wholeTool, text}]}; wholeTool marks a grant that covers every call of the tool (older sessions). A refused revoke is {sessionId, error} with no grants" },
139
+ "session_grants": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A session's grants as {sessionId, grants: [{key, tool, wholeTool, text}]}; wholeTool marks a grant that covers every call of the tool (every grant except a Skill one). A refused revoke is {sessionId, error} with no grants" },
140
140
  "permission_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_request (kind permission or plan); history carries permissionState or promptState" },
141
141
  "permission_request_pending": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_pending (kind permission or plan)" },
142
142
  "permission_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "Alias of prompt_response for kinds permission and plan: {requestId, decision, feedback, planContent}" },
@@ -105,12 +105,12 @@ function applyWorkerClaudeBinary(options) {
105
105
  function applyRuntimeEnv(options) {
106
106
  if (!options) return options;
107
107
  var overlay = options.runtimeEnv;
108
- var initiator = options.initiator;
109
108
  delete options.runtimeEnv;
110
- delete options.initiator;
111
- // Always built: the product identity is part of every Claude process's
112
- // environment, with the initiator of the turn that starts the query.
113
- options.env = turnInitiator.claudeProcessEnv(process.env, overlay, initiator);
109
+ var identity = options.identity;
110
+ delete options.identity;
111
+ // Always built: the product identity and host declaration are part of every
112
+ // Claude process's environment.
113
+ options.env = turnInitiator.claudeProcessEnv(process.env, overlay, identity);
114
114
  return options;
115
115
  }
116
116
 
@@ -1649,9 +1649,8 @@ function createClaudeAdapter(opts) {
1649
1649
 
1650
1650
  // options.env REPLACES the subprocess environment, so the query is handed
1651
1651
  // the whole environment (the process's own, the Settings variables, and
1652
- // the product identity), not the additions. queryOpts.initiator is the
1653
- // initiator of the turn that starts this process.
1654
- sdkOptions.env = turnInitiator.claudeProcessEnv(process.env, queryOpts.runtimeEnv, queryOpts.initiator);
1652
+ // the product identity and host declaration), not the additions.
1653
+ sdkOptions.env = turnInitiator.claudeProcessEnv(process.env, queryOpts.runtimeEnv, queryOpts.identity);
1655
1654
 
1656
1655
  var rawQuery = sdk.query({ prompt: mq, options: sdkOptions });
1657
1656
  return createQueryHandle(rawQuery, mq, ac);
@@ -1768,8 +1767,9 @@ function createClaudeAdapter(opts) {
1768
1767
  // The worker lays these over its own environment (the OS user's), then
1769
1768
  // hands the SDK the complete result.
1770
1769
  if (runtimeEnv.hasOverlay(queryOpts.runtimeEnv)) queryOptions.runtimeEnv = queryOpts.runtimeEnv;
1771
- // The worker builds the environment (see applyRuntimeEnv in claude-worker.js).
1772
- if (queryOpts.initiator) queryOptions.initiator = queryOpts.initiator;
1770
+ // Present only when an identity provider is configured; the worker adds the
1771
+ // delivery directory to the Claude process's environment.
1772
+ if (queryOpts.identity) queryOptions.identity = queryOpts.identity;
1773
1773
 
1774
1774
  if (queryOpts.toolServerDescriptors) queryOptions.mcpServerDescriptors = queryOpts.toolServerDescriptors;
1775
1775
  if (queryOpts.model) queryOptions.model = queryOpts.model;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.10.0-beta.3",
6
+ "version": "1.10.0-beta.4",
7
7
  "description": "Self-hosted console for Claude Code and Codex. Multi-user, browser-based, persistent AI sessions.",
8
8
  "bin": {
9
9
  "clagentic-console": "./bin/cli.js"
@@ -14,6 +14,7 @@
14
14
  "prepack": "node scripts/write-build-sha.js",
15
15
  "test": "node scripts/check-test-count.js test/*.test.js",
16
16
  "test:prompt-history": "node scripts/prompt-harness-history.js",
17
+ "vendor:identity-vectors": "node scripts/vendor-identity-vectors.js",
17
18
  "install:local-test": "node scripts/install-local-test.js",
18
19
  "verify:installed-build": "node scripts/verify-installed.js",
19
20
  "semantic-release": "semantic-release"
@@ -64,6 +65,7 @@
64
65
  "@anthropic-ai/sdk": "0.104.2",
65
66
  "@lydell/node-pty": "^1.2.0-beta.3",
66
67
  "ajv": "^8.20.0",
68
+ "jose": "^6.2.3",
67
69
  "nodemailer": "^10.1.0",
68
70
  "qrcode-terminal": "^0.12.0",
69
71
  "web-push": "^3.6.7",